summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rwxr-xr-xbuild.sh4
-rw-r--r--eval.c39
-rw-r--r--main.c10
-rw-r--r--test.toc7
-rw-r--r--types.c2
-rw-r--r--types.h6
7 files changed, 39 insertions, 32 deletions
diff --git a/README.md b/README.md
index a7aa712..5286dfd 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/build.sh b/build.sh
index 4c26cc7..6e1628c 100755
--- a/build.sh
+++ b/build.sh
@@ -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
diff --git a/eval.c b/eval.c
index bf897ed..da173d8 100644
--- a/eval.c
+++ b/eval.c
@@ -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
diff --git a/main.c b/main.c
index a78648b..669835a 100644
--- a/main.c
+++ b/main.c
@@ -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
diff --git a/test.toc b/test.toc
index d8f9f00..c85a94a 100644
--- a/test.toc
+++ b/test.toc
@@ -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);
+ }
}
diff --git a/types.c b/types.c
index e86bf40..1f3261c 100644
--- a/types.c
+++ b/types.c
@@ -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;
diff --git a/types.h b/types.h
index 9affa5e..d9fc550 100644
--- a/types.h
+++ b/types.h
@@ -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