From 4caddd3bb30cbded8148fd9b8985211247fff28f Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 30 Jan 2020 01:16:59 -0800 Subject: 5962 - string literals --- apps/mu | Bin 102201 -> 102349 bytes apps/mu.subx | 49 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/apps/mu b/apps/mu index f5ace718..c4f8dbaf 100755 Binary files a/apps/mu and b/apps/mu differ diff --git a/apps/mu.subx b/apps/mu.subx index 537c80c3..c7c972ad 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -3591,20 +3591,27 @@ lookup-var-or-literal: # name: (addr slice), vars: (addr stack (handle var)) -> (slice-empty? %esi) # => eax 3d/compare-eax-and 0/imm32 0f 85/jump-if-!= $lookup-var-or-literal:abort/disp32 - # var ecx: byte = *name->start + # var c/ecx: byte = *name->start 8b/-> *esi 1/r32/ecx 8a/copy-byte *ecx 1/r32/CL 81 4/subop/and %ecx 0xff/imm32 - # if is-decimal-digit?(*name->start) return new var(name) - (is-decimal-digit? %ecx) # => eax - 81 7/subop/compare %eax 0/imm32 + # if is-decimal-digit?(c) return new var(name) { + (is-decimal-digit? %ecx) # => eax + 81 7/subop/compare %eax 0/imm32 74/jump-if-= break/disp8 (new-literal-integer Heap %esi) # => eax + eb/jump $lookup-var-or-literal:end/disp8 } - # otherwise return lookup-var(name, vars) + # else if (c == '"') return new var(name) { + 81 7/subop/compare %ecx 0x22/imm32/dquote 75/jump-if-!= break/disp8 + (new-literal-string Heap %esi) # => eax + eb/jump $lookup-var-or-literal:end/disp8 + } + # otherwise return lookup-var(name, vars) + { (lookup-var %esi *(ebp+0xc)) # => eax } $lookup-var-or-literal:end: @@ -3928,14 +3935,16 @@ new-literal-integer: # ad: (addr allocation-descriptor), name: (addr slice) -> # var s/ecx: (addr array byte) (slice-to-string Heap *(ebp+0xc)) # => eax 89/<- %ecx 0/r32/eax - # + # result/ecx = new var(s) (allocate *(ebp+8) *Var-size) # => eax (zero-out %eax *Var-size) 89/<- *eax 1/r32/ecx # Var-name 89/<- %ecx 0/r32/eax + # result->type = new type() (allocate *(ebp+8) *Tree-size) # => eax (zero-out %eax *Tree-size) # default type is 'literal' 89/<- *(ecx+4) 0/r32/eax # Var-type + # move result to eax 89/<- %eax 1/r32/ecx $new-literal-integer:end: # . restore registers @@ -3956,6 +3965,34 @@ $new-literal-integer:abort: cd/syscall 0x80/imm8 # never gets here +new-literal-string: # ad: (addr allocation-descriptor), name: (addr slice) -> result/eax: (handle var) + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # . save registers + 51/push-ecx + # var s/ecx: (addr array byte) + (slice-to-string Heap *(ebp+0xc)) # => eax + 89/<- %ecx 0/r32/eax + # result/ecx = new var(s) + (allocate *(ebp+8) *Var-size) # => eax + (zero-out %eax) + 89/<- *eax 1/r32/ecx # Var-name + 89/<- %ecx 0/r32/eax + # result->type = new type() + (allocate *(ebp+8) *Tree-size) # => eax + (zero-out %eax) # default type is 'literal' + 89/<- *(ecx+4) 0/r32/eax # Var-type + # move result to eax + 89/<- %eax 1/r32/ecx +$new-literal-string:end: + # . restore registers + 59/pop-to-ecx + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + new-label: # ad: (addr allocation-descriptor), name: (addr slice) -> result/eax: (handle var) # . prologue 55/push-ebp -- cgit 1.4.1-2-gfad0