summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.c4
-rw-r--r--types.c25
2 files changed, 26 insertions, 3 deletions
diff --git a/package.c b/package.c
index de0ab43..b83c4d0 100644
--- a/package.c
+++ b/package.c
@@ -605,3 +605,7 @@ static bool exptr_finish(Exporter *ex) {
return true;
}
+
+static void import_pkg(Package *p, FILE *f) {
+ idents_create(&p->idents);
+}
diff --git a/types.c b/types.c
index dbc8b09..32c8a41 100644
--- a/types.c
+++ b/types.c
@@ -873,11 +873,30 @@ static bool types_expr(Typer *tr, Expression *e) {
err_print(name_expr->where, "Package name has negative length (" I64_FMT ")!", name_str.n);
return false;
}
- char *name_cstr = err_malloc((size_t)name_str.n + 1);
- memcpy(name_cstr, name_str.data, (size_t)name_str.n);
+ size_t name_str_len = (size_t)name_str.n;
+ char *name_cstr = err_malloc(name_str_len + 1);
+ memcpy(name_cstr, name_str.data, name_str_len);
name_cstr[name_str.n] = '\0';
- Identifier name_ident = ident_insert(tr->idents, &name_cstr);
+ /* advance copy so we can free the original */
+ char *copy = name_cstr;
+ Identifier name_ident = ident_insert(tr->idents, &copy);
+ free(name_cstr);
e->pkg.name_ident = name_ident;
+ if (!name_ident->pkg) {
+ char *filename = err_malloc(name_str_len + 5);
+ Package *pkg = name_ident->pkg = allocr_calloc(tr->allocr, 1, sizeof *pkg);
+ memcpy(filename, name_str.data, name_str_len);
+ strcpy(filename + name_str.n, ".top");
+ /* TODO: library paths */
+ FILE *fp = fopen(filename, "rb");
+ if (!fp) {
+ err_print(e->where, "Could not open package: %s (does this file exist?)", filename);
+ free(filename);
+ return false;
+ }
+ import_pkg(pkg, fp);
+ fclose(fp);
+ }
} break;
case EXPR_EACH: {
EachExpr *ea = e->each;