Преглед изворни кода

Browser: do not step by step compilation yourself.

Herby Vojčík пре 6 година
родитељ
комит
00175e32e3
2 измењених фајлова са 35 додато и 50 уклоњено
  1. 31 41
      src/IDE.js
  2. 4 9
      src/IDE.st

+ 31 - 41
src/IDE.js

@@ -3215,7 +3215,7 @@ var compiler,package_,method,compiledSource,source,node;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$4,$3,$8,$7,$6,$5,$9,$receiver;
+var $1,$2,$3,$5,$4,$9,$8,$7,$6,$receiver;
 var $early={};
 try {
 source=$recv($self["@sourceArea"])._val();
@@ -3226,72 +3226,61 @@ $self["@selectedProtocol"];
 } else {
 $1;
 }
-compiler=$recv($globals.Compiler)._new();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["new"]=1;
-//>>excludeEnd("ctx");
-$recv(compiler)._source_(source);
 $recv((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-node=$recv(compiler)._parse_(source);
-return node;
+return $recv((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
-}))._on_do_($globals.ParseError,(function(e){
+$2=$recv($globals.Compiler)._new();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
+$ctx3.sendIdx["new"]=1;
 //>>excludeEnd("ctx");
-$2="PARSE ERROR: ".__comma($recv(e)._messageText());
+method=$recv($2)._install_forClass_protocol_(source,aClass,$self["@selectedProtocol"]);
+return method;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx[","]=1;
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)});
 //>>excludeEnd("ctx");
-throw $early=[$recv($globals.Terminal)._alert_($2)];
+}))._on_do_($globals.ParseError,(function(e){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1,3)});
+return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
-}));
+$3="PARSE ERROR: ".__comma($recv(e)._messageText());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["on:do:"]=1;
+$ctx3.sendIdx[","]=1;
 //>>excludeEnd("ctx");
-package_=$recv(aClass)._packageOfProtocol_($self["@selectedProtocol"]);
-$recv((function(){
+throw $early=[$recv($globals.Terminal)._alert_($3)];
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
+}, function($ctx3) {$ctx3.fillBlock({e:e},$ctx2,4)});
 //>>excludeEnd("ctx");
-compiledSource=$recv(compiler)._compileNode_forClass_package_(node,aClass,package_);
-return compiledSource;
+}));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
 //>>excludeEnd("ctx");
 }))._on_do_($globals.UnknownVariableError,(function(e){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$4=$recv(e)._variableName();
+$5=$recv(e)._variableName();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["variableName"]=1;
 //>>excludeEnd("ctx");
-$3=$recv($globals.Platform)._includesGlobal_($4);
-if(!$core.assert($3)){
-$8=$recv(e)._variableName();
+$4=$recv($globals.Platform)._includesGlobal_($5);
+if(!$core.assert($4)){
+$9=$recv(e)._variableName();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["variableName"]=2;
 //>>excludeEnd("ctx");
-$7="Declare '".__comma($8);
-$6=$recv($7).__comma("' as instance variable?");
+$8="Declare '".__comma($9);
+$7=$recv($8).__comma("' as instance variable?");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx[","]=2;
 //>>excludeEnd("ctx");
-$5=$recv($globals.Terminal)._confirm_($6);
-if($core.assert($5)){
-$9=$recv($globals.Environment)._new();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx["new"]=2;
-//>>excludeEnd("ctx");
-$recv($9)._addInstVarNamed_to_($recv(e)._variableName(),aClass);
+$6=$recv($globals.Terminal)._confirm_($7);
+if($core.assert($6)){
+$recv($recv($globals.Environment)._new())._addInstVarNamed_to_($recv(e)._variableName(),aClass);
 throw $early=[$self._compileMethodDefinitionFor_(aClass)];
 } else {
 throw $early=[nil];
@@ -3301,8 +3290,9 @@ throw $early=[nil];
 }, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1,5)});
 //>>excludeEnd("ctx");
 }));
-method=$recv(compiler)._eval_forPackage_(compiledSource,package_);
-$recv($recv($globals.ClassBuilder)._new())._installMethod_forClass_protocol_(method,aClass,$self["@selectedProtocol"]);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["on:do:"]=1;
+//>>excludeEnd("ctx");
 $self._updateMethodsList();
 $self._selectMethod_(method);
 return self;
@@ -3314,10 +3304,10 @@ catch(e) {if(e===$early)return e[0]; throw e}
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aClass"],
-source: "compileMethodDefinitionFor: aClass\x0a\x09| compiler package method compiledSource source node |\x0a\x09source := sourceArea val.\x0a\x09selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].\x0a\x09compiler := Compiler new.\x0a\x09compiler source: source.\x0a\x09[ node := compiler parse: source ]\x0a\x09on: ParseError do: [ :e |\x0a\x09^ Terminal alert: 'PARSE ERROR: ', e messageText ].\x0a\x09package := aClass packageOfProtocol: selectedProtocol.\x0a\x09[ compiledSource := compiler compileNode: node forClass: aClass package: package ]\x0a\x09on: UnknownVariableError do: [ :e |\x0a\x09\x09\x22Do not try to redeclare javascript's objects\x22\x0a\x09\x09(Platform includesGlobal: e variableName) ifFalse: [\x0a\x09\x09(Terminal confirm: 'Declare ''', e variableName, ''' as instance variable?') ifFalse: [ ^ nil ] ifTrue: [\x0a\x09\x09\x09Environment new addInstVarNamed: e variableName to: aClass.\x0a\x09\x09\x09^ self compileMethodDefinitionFor: aClass ]] ].\x0a\x09method := compiler eval: compiledSource forPackage: package.\x0a\x09ClassBuilder new installMethod: method forClass: aClass protocol: selectedProtocol.\x0a\x09self updateMethodsList.\x0a\x09self selectMethod: method",
-referencedClasses: ["Compiler", "ParseError", "Terminal", "UnknownVariableError", "Platform", "Environment", "ClassBuilder"],
+source: "compileMethodDefinitionFor: aClass\x0a\x09| compiler package method compiledSource source node |\x0a\x09source := sourceArea val.\x0a\x09selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].\x0a\x09[[ method := Compiler new\x0a\x09\x09install: source forClass: aClass protocol: selectedProtocol ]\x0a\x09on: ParseError do: [ :e |\x0a\x09\x09^ Terminal alert: 'PARSE ERROR: ', e messageText ]]\x0a\x09on: UnknownVariableError do: [ :e |\x0a\x09\x09\x22Do not try to redeclare javascript's objects\x22\x0a\x09\x09(Platform includesGlobal: e variableName) ifFalse: [\x0a\x09\x09(Terminal confirm: 'Declare ''', e variableName, ''' as instance variable?') ifFalse: [ ^ nil ] ifTrue: [\x0a\x09\x09\x09Environment new addInstVarNamed: e variableName to: aClass.\x0a\x09\x09\x09^ self compileMethodDefinitionFor: aClass ] ] ].\x0a\x09self updateMethodsList.\x0a\x09self selectMethod: method",
+referencedClasses: ["Compiler", "ParseError", "Terminal", "UnknownVariableError", "Platform", "Environment"],
 //>>excludeEnd("ide");
-messageSends: ["val", "ifNil:", "protocol", "new", "source:", "on:do:", "parse:", "alert:", ",", "messageText", "packageOfProtocol:", "compileNode:forClass:package:", "ifFalse:", "includesGlobal:", "variableName", "ifFalse:ifTrue:", "confirm:", "addInstVarNamed:to:", "compileMethodDefinitionFor:", "eval:forPackage:", "installMethod:forClass:protocol:", "updateMethodsList", "selectMethod:"]
+messageSends: ["val", "ifNil:", "protocol", "on:do:", "install:forClass:protocol:", "new", "alert:", ",", "messageText", "ifFalse:", "includesGlobal:", "variableName", "ifFalse:ifTrue:", "confirm:", "addInstVarNamed:to:", "compileMethodDefinitionFor:", "updateMethodsList", "selectMethod:"]
 }),
 $globals.Browser);
 

+ 4 - 9
src/IDE.st

@@ -817,21 +817,16 @@ compileMethodDefinitionFor: aClass
 	| compiler package method compiledSource source node |
 	source := sourceArea val.
 	selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].
-	compiler := Compiler new.
-	compiler source: source.
-	[ node := compiler parse: source ]
+	[[ method := Compiler new
+		install: source forClass: aClass protocol: selectedProtocol ]
 	on: ParseError do: [ :e |
-	^ Terminal alert: 'PARSE ERROR: ', e messageText ].
-	package := aClass packageOfProtocol: selectedProtocol.
-	[ compiledSource := compiler compileNode: node forClass: aClass package: package ]
+		^ Terminal alert: 'PARSE ERROR: ', e messageText ]]
 	on: UnknownVariableError do: [ :e |
 		"Do not try to redeclare javascript's objects"
 		(Platform includesGlobal: e variableName) ifFalse: [
 		(Terminal confirm: 'Declare ''', e variableName, ''' as instance variable?') ifFalse: [ ^ nil ] ifTrue: [
 			Environment new addInstVarNamed: e variableName to: aClass.
-			^ self compileMethodDefinitionFor: aClass ]] ].
-	method := compiler eval: compiledSource forPackage: package.
-	ClassBuilder new installMethod: method forClass: aClass protocol: selectedProtocol.
+			^ self compileMethodDefinitionFor: aClass ] ] ].
 	self updateMethodsList.
 	self selectMethod: method
 !