free up '_' for top-level SubX functions

This commit is contained in:
Kartik K. Agaram 2021-05-14 22:36:38 -07:00
parent 56c9248109
commit 7bad89bdf9
2 changed files with 40 additions and 40 deletions

Binary file not shown.

View File

@ -11,10 +11,10 @@
# 74/jump-if-= loop/disp8 # 74/jump-if-= loop/disp8
# } # }
# $ cat x.subx |braces # $ cat x.subx |braces
# _loop1: # @loop1:
# 7c/jump-if-< _break1/disp8 # 7c/jump-if-< @break1/disp8
# 74/jump-if-= _loop1/disp8 # 74/jump-if-= @loop1/disp8
# _break1: # @break1:
# #
# Example 2: # Example 2:
# $ cat x.subx # $ cat x.subx
@ -25,12 +25,12 @@
# 74/jump-if-= loop/disp8 # 74/jump-if-= loop/disp8
# } # }
# $ cat x.subx |braces # $ cat x.subx |braces
# _loop1: # @loop1:
# 7c/jump-if-< _break1/disp8 # 7c/jump-if-< @break1/disp8
# _break1: # @break1:
# _loop2: # @loop2:
# 74/jump-if-= _loop2/disp8 # 74/jump-if-= @loop2/disp8
# _break2: # @break2:
# #
# Example 3: # Example 3:
# $ cat x.subx # $ cat x.subx
@ -41,12 +41,12 @@
# 7c/jump-if-< loop/disp8 # 7c/jump-if-< loop/disp8
# } # }
# $ cat x.subx |braces # $ cat x.subx |braces
# _loop1: # @loop1:
# _loop2: # @loop2:
# 74/jump-if-= _loop2/disp8 # 74/jump-if-= @loop2/disp8
# _break2: # @break2:
# 7c/jump-if-< _loop1/disp8 # 7c/jump-if-< @loop1/disp8
# _break1: # @break1:
== code == code
@ -85,13 +85,13 @@ subx-braces: # in: (addr buffered-file), out: (addr buffered-file)
# if (line->write == 0) break # end of file # if (line->write == 0) break # end of file
# skip-chars-matching-whitespace(line) # skip-chars-matching-whitespace(line)
# if line->data[line->read] == '{' # if line->data[line->read] == '{'
# print(out, "_loop" next-label-id ":\n") # print(out, "@loop" next-label-id ":\n")
# push(label-stack, next-label-id) # push(label-stack, next-label-id)
# ++next-label-id # ++next-label-id
# continue # continue
# if line->data[line->read] == '}' # if line->data[line->read] == '}'
# var top = pop(label-stack) # var top = pop(label-stack)
# print(out, "_break" top ":\n") # print(out, "@break" top ":\n")
# continue # continue
# while true # while true
# var word-slice: (addr slice) = next-word-or-string(line) # var word-slice: (addr slice) = next-word-or-string(line)
@ -101,11 +101,11 @@ subx-braces: # in: (addr buffered-file), out: (addr buffered-file)
# continue # continue
# if slice-starts-with?(word-slice, "break/") # if slice-starts-with?(word-slice, "break/")
# var top = top(label-stack) # var top = top(label-stack)
# print(out, "_break" top) # print(out, "@break" top)
# word-slice->start += len("break") # word-slice->start += len("break")
# else if slice-starts-with?(word-slice, "loop/") # else if slice-starts-with?(word-slice, "loop/")
# var top = top(label-stack) # var top = top(label-stack)
# print(out, "_loop" top) # print(out, "@loop" top)
# word-slice->start += len("loop") # word-slice->start += len("loop")
# print(out, word-slice " ") # print(out, word-slice " ")
# print(out, "\n") # print(out, "\n")
@ -157,8 +157,8 @@ $subx-braces:check-for-curly-open:
3d/compare-eax-and 0x7b/imm32/open-curly 3d/compare-eax-and 0x7b/imm32/open-curly
0f 85/jump-if-!= $subx-braces:check-for-curly-closed/disp32 0f 85/jump-if-!= $subx-braces:check-for-curly-closed/disp32
$subx-braces:emit-curly-open: $subx-braces:emit-curly-open:
# print(out, "_loop" next-label-id ":") # print(out, "@loop" next-label-id ":")
(write-buffered *(ebp+0xc) "_loop") (write-buffered *(ebp+0xc) "@loop")
(write-int32-hex-buffered *(ebp+0xc) %ebx) (write-int32-hex-buffered *(ebp+0xc) %ebx)
(write-buffered *(ebp+0xc) ":") (write-buffered *(ebp+0xc) ":")
# push(label-stack, next-label-id) # push(label-stack, next-label-id)
@ -174,8 +174,8 @@ $subx-braces:check-for-curly-closed:
$subx-braces:emit-curly-closed: $subx-braces:emit-curly-closed:
# eax = pop(label-stack) # eax = pop(label-stack)
(pop %edx) (pop %edx)
# print(out, "_break" eax ":") # print(out, "@break" eax ":")
(write-buffered *(ebp+0xc) "_break") (write-buffered *(ebp+0xc) "@break")
(write-int32-hex-buffered *(ebp+0xc) %eax) (write-int32-hex-buffered *(ebp+0xc) %eax)
(write-buffered *(ebp+0xc) ":") (write-buffered *(ebp+0xc) ":")
# continue # continue
@ -205,8 +205,8 @@ $subx-braces:check-for-break:
74/jump-if-= $subx-braces:check-for-loop/disp8 74/jump-if-= $subx-braces:check-for-loop/disp8
$subx-braces:emit-break: $subx-braces:emit-break:
(top %edx) (top %edx)
# print(out, "_break" eax) # print(out, "@break" eax)
(write-buffered *(ebp+0xc) "_break") (write-buffered *(ebp+0xc) "@break")
(write-int32-hex-buffered *(ebp+0xc) %eax) (write-int32-hex-buffered *(ebp+0xc) %eax)
# word-slice->start += len("break") # word-slice->start += len("break")
81 0/subop/add *edi 5/imm32/strlen 81 0/subop/add *edi 5/imm32/strlen
@ -221,8 +221,8 @@ $subx-braces:check-for-loop:
74/jump-if-= $subx-braces:emit-word-slice/disp8 74/jump-if-= $subx-braces:emit-word-slice/disp8
$subx-braces:emit-loop: $subx-braces:emit-loop:
(top %edx) (top %edx)
# print(out, "_loop" eax) # print(out, "@loop" eax)
(write-buffered *(ebp+0xc) "_loop") (write-buffered *(ebp+0xc) "@loop")
(write-int32-hex-buffered *(ebp+0xc) %eax) (write-int32-hex-buffered *(ebp+0xc) %eax)
# word-slice->start += len("loop") # word-slice->start += len("loop")
81 0/subop/add *edi 4/imm32/strlen 81 0/subop/add *edi 4/imm32/strlen
@ -288,10 +288,10 @@ test-subx-braces-1:
# } # }
# #
# output: # output:
# _loop1: # @loop1:
# ab _break1/imm32 # ab @break1/imm32
# cd _loop1/imm32 # cd @loop1/imm32
# _break1: # @break1:
# #
# . prologue # . prologue
55/push-ebp 55/push-ebp
@ -311,7 +311,7 @@ test-subx-braces-1:
#? (write-stream 2 _test-output-stream) #? (write-stream 2 _test-output-stream)
#? (write 2 "$\n") #? (write 2 "$\n")
#? # }}} #? # }}}
(check-stream-equal _test-output-stream "_loop0x00000001:\nab _break0x00000001/imm32 \ncd _loop0x00000001/imm32 \n_break0x00000001:\n" "F - test-subx-braces-1") (check-stream-equal _test-output-stream "@loop0x00000001:\nab @break0x00000001/imm32 \ncd @loop0x00000001/imm32 \n@break0x00000001:\n" "F - test-subx-braces-1")
# . epilogue # . epilogue
89/<- %esp 5/r32/ebp 89/<- %esp 5/r32/ebp
5d/pop-to-ebp 5d/pop-to-ebp
@ -327,12 +327,12 @@ test-subx-braces-2:
# } # }
# #
# output: # output:
# _loop1: # @loop1:
# _loop2: # @loop2:
# ab _break2/imm32 # ab @break2/imm32
# _break2: # @break2:
# cd _loop1/imm32 # cd @loop1/imm32
# _break1: # @break1:
# #
# . prologue # . prologue
55/push-ebp 55/push-ebp
@ -352,7 +352,7 @@ test-subx-braces-2:
#? (write-stream 2 _test-output-stream) #? (write-stream 2 _test-output-stream)
#? (write 2 "$\n") #? (write 2 "$\n")
#? # }}} #? # }}}
(check-stream-equal _test-output-stream "_loop0x00000001:\n_loop0x00000002:\nab _break0x00000002/imm32 \n_break0x00000002:\ncd _loop0x00000001/imm32 \n_break0x00000001:\n" "F - test-subx-braces-2") (check-stream-equal _test-output-stream "@loop0x00000001:\n@loop0x00000002:\nab @break0x00000002/imm32 \n@break0x00000002:\ncd @loop0x00000001/imm32 \n@break0x00000001:\n" "F - test-subx-braces-2")
# . epilogue # . epilogue
89/<- %esp 5/r32/ebp 89/<- %esp 5/r32/ebp
5d/pop-to-ebp 5d/pop-to-ebp