about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-29 23:53:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-29 23:53:28 -0700
commit3385febc11dbe76ac86ef00992e7fdded19c58fc (patch)
tree4976cfa64913ba32ff4a13d226534911e68f7427
parentd46c4b06b279e6dc43d2f8278cc91a8f2a137be4 (diff)
downloadmu-3385febc11dbe76ac86ef00992e7fdded19c58fc.tar.gz
shell: allow 'def' to overwrite
-rw-r--r--shell/evaluate.mu2
-rw-r--r--shell/global.mu19
2 files changed, 7 insertions, 14 deletions
diff --git a/shell/evaluate.mu b/shell/evaluate.mu
index 23ec8e3a..491a2022 100644
--- a/shell/evaluate.mu
+++ b/shell/evaluate.mu
@@ -199,7 +199,7 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel
     stream-to-array first-arg-data, tmp-ah
     var first-arg-data-string/eax: (addr array byte) <- lookup *tmp-ah
     var out2/edi: (addr handle cell) <- copy out
-    append-global globals, first-arg-data-string, *out2, trace
+    assign-or-create-global globals, first-arg-data-string, *out2, trace
     trace-higher trace
     return
   }
diff --git a/shell/global.mu b/shell/global.mu
index b736846f..75dfc60e 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -282,23 +282,16 @@ fn append-primitive _self: (addr global-table), name: (addr array byte) {
   new-primitive-function curr-value-ah, curr-index
 }
 
-fn append-global _self: (addr global-table), name: (addr array byte), value: (handle cell), trace: (addr trace) {
+fn assign-or-create-global _self: (addr global-table), name: (addr array byte), value: (handle cell), trace: (addr trace) {
   var self/esi: (addr global-table) <- copy _self
+  var curr-index/ecx: int <- find-symbol-name-in-globals self, name
   {
-    var curr-index/ecx: int <- find-symbol-name-in-globals self, name
     compare curr-index, -1/not-found
-    break-if-=
-    # otherwise error "global already exists: ", sym
-    var stream-storage: (stream byte 0x40)
-    var stream/ecx: (addr stream byte) <- address stream-storage
-    write stream, "global already exists: "
-    write stream, name
-    trace trace, "error", stream
-    return
+    break-if-!=
+    var final-index-addr/eax: (addr int) <- get self, final-index
+    increment *final-index-addr
+    curr-index <- copy *final-index-addr
   }
-  var final-index-addr/ecx: (addr int) <- get self, final-index
-  increment *final-index-addr
-  var curr-index/ecx: int <- copy *final-index-addr
   var data-ah/eax: (addr handle array global) <- get self, data
   var data/eax: (addr array global) <- lookup *data-ah
   var curr-offset/esi: (offset global) <- compute-offset data, curr-index