diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-10-02 20:55:12 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-10-02 20:55:12 -0400 |
commit | e3634dd87fa6598610088e3d5622e6d35f80e19f (patch) | |
tree | 2b5e4a28691f563e499340cb966327b11cb187a4 | |
parent | f2ca07e37241e492c271f79633505c78b49f44a2 (diff) |
finished eval casting
-rwxr-xr-x | build.sh | 6 | ||||
-rw-r--r-- | eval.c | 97 | ||||
-rw-r--r-- | test.toc | 2 |
3 files changed, 96 insertions, 9 deletions
@@ -1,5 +1,5 @@ #!/bin/bash -CC=clang +CC=gcc # Possible extra build flags # these are for compiling the compiler, and NOT for compiling the program itself. @@ -7,12 +7,12 @@ CC=clang # - must be set if the zero value of a pointer (as might be set by calloc/memset) # is not the NULL pointer. -ADDITIONAL_FLAGS='-Wno-unused-function -Wno-unneeded-internal-declaration' +ADDITIONAL_FLAGS='-Wno-unused-function' if [[ $CC == "clang" ]]; then WARNINGS='-Wall -Wextra -Wpedantic -Wshadow -Wimplicit-fallthrough' else - WARNINGS='-Wall -Wextra -Wpedantic -Wshadow' + WARNINGS='-Wall -Wextra -Wpedantic -Wshadow -Wno-pointer-to-int-cast' fi DEBUG_FLAGS="-O0 -g3 $WARNINGS -std=c11 -DTOC_DEBUG" @@ -46,8 +46,9 @@ static bool builtin_truthiness(Value *v, BuiltinType b) { case BUILTIN_F64: return v->f64 != 0; case BUILTIN_BOOL: return v->boolv; case BUILTIN_CHAR: return v->charv != 0; - case BUILTIN_TYPE_COUNT: assert(0); return false; + case BUILTIN_TYPE_COUNT: break; } + assert(0); return false; } static bool val_truthiness(Value *v, Type *t) { @@ -174,7 +175,7 @@ static void val_builtin_cast(Value *vin, BuiltinType from, Value *vout, BuiltinT builtin_float_casts(f32, F32); builtin_float_casts(f64, F64); - case BUILTIN_BOOL: vout->boolv = builtin_truthiness(vin, from); + case BUILTIN_BOOL: vout->boolv = builtin_truthiness(vin, from); break; case BUILTIN_CHAR: switch (to) { builtin_casts_to_int(charv); @@ -191,6 +192,10 @@ static void val_builtin_cast(Value *vin, BuiltinType from, Value *vout, BuiltinT } static void val_cast(Value *vin, Type *from, Value *vout, Type *to) { + if (to->kind == TYPE_BUILTIN && to->builtin == BUILTIN_BOOL) { + vout->boolv = val_truthiness(vin, from); + return; + } switch (from->kind) { case TYPE_VOID: assert(0); break; case TYPE_UNKNOWN: assert(0); break; @@ -198,13 +203,95 @@ static void val_cast(Value *vin, Type *from, Value *vout, Type *to) { case TYPE_BUILTIN: switch (to->kind) { - case TYPE_VOID: assert(0); break; - case TYPE_UNKNOWN: assert(0); break; - case TYPE_TUPLE: assert(0); break; case TYPE_BUILTIN: val_builtin_cast(vin, from->builtin, vout, to->builtin); break; + case TYPE_PTR: + switch (from->builtin) { + case BUILTIN_I8: vout->ptr = (void *)(U64)vin->i8; break; + case BUILTIN_I16: vout->ptr = (void *)(U64)vin->i16; break; + case BUILTIN_I32: vout->ptr = (void *)(U64)vin->i32; break; + case BUILTIN_I64: vout->ptr = (void *)(U64)vin->i64; break; + case BUILTIN_U8: vout->ptr = (void *)(U64)vin->u8; break; + case BUILTIN_U16: vout->ptr = (void *)(U64)vin->u16; break; + case BUILTIN_U32: vout->ptr = (void *)(U64)vin->u32; break; + case BUILTIN_U64: vout->ptr = (void *)(U64)vin->u64; break; + default: assert(0); break; + } + break; + case TYPE_VOID: + case TYPE_UNKNOWN: + case TYPE_TUPLE: + case TYPE_FN: + case TYPE_ARR: + assert(0); + break; } + break; + + case TYPE_FN: + switch (to->kind) { + case TYPE_PTR: + vout->ptr = (void *)vin->fn; + break; + case TYPE_FN: + vout->fn = vin->fn; + break; + case TYPE_UNKNOWN: + case TYPE_TUPLE: + case TYPE_VOID: + case TYPE_ARR: + case TYPE_BUILTIN: + assert(0); break; + } + break; + + case TYPE_PTR: + switch (to->kind) { + case TYPE_BUILTIN: + switch (to->builtin) { + builtin_casts_to_int(ptr); + case BUILTIN_BOOL: + case BUILTIN_CHAR: + case BUILTIN_F32: + case BUILTIN_F64: + case BUILTIN_TYPE_COUNT: + assert(0); break; + } + break; + case TYPE_ARR: + vout->arr = vin->ptr; + break; + case TYPE_PTR: + vout->ptr = vin->ptr; + break; + case TYPE_FN: + vout->fn = vin->ptr; + break; + case TYPE_UNKNOWN: + case TYPE_TUPLE: + case TYPE_VOID: + assert(0); + break; + } + break; + + case TYPE_ARR: + switch (to->kind) { + case TYPE_PTR: + vout->ptr = vin->arr; + break; + case TYPE_ARR: + vout->arr = vin->arr; + break; + case TYPE_FN: + case TYPE_UNKNOWN: + case TYPE_TUPLE: + case TYPE_VOID: + case TYPE_BUILTIN: + assert(0); break; + } + break; } } @@ -1,5 +1,5 @@ main @= fn() { - a : [('a' as u8 as f32) / 2 + 0.5 as i8]int; + a : [('a' as u8 as f32) / 2 + 0.5 as i8 as &int as u64]int; // arr1 : ['a' as u8]int; // arr2 : [main as u64]int; // arr3 : [main as i64]int; |