From c089e33853f613b24005153515d2e51c79c446e2 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 17 Feb 2020 20:10:39 -0800 Subject: 6017 - simplify type-dispatch for primitives We'll be doing type-checking in a separate phase in future. For now we need only to distinguish between literals and non-literals for x86 primitive instructions. I was tempted to support x86 set__ instructions for this change: https://c9x.me/x86/html/file_module_x86_id_288.html That will happen at some point. And I'll simplify a bunch of branches for results of predicate functions when it happens. --- apps/mu | Bin 133450 -> 133529 bytes apps/mu.subx | 92 ++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 26 deletions(-) (limited to 'apps') diff --git a/apps/mu b/apps/mu index 29e0f145..d1a0d098 100755 Binary files a/apps/mu and b/apps/mu differ diff --git a/apps/mu.subx b/apps/mu.subx index 98aefa34..fa32de32 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -4329,6 +4329,45 @@ $size-of:end: 5d/pop-to-ebp c3/return +type-equal?: # a: (handle tree type-id), b: (handle tree type-id) -> result/eax: boolean + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # . save registers + 51/push-ecx + 52/push-edx + # ecx = a + 8b/-> *(ebp+8) 1/r32/ecx + # edx = b + 8b/-> *(ebp+0xc) 2/r32/edx + # if (a == b) return true + 8b/-> %ecx 0/r32/eax # Var-type + 39/compare %edx 0/r32/eax # Var-type + b8/copy-to-eax 1/imm32/true + 74/jump-if-= $type-equal?:end/disp8 + # if (a < MAX_TYPE_ID) return false + 81 7/subop/compare %ecx 0x10000/imm32 + b8/copy-to-eax 0/imm32/false + 72/jump-if-addr< $type-equal?:end/disp8 + # if (b < MAX_TYPE_ID) return false + 81 7/subop/compare %edx 0x10000/imm32 + b8/copy-to-eax 0/imm32/false + 72/jump-if-addr< $type-equal?:end/disp8 + # if (!type-equal?(a->left, b->left)) return false + (type-equal? *ecx *edx) # Tree-left, Tree-left => eax + 3d/compare-eax-and 0/imm32/false + 74/jump-if-= $type-equal?:end/disp8 + # return type-equal?(a->right, b->right) + (type-equal? *(ecx+4) *(edx+4)) # Tree-right, Tree-right => eax +$type-equal?:end: + # . restore registers + 5a/pop-to-edx + 59/pop-to-ecx + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + == data # not yet used, but it will be @@ -7077,45 +7116,46 @@ $operand-matches-primitive?:end: 5d/pop-to-ebp c3/return -type-equal?: # a: (handle tree type-id), b: (handle tree type-id) -> result/eax: boolean +subx-type-equal?: # a: (handle tree type-id), b: (handle tree type-id) -> result/eax: boolean # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp # . save registers 51/push-ecx - 52/push-edx - # ecx = a - 8b/-> *(ebp+8) 1/r32/ecx - # edx = b - 8b/-> *(ebp+0xc) 2/r32/edx - # if (a == b) return true - 8b/-> %ecx 0/r32/eax # Var-type - 39/compare %edx 0/r32/eax # Var-type - b8/copy-to-eax 1/imm32/true - 74/jump-if-= $type-equal?:end/disp8 - # if (a < MAX_TYPE_ID) return false - 81 7/subop/compare %ecx 0x10000/imm32 - b8/copy-to-eax 0/imm32/false - 72/jump-if-addr< $type-equal?:end/disp8 - # if (b < MAX_TYPE_ID) return false - 81 7/subop/compare %edx 0x10000/imm32 + # var alit/ecx: boolean = is-literal-type?(a) + (is-literal-type? *(ebp+8)) # => eax + 89/<- %ecx 0/r32/eax + # var blit/eax: boolean = is-literal-type?(b) + (is-literal-type? *(ebp+0xc)) # => eax + # return alit == blit + 39/compare %eax 1/r32/ecx + 74/jump-if-= $subx-type-equal?:true/disp8 +$subx-type-equal?:false: b8/copy-to-eax 0/imm32/false - 72/jump-if-addr< $type-equal?:end/disp8 - # if (!type-equal?(a->left, b->left)) return false - (type-equal? *ecx *edx) # Tree-left, Tree-left => eax - 3d/compare-eax-and 0/imm32/false - 74/jump-if-= $type-equal?:end/disp8 - # return type-equal?(a->right, b->right) - (type-equal? *(ecx+4) *(edx+4)) # Tree-right, Tree-right => eax -$type-equal?:end: + eb/jump $subx-type-equal?:end/disp8 +$subx-type-equal?:true: + b8/copy-to-eax 1/imm32/true +$subx-type-equal?:end: # . restore registers - 5a/pop-to-edx 59/pop-to-ecx # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp c3/return +is-literal-type?: # a: (handle tree type-id) -> result/eax: boolean + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # + 8b/-> *(ebp+8) 0/r32/eax + 8b/-> *eax 0/r32/eax # Atom-value +$is-literal-type?:end: + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + test-emit-subx-statement-primitive: # Primitive operation on a variable on the stack. # increment foo -- cgit 1.4.1-2-gfad0 est_all?h=hlt&id=b3707a6f5002c9a82cfc5164aa86b8c4f7fe69f9'>b3707a6f ^
da388212 ^
b589f25a ^
1
2
3
4
5
6
7