public override void Compile(ByteCode bc) { using (bc.EnterSource(_do)) { bc.Emit_Enter(_stackFrame); } _block.Compile(bc); using (bc.EnterSource(_end)) { bc.Emit_Leave(_stackFrame); } }
public override void Compile(ByteCode bc) { var endJumps = new List <Instruction>(); Instruction lastIfJmp = null; foreach (var ifblock in _ifs) { using (bc.EnterSource(ifblock.Source)) { if (lastIfJmp != null) { lastIfJmp.NumVal = bc.GetJumpPointForNextInstruction(); } ifblock.Exp.Compile(bc); lastIfJmp = bc.Emit_Jump(OpCode.Jf, -1); bc.Emit_Enter(ifblock.StackFrame); ifblock.Block.Compile(bc); } using (bc.EnterSource(_end)) { bc.Emit_Leave(ifblock.StackFrame); } endJumps.Add(bc.Emit_Jump(OpCode.Jump, -1)); } lastIfJmp.NumVal = bc.GetJumpPointForNextInstruction(); if (_else != null) { using (bc.EnterSource(_else.Source)) { bc.Emit_Enter(_else.StackFrame); _else.Block.Compile(bc); } using (bc.EnterSource(_end)) { bc.Emit_Leave(_else.StackFrame); } } foreach (var endjmp in endJumps) { endjmp.NumVal = bc.GetJumpPointForNextInstruction(); } }
internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode) { ScriptLoadingContext lcontext = CreateLoadingContext(script, source); try { Statement stat; using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation)) stat = new ChunkStatement(lcontext); int beginIp = -1; //var srcref = new SourceRef(source.SourceID); using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation)) using (bytecode.EnterSource(null)) { bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name)); beginIp = bytecode.GetJumpPointForLastInstruction(); stat.Compile(bytecode); bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name)); } //Debug_DumpByteCode(bytecode, source.SourceID); return(beginIp); } catch (SyntaxErrorException ex) { ex.DecorateMessage(script); ex.Rethrow(); throw; } }
internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, bool usesGlobalEnv) { ScriptLoadingContext lcontext = CreateLoadingContext(script, source); try { FunctionDefinitionExpression fnx; using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation)) fnx = new FunctionDefinitionExpression(lcontext, usesGlobalEnv); int beginIp = -1; //var srcref = new SourceRef(source.SourceID); using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation)) using (bytecode.EnterSource(null)) { bytecode.Emit_Nop(string.Format("Begin function {0}", source.Name)); beginIp = fnx.CompileBody(bytecode, source.Name); bytecode.Emit_Nop(string.Format("End function {0}", source.Name)); } //Debug_DumpByteCode(bytecode, source.SourceID); return(beginIp); } catch (SyntaxErrorException ex) { ex.DecorateMessage(script); ex.Rethrow(); throw; } }
internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode) { var lcontext = CreateLoadingContext(script, source); try { Statement stat = new ChunkStatement(lcontext); int beginIp; using (bytecode.EnterSource(null)) { bytecode.Emit_Nop($"Begin chunk {source.Name}"); beginIp = bytecode.GetJumpPointForLastInstruction(); stat.Compile(bytecode); bytecode.Emit_Nop($"End chunk {source.Name}"); } return(beginIp); } catch (SyntaxErrorException ex) { ex.DecorateMessage(script); ex.Rethrow(); throw; } }
internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, bool usesGlobalEnv) { var lcontext = CreateLoadingContext(script, source); try { FunctionDefinitionExpression fnx; fnx = new FunctionDefinitionExpression(lcontext, usesGlobalEnv); int beginIp; using (bytecode.EnterSource(null)) { bytecode.Emit_Nop($"Begin function {source.Name}"); beginIp = fnx.CompileBody(bytecode, source.Name); bytecode.Emit_Nop($"End function {source.Name}"); } return(beginIp); } catch (SyntaxErrorException ex) { ex.DecorateMessage(script); ex.Rethrow(); throw; } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(m_FunctionCallExpression.SourceRef)) { m_FunctionCallExpression.Compile(bc); RemoveBreakpointStop(bc.Emit_Pop()); } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(m_SourceRef)) { m_FunctionCallChain.Compile(bc); bc.Emit_Pop(); } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(m_FunctionCallExpression.SourceRef)) { m_FunctionCallExpression.Compile(bc); bc.Emit_Pop(); bc.SourceRefs[bc.SourceRefs.Count - 1] = null; //Remove breakpoint stop } }
public int Compile(ByteCode bc, Func <int> afterDecl, string friendlyName) { using (bc.EnterSource(_begin)) { var symbs = _closure.ToArray(); _closureInstruction = bc.Emit_Closure(symbs, bc.GetJumpPointForNextInstruction()); int ops = afterDecl(); _closureInstruction.NumVal += 2 + ops; } return(this.CompileBody(bc, friendlyName)); }
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 int Compile(ByteCode bc, Func <int> afterDecl, string friendlyName) { using (bc.EnterSource(m_Begin)) { SymbolRef[] symbs = m_Closure //.Select((s, idx) => s.CloneLocalAndSetFrame(m_ClosureFrames[idx])) .ToArray(); m_ClosureInstruction = bc.Emit_Closure(symbs, bc.GetJumpPointForNextInstruction()); int ops = afterDecl(); m_ClosureInstruction.NumVal += 2 + ops; } return(CompileBody(bc, friendlyName)); }
public override void Compile(ByteCode bc) { using (bc.EnterSource(_ref)) { foreach (var exp in _rValues) { exp.Compile(bc); } for (int i = 0; i < _lValues.Count; i++) { _lValues[i].CompileAssignment(bc, Math.Max(_rValues.Count - 1 - i, 0), // index of r-value i - Math.Min(i, _rValues.Count - 1)); // index in last tuple } bc.Emit_Pop(_rValues.Count); } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(m_Ref)) { if (bc.LoopTracker.Loops.Count == 0) { throw new SyntaxErrorException(this.Script, m_Ref, "<break> at line {0} not inside a loop", m_Ref.FromLine); } ILoop loop = bc.LoopTracker.Loops.Peek(); if (loop.IsBoundary()) { throw new SyntaxErrorException(this.Script, m_Ref, "<break> at line {0} not inside a loop", m_Ref.FromLine); } loop.CompileBreak(bc); } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(m_Ref)) { if (bc.LoopTracker.Loops.Count == 0) { throw new SyntaxErrorException("<break> not inside a loop"); } ILoop loop = bc.LoopTracker.Loops.Peek(); if (loop.IsBoundary()) { throw new SyntaxErrorException("<break> not inside a loop"); } loop.CompileBreak(bc); } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(_sourceRef)) { if (_local) { bc.Emit_Literal(DynValue.Nil); bc.Emit_Store(_funcSymbol, 0, 0); _funcDef.Compile(bc, () => this.SetFunction(bc, 2), _friendlyName); } else if (_methodName == null) { _funcDef.Compile(bc, () => this.SetFunction(bc, 1), _friendlyName); } else { _funcDef.Compile(bc, () => this.SetMethod(bc), _friendlyName); } } }
internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode, Table globalContext) { AntlrErrorListener listener = new AntlrErrorListener(source); try { LuaParser parser = CreateParser(script, new AntlrInputStream(source.Code), source.SourceID, p => p.chunk(), listener); ScriptLoadingContext lcontext = CreateLoadingContext(script, source); ChunkStatement stat; using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation)) stat = new ChunkStatement(parser.chunk(), lcontext, globalContext); int beginIp = -1; //var srcref = new SourceRef(source.SourceID); using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation)) using (bytecode.EnterSource(null)) { bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name)); beginIp = bytecode.GetJumpPointForLastInstruction(); stat.Compile(bytecode); bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name)); } Debug_DumpByteCode(bytecode, source.SourceID); return(beginIp); } catch (ParseCanceledException ex) { HandleParserError(ex, listener); throw; } }
internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, Table globalContext) { AntlrErrorListener listener = new AntlrErrorListener(source); try { LuaParser parser = CreateParser(script, new AntlrInputStream(source.Code), source.SourceID, p => p.singlefunc(), listener); ScriptLoadingContext lcontext = CreateLoadingContext(script, source); FunctionDefinitionExpression fndef; using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation)) fndef = new FunctionDefinitionExpression(parser.anonfunctiondef(), lcontext, false, globalContext); int beginIp = -1; // var srcref = new SourceRef(source.SourceID); using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation)) using (bytecode.EnterSource(null)) { bytecode.Emit_Nop(string.Format("Begin function {0}", source.Name)); beginIp = fndef.CompileBody(bytecode, source.Name); bytecode.Emit_Nop(string.Format("End function {0}", source.Name)); Debug_DumpByteCode(bytecode, source.SourceID); } return(beginIp); } catch (ParseCanceledException ex) { HandleParserError(ex, listener); throw; } }