本文整理汇总了C#中Kernel.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# Kernel.Emit方法的具体用法?C# Kernel.Emit怎么用?C# Kernel.Emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kernel
的用法示例。
在下文中一共展示了Kernel.Emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Kernel k)
{
k.EmitPush("1u");
k.Emit(Opcode.ALLOC).SetDebug(File, Line, Column, DebugType.Define, this.VariableName);
k.CurrentScope.MemorySpace += 1;
Symbol symbol = new Symbol()
{
Name = this.VariableName,
SMode = Symbol.Mode.Intern,
SType = Symbol.Type.Variable,
Id = k.CurrentScope.RequestId()
};
k.RegisterSymbol(symbol);
if (this.Value == null)
{
k.Emit(Opcode.PUSHNIL).Comment = "clear memory for variable";
}
else
{
this.Value.Compile(k);
}
k.EmitPush(symbol.Id.ToString() + "u");
k.Emit(Opcode.STLO).SetDebug(File, Line, Column, DebugType.Set, this.VariableName);
}
示例2: Compile
public override void Compile(Kernel k)
{
Symbol returnSymbol = k.Lookup("+return");
if (this.Value != null)
this.Value.Compile(k);
else
k.Emit(Opcode.PUSHNIL);
var rvn = new RetrieveVariableNode(-1, -1) {VariableName = "+return"};
rvn.PrePass(k);
rvn.PreCompile(k);
rvn.Compile(k);
uint mem = 0;
Scope current = k.CurrentScope;
while(current != returnSymbol.SScope)
{
mem += current.MemorySpace;
current.PopMemory(k, false);
current = current.Parent;
}
mem += current.MemorySpace;
current.PopMemory(k, false);
k.EmitPush(mem + "u").Comment = "deallocate function memory";
k.Emit(Opcode.DEALLOC);
k.Emit(Opcode.JUMP).SetDebug(File, Line, Column, DebugType.Return, "");
}
示例3: Compile
public override void Compile(Kernel k)
{
Symbol symbol = k.Lookup(this.VariableName);
if(this.Value == null)
{
k.Emit(Opcode.PUSHNIL).Comment = "set variable to nil";
}
else
{
this.Value.Compile(k);
}
if (symbol.SScope == k.CurrentScope)
{
k.EmitPush(symbol.Id.ToString() + "u").Comment = "store into variable " + this.VariableName;
k.Emit(Opcode.STLO).SetDebug(File, Line, Column, DebugType.Set, this.VariableName);
}
else
{
uint mem = k.CurrentScope.WalkMemoryBack(symbol.SScope);
mem -= symbol.Id;
k.EmitPush(mem.ToString() + "u").Comment = "store into variable " + this.VariableName;
k.Emit(Opcode.STNLO).SetDebug(File, Line, Column, DebugType.Set, this.VariableName);
}
}
示例4: Compile
public override void Compile(Kernel k)
{
if(this.Value)
{
k.Emit(Opcode.PUSHT).SetDebug(File, Line, Column, DebugType.Value, "true");
}
else
{
k.Emit(Opcode.PUSHF).SetDebug(File, Line, Column, DebugType.Value, "false");
}
}
示例5: Compile
public override void Compile(Kernel k)
{
k.CurrentScope.PushMemory(k);
Scope scope = k.PushScope();
scope.Name = "for" + scope.Parent.RequestLabelId();
if (this.Init != null)
this.Init.Compile(k);
string forLabel = "sl_fl_" + k.GetScopeName();
string endLabel = "sl_flh_" + k.GetScopeName();
Symbol breakSymbol = new Symbol()
{
Name = "+break",
AsmName = endLabel
};
k.RegisterSymbol(breakSymbol);
k.Emit(Opcode.LABEL, forLabel).Comment = "for loop";
k.Emit(Opcode.NOOP).SetDebug(File, Line, Column, DebugType.ForLoop, "");
this.Check.Compile(k);
k.Emit(Opcode.NOT);
k.Emit(Opcode.GOTOF, '"' + endLabel + '"');
scope.PushMemory(k);
Scope innerScope = k.PushScope();
innerScope.Name = "in";
if (this.Body != null)
this.Body.Compile(k);
k.EmitPush(innerScope.MemorySpace.ToString() + "u");
k.Emit(Opcode.DEALLOC);
k.PopScope();
scope.PopMemory(k);
if (this.Increment != null)
this.Increment.Compile(k);
k.Emit(Opcode.GOTO, '"' + forLabel + '"');
k.Emit(Opcode.LABEL, endLabel).Comment = "end for";
k.PopScope();
k.CurrentScope.PopMemory(k);
}
示例6: Compile
public override void Compile(Kernel k)
{
int op = 0;
for (int i = 0; i < this.Values.Count; i++)
{
this.Values[i].Compile(k);
if(i > 0)
{
k.Emit(Opcode.SWAP);
k.Emit(this.Ops[op]);
op++;
}
}
}
示例7: Compile
public override void Compile(Kernel k)
{
Symbol breakSymbol = k.Lookup("+break");
uint mem = 0;
Scope current = k.CurrentScope;
while (current != breakSymbol.SScope)
{
mem += current.MemorySpace;
current.PopMemory(k, false);
current = current.Parent;
}
current.PopMemory(k, false);
k.EmitPush(mem + "u").Comment = "deallocate scope memory";
k.Emit(Opcode.DEALLOC);
k.Emit(Opcode.GOTO, "\"" + breakSymbol.AsmName + "\"").SetDebug(File, Line, Column, DebugType.Break, "");
}
示例8: Compile
public override void Compile(Kernel k)
{
if(this.Value == null)
{
k.Emit(Opcode.PUSHNIL).SetDebug(File, Line, Column, DebugType.Value, "nil");
}
else
{
k.EmitPush(this.Value).SetDebug(File, Line, Column, DebugType.Value, this.Value);
}
}
示例9: Compile
public override void Compile(Kernel k)
{
k.CurrentScope.PushMemory(k);
Scope ifScope = k.PushScope();
ifScope.Name = "if" + ifScope.Parent.RequestLabelId();
string trueLabel = "sl_if_" + k.GetScopeName();
string falseLabel = "sl_fe_" + k.GetScopeName();
string endLabel = "sl_fh_" + k.GetScopeName();
this.Check.Compile(k);
k.Emit(Opcode.GOTOF, '"' + trueLabel + '"').SetDebug(File, Line, Column, DebugType.Branch, "");
k.Emit(Opcode.GOTO, '"' + falseLabel + '"');
k.Emit(Opcode.LABEL, trueLabel);
k.CurrentScope.PushMemory(k);
Scope trueScope = k.PushScope();
trueScope.Name = "true";
if (this.BranchTrue != null)
this.BranchTrue.Compile(k);
k.PopScope();
k.CurrentScope.PopMemory(k);
if(this.BranchFalse == null)
{
k.Emit(Opcode.LABEL, falseLabel).Comment = "no else block, used as end label";
}
else if(this.BranchFalse != null)
{
k.Emit(Opcode.GOTO, '"' + endLabel + '"');
k.Emit(Opcode.LABEL, falseLabel);
k.CurrentScope.PushMemory(k);
Scope falseScope = k.PushScope();
falseScope.Name = "false";
this.BranchFalse.Compile(k);
k.PopScope();
k.CurrentScope.PopMemory(k);
k.Emit(Opcode.LABEL, endLabel).Comment = "end if";
}
k.PopScope();
k.CurrentScope.PopMemory(k);
}
示例10: Compile
public override void Compile(Kernel k)
{
Symbol symbol = k.Lookup(this.VariableName);
if (symbol.SType != Symbol.Type.Variable)
{
throw new CompileException(String.Format("Symbol {0} is not a variable", this.VariableName));
}
if (symbol.SScope == k.CurrentScope)
{
k.EmitPush(symbol.Id.ToString() + "u").Comment = "retrieve variable " + this.VariableName;
k.Emit(Opcode.LDLO).SetDebug(File, Line, Column, DebugType.Retrieve, this.VariableName);
}
else
{
uint mem = k.CurrentScope.WalkMemoryBack(symbol.SScope);
mem -= symbol.Id;
k.EmitPush(mem.ToString() + "u").Comment = "retrieve variable " + this.VariableName;
k.Emit(Opcode.LDNLO).SetDebug(File, Line, Column, DebugType.Retrieve, this.VariableName);
}
}
示例11: Compile
public override void Compile(Kernel k)
{
Symbol symbol = k.Lookup(this.Function);
switch(symbol.SType)
{
case Symbol.Type.Function:
break;
default:
throw new InvalidOperationException(string.Format("Tried to compile a function call on a non-function symbol \"{0}\"", this.Function));
}
if (symbol.Args != this.Arguments.Count)
throw new ArgumentOutOfRangeException(string.Format("Tried to pass {0} arguments to {1} (requires: {2})", this.Arguments.Count, symbol.Name, symbol.Args));
switch(symbol.SMode)
{
default:
throw new InvalidOperationException(string.Format("Unknown symbol mode {0} on symbol \"{1}\"", symbol.SMode.ToString(), this.Function));
case Symbol.Mode.Extern:
this.CompileExtern(k);
break;
case Symbol.Mode.Intern:
this.CompileIntern(k);
break;
case Symbol.Mode.Library:
this.CompileLibrary(k);
break;
}
if(!this.UseReturn)
{
k.Emit(Opcode.POP).Comment = "remove unused return value";
}
}
示例12: Compile
public override void Compile(Kernel k)
{
k.Emit(this.Operation).SetDebug(File, Line, Column, DebugType.Raw, "");
}
示例13: Compile
public override void Compile(Kernel k)
{
this.Value.Compile(k);
k.Emit(Opcode.NOT).SetDebug(File, Line, Column, DebugType.Operation, "not");
}
示例14: Compile
public override void Compile(Kernel k)
{
k.Emit(Opcode.DBRK).SetDebug(File, Line, Column, DebugType.Debug, "");
}
示例15: CompileLibrary
protected void CompileLibrary(Kernel k)
{
for (int i = this.Arguments.Count - 1; i >= 0; i--)
{
this.Arguments[i].Compile(k);
}
uint returnId = k.CurrentScope.RequestLabelId();
k.Emit(Opcode.PLABL, "\"sl_r_" + k.GetScopeName() + "_" + returnId.ToString() + "\"");
var rvn = new RetrieveVariableNode(-1, -1)
{
VariableName = this.Function
};
rvn.PrePass(k);
rvn.PreCompile(k);
rvn.Compile(k);
k.CurrentScope.PushMemory(k);
k.Emit(Opcode.JUMP).SetDebug(File, Line, Column, DebugType.LCall, this.Function);
k.Emit(Opcode.LABEL, "sl_r_" + k.GetScopeName() + "_" + returnId.ToString()).Comment = "return point from " + this.Function;
k.CurrentScope.PopMemory(k);
}