Correct ExactValue_Pointer

This commit is contained in:
gingerBill
2022-02-22 22:59:00 +00:00
parent 8906a0120c
commit 62d232d798
2 changed files with 14 additions and 66 deletions

View File

@@ -630,6 +630,9 @@ void match_exact_values(ExactValue *x, ExactValue *y) {
case ExactValue_Bool:
case ExactValue_String:
case ExactValue_Quaternion:
case ExactValue_Pointer:
case ExactValue_Procedure:
case ExactValue_Typeid:
return;
case ExactValue_Integer:
@@ -671,9 +674,6 @@ void match_exact_values(ExactValue *x, ExactValue *y) {
return;
}
break;
case ExactValue_Procedure:
return;
}
compiler_error("match_exact_values: How'd you get here? Invalid ExactValueKind %d", x->kind);
@@ -932,6 +932,17 @@ bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) {
break;
}
case ExactValue_Pointer: {
switch (op) {
case Token_CmpEq: return x.value_pointer == y.value_pointer;
case Token_NotEq: return x.value_pointer != y.value_pointer;
case Token_Lt: return x.value_pointer < y.value_pointer;
case Token_LtEq: return x.value_pointer <= y.value_pointer;
case Token_Gt: return x.value_pointer > y.value_pointer;
case Token_GtEq: return x.value_pointer >= y.value_pointer;
}
}
case ExactValue_Typeid:
switch (op) {
case Token_CmpEq: return are_types_identical(x.value_typeid, y.value_typeid);

View File

@@ -3013,69 +3013,6 @@ i32 token_precedence(AstFile *f, TokenKind t) {
return 0;
}
// Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) {
// Ast *expr = parse_unary_expr(f, lhs);
// for (i32 prec = token_precedence(f, f->curr_token.kind); prec >= prec_in; prec--) {
// for (;;) {
// Token op = f->curr_token;
// i32 op_prec = token_precedence(f, op.kind);
// if (op_prec != prec) {
// // NOTE(bill): This will also catch operators that are not valid "binary" operators
// break;
// }
// Token prev = f->prev_token;
// switch (op.kind) {
// case Token_if:
// case Token_when:
// if (prev.pos.line < op.pos.line) {
// // NOTE(bill): Check to see if the `if` or `when` is on the same line of the `lhs` condition
// goto loop_end;
// }
// break;
// }
// expect_operator(f); // NOTE(bill): error checks too
// if (op.kind == Token_Question) {
// Ast *cond = expr;
// // Token_Question
// Ast *x = parse_expr(f, lhs);
// Token token_c = expect_token(f, Token_Colon);
// Ast *y = parse_expr(f, lhs);
// expr = ast_ternary_if_expr(f, x, cond, y);
// } else if (op.kind == Token_if || op.kind == Token_when) {
// Ast *x = expr;
// Ast *cond = parse_expr(f, lhs);
// Token tok_else = expect_token(f, Token_else);
// Ast *y = parse_expr(f, lhs);
// switch (op.kind) {
// case Token_if:
// expr = ast_ternary_if_expr(f, x, cond, y);
// break;
// case Token_when:
// expr = ast_ternary_when_expr(f, x, cond, y);
// break;
// }
// } else {
// Ast *right = parse_binary_expr(f, false, prec+1);
// if (right == nullptr) {
// syntax_error(op, "Expected expression on the right-hand side of the binary operator '%.*s'", LIT(op.string));
// }
// if (op.kind == Token_or_else) {
// // NOTE(bill): easier to handle its logic different with its own AST kind
// expr = ast_or_else_expr(f, expr, op, right);
// } else {
// expr = ast_binary_expr(f, op, expr, right);
// }
// }
// lhs = false;
// }
// loop_end:;
// }
// return expr;
// }
Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) {
Ast *expr = parse_unary_expr(f, lhs);
for (;;) {