From 3080d1149ad3838f053d5d4faad25f24555337ef Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 10 Jul 2020 16:23:31 -0400 Subject: fixed problem unveiled by making types smaller --- parse.c | 4 +--- test.toc | 15 +++------------ types.h | 2 +- 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; }; -- cgit v1.2.3