diff options
-rw-r--r-- | html/mu_instructions.html | 39 | ||||
-rw-r--r-- | mu.md | 11 | ||||
-rw-r--r-- | mu_instructions | 16 |
3 files changed, 27 insertions, 39 deletions
diff --git a/html/mu_instructions.html b/html/mu_instructions.html index 0353f35b..6d91ec55 100644 --- a/html/mu_instructions.html +++ b/html/mu_instructions.html @@ -101,6 +101,13 @@ var/reg <span class="Special"><-</span> xor n => <span cl xor-with var, n => <span class="Constant">"81 6/subop/xor *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> xor-with *var/reg, n => <span class="Constant">"81 6/subop/xor *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="Special"><-</span> shift-left n +var/reg <span class="Special"><-</span> shift-right n +var/reg <span class="Special"><-</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"><-</span> copy n => <span class="Constant">"b8/copy-to-eax "</span> n <span class="Constant">"/imm32"</span> var/<span class="Constant">ecx</span> <span class="Special"><-</span> copy n => <span class="Constant">"b9/copy-to-ecx "</span> n <span class="Constant">"/imm32"</span> var/<span class="Constant">edx</span> <span class="Special"><-</span> copy n => <span class="Constant">"ba/copy-to-edx "</span> n <span class="Constant">"/imm32"</span> @@ -115,6 +122,10 @@ var/reg <span class="Special"><-</span> copy n => <span cl copy-to var, n => <span class="Constant">"c7 0/subop/copy *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> copy-to *var/reg, n => <span class="Constant">"c7 0/subop/copy *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="Special"><-</span> copy-byte var2/reg2 => <span class="Constant">"8a/byte-> %"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="Special"><-</span> copy-byte *var2/reg2 => <span class="Constant">"8a/byte-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +copy-byte-to *var1/reg1, var2/reg2 => <span class="Constant">"88/byte<- *"</span> reg1 <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> + compare var1, var2/reg2 => <span class="Constant">"39/compare *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg2 <span class="Constant">"/r32"</span> compare *var1/reg1, var2/reg2 => <span class="Constant">"39/compare *"</span> reg1 <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> compare var1/reg1, var2 => <span class="Constant">"3b/compare<- *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg1 <span class="Constant">"/r32"</span> @@ -245,29 +256,13 @@ var/reg <span class="Special"><-</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"><-</span> get var2/reg2: (addr F), f +var/reg: (addr T_f) <span class="Special"><-</span> get var2/reg2: (addr T), f => <span class="Constant">"8d/copy-address *("</span> reg2 <span class="Constant">"+"</span> offset(f) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg: (addr T_f) <span class="Special"><-</span> get var2: (addr F), f +var/reg: (addr T_f) <span class="Special"><-</span> get var2: T, f => <span class="Constant">"8d/copy-address *(ebp+"</span> var2.stack-offset <span class="Constant">"+"</span> offset(f) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> <span class="Comment"># Handles for safe access to the heap</span> -copy-handle-to dest: (handle T), src: (handle T) - => <span class="Constant">"50/push-eax"</span> - <span class="Constant">"8b/-> *(ebp+"</span> src.stack-offset <span class="Constant">") 0/r32/eax"</span> - <span class="Constant">"89/<- *(ebp+"</span> dest.stack-offset <span class="Constant">") 0/r32/eax"</span> - <span class="Constant">"8b/-> *(ebp+"</span> src.stack-offset+<span class="Constant">4</span> <span class="Constant">") 0/r32/eax"</span> - <span class="Constant">"89/<- *(ebp+"</span> dest.stack-offset+<span class="Constant">4</span> <span class="Constant">") 0/r32/eax"</span> - <span class="Constant">"58/pop-to-eax"</span> - -copy-handle-to *dest/reg: (addr handle T), src: (handle T) - => <span class="Constant">"50/push-eax"</span> - <span class="Constant">"8b/-> *(ebp+"</span> src.stack-offset <span class="Constant">") 0/r32/eax"</span> - <span class="Constant">"89/<- *"</span> reg <span class="Constant">" 0/r32/eax"</span> - <span class="Constant">"8b/-> *(ebp+"</span> src.stack-offset+<span class="Constant">4</span> <span class="Constant">") 0/r32/eax"</span> - <span class="Constant">"89/<- *("</span> reg <span class="Constant">"+4) 0/r32/eax"</span> - <span class="Constant">"58/pop-to-eax"</span> - out/reg: (addr T) <span class="Special"><-</span> lookup in: (handle T) => <span class="Comment"># payload_allocid = in->address->allocid</span> <span class="Constant">"8b/-> *(epb+"</span> (in.stack-offset+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> @@ -279,6 +274,14 @@ out/reg: (addr T) <span class="Special"><-</span> lookup in: (handle T) <span class="Constant">"8b/-> *(epb+"</span> (in.stack-offset+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> <span class="Constant">"81 0/subop/add %"</span> reg <span class="Constant">" 4/imm32"</span> <span class="Comment"># skip payload->allocid</span> +<span class="Comment"># Allocating memory</span> + +allocate in: (addr handle T) + => <span class="Constant">"(allocate Heap "</span> size-of(T) <span class="Constant">" "</span> in <span class="Constant">")"</span> + +populate in: (addr handle array T), num <span class="Comment"># can be literal or variable on stack or register</span> + => <span class="Constant">"(allocate-array2 Heap "</span> size-of(T) <span class="Constant">" "</span> num <span class="Constant">" "</span> in <span class="Constant">")"</span> + vim:ft=mu:nowrap:textwidth=<span class="Constant">0</span> </pre> </body> diff --git a/mu.md b/mu.md index be91fc10..aadb78e8 100644 --- a/mu.md +++ b/mu.md @@ -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`: diff --git a/mu_instructions b/mu_instructions index 69999444..e28edfff 100644 --- a/mu_instructions +++ b/mu_instructions @@ -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" |