Search in sources :

Example 6 with RuntimeInstUnary

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

the class StmtIf method genCode.

@Override
public void genCode(ICodegen codegen) {
    exp.genCode(codegen);
    RuntimeInstUnary jf = codegen.genCode(RuntimeInst.ijf, -1);
    trueBlock.genCode(codegen);
    if (falseBlock != null) {
        RuntimeInstUnary jmp = codegen.genCode(RuntimeInst.ijmp, -1);
        jf.op1 = codegen.getCodeIndex();
        falseBlock.genCode(codegen);
        jmp.op1 = codegen.getCodeIndex();
    } else {
        jf.op1 = codegen.getCodeIndex();
    }
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary)

Example 7 with RuntimeInstUnary

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

the class StmtWhile method genCode.

@Override
public void genCode(ICodegen codegen) {
    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();
    cond.genCode(codegen);
    codegen.genCode(RuntimeInst.ijf, cb.breakId);
    codegen.getBlockService().enterBlockEntry(cb);
    block.genCode(codegen);
    codegen.getBlockService().leaveBlockEntry();
    continueJmp.op1 = codegen.getCodeIndex();
    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 8 with RuntimeInstUnary

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

the class ExpBinop method genCode.

@Override
public void genCode(ICodegen codegen) {
    if (token.kToken == TokenType.OPERATOR && token.object == OperatorType.DOT) {
        codegen.genCode(RuntimeInst.iopena);
        leftOperand.genCode(codegen);
        codegen.genCode(RuntimeInst.ipusha);
        rightOperand.genCode(codegen);
        codegen.genCode(RuntimeInst.ipusha);
        codegen.genCode(RuntimeInst.ipush, codegen.genDataRef("g_get_property"));
        codegen.genCode(RuntimeInst.icallx);
        return;
    }
    if (token.kToken == TokenType.OPERATOR) {
        OperatorType op = (OperatorType) token.object;
        if (TokenTools.isAssignment(op)) {
            RuntimeInst ins = TokenTools.op2ins(token);
            ExpValue left = (ExpValue) leftOperand;
            if (ins == RuntimeInst.ice) {
                rightOperand.genCode(codegen);
                codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(left.getToken().object));
                codegen.genCode(RuntimeInst.istore);
                return;
            }
            leftOperand.genCode(codegen);
            rightOperand.genCode(codegen);
            codegen.genCode(ins);
            codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(left.getToken().object));
            codegen.genCode(RuntimeInst.istore);
            return;
        } else if (op == OperatorType.COLON) {
            rightOperand.genCode(codegen);
            leftOperand.genCode(codegen);
            return;
        }
    }
    RuntimeInst inst = TokenTools.op2ins(token);
    leftOperand.genCode(codegen);
    RuntimeInstUnary jmp = null;
    switch(inst) {
        case iandl:
            jmp = codegen.genCode(RuntimeInst.ijfx, -1);
            break;
        case iorl:
            jmp = codegen.genCode(RuntimeInst.ijtx, -1);
            break;
        default:
            break;
    }
    rightOperand.genCode(codegen);
    codegen.genCode(inst);
    if (jmp != null) {
        jmp.op1 = codegen.getCodeIndex();
    }
}
Also used : RuntimeInstUnary(priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary) RuntimeInst(priv.bajdcc.LALR1.grammar.runtime.RuntimeInst) OperatorType(priv.bajdcc.util.lexer.token.OperatorType)

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