1
0

Add VAR(expr)=expr

This commit is contained in:
otya128
2016-12-08 22:32:51 +09:00
parent 879d28c9bf
commit 609bc0bcd5
3 changed files with 79 additions and 1 deletions

View File

@@ -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]);
}
}