This commit is contained in:
Kartik Agaram 2020-07-16 22:34:57 -07:00
parent 571dd3e23c
commit 28b25a4893
3 changed files with 27 additions and 39 deletions

View File

@ -101,6 +101,13 @@ var/reg <span class="Special">&lt;-</span> xor n =&gt; <span cl
xor-with var, n =&gt; <span class="Constant">&quot;81 6/subop/xor *(ebp+&quot;</span> var.stack-offset <span class="Constant">&quot;) &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
xor-with *var/reg, n =&gt; <span class="Constant">&quot;81 6/subop/xor *&quot;</span> reg <span class="Constant">&quot; &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
var/reg <span class="Special">&lt;-</span> shift-left n
var/reg <span class="Special">&lt;-</span> shift-right n
var/reg <span class="Special">&lt;-</span> shift-right-signed n
shift-left var, n
shift-right var, n
shift-right-signed var, n
var/<span class="Constant">eax</span> <span class="Special">&lt;-</span> copy n =&gt; <span class="Constant">&quot;b8/copy-to-eax &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
var/<span class="Constant">ecx</span> <span class="Special">&lt;-</span> copy n =&gt; <span class="Constant">&quot;b9/copy-to-ecx &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
var/<span class="Constant">edx</span> <span class="Special">&lt;-</span> copy n =&gt; <span class="Constant">&quot;ba/copy-to-edx &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
@ -115,6 +122,10 @@ var/reg <span class="Special">&lt;-</span> copy n =&gt; <span cl
copy-to var, n =&gt; <span class="Constant">&quot;c7 0/subop/copy *(ebp+&quot;</span> var.stack-offset <span class="Constant">&quot;) &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
copy-to *var/reg, n =&gt; <span class="Constant">&quot;c7 0/subop/copy *&quot;</span> reg <span class="Constant">&quot; &quot;</span> n <span class="Constant">&quot;/imm32&quot;</span>
var/reg <span class="Special">&lt;-</span> copy-byte var2/reg2 =&gt; <span class="Constant">&quot;8a/byte-&gt; %&quot;</span> reg2 <span class="Constant">&quot; &quot;</span> reg <span class="Constant">&quot;/r32&quot;</span>
var/reg <span class="Special">&lt;-</span> copy-byte *var2/reg2 =&gt; <span class="Constant">&quot;8a/byte-&gt; *&quot;</span> reg2 <span class="Constant">&quot; &quot;</span> reg <span class="Constant">&quot;/r32&quot;</span>
copy-byte-to *var1/reg1, var2/reg2 =&gt; <span class="Constant">&quot;88/byte&lt;- *&quot;</span> reg1 <span class="Constant">&quot; &quot;</span> reg2 <span class="Constant">&quot;/r32&quot;</span>
compare var1, var2/reg2 =&gt; <span class="Constant">&quot;39/compare *(ebp+&quot;</span> var1.stack-offset <span class="Constant">&quot;) &quot;</span> reg2 <span class="Constant">&quot;/r32&quot;</span>
compare *var1/reg1, var2/reg2 =&gt; <span class="Constant">&quot;39/compare *&quot;</span> reg1 <span class="Constant">&quot; &quot;</span> reg2 <span class="Constant">&quot;/r32&quot;</span>
compare var1/reg1, var2 =&gt; <span class="Constant">&quot;3b/compare&lt;- *(ebp+&quot;</span> var2.stack-offset <span class="Constant">&quot;) &quot;</span> reg1 <span class="Constant">&quot;/r32&quot;</span>
@ -245,29 +256,13 @@ var/reg <span class="Special">&lt;-</span> length arr/reg2: (addr array T)
If a record (product) type T was defined to have elements a, b, c, ... of
types T_a, T_b, T_c, ..., then accessing one of those elements f of type T_f:
var/reg: (addr T_f) <span class="Special">&lt;-</span> get var2/reg2: (addr F), f
var/reg: (addr T_f) <span class="Special">&lt;-</span> get var2/reg2: (addr T), f
=&gt; <span class="Constant">&quot;8d/copy-address *(&quot;</span> reg2 <span class="Constant">&quot;+&quot;</span> offset(f) <span class="Constant">&quot;) &quot;</span> reg <span class="Constant">&quot;/r32&quot;</span>
var/reg: (addr T_f) <span class="Special">&lt;-</span> get var2: (addr F), f
var/reg: (addr T_f) <span class="Special">&lt;-</span> get var2: T, f
=&gt; <span class="Constant">&quot;8d/copy-address *(ebp+&quot;</span> var2.stack-offset <span class="Constant">&quot;+&quot;</span> offset(f) <span class="Constant">&quot;) &quot;</span> reg <span class="Constant">&quot;/r32&quot;</span>
<span class="Comment"># Handles for safe access to the heap</span>
copy-handle-to dest: (handle T), src: (handle T)
=&gt; <span class="Constant">&quot;50/push-eax&quot;</span>
<span class="Constant">&quot;8b/-&gt; *(ebp+&quot;</span> src.stack-offset <span class="Constant">&quot;) 0/r32/eax&quot;</span>
<span class="Constant">&quot;89/&lt;- *(ebp+&quot;</span> dest.stack-offset <span class="Constant">&quot;) 0/r32/eax&quot;</span>
<span class="Constant">&quot;8b/-&gt; *(ebp+&quot;</span> src.stack-offset+<span class="Constant">4</span> <span class="Constant">&quot;) 0/r32/eax&quot;</span>
<span class="Constant">&quot;89/&lt;- *(ebp+&quot;</span> dest.stack-offset+<span class="Constant">4</span> <span class="Constant">&quot;) 0/r32/eax&quot;</span>
<span class="Constant">&quot;58/pop-to-eax&quot;</span>
copy-handle-to *dest/reg: (addr handle T), src: (handle T)
=&gt; <span class="Constant">&quot;50/push-eax&quot;</span>
<span class="Constant">&quot;8b/-&gt; *(ebp+&quot;</span> src.stack-offset <span class="Constant">&quot;) 0/r32/eax&quot;</span>
<span class="Constant">&quot;89/&lt;- *&quot;</span> reg <span class="Constant">&quot; 0/r32/eax&quot;</span>
<span class="Constant">&quot;8b/-&gt; *(ebp+&quot;</span> src.stack-offset+<span class="Constant">4</span> <span class="Constant">&quot;) 0/r32/eax&quot;</span>
<span class="Constant">&quot;89/&lt;- *(&quot;</span> reg <span class="Constant">&quot;+4) 0/r32/eax&quot;</span>
<span class="Constant">&quot;58/pop-to-eax&quot;</span>
out/reg: (addr T) <span class="Special">&lt;-</span> lookup in: (handle T)
=&gt; <span class="Comment"># payload_allocid = in-&gt;address-&gt;allocid</span>
<span class="Constant">&quot;8b/-&gt; *(epb+&quot;</span> (in.stack-offset+<span class="Constant">4</span>) <span class="Constant">&quot;) &quot;</span> reg <span class="Constant">&quot;/r32&quot;</span>
@ -279,6 +274,14 @@ out/reg: (addr T) <span class="Special">&lt;-</span> lookup in: (handle T)
<span class="Constant">&quot;8b/-&gt; *(epb+&quot;</span> (in.stack-offset+<span class="Constant">4</span>) <span class="Constant">&quot;) &quot;</span> reg <span class="Constant">&quot;/r32&quot;</span>
<span class="Constant">&quot;81 0/subop/add %&quot;</span> reg <span class="Constant">&quot; 4/imm32&quot;</span> <span class="Comment"># skip payload-&gt;allocid</span>
<span class="Comment"># Allocating memory</span>
allocate in: (addr handle T)
=&gt; <span class="Constant">&quot;(allocate Heap &quot;</span> size-of(T) <span class="Constant">&quot; &quot;</span> in <span class="Constant">&quot;)&quot;</span>
populate in: (addr handle array T), num <span class="Comment"># can be literal or variable on stack or register</span>
=&gt; <span class="Constant">&quot;(allocate-array2 Heap &quot;</span> size-of(T) <span class="Constant">&quot; &quot;</span> num <span class="Constant">&quot; &quot;</span> in <span class="Constant">&quot;)&quot;</span>
vim&#0058;ft=mu:nowrap:textwidth=<span class="Constant">0</span>
</pre>
</body>

11
mu.md
View File

@ -438,18 +438,19 @@ rules:
Try to avoid mixing these use cases.
You can save handles inside compound types like this:
If you have a variable `src` of type `(handle ...)`, you can save it inside a
compound type like this (provided the types match):
```
var y/reg: (addr handle T_f) <- get var: (addr T), f
copy-handle-to *y, x
var dest/reg: (addr handle T_f) <- get var: (addr T), f
copy-handle src, dest
```
Or this:
```
var y/reg: (addr handle T) <- index arr: (addr array handle T), n
copy-handle-to *y, x
var dest/reg: (addr handle T) <- index arr: (addr array handle T), n
copy-handle src, dest
```
To create handles to non-array types, use `allocate`:

View File

@ -238,22 +238,6 @@ var/reg: (addr T_f) <- get var2: T, f
# Handles for safe access to the heap
copy-handle-to dest: (handle T), src: (handle T)
=> "50/push-eax"
"8b/-> *(ebp+" src.stack-offset ") 0/r32/eax"
"89/<- *(ebp+" dest.stack-offset ") 0/r32/eax"
"8b/-> *(ebp+" src.stack-offset+4 ") 0/r32/eax"
"89/<- *(ebp+" dest.stack-offset+4 ") 0/r32/eax"
"58/pop-to-eax"
copy-handle-to *dest/reg: (addr handle T), src: (handle T)
=> "50/push-eax"
"8b/-> *(ebp+" src.stack-offset ") 0/r32/eax"
"89/<- *" reg " 0/r32/eax"
"8b/-> *(ebp+" src.stack-offset+4 ") 0/r32/eax"
"89/<- *(" reg "+4) 0/r32/eax"
"58/pop-to-eax"
out/reg: (addr T) <- lookup in: (handle T)
=> # payload_allocid = in->address->allocid
"8b/-> *(epb+" (in.stack-offset+4) ") " reg "/r32"