소스 검색

Split the Compiler into 2 classes: AbstractCompiler and Compiler

Nicolas Petton 12 년 전
부모
커밋
622a8fc5d2
4개의 변경된 파일88개의 추가작업 그리고 103개의 파일을 삭제
  1. 2 2
      js/Compiler.deploy.js
  2. 14 14
      js/Compiler.js
  3. 20 39
      js/boot.js
  4. 52 48
      st/Compiler.st

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2 - 2
js/Compiler.deploy.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 14 - 14
js/Compiler.js


+ 20 - 39
js/boot.js

@@ -309,23 +309,9 @@ function Smalltalk(){
 		method.jsSelector = jsSelector;
 	};
 
-	/* Handles Smalltalk message send. Automatically converts undefined to the nil object.
-	   If the receiver does not understand the selector, call its #doesNotUnderstand: method */
-
-	sendWithoutContext = function(receiver, selector, args, klass) {
-		if(receiver == null) {
-			receiver = nil;
-		}
-		var imp = klass ? klass.fn.prototype[selector] : receiver.klass && receiver[selector];
-		return imp
-			? imp.apply(receiver, args)
-			: messageNotUnderstood(receiver, selector, args);
-	};
-
-
 	/* Handles unhandled errors during message sends */
 
-	sendWithContext = function(receiver, selector, args, klass) {
+	st.send = function(receiver, selector, args, klass) {
 		if(st.thisContext) {
 			return withContextSend(receiver, selector, args, klass);
 		} else {
@@ -342,25 +328,21 @@ function Smalltalk(){
 		}
 	};
 
-	/* Same as sendWithoutContext but creates a methodContext. */
-
 	function withContextSend(receiver, selector, args, klass) {
-		var call, context, imp;
+		var call, imp;
 		if(receiver == null) {
 			receiver = nil;
 		}
 		imp = klass ? klass.fn.prototype[selector] : receiver.klass && receiver[selector];
 		if(imp) {
-			context = pushContext(receiver, selector, args);
+			pushContext(receiver, selector, args);
 			call = imp.apply(receiver, args);
-			st.thisContext = context.homeContext;
-			context.homeContext = undefined;
-			st.oldContext = context;
+            popContext();
 			return call;
 		} else {
 			return messageNotUnderstood(receiver, selector, args);
 		}
-	}
+	};
 
 	/* Handles Smalltalk errors. Triggers the registered ErrorHandler 
 	   (See the Smalltalk class ErrorHandler and its subclasses */
@@ -368,7 +350,7 @@ function Smalltalk(){
 	function handleError(error) {
 		st.thisContext = undefined;
 		smalltalk.ErrorHandler._current()._handleError_(error);
-	}
+	};
 
 	/* Handles #dnu: *and* JavaScript method calls.
 	   if the receiver has no klass, we consider it a JS object (outside of the
@@ -434,7 +416,7 @@ function Smalltalk(){
 		}/* else { // this is the default
 			return undefined;
 		}*/
-	}
+	};
 
 	function pushContext(receiver, selector, temps) {
 		var c = st.oldContext, tc = st.thisContext;
@@ -447,7 +429,14 @@ function Smalltalk(){
 		c.selector = selector;
 		c.temps = temps || {};
 		return st.thisContext = c;
-	}
+	};
+
+    function popContext() {
+        var context = st.thisContext;
+        st.thisContext = context.homeContext;
+		context.homeContext = undefined;
+		st.oldContext = context;
+    };
 
 	/* Convert a string to a valid smalltalk selector.
 	   if you modify the following functions, also change String>>asSelector
@@ -499,25 +488,17 @@ function Smalltalk(){
 		return object;
 	};
 
-	/* Toggle deployment mode (no context will be handled during message send */
-	st.setDeploymentMode = function() {
-		st.send = sendWithoutContext;
-	};
-
-	st.setDevelopmentMode = function() {
-		st.send = sendWithContext;
-	}
-
-	/* Set development mode by default */
-	st.setDevelopmentMode();
-}
+	/* Kept for backward compatibility */
+	st.setDeploymentMode = function() {};
+	st.setDevelopmentMode = function() {};
+};
 
 function SmalltalkMethodContext(receiver, selector, temps, home) {
 	this.receiver = receiver;
 	this.selector = selector;
 	this.temps = temps || {};
 	this.homeContext = home;
-}
+};
 
 SmalltalkMethodContext.prototype.copy = function() {
 	var home = this.homeContext;

+ 52 - 48
st/Compiler.st

@@ -782,15 +782,11 @@ visitVariableNode: aNode
 	self visitNode: aNode
 ! !
 
-NodeVisitor subclass: #Compiler
-	instanceVariableNames: 'stream nestedBlocks earlyReturn currentClass currentSelector unknownVariables tempVariables messageSends referencedClasses classReferenced source argVariables'
+NodeVisitor subclass: #AbstractCompiler
+	instanceVariableNames: 'currentClass source'
 	package: 'Compiler'!
 
-!Compiler methodsFor: 'accessing'!
-
-argVariables
-	^argVariables copy
-!
+!AbstractCompiler methodsFor: 'accessing'!
 
 classNameFor: aClass
 	^aClass isMetaclass
@@ -809,17 +805,6 @@ currentClass: aClass
 	currentClass := aClass
 !
 
-knownVariables
-	^self pseudoVariables 
-		addAll: self tempVariables;
-		addAll: self argVariables;
-		yourself
-!
-
-parser
-	^SmalltalkParser new
-!
-
 pseudoVariables
 	^#('self' 'super' 'true' 'false' 'nil' 'thisContext')
 !
@@ -836,17 +821,9 @@ source
 
 source: aString
 	source := aString
-!
-
-tempVariables
-	^tempVariables copy
-!
-
-unknownVariables
-	^unknownVariables copy
 ! !
 
-!Compiler methodsFor: 'compiling'!
+!AbstractCompiler methodsFor: 'compiling'!
 
 compile: aString
 	^self compileNode: (self parse: aString)
@@ -864,12 +841,6 @@ compileExpression: aString
 	^self compileNode: (self parse: self source)
 !
 
-compileNode: aNode
-	stream := '' writeStream.
-	self visit: aNode.
-	^stream contents
-!
-
 eval: aString
 	<return eval(aString)>
 !
@@ -915,6 +886,54 @@ setupClass: aClass
 	<smalltalk.init(aClass)>
 ! !
 
+!AbstractCompiler class methodsFor: 'compiling'!
+
+recompile: aClass
+	aClass methodDictionary do: [:each || method |
+		method := self new load: each source forClass: aClass.
+		method category: each category.
+		aClass addCompiledMethod: method].
+	aClass isMetaclass ifFalse: [self recompile: aClass class]
+!
+
+recompileAll
+	Smalltalk current classes do: [:each |
+		self recompile: each]
+! !
+
+AbstractCompiler subclass: #Compiler
+	instanceVariableNames: 'stream nestedBlocks earlyReturn currentSelector unknownVariables tempVariables messageSends referencedClasses classReferenced argVariables'
+	package: 'Compiler'!
+
+!Compiler methodsFor: 'accessing'!
+
+argVariables
+	^argVariables copy
+!
+
+knownVariables
+	^self pseudoVariables 
+		addAll: self tempVariables;
+		addAll: self argVariables;
+		yourself
+!
+
+tempVariables
+	^tempVariables copy
+!
+
+unknownVariables
+	^unknownVariables copy
+! !
+
+!Compiler methodsFor: 'compiling'!
+
+compileNode: aNode
+	stream := '' writeStream.
+	self visit: aNode.
+	^stream contents
+! !
+
 !Compiler methodsFor: 'initialization'!
 
 initialize
@@ -1421,18 +1440,3 @@ performOptimizations: aBoolean
 	performOptimizations := aBoolean
 ! !
 
-!Compiler class methodsFor: 'compiling'!
-
-recompile: aClass
-	aClass methodDictionary do: [:each || method |
-		method := self new load: each source forClass: aClass.
-		method category: each category.
-		aClass addCompiledMethod: method].
-	aClass isMetaclass ifFalse: [self recompile: aClass class]
-!
-
-recompileAll
-	Smalltalk current classes do: [:each |
-		self recompile: each]
-! !
-

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.