Search in sources :

Example 1 with RuntimeInst

use of priv.bajdcc.LALR1.grammar.runtime.RuntimeInst 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

RuntimeInst (priv.bajdcc.LALR1.grammar.runtime.RuntimeInst)1 RuntimeInstUnary (priv.bajdcc.LALR1.grammar.runtime.RuntimeInstUnary)1 OperatorType (priv.bajdcc.util.lexer.token.OperatorType)1