diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | a.c | 23 | ||||
-rw-r--r-- | a.toc | 6 | ||||
-rw-r--r-- | arr.c | 2 | ||||
-rw-r--r-- | copy.c | 1 | ||||
-rw-r--r-- | package.c | 5 | ||||
-rwxr-xr-x | pkg.sh | 2 | ||||
-rw-r--r-- | test.toc | 2 | ||||
-rw-r--r-- | types.c | 1 |
9 files changed, 11 insertions, 32 deletions
@@ -1,3 +1,4 @@ +a.c toc a.out out.c @@ -1,23 +0,0 @@ -#include <stdint.h> -#include <stdio.h> -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef float f32; -typedef double f64; -typedef u8 bool; -typedef struct { void *data; i64 n; } slice_; -#define false ((bool)0) -#define true ((bool)1) -static slice_ mkslice_(void *data, i64 n) { slice_ ret; ret.data = data; ret.n = n; return ret; } -static void free_(void *data) { extern void free(void *data); free(data); } -static void *e__calloc(size_t n, size_t sz) { extern void *calloc(size_t n, size_t size); extern void abort(void); void *ret = calloc(n, sz); if (n && sz && !ret) { fprintf(stderr, "Out of memory.\n"); abort(); } return ret; } - - -/* declarations */ -/* code */ @@ -7,7 +7,6 @@ pkg "a"; len, cap : int; } }; -/* #export arr_add ::= fn(t ::=, a : &Arr(t), x : t) { if a.len >= a.cap { a.cap = a.cap * 2 + 2; @@ -20,9 +19,10 @@ pkg "a"; a.data[a.len] = x; a.len += 1; }; - +/* #export arr_foreach ::= fn(t ::=, a : Arr(t), f : fn(&t)) { each i := 0..a.len-1 { f(&a.data[i]); } -};*/
\ No newline at end of file +}; +*/
\ No newline at end of file @@ -80,6 +80,8 @@ static void arr_set_len_(void **arr, size_t n, size_t item_sz) { static void arr_set_lena_(void **arr, size_t n, size_t item_sz, Allocator *a) { if (n == 0) { /* OPTIM: arr_cleara */ + *arr = NULL; + return; } arr_resva_(arr, n, item_sz, a); arr_hdr(*arr)->len = n; @@ -118,7 +118,6 @@ static void copy_type(Copier *c, Type *out, Type *in) { case TYPE_STRUCT: { out->struc = allocr_malloc(c->allocr, sizeof *out->struc); *out->struc = *in->struc; - printf("\n--- USE %p\n",in->struc); size_t nfields = arr_len(in->struc->fields); out->struc->fields = NULL; @@ -634,7 +634,7 @@ static bool export_expr(Exporter *ex, Expression *e) { export_vlq(ex, e->intl); break; case EXPR_LITERAL_FLOAT: - if ((e->type.flags & TYPE_IS_FLEXIBLE) || e->type.builtin == BUILTIN_F64) + if (!found_type || (e->type.flags & TYPE_IS_FLEXIBLE) || e->type.builtin == BUILTIN_F64) export_f64(ex, (F64)e->floatl); else export_f32(ex, (F32)e->floatl); @@ -801,7 +801,7 @@ static void import_expr(Importer *im, Expression *e) { e->intl = import_vlq(im); break; case EXPR_LITERAL_FLOAT: - if ((e->type.flags & TYPE_IS_FLEXIBLE) || e->type.builtin == BUILTIN_F64) + if (!found_type || (e->type.flags & TYPE_IS_FLEXIBLE) || e->type.builtin == BUILTIN_F64) e->floatl = (Floating)import_f64(im); else e->floatl = (Floating)import_f32(im); @@ -1104,7 +1104,6 @@ static bool export_struct(Exporter *ex, StructDef *s) { } static void import_struct(Importer *im, StructDef *s) { - printf("---IMPORT %p\n",s); s->name = import_ident(im); size_t nfields = import_arr(im, &s->fields); for (size_t i = 0; i < nfields; ++i) { @@ -1,5 +1,5 @@ #!/bin/sh valgrind -q ./toc $1.toc -o $1.c || exit 1 valgrind -q ./toc test.toc || exit 1 -gcc test.toc $1.c || exit 1 +gcc out.c $1.c || exit 1 ./a.out @@ -9,6 +9,8 @@ putf ::= fn(x: float) { arr ::= pkg "a"; + + main ::= fn() { x : arr.Arr(int); };
\ No newline at end of file @@ -2140,7 +2140,6 @@ static bool types_decl(Typer *tr, Declaration *d) { if (d->flags & DECL_ANNOTATES_TYPE) { /* type supplied */ assert(d->type.kind != TYPE_VOID); /* there's no way to annotate void */ - print_location(d->where); if (!type_resolve(tr, &d->type, d->where)) { success = false; goto ret; |