Search in sources :

Example 1 with Frame

use of st.gravel.support.compiler.jvm.Frame in project gravel by gravel-st.

the class JVMMethodCompiler method newFrame_.

public Frame newFrame_(final st.gravel.support.jvm.Block0<Object> _aBlock) {
    final JVMStack _oldStack;
    final List<JVMInstruction> _oldInstructions;
    final Frame _frame;
    final Map<String, JVMLocalDeclaration> _oldLocals;
    _oldStack = _stack;
    _oldInstructions = _instructions;
    _oldLocals = _locals;
    this.reset();
    _locals = st.gravel.support.jvm.DictionaryExtensions.copy(_oldLocals);
    _aBlock.value();
    _frame = Frame.factory.instructions_endStack_(_instructions.toArray(new JVMInstruction[_instructions.size()]), _stack);
    _stack = _oldStack;
    _instructions = _oldInstructions;
    _locals = _oldLocals;
    return _frame;
}
Also used : Frame(st.gravel.support.compiler.jvm.Frame) JVMLocalDeclaration(st.gravel.support.compiler.jvm.JVMLocalDeclaration) PushString(st.gravel.support.compiler.jvm.PushString) JVMStack(st.gravel.support.compiler.jvm.JVMStack) JVMInstruction(st.gravel.support.compiler.jvm.JVMInstruction)

Example 2 with Frame

use of st.gravel.support.compiler.jvm.Frame in project gravel by gravel-st.

the class JVMMethodCompiler method newSubFrame_.

public Frame newSubFrame_(final st.gravel.support.jvm.Block0<Object> _aBlock) {
    final JVMStack _oldStack;
    final List<JVMInstruction> _oldInstructions;
    final Frame _frame;
    final Map<String, JVMLocalDeclaration> _oldLocals;
    _oldStack = _stack;
    _oldInstructions = _instructions;
    _oldLocals = _locals;
    _locals = st.gravel.support.jvm.DictionaryExtensions.copy(_oldLocals);
    _instructions = new java.util.ArrayList();
    _stack = _oldStack.copy();
    _aBlock.value();
    _frame = Frame.factory.instructions_endStack_(_instructions.toArray(new JVMInstruction[_instructions.size()]), _stack);
    _stack = _oldStack;
    _instructions = _oldInstructions;
    _locals = _oldLocals;
    return _frame;
}
Also used : Frame(st.gravel.support.compiler.jvm.Frame) JVMLocalDeclaration(st.gravel.support.compiler.jvm.JVMLocalDeclaration) PushString(st.gravel.support.compiler.jvm.PushString) JVMStack(st.gravel.support.compiler.jvm.JVMStack) JVMInstruction(st.gravel.support.compiler.jvm.JVMInstruction) ArrayList(java.util.ArrayList)

Example 3 with Frame

use of st.gravel.support.compiler.jvm.Frame in project gravel by gravel-st.

the class JVMMethodCompiler method produceToDoNodeConstantStep_step_.

public JVMMethodCompiler produceToDoNodeConstantStep_step_(final ToDoNode _toDoNode, final int _step) {
    this.emit_(this.newFrame_(new st.gravel.support.jvm.Block0<Object>() {

        @Override
        public Object value() {
            final String _stop;
            final String _startObj;
            final String _stopObj;
            _startObj = JVMMethodCompiler.this.newTempName();
            _stopObj = JVMMethodCompiler.this.newTempName();
            JVMMethodCompiler.this.pushLocal_(_startObj);
            JVMMethodCompiler.this.pushLocal_(_stopObj);
            JVMMethodCompiler.this.visit_(_toDoNode.start());
            JVMMethodCompiler.this.localStore_(_startObj);
            JVMMethodCompiler.this.visit_(_toDoNode.stop());
            JVMMethodCompiler.this.localStore_(_stopObj);
            JVMMethodCompiler.this.pushLocal_type_(_toDoNode.counterName(), JVMIntType.factory.basicNew());
            _stop = JVMMethodCompiler.this.newTempName();
            JVMMethodCompiler.this.pushLocal_type_(_stop, JVMIntType.factory.basicNew());
            return JVMMethodCompiler.this.try_do_exception_catch_(new st.gravel.support.jvm.Block0<Object>() {

                @Override
                public Object value() {
                    JVMMethodCompiler.this.produceVarRead_(_stopObj);
                    JVMMethodCompiler.this.produceVarRead_(_startObj);
                    JVMMethodCompiler.this.localStore_(_toDoNode.counterName());
                    return JVMMethodCompiler.this.localStore_(_stop);
                }
            }, new st.gravel.support.jvm.Block0<Object>() {

                @Override
                public Object value() {
                    final Frame _testFrame;
                    final Frame _doFrame;
                    _testFrame = JVMMethodCompiler.this.newFrame_(new st.gravel.support.jvm.Block0<Object>() {

                        @Override
                        public Object value() {
                            JVMMethodCompiler.this.produceVarRead_(_toDoNode.counterName());
                            return JVMMethodCompiler.this.produceVarRead_(_stop);
                        }
                    });
                    _doFrame = JVMMethodCompiler.this.newFrame_(new st.gravel.support.jvm.Block0<Object>() {

                        @Override
                        public Object value() {
                            JVMMethodCompiler.this.visit_(_toDoNode.doSequence());
                            JVMMethodCompiler.this.trashStack();
                            return JVMMethodCompiler.this.emit_(IncrementLocal.factory.local_increment_(_locals.get(_toDoNode.counterName()), _step));
                        }
                    });
                    return JVMMethodCompiler.this.emit_((_step > 0) ? WhileLessThanLoop.factory.testFrame_doFrame_(_testFrame, _doFrame) : WhileGreaterThanLoop.factory.testFrame_doFrame_(_testFrame, _doFrame));
                }
            }, JVMDefinedObjectType.factory.classCastException(), new st.gravel.support.jvm.Block0<Object>() {

                @Override
                public Object value() {
                    JVMMethodCompiler.this.emit_(Pop.factory.basicNew());
                    JVMMethodCompiler.this.renameLocal_to_(_toDoNode.counterName(), JVMMethodCompiler.this.newTempName());
                    return JVMMethodCompiler.this.produceSafe_to_counterName_step_do_(_startObj, _stopObj, _toDoNode.counterName(), _step, _toDoNode.doSequence());
                }
            });
        }
    }));
    this.pushNull();
    return this;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) Frame(st.gravel.support.compiler.jvm.Frame) PushString(st.gravel.support.compiler.jvm.PushString)

Aggregations

Frame (st.gravel.support.compiler.jvm.Frame)3 PushString (st.gravel.support.compiler.jvm.PushString)3 ArrayList (java.util.ArrayList)2 JVMInstruction (st.gravel.support.compiler.jvm.JVMInstruction)2 JVMLocalDeclaration (st.gravel.support.compiler.jvm.JVMLocalDeclaration)2 JVMStack (st.gravel.support.compiler.jvm.JVMStack)2 List (java.util.List)1 TypeCast (st.gravel.support.compiler.ast.TypeCast)1