Esempio n. 1
0
 public void CompilePossibleLiteral(ByteCode bc)
 {
     if (EvalLiteral(out var dv))
     {
         bc.Emit_Literal(dv);
     }
     else
     {
         Compile(bc);
     }
 }
Esempio n. 2
0
        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 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);
         }
     }
 }
Esempio n. 4
0
 public override void Compile(ByteCode bc)
 {
     bc.Emit_Literal(this.Value);
 }