help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Re: STCompiler ignores current namespace change for


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Re: STCompiler ignores current namespace change for var lookup in evals
Date: Tue, 05 Dec 2006 09:51:46 +0100
User-agent: Thunderbird 1.5.0.8 (Macintosh/20061025)


However, I am not sure that I wouldn't prefer the semantic change of putting compilation in the valueWithUnwind (using STCompiler class>>#evaluate:parser:) or removing it entirely.

Why shouldn't an exception during evaluation by the FileInParser (which only happens in RBParser>>#parseDoits AFAICS) halt parsing/loading of a stream without further intervention/resetting by clients of the FileInParser?

This is in fact inconsistent with the C parser; chunks are supposed to be completely independent, so it's true that both compilation and evaluation should be in the valueWithUnwind (using #evaluate:parser:). However, this would make it a little harder to spot bugs in the Smalltalk compiler and parser (as this would not stop the evaluation). For example, I just found out that the Smalltalk parser does not parse _ as assignment the same way the C parser does.

I'm committing the attached patch. It's pretty safe, so we don't need a further RC before 2.3. This will in fact be the last change before 2.3, I might even make the big release later today if I have time. :-)

Paolo
2006-12-05  Paolo Bonzini  <address@hidden>

        * compiler/STCompiler.st: Pass current environment in evaluate:parser:,
        add #compile:asMethodOf:classified:parser:environment: and don't inline
        its functionality elsewhere.
        * compiler/StartCompiler.st: Pass current environment when compiling
        doits.

--- orig/compiler/STCompiler.st
+++ mod/compiler/STCompiler.st
@@ -115,9 +115,9 @@ evaluate: aSequenceNode parser: aParser
        source: nil;
        yourself.
 
-    cm := self new
-       class: UndefinedObject parser: aParser;
-       visitNode: methodNode.
+    cm := self
+       compile: methodNode asMethodOf: UndefinedObject classified: nil
+       parser: aParser environment: Namespace current.
 
     ^nil perform: cm
 ! !
@@ -125,27 +125,34 @@ evaluate: aSequenceNode parser: aParser
 !STCompiler class methodsFor: 'compilation'!
 
 compile: methodNode for: aBehavior classified: aString parser: aParser
-    | cm |
-    cm := self new
-       class: aBehavior parser: aParser;
-       visitNode: methodNode.
-
-    cm methodCategory: aString.
-
     ^aBehavior
        addSelector: methodNode selector
-       withMethod: cm
+       withMethod: (self
+                       compile: methodNode
+                       asMethodOf: aBehavior
+                       classified: aString
+                       parser: aParser)
 !
 
 compile: methodNode asMethodOf: aBehavior classified: aString parser: aParser
-    | cm |
-    cm := self new
-       class: aBehavior parser: aParser;
-       visitNode: methodNode.
-
-    cm methodCategory: aString.
-
-    ^cm
+    ^self
+       compile: methodNode
+       asMethodOf: aBehavior
+       classified: aString
+       parser: aParser
+       environment: nil!
+
+compile: methodNode asMethodOf: aBehavior classified: aString parser: aParser
+    environment: aNamespace
+
+    | compiler |
+    compiler := self new.
+    compiler class: aBehavior parser: aParser.
+    aNamespace isNil ifFalse: [ compiler addPool: aNamespace ].
+
+    ^(compiler visitNode: methodNode)
+       methodCategory: aString;
+       yourself
 ! !
 
 !STCompiler methodsFor: 'private'!
@@ -168,6 +175,10 @@ addLiteral: literal
     ^symTable addLiteral: literal
 !
 
+addPool: aNamespace
+    ^symTable addPool: aNamespace
+!
+
 bytecodesFor: aBlockNode
     ^self bytecodesFor: aBlockNode atEndDo: []
 !
@@ -708,7 +719,7 @@ compileSendToSuper: aNode
     aNode arguments do: [ :each | each acceptVisitor: self ].
     self pushLiteral: destClass superclass.
     VMSpecialSelectors at: aNode selector ifPresent: [ :idx |
-       self compileByte: SendSuperImmediate arg: idx.
+       self compileByte: SendImmediateSuper arg: idx.
        ^aNode
     ].
 


--- orig/compiler/StartCompiler.st
+++ mod/compiler/StartCompiler.st
@@ -116,7 +116,8 @@ evaluate: node
        compile: node
        asMethodOf: evalFor class
        classified: nil
-       parser: self.
+       parser: self
+       environment: Namespace current.
 
     [ lastResult := evalFor perform: method ] valueWithUnwind.
     ^curClass notNil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]