bool assembler::compile_next(asmgen & asg, const func_binary & fb) { command cmd = GET_CMD(fb, m_pos); int type = COMMAND_TYPE(cmd); int code = COMMAND_CODE(cmd); USE(type); FKLOG("[assembler] compile_next cmd %d %d %s", type, code, OpCodeStr(code)); assert (type == COMMAND_OPCODE); m_pos++; m_conposnum = 0; memset(m_conpos, 0, sizeof(m_conpos)); bool ret = false; USE(ret); // 执行对应命令,放一起switch效率更高,cpu有缓存 switch (code) { case OPCODE_ASSIGN: { ret = compile_assign(asg, fb, cmd); } break; case OPCODE_RETURN: { ret = compile_return(asg, fb, cmd); } break; case OPCODE_PLUS: case OPCODE_MINUS: case OPCODE_MULTIPLY: case OPCODE_DIVIDE: case OPCODE_DIVIDE_MOD: { ret = compile_math(asg, fb, cmd); } break; case OPCODE_PLUS_ASSIGN: case OPCODE_MINUS_ASSIGN: case OPCODE_MULTIPLY_ASSIGN: case OPCODE_DIVIDE_ASSIGN: case OPCODE_DIVIDE_MOD_ASSIGN: { ret = compile_math_assign(asg, fb, cmd); } break; case OPCODE_AND: case OPCODE_OR: case OPCODE_LESS: case OPCODE_MORE: case OPCODE_EQUAL: case OPCODE_MOREEQUAL: case OPCODE_LESSEQUAL: case OPCODE_NOTEQUAL: { ret = compile_cmp(asg, fb, cmd); } break; case OPCODE_AND_JNE: case OPCODE_OR_JNE: case OPCODE_LESS_JNE: case OPCODE_MORE_JNE: case OPCODE_EQUAL_JNE: case OPCODE_MOREEQUAL_JNE: case OPCODE_LESSEQUAL_JNE: case OPCODE_NOTEQUAL_JNE: { ret = compile_cmp_jne(asg, fb, cmd); } break; case OPCODE_NOT: { ret = compile_single(asg, fb, cmd); } break; case OPCODE_NOT_JNE: { ret = compile_single_jne(asg, fb, cmd); } break; case OPCODE_JNE: { ret = compile_jne(asg, fb, cmd); } break; case OPCODE_JMP: { ret = compile_jmp(asg, fb, cmd); } break; case OPCODE_CALL: { ret = compile_call(asg, fb, cmd); } break; case OPCODE_SLEEP: case OPCODE_YIELD: { setwarn(m_fk, "assembler only support SLEEP or YIELD, skip code"); ret = true; m_pos++; } break; case OPCODE_FORBEGIN: case OPCODE_FORLOOP: { FKERR("assembler dont support for i -> n, j"); compile_seterror(fb, cmd, efk_jit_error, "assembler dont support for i -> n, j"); return false; } break; default: assert(0); FKERR("[assembler] compile_next err code %d %s", code, OpCodeStr(code)); compile_seterror(fb, cmd, efk_jit_error, "compile_next err code %d %s", code, OpCodeStr(code)); return false; } return ret; }
Type compile(const Node& l, const Node& r, const BinaryOperator& op, Context& ctx) { switch(op) { case(Operator('.')): break; case(Operator('(',')')): { auto r_type = r.compile(ctx); if(r_type != TypeKind::argument_list) { r_type.print(); printf("\n実引数のリストではありません\n"); throw; } auto l_type = l.compile(ctx); if(l_type != TypeKind::function) { l_type.print(); printf("\n関数ではありません\n"); throw; } // return *l_type.get_referred_type(); } break; case(Operator('[',']')): break; case(Operator('*')): case(Operator('/')): case(Operator('%')): case(Operator('+')): case(Operator('-')): case(Operator('<','<')): case(Operator('>','>')): case(Operator('<') ): case(Operator('<','=')): case(Operator('>') ): case(Operator('>','=')): case(Operator('=','=')): case(Operator('!','=')): case(Operator('&')): case(Operator('|')): case(Operator('^')): case(Operator('&','&')): case(Operator('|','|')): return compile_arithmetic(l,r,op,ctx); break; case(Operator('<','<','=')): case(Operator('>','>','=')): case(Operator('+','=')): case(Operator('-','=')): case(Operator('*','=')): case(Operator('/','=')): case(Operator('%','=')): case(Operator('&','=')): case(Operator('|','=')): case(Operator('^','=')): case(Operator('=') ): return compile_assign(l,r,op,ctx); break; default:; } return Type(); }