1
0

Fix VAR(NAME$)

This commit is contained in:
otya128
2016-12-16 23:40:54 +09:00
parent 00efdec87d
commit 84a82d1336
2 changed files with 43 additions and 2 deletions

View File

@@ -2052,6 +2052,41 @@ class PushVarExpression : Code
}
}
class PopVarExpression : Code
{
Scope sc;
this(Scope sc)
{
this.sc = sc;
}
override void execute(VM vm)
{
Value valv;
vm.pop(valv);
Value expr;
vm.pop(expr);
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.stack[vm.bp + vmv.index] = expr;
return;
}
}
vmv = vm.currentSlot.globalTable.get(name, vmv);
if (vmv.index == int.min)
{
throw new UndefinedVariable();
}
vm.currentSlot.global[vmv.index] = expr;
}
}
class SetX : Code
{
wstring func;

View File

@@ -686,9 +686,15 @@ class Compiler
}
}
goto default;
case NodeType.VarRef:
{
auto varref = cast(VarRef)expr;
compileExpression(varref.expression, sc);
genCode(new PopVarExpression(sc));
}
break;
default:
stderr.writeln("ERROR");
break;
throw new SyntaxError();
}
}