about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--shell/evaluate.mu47
-rw-r--r--shell/global.mu15
2 files changed, 62 insertions, 0 deletions
diff --git a/shell/evaluate.mu b/shell/evaluate.mu
index 4066db20..729fdfe9 100644
--- a/shell/evaluate.mu
+++ b/shell/evaluate.mu
@@ -88,6 +88,53 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel
     trace-higher trace
     return
   }
+  $evaluate:set: {
+    # trees starting with "set" define globals
+    var expr/esi: (addr cell) <- copy in-addr
+    # if its first elem is not "set", break
+    var first-ah/ecx: (addr handle cell) <- get in-addr, left
+    var rest-ah/edx: (addr handle cell) <- get in-addr, right
+    var first/eax: (addr cell) <- lookup *first-ah
+    var first-type/ecx: (addr int) <- get first, type
+    compare *first-type, 2/symbol
+    break-if-!=
+    var sym-data-ah/eax: (addr handle stream byte) <- get first, text-data
+    var sym-data/eax: (addr stream byte) <- lookup *sym-data-ah
+    var set?/eax: boolean <- stream-data-equal? sym-data, "set"
+    compare set?, 0/false
+    break-if-=
+    #
+    trace-text trace, "eval", "set"
+    trace-text trace, "eval", "evaluating second arg"
+    var rest/eax: (addr cell) <- lookup *rest-ah
+    var first-arg-ah/ecx: (addr handle cell) <- get rest, left
+    {
+      var first-arg/eax: (addr cell) <- lookup *first-arg-ah
+      var first-arg-type/eax: (addr int) <- get first-arg, type
+      compare *first-arg-type, 2/symbol
+      break-if-=
+      error trace, "first arg to set must be a symbol"
+      trace-higher trace
+      return
+    }
+    rest-ah <- get rest, right
+    rest <- lookup *rest-ah
+    var second-arg-ah/edx: (addr handle cell) <- get rest, left
+    evaluate second-arg-ah, out, env-h, globals, trace
+    trace-text trace, "eval", "saving global binding"
+    var first-arg/eax: (addr cell) <- lookup *first-arg-ah
+    var first-arg-data-ah/eax: (addr handle stream byte) <- get first-arg, text-data
+    var first-arg-data/eax: (addr stream byte) <- lookup *first-arg-data-ah
+    var tmp-string: (handle array byte)
+    var tmp-ah/edx: (addr handle array byte) <- address tmp-string
+    rewind-stream first-arg-data
+    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-higher trace
+    return
+  }
   trace-text trace, "eval", "function call"
   trace-text trace, "eval", "evaluating list elements"
   var evaluated-list-storage: (handle cell)
diff --git a/shell/global.mu b/shell/global.mu
index 5204ffc6..c87198ee 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -37,6 +37,21 @@ 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) {
+  var self/esi: (addr global-table) <- copy _self
+  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
+  var curr/esi: (addr global) <- index data, curr-offset
+  var curr-name-ah/eax: (addr handle array byte) <- get curr, name
+  copy-array-object name, curr-name-ah
+  var curr-value-ah/eax: (addr handle cell) <- get curr, value
+  copy-handle value, curr-value-ah
+}
+
 fn lookup-symbol-in-globals _sym: (addr cell), out: (addr handle cell), _globals: (addr global-table), trace: (addr trace) {
   var sym/eax: (addr cell) <- copy _sym
   var sym-data-ah/eax: (addr handle stream byte) <- get sym, text-data
ref='/acidbong/suckless/dwm/commit/config.default.h?h=3.7&id=b515765216c46246358256da6098ea2c07a93c84'>b515765 ^
b355755 ^









b515765 ^

9955ddc ^
b515765 ^



e21d93b ^


b515765 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54