public Method Compile(IBlock b, bool mainProgram) { List<Instruction> instructions = CompileBlockToInstructions(b, mainProgram); Method ret = new Method(); ret.Instructions = instructions.ToArray(); ret.Arity = 0; ret.PrepareLabels(); return ret; }
public Method Compile(IBlock b, bool mainProgram) { List <Instruction> instructions = CompileBlockToInstructions(b, mainProgram); Method ret = new Method(); ret.Instructions = instructions.ToArray(); ret.Arity = 0; ret.PrepareLabels(); return(ret); }
public Method DefineMethod(ProcDefBlock b, BlockStack stack) { // 'stack' is a BlockStack whose first element (#0) is a ProcDefBlock, the same as 'b' Method ret = new Method(); List<Instruction> instructions = new List<Instruction>(); string[] argNames = b.GetArgNames(); for (int i = 0; i < argNames.Length; ++i) { instructions.Add(new PopLocal(vm, argNames[i])); } for(int i=1; i<stack.Count; ++i) instructions.AddRange(CompileBlockToInstructions(stack[i], false)); instructions.Add(new Push(vm, null)); instructions.Add(new Ret(vm)); ret.Instructions = instructions.ToArray(); ret.Arity = argNames.Length; ret.PrepareLabels(); return ret; }
public Method DefineMethod(ProcDefBlock b, BlockStack stack) { // 'stack' is a BlockStack whose first element (#0) is a ProcDefBlock, the same as 'b' Method ret = new Method(); List <Instruction> instructions = new List <Instruction>(); string[] argNames = b.GetArgNames(); for (int i = 0; i < argNames.Length; ++i) { instructions.Add(new PopLocal(vm, argNames[i])); } for (int i = 1; i < stack.Count; ++i) { instructions.AddRange(CompileBlockToInstructions(stack[i], false)); } instructions.Add(new Push(vm, null)); instructions.Add(new Ret(vm)); ret.Instructions = instructions.ToArray(); ret.Arity = argNames.Length; ret.PrepareLabels(); return(ret); }