summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-22 00:01:29 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-22 00:01:29 -0400
commit9fcf1a0190a6cc9e379448d14b628fd3b93a4d32 (patch)
tree947f810b3697a424d2aa7a5f1d617c65b74b8c7d
parent54f2ec8827cca60d1f31b50a60f23c6e107a0fe4 (diff)
more use
-rw-r--r--test.toc8
-rw-r--r--types.c1
-rw-r--r--types.h11
3 files changed, 17 insertions, 3 deletions
diff --git a/test.toc b/test.toc
index d27fae6..8e611c0 100644
--- a/test.toc
+++ b/test.toc
@@ -1,6 +1,8 @@
-#include "std/mem.toc";
+Point ::= struct {
+ x, y: int;
+}
main ::= fn() {
- thing := new(int);
- del(thing);
+ p: Point;
+ use p;
}
diff --git a/types.c b/types.c
index b9c9ebd..109fa68 100644
--- a/types.c
+++ b/types.c
@@ -3480,6 +3480,7 @@ static Status types_stmt(Typer *tr, Statement *s) {
}
static void typer_create(Typer *tr, Evaluator *ev, ErrCtx *err_ctx, Allocator *allocr, Identifiers *idents) {
+ tr->used = NULL;
tr->block = NULL;
tr->blocks = NULL;
tr->fn = NULL;
diff --git a/types.h b/types.h
index 195c97e..0b0fcbb 100644
--- a/types.h
+++ b/types.h
@@ -1033,6 +1033,16 @@ typedef struct Evaluator {
ForeignFnManager ffmgr;
} Evaluator;
+/*
+Keeps track of use stmts.
+We need to keep track of the block so that
+it can be removed when we exit the block.
+*/
+typedef struct {
+ Statement *stmt;
+ Block *scope;
+} UsedExpr;
+
typedef struct Typer {
Allocator *allocr;
Evaluator *evalr;
@@ -1046,6 +1056,7 @@ typedef struct Typer {
ParsedFile *parsed_file;
Namespace *nms;
StrHashTable included_files; /* maps to IncludedFile */
+ UsedExpr *used; /* things which are currently being `use`d */
} Typer;
typedef struct CGenerator {