about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-02-21 15:19:34 -0800
committerKartik Agaram <vc@akkartik.com>2020-02-21 15:19:34 -0800
commit4fc03f219c3eae3407acf3f67ae707e29e3708dd (patch)
tree76bfb9ce717d3e179371c19a7de61ef5fa4ebe10
parent71478004a83e2b09ba22d3d5a8a94ec6d986e66a (diff)
downloadmu-4fc03f219c3eae3407acf3f67ae707e29e3708dd.tar.gz
6043
Test for 'index'.
-rwxr-xr-xapps/mubin152298 -> 154520 bytes
-rw-r--r--apps/mu.subx52
2 files changed, 52 insertions, 0 deletions
diff --git a/apps/mu b/apps/mu
index 86258bcd..170aa41d 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index bd3a4b96..6e1bea4e 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -1863,6 +1863,58 @@ test-convert-length-of-array:
     5d/pop-to-ebp
     c3/return
 
+test-convert-index-into-array:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # setup
+    (clear-stream _test-input-stream)
+    (clear-stream $_test-input-buffered-file->buffer)
+    (clear-stream _test-output-stream)
+    (clear-stream $_test-output-buffered-file->buffer)
+    c7 0/subop/copy *Next-block-index 1/imm32
+    #
+    (write _test-input-stream "fn foo {\n")
+    (write _test-input-stream "  var arr/eax: (addr array int) <- copy 0\n")
+    (write _test-input-stream "  var idx/ecx: int <- copy 3\n")
+    (write _test-input-stream "  var x/eax: (addr int) <- index arr, idx\n")
+    (write _test-input-stream "}\n")
+    # convert
+    (convert-mu _test-input-buffered-file _test-output-buffered-file)
+    (flush _test-output-buffered-file)
+#?     # dump _test-output-stream {{{
+#?     (write 2 "^")
+#?     (write-stream 2 _test-output-stream)
+#?     (write 2 "$\n")
+#?     (rewind-stream _test-output-stream)
+#?     # }}}
+    # check output
+    (check-next-stream-line-equal _test-output-stream "foo:"                                        "F - test-convert-length-of-array/0")
+    (check-next-stream-line-equal _test-output-stream "  # . prologue"                              "F - test-convert-length-of-array/1")
+    (check-next-stream-line-equal _test-output-stream "  55/push-ebp"                               "F - test-convert-length-of-array/2")
+    (check-next-stream-line-equal _test-output-stream "  89/<- %ebp 4/r32/esp"                      "F - test-convert-length-of-array/3")
+    (check-next-stream-line-equal _test-output-stream "  {"                                         "F - test-convert-length-of-array/4")
+    (check-next-stream-line-equal _test-output-stream "$foo:0x00000001:loop:"                       "F - test-convert-length-of-array/5")
+    (check-next-stream-line-equal _test-output-stream "    ff 6/subop/push %eax"                    "F - test-convert-length-of-array/6")
+    (check-next-stream-line-equal _test-output-stream "    b8/copy-to-eax 0/imm32"                  "F - test-convert-length-of-array/7")
+    (check-next-stream-line-equal _test-output-stream "    ff 6/subop/push %ecx"                    "F - test-convert-length-of-array/8")
+    (check-next-stream-line-equal _test-output-stream "    b9/copy-to-ecx 3/imm32"                  "F - test-convert-length-of-array/9")
+    (check-next-stream-line-equal _test-output-stream "    ff 6/subop/push %eax"                    "F - test-convert-length-of-array/10")
+    (check-next-stream-line-equal _test-output-stream "    8d/copy-address *(eax + ecx<<2 + 4) 0x00000000/r32"  "F - test-convert-length-of-array/11")
+    (check-next-stream-line-equal _test-output-stream "    8f 0/subop/pop %eax"                     "F - test-convert-length-of-array/12")
+    (check-next-stream-line-equal _test-output-stream "    8f 0/subop/pop %ecx"                     "F - test-convert-length-of-array/13")
+    (check-next-stream-line-equal _test-output-stream "    8f 0/subop/pop %eax"                     "F - test-convert-length-of-array/14")
+    (check-next-stream-line-equal _test-output-stream "  }"                                         "F - test-convert-length-of-array/15")
+    (check-next-stream-line-equal _test-output-stream "$foo:0x00000001:break:"                      "F - test-convert-length-of-array/16")
+    (check-next-stream-line-equal _test-output-stream "  # . epilogue"                              "F - test-convert-length-of-array/17")
+    (check-next-stream-line-equal _test-output-stream "  89/<- %esp 5/r32/ebp"                      "F - test-convert-length-of-array/18")
+    (check-next-stream-line-equal _test-output-stream "  5d/pop-to-ebp"                             "F - test-convert-length-of-array/19")
+    (check-next-stream-line-equal _test-output-stream "  c3/return"                                 "F - test-convert-length-of-array/20")
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 #######################################################
 # Parsing
 #######################################################