Package org.perl6.nqp.runtime

Examples of org.perl6.nqp.runtime.IOOps


    }

    private JavaClass compileJast(SixModelObject jast, SixModelObject jastNodes, boolean split, ThreadContext tc) throws Exception {

        SixModelObject jastClassObj = jastNodes.at_key_boxed(tc, "JAST::Class");
        SixModelObject jastField = jastNodes.at_key_boxed(tc, "JAST::Field");
        SixModelObject jastMethod = jastNodes.at_key_boxed(tc, "JAST::Method");

        JastClass jastClass = new JastClass(jast, jastClassObj, tc);
        JavaClass c = new JavaClass();

        c.name = jastClass.className;
        c.serialized = jastClass.serialized;

        String className = jastClass.className.replace('.', '/');
        String superName = jastClass.superName.replace('.', '/');

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        cw.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className, null,
                superName, null);
        cw.visitSource(jastClass.filename, null);

        SixModelObject iter = iter(jastClass.fields, tc);
        while (istrue(iter, tc) != 0) {
            JastField field = new JastField(iter.shift_boxed(tc), jastField, tc);

            cw.visitField(
                    field.isStatic
                        ? Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC
                        : Opcodes.ACC_PUBLIC,
                    field.name, field.type.getDescriptor(), null, null);
        }

        iter = iter(jastClass.methods, tc);
        while (istrue(iter, tc) != 0) {
            JastMethod method = new JastMethod(iter.shift_boxed(tc), jastMethod, tc);
            compileMethod(c, method, cw, className, split, tc);
        }

        // Add empty constructor.
        MethodVisitor constructor = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
View Full Code Here


            method.locals.put("this", new VariableDef(0, "L"+className+";", method.beginAll, method.endAll));

        m.visitCode();
        m.visitLabel(method.beginAll);

        SixModelObject iter = iter(method.instructions, tc);
        while (istrue(iter, tc) != 0) {
            SixModelObject insn = iter.shift_boxed(tc);
            compileInstruction(insn, method, m, tc);
        }

        m.visitLabel(method.endAll);
        for (Map.Entry<String, VariableDef> e : method.locals.entrySet()) {
View Full Code Here

        }
        else if (istype(insn, jastIndy, tc) != 0) {
            emitInvokeDynamic(insn, m, tc);
        }
        else if (istype(insn, jastInstructionList, tc) != 0) {
            SixModelObject iter = iter(getattr(insn, jastInstructionList, "@!instructions", 0, tc), tc);
            while (istrue(iter, tc) != 0) {
                compileInstruction(iter.shift_boxed(tc), method, m, tc);
            }
        }
        else {
            throw new Exception("Unknown JAST::Node in @!instructions");
        }
View Full Code Here

        }
    }

    private void emitInstruction(SixModelObject insn, JastMethod method, MethodVisitor m, ThreadContext tc) throws Exception {
        int instruction = (int) getattr_i(insn, jastInstruction, "$!op", 0, tc);
        SixModelObject args = getattr(insn, jastInstruction, "@!args", 1, tc);

        // Go by instruction.
        switch (instruction) {
        case 0x00: // nop
        case 0x01: //aconst_null
View Full Code Here

                ThreadContext curTC = tc.gc.getCurrentThreadContext();
                callback(curTC, task, IOType, Ops.box_s(t.toString(), Str, curTC));
            }

            protected void callback(ThreadContext tc, AsyncTaskInstance task, SixModelObject ioHandle, SixModelObject err) {
                SixModelObject result = Array.st.REPR.allocate(tc, Array.st);
                result.push_boxed(tc, task.schedulee);
                result.push_boxed(tc, ioHandle);
                result.push_boxed(tc, err);
                ((ConcBlockingQueueInstance) task.queue).push_boxed(tc, result);
            }
        };

        try {
View Full Code Here

                Type.getMethodDescriptor(returnType, argumentTypes));
    }

    private void emitInvokeDynamic(SixModelObject insn, MethodVisitor m, ThreadContext tc) {
        String name = getattr(insn, jastIndy, "$!name", 0, tc).get_str(tc);
        SixModelObject argTypesSmo = getattr(insn, jastIndy, "@!arg_types", 1, tc);
        Type retType = processType(getattr(insn, jastIndy, "$!ret_type", 2, tc).get_str(tc));
        String bsmType = getattr(insn, jastIndy, "$!bsm_type", 3, tc).get_str(tc);
        String bsmName = getattr(insn, jastIndy, "$!bsm_name", 4, tc).get_str(tc);
        SixModelObject extraArgsSmo = getattr(insn, jastIndy, "@!extra_args", 5, tc);

        int numArgs = (int) argTypesSmo.elems(tc);
        Type[] argTypes = new Type[numArgs];
        for (int i = 0; i < numArgs; i++) {
            argTypes[i] = processType(atpos(argTypesSmo, i, tc).get_str(tc));
        }

        int numExtraArgs = (int) extraArgsSmo.elems(tc);
        MethodType bsmMT = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class,
                java.lang.String.class, MethodType.class);

        Object[] extraArgs = new Object[numExtraArgs];
        for (int i = 0; i < numExtraArgs; i++) {
            SixModelObject extra = atpos(extraArgsSmo, i, tc);
            if (istype(extra, jastPushI, tc) != 0) {
                extraArgs[i] = getattr_i(extra, jastPushI, "$!value", 0, tc);
                bsmMT = bsmMT.appendParameterTypes(long.class);
            }
            else if (istype(extra, jastPushN, tc) != 0) {
View Full Code Here

    }

    private void writeByteBuffer(final ThreadContext tc, final AsyncTaskInstance task, ByteBuffer buffer) {
        try {
            HLLConfig hllConfig = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig;
            final SixModelObject Array = hllConfig.listType;
            final SixModelObject Int = hllConfig.intBoxType;
            final SixModelObject Null = hllConfig.nullValue;
            final SixModelObject Str = hllConfig.strBoxType;

            CompletionHandler<Integer, AsyncTaskInstance> handler
                = new CompletionHandler<Integer, AsyncTaskInstance>() {

                @Override
                public void completed(Integer bytesWritten, AsyncTaskInstance task) {
                    ThreadContext curTC = tc.gc.getCurrentThreadContext();
                    callback(curTC, task, Ops.box_i(bytesWritten, Int, curTC), Null);
                }

                @Override
                public void failed(Throwable t, AsyncTaskInstance attachment) {
                    ThreadContext curTC = tc.gc.getCurrentThreadContext();
                    callback(curTC, task, Str, Ops.box_s(t.toString(), Str, curTC));
                }

                protected void callback(ThreadContext tc, AsyncTaskInstance task, SixModelObject bytesWritten, SixModelObject err) {
                    SixModelObject result = Array.st.REPR.allocate(tc, Array.st);
                    result.push_boxed(tc, task.schedulee);
                    result.push_boxed(tc, bytesWritten);
                    result.push_boxed(tc, err);
                    ((ConcBlockingQueueInstance) task.queue).push_boxed(tc, result);
                }
            };

            channel.write(buffer, task, handler);
View Full Code Here

        }
    }

    public void readChars(final ThreadContext tc, final AsyncTaskInstance task) {
        HLLConfig hllConfig = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig;
        final SixModelObject Str = hllConfig.strBoxType;

        readSocket(tc, task, new Decoder () {
            final CharBuffer decodedBuffer = CharBuffer.allocate(32768);

            public SixModelObject decode(ThreadContext tc, ByteBuffer source, Integer numRead) throws Exception {
View Full Code Here

    public void readBytes(final ThreadContext tc, final AsyncTaskInstance task, final SixModelObject bufType) {
        readSocket(tc, task, new Decoder() {
            public SixModelObject decode(ThreadContext tc, ByteBuffer source, Integer numRead)
                    throws Exception {
                SixModelObject res = bufType.st.REPR.allocate(tc, bufType.st);
                byte[] bytes = new byte[source.remaining()];
                source.get(bytes);
                Buffers.stashBytes(tc, res, bytes);
                return res;
            }
View Full Code Here

    private void readSocket(final ThreadContext tc, final AsyncTaskInstance task, final Decoder decoder) {
        final ByteBuffer readBuffer = ByteBuffer.allocate(32768);

        HLLConfig hllConfig = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig;
        final SixModelObject Array = hllConfig.listType;
        final SixModelObject Int = hllConfig.intBoxType;
        final SixModelObject Str = hllConfig.strBoxType;
        final SixModelObject Null = hllConfig.nullValue;

        CompletionHandler<Integer, AsyncTaskInstance> handler
        = new CompletionHandler<Integer, AsyncTaskInstance>() {

            @Override
            public void completed(Integer numRead, AsyncTaskInstance task) {
                ThreadContext curTC = tc.gc.getCurrentThreadContext();

                try {
                    if (numRead == -1) {
                        task.seq = -1;
                        callback(curTC, task, -1, Str, Null);
                    } else {
                        readBuffer.flip();
                        SixModelObject decoded = decoder.decode(tc, readBuffer, numRead);
                        readBuffer.compact();

                        callback(curTC, task, task.seq++, decoded, Null);

                        channel.read(readBuffer, task, this);
                    }
                } catch (Throwable t) {
                    failed(t, task);
                }
            }

            @Override
            public void failed(Throwable t, AsyncTaskInstance task) {
                ThreadContext curTC = tc.gc.getCurrentThreadContext();
                SixModelObject err = (t instanceof AsynchronousCloseException)
                        ? Str : Ops.box_s(t.toString(), Str, curTC);
                callback(curTC, task, -1, Str, err);
            }

            protected void callback(ThreadContext tc, AsyncTaskInstance task, long seq, SixModelObject str, SixModelObject err) {
                SixModelObject result = Array.st.REPR.allocate(tc, Array.st);
                result.push_boxed(tc, task.schedulee);
                result.push_boxed(tc, Ops.box_i(seq, Int, tc));
                result.push_boxed(tc, str);
                result.push_boxed(tc, err);
                ((ConcBlockingQueueInstance) task.queue).push_boxed(tc, result);
            }
        };

        try {
View Full Code Here

TOP

Related Classes of org.perl6.nqp.runtime.IOOps

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.