compiler/PPCCodeGenerator.st
changeset 459 4751c407bb40
parent 452 9f4558b3be66
child 460 87a3d30ab570
child 464 f6d77fee9811
--- a/compiler/PPCCodeGenerator.st	Sun May 10 06:28:36 2015 +0100
+++ b/compiler/PPCCodeGenerator.st	Tue May 12 01:24:03 2015 +0100
@@ -11,6 +11,12 @@
 
 !PPCCodeGenerator class methodsFor:'as yet unclassified'!
 
+new
+    ^ self basicNew
+        initialize;
+        yourself 
+!
+
 on: aPPCCompiler
     ^ self new 
         compiler: aPPCCompiler;
@@ -21,6 +27,10 @@
 
 compiler: aPPCCompiler
     compiler := aPPCCompiler 
+!
+
+guards
+    ^ arguments guards
 ! !
 
 !PPCCodeGenerator methodsFor:'hooks'!
@@ -48,7 +58,7 @@
 
 addGuard: node
     |  guard firsts id |
-    (arguments guards not or: [(guard := PPCGuard on: node) makesSense not]) ifTrue: [ ^ self].
+    (self guards not or: [(guard := PPCGuard on: node) makesSense not]) ifTrue: [ ^ self].
 
     id := compiler idFor: node.
     firsts := node firstSetWithTokens.
@@ -245,12 +255,6 @@
         ^ nil
     ].
 
-    "TODO JK: this is is wrong,.. to tired now to fix this :("
-"	(self isCached: child) ifTrue: [ 
-        node replace: child with: (self cachedValue: child).
-        ^ nil
-    ]. 
-"
     ^ self visit: child.
 !
 
@@ -268,7 +272,7 @@
         If we want to compile in guard and the choice starts with trimming token, 
         we should invoke the whitespace parser
     "
-    (arguments guards and: [ firsts allSatisfy: [ :e | e isTrimmingTokenNode ] ]) ifTrue: [  
+    (self guards and: [ firsts allSatisfy: [ :e | e isTrimmingTokenNode ] ]) ifTrue: [  
         self compileTokenWhitespace: firsts anyOne.
         whitespaceConsumed := true.
     ].
@@ -277,7 +281,7 @@
         child := node children at: idx.
         allowGuard := whitespaceConsumed.
                                 
-        (allowGuard and: [arguments guards and: [ (guard := PPCGuard on: child) makesSense ]]) ifTrue: [         
+        (allowGuard and: [self guards and: [ (guard := PPCGuard on: child) makesSense ]]) ifTrue: [         
             guard id: (compiler idFor: guard prefixed: #guard).
             guard compileGuard: compiler.
             compiler add: ' ifTrue: [ '.
@@ -397,6 +401,8 @@
     compiler smartRestore: node child from: mementoVar.
 
     compiler add: '^ error ifFalse: [ self error ] ifTrue: [ self clearError. nil ]'.
+
+    "Modified: / 05-05-2015 / 14:29:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 visitOptionalNode: node
@@ -511,13 +517,16 @@
 !
 
 visitStarAnyNode: node
+    | retvalVar sizeVar |
 
-    compiler addVariable: 'retval size'.
-    compiler add: 'size := context size - context position.'.
-    compiler add: 'retval := Array new: size.'.
-    compiler add: '(1 to: size) do: [ :e | retval at: e put: context next ].'.
-    compiler add: '^ retval'.
+    retvalVar := compiler allocateReturnVariable.
+    sizeVar := compiler allocateTemporaryVariableNamed: 'size'.  
+    compiler add: sizeVar , ' := context size - context position.'.
+    compiler add: retvalVar,' := Array new: ',sizeVar,'.'.
+    compiler add: '(1 to: ',sizeVar,') do: [ :e | ',retvalVar,' at: e put: context next ].'.
+    compiler codeReturn.
     
+    "Modified: / 05-05-2015 / 14:13:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 visitStarCharSetPredicateNode: node