summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compatibility.c12
-rw-r--r--identifiers.c7
-rw-r--r--main.c2
-rw-r--r--package.c35
-rw-r--r--types.c4
-rw-r--r--types.h1
6 files changed, 46 insertions, 15 deletions
diff --git a/compatibility.c b/compatibility.c
new file mode 100644
index 0000000..705bd07
--- /dev/null
+++ b/compatibility.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ int *p;
+ memset(&p, 0, sizeof p);
+ if (p) {
+ fprintf(stderr, "You cannot run toc. Sorry.\n");
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/identifiers.c b/identifiers.c
index 3bb3eb1..e960a14 100644
--- a/identifiers.c
+++ b/identifiers.c
@@ -31,13 +31,6 @@ static int isident(int c) {
static Identifier ident_new(Identifiers *ids, Identifier parent, unsigned char index_in_parent) {
IdentTree *tree = block_arr_add(&ids->trees);
memset(tree, 0, sizeof *tree); /* use zero value of IdentTree */
-#ifdef NONZERO_NULL_PTRS
- tree->parent = NULL;
- for (size_t i = 0; i < TREE_NCHILDREN; ++i)
- tree->children[i] = NULL;
- tree->decls = NULL;
- tree->pkg = NULL;
-#endif
tree->parent = parent;
if (parent)
tree->depth = (uint16_t)(parent->depth + 1);
diff --git a/main.c b/main.c
index d1a6179..226d507 100644
--- a/main.c
+++ b/main.c
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
if (!block_enter(NULL, f.stmts, SCOPE_CHECK_REDECL)) /* enter global scope */
return false;
- if (!types_file(&tr, &f, contents)) {
+ if (!types_file(&tr, &f)) {
/* TODO(eventually): fix this if the error occured while exporting something */
err_fprint(TEXT_IMPORTANT("Errors occured while determining types.\n"));
return EXIT_FAILURE;
diff --git a/package.c b/package.c
index 38b92fa..caacbb1 100644
--- a/package.c
+++ b/package.c
@@ -11,7 +11,7 @@ static bool export_block(Exporter *ex, Block *b);
static bool export_expr(Exporter *ex, Expression *e);
static bool import_footer(Importer *i);
-static void exptr_create(Exporter *ex, FILE *out, char *code) {
+static void exptr_create(Exporter *ex, FILE *out) {
ex->out = out;
ex->ident_id = 0;
ex->export_locations = true;
@@ -19,7 +19,7 @@ static void exptr_create(Exporter *ex, FILE *out, char *code) {
ex->exported_structs = NULL;
ex->exported_idents = NULL;
ex->started = false;
- ex->code = code;
+ ex->code = NULL;
}
static inline void *imptr_malloc(Importer *i, size_t n) {
@@ -217,6 +217,10 @@ static bool import_pkg(Allocator *allocr, Package *p, FILE *f, const char *fname
if (!import_footer(&i))
return false;
fseek(f, code_offset, SEEK_SET);
+
+
+
+ free(i.ident_map);
return true;
}
@@ -672,7 +676,10 @@ static bool exptr_finish(Exporter *ex) {
export_u64(ex, (U64)ident_offset);
fseek(ex->out, 0L, SEEK_END);
-
+ /* export total number of identifiers */
+ export_len(ex, ex->ident_id);
+
+ /* export number of identifiers *whose names matter* */
export_len(ex, arr_len(ex->exported_idents));
arr_foreach(ex->exported_idents, Identifier, ident) {
Identifier i = *ident;
@@ -706,7 +713,25 @@ static bool exptr_finish(Exporter *ex) {
return true;
}
-static bool import_footer(Importer *i) {
- /* TODO */
+static bool import_footer(Importer *im) {
+ size_t i;
+ size_t max_ident_id = import_len(im);
+ im->ident_map = err_calloc(max_ident_id + 1, sizeof *im->ident_map);
+ size_t n_named_idents = import_len(im);
+ for (i = 0; i < n_named_idents; ++i) {
+ U64 id = import_vlq(im);
+ size_t name_len = import_vlq(im);
+ char *name = err_malloc(name_len+1);
+ name[name_len] = 0;
+ fread(name, 1, name_len, im->in);
+ char *copy = name; /* don't change the value of name */
+ im->ident_map[id] = ident_insert(&im->pkg->idents, &copy);
+ free(name);
+ }
+ for (i = 1; i <= max_ident_id; ++i) {
+ if (!im->ident_map[i]) {
+ /* TODO (maybe generate random identifier -- or just use malloc and set a certain field to indicate it's not part of a tree?) */
+ }
+ }
return true;
}
diff --git a/types.c b/types.c
index 563be4a..b5ba6c9 100644
--- a/types.c
+++ b/types.c
@@ -2168,7 +2168,7 @@ static void typer_create(Typer *tr, Evaluator *ev, Allocator *allocr, Identifier
*(Block **)arr_adda(&tr->blocks, allocr) = NULL;
}
-static bool types_file(Typer *tr, ParsedFile *f, char *code) {
+static bool types_file(Typer *tr, ParsedFile *f) {
bool ret = true;
FILE *pkg_fp = NULL;
if (f->pkg_name) {
@@ -2204,7 +2204,7 @@ static bool types_file(Typer *tr, ParsedFile *f, char *code) {
return false;
}
free(pkg_file_name);
- exptr_create(tr->exptr, pkg_fp, code);
+ exptr_create(tr->exptr, pkg_fp);
exptr_start(tr->exptr, pkg_name_str, pkg_name_len);
}
arr_foreach(f->stmts, Statement, s) {
diff --git a/types.h b/types.h
index b01e295..4082dd6 100644
--- a/types.h
+++ b/types.h
@@ -788,6 +788,7 @@ typedef struct Importer {
FILE *in;
Package *pkg;
Allocator *allocr;
+ Identifier *ident_map; /* [i] = value of identifier with ID i */
} Importer;
typedef struct CGenerator {