public override void Compile(ByteCode bc) { using (bc.EnterSource(m_Do)) bc.Emit_Enter(m_StackFrame); m_Block.Compile(bc); using (bc.EnterSource(m_End)) bc.Emit_Leave(m_StackFrame); }
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); 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) { var endJumps = new List<Instruction>(); Instruction lastIfJmp = null; foreach (var ifblock in m_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(m_End)) bc.Emit_Leave(ifblock.StackFrame); endJumps.Add(bc.Emit_Jump(OpCode.Jump, -1)); } lastIfJmp.NumVal = bc.GetJumpPointForNextInstruction(); if (m_Else != null) { using (bc.EnterSource(m_Else.Source)) { bc.Emit_Enter(m_Else.StackFrame); m_Else.Block.Compile(bc); } using (bc.EnterSource(m_End)) bc.Emit_Leave(m_Else.StackFrame); } foreach (var endjmp in endJumps) endjmp.NumVal = bc.GetJumpPointForNextInstruction(); }
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 (m_Expression != null) { m_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)) { var symbs = m_Closure //.Select((s, idx) => s.CloneLocalAndSetFrame(m_ClosureFrames[idx])) .ToArray(); m_ClosureInstruction = bc.Emit_Closure(symbs, bc.GetJumpPointForNextInstruction()); var ops = afterDecl(); m_ClosureInstruction.NumVal += 2 + ops; } return CompileBody(bc, friendlyName); }
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); throw; } }
public override void Compile(ByteCode bc) { using (bc.EnterSource(m_Ref)) { foreach (var exp in m_RValues) { exp.Compile(bc); } for (var i = 0; i < m_LValues.Count; i++) m_LValues[i].CompileAssignment(bc, Math.Max(m_RValues.Count - 1 - i, 0), // index of r-value i - Math.Min(i, m_RValues.Count - 1)); // index in last tuple bc.Emit_Pop(m_RValues.Count); } }