about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compile.c29
-rw-r--r--thac.h5
-rw-r--r--vertex.c12
3 files changed, 22 insertions, 24 deletions
diff --git a/compile.c b/compile.c
index d488414..61aab05 100644
--- a/compile.c
+++ b/compile.c
@@ -51,7 +51,7 @@ rvar(struct node *node, struct scope *scope) {
 static struct val
 roper(struct node *node, struct scope *scope)
 {
-	struct val l, m, r, ref, val;
+	struct val l, m, r, ref, refl, refr, val;
 	struct scope *lscope;
 	vlong i, j;
 
@@ -99,23 +99,19 @@ roper(struct node *node, struct scope *scope)
 	UN(OINV, ~)
 #undef UN
 	break; case OASSIGN:
-	{
-		struct val shouldfree = nil;
-		struct var *var;
-
-		val = getval(VVAR, eval(node->noper.l, scope), scope, 0);
+		refl = getval(VVAR, eval(node->noper.l, scope), scope, 0);
 		lscope = scope;
-		i = findvar(val.name, &lscope);
-		if (i > 0)
-			shouldfree = deref(val, scope);
+		i = findvar(refl.name, &lscope);
+		l = i >= 0 ? deref(refl, scope) : nil;
 
-		r = deref(eval(node->noper.r, scope), scope);
+		refr = eval(node->noper.r, scope);
+		r = deref(refr, scope);
 
 		/* it's fine to use scope here as it won't be used after */
-		assignvar(val.name, copyval(r), &scope);
-		freeval(shouldfree);
-		freeval(r);
-	}
+		assignvar(refl.name, copyval(r), &scope);
+		freeval(l);
+		if (refr.type == VVAR)
+			freeval(r);
 #define ASS(NAME, OPER) break; case NAME: \
 { \
 	ref = getval(VVAR, eval(node->noper.l, scope), scope, 0); \
@@ -217,8 +213,6 @@ roper(struct node *node, struct scope *scope)
 		if (ref.type == VARR)
 			freeval(ref);
 	break; case OCONCAT:
-	{
-		struct val refl, refr;
 		refl = eval(node->noper.l, scope);
 		l = getval(VARR, refl, scope, 1);
 		refr = eval(node->noper.r, scope);
@@ -239,7 +233,6 @@ roper(struct node *node, struct scope *scope)
 			freeval(refl);
 		if (refr.type == VARR)
 			freeval(refr);
-	}
 	break; case OLEN:
 		m = getval(VARR, eval(node->noper.m, scope), scope, 1);
 		val.num = m.len;
@@ -402,7 +395,7 @@ rwith(struct node *node, struct scope *scope)
 			mod->nmod.len,
 			mod->nmod.len != 1 ? "s" : "",
 			node->nwith.len,
-			mod->nwith.len != 1 ? "s" : ""
+			node->nwith.len != 1 ? "s" : ""
 		);
 
 	argscope.len = mod->nmod.len;
diff --git a/thac.h b/thac.h
index 37dd9f5..060fcdf 100644
--- a/thac.h
+++ b/thac.h
@@ -294,6 +294,11 @@ int _exptok(enum tok_t, ...);
 struct node *getstmt(void);
 struct val eval(struct node *, struct scope *);
 
+/*
+ * TODO: Probably current struct scope implementation is bad,
+ * as because of it functions below require double pointer
+ * and consequently overwrite it. Maybe a pure linked list?
+ */
 long findvar(char *, struct scope **);
 ulong assignvar(char *, struct val, struct scope **);
 int varnextchar(struct scope *);
diff --git a/vertex.c b/vertex.c
index b8290b1..fb28029 100644
--- a/vertex.c
+++ b/vertex.c
@@ -46,8 +46,8 @@ mkvert(void)
 void
 addprop(ulong i, vlong prop)
 {
-	if (i < 0 || i >= len)
-		complain(1, "addprop: how would you want this? (0<=%lld<%lld)", i, len);
+	if (i >= len)
+		complain(1, "addprop: how would you want this? (%lld<%lld)", i, len);
 
 	verts[i].props.arr = realloc(
 		verts[i].props.arr,
@@ -64,10 +64,10 @@ addedge(ulong from, ulong to)
 {
 	ulong i;
 
-	if (from < 0 || from >= len)
-		complain(1, "addedge: how would you want this? (0<=%lld<%lld)", from, len);
-	if (to < 0 || to >= len)
-		complain(1, "addedge: how would you want this? (0<=%lld<%lld)", from, len);
+	if (from >= len)
+		complain(1, "addedge: how would you want this? (%lld<%lld)", from, len);
+	if (to >= len)
+		complain(1, "addedge: how would you want this? (%lld<%lld)", from, len);
 
 	for (i = 0; i < verts[from].nbrs.len; ++i)
 		if (verts[from].nbrs.arr[i] == to)