compiler/TSemanticAnalyser.st
changeset 15 10a95d798b36
parent 13 97090c2baa33
child 16 17a2d1d9f205
--- a/compiler/TSemanticAnalyser.st	Tue Sep 22 17:43:38 2015 +0100
+++ b/compiler/TSemanticAnalyser.st	Wed Sep 23 22:21:44 2015 +0100
@@ -40,29 +40,69 @@
     ] ifFalse:[ 
         binding := TArgumentBinding name:anRBVariableNode name.
         binding index: (anRBVariableNode parent arguments indexOf: anRBVariableNode)                                
-                       + (anRBVariableNode parent scope isMethodScope ifTrue:[1] ifFalse:[0])     
+                       + (anRBVariableNode parent scope hasSelfArgument ifTrue:[1] ifFalse:[0])     
     ].
     anRBVariableNode parent scope addVariable: binding.
     super visitArgument: anRBVariableNode.
 
     "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-09-2015 / 06:17:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 23-09-2015 / 18:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !TSemanticAnalyser methodsFor:'visitor-double dispatching'!
 
 acceptBlockNode: aBlockNode
-    | scope |
+    | scope binding |
     aBlockNode parent isSpecialFormNode ifTrue:[ 
         scope := TScope node: aBlockNode parent: aBlockNode parent scope
     ] ifFalse:[ 
         scope := TScope node: aBlockNode
     ].
     aBlockNode scope: scope.
+
+    binding := TBlockBinding new.
+    binding parameterTypes: aBlockNode parameterTypes.
+    binding returnType: aBlockNode returnType.
+    aBlockNode binding: binding.
+
     super acceptBlockNode: aBlockNode
 
     "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-09-2015 / 06:16:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 23-09-2015 / 16:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+acceptIfTrueIfFalseNode: node 
+    node arguments first isBlock ifFalse:[ 
+        context reportSemanticError: 'First argument (true block) of ifTrue:ifFalse: special form is not a block'.
+    ] ifTrue:[ 
+        node arguments first arguments notEmptyOrNil ifTrue:[ 
+            context reportSemanticError: 'First argument (true block) of ifTrue::ifFalse: special form may not have any arguments'.
+        ]
+    ].  
+    node arguments second isBlock ifFalse:[ 
+        context reportSemanticError: 'Second argument (false block) of ifTrue:ifFalse: special form is not a block'.
+    ] ifTrue:[ 
+        node arguments second arguments notEmptyOrNil ifTrue:[ 
+            context reportSemanticError: 'Second argument (false block) of ifTrue::ifFalse: special form may not have any arguments'.
+        ]
+    ].  
+
+    ^ self acceptMessageNode: node.
+
+    "Created: / 23-09-2015 / 14:20:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+acceptIfTrueNode: node
+    node arguments first isBlock ifFalse:[ 
+        context reportSemanticError: 'Argument (true block) of ifTrue: special form is not a block'.
+    ] ifTrue:[ 
+        node arguments first arguments notEmptyOrNil ifTrue:[ 
+            context reportSemanticError: 'Argument (true block) of ifTrue: special form may not have any arguments'.
+        ]
+    ].     
+    self acceptMessageNode: node
+
+    "Created: / 23-09-2015 / 14:18:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptLiteralNode: aRBLiteralNode
@@ -89,7 +129,7 @@
 
     scope   := TScope node: aMethodNode.
     bindingForSelf := TArgumentBinding name:'self'.
-    bindingForSelf index: self.
+    bindingForSelf index: 1.
     scope addVariable: bindingForSelf.
 
     aMethodNode scope: scope.
@@ -97,7 +137,7 @@
     super acceptMethodNode: aMethodNode
 
     "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 13-09-2015 / 09:30:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 23-09-2015 / 18:31:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptVariableNode: aVariableNode
@@ -113,6 +153,26 @@
 
     "Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 20-09-2015 / 06:14:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+acceptWhileTrueNode: node
+    node receiver isBlock ifFalse:[ 
+        context reportSemanticError: 'Receiver (condition) of whileTrue: special form is not a block'.
+    ] ifTrue:[ 
+        node receiver arguments notEmptyOrNil ifTrue:[ 
+            context reportSemanticError: 'Receiver (condition) of whileTrue: special form may not have any arguments'.
+        ]
+    ].
+    node arguments first isBlock ifFalse:[ 
+        context reportSemanticError: 'Argument (loop body) of whileTrue: special form is not a block'.
+    ] ifTrue:[ 
+        node arguments first arguments notEmptyOrNil ifTrue:[ 
+            context reportSemanticError: 'Argument (loop body) of whileTrue: special form may not have any arguments'.
+        ]
+    ].
+    super acceptWhileTrueNode: node
+
+    "Created: / 23-09-2015 / 14:10:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !TSemanticAnalyser class methodsFor:'documentation'!