Browse Source

- Removes MethodContext >> pc
- Adds MethodContext >> sendIndexes

Nicolas Petton 11 years ago
parent
commit
dc2ff669f3
5 changed files with 46 additions and 80 deletions
  1. 4 46
      js/Compiler-Interpreter.js
  2. 32 16
      js/Kernel-Methods.js
  3. 1 12
      st/Compiler-Interpreter.st
  4. 8 4
      st/Kernel-Methods.st
  5. 1 2
      support/boot.js

+ 4 - 46
js/Compiler-Interpreter.js

@@ -359,7 +359,6 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 return smalltalk.withContext(function($ctx1) { 
 var $1,$2,$3,$4;
 var $1,$2,$3,$4;
 $1=self;
 $1=self;
-_st($1)._pc_(_st(aMethodContext)._pc());
 _st($1)._index_(_st(aMethodContext)._index());
 _st($1)._index_(_st(aMethodContext)._index());
 _st($1)._receiver_(_st(aMethodContext)._receiver());
 _st($1)._receiver_(_st(aMethodContext)._receiver());
 $2=_st($1)._selector_(_st(aMethodContext)._selector());
 $2=_st($1)._selector_(_st(aMethodContext)._selector());
@@ -382,8 +381,8 @@ return _st(self._locals())._at_put_(key,value);
 };
 };
 return self}, function($ctx1) {$ctx1.fill(self,"initializeFromMethodContext:",{aMethodContext:aMethodContext},smalltalk.AIContext)})},
 return self}, function($ctx1) {$ctx1.fill(self,"initializeFromMethodContext:",{aMethodContext:aMethodContext},smalltalk.AIContext)})},
 args: ["aMethodContext"],
 args: ["aMethodContext"],
-source: "initializeFromMethodContext: aMethodContext\x0a\x0a\x09self \x0a\x09\x09pc: aMethodContext pc;\x0a\x09\x09index: aMethodContext index;\x0a\x09\x09receiver: aMethodContext receiver;\x0a\x09\x09selector: aMethodContext selector.\x0a\x09\x09\x0a\x09aMethodContext outerContext ifNotNil: [ :outer |\x0a\x09\x09\x22If the method context is nil, the block was defined in JS, so ignore it\x22\x0a\x09\x09outer methodContext ifNotNil: [\x0a\x09\x09\x09self outerContext: (self class fromMethodContext: aMethodContext outerContext) ].\x0a\x09\x09\x09aMethodContext locals keysAndValuesDo: [ :key :value |\x0a\x09\x09\x09\x09self locals at: key put: value ] ]",
-messageSends: ["pc:", "pc", "index:", "index", "receiver:", "receiver", "selector:", "selector", "ifNotNil:", "outerContext", "methodContext", "outerContext:", "fromMethodContext:", "class", "keysAndValuesDo:", "locals", "at:put:"],
+source: "initializeFromMethodContext: aMethodContext\x0a\x0a\x09self\x0a\x09\x09index: aMethodContext index;\x0a\x09\x09receiver: aMethodContext receiver;\x0a\x09\x09selector: aMethodContext selector.\x0a\x09\x09\x0a\x09aMethodContext outerContext ifNotNil: [ :outer |\x0a\x09\x09\x22If the method context is nil, the block was defined in JS, so ignore it\x22\x0a\x09\x09outer methodContext ifNotNil: [\x0a\x09\x09\x09self outerContext: (self class fromMethodContext: aMethodContext outerContext) ].\x0a\x09\x09\x09aMethodContext locals keysAndValuesDo: [ :key :value |\x0a\x09\x09\x09\x09self locals at: key put: value ] ]",
+messageSends: ["index:", "index", "receiver:", "receiver", "selector:", "selector", "ifNotNil:", "outerContext", "methodContext", "outerContext:", "fromMethodContext:", "class", "keysAndValuesDo:", "locals", "at:put:"],
 referencedClasses: []
 referencedClasses: []
 }),
 }),
 smalltalk.AIContext);
 smalltalk.AIContext);
@@ -684,46 +683,6 @@ referencedClasses: []
 }),
 }),
 smalltalk.AIContext);
 smalltalk.AIContext);
 
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "pc",
-category: 'interpreting',
-fn: function (){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $2,$1;
-$2=self["@pc"];
-if(($receiver = $2) == nil || $receiver == null){
-self["@pc"]=(0);
-$1=self["@pc"];
-} else {
-$1=$2;
-};
-return $1;
-}, function($ctx1) {$ctx1.fill(self,"pc",{},smalltalk.AIContext)})},
-args: [],
-source: "pc\x0a\x09^ pc ifNil: [ pc := 0 ]",
-messageSends: ["ifNil:"],
-referencedClasses: []
-}),
-smalltalk.AIContext);
-
-smalltalk.addMethod(
-smalltalk.method({
-selector: "pc:",
-category: 'interpreting',
-fn: function (anInteger){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-self["@pc"]=anInteger;
-return self}, function($ctx1) {$ctx1.fill(self,"pc:",{anInteger:anInteger},smalltalk.AIContext)})},
-args: ["anInteger"],
-source: "pc: anInteger\x0a\x09pc := anInteger",
-messageSends: [],
-referencedClasses: []
-}),
-smalltalk.AIContext);
-
 smalltalk.addMethod(
 smalltalk.addMethod(
 smalltalk.method({
 smalltalk.method({
 selector: "receiver",
 selector: "receiver",
@@ -1911,7 +1870,6 @@ return self._pop();
 receiver=self._pop();
 receiver=self._pop();
 message=self._messageFromSendNode_arguments_(aNode,_st(args)._reversed());
 message=self._messageFromSendNode_arguments_(aNode,_st(args)._reversed());
 result=self._sendMessage_to_superSend_(message,receiver,_st(aNode)._superSend());
 result=self._sendMessage_to_superSend_(message,receiver,_st(aNode)._superSend());
-_st(self._context())._pc_(_st(_st(self._context())._pc()).__plus((1)));
 $1=_st(_st(aNode)._isCascadeSendNode())._and_((function(){
 $1=_st(_st(aNode)._isCascadeSendNode())._and_((function(){
 return smalltalk.withContext(function($ctx2) {
 return smalltalk.withContext(function($ctx2) {
 return _st(_st(aNode)._isLastChild())._not();
 return _st(_st(aNode)._isLastChild())._not();
@@ -1923,8 +1881,8 @@ self._push_(result);
 };
 };
 return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode,receiver:receiver,args:args,message:message,result:result},smalltalk.ASTInterpreter)})},
 return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode,receiver:receiver,args:args,message:message,result:result},smalltalk.ASTInterpreter)})},
 args: ["aNode"],
 args: ["aNode"],
-source: "visitSendNode: aNode\x0a\x09| receiver args message result |\x0a\x09\x0a\x09args := aNode arguments collect: [ :each | self pop ].\x0a\x09receiver := self pop.\x0a\x09\x0a\x09message := self\x0a\x09\x09messageFromSendNode: aNode\x0a\x09\x09arguments: args reversed.\x0a\x09\x0a\x09result := self sendMessage: message to: receiver superSend: aNode superSend.\x0a\x09\x0a\x09self context pc: self context pc + 1.\x0a\x09\x0a\x09\x22For cascade sends, push the reciever if the send is not the last one\x22\x0a\x09(aNode isCascadeSendNode and: [ aNode isLastChild not ])\x0a\x09\x09ifTrue: [ self push: receiver ]\x0a\x09\x09ifFalse: [ self push: result ]",
-messageSends: ["collect:", "arguments", "pop", "messageFromSendNode:arguments:", "reversed", "sendMessage:to:superSend:", "superSend", "pc:", "context", "+", "pc", "ifTrue:ifFalse:", "and:", "isCascadeSendNode", "not", "isLastChild", "push:"],
+source: "visitSendNode: aNode\x0a\x09| receiver args message result |\x0a\x09\x0a\x09args := aNode arguments collect: [ :each | self pop ].\x0a\x09receiver := self pop.\x0a\x09\x0a\x09message := self\x0a\x09\x09messageFromSendNode: aNode\x0a\x09\x09arguments: args reversed.\x0a\x09\x0a\x09result := self sendMessage: message to: receiver superSend: aNode superSend.\x0a\x09\x0a\x09\x22For cascade sends, push the reciever if the send is not the last one\x22\x0a\x09(aNode isCascadeSendNode and: [ aNode isLastChild not ])\x0a\x09\x09ifTrue: [ self push: receiver ]\x0a\x09\x09ifFalse: [ self push: result ]",
+messageSends: ["collect:", "arguments", "pop", "messageFromSendNode:arguments:", "reversed", "sendMessage:to:superSend:", "superSend", "ifTrue:ifFalse:", "and:", "isCascadeSendNode", "not", "isLastChild", "push:"],
 referencedClasses: []
 referencedClasses: []
 }),
 }),
 smalltalk.ASTInterpreter);
 smalltalk.ASTInterpreter);

+ 32 - 16
js/Kernel-Methods.js

@@ -1608,22 +1608,6 @@ referencedClasses: []
 }),
 }),
 smalltalk.MethodContext);
 smalltalk.MethodContext);
 
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "pc",
-category: 'accessing',
-fn: function (){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-return self.pc;
-return self}, function($ctx1) {$ctx1.fill(self,"pc",{},smalltalk.MethodContext)})},
-args: [],
-source: "pc\x0a\x09<return self.pc>",
-messageSends: [],
-referencedClasses: []
-}),
-smalltalk.MethodContext);
-
 smalltalk.addMethod(
 smalltalk.addMethod(
 smalltalk.method({
 smalltalk.method({
 selector: "printOn:",
 selector: "printOn:",
@@ -1683,6 +1667,38 @@ referencedClasses: []
 }),
 }),
 smalltalk.MethodContext);
 smalltalk.MethodContext);
 
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "sendIndexAt:",
+category: 'accessing',
+fn: function (aSelector){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self.sendIdx[aSelector] || 0;
+return self}, function($ctx1) {$ctx1.fill(self,"sendIndexAt:",{aSelector:aSelector},smalltalk.MethodContext)})},
+args: ["aSelector"],
+source: "sendIndexAt: aSelector\x0a\x09<return self.sendIdx[aSelector] || 0>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.MethodContext);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "sendIndexes",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self.sendIdx;
+return self}, function($ctx1) {$ctx1.fill(self,"sendIndexes",{},smalltalk.MethodContext)})},
+args: [],
+source: "sendIndexes\x0a\x09<return self.sendIdx>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.MethodContext);
+
 smalltalk.addMethod(
 smalltalk.addMethod(
 smalltalk.method({
 smalltalk.method({
 selector: "temps",
 selector: "temps",

+ 1 - 12
st/Compiler-Interpreter.st

@@ -188,8 +188,7 @@ initializeAST
 
 
 initializeFromMethodContext: aMethodContext
 initializeFromMethodContext: aMethodContext
 
 
-	self 
-		pc: aMethodContext pc;
+	self
 		index: aMethodContext index;
 		index: aMethodContext index;
 		receiver: aMethodContext receiver;
 		receiver: aMethodContext receiver;
 		selector: aMethodContext selector.
 		selector: aMethodContext selector.
@@ -242,14 +241,6 @@ interpreter: anInterpreter
 	interpreter := anInterpreter
 	interpreter := anInterpreter
 !
 !
 
 
-pc
-	^ pc ifNil: [ pc := 0 ]
-!
-
-pc: anInteger
-	pc := anInteger
-!
-
 receiver
 receiver
 	^ self localAt: 'self'
 	^ self localAt: 'self'
 !
 !
@@ -673,8 +664,6 @@ visitSendNode: aNode
 	
 	
 	result := self sendMessage: message to: receiver superSend: aNode superSend.
 	result := self sendMessage: message to: receiver superSend: aNode superSend.
 	
 	
-	self context pc: self context pc + 1.
-	
 	"For cascade sends, push the reciever if the send is not the last one"
 	"For cascade sends, push the reciever if the send is not the last one"
 	(aNode isCascadeSendNode and: [ aNode isLastChild not ])
 	(aNode isCascadeSendNode and: [ aNode isLastChild not ])
 		ifTrue: [ self push: receiver ]
 		ifTrue: [ self push: receiver ]

+ 8 - 4
st/Kernel-Methods.st

@@ -580,10 +580,6 @@ outerContext
 	<return self.outerContext || self.homeContext>
 	<return self.outerContext || self.homeContext>
 !
 !
 
 
-pc
-	<return self.pc>
-!
-
 receiver
 receiver
 	<return self.receiver>
 	<return self.receiver>
 !
 !
@@ -598,6 +594,14 @@ selector
 	>
 	>
 !
 !
 
 
+sendIndexAt: aSelector
+	<return self.sendIdx[aSelector] || 0>
+!
+
+sendIndexes
+	<return self.sendIdx>
+!
+
 temps
 temps
 	self deprecatedAPI.
 	self deprecatedAPI.
 	
 	

+ 1 - 2
support/boot.js

@@ -792,7 +792,6 @@ function RuntimeBrik(brikz, st) {
 	function SmalltalkMethodContext(home, setup) {
 	function SmalltalkMethodContext(home, setup) {
 		this.homeContext = home;
 		this.homeContext = home;
 		this.setup       = setup || function() {};
 		this.setup       = setup || function() {};
-		this.pc          = 0;
 	}
 	}
 
 
 	inherits(SmalltalkMethodContext, SmalltalkObject);
 	inherits(SmalltalkMethodContext, SmalltalkObject);
@@ -806,6 +805,7 @@ function RuntimeBrik(brikz, st) {
 		SmalltalkMethodContext.prototype.receiver = null;
 		SmalltalkMethodContext.prototype.receiver = null;
 		SmalltalkMethodContext.prototype.selector = null;
 		SmalltalkMethodContext.prototype.selector = null;
 		SmalltalkMethodContext.prototype.lookupClass = null;
 		SmalltalkMethodContext.prototype.lookupClass = null;
+		SmalltalkMethodContext.prototype.sendIdx = {};
 
 
 		SmalltalkMethodContext.prototype.fill = function(receiver, selector, locals, lookupClass) {
 		SmalltalkMethodContext.prototype.fill = function(receiver, selector, locals, lookupClass) {
 			this.receiver    = receiver;
 			this.receiver    = receiver;
@@ -848,7 +848,6 @@ function RuntimeBrik(brikz, st) {
 
 
 	st.withContext = function(worker, setup) {
 	st.withContext = function(worker, setup) {
 		if(st.thisContext) {
 		if(st.thisContext) {
-            st.thisContext.pc++;
 			return inContext(worker, setup);
 			return inContext(worker, setup);
 		} else {
 		} else {
 			try {
 			try {