From 28b25a489338f31f291832e8dc94174619387e95 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 16 Jul 2020 22:34:57 -0700 Subject: [PATCH] 6657 --- html/mu_instructions.html | 39 +++++++++++++++++++++------------------ mu.md | 11 ++++++----- 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 <- xor n => "81 6/subop/xor *(ebp+" var.stack-offset ") " n "/imm32" xor-with *var/reg, n => "81 6/subop/xor *" reg " " n "/imm32" +var/reg <- shift-left n +var/reg <- shift-right n +var/reg <- shift-right-signed n +shift-left var, n +shift-right var, n +shift-right-signed var, n + var/eax <- copy n => "b8/copy-to-eax " n "/imm32" var/ecx <- copy n => "b9/copy-to-ecx " n "/imm32" var/edx <- copy n => "ba/copy-to-edx " n "/imm32" @@ -115,6 +122,10 @@ var/reg <- copy n => "c7 0/subop/copy *(ebp+" var.stack-offset ") " n "/imm32" copy-to *var/reg, n => "c7 0/subop/copy *" reg " " n "/imm32" +var/reg <- copy-byte var2/reg2 => "8a/byte-> %" reg2 " " reg "/r32" +var/reg <- copy-byte *var2/reg2 => "8a/byte-> *" reg2 " " reg "/r32" +copy-byte-to *var1/reg1, var2/reg2 => "88/byte<- *" reg1 " " reg2 "/r32" + compare var1, var2/reg2 => "39/compare *(ebp+" var1.stack-offset ") " reg2 "/r32" compare *var1/reg1, var2/reg2 => "39/compare *" reg1 " " reg2 "/r32" compare var1/reg1, var2 => "3b/compare<- *(ebp+" var2.stack-offset ") " reg1 "/r32" @@ -245,29 +256,13 @@ var/reg <- 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) <- get var2/reg2: (addr F), f +var/reg: (addr T_f) <- get var2/reg2: (addr T), f => "8d/copy-address *(" reg2 "+" offset(f) ") " reg "/r32" -var/reg: (addr T_f) <- get var2: (addr F), f +var/reg: (addr T_f) <- get var2: T, f => "8d/copy-address *(ebp+" var2.stack-offset "+" offset(f) ") " reg "/r32" # 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" @@ -279,6 +274,14 @@ out/reg: (addr T) <- lookup in: (handle T) "8b/-> *(epb+" (in.stack-offset+4) ") " reg "/r32" "81 0/subop/add %" reg " 4/imm32" # skip payload->allocid +# Allocating memory + +allocate in: (addr handle T) + => "(allocate Heap " size-of(T) " " in ")" + +populate in: (addr handle array T), num # can be literal or variable on stack or register + => "(allocate-array2 Heap " size-of(T) " " num " " in ")" + vim:ft=mu:nowrap:textwidth=0 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"