Ver código fonte

BlockClosure >> asCompiledMethod

Allows creating CompiledMethod from a block.
Combined with previous commit's `ClassBuilder >> install:...`
it allows to add dynamic api in runtime using parametrized
block, without needing the `Compiler` to actually compile
Smalltalk source.

(in deployed scenario, there is no Compiler,
but there is a need to "compile" various kind of templates)
Herbert Vojčík 11 anos atrás
pai
commit
3dee9cd106
3 arquivos alterados com 33 adições e 0 exclusões
  1. 11 0
      js/Kernel-Methods.deploy.js
  2. 16 0
      js/Kernel-Methods.js
  3. 6 0
      st/Kernel-Methods.st

+ 11 - 0
js/Kernel-Methods.deploy.js

@@ -11,6 +11,17 @@ return self}, function($ctx1) {$ctx1.fill(self,"applyTo:arguments:",{anObject:an
 }),
 smalltalk.BlockClosure);
 
+smalltalk.addMethod(
+"_asCompiledMethod_",
+smalltalk.method({
+selector: "asCompiledMethod:",
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
return smalltalk.method({selector:aString, fn:self});;
+return self}, function($ctx1) {$ctx1.fill(self,"asCompiledMethod:",{aString:aString}, smalltalk.BlockClosure)})}
+}),
+smalltalk.BlockClosure);
+
 smalltalk.addMethod(
 "_compiledSource",
 smalltalk.method({

+ 16 - 0
js/Kernel-Methods.js

@@ -17,6 +17,22 @@ referencedClasses: []
 }),
 smalltalk.BlockClosure);
 
+smalltalk.addMethod(
+"_asCompiledMethod_",
+smalltalk.method({
+selector: "asCompiledMethod:",
+category: 'converting',
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
return smalltalk.method({selector:aString, fn:self});;
+return self}, function($ctx1) {$ctx1.fill(self,"asCompiledMethod:",{aString:aString}, smalltalk.BlockClosure)})},
+args: ["aString"],
+source: "asCompiledMethod: aString\x0a\x09<return smalltalk.method({selector:aString, fn:self});>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.BlockClosure);
+
 smalltalk.addMethod(
 "_compiledSource",
 smalltalk.method({

+ 6 - 0
st/Kernel-Methods.st

@@ -40,6 +40,12 @@ whileTrue: aBlock
 	<while(self()) {aBlock()}>
 ! !
 
+!BlockClosure methodsFor: 'converting'!
+
+asCompiledMethod: aString
+	<return smalltalk.method({selector:aString, fn:self});>
+! !
+
 !BlockClosure methodsFor: 'error handling'!
 
 on: anErrorClass do: aBlock