diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-03-22 12:11:49 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-05-18 00:44:46 -0700 |
commit | 546a92985f7da2491077d641a2c118b4af7f6913 (patch) | |
tree | 1e6ab75543a3028e78c9454fbb6bd6b6a076e0ee /070new-stream.subx | |
parent | 1f38b75e31d713fc72a9d29d360fe5ad66ba22fe (diff) | |
download | mu-546a92985f7da2491077d641a2c118b4af7f6913.tar.gz |
start migrating handles to fat pointers
CI will fail from this commit onward. Currently working: $ bootstrap translate init.linux 0[4-7]*.subx 080zero-out.subx -o a.elf && ./a.elf test $ bootstrap run a.elf test $ chmod +x a.elf; ./a.elf test Plan: migrate functions that used to return handles to pass in a new arg of type (addr handle). That's a bit of a weird type. There should be few of these functions. (Open question: do we even want to expose this type in the Mu language?) Functions that just need to read from heap without modifying the handle will receive `(addr T)` or `(handle T)` types as arguments. As I sanitize each new file, I need to update signatures for any new functions and add them to a list. I also need to update calls to any functions on the list.
Diffstat (limited to '070new-stream.subx')
-rw-r--r-- | 070new-stream.subx | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/070new-stream.subx b/070new-stream.subx index 5474175b..b4326096 100644 --- a/070new-stream.subx +++ b/070new-stream.subx @@ -5,11 +5,12 @@ # . op subop mod rm32 base index scale r32 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes -new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int -> address/eax: (handle stream _) +new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int, out: (handle stream _) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers + 50/push-eax 52/push-edx # var n/eax: int = elemsize * length + 12 (for read, write and size) # . eax = elemsize @@ -24,14 +25,20 @@ new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int -> a 89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . . # copy eax to edx # . eax += 12 05/add-to-eax 0xc/imm32 - # var eax: (handle stream _) = allocate(ad, n) + # allocate(ad, n, out) # . . push args + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 . # push *(ebp+20) 50/push-eax ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call allocate/disp32 # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # eax = out->payload + 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x14/disp8 . # copy *(ebp+20) to eax + 8b/copy 1/mod/*+disp8 0/rm32/eax . . . 0/r32/eax 4/disp8 . # copy *(eax+4) to eax + # skip payload->allocid + 05/add-to-eax 4/imm32 # eax->size = elemsize*length 89/copy 1/mod/*+disp8 0/rm32/eax . . . 2/r32/edx 8/disp8 . # copy edx to *(eax+8) # clear-stream(eax) @@ -44,6 +51,7 @@ new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int -> a $new-stream:end: # . restore registers 5a/pop-to-edx + 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp @@ -82,15 +90,22 @@ test-new-stream: 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # var start/edx = ad->curr 8b/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . . # copy *ecx to edx - # var eax: (handle stream byte) = new-stream(heap, 3, 2) + # var h/ebx: (handle stream byte) + 68/push 0/imm32 + 68/push 0/imm32 + 89/copy 3/mod/direct 3/rm32/ebx . . . 4/r32/esp . . # copy esp to ebx + # new-stream(heap, 3, 2, h) # . . push args + 53/push-ebx 68/push 2/imm32 68/push 3/imm32 51/push-ecx # . . call e8/call new-stream/disp32 # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp + # eax = out->payload + 8b/copy 1/mod/*+disp8 3/rm32/ebx . . . 0/r32/eax 4/disp8 . # copy *(ebx+4) to eax # check-ints-equal(eax, edx, msg) # . . push args 68/push "F - test-new-stream: returns current pointer of allocation descriptor"/imm32 @@ -100,6 +115,8 @@ test-new-stream: e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # skip payload->allocid + 05/add-to-eax 4/imm32 # check-ints-equal(eax->size, 6, msg) # . . push args 68/push "F - test-new-stream: sets size correctly"/imm32 @@ -110,6 +127,8 @@ test-new-stream: # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # the rest is delegated to clear-stream() so we won't bother checking it + # . reclaim locals + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp |