Implement USE/EXEC compilation
This commit is contained in:
@@ -2182,3 +2182,22 @@ class Pop : Code
|
||||
vm.decSP();
|
||||
}
|
||||
}
|
||||
|
||||
class Exec : Code
|
||||
{
|
||||
override void execute(VM vm)
|
||||
{
|
||||
Value arg;
|
||||
vm.pop(arg);
|
||||
}
|
||||
}
|
||||
|
||||
class Use : Code
|
||||
{
|
||||
override void execute(VM vm)
|
||||
{
|
||||
Value arg;
|
||||
vm.pop(arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -933,6 +933,16 @@ class Compiler
|
||||
{
|
||||
genCode(new SetX(x.func, false));
|
||||
}
|
||||
void compileExec(otya.smilebasic.node.Exec exec, Scope sc)
|
||||
{
|
||||
compileExpression(exec.expression, sc);
|
||||
genCode(new otya.smilebasic.vm.Exec);
|
||||
}
|
||||
void compileUse(otya.smilebasic.node.Use use, Scope sc)
|
||||
{
|
||||
compileExpression(use.expression, sc);
|
||||
genCode(new otya.smilebasic.vm.Use);
|
||||
}
|
||||
void compileStatement(Statement i, Scope s)
|
||||
{
|
||||
switch(i.type)
|
||||
@@ -1201,6 +1211,12 @@ class Compiler
|
||||
case NodeType.XOff:
|
||||
compileXOff(cast(XOff)i, s);
|
||||
break;
|
||||
case NodeType.Exec:
|
||||
compileExec(cast(otya.smilebasic.node.Exec)i, s);
|
||||
break;
|
||||
case NodeType.Use:
|
||||
compileUse(cast(otya.smilebasic.node.Use)i, s);
|
||||
break;
|
||||
default:
|
||||
stderr.writeln("Compile:NotImpl ", i.type);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ enum NodeType
|
||||
VarRef,
|
||||
XOn,
|
||||
XOff,
|
||||
Exec,
|
||||
Use,
|
||||
}
|
||||
abstract class Node
|
||||
{
|
||||
@@ -653,4 +655,23 @@ class XOff : Statement
|
||||
this.func = func;
|
||||
}
|
||||
}
|
||||
|
||||
class Exec : Statement
|
||||
{
|
||||
Expression expression;
|
||||
this(Expression e, SourceLocation loc)
|
||||
{
|
||||
super.location = loc;
|
||||
expression = e;
|
||||
this.type = NodeType.Exec;
|
||||
}
|
||||
}
|
||||
class Use : Statement
|
||||
{
|
||||
Expression expression;
|
||||
this(Expression e, SourceLocation loc)
|
||||
{
|
||||
super.location = loc;
|
||||
expression = e;
|
||||
this.type = NodeType.Use;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,14 +1111,14 @@ class Parser
|
||||
{
|
||||
lex.popFront();
|
||||
auto expr = expression();
|
||||
writeln("NOTIMPL:USE");
|
||||
return new Use(expr, lex.location);
|
||||
}
|
||||
break;
|
||||
case TokenType.Exec:
|
||||
{
|
||||
lex.popFront();
|
||||
auto expr = expression();
|
||||
writeln("NOTIMPL:EXEC");
|
||||
return new Exec(expr, lex.location);
|
||||
}
|
||||
break;
|
||||
case TokenType.Swap:
|
||||
|
||||
Reference in New Issue
Block a user