Browse Source

Stop using fn.

Herby Vojčík 2 months ago
parent
commit
c0d02f9d64
4 changed files with 46 additions and 70 deletions
  1. 13 39
      lang/src/Compiler-Core.js
  2. 1 4
      lang/src/Compiler-Core.st
  3. 27 22
      lang/src/Kernel-Methods.js
  4. 5 5
      lang/src/Kernel-Methods.st

File diff suppressed because it is too large
+ 13 - 39
lang/src/Compiler-Core.js


+ 1 - 4
lang/src/Compiler-Core.st

@@ -168,17 +168,14 @@ ast: aString forClass: aClass protocol: anotherString
 !
 
 compile: aString forClass: aClass protocol: anotherString
-	| compilationResult result pragmas closure closureFactory |
+	| compilationResult result pragmas closureFactory |
 	compilationResult :=
 		self compileSource: aString forClass: aClass protocol: anotherString.
 	pragmas := compilationResult removeKey: #pragmas.
-	closure := (compilationResult removeKey: #fn ifAbsent: [])
-		ifNotNil: [ :js | self eval: js forPackage: self currentPackage ].
 	closureFactory := (compilationResult removeKey: #instantiateFn ifAbsent: [])
 		ifNotNil: [ :js | self eval: js forPackage: self currentPackage ].
 	result := Smalltalk core method: compilationResult.
 	result protocol: anotherString; pragmas: pragmas.
-	closure ifNotNil: [ result fn: closure ].
 	closureFactory ifNotNil: [ result instantiateFn: closureFactory ].
 	^ result
 !

+ 27 - 22
lang/src/Kernel-Methods.js

@@ -1004,25 +1004,6 @@ return $self.fn;
 }; }),
 $globals.CompiledMethod);
 
-$core.addMethod(
-$core.method({
-selector: "fn:",
-protocol: "accessing",
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aBlock"],
-source: "fn: aBlock\x0a\x09fn := aBlock",
-referencedClasses: [],
-//>>excludeEnd("ide");
-pragmas: [],
-messageSends: []
-}, function ($class, $globals){ return function (aBlock){
-var self=this,$self=this;
-$self.fn=aBlock;
-return self;
-
-}; }),
-$globals.CompiledMethod);
-
 $core.addMethod(
 $core.method({
 selector: "instantiateFn",
@@ -1060,6 +1041,30 @@ return self;
 }; }),
 $globals.CompiledMethod);
 
+$core.addMethod(
+$core.method({
+selector: "instantiatedFn",
+protocol: "evaluating",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "instantiatedFn\x0a\x09<inlineJS: 'return $self.instantiateFn($self.methodClass, $globals)'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [["inlineJS:", ["return $self.instantiateFn($self.methodClass, $globals)"]]],
+messageSends: []
+}, function ($class, $globals){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $self.instantiateFn($self.methodClass, $globals);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"instantiatedFn",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.CompiledMethod);
+
 $core.addMethod(
 $core.method({
 selector: "isCompiledMethod",
@@ -1442,17 +1447,17 @@ selector: "sendTo:arguments:",
 protocol: "evaluating",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject", "aCollection"],
-source: "sendTo: anObject arguments: aCollection\x0a\x09^ self fn applyTo: anObject arguments: aCollection",
+source: "sendTo: anObject arguments: aCollection\x0a\x09^ self instantiatedFn applyTo: anObject arguments: aCollection",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["applyTo:arguments:", "fn"]
+messageSends: ["applyTo:arguments:", "instantiatedFn"]
 }, function ($class, $globals){ return function (anObject,aCollection){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($self._fn())._applyTo_arguments_(anObject,aCollection);
+return $recv($self._instantiatedFn())._applyTo_arguments_(anObject,aCollection);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"sendTo:arguments:",{anObject:anObject,aCollection:aCollection})});
 //>>excludeEnd("ctx");

+ 5 - 5
lang/src/Kernel-Methods.st

@@ -241,10 +241,6 @@ fn
 	^ fn
 !
 
-fn: aBlock
-	fn := aBlock
-!
-
 instantiateFn
 	^ instantiateFn
 !
@@ -351,8 +347,12 @@ defaultProtocol
 
 !CompiledMethod methodsFor: 'evaluating'!
 
+instantiatedFn
+	<inlineJS: 'return $self.instantiateFn($self.methodClass, $globals)'>
+!
+
 sendTo: anObject arguments: aCollection
-	^ self fn applyTo: anObject arguments: aCollection
+	^ self instantiatedFn applyTo: anObject arguments: aCollection
 ! !
 
 !CompiledMethod methodsFor: 'testing'!