aboutsummaryrefslogtreecommitdiff
path: root/src/exact_value.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-07-24 22:27:45 +0100
committerGitHub <noreply@github.com>2022-07-24 22:27:45 +0100
commit02a8bba02e6d5a499781dcb362803533c34ab1f1 (patch)
tree5aa0c61eed5fc1f6ed25d735641fb56246f6c806 /src/exact_value.cpp
parent6ea68869c934807f1ecdc411e58bdce6b64ee7e2 (diff)
parenta3afe617c218736563723fd1ab343f403bdd33f0 (diff)
Merge branch 'master' into fix/freebsd-syscall
Diffstat (limited to 'src/exact_value.cpp')
-rw-r--r--src/exact_value.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/exact_value.cpp b/src/exact_value.cpp
index fd90278e5..175cb61f6 100644
--- a/src/exact_value.cpp
+++ b/src/exact_value.cpp
@@ -50,9 +50,9 @@ struct ExactValue {
union {
bool value_bool;
String value_string;
- BigInt value_integer; // NOTE(bill): This must be an integer and not a pointer
+ BigInt value_integer;
f64 value_float;
- i64 value_pointer;
+ i64 value_pointer; // NOTE(bill): This must be an integer and not a pointer
Complex128 *value_complex;
Quaternion256 *value_quaternion;
Ast * value_compound;
@@ -177,7 +177,11 @@ ExactValue exact_value_typeid(Type *type) {
ExactValue exact_value_integer_from_string(String const &string) {
ExactValue result = {ExactValue_Integer};
- big_int_from_string(&result.value_integer, string);
+ bool success;
+ big_int_from_string(&result.value_integer, string, &success);
+ if (!success) {
+ result = {ExactValue_Invalid};
+ }
return result;
}
@@ -591,6 +595,7 @@ failure:
i32 exact_value_order(ExactValue const &v) {
switch (v.kind) {
case ExactValue_Invalid:
+ case ExactValue_Compound:
return 0;
case ExactValue_Bool:
case ExactValue_String:
@@ -607,8 +612,6 @@ i32 exact_value_order(ExactValue const &v) {
return 6;
case ExactValue_Procedure:
return 7;
- // case ExactValue_Compound:
- // return 8;
default:
GB_PANIC("How'd you get here? Invalid Value.kind %d", v.kind);
@@ -630,6 +633,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 +677,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 +935,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);