Browse Source

Pseudovars including nil, true, false actually parsed as such.

The nil, true and false still parsed as values
in pragmas and literal array, though.
Only parsed as variables in operand context.
May be hackish, but works atm.

Includes hotfix to ASTInterpreter.
Herby Vojčík 4 years ago
parent
commit
d97910b6ec

+ 2 - 2
lang/base/parser.js

@@ -3349,9 +3349,9 @@ define(["./boot"], function(__boot) {
         return cached.result;
         return cached.result;
       }
       }
 
 
-      s0 = peg$parseliteral();
+      s0 = peg$parsevariable();
       if (s0 === peg$FAILED) {
       if (s0 === peg$FAILED) {
-        s0 = peg$parsevariable();
+        s0 = peg$parseliteral();
         if (s0 === peg$FAILED) {
         if (s0 === peg$FAILED) {
           s0 = peg$parsesubexpression();
           s0 = peg$parsesubexpression();
         }
         }

+ 1 - 1
lang/base/parser.pegjs

@@ -194,7 +194,7 @@ block = '[' params:wsBlockParamList? sequence:wsBlockSequenceWs ']' {
 	return newNode($globals.BlockNode)._parameters_(params || [])._dagChildren_([sequence]);
 	return newNode($globals.BlockNode)._parameters_(params || [])._dagChildren_([sequence]);
 }
 }
 
 
-operand = literal / reference / subexpression
+operand = reference / literal / subexpression
 
 
 wsUnaryMessage = ws selector:unarySelector !':' {
 wsUnaryMessage = ws selector:unarySelector !':' {
 	return newNode($globals.SendNode)._selector_(selector);
 	return newNode($globals.SendNode)._selector_(selector);

+ 42 - 9
lang/src/Compiler-Interpreter.js

@@ -3404,17 +3404,17 @@ selector: "visitVariableNode:",
 protocol: "visiting",
 protocol: "visiting",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aNode"],
 args: ["aNode"],
-source: "visitVariableNode: aNode\x0a\x09aNode binding isExternallyKnownVar ifTrue: [\x0a\x09\x09^ self push: (Platform globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].\x0a\x09\x09\x0a\x09self push: (aNode binding isInstanceVar\x0a\x09\x09ifTrue: [ self context receiver instVarAt: aNode value ]\x0a\x09\x09ifFalse: [ self context \x0a\x09\x09\x09localAt: (aNode binding isSuper ifTrue: [ 'self' ] ifFalse: [ aNode value ])\x0a\x09\x09\x09ifAbsent: [\x0a\x09\x09\x09\x09aNode value isCapitalized\x0a\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09Smalltalk globals \x0a\x09\x09\x09\x09\x09\x09\x09at: aNode value \x0a\x09\x09\x09\x09\x09\x09\x09ifAbsent: [ Platform globals at: aNode value ] ] ] ])",
+source: "visitVariableNode: aNode\x0a\x09aNode binding isExternallyKnownVar ifTrue: [\x0a\x09\x09^ self push: (Platform globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].\x0a\x09\x09\x0a\x09self push: (aNode binding isInstanceVar\x0a\x09\x09ifTrue: [ self context receiver instVarAt: aNode value ]\x0a\x09\x09ifFalse: [ self context \x0a\x09\x09\x09localAt: (aNode binding isSuper ifTrue: [ 'self' ] ifFalse: [ aNode value ])\x0a\x09\x09\x09ifAbsent: [\x0a\x09\x09\x09\x09aNode value = 'nil' ifTrue: [ nil ] ifFalse: [\x0a\x09\x09\x09\x09aNode value = 'true' ifTrue: [ true ] ifFalse: [\x0a\x09\x09\x09\x09aNode value = 'false' ifTrue: [ false ] ifFalse: [\x0a\x09\x09\x09\x09aNode value isCapitalized\x0a\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09Smalltalk globals \x0a\x09\x09\x09\x09\x09\x09\x09at: aNode value \x0a\x09\x09\x09\x09\x09\x09\x09ifAbsent: [ Platform globals at: aNode value ] ] ] ] ] ] ])",
 referencedClasses: ["Platform", "Smalltalk"],
 referencedClasses: ["Platform", "Smalltalk"],
 //>>excludeEnd("ide");
 //>>excludeEnd("ide");
 pragmas: [],
 pragmas: [],
-messageSends: ["ifTrue:", "isExternallyKnownVar", "binding", "push:", "at:ifAbsent:", "globals", "value", "error:", "ifTrue:ifFalse:", "isInstanceVar", "instVarAt:", "receiver", "context", "localAt:ifAbsent:", "isSuper", "isCapitalized", "at:"]
+messageSends: ["ifTrue:", "isExternallyKnownVar", "binding", "push:", "at:ifAbsent:", "globals", "value", "error:", "ifTrue:ifFalse:", "isInstanceVar", "instVarAt:", "receiver", "context", "localAt:ifAbsent:", "isSuper", "=", "isCapitalized", "at:"]
 }, function ($methodClass){ return function (aNode){
 }, function ($methodClass){ return function (aNode){
 var self=this,$self=this;
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
-var $2,$1,$5,$6,$4,$3,$9,$8,$11,$10,$12,$13,$15,$14,$17,$16,$18,$19,$7;
+var $2,$1,$5,$6,$4,$3,$9,$8,$11,$10,$12,$13,$15,$14,$17,$16,$19,$18,$21,$20,$23,$22,$24,$25,$7;
 $2=$recv(aNode)._binding();
 $2=$recv(aNode)._binding();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["binding"]=1;
 $ctx1.sendIdx["binding"]=1;
@@ -3482,26 +3482,59 @@ $17=$recv(aNode)._value();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["value"]=4;
 $ctx2.sendIdx["value"]=4;
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
-$16=$recv($17)._isCapitalized();
-if($core.assert($16)){
-$18=$recv($globals.Smalltalk)._globals();
+$16=$recv($17).__eq("nil");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx["globals"]=2;
+$ctx2.sendIdx["="]=1;
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
+if($core.assert($16)){
+return nil;
+} else {
 $19=$recv(aNode)._value();
 $19=$recv(aNode)._value();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["value"]=5;
 $ctx2.sendIdx["value"]=5;
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
-return $recv($18)._at_ifAbsent_($19,(function(){
+$18=$recv($19).__eq("true");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["="]=2;
+//>>excludeEnd("ctx");
+if($core.assert($18)){
+return true;
+} else {
+$21=$recv(aNode)._value();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["value"]=6;
+//>>excludeEnd("ctx");
+$20=$recv($21).__eq("false");
+if($core.assert($20)){
+return false;
+} else {
+$23=$recv(aNode)._value();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["value"]=7;
+//>>excludeEnd("ctx");
+$22=$recv($23)._isCapitalized();
+if($core.assert($22)){
+$24=$recv($globals.Smalltalk)._globals();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["globals"]=2;
+//>>excludeEnd("ctx");
+$25=$recv(aNode)._value();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["value"]=8;
+//>>excludeEnd("ctx");
+return $recv($24)._at_ifAbsent_($25,(function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx3) {
 return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
 return $recv($recv($globals.Platform)._globals())._at_($recv(aNode)._value());
 return $recv($recv($globals.Platform)._globals())._at_($recv(aNode)._value());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx3) {$ctx3.fillBlock({},$ctx2,9)});
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,15)});
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");
 }));
 }));
 }
 }
+}
+}
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,7)});
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,7)});
 //>>excludeEnd("ctx");
 //>>excludeEnd("ctx");

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

@@ -895,11 +895,14 @@ visitVariableNode: aNode
 		ifFalse: [ self context 
 		ifFalse: [ self context 
 			localAt: (aNode binding isSuper ifTrue: [ 'self' ] ifFalse: [ aNode value ])
 			localAt: (aNode binding isSuper ifTrue: [ 'self' ] ifFalse: [ aNode value ])
 			ifAbsent: [
 			ifAbsent: [
+				aNode value = 'nil' ifTrue: [ nil ] ifFalse: [
+				aNode value = 'true' ifTrue: [ true ] ifFalse: [
+				aNode value = 'false' ifTrue: [ false ] ifFalse: [
 				aNode value isCapitalized
 				aNode value isCapitalized
 					ifTrue: [
 					ifTrue: [
 						Smalltalk globals 
 						Smalltalk globals 
 							at: aNode value 
 							at: aNode value 
-							ifAbsent: [ Platform globals at: aNode value ] ] ] ])
+							ifAbsent: [ Platform globals at: aNode value ] ] ] ] ] ] ])
 ! !
 ! !
 
 
 Error subclass: #ASTInterpreterError
 Error subclass: #ASTInterpreterError