3 Commits 8177ea7ac4 ... ba64716de3

Author SHA1 Message Date
  Herby Vojčík ba64716de3 Performance optimizations. 4 years ago
  Herby Vojčík 752127ddfe Formatting. 4 years ago
  Herby Vojčík 25dc722d47 parser: Inline sequences. 4 years ago

File diff suppressed because it is too large
+ 179 - 243
lang/base/parser.js


+ 12 - 18
lang/base/parser.pegjs

@@ -4,6 +4,10 @@
 	function newNode(nodeClass) {
 		return nodeClass._new()._location_(location())._source_(text());
 	}
+
+	function newSequenceNode(nodeClass, temps, statements) {
+		return newNode(nodeClass)._temps_(temps || [])._dagChildren_(statements || []);
+	}
 }
 
 start = method
@@ -155,7 +159,7 @@ assignment = variable:variable ws ':=' ws expression:expression {
 ret = '^' ws expression:expression {
 	return newNode($globals.ReturnNode)._dagChildren_([expression]);
 }
-  
+
 temps = '|' vars:(ws variable:identifier {return variable;})* ws '|' {
 	return vars;
 }
@@ -178,20 +182,10 @@ wsStatements =
 	} /
 	expressions:wsExpressions? {return expressions || [];}
 
-wsSequenceWs = aPragmas:wsPragmas? ws temps:temps? zPragmas:wsPragmas? statements:wsStatements? maybeDotsWs {
-	return [newNode($globals.SequenceNode)
-		._temps_(temps || [])
-		._dagChildren_(statements || []), (aPragmas || []).concat(zPragmas || [])];
-}
-
-wsBlockSequenceWs = ws temps:temps? statements:wsStatements? maybeDotsWs {
-	return newNode($globals.BlockSequenceNode)
-		._temps_(temps || [])
-		._dagChildren_(statements || []);
-}
-
-block = '[' params:wsBlockParamList? sequence:wsBlockSequenceWs ']' {
-	return newNode($globals.BlockNode)._parameters_(params || [])._dagChildren_([sequence]);
+block = '[' params:wsBlockParamList? ws temps:temps? statements:wsStatements? maybeDotsWs ']' {
+	return newNode($globals.BlockNode)
+		._parameters_(params || [])
+		._dagChildren_([newSequenceNode($globals.BlockSequenceNode, temps, statements)]);
 }
 
 operand = reference / literal / subexpression
@@ -247,12 +241,12 @@ cascade =
 
 method =
 	pattern:(wsKeywordPattern / wsBinaryPattern / wsUnaryPattern)
-	sequence:wsSequenceWs {
+	aPragmas:wsPragmas? ws temps:temps? zPragmas:wsPragmas? statements:wsStatements? maybeDotsWs {
 		return newNode($globals.MethodNode)
 			._selector_(pattern[0])
 			._arguments_(pattern[1])
-			._pragmas_(sequence[1])
-			._dagChildren_([sequence[0]]);
+			._pragmas_((aPragmas || []).concat(zPragmas || []))
+			._dagChildren_([newSequenceNode($globals.SequenceNode, temps, statements)]);
 	}
 
 associationSend =

+ 8 - 14
lang/src/Compiler-AST.js

@@ -1558,34 +1558,28 @@ selector: "sequenceNode",
 protocol: "accessing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "sequenceNode\x0a\x09self dagChildren do: [ :each |\x0a\x09\x09each isSequenceNode ifTrue: [ ^ each ] ].\x0a\x09\x09\x0a\x09^ nil",
+source: "sequenceNode\x0a\x09^ self dagChildren detect: [ :one | one isSequenceNode ] ifNone: [ nil ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["do:", "dagChildren", "ifTrue:", "isSequenceNode"]
+messageSends: ["detect:ifNone:", "dagChildren", "isSequenceNode"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1;
-var $early={};
-try {
-$recv($self._dagChildren())._do_((function(each){
+return $recv($self._dagChildren())._detect_ifNone_((function(one){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$1=$recv(each)._isSequenceNode();
-if($core.assert($1)){
-throw $early=[each];
-}
+return $recv(one)._isSequenceNode();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
+}, function($ctx2) {$ctx2.fillBlock({one:one},$ctx1,1)});
 //>>excludeEnd("ctx");
-}));
+}),(function(){
 return nil;
-}
-catch(e) {if(e===$early)return e[0]; throw e}
+
+}));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"sequenceNode",{})});
 //>>excludeEnd("ctx");

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

@@ -387,10 +387,7 @@ sendIndexes: aDictionary
 !
 
 sequenceNode
-	self dagChildren do: [ :each |
-		each isSequenceNode ifTrue: [ ^ each ] ].
-		
-	^ nil
+	^ self dagChildren detect: [ :one | one isSequenceNode ] ifNone: [ nil ]
 ! !
 
 !MethodNode methodsFor: 'visiting'!

+ 9 - 16
lang/src/Compiler-Core.js

@@ -1165,7 +1165,7 @@ selector: "wrappedSourceOf:",
 protocol: "private",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRMethod"],
-source: "wrappedSourceOf: anIRMethod\x0a\x09anIRMethod attachments\x0a\x09\x09ifEmpty: [ ^\x0a\x09\x09\x09'(function ($methodClass){ return ',\x0a\x09\x09\x09anIRMethod compiledSource,\x0a\x09\x09\x09'; })' ]\x0a\x09\x09ifNotEmpty: [ :attachments | ^ \x0a\x09\x09\x09'(function ($methodClass){ return (function(method){Object.defineProperty(method,\x22a$atx\x22,{enumerable:false,configurable:true,writable:true,value:',\x0a\x09\x09\x09attachments asJavaScriptSource,\x0a\x09\x09\x09'});return method})(',\x0a\x09\x09\x09anIRMethod compiledSource,\x0a\x09\x09\x09'); })' ]",
+source: "wrappedSourceOf: anIRMethod\x0a\x09^ anIRMethod attachments\x0a\x09\x09ifEmpty: [\x0a\x09\x09\x09'(function ($methodClass){ return ',\x0a\x09\x09\x09anIRMethod compiledSource,\x0a\x09\x09\x09'; })' ]\x0a\x09\x09ifNotEmpty: [ :attachments |\x0a\x09\x09\x09'(function ($methodClass){ return (function(method){Object.defineProperty(method,\x22a$atx\x22,{enumerable:false,configurable:true,writable:true,value:',\x0a\x09\x09\x09attachments asJavaScriptSource,\x0a\x09\x09\x09'});return method})(',\x0a\x09\x09\x09anIRMethod compiledSource,\x0a\x09\x09\x09'); })' ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
@@ -1175,26 +1175,23 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $3,$2,$1,$6,$5,$4;
-var $early={};
-try {
-$recv($recv(anIRMethod)._attachments())._ifEmpty_ifNotEmpty_((function(){
+var $2,$1,$4,$3;
+return $recv($recv(anIRMethod)._attachments())._ifEmpty_ifNotEmpty_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$3=$recv(anIRMethod)._compiledSource();
+$2=$recv(anIRMethod)._compiledSource();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["compiledSource"]=1;
 //>>excludeEnd("ctx");
-$2="(function ($methodClass){ return ".__comma($3);
+$1="(function ($methodClass){ return ".__comma($2);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx[","]=2;
 //>>excludeEnd("ctx");
-$1=$recv($2).__comma("; })");
+return $recv($1).__comma("; })");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx[","]=1;
 //>>excludeEnd("ctx");
-throw $early=[$1];
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -1202,26 +1199,22 @@ throw $early=[$1];
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$6=$recv("(function ($methodClass){ return (function(method){Object.defineProperty(method,\x22a$atx\x22,{enumerable:false,configurable:true,writable:true,value:".__comma($recv(attachments)._asJavaScriptSource())).__comma("});return method})(");
+$4=$recv("(function ($methodClass){ return (function(method){Object.defineProperty(method,\x22a$atx\x22,{enumerable:false,configurable:true,writable:true,value:".__comma($recv(attachments)._asJavaScriptSource())).__comma("});return method})(");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx[","]=5;
 //>>excludeEnd("ctx");
-$5=$recv($6).__comma($recv(anIRMethod)._compiledSource());
+$3=$recv($4).__comma($recv(anIRMethod)._compiledSource());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx[","]=4;
 //>>excludeEnd("ctx");
-$4=$recv($5).__comma("); })");
+return $recv($3).__comma("); })");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx[","]=3;
 //>>excludeEnd("ctx");
-throw $early=[$4];
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({attachments:attachments},$ctx1,2)});
 //>>excludeEnd("ctx");
 }));
-return self;
-}
-catch(e) {if(e===$early)return e[0]; throw e}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"wrappedSourceOf:",{anIRMethod:anIRMethod})});
 //>>excludeEnd("ctx");

+ 3 - 3
lang/src/Compiler-Core.st

@@ -289,12 +289,12 @@ basicParse: aString
 !
 
 wrappedSourceOf: anIRMethod
-	anIRMethod attachments
-		ifEmpty: [ ^
+	^ anIRMethod attachments
+		ifEmpty: [
 			'(function ($methodClass){ return ',
 			anIRMethod compiledSource,
 			'; })' ]
-		ifNotEmpty: [ :attachments | ^ 
+		ifNotEmpty: [ :attachments |
 			'(function ($methodClass){ return (function(method){Object.defineProperty(method,"a$atx",{enumerable:false,configurable:true,writable:true,value:',
 			attachments asJavaScriptSource,
 			'});return method})(',

+ 19 - 27
lang/src/Compiler-IR.js

@@ -105,20 +105,18 @@ selector: "aliasTemporally:",
 protocol: "visiting",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aCollection"],
-source: "aliasTemporally: aCollection\x0a\x09\x22https://lolg.it/amber/amber/issues/296\x0a\x09\x0a\x09If a node is aliased, all preceding ones are aliased as well.\x0a\x09The tree is iterated twice. First we get the aliasing dependency,\x0a\x09then the aliasing itself is done\x22\x0a\x0a\x09| threshold shouldAlias |\x0a\x09threshold := aCollection reversed\x0a\x09\x09detect: [ :each | each subtreeNeedsAliasing ]\x0a\x09\x09ifNone: [ ^ self visitAll: aCollection ].\x0a\x0a\x09shouldAlias := true.\x0a\x09^ aCollection collect: [ :each |\x0a\x09\x09shouldAlias\x0a\x09\x09\x09ifTrue: [ each == threshold ifTrue: [ shouldAlias := false ]. self alias: each ]\x0a\x09\x09\x09ifFalse: [ self visit: each ] ]",
+source: "aliasTemporally: aCollection\x0a\x09\x22https://lolg.it/amber/amber/issues/296\x0a\x09\x0a\x09If a node is aliased, all preceding ones are aliased as well.\x0a\x09The tree is iterated twice. First we get the aliasing dependency,\x0a\x09then the aliasing itself is done\x22\x0a\x0a\x09| threshold shouldAlias |\x0a\x09threshold := aCollection reversed\x0a\x09\x09detect: [ :each | each subtreeNeedsAliasing ] ifNone: [ nil ].\x0a\x09threshold ifNil: [ ^ self visitAll: aCollection ].\x0a\x0a\x09shouldAlias := true.\x0a\x09^ aCollection collect: [ :each |\x0a\x09\x09shouldAlias\x0a\x09\x09\x09ifTrue: [ each == threshold ifTrue: [ shouldAlias := false ]. self alias: each ]\x0a\x09\x09\x09ifFalse: [ self visit: each ] ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["detect:ifNone:", "reversed", "subtreeNeedsAliasing", "visitAll:", "collect:", "ifTrue:ifFalse:", "ifTrue:", "==", "alias:", "visit:"]
+messageSends: ["detect:ifNone:", "reversed", "subtreeNeedsAliasing", "ifNil:", "visitAll:", "collect:", "ifTrue:ifFalse:", "ifTrue:", "==", "alias:", "visit:"]
 }, function ($methodClass){ return function (aCollection){
 var self=this,$self=this;
 var threshold,shouldAlias;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2;
-var $early={};
-try {
+var $1,$2,$3,$receiver;
 threshold=$recv($recv(aCollection)._reversed())._detect_ifNone_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
@@ -128,23 +126,24 @@ return $recv(each)._subtreeNeedsAliasing();
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
 //>>excludeEnd("ctx");
 }),(function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-throw $early=[$self._visitAll_(aCollection)];
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
-//>>excludeEnd("ctx");
+return nil;
+
 }));
+$1=threshold;
+if(($receiver = $1) == null || $receiver.a$nil){
+return $self._visitAll_(aCollection);
+} else {
+$1;
+}
 shouldAlias=true;
 return $recv(aCollection)._collect_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$1=shouldAlias;
-if($core.assert($1)){
-$2=$recv(each).__eq_eq(threshold);
+$2=shouldAlias;
 if($core.assert($2)){
+$3=$recv(each).__eq_eq(threshold);
+if($core.assert($3)){
 shouldAlias=false;
 shouldAlias;
 }
@@ -153,11 +152,9 @@ return $self._alias_(each);
 return $self._visit_(each);
 }
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,4)});
 //>>excludeEnd("ctx");
 }));
-}
-catch(e) {if(e===$early)return e[0]; throw e}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"aliasTemporally:",{aCollection:aCollection,threshold:threshold,shouldAlias:shouldAlias})});
 //>>excludeEnd("ctx");
@@ -5905,7 +5902,7 @@ selector: "asReceiver",
 protocol: "*Compiler-IR",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "asReceiver\x0a\x09self class receiverNames\x0a\x09\x09at: self name\x0a\x09\x09ifPresent: [ :newName | ^ self copy name: newName; yourself ]\x0a\x09\x09ifAbsent: [ ^ self ]",
+source: "asReceiver\x0a\x09^ self class receiverNames\x0a\x09\x09at: self name\x0a\x09\x09ifPresent: [ :newName | self copy name: newName; yourself ]\x0a\x09\x09ifAbsent: [ self ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
@@ -5916,25 +5913,20 @@ var self=this,$self=this;
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1;
-var $early={};
-try {
-$recv($recv($self._class())._receiverNames())._at_ifPresent_ifAbsent_($self._name(),(function(newName){
+return $recv($recv($self._class())._receiverNames())._at_ifPresent_ifAbsent_($self._name(),(function(newName){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 $1=$self._copy();
 $recv($1)._name_(newName);
-throw $early=[$recv($1)._yourself()];
+return $recv($1)._yourself();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({newName:newName},$ctx1,1)});
 //>>excludeEnd("ctx");
 }),(function(){
-throw $early=[self];
+return self;
 
 }));
-return self;
-}
-catch(e) {if(e===$early)return e[0]; throw e}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"asReceiver",{})});
 //>>excludeEnd("ctx");

+ 5 - 5
lang/src/Compiler-IR.st

@@ -91,8 +91,8 @@ aliasTemporally: aCollection
 
 	| threshold shouldAlias |
 	threshold := aCollection reversed
-		detect: [ :each | each subtreeNeedsAliasing ]
-		ifNone: [ ^ self visitAll: aCollection ].
+		detect: [ :each | each subtreeNeedsAliasing ] ifNone: [ nil ].
+	threshold ifNil: [ ^ self visitAll: aCollection ].
 
 	shouldAlias := true.
 	^ aCollection collect: [ :each |
@@ -1366,10 +1366,10 @@ subtreeNeedsAliasing
 !PseudoVar methodsFor: '*Compiler-IR'!
 
 asReceiver
-	self class receiverNames
+	^ self class receiverNames
 		at: self name
-		ifPresent: [ :newName | ^ self copy name: newName; yourself ]
-		ifAbsent: [ ^ self ]
+		ifPresent: [ :newName | self copy name: newName; yourself ]
+		ifAbsent: [ self ]
 ! !
 
 !ScopeVar methodsFor: '*Compiler-IR'!

Some files were not shown because too many files changed in this diff