summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-10-21 16:57:56 -0400
committerWormHeamer2025-10-21 16:57:56 -0400
commit82a5363d1a2575662e4d23d7e683398efb966500 (patch)
treeb80decf7eda4e7ea7dc8170eadaf089cf2dd202d
parent1619e765e3ae2a88765c94a01ec731e8cabd0ff1 (diff)
cleanup comments
-rw-r--r--main.c63
-rw-r--r--proc.h12
-rw-r--r--test.lang5
3 files changed, 8 insertions, 72 deletions
diff --git a/main.c b/main.c
index 25469bc..d590ce6 100644
--- a/main.c
+++ b/main.c
@@ -162,69 +162,6 @@ void parse_assign(Lexer *l, Proc *p) {
scope_update(&p->scope, b, e, &p->graph);
}
-/* TODO: Implement a better system for this.
- *
- * Something like:
- *
- * ScopeChangeList chg_true = {0}, chg_false = {0};
- * scope_track_changes(&p->scope, &chg_true, p, scratch);
- * parse_block(l, p);
- * scope_rewind_changes(&p->scope, &chg_true, p);
- * scope_track_changes(&p->scope, &chg_false, p, scratch);
- * parse_block(l, p);
- * scope_merge_changes(&p->scope, &chg_true, &chg_false, region, p);
- *
- * We put a flag in Scope somewhere that marks where it's tracking changes to,
- * then have scope_update() look up the name binding being changed in the change
- * list; if present, update value to the new node. If not, create it with
- * orig set to the previous value of the name binding, and value to the new node.
- * Since we're only tracking _changes_, there should be some way to make sure that
- * newly created let-bindings after tracking starts aren't stored in the list.
- * Maybe give NameBindings an index, note the index of the latest binding at the
- * time scope_track_changes() is called, ignore any larger than it.
- *
- * Take care with making sure changes remain attached to keepalive --- rewind
- * doesn't remove the new values, since it's just to revert temporarily.
- *
- * Also, probably should have a scratch arena for this sort of throwaway parsing
- * data, instead of putting stuff in the procedure graph arena. It can be reset
- * after each statement.
- *
- * Also also, switch scopes from a linked list to something a bit faster, like
- * a simple arena-backed hash trie.
- *
- */
-
-#if 0
-void merge_scope(Lexer *l, Proc *p, Node *region, ScopeNameList *before, ScopeNameList *ntrue, ScopeNameList *nfalse) {
- Graph *g = &p->graph;
- for (int i = 0; i < before->len; i++) {
- int j, k;
- ScopeName *b4 = &before->data[i];
- for (j = 0; j < ntrue->len && !str_eql(ntrue->data[j].name, b4->name); j++);
- for (k = 0; k < nfalse->len && !str_eql(nfalse->data[k].name, b4->name); k++);
- ScopeName *yes = j < ntrue->len ? &ntrue->data[j] : NULL;
- ScopeName *no = k < nfalse->len ? &nfalse->data[k] : NULL;
- if (!yes && !no) continue; /* no change */
- Node *phi;
- if (!no) {
- if (yes->node == b4->node) continue;
- phi = node_new(g, N_PHI, region, yes->node, b4->node);
- } else if (!yes) {
- if (no->node == b4->node) continue;
- phi = node_new(g, N_PHI, region, b4->node, no->node);
- } else {
- if (yes->node == b4->node && no->node == b4->node) continue;
- phi = node_new(g, N_PHI, region, yes->node, no->node);
- }
- phi = node_peephole(phi, g, l);
- NameBinding *b = scope_find(&p->scope, b4->name);
- assert(b);
- scope_update(b, phi, g);
- }
-}
-#endif
-
/* TODO: find out a way to encode known relations between nodes, based on the
* conditional, within the body of an if statement --- e.g., for a statement
*
diff --git a/proc.h b/proc.h
index b95c149..addc192 100644
--- a/proc.h
+++ b/proc.h
@@ -4,6 +4,8 @@
#include "ir.h"
#include "xar.h"
+/* TODO: use a hash trie instead of linked list? */
+
typedef struct NameBinding {
struct NameBinding *prev;
LexSpan src_pos;
@@ -12,11 +14,6 @@ typedef struct NameBinding {
unsigned nestlvl;
} NameBinding;
-typedef struct ScopeFrame {
- struct ScopeFrame *prev;
- NameBinding *latest;
-} ScopeFrame;
-
typedef struct {
NameBinding *bind;
Node *from, *to;
@@ -28,6 +25,11 @@ typedef struct ScopeChangeList {
Arena *arena;
} ScopeChangeList;
+typedef struct ScopeFrame {
+ struct ScopeFrame *prev;
+ NameBinding *latest;
+} ScopeFrame;
+
typedef struct {
Arena *arena;
ScopeFrame *tail, *free_scope;
diff --git a/test.lang b/test.lang
index 40c3ff7..dc6e4cf 100644
--- a/test.lang
+++ b/test.lang
@@ -1,11 +1,8 @@
func main(a, b i64) i64 {
let x = 2
if a < b {
+ let z = 3
x := 3
- } else {
- let t = a
- a := b
- b := t
}
return a + x
}