public void compile( List<FrameVar> locals, List<DynamicVar> dynamics, CodeBox code, boolean isLast) { if (isApplyLocal(locals)) compileApplyLocal(locals, dynamics, code, isLast); else if (isApplyDynamic(dynamics)) compileApplyDynamic(locals, dynamics, code, isLast); else if (isApplyFun()) compileApplyFun(locals, dynamics, code, isLast); else { code.add(new StartCall(getLineStart()), locals, dynamics); for (AST arg : args) arg.compile(locals, dynamics, code, false); op.compile(locals, dynamics, code, false); code.add(new instrs.apply.Apply(getLineStart(), args.length), locals, dynamics); } }
public void compile( List<FrameVar> locals, List<DynamicVar> dynamics, CodeBox code, boolean isLast) { // An act definition returns a behaviour. The bindings in the behaviour must // be constructed as recursive bindings *and* be dynamic variables so that // '.' can find them. Therefore, compile a behaviour as though it were // constructed in the context of a letrec, but force the bindings to be // dynamic... bindings = Binding.mergeBindings(bindings); for (Binding b : Binding.valueBindings(bindings)) { code.add(new Null(getLineStart()), locals, dynamics); code.add(new NewDynamic(getLineStart()), locals, dynamics); dynamics = dynamics.map(DynamicVar::incDynamic).cons(new DynamicVar(b.name, 0)); } for (Binding b : Binding.valueBindings(bindings)) { b.getValue().compile(locals, dynamics, code, false); code.add( new SetDynamic(b.getValue().getLineStart(), lookup(b.name, dynamics).getIndex()), locals, dynamics); code.add(new Pop(b.getValue().getLineStart()), locals, dynamics); } orderExports(dynamics); name.compile(locals, dynamics, code, false); compileBehaviour(locals, dynamics, code); // Remove the dynamics... for (Binding b : Binding.valueBindings(bindings)) { code.add(new PopDynamic(getLineStart()), locals, dynamics); dynamics = dynamics.getTail(); } }
private void compileApplyDynamic( List<FrameVar> locals, List<DynamicVar> dynamics, CodeBox code, boolean isLast) { code.add(new StartCall(getLineStart()), locals, dynamics); for (AST arg : args) arg.compile(locals, dynamics, code, false); Var v = (Var) op; lookup(v.name, dynamics).apply(args.length, getLineStart(), code, locals, dynamics, isLast); }
private void compileApplyFun( List<FrameVar> locals, List<DynamicVar> dynamics, CodeBox code, boolean isLast) { code.add(new StartCall(getLineStart()), locals, dynamics); for (AST arg : args) arg.compile(locals, dynamics, code, false); Fun fun = (Fun) op; fun.compileApply(locals, dynamics, code, isLast); }
public void compile( List<FrameVar> locals, List<DynamicVar> dynamics, CodeBox code, boolean isLast) { // The expressions matched by the case arms are set in the stack frame as // locals... int base = locals.length(); int index = 0; for (AST exp : exps) { exp.compile(locals, dynamics, code, false); locals = locals.cons(new FrameVar("$case-" + (index++), locals.length())); code.add(new SetFrame(getLineStart(), locals.length() - 1), locals, dynamics); code.add(new Pop(getLineStart()), locals, dynamics); } compileArms(base, locals, dynamics, code, isLast); }
public void compileBehaviour(List<FrameVar> locals, List<DynamicVar> dynamics, CodeBox code) { // Compilation of a behaviour produces a closure-like value that captures // the current // dynamics and waits to be transformed into an actor via 'new'. CodeBox bodyCode = new CodeBox(path, maxLocals() + 1); // Message will be local 0 in the stack frame... locals = new Nil<FrameVar>().cons(new FrameVar("$0", 0)); bodyCode.add(new instrs.vars.FrameVar(getLineStart(), 0), locals, dynamics); Case handlers = new Case(getFirstHandlerLine(), getLineEnd(), new Dec[] {}, new AST[] {}, arms); handlers.compileArms(0, locals, dynamics, bodyCode, true); bodyCode.add(new Return(getLineStart()), locals, dynamics); int initIndex = bodyCode.getCode().size(); init.compile(locals, dynamics, bodyCode, false); bodyCode.add(new PopFrame(getLineStart()), locals, dynamics); // Set the locals + 1 since the message is the first local... code.add( new instrs.data.Behaviour( getLineStart(), toKeys(exports.getStrings()), initIndex, bodyCode, handlesTime()), locals, dynamics); }