public override void Compile(ByteCode bc) { using (bc.EnterSource(_ref)) { if (_expression != null) { _expression.Compile(bc); bc.Emit_Ret(1); } else { bc.Emit_Ret(0); } } }
public override void Compile(ByteCode bc) { var meta = bc.Emit_Meta("<chunk-root>", OpCodeMetadataType.ChunkEntrypoint); int metaip = bc.GetJumpPointForLastInstruction(); bc.Emit_BeginFn(_stackFrame); bc.Emit_Args(_varArgs); bc.Emit_Load(SymbolRef.Upvalue(WellKnownSymbols.ENV, 0)); bc.Emit_Store(_env, 0, 0); bc.Emit_Pop(); _block.Compile(bc); bc.Emit_Ret(0); meta.NumVal = bc.GetJumpPointForLastInstruction() - metaip; }
public int CompileBody(ByteCode bc, string friendlyName) { string funcName = friendlyName ?? $"<{_begin.FormatLocation(bc.Script)}>"; bc.PushSourceRef(_begin); var I = bc.Emit_Jump(OpCode.Jump, -1); var meta = bc.Emit_Meta(funcName, OpCodeMetadataType.FunctionEntrypoint); int metaip = bc.GetJumpPointForLastInstruction(); bc.Emit_BeginFn(_stackFrame); bc.LoopTracker.Loops.Push(new LoopBoundary()); int entryPoint = bc.GetJumpPointForLastInstruction(); if (_usesGlobalEnv) { bc.Emit_Load(SymbolRef.Upvalue(WellKnownSymbols.ENV, 0)); bc.Emit_Store(_env, 0, 0); bc.Emit_Pop(); } if (_paramNames.Length > 0) { bc.Emit_Args(_paramNames); } _statement.Compile(bc); bc.PopSourceRef(); bc.PushSourceRef(_end); bc.Emit_Ret(0); bc.LoopTracker.Loops.Pop(); I.NumVal = bc.GetJumpPointForNextInstruction(); meta.NumVal = bc.GetJumpPointForLastInstruction() - metaip; bc.PopSourceRef(); return(entryPoint); }
public int CompileBody(ByteCode bc, string friendlyName) { string funcName = friendlyName ?? ("<" + this.m_Begin.FormatLocation(bc.Script, true) + ">"); bc.PushSourceRef(m_Begin); Instruction I = bc.Emit_Jump(OpCode.Jump, -1); Instruction meta = bc.Emit_FuncMeta(funcName); int metaip = bc.GetJumpPointForLastInstruction(); bc.Emit_BeginFn(m_StackFrame); bc.LoopTracker.Loops.Push(new LoopBoundary()); int entryPoint = bc.GetJumpPointForLastInstruction(); if (m_GlobalEnv != null) { bc.Emit_Literal(DynValue.NewTable(m_GlobalEnv)); bc.Emit_Store(m_Env, 0, 0); bc.Emit_Pop(); } if (m_ParamNames.Length > 0) { bc.Emit_Args(m_ParamNames); } m_Statement.Compile(bc); bc.PopSourceRef(); bc.PushSourceRef(m_End); bc.Emit_Ret(0); bc.LoopTracker.Loops.Pop(); I.NumVal = bc.GetJumpPointForNextInstruction(); meta.NumVal = bc.GetJumpPointForLastInstruction() - metaip; bc.PopSourceRef(); return(entryPoint); }
public int CompileBody(ByteCode bc, string friendlyName) { string funcName = friendlyName ?? ("<" + this.m_Begin.FormatLocation(bc.Script, true) + ">"); bc.PushSourceRef(m_Begin); int I = bc.Emit_Jump(OpCode.Jump, -1); int meta = bc.Emit_Meta(funcName, OpCodeMetadataType.FunctionEntrypoint); bc.Emit_BeginFn(m_StackFrame); bc.LoopTracker.Loops.Push(new LoopBoundary()); int entryPoint = bc.GetJumpPointForLastInstruction(); if (m_UsesGlobalEnv) { bc.Emit_Load(SymbolRef.Upvalue(WellKnownSymbols.ENV, 0)); bc.Emit_Store(m_Env, 0, 0); bc.Emit_Pop(); } if (m_ParamNames.Length > 0) { bc.Emit_Args(m_ParamNames); } m_Statement.Compile(bc); bc.PopSourceRef(); bc.PushSourceRef(m_End); bc.Emit_Ret(0); bc.LoopTracker.Loops.Pop(); bc.SetNumVal(I, bc.GetJumpPointForNextInstruction()); bc.SetNumVal(meta, bc.GetJumpPointForLastInstruction() - meta); bc.PopSourceRef(); return(entryPoint); }