summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-07-10 16:23:31 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-07-10 16:23:31 -0400
commit3080d1149ad3838f053d5d4faad25f24555337ef (patch)
tree429c4f079f4d793128f0d16a48034b27bbc67863
parent4fcae53ed9180dfbb41c922540e7db769bd118d8 (diff)
fixed problem unveiled by making types smaller
-rw-r--r--parse.c4
-rw-r--r--test.toc15
-rw-r--r--types.h2
3 files changed, 5 insertions, 16 deletions
diff --git a/parse.c b/parse.c
index c1238ad..7538202 100644
--- a/parse.c
+++ b/parse.c
@@ -1380,9 +1380,7 @@ static Status parse_expr(Parser *p, Expression *e, Token *end) {
++t->token;
Type *fn_t = &fn->foreign.type;
fn_t->kind = TYPE_FN;
- FnType *fn_type = fn_t->fn = parser_malloc(p, sizeof *fn_t);
- fn_type->constness = NULL;
- fn_type->types = NULL;
+ FnType *fn_type = fn_t->fn = parser_calloc(p, 1, sizeof *fn_type);
/* reserve space for return type (Type + CType) */
parser_arr_add_ptr(p, fn_type->types);
parser_arr_add_ptr(p, fn->foreign.ctypes);
diff --git a/test.toc b/test.toc
index 48c31a6..6acebc5 100644
--- a/test.toc
+++ b/test.toc
@@ -1,13 +1,4 @@
-#include "std/io.toc", io;
-#include "std/mem.toc";
-
-main ::= fn() {
- file, err := io.fopen_write("test.txt");
-
- for i := 0.,1000000 {
- io.fputs(file, "!");
- }
-
- io.fclose(file);
+n ::= nms {
+ putchar ::= #foreign("putchar") fn(#C int) #C int;
}
-main();
+main ::= fn(){}
diff --git a/types.h b/types.h
index b8c1026..2f6946d 100644
--- a/types.h
+++ b/types.h
@@ -648,11 +648,11 @@ enum {
typedef struct FnExpr {
Location where;
Block *declaration_block; /* block wherein this function is declared */
+ U64 instance_id; /* 0 if not an instance. needs to be available even for #foreign functions */
union {
struct {
struct Declaration *params; /* declarations of the parameters to this function */
struct Declaration *ret_decls; /* array of decls, if this has named return values. otherwise, NULL */
- U64 instance_id; /* 0 if not an instance */
Type ret_type;
Block body;
};