From d85514452aeb9c8d322ad2b82366ca910d96ba19 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 11 Jan 2020 12:34:27 -0500 Subject: fixed problem with importing decls --- package.c | 27 +++++++++++++-------------- types.h | 2 -- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/package.c b/package.c index 5b2a53b..4968d9b 100644 --- a/package.c +++ b/package.c @@ -16,7 +16,6 @@ static void import_expr(Importer *im, Expression *e); static void exptr_create(Exporter *ex, FILE *out) { ex->out = out; ex->ident_id = 0; - ex->export_locations = true; ex->exported_fns = NULL; ex->exported_structs = NULL; ex->exported_idents = NULL; @@ -144,10 +143,8 @@ static inline char *import_str(Importer *i, size_t len) { } static void export_location(Exporter *ex, Location where) { - if (ex->export_locations) { - /* for now, we only export the line */ - export_vlq(ex, (U64)where.start->pos.line); - } + /* for now, we only export the line */ + export_vlq(ex, (U64)where.start->pos.line); } static Location import_location(Importer *im) { Location l; @@ -342,7 +339,7 @@ static void import_type(Importer *im, Type *type) { type->kind = (TypeKind)kind; } type->flags = import_u8(im); - int is_resolved = type->flags & TYPE_IS_RESOLVED; + unsigned is_resolved = type->flags & TYPE_IS_RESOLVED; switch (type->kind) { case TYPE_VOID: case TYPE_BUILTIN: @@ -508,7 +505,7 @@ static inline bool export_optional_expr(Exporter *ex, Expression *e) { static bool export_expr(Exporter *ex, Expression *e) { possibly_static_assert(sizeof e->flags == 1); export_u8(ex, (U8)e->flags); - int found_type = e->flags & EXPR_FOUND_TYPE; + unsigned found_type = e->flags & EXPR_FOUND_TYPE; if (found_type) { if (!export_type(ex, &e->type, e->where)) return false; @@ -679,8 +676,10 @@ enum { static bool export_decl(Exporter *ex, Declaration *d) { assert(ex->started); - bool found_type = (d->flags & DECL_FOUND_TYPE) != 0; - export_bool(ex, found_type); + possibly_static_assert(sizeof d->flags == 2); + export_u16(ex, d->flags); + + unsigned found_type = d->flags & DECL_FOUND_TYPE; if (found_type && d->type.kind == TYPE_UNKNOWN) { err_print(d->where, "Can't export declaration of unknown type."); @@ -730,15 +729,16 @@ static bool export_decl(Exporter *ex, Declaration *d) { } static void import_decl(Importer *im, Declaration *d) { + d->flags = import_u16(im); + possibly_static_assert(sizeof d->flags == 2); d->where = import_location(im); d->idents = NULL; - size_t n_idents = import_len(im); - arr_set_lena(&d->idents, n_idents, im->allocr); + size_t n_idents = import_arr(im, &d->idents); for (size_t i = 0; i < n_idents; ++i) { d->idents[i] = import_ident(im); } - /* import_type(im, &d->type); */ - /* printf("%s\n",type_to_str(&d->type)); */ + import_type(im, &d->type); + printf("%s\n",type_to_str(&d->type)); exit(0); } @@ -808,7 +808,6 @@ static bool export_struct(Exporter *ex, StructDef *s) { } static void import_struct(Importer *im, StructDef *s) { - fprintf(stderr,"%lx\n",ftell(im->in)); size_t nfields = import_arr(im, &s->fields); for (size_t i = 0; i < nfields; ++i) { s->fields[i].name = import_ident(im); diff --git a/types.h b/types.h index b994f48..8050c3a 100644 --- a/types.h +++ b/types.h @@ -704,7 +704,6 @@ enum { typedef U16 DeclFlags; -/* OPTIM: Instead of using dynamic arrays, do two passes. */ typedef struct Declaration { Location where; Identifier *idents; @@ -792,7 +791,6 @@ typedef struct Package { typedef struct Exporter { FILE *out; /* .top (toc package) to output to */ - bool export_locations; bool started; U64 ident_id; FnExpr **exported_fns; -- cgit v1.2.3