Browse Source

add Behavior >> #>> and CompiledMethod >> ast

Nicolas Petton 11 years ago
parent
commit
777244506c
6 changed files with 84 additions and 0 deletions
  1. 18 0
      js/Compiler-AST.deploy.js
  2. 23 0
      js/Compiler-AST.js
  3. 13 0
      js/Kernel-Classes.deploy.js
  4. 18 0
      js/Kernel-Classes.js
  5. 8 0
      st/Compiler-AST.st
  6. 4 0
      st/Kernel-Classes.st

+ 18 - 0
js/Compiler-AST.deploy.js

@@ -1518,3 +1518,21 @@ return false;
 messageSends: []}),
 smalltalk.Object);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "ast",
+fn: function (){
+var self=this;
+function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+_st(_st(self)._source())._ifEmpty_((function(){
+return smalltalk.withContext(function($ctx2) {
+return _st(self)._error_("Method source is empty");
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+$1=_st(_st($Smalltalk())._current())._parse_(_st(self)._source());
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"ast",{},smalltalk.CompiledMethod)})},
+messageSends: ["ifEmpty:", "error:", "source", "parse:", "current"]}),
+smalltalk.CompiledMethod);
+

+ 23 - 0
js/Compiler-AST.js

@@ -2078,3 +2078,26 @@ referencedClasses: []
 }),
 smalltalk.Object);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "ast",
+category: '*Compiler-AST',
+fn: function (){
+var self=this;
+function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+_st(_st(self)._source())._ifEmpty_((function(){
+return smalltalk.withContext(function($ctx2) {
+return _st(self)._error_("Method source is empty");
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+$1=_st(_st($Smalltalk())._current())._parse_(_st(self)._source());
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"ast",{},smalltalk.CompiledMethod)})},
+args: [],
+source: "ast\x0a\x09self source ifEmpty: [ self error: 'Method source is empty' ].\x0a\x09\x0a\x09^ Smalltalk current parse: self source",
+messageSends: ["ifEmpty:", "error:", "source", "parse:", "current"],
+referencedClasses: ["Smalltalk"]
+}),
+smalltalk.CompiledMethod);
+

+ 13 - 0
js/Kernel-Classes.deploy.js

@@ -1,5 +1,18 @@
 smalltalk.addPackage('Kernel-Classes');
 smalltalk.addClass('Behavior', smalltalk.Object, [], 'Kernel-Classes');
+smalltalk.addMethod(
+smalltalk.method({
+selector: ">>",
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(self)._methodAt_(aString);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,">>",{aString:aString},smalltalk.Behavior)})},
+messageSends: ["methodAt:"]}),
+smalltalk.Behavior);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "addCompiledMethod:",

+ 18 - 0
js/Kernel-Classes.js

@@ -1,6 +1,24 @@
 smalltalk.addPackage('Kernel-Classes');
 smalltalk.addClass('Behavior', smalltalk.Object, [], 'Kernel-Classes');
 smalltalk.Behavior.comment="I am the superclass of all class objects.\x0a\x0aI define the protocol for creating instances of a class with `#basicNew` and `#new` (see `boot.js` for class constructors details).\x0a\x0aMy instances know about the subclass/superclass relationships between classes, contain the description that instances are created from,\x0aand hold the method dictionary that's associated with each class.\x0a\x0aI also provides methods for compiling methods, examining the method dictionary, and iterating over the class hierarchy."
+smalltalk.addMethod(
+smalltalk.method({
+selector: ">>",
+category: 'accessing',
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(self)._methodAt_(aString);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,">>",{aString:aString},smalltalk.Behavior)})},
+args: ["aString"],
+source: ">> aString\x0a\x09^ self methodAt: aString",
+messageSends: ["methodAt:"],
+referencedClasses: []
+}),
+smalltalk.Behavior);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "addCompiledMethod:",

+ 8 - 0
st/Compiler-AST.st

@@ -647,3 +647,11 @@ isNode
 	^ false
 ! !
 
+!CompiledMethod methodsFor: '*Compiler-AST'!
+
+ast
+	self source ifEmpty: [ self error: 'Method source is empty' ].
+	
+	^ Smalltalk current parse: self source
+! !
+

+ 4 - 0
st/Kernel-Classes.st

@@ -14,6 +14,10 @@ I also provides methods for compiling methods, examining the method dictionary,
 
 !Behavior methodsFor: 'accessing'!
 
+>> aString
+	^ self methodAt: aString
+!
+
 allInstanceVariableNames
 	| result |
 	result := self instanceVariableNames copy.