summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c4
-rw-r--r--parse.c12
-rw-r--r--std/mem.toc10
-rw-r--r--test.toc12
-rw-r--r--types.h2
5 files changed, 23 insertions, 17 deletions
diff --git a/main.c b/main.c
index 7dec0fe..30bea22 100644
--- a/main.c
+++ b/main.c
@@ -215,8 +215,10 @@ int main(int argc, char **argv) {
}
if (verbose) printf("Parsing...\n");
+ StrHashTable included_files = {0};
+ str_hash_table_create(&included_files, sizeof(IncludedFile), &main_allocr);
Parser p;
- parser_create(&p, &globals, &t, &main_allocr, &file);
+ parser_create(&p, &globals, &t, &main_allocr, &file, &included_files);
ParsedFile f;
if (!parse_file(&p, &f)) {
err_text_important(&err_ctx, "Errors occured during parsing.\n");
diff --git a/parse.c b/parse.c
index 5679e20..e59c48c 100644
--- a/parse.c
+++ b/parse.c
@@ -3,7 +3,7 @@
This file is part of toc. toc is distributed under version 3 of the GNU General Public License, without any warranty whatsoever.
You should have received a copy of the GNU General Public License along with toc. If not, see <https://www.gnu.org/licenses/>.
*/
-static void parser_create(Parser *p, Identifiers *globals, Tokenizer *t, Allocator *allocr, File *main_file);
+static void parser_create(Parser *p, Identifiers *globals, Tokenizer *t, Allocator *allocr, File *main_file, StrHashTable *included_files);
static Status parse_file(Parser *p, ParsedFile *f);
static Status parse_expr(Parser *p, Expression *e, Token *end);
static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement);
@@ -2576,7 +2576,7 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) {
err_print(s->where, "Circular #include detected. You can add #force to this #include to force it to be included.");
success = false; goto nms_done;
}
- inc_f = str_hash_table_get(&p->included_files, filename, filename_len);
+ inc_f = str_hash_table_get(p->included_files, filename, filename_len);
if (inc_f) {
/* has already been included */
if (inc_f->flags & INC_FILE_INCLUDING) {
@@ -2590,7 +2590,7 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) {
}
goto nms_done;
}
- inc_f = str_hash_table_insert(&p->included_files, filename, filename_len);
+ inc_f = str_hash_table_insert(p->included_files, filename, filename_len);
inc_f->flags |= INC_FILE_INCLUDING;
inc_f->main_nms = p->nms;
}
@@ -2619,7 +2619,7 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) {
#endif
Parser parser;
- parser_create(&parser, p->globals, &tokr, p->allocr, p->main_file);
+ parser_create(&parser, p->globals, &tokr, p->allocr, p->main_file, p->included_files);
parser.block = p->block;
parser.nms = p->nms;
ParsedFile parsed_file;
@@ -2745,13 +2745,13 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) {
return true;
}
-static void parser_create(Parser *p, Identifiers *globals, Tokenizer *t, Allocator *allocr, File *main_file) {
+static void parser_create(Parser *p, Identifiers *globals, Tokenizer *t, Allocator *allocr, File *main_file, StrHashTable *included_files) {
p->tokr = t;
p->block = NULL;
p->globals = globals;
p->allocr = allocr;
p->main_file = main_file;
- str_hash_table_create(&p->included_files, sizeof(IncludedFile), p->allocr);
+ p->included_files = included_files;
}
static Status parse_file(Parser *p, ParsedFile *f) {
diff --git a/std/mem.toc b/std/mem.toc
index 1e21702..9ea9b12 100644
--- a/std/mem.toc
+++ b/std/mem.toc
@@ -5,14 +5,14 @@ calloc ::= #foreign("calloc", base.libc) fn(#C size_t, #C size_t) #C &"void";
free ::= #foreign("free", base.libc) fn(#C &"void");
new ::= fn(t :: Type) &t {
- calloc(1, (sizeof t) as #C size_t)
+ return calloc(1, (sizeof t) as #C size_t);
}
news ::= fn(t :: Type, n : int) []t {
s: []t;
s.data = calloc(n as #C size_t, (sizeof t) as #C size_t);
s.len = n;
- s
+ return s;
}
// TODO(eventually): use type information to make this just one function
@@ -23,9 +23,3 @@ del ::= fn(t::=, x: &t) {
dels ::= fn(t::=, x: []t) {
free(x.data);
}
-
-// @TODO: write your own
-memcpy ::= #foreign("memcpy", base.libc) fn(&void, #C &"const void", #C size_t) &void;
-mem_copy ::= fn(dst: &void, src: &void, n: int) {
- memcpy(dst, src, n as #C size_t);
-}
diff --git a/test.toc b/test.toc
index 5976415..54f7b2b 100644
--- a/test.toc
+++ b/test.toc
@@ -1,6 +1,16 @@
-
+#include "tests/std/io.toc", io;
+#include "tests/std/io.toc", foo;
+#include "tests/std/io.toc", bar;
+#include "tests/std/io.toc", baz;
#include "tests/std/io.toc";
+#include "tests/included.toc", inc;
main ::= fn() {
puts("hello");
+ io.puts("hello");
+ foo.puts("hello");
+ bar.puts("hello");
+ baz.puts("hello");
+ inc.puts("hello");
+ inc.foo.puts("hello");
}
diff --git a/types.h b/types.h
index 35e0be4..1abe7eb 100644
--- a/types.h
+++ b/types.h
@@ -1001,7 +1001,7 @@ typedef struct Parser {
Block *block; /* which block are we in? NULL = file scope */
Namespace *nms;
ParsedFile *parsed_file;
- StrHashTable included_files; /* maps to IncludedFile */
+ StrHashTable *included_files; /* maps to IncludedFile. this is a pointer because all Parsers (i.e. the Parser for every file) have a common included_files */
} Parser;
typedef struct {