Skip to content

Commit

Permalink
Fixing the code to be able to export
Browse files Browse the repository at this point in the history
  • Loading branch information
tesonep committed Oct 4, 2022
1 parent 563039d commit f61f801
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
71 changes: 39 additions & 32 deletions smalltalksrc/Melchor/CCodeGeneratorGlobalStructure.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ Class {
CCodeGeneratorGlobalStructure >> bindBlock: aTBlockNode withArgs: arguments [

| blockStatements argumentNames replacements |

blockStatements := aTBlockNode statements.
argumentNames := aTBlockNode args.
argumentNames := aTBlockNode arguments.

self assert: argumentNames size = arguments size.

replacements := argumentNames with: arguments collect: [ :name :value | name -> value ] .
replacements := argumentNames
with: arguments
collect: [ :name :value | name -> value ].

^ blockStatements collect: [ :anStatement |
anStatement copy bindVariableUsesIn: replacements asDictionary ]
Expand Down Expand Up @@ -213,7 +214,7 @@ CCodeGeneratorGlobalStructure >> generateCASTSetFieldTo: aTSendNode [
receiver: comparison
selector: 'ifTrue:'
arguments: {
TStmtListNode
TStatementListNode
statements: {
TSendNode
receiver: aTSendNode receiver
Expand All @@ -229,52 +230,58 @@ CCodeGeneratorGlobalStructure >> generateCASTSetFieldTo: aTSendNode [
]

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> generateCASTWithFieldsDoSeparatedBy: aTSendNode [
CCodeGeneratorGlobalStructure >> generateCASTWithFieldsDoSeparatedBy: aTSendNode [

| structType allRewrittenStatements blockSeparatorStatements fieldBlock allFieldArguments |

self assert: aTSendNode arguments size = 2.
self assert: aTSendNode arguments first args size = 2.
self assert: aTSendNode arguments second args size = 0.
self assert: aTSendNode arguments first arguments size = 2.
self assert: aTSendNode arguments second arguments size = 0.

fieldBlock := aTSendNode arguments first.
blockSeparatorStatements := aTSendNode arguments second statements.

structType := self structTypeFor: aTSendNode receiver.

allFieldArguments := structType asClass allSlots collect: [ :slot |
{
TConstantNode value: slot name asString.
TSendNode receiver: aTSendNode receiver selector: slot name arguments: { }.
}
].

allRewrittenStatements := OrderedCollection new.
allFieldArguments := structType asClass allSlots collect: [ :slot |
{
(TConstantNode value: slot name asString).
(TSendNode
receiver: aTSendNode receiver
selector: slot name
arguments: { }) } ].

allFieldArguments do: [ :fieldArgs | allRewrittenStatements addAll: (self bindBlock: fieldBlock withArgs: fieldArgs) ]
separatedBy: [ allRewrittenStatements addAll: blockSeparatorStatements ].
allRewrittenStatements := OrderedCollection new.

^ CCompoundStatementNode statements: (allRewrittenStatements collect: [ :e | e asCASTIn: self]).
allFieldArguments
do: [ :fieldArgs |
allRewrittenStatements addAll:
(self bindBlock: fieldBlock withArgs: fieldArgs) ]
separatedBy: [
allRewrittenStatements addAll: blockSeparatorStatements ].

^ CCompoundStatementNode statements:
(allRewrittenStatements collect: [ :e | e asCASTIn: self ])
]

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> generateCASTWithStructNameDo: aTSendNode [
CCodeGeneratorGlobalStructure >> generateCASTWithStructNameDo: aTSendNode [

| argumentName structType rewrittenStatements aBlock |

self assert: aTSendNode arguments size = 1.
self assert: aTSendNode arguments first args size = 1.
self assert: aTSendNode arguments first arguments size = 1.

structType := self structTypeFor: aTSendNode receiver.

aBlock := aTSendNode arguments first.
argumentName := aTSendNode arguments first args first.

rewrittenStatements := self bindBlock: aBlock withArgs: { TConstantNode value: structType asString }.

^ CCompoundStatementNode statements: (rewrittenStatements collect: [ :e | e asCASTIn: self]).

argumentName := aTSendNode arguments first arguments first.

rewrittenStatements := self
bindBlock: aBlock
withArgs:
{ (TConstantNode value: structType asString) }.

^ CCompoundStatementNode statements:
(rewrittenStatements collect: [ :e | e asCASTIn: self ])
]

{ #category : #'C code generator' }
Expand Down Expand Up @@ -346,6 +353,6 @@ CCodeGeneratorGlobalStructure >> structDefDefine: aString [
CCodeGeneratorGlobalStructure >> structTypeFor: structNode [

| nodeType |
nodeType := self typeFor: structNode in: currentMethod.
nodeType := self typeFor: structNode in: self currentMethod.
^ nodeType trimRight: [ :c | { $* . $ } includes: c ]
]
5 changes: 2 additions & 3 deletions smalltalksrc/Slang/CCodeGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Class {
'apiMethods',
'apiVariables',
'kernelReturnTypes',
'currentMethod',
'headerFiles',
'globalVariableUsage',
'useSymbolicConstants',
Expand Down Expand Up @@ -3495,8 +3494,8 @@ CCodeGenerator >> isNode: aNode constantValueWithinRangeOfType: aType [
{ #category : #'C code generator' }
CCodeGenerator >> isNonArgumentImplicitReceiverVariableName: aString [
^ (currentMethod definingClass isNotNil and: [
currentMethod definingClass implicitVariables includes: aString ])
^ (self currentMethod definingClass isNotNil and: [
self currentMethod definingClass implicitVariables includes: aString ])
or: [ (self typeOfVariable: aString) == #implicit ]
]
Expand Down
19 changes: 12 additions & 7 deletions smalltalksrc/VMMaker/ComposedImageReader.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ ComposedImageReader >> readHeaderFromImage: imageFileName [
<var: #file type: #sqImageFile>
<var: #buffer declareC: 'char buffer[255]'>
<var: #header type: #SpurImageHeaderStruct>
| header buffer file |
<var: #headerPtr type: #'SpurImageHeaderStruct *'>

| header buffer file headerPtr |

self simulationOnly: [
buffer := nil.
Expand All @@ -110,10 +112,10 @@ ComposedImageReader >> readHeaderFromImage: imageFileName [

interpreter ioExitWithErrorCode: 1 ].


self readSTONFrom: file into: (self addressOf: header).
headerPtr := self addressOf: header.
self readSTONFrom: file into: headerPtr.

self extractImageVersionFrom: (header imageFormat) into: (self addressOf: header).
self extractImageVersionFrom: (header imageFormat) into: headerPtr.

self sqImageFileClose: file.

Expand Down Expand Up @@ -145,16 +147,19 @@ ComposedImageReader >> readMetadataFromFileName: fullFileName [
<inline: true>
<var: #file type: #sqImageFile>
<var: #metadata type: #ComposedMetadataStruct>
<var: #metadataPointer type: #'ComposedMetadataStruct *'>

| metadata file |
| metadata file metadataPointer |

self simulationOnly: [ metadata := ComposedMetadataStruct new ].

file := self
sqImageFile: fullFileName
Open: 'r'.

self readSTONFrom: file into: (self addressOf: metadata).
"Needed because addressOf: miss the parameter type"
metadataPointer := self addressOf: metadata.
self readSTONFrom: file into: metadataPointer.

self sqImageFileClose: file.

Expand All @@ -175,7 +180,7 @@ ComposedImageReader >> readPermanentSpaceFromImageFile: imageFileName header: aH

<inline: false>
<var: #imageFile type: #sqImageFile>
<var: 'aHeader' type: #SpurImageHeaderStruct>
<var: #aHeader type: #SpurImageHeaderStruct>
<var: #permSpaceMetadata type: #ComposedMetadataStruct>
<var: #bytesRead type: #'size_t'>
<var: #dataSize type: #'size_t'>
Expand Down

0 comments on commit f61f801

Please sign in to comment.