Exemple #1
0
        private void NewProcedure(string name, bool exported, bool varargs, int line, bool upvalueOfSelf)
        {
            var current = asm;

            procedures.Push(asm);

            asm = new ProcedureWriter(name, exported, varargs, line);
            if (upvalueOfSelf)
            {
                asm.MarkUpValue(name);
            }

            if (current != null)
            {
                foreach (var param in current.Parameters)
                {
                    asm.MarkUpValue(param.Name);
                }

                foreach (var local in current.Locals)
                {
                    asm.MarkUpValue(local);
                }

                foreach (var upvalue in current.UpValues)
                {
                    asm.MarkUpValue(upvalue);
                }
            }
        }
Exemple #2
0
        private Procedure FinishProcedure(bool set = false)
        {
            var proc = asm.Finish();

            asm = procedures.Pop();

            if (asm != null)
            {
                asm.AddProcedure(proc);

                if (set)
                {
                    asm.MarkLocal(proc.Name);
                    asm.Declare(proc.Name, VariableFlags.FINAL);
                    Closure(proc);
                    asm.SetLocal(proc.Name);
                }
            }
            else
            {
                if (chunk.Procedures.ContainsKey(proc.Name))
                {
                    throw new NeoError("attempt to redeclare '" + proc.Name + "'", ast.Name, proc.Line);
                }
                chunk.Procedures[proc.Name] = proc;
            }

            return(proc);
        }