diff options
-rw-r--r-- | 069allocate.subx | 137 | ||||
-rw-r--r-- | 080zero-out.subx | 84 | ||||
-rwxr-xr-x | apps/assort | bin | 40838 -> 40881 bytes | |||
-rwxr-xr-x | apps/braces | bin | 42633 -> 42676 bytes | |||
-rwxr-xr-x | apps/calls | bin | 47294 -> 47337 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1 | bin | 40241 -> 40284 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1b | bin | 40788 -> 40831 bytes | |||
-rwxr-xr-x | apps/dquotes | bin | 44483 -> 44526 bytes | |||
-rwxr-xr-x | apps/factorial | bin | 39260 -> 39303 bytes | |||
-rwxr-xr-x | apps/handle | bin | 40158 -> 40201 bytes | |||
-rwxr-xr-x | apps/hex | bin | 43080 -> 43123 bytes | |||
-rwxr-xr-x | apps/mu | bin | 212019 -> 211758 bytes | |||
-rw-r--r-- | apps/mu.subx | 18 | ||||
-rwxr-xr-x | apps/pack | bin | 53225 -> 53268 bytes | |||
-rwxr-xr-x | apps/sigils | bin | 55018 -> 55061 bytes | |||
-rwxr-xr-x | apps/survey | bin | 49863 -> 49906 bytes | |||
-rwxr-xr-x | apps/tests | bin | 39631 -> 39674 bytes |
17 files changed, 123 insertions, 116 deletions
diff --git a/069allocate.subx b/069allocate.subx index 6332a73a..3857ddb8 100644 --- a/069allocate.subx +++ b/069allocate.subx @@ -54,12 +54,40 @@ $array-equal-main:end: b8/copy-to-eax 1/imm32/exit cd/syscall 0x80/imm8 -# Claim the next 'n' bytes of memory starting at ad->curr and update ad->curr. +# Allocate and clear 'n' bytes of memory from an allocation-descriptor 'ad'. # Abort if there isn't enough memory in 'ad'. allocate: # ad: (addr allocation-descriptor), n: int -> address-or-null/eax: (addr _) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # eax = allocate-raw(ad, n) + # . . push args + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call allocate-raw/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # zero-out(eax, n) + # . . push args + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) + 50/push-eax + # . . call + e8/call zero-out/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +$allocate:end: + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + +# Claim the next 'n' bytes of memory starting at ad->curr and update ad->curr. +# Abort if there isn't enough memory in 'ad'. +allocate-raw: # ad: (addr allocation-descriptor), n: int -> address-or-null/eax: (addr _) + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 51/push-ecx 52/push-edx @@ -72,11 +100,11 @@ allocate: # ad: (addr allocation-descriptor), n: int -> address-or-null/eax: (a 89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . . # copy eax to edx 03/add 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 . # add *(ebp+12) to edx 3b/compare 1/mod/*+disp8 1/rm32/ecx . . . 2/r32/edx 4/disp8 . # compare edx with *(ecx+4) - 73/jump-if->=-signed $allocate:abort/disp8 -$allocate:commit: + 73/jump-if->=-signed $allocate-raw:abort/disp8 +$allocate-raw:commit: # update ad->curr 89/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . . # copy edx to *ecx -$allocate:end: +$allocate-raw:end: # . restore registers 5a/pop-to-edx 59/pop-to-ecx @@ -85,10 +113,10 @@ $allocate:end: 5d/pop-to-ebp c3/return -$allocate:abort: +$allocate-raw:abort: # . _write(2/stderr, error) # . . push args - 68/push "allocate: failed to allocate\n"/imm32 + 68/push "allocate: failed\n"/imm32 68/push 2/imm32/stderr # . . call e8/call _write/disp32 @@ -100,7 +128,7 @@ $allocate:abort: cd/syscall 0x80/imm8 # never gets here -test-allocate-success: +test-allocate-raw-success: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp @@ -108,17 +136,17 @@ test-allocate-success: 68/push 0xf/imm32/limit 68/push 0xb/imm32/curr 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx - # var eax: (handle byte) = allocate(ad, 3) + # var eax: (handle byte) = allocate-raw(ad, 3) # . . push args 68/push 3/imm32 51/push-ecx # . . call - e8/call allocate/disp32 + e8/call allocate-raw/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-ints-equal(eax, 11, msg) # . . push args - 68/push "F - test-allocate-success: returns current pointer of allocation descriptor"/imm32 + 68/push "F - test-allocate-raw-success: returns current pointer of allocation descriptor"/imm32 68/push 0xb/imm32 50/push-eax # . . call @@ -127,7 +155,7 @@ test-allocate-success: 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(ad->curr, 14, msg) # . . push args - 68/push "F - test-allocate-success: updates allocation descriptor"/imm32 + 68/push "F - test-allocate-raw-success: updates allocation descriptor"/imm32 68/push 0xe/imm32 ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call @@ -139,7 +167,7 @@ test-allocate-success: 5d/pop-to-ebp c3/return -_pending-test-allocate-failure: +_pending-test-allocate-raw-failure: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp @@ -147,17 +175,17 @@ _pending-test-allocate-failure: 68/push 0xf/imm32/limit 68/push 0xb/imm32/curr 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx - # var eax: (handle byte) = allocate(ad, 6) + # var eax: (handle byte) = allocate-raw(ad, 6) # . . push args 68/push 6/imm32 51/push-ecx # . . call - e8/call allocate/disp32 + e8/call allocate-raw/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-ints-equal(eax, 0, msg) # . . push args - 68/push "F - test-allocate-failure: returns null"/imm32 + 68/push "F - test-allocate-raw-failure: returns null"/imm32 68/push 0/imm32 50/push-eax # . . call @@ -167,7 +195,7 @@ _pending-test-allocate-failure: # no change to ad->curr # . check-ints-equal(ad->curr, 11) # . . push args - 68/push "F - test-allocate-failure: updates allocation descriptor"/imm32 + 68/push "F - test-allocate-raw-failure: updates allocation descriptor"/imm32 68/push 0xb/imm32 ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call @@ -266,4 +294,81 @@ $allocate-array:end: 5d/pop-to-ebp c3/return +# Fill a region of memory with zeroes. +zero-out: # start: (addr byte), len: int + # pseudocode: + # curr/esi = start + # i/ecx = 0 + # while true + # if (i >= len) break + # *curr = 0 + # ++curr + # ++i + # + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # . save registers + 50/push-eax + 51/push-ecx + 52/push-edx + 56/push-esi + # curr/esi = start + 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi + # var i/ecx: int = 0 + 31/xor 3/mod/direct 1/rm32/ecx . . . 1/r32/ecx . . # clear ecx + # edx = len + 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 . # copy *(ebp+12) to edx +$zero-out:loop: + # if (i >= len) break + 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . . # compare ecx with edx + 7d/jump-if->= $zero-out:end/disp8 + # *curr = 0 + c6 0/subop/copy 0/mod/direct 6/rm32/esi . . . . . 0/imm8 # copy byte to *esi + # ++curr + 46/increment-esi + # ++i + 41/increment-ecx + eb/jump $zero-out:loop/disp8 +$zero-out:end: + # . restore registers + 5e/pop-to-esi + 5a/pop-to-edx + 59/pop-to-ecx + 58/pop-to-eax + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + +test-zero-out: + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # region/ecx = 34, 35, 36, 37 + 68/push 0x37363534/imm32 + 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx + # zero-out(ecx, 3) + # . . push args + 68/push 3/imm32/len + 51/push-ecx + # . . call + e8/call zero-out/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # first 3 bytes cleared, fourth left alone + # . check-ints-equal(*ecx, 0x37000000, msg) + # . . push args + 68/push "F - test-zero-out"/imm32 + 68/push 0x37000000/imm32 + ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx + # . . call + e8/call check-ints-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + # . . vim:nowrap:textwidth=0 diff --git a/080zero-out.subx b/080zero-out.subx deleted file mode 100644 index 681dd621..00000000 --- a/080zero-out.subx +++ /dev/null @@ -1,84 +0,0 @@ -# Fill a region of memory with zeroes. - -== code -# instruction effective address register displacement immediate -# . 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 - -zero-out: # start: (addr byte), len: int - # pseudocode: - # curr/esi = start - # i/ecx = 0 - # while true - # if (i >= len) break - # *curr = 0 - # ++curr - # ++i - # - # . prologue - 55/push-ebp - 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - # . save registers - 50/push-eax - 51/push-ecx - 52/push-edx - 56/push-esi - # curr/esi = start - 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi - # var i/ecx: int = 0 - 31/xor 3/mod/direct 1/rm32/ecx . . . 1/r32/ecx . . # clear ecx - # edx = len - 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 . # copy *(ebp+12) to edx -$zero-out:loop: - # if (i >= len) break - 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . . # compare ecx with edx - 7d/jump-if->= $zero-out:end/disp8 - # *curr = 0 - c6 0/subop/copy 0/mod/direct 6/rm32/esi . . . . . 0/imm8 # copy byte to *esi - # ++curr - 46/increment-esi - # ++i - 41/increment-ecx - eb/jump $zero-out:loop/disp8 -$zero-out:end: - # . restore registers - 5e/pop-to-esi - 5a/pop-to-edx - 59/pop-to-ecx - 58/pop-to-eax - # . epilogue - 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 5d/pop-to-ebp - c3/return - -test-zero-out: - # . prologue - 55/push-ebp - 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - # region/ecx = 34, 35, 36, 37 - 68/push 0x37363534/imm32 - 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx - # zero-out(ecx, 3) - # . . push args - 68/push 3/imm32/len - 51/push-ecx - # . . call - e8/call zero-out/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # first 3 bytes cleared, fourth left alone - # . check-ints-equal(*ecx, 0x37000000, msg) - # . . push args - 68/push "F - test-zero-out"/imm32 - 68/push 0x37000000/imm32 - ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx - # . . call - e8/call check-ints-equal/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp - # . epilogue - 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 5d/pop-to-ebp - c3/return - -# . . vim:nowrap:textwidth=0 diff --git a/apps/assort b/apps/assort index 3c24b4a6..5a5104df 100755 --- a/apps/assort +++ b/apps/assort Binary files differdiff --git a/apps/braces b/apps/braces index f26cc91a..59a7abfd 100755 --- a/apps/braces +++ b/apps/braces Binary files differdiff --git a/apps/calls b/apps/calls index 15e8b095..815c1a3d 100755 --- a/apps/calls +++ b/apps/calls Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1 index 8f59dc7e..a3a6e78c 100755 --- a/apps/crenshaw2-1 +++ b/apps/crenshaw2-1 Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b index 62ca8b7a..12541d5b 100755 --- a/apps/crenshaw2-1b +++ b/apps/crenshaw2-1b Binary files differdiff --git a/apps/dquotes b/apps/dquotes index 9f1d1b4d..e87639f8 100755 --- a/apps/dquotes +++ b/apps/dquotes Binary files differdiff --git a/apps/factorial b/apps/factorial index 0bb8b2c8..97c62ac8 100755 --- a/apps/factorial +++ b/apps/factorial Binary files differdiff --git a/apps/handle b/apps/handle index 51b34f63..33486991 100755 --- a/apps/handle +++ b/apps/handle Binary files differdiff --git a/apps/hex b/apps/hex index 55e10f7f..2dabb90f 100755 --- a/apps/hex +++ b/apps/hex Binary files differdiff --git a/apps/mu b/apps/mu index e3fd8afe..26650b50 100755 --- a/apps/mu +++ b/apps/mu Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx index d2ca23b9..fddf9444 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -3217,7 +3217,6 @@ $parse-mu:fn: 0f 84/jump-if-= break/disp32 # var new-function/eax: (handle function) = populate-mu-function(line, in, vars) (allocate Heap *Function-size) # => eax - (zero-out %eax *Function-size) (clear-stack %ebx) (populate-mu-function-header %ecx %eax %ebx) (populate-mu-function-body *(ebp+8) %eax %ebx) @@ -3796,7 +3795,6 @@ parse-type: # ad: (address allocation-descriptor), in: (addr stream byte) -> re 0f 85/jump-if-!= $parse-type:end/disp32 # var result/edx: (handle tree type-id) (allocate *(ebp+8) *Tree-size) # => eax - (zero-out %eax *Tree-size) $aa-alloc: 89/<- %edx 0/r32/eax { @@ -3890,7 +3888,6 @@ parse-type-tree: # ad: (address allocation-descriptor), in: (addr stream byte) 89/<- %ecx 0/r32/eax # var result/edx: (handle tree type-id) (allocate *(ebp+8) *Tree-size) # => eax - (zero-out %eax *Tree-size) 89/<- %edx 0/r32/eax # result->left = tmp2 89/<- *(edx+4) 1/r32/ecx # Tree-left @@ -4701,7 +4698,6 @@ parse-mu-block: # in: (addr buffered-file), vars: (addr stack (handle var)), fn 89/<- %edx 4/r32/esp # edi = result (allocate Heap *Stmt-size) # => eax - (zero-out %eax *Stmt-size) 89/<- %edi 0/r32/eax # set result->tag c7 0/subop/copy *edi 0/imm32/block # Stmt-tag @@ -5126,7 +5122,6 @@ parse-mu-stmt: # line: (addr stream byte), vars: (addr stack (handle var)), fn: ba/copy-to-edx 0/imm32/false # result/edi: (handle stmt) (allocate Heap *Stmt-size) # => eax - (zero-out %eax *Stmt-size) 89/<- %edi 0/r32/eax # result->tag = 1/stmt c7 0/subop/copy *edi 1/imm32/stmt1 # Stmt-tag @@ -5646,7 +5641,6 @@ new-var: # ad: (addr allocation-descriptor), name: (addr array byte) -> result/ 51/push-ecx # (allocate *(ebp+8) *Var-size) # => eax - (zero-out %eax *Var-size) 8b/-> *(ebp+0xc) 1/r32/ecx 89/<- *eax 1/r32/ecx # Var-name $new-var:end: @@ -5669,7 +5663,7 @@ new-literal-integer: # ad: (addr allocation-descriptor), name: (addr slice) -> 0f 84/jump-if-= $new-literal-integer:abort/disp32 # var type/ecx: (handle tree type-id) = new type() (allocate *(ebp+8) *Tree-size) # => eax - (zero-out %eax *Tree-size) # default type is 'literal' + # nothing else to do; default type is 'literal' c7 0/subop/copy *eax 1/imm32/true # Tree-is-atom 89/<- %ecx 0/r32/eax # result = new var(s) @@ -5706,7 +5700,7 @@ new-literal: # ad: (addr allocation-descriptor), name: (addr slice) -> result/e 89/<- %ecx 0/r32/eax # type = new type() (allocate *(ebp+8) *Tree-size) # => eax - (zero-out %eax *Tree-size) # default type is 'literal' + # nothing else to do; default type is 'literal' c7 0/subop/copy *eax 1/imm32/true # Tree-is-atom 89/<- %edx 0/r32/eax # eax = result @@ -5747,7 +5741,6 @@ new-block: # ad: (addr allocation-descriptor), data: (handle list stmt) -> resu 51/push-ecx # (allocate *(ebp+8) *Stmt-size) # => eax - (zero-out %eax *Stmt-size) c7 0/subop/copy *eax 0/imm32/tag/block # Stmt-tag 8b/-> *(ebp+0xc) 1/r32/ecx 89/<- *(eax+4) 1/r32/ecx # Block-stmts @@ -5767,7 +5760,6 @@ new-var-def: # ad: (addr allocation-descriptor), var: (handle var) -> result/ea 51/push-ecx # (allocate *(ebp+8) *Stmt-size) # => eax - (zero-out %eax *Stmt-size) c7 0/subop/copy *eax 2/imm32/tag/var-on-stack # Stmt-tag # result->var = var 8b/-> *(ebp+0xc) 1/r32/ecx @@ -5792,7 +5784,6 @@ new-reg-var-def: # ad: (addr allocation-descriptor), var: (handle var) -> resul # edi = result (allocate *(ebp+8) *Stmt-size) # => eax 89/<- %edi 0/r32/eax - (zero-out %edi *Stmt-size) # set tag c7 0/subop/copy *edi 3/imm32/tag/var-in-register # Stmt-tag # set output @@ -5816,7 +5807,6 @@ append-list: # ad: (addr allocation-descriptor), value: _type, list: (handle li 51/push-ecx # (allocate *(ebp+8) *List-size) # => eax - (zero-out %eax *List-size) 8b/-> *(ebp+0xc) 1/r32/ecx 89/<- *eax 1/r32/ecx # List-value # if (list == null) return result @@ -5853,7 +5843,6 @@ append-stmt-var: # ad: (addr allocation-descriptor), v: (handle var), vars: (ha 51/push-ecx # (allocate *(ebp+8) *Stmt-var-size) # => eax - (zero-out %eax *Stmt-var-size) 8b/-> *(ebp+0xc) 1/r32/ecx 89/<- *eax 1/r32/ecx # Stmt-var-value 8b/-> *(ebp+0x14) 1/r32/ecx @@ -5976,7 +5965,6 @@ find-or-create-typeinfo: # t: type-id -> result/eax: (handle typeinfo) 75/jump-if-!= break/disp8 $find-or-create-typeinfo:create: (allocate Heap *Typeinfo-size) # => eax - (zero-out %eax *Typeinfo-size) # result->id = t 8b/-> *(ebp+8) 1/r32/ecx 89/<- *eax 1/r32/ecx # Typeinfo-id @@ -6048,7 +6036,6 @@ find-or-create-typeinfo-output-var: # T: (handle typeinfo), f: (addr slice) -> 75/jump-if-!= break/disp8 # var type/eax: (handle tree type-id) = new var("dummy name", constant type, -1 offset) (allocate Heap *Tree-size) # => eax - (zero-out %eax *Tree-size) c7 0/subop/copy *(eax+4) 6/imm32/constant # Tree-value c7 0/subop/copy *(eax+8) 0/imm32 # Tree-right 89/<- %ecx 0/r32/eax @@ -6089,7 +6076,6 @@ find-or-create-typeinfo-fields: # T: (handle typeinfo), f: (addr slice) -> resu 81 7/subop/compare *esi 0/imm32 # output var 75/jump-if-!= break/disp8 (allocate Heap *Typeinfo-entry-size) # => eax - (zero-out %eax *Typeinfo-entry-size) 89/<- *esi 0/r32/eax } # eax = T->fields[f]->entry diff --git a/apps/pack b/apps/pack index d9c6b804..b190e67d 100755 --- a/apps/pack +++ b/apps/pack Binary files differdiff --git a/apps/sigils b/apps/sigils index 6b79497e..4879cb36 100755 --- a/apps/sigils +++ b/apps/sigils Binary files differdiff --git a/apps/survey b/apps/survey index b1fd77a7..633e7fe4 100755 --- a/apps/survey +++ b/apps/survey Binary files differdiff --git a/apps/tests b/apps/tests index 9d5a07b4..feda7995 100755 --- a/apps/tests +++ b/apps/tests Binary files differ |