diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-08 00:15:36 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-08 00:15:58 -0400 |
commit | b7070892055fbf4a278657a4f108fa5b2558418c (patch) | |
tree | e8f8a54437804030c54200ee106bb4edc7fbfa1b | |
parent | b6cf5163c8a3a8acec2eb0cc56d00394b652691e (diff) |
fixed compiler warnings about pointer casting
-rw-r--r-- | README.md | 3 | ||||
-rwxr-xr-x | build.sh | 4 | ||||
-rw-r--r-- | eval.c | 39 | ||||
-rw-r--r-- | main.c | 10 | ||||
-rw-r--r-- | test.toc | 7 | ||||
-rw-r--r-- | types.c | 2 | ||||
-rw-r--r-- | types.h | 6 |
7 files changed, 39 insertions, 32 deletions
@@ -64,10 +64,9 @@ Here are all the C99 features which `toc` depends on (I might have forgotten som - Flexible array members - `snprintf` -And here are all of its C11 features: +And here are all of its (mandatory) C11 features: - Anonymous structures/unions -- `max_align_t` - It can still compile without this, and will almost definitely work, but it won't technically be standard-compliant #### More @@ -16,9 +16,9 @@ ADDITIONAL_FLAGS="$CFLAGS -Wno-unused-function" if [ "$CC" = "clang" ]; then WARNINGS='-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wimplicit-fallthrough -Wno-missing-braces' elif [ "$CC" = "gcc" ]; then - WARNINGS='-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wno-pointer-to-int-cast' + WARNINGS='-Wall -Wextra -Wpedantic -Wshadow -Wconversion' elif [ "$CC" = "tcc" ]; then - WARNINGS='-w' + WARNINGS='-Wall' elif [ "$CC" = "g++" ]; then WARNINGS='-w -fpermissive' else @@ -120,18 +120,27 @@ static void i64_to_val(Value *v, BuiltinType v_type, I64 x) { static void u64_to_val(Value *v, BuiltinType v_type, U64 x) { switch (v_type) { + case BUILTIN_I8: + v->i8 = (I8)x; break; + case BUILTIN_I16: + v->i16 = (I16)x; break; + case BUILTIN_I32: + v->i32 = (I32)x; break; + case BUILTIN_I64: + v->i64 = (I64)x; break; + case BUILTIN_U8: + v->u8 = (U8)x; break; + case BUILTIN_U16: + v->u16 = (U16)x; break; + case BUILTIN_U32: + v->u32 = (U32)x; break; case BUILTIN_U64: - v->u64 = x; - break; + v->u64 = (U64)x; break; case BUILTIN_F32: - v->f32 = (F32)x; - break; + v->f32 = (F32)x; break; case BUILTIN_F64: - v->f64 = (F64)x; - break; - default: - i64_to_val(v, v_type, (I64)x); - break; + v->f64 = (F64)x; break; + default: assert(0); break; } } @@ -299,19 +308,19 @@ static inline void val_free_ptr(Value *v, Type *t) { #define builtin_casts_to_int(x) \ case BUILTIN_I8: \ - vout->i8 = (I8)vin->x; break; \ + vout->i8 = (I8)(I64)vin->x; break; \ case BUILTIN_I16: \ - vout->i16 = (I16)vin->x; break; \ + vout->i16 = (I16)(I64)vin->x; break; \ case BUILTIN_I32: \ - vout->i32 = (I32)vin->x; break; \ + vout->i32 = (I32)(I64)vin->x; break; \ case BUILTIN_I64: \ vout->i64 = (I64)vin->x; break; \ case BUILTIN_U8: \ - vout->u8 = (U8)vin->x; break; \ + vout->u8 = (U8)(U64)vin->x; break; \ case BUILTIN_U16: \ - vout->u16 = (U16)vin->x; break; \ + vout->u16 = (U16)(U64)vin->x; break; \ case BUILTIN_U32: \ - vout->u32 = (U32)vin->x; break; \ + vout->u32 = (U32)(U64)vin->x; break; \ case BUILTIN_U64: \ vout->u64 = (U64)vin->x; break @@ -8,18 +8,13 @@ /* TODO: -fix tcc warnings about dubious pointer conversions -just use MaxAlign and remove long double--now we're using less memory use - - use with a decl, e.g. use p : Point; - - use with struct members - - make sure use works with functions and for, e.g. for use p := points - - exceptions (so that if you accidentally use something but have a function with the same - name you can still use the function) + - use with struct members (e.g. SuperPoint ::= struct { use p: Point; }) for accessing struct members (and other things, potentially) with struct["member"], just replace e with a BINARY_DOT local structs should not be named in C simplify eval macros with val_to_u/i64 +consider replacing weird EXPR_FOR system with just a declaration- would make "for use p := points" easier &&, || start making a standard library... (printf; stringbuilder would be nice to have) switch @@ -30,6 +25,7 @@ unions switch to / add as an alternative: libffi X ::= newtype(int); or something any odd number of "s for a string +use point #except x; optional -Wshadow --- make sure that floating point literals are exact as possible @@ -25,4 +25,11 @@ main ::= fn() { normalize(&p); fmt := "%f %f\n\0"; printf(&fmt[0], p.x, p.y); + ps: [10]Point; + ps[0].x = 12; + ps[7].y = 13; + for p := &ps { + use p; + printf(&fmt[0], x, y); + } } @@ -448,6 +448,7 @@ static Status type_of_fn(Typer *tr, FnExpr *f, Type *t, U16 flags) { Type *ret_type = typer_arr_add(tr, &t->fn.types); tr->fn = f; typer_block_enter(tr, &f->body); + f->body.uses = NULL; size_t nparams = arr_len(f->params); entered_fn = true; for (param_idx = 0; param_idx < nparams; ++param_idx) { @@ -541,7 +542,6 @@ static Status type_of_fn(Typer *tr, FnExpr *f, Type *t, U16 flags) { } } if (!generic) { - f->body.uses = NULL; if (!type_resolve(tr, &f->ret_type, f->where)) { success = false; goto ret; @@ -37,17 +37,13 @@ typedef long longlong; #endif -#if __STDC_VERSION__ < 201112 /* try to find the type with the strictest alignment */ typedef union { - long double floating; + double floating; void *ptr; longlong integer; void (*fn_ptr)(void); } MaxAlign; -#else -typedef max_align_t MaxAlign; -#endif typedef uint8_t U8; #define U8_MAX UINT8_MAX |