private IMethod makeNullaryValueConstructor(IClass cls, Object value) { JSInstructionFactory insts = (JSInstructionFactory) cls.getClassLoader().getInstructionFactory(); MethodReference ref = JavaScriptMethods.makeCtorReference(cls.getReference()); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addStatement(insts.GetInstruction(4, 1, "prototype")); S.getNextProgramCounter(); S.addStatement( insts.NewInstruction( 5, NewSiteReference.make(S.getNextProgramCounter(), cls.getReference()))); S.addStatement(insts.SetPrototype(5, 4)); // S.addStatement(insts.PutInstruction(5, 4, "__proto__")); S.getNextProgramCounter(); S.addConstant(new Integer(8), new ConstantValue(value)); S.addStatement(insts.PutInstruction(5, 8, "$value")); S.getNextProgramCounter(); S.addStatement(insts.ReturnInstruction(5, false)); S.getNextProgramCounter(); // S.addConstant(9, new ConstantValue("__proto__")); return new JavaScriptConstructor(ref, S, cls); }
private IMethod makeNullaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory) cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addConstant(new Integer(2), new ConstantValue(0.0)); S.addStatement(insts.ReturnInstruction(2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls); }
private IMethod makeArrayContentsConstructor(IClass cls, int nargs) { JSInstructionFactory insts = (JSInstructionFactory) cls.getClassLoader().getInstructionFactory(); MethodReference ref = JavaScriptMethods.makeCtorReference(JavaScriptTypes.Array); JavaScriptSummary S = new JavaScriptSummary(ref, nargs + 1); S.addConstant(new Integer(nargs + 3), new ConstantValue("prototype")); S.addStatement(insts.PropertyRead(nargs + 4, 1, nargs + 3)); S.getNextProgramCounter(); S.addStatement( insts.NewInstruction( nargs + 5, NewSiteReference.make(S.getNextProgramCounter(), JavaScriptTypes.Array))); S.addStatement(insts.SetPrototype(nargs + 5, nargs + 4)); // S.addStatement(insts.PutInstruction(nargs + 5, nargs + 4, "__proto__")); S.getNextProgramCounter(); S.addConstant(new Integer(nargs + 7), new ConstantValue(nargs)); S.addStatement(insts.PutInstruction(nargs + 5, nargs + 7, "length")); S.getNextProgramCounter(); int vn = nargs + 9; for (int i = 0; i < nargs; i++, vn += 2) { S.addConstant(new Integer(vn), new ConstantValue(i)); S.addStatement(insts.PropertyWrite(nargs + 5, vn, i + 1)); S.getNextProgramCounter(); } S.addStatement(insts.ReturnInstruction(5, false)); S.getNextProgramCounter(); // S.addConstant(vn, new ConstantValue("__proto__")); return new JavaScriptConstructor(ref, S, cls); }