Search in sources :

Example 1 with RuntimeInstUnary

use of priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary in project jMiniLang by bajdcc.

the class ExpInvoke method genCode.

@Override
public void genCode(ICodegen codegen) {
    if (yield) {
        int yldLine = codegen.getCodeIndex();
        RuntimeInstUnary yld = codegen.genCode(RuntimeInst.ijyld, -1);
        if (func != null) {
            // call本地地址,1
            codegen.genCode(RuntimeInst.ipush, 1);
            codegen.genCode(RuntimeInst.iyldi);
            for (IExp exp : params) {
                exp.genCode(codegen);
                codegen.genCode(RuntimeInst.iyldi);
            }
            codegen.genCodeWithFuncWriteBack(RuntimeInst.ipush, codegen.getFuncIndex(func));
            codegen.genCode(RuntimeInst.iyldi);
        } else {
            if (invoke) {
                // call本地符号,2
                codegen.genCode(RuntimeInst.ipush, 2);
                codegen.genCode(RuntimeInst.iyldi);
            } else {
                // call外部模块,3
                codegen.genCode(RuntimeInst.ipush, 3);
                codegen.genCode(RuntimeInst.iyldi);
            }
            for (IExp exp : params) {
                exp.genCode(codegen);
                codegen.genCode(RuntimeInst.iyldi);
            }
            codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(extern.object));
            codegen.genCode(RuntimeInst.iyldi);
        }
        codegen.genCode(RuntimeInst.iyldy, yldLine);
        codegen.genCode(RuntimeInst.iyldo);
        RuntimeInstUnary jmp = codegen.genCode(RuntimeInst.ijmp, -1);
        yld.op1 = codegen.getCodeIndex();
        codegen.genCode(RuntimeInst.iyldr, yldLine);
        codegen.genCode(RuntimeInst.iyldo);
        jmp.op1 = codegen.getCodeIndex();
    } else {
        codegen.genCode(RuntimeInst.iopena);
        for (IExp exp : params) {
            exp.genCode(codegen);
            codegen.genCode(RuntimeInst.ipusha);
        }
        if (func != null) {
            codegen.genCodeWithFuncWriteBack(RuntimeInst.ipush, codegen.getFuncIndex(func));
            codegen.genCode(RuntimeInst.icall);
        } else {
            codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(extern.object));
            if (invoke) {
                codegen.genCode(RuntimeInst.ically);
            } else {
                codegen.genCode(RuntimeInst.icallx);
            }
        }
    }
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary)

Example 2 with RuntimeInstUnary

use of priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary in project jMiniLang by bajdcc.

the class ExpTriop method genCode.

@Override
public void genCode(ICodegen codegen) {
    firstOperand.genCode(codegen);
    RuntimeInstUnary jf = codegen.genCode(RuntimeInst.ijf, -1);
    secondOperand.genCode(codegen);
    RuntimeInstUnary jmp = codegen.genCode(RuntimeInst.ijmp, -1);
    jf.op1 = codegen.getCodeIndex();
    thirdOperand.genCode(codegen);
    jmp.op1 = codegen.getCodeIndex();
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary)

Example 3 with RuntimeInstUnary

use of priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary in project jMiniLang by bajdcc.

the class StmtTry method genCode.

@Override
public void genCode(ICodegen codegen) {
    RuntimeInstUnary t = codegen.genCode(RuntimeInst.itry, -1);
    codegen.genCode(RuntimeInst.iscpi);
    tryBlock.genCode(codegen);
    RuntimeInstUnary jmp = codegen.genCode(RuntimeInst.ijmp, -1);
    t.op1 = codegen.getCodeIndex();
    if (token != null) {
        // 'throw' push exp to stack top
        codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(token.object));
        codegen.genCode(RuntimeInst.ialloc);
    }
    catchBlock.genCode(codegen);
    jmp.op1 = codegen.getCodeIndex();
    codegen.genCode(RuntimeInst.ipop);
    codegen.genCode(RuntimeInst.iscpo);
    codegen.genCode(RuntimeInst.itry, -1);
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary)

Example 4 with RuntimeInstUnary

use of priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary in project jMiniLang by bajdcc.

the class StmtFor method genCode.

@Override
public void genCode(ICodegen codegen) {
    if (var != null) {
        var.genCode(codegen);
        codegen.genCode(RuntimeInst.ipop);
    }
    CodegenBlock cb = new CodegenBlock();
    RuntimeInstUnary start = codegen.genCode(RuntimeInst.ijmp, -1);
    cb.breakId = codegen.getCodeIndex();
    RuntimeInstUnary breakJmp = codegen.genCode(RuntimeInst.ijmp, -1);
    cb.continueId = codegen.getCodeIndex();
    RuntimeInstUnary continueJmp = codegen.genCode(RuntimeInst.ijmp, -1);
    start.op1 = codegen.getCodeIndex();
    if (cond != null) {
        cond.genCode(codegen);
        codegen.genCode(RuntimeInst.ijf, cb.breakId);
    }
    codegen.getBlockService().enterBlockEntry(cb);
    block.genCode(codegen);
    codegen.getBlockService().leaveBlockEntry();
    continueJmp.op1 = codegen.getCodeIndex();
    if (ctrl != null) {
        ctrl.genCode(codegen);
        codegen.genCode(RuntimeInst.ipop);
    }
    codegen.genCode(RuntimeInst.ijmp, start.op1);
    breakJmp.op1 = codegen.getCodeIndex();
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary) CodegenBlock(priv.bajdcc.LALR1.grammar.codegen.CodegenBlock)

Example 5 with RuntimeInstUnary

use of priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary in project jMiniLang by bajdcc.

the class StmtForeach method genCode.

@Override
public void genCode(ICodegen codegen) {
    codegen.genCode(RuntimeInst.ipushx);
    codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(var.object));
    codegen.genCode(RuntimeInst.ialloc);
    codegen.genCode(RuntimeInst.ipop);
    CodegenBlock cb = new CodegenBlock();
    RuntimeInstUnary start = codegen.genCode(RuntimeInst.ijmp, -1);
    cb.breakId = codegen.getCodeIndex();
    codegen.genCode(RuntimeInst.ipop);
    codegen.genCode(RuntimeInst.iyldx);
    RuntimeInstUnary breakJmp = codegen.genCode(RuntimeInst.ijmp, -1);
    cb.continueId = codegen.getCodeIndex();
    RuntimeInstUnary continueJmp = codegen.genCode(RuntimeInst.ijmp, -1);
    start.op1 = cb.continueId;
    int content = codegen.getCodeIndex();
    enumerator.genCode(codegen);
    codegen.genCode(RuntimeInst.ijnan, cb.breakId);
    codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(var.object));
    codegen.genCode(RuntimeInst.istore);
    codegen.genCode(RuntimeInst.ipop);
    codegen.getBlockService().enterBlockEntry(cb);
    block.genCode(codegen);
    codegen.getBlockService().leaveBlockEntry();
    continueJmp.op1 = codegen.getCodeIndex();
    codegen.genCode(RuntimeInst.ijmp, content);
    breakJmp.op1 = codegen.getCodeIndex();
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary) CodegenBlock(priv.bajdcc.LALR1.grammar.codegen.CodegenBlock)

Aggregations

RuntimeInstUnary (priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary)8 CodegenBlock (priv.bajdcc.LALR1.grammar.codegen.CodegenBlock)3 RuntimeInst (priv.bajdcc.LALR1.grammar.runtime.RuntimeInst)1 OperatorType (priv.bajdcc.util.lexer.token.OperatorType)1