Add VAR(expr)=expr
This commit is contained in:
@@ -1943,3 +1943,67 @@ class SwapCode : Code
|
||||
*dp1 = num2;
|
||||
}
|
||||
}
|
||||
|
||||
class PushVarRefExpression : Code
|
||||
{
|
||||
Scope sc;
|
||||
this(Scope sc)
|
||||
{
|
||||
this.sc = sc;
|
||||
}
|
||||
override void execute(VM vm)
|
||||
{
|
||||
Value valv;
|
||||
vm.pop(valv);
|
||||
auto name = valv.castString;
|
||||
|
||||
VMVariable vmv = VMVariable(int.min);
|
||||
if (sc.func)
|
||||
{
|
||||
vmv = sc.func.variable.get(name, vmv);
|
||||
if (vmv.index != int.min)
|
||||
{
|
||||
vm.push(Value(&vm.stack[vm.bp + vmv.index]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
vmv = vm.currentSlot.globalTable.get(name, vmv);
|
||||
if (vmv.index == int.min)
|
||||
{
|
||||
throw new UndefinedVariable();
|
||||
}
|
||||
vm.push(Value(&vm.currentSlot.global[vmv.index]));
|
||||
}
|
||||
}
|
||||
|
||||
class PushVarExpression : Code
|
||||
{
|
||||
Scope sc;
|
||||
this(Scope sc)
|
||||
{
|
||||
this.sc = sc;
|
||||
}
|
||||
override void execute(VM vm)
|
||||
{
|
||||
Value valv;
|
||||
vm.pop(valv);
|
||||
auto name = valv.castString;
|
||||
|
||||
VMVariable vmv = VMVariable(int.min);
|
||||
if (sc.func)
|
||||
{
|
||||
vmv = sc.func.variable.get(name, vmv);
|
||||
if (vmv.index != int.min)
|
||||
{
|
||||
vm.push(vm.stack[vm.bp + vmv.index]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
vmv = vm.currentSlot.globalTable.get(name, vmv);
|
||||
if (vmv.index == int.min)
|
||||
{
|
||||
throw new UndefinedVariable();
|
||||
}
|
||||
vm.push(vm.currentSlot.global[vmv.index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,6 +578,13 @@ class Compiler
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NodeType.VarRef:
|
||||
{
|
||||
auto varref = cast(VarRef)exp;
|
||||
compileExpression(varref.expression, sc);
|
||||
genCode(new PushVarExpression(sc));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
stderr.writeln("Compile:NotImpl ", exp.type);
|
||||
break;
|
||||
@@ -628,6 +635,13 @@ class Compiler
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NodeType.VarRef:
|
||||
{
|
||||
auto varref = cast(VarRef)exp;
|
||||
compileExpression(varref.expression, sc);
|
||||
genCode(new PushVarRefExpression(sc));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
stderr.writeln("Compile:NotImpl ", exp.type);
|
||||
break;
|
||||
|
||||
@@ -628,6 +628,6 @@ class VarRef : Expression
|
||||
{
|
||||
super.location = loc;
|
||||
this.type = NodeType.VarRef;
|
||||
this.expression = expression;
|
||||
this.expression = expr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user