summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-15 20:13:06 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-15 20:13:06 -0500
commit757b7a618bfdd8cb5690cce1c943e6d6e1a11cb2 (patch)
tree053b4aec16a6aa67bda3b2dd1991e5c364890864
parent0a018a8b15e8ee1790358ef2e3325185b99212bc (diff)
fixing packages more. more to come
-rw-r--r--.gitignore1
-rw-r--r--a.c23
-rw-r--r--a.toc6
-rw-r--r--arr.c2
-rw-r--r--copy.c1
-rw-r--r--package.c5
-rwxr-xr-xpkg.sh2
-rw-r--r--test.toc2
-rw-r--r--types.c1
9 files changed, 11 insertions, 32 deletions
diff --git a/.gitignore b/.gitignore
index d40b8cc..9c1ef31 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+a.c
toc
a.out
out.c
diff --git a/a.c b/a.c
deleted file mode 100644
index 2d2c03a..0000000
--- a/a.c
+++ /dev/null
@@ -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 */
diff --git a/a.toc b/a.toc
index 60c31dd..7efdaf5 100644
--- a/a.toc
+++ b/a.toc
@@ -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
diff --git a/arr.c b/arr.c
index 5b005ef..b44935d 100644
--- a/arr.c
+++ b/arr.c
@@ -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;
diff --git a/copy.c b/copy.c
index bcb04aa..0ad1adc 100644
--- a/copy.c
+++ b/copy.c
@@ -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;
diff --git a/package.c b/package.c
index 0dbbd56..6b6769e 100644
--- a/package.c
+++ b/package.c
@@ -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) {
diff --git a/pkg.sh b/pkg.sh
index 0e5eb94..b86c1ca 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -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
diff --git a/test.toc b/test.toc
index 6112afa..d522bad 100644
--- a/test.toc
+++ b/test.toc
@@ -9,6 +9,8 @@ putf ::= fn(x: float) {
arr ::= pkg "a";
+
+
main ::= fn() {
x : arr.Arr(int);
}; \ No newline at end of file
diff --git a/types.c b/types.c
index 43a0414..dba9820 100644
--- a/types.c
+++ b/types.c
@@ -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;