expr_val * compile_statement(base_node * stmt, scope * scope, str_list * lines) { int op; switch (stmt->type) { case BINARY_OP_NODE: op = ((binary_op_node*) stmt)->op; switch(op) { case OP_EQUAL: return compile_assignment(((binary_op_node*) stmt), scope, lines); case OP_PLUS: return compile_addition(((binary_op_node*) stmt), scope, lines); case OP_TYPE_ASS: return compile_type_assignment(((binary_op_node*) stmt), scope, lines); case EQUAL: case LESS: case LESS_EQUAL: case GREATER: case GREATER_EQUAL: return compile_comparison_assignment(((binary_op_node*) stmt), scope, lines); } case IF_NODE: return compile_if((if_node*) stmt, scope, lines); case BLOCK_NODE: return compile_block((block_node *) stmt, scope, lines, 1); case ID_NODE: return compile_id(((id_node*) stmt), scope, lines); case INT_NODE: return compile_int((int_node*) stmt, scope, lines); case CHAR_NODE: return compile_char((char_node*) stmt, scope, lines); case INT_TYPE_NODE: return compile_int_type((type_node *) stmt, scope, lines); case CHAR_TYPE_NODE: return compile_char_type((type_node *) stmt, scope, lines); case FUNC_NODE: return compile_function((function_node*) stmt, scope, lines); case FUNC_ARGS_NODE: return compile_args((argument_node *) stmt, scope, lines); case RETURN_NODE: return compile_return((return_node *) stmt, scope, lines); case CALL_NODE: return compile_call((call_node *) stmt, scope, lines); case CALL_ARGS_NODE: return compile_call_args((argument_node *) stmt, scope, lines); case END_NODE: break; } return NULL; }
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; }