Skip to content

Commit

Permalink
Read STON fields separator from file
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Feb 22, 2022
1 parent 112f1b9 commit d1ec8ac
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ CCodeGeneratorGlobalStructure >> generateCASTSetFieldTo: aTSendNode [

comparison := TSendNode
receiver: (TConstantNode value: slot name asString)
selector: '='
selector: 'strcmp:'
arguments: { fieldName }.

TSendNode
Expand Down
54 changes: 8 additions & 46 deletions smalltalksrc/VMMaker/AbstractComposedImageAccess.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ AbstractComposedImageAccess class >> declareCVarsIn: aCCodeGenerator [

]

{ #category : #'archive operations' }
AbstractComposedImageAccess >> contentsOf: valueHolder [

<cmacro: '(value) value'>

^ valueHolder contents
]

{ #category : #'file operations' }
AbstractComposedImageAccess >> createImageDirectory: imageFileName [

Expand Down Expand Up @@ -54,39 +46,6 @@ AbstractComposedImageAccess >> existSegment: segmentIndex inImage: imageFileName
inSmalltalk: [ fileName asFileReference exists ]
]

{ #category : #'file primitives' }
AbstractComposedImageAccess >> fprintf: aStream _: format [

<doNotGenerate>
^ self fprintf: aStream format: format arguments: { }
]

{ #category : #'file primitives' }
AbstractComposedImageAccess >> fprintf: aStream _: format _: aValue [

<doNotGenerate>
^ self fprintf: aStream format: format arguments: { aValue }
]

{ #category : #'file primitives' }
AbstractComposedImageAccess >> fprintf: aStream _: format _: aValue _: otherValue [

<doNotGenerate>
^ self fprintf: aStream format: format arguments: { aValue. otherValue }
]

{ #category : #'file primitives' }
AbstractComposedImageAccess >> fprintf: aStream format: aFormat arguments: arguments [

<doNotGenerate>
| printf |
printf := PrintfFormatString new setFormat: aFormat.

aStream nextPutAll: (printf
printf: arguments;
string)
]

{ #category : #'file primitives' }
AbstractComposedImageAccess >> fscanf: file _: format _: varHolder [

Expand All @@ -103,11 +62,14 @@ AbstractComposedImageAccess >> fscanf: file _: format _: varHolder1 _: varHolder
<doNotGenerate>
^ (format = fieldFormat)
ifTrue: [
| dataArray |
dataArray := file nextLine substrings: '#:,'.
(dataArray first = '}') ifTrue: [ ^false ].
varHolder1 contents: dataArray second trimLineSpaces.
varHolder2 contents: dataArray third trimLineSpaces asInteger ];
| line dataArray |
line := file nextLine.
dataArray := line substrings: '#:, '.
dataArray first = '}' ifTrue: [ ^ false ].
varHolder1 contents: dataArray second.
varHolder2 contents: dataArray third asInteger.
file position: file position - 1. "Not consume '\n' "
(line last = $,) ifTrue: [ file position: file position - 1 ] "Not consume ',' " ];
yourself
]

Expand Down
34 changes: 24 additions & 10 deletions smalltalksrc/VMMaker/ComposedImageReader.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Class {
#category : #'VMMaker-ImageFormat'
}

{ #category : #reading }
ComposedImageReader >> endOfSTON: file [

"This method consume 2 chars from file and return they are equivalent to '\n}'"

| charLeft charRight |
charLeft := self fgetc: file.
charRight := self fgetc: file.
^ (charLeft = self endOfLine) and: [ charRight = $} ]
]

{ #category : #reading }
ComposedImageReader >> readFieldsSTONFrom: file into: aStruct [

Expand All @@ -15,16 +26,19 @@ ComposedImageReader >> readFieldsSTONFrom: file into: aStruct [
fieldName := ValueHolder new.
fieldValue := ValueHolder new ].

[ self
fscanf: file
_: fieldFormat
_: (self addressOf: fieldName)
_: (self addressOf: fieldValue)
"check if line ends with ',\n' "
] whileTrue: [
"This solution does NOT WORK with STON file without fields (empty STON)"

[
self
fscanf: file
_: fieldFormat
_: fieldName
_: (self addressOf: fieldValue).

aStruct setField: (self contentsOf: fieldName) to: (self contentsOf: fieldValue).
]


self endOfSTON: file
] whileFalse
]

{ #category : #reading }
Expand All @@ -35,7 +49,7 @@ ComposedImageReader >> readHeadSTONFrom: file into: aStruct [
| structName |
self simulationOnly: [ structName := ValueHolder new ].

self fscanf: file _: headFormat _: (self addressOf: structName).
self fscanf: file _: headFormat _: structName.

self simulationOnly: [
aStruct withStructNameDo: [ :name |
Expand Down
54 changes: 54 additions & 0 deletions smalltalksrc/VMMaker/VMClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,14 @@ VMClass >> calloc: num _: size [
^ self malloc: num * size
]

{ #category : #'translation support' }
VMClass >> contentsOf: valueHolder [

<cmacro: '(value) value'>

^ valueHolder contents
]

{ #category : #'translation support' }
VMClass >> cppIf: conditionBlockOrValue ifTrue: trueExpressionOrBlock [
"When translated, produces #if (condition) #else #endif CPP directives.
Expand All @@ -601,6 +609,12 @@ VMClass >> defined: aSymbol [
ifNotNil: [:binding| binding value ~~ #undefined]
]

{ #category : #'file primitives' }
VMClass >> endOfLine [

^ self cCode: [ 13 ] inSmalltalk: [ Character cr ]
]

{ #category : #'memory access' }
VMClass >> fetchSingleFloatAtPointer: pointer into: aFloat [
"This gets implemented by Macros in C, where its types will also be checked.
Expand All @@ -610,6 +624,13 @@ VMClass >> fetchSingleFloatAtPointer: pointer into: aFloat [
^self fetchSingleFloatAt: pointer into: aFloat
]

{ #category : #'file primitives' }
VMClass >> fgetc: file [

<doNotGenerate>
^ file next
]

{ #category : #'memory access' }
VMClass >> floatAtPointer: pointer [
<doNotGenerate>
Expand All @@ -622,6 +643,39 @@ VMClass >> floatAtPointer: pointer put: value [
self halt.
]

{ #category : #'file primitives' }
VMClass >> fprintf: aStream _: format [

<doNotGenerate>
^ self fprintf: aStream format: format arguments: { }
]

{ #category : #'file primitives' }
VMClass >> fprintf: aStream _: format _: aValue [

<doNotGenerate>
^ self fprintf: aStream format: format arguments: { aValue }
]

{ #category : #'file primitives' }
VMClass >> fprintf: aStream _: format _: aValue _: otherValue [

<doNotGenerate>
^ self fprintf: aStream format: format arguments: { aValue. otherValue }
]

{ #category : #'file primitives' }
VMClass >> fprintf: aStream format: aFormat arguments: arguments [

<doNotGenerate>
| printf |
printf := PrintfFormatString new setFormat: aFormat.

aStream nextPutAll: (printf
printf: arguments;
string)
]

{ #category : #'C library simulation' }
VMClass >> free: pointer [
<doNotGenerate>
Expand Down

0 comments on commit d1ec8ac

Please sign in to comment.