about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/tile/data.mu1
-rw-r--r--apps/tile/environment.mu20
-rw-r--r--apps/tile/rpn.mu32
-rw-r--r--apps/tile/value-stack.mu13
4 files changed, 65 insertions, 1 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
index 7575461c..8a23fea9 100644
--- a/apps/tile/data.mu
+++ b/apps/tile/data.mu
@@ -38,6 +38,7 @@ type value {
   int-data: int  # if type = 0
   text-data: (handle array byte)  # if type = 1
   array-data: (handle array int)  # if type = 2
+  file-data: (handle buffered-file)  # if type = 3
 }
 
 type table {
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index e37b32ba..757e62b9 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -778,6 +778,14 @@ fn bound-function? w: (addr word), functions-ah: (addr handle function) -> resul
   subresult <- word-equal? w, "len"
   compare subresult, 0  # false
   break-if-!=
+  # if w == "open" return true
+  subresult <- word-equal? w, "open"
+  compare subresult, 0  # false
+  break-if-!=
+  # if w == "read" return true
+  subresult <- word-equal? w, "read"
+  compare subresult, 0  # false
+  break-if-!=
   # return w in functions
   var out-h: (handle function)
   var out/eax: (addr handle function) <- address out-h
@@ -1372,6 +1380,16 @@ fn render-column screen: (addr screen), functions: (addr handle function), bindi
             render-array screen, val
             break $render-column:render-value
           }
+          {
+            compare *val-type, 3  # file
+            break-if-!=
+            var val-ah/eax: (addr handle buffered-file) <- get val-addr, file-data
+            var val/eax: (addr buffered-file) <- lookup *val-ah
+            start-color screen, 0, 7
+            # TODO
+            print-string screen, " FILE "
+            break $render-column:render-value
+          }
           # render ints by default for now
           var val-addr2/eax: (addr int) <- get val-addr, int-data
           render-integer screen, *val-addr2, max-width
@@ -1498,7 +1516,7 @@ fn clear-canvas _env: (addr environment) {
   print-string screen, "functions:"
   start-col <- add 2
   move-cursor screen, 2, start-col
-  print-string screen, "+ - * len"
+  print-string screen, "+ - * len open read"
   # currently defined functions
   var row/ebx: int <- copy 5
   var functions/esi: (addr handle function) <- get env, functions
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index ef53bb7e..c206e997 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -102,6 +102,38 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
           break $evaluate:process-word
         }
       }
+      {
+        var is-open?/eax: boolean <- stream-data-equal? curr-stream, "open"
+        compare is-open?, 0
+        break-if-=
+        # pop target-val from out
+        var out2/esi: (addr value-stack) <- copy out
+        var top-addr/ecx: (addr int) <- get out2, top
+        compare *top-addr, 0
+        break-if-<=
+        var data-ah/eax: (addr handle array value) <- get out2, data
+        var data/eax: (addr array value) <- lookup *data-ah
+        var top/edx: int <- copy *top-addr
+        top <- decrement
+        var dest-offset/edx: (offset value) <- compute-offset data, top
+        var target-val/edx: (addr value) <- index data, dest-offset
+        # check target-val is a string
+        var target-type-addr/eax: (addr int) <- get target-val, type
+        compare *target-type-addr, 1  # string
+        break-if-!=
+        # open target-val as a filename and save the handle in target-val
+        var src-ah/eax: (addr handle array byte) <- get target-val, text-data
+        var src/eax: (addr array byte) <- lookup *src-ah
+        var result-ah/ecx: (addr handle buffered-file) <- get target-val, file-data
+        open src, 0, result-ah  # write? = false
+        # save result into target-val
+        var type-addr/eax: (addr int) <- get target-val, type
+        copy-to *type-addr, 3  # file
+        var target-string-ah/eax: (addr handle array byte) <- get target-val, text-data
+        var empty: (handle array byte)
+        copy-handle empty, target-string-ah
+        break $evaluate:process-word
+      }
       # if curr-stream defines a binding, save top of stack to bindings
       {
         var done?/eax: boolean <- stream-empty? curr-stream
diff --git a/apps/tile/value-stack.mu b/apps/tile/value-stack.mu
index dbe25b74..2eae94d3 100644
--- a/apps/tile/value-stack.mu
+++ b/apps/tile/value-stack.mu
@@ -176,6 +176,19 @@ fn value-stack-max-width _self: (addr value-stack) -> result/eax: int {
       break-if-<=
       copy-to out, w
     }
+    {
+      compare *type, 3  # file handle
+      break-if-!=
+      var f-ah/eax: (addr handle buffered-file) <- get g, file-data
+      var f/eax: (addr buffered-file) <- lookup *f-ah
+      compare f, 0
+      break-if-=
+      # TODO
+      var w/eax: int <- copy 4
+      compare w, out
+      break-if-<=
+      copy-to out, w
+    }
     i <- increment
     loop
   }
pre>
4c13e1f2 ^

f07bb12f ^















34a60763 ^
4c13e1f2 ^
















34a60763 ^
f07bb12f ^





1cd06f3f ^

f07bb12f ^



4e9450f9 ^

34a60763 ^
f07bb12f ^
4e9450f9 ^

f07bb12f ^








34a60763 ^

4e9450f9 ^

f07bb12f ^





















34a60763 ^
f07bb12f ^

34a60763 ^
f07bb12f ^

34a60763 ^
f07bb12f ^














4c13e1f2 ^








f07bb12f ^
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222