static HRESULT compile_member_expression(compile_ctx_t *ctx, member_expression_t *expr, BOOL ret_val) { unsigned arg_cnt = 0; HRESULT hres; if(ret_val && !expr->args) { expression_t *const_expr; const_expr = lookup_const_decls(ctx, expr->identifier, TRUE); if(const_expr) return compile_expression(ctx, const_expr); } hres = compile_args(ctx, expr->args, &arg_cnt); if(FAILED(hres)) return hres; if(expr->obj_expr) { hres = compile_expression(ctx, expr->obj_expr); if(FAILED(hres)) return hres; hres = push_instr_bstr_uint(ctx, ret_val ? OP_mcall : OP_mcallv, expr->identifier, arg_cnt); }else { hres = push_instr_bstr_uint(ctx, ret_val ? OP_icall : OP_icallv, expr->identifier, arg_cnt); } return hres; }
static HRESULT compile_assignment(compile_ctx_t *ctx, member_expression_t *member_expr, expression_t *value_expr, BOOL is_set) { unsigned args_cnt; vbsop_t op; HRESULT hres; if(member_expr->obj_expr) { hres = compile_expression(ctx, member_expr->obj_expr); if(FAILED(hres)) return hres; op = is_set ? OP_set_member : OP_assign_member; }else { op = is_set ? OP_set_ident : OP_assign_ident; } hres = compile_expression(ctx, value_expr); if(FAILED(hres)) return hres; hres = compile_args(ctx, member_expr->args, &args_cnt); if(FAILED(hres)) return hres; return push_instr_bstr_uint(ctx, op, member_expr->identifier, args_cnt); }
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; }