diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:23:29 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:23:29 -0800 |
commit | 113bae7311b63e55e55160970718d19bfeeb56c3 (patch) | |
tree | d2468b58470e173329c7ef6e8da496c2f768b037 | |
parent | 1b050736eea04323e09e5e8e7499c33cee1899d0 (diff) | |
download | mu-113bae7311b63e55e55160970718d19bfeeb56c3.tar.gz |
5856
-rw-r--r-- | 011run.cc | 2 | ||||
-rw-r--r-- | Readme.md | 43 | ||||
-rw-r--r-- | apps/Readme.md | 13 | ||||
-rwxr-xr-x | apps/ex1 (renamed from examples/ex1) | bin | 197 -> 197 bytes | |||
-rw-r--r-- | apps/ex1.subx (renamed from examples/ex1.subx) | 0 | ||||
-rwxr-xr-x | apps/ex10 (renamed from examples/ex10) | bin | 264 -> 264 bytes | |||
-rw-r--r-- | apps/ex10.subx (renamed from examples/ex10.subx) | 0 | ||||
-rwxr-xr-x | apps/ex11 (renamed from examples/ex11) | bin | 1178 -> 1178 bytes | |||
-rw-r--r-- | apps/ex11.subx (renamed from examples/ex11.subx) | 0 | ||||
-rwxr-xr-x | apps/ex12 (renamed from examples/ex12) | bin | 234 -> 234 bytes | |||
-rw-r--r-- | apps/ex12.subx (renamed from examples/ex12.subx) | 0 | ||||
-rwxr-xr-x | apps/ex2 (renamed from examples/ex2) | bin | 198 -> 198 bytes | |||
-rw-r--r-- | apps/ex2.subx (renamed from examples/ex2.subx) | 0 | ||||
-rwxr-xr-x | apps/ex3 (renamed from examples/ex3) | bin | 215 -> 215 bytes | |||
-rw-r--r-- | apps/ex3.subx (renamed from examples/ex3.subx) | 0 | ||||
-rwxr-xr-x | apps/ex4 (renamed from examples/ex4) | bin | 236 -> 236 bytes | |||
-rw-r--r-- | apps/ex4.subx (renamed from examples/ex4.subx) | 0 | ||||
-rwxr-xr-x | apps/ex5 (renamed from examples/ex5) | bin | 238 -> 238 bytes | |||
-rw-r--r-- | apps/ex5.subx (renamed from examples/ex5.subx) | 0 | ||||
-rwxr-xr-x | apps/ex6 (renamed from examples/ex6) | bin | 232 -> 232 bytes | |||
-rw-r--r-- | apps/ex6.subx (renamed from examples/ex6.subx) | 0 | ||||
-rwxr-xr-x | apps/ex7 (renamed from examples/ex7) | bin | 366 -> 366 bytes | |||
-rw-r--r-- | apps/ex7.subx (renamed from examples/ex7.subx) | 0 | ||||
-rwxr-xr-x | apps/ex8 (renamed from examples/ex8) | bin | 234 -> 234 bytes | |||
-rw-r--r-- | apps/ex8.subx (renamed from examples/ex8.subx) | 0 | ||||
-rwxr-xr-x | apps/ex9 (renamed from examples/ex9) | bin | 228 -> 228 bytes | |||
-rw-r--r-- | apps/ex9.subx (renamed from examples/ex9.subx) | 0 | ||||
-rwxr-xr-x | edit | 9 | ||||
-rw-r--r-- | examples/Readme.md | 6 | ||||
-rw-r--r-- | html/apps/ex1.subx.html (renamed from html/examples/ex1.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex10.subx.html (renamed from html/examples/ex10.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex11.subx.html (renamed from html/examples/ex11.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex12.subx.html (renamed from html/examples/ex12.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex2.subx.html (renamed from html/examples/ex2.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex3.subx.html (renamed from html/examples/ex3.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex4.subx.html (renamed from html/examples/ex4.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex5.subx.html (renamed from html/examples/ex5.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex6.subx.html (renamed from html/examples/ex6.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex7.subx.html (renamed from html/examples/ex7.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex8.subx.html (renamed from html/examples/ex8.subx.html) | 0 | ||||
-rw-r--r-- | html/apps/ex9.subx.html (renamed from html/examples/ex9.subx.html) | 0 | ||||
-rwxr-xr-x | test_apps | 104 | ||||
-rw-r--r-- | vimrc.vim | 10 |
43 files changed, 89 insertions, 98 deletions
diff --git a/011run.cc b/011run.cc index 194676d8..585f9930 100644 --- a/011run.cc +++ b/011run.cc @@ -27,7 +27,7 @@ put_new(Help, "syntax", "after a '/', but they can never contain whitespace. Metadata has no effect\n" "at runtime, but can be handy when rewriting macros.\n" "\n" - "Check out the examples in the examples/ directory.\n" + "Check out the example programs in the apps/ directory, particularly apps/ex*.\n" ); :(before "End Help Contents") cerr << " syntax\n"; diff --git a/Readme.md b/Readme.md index 1d0329de..04bd4b5a 100644 --- a/Readme.md +++ b/Readme.md @@ -48,7 +48,7 @@ In priority order: You get a thin syntax called SubX for programming in (a subset of) x86 machine code. (A memory-safe compiled language is [being designed](http://akkartik.name/post/mu-2019-2).) -Here's a program (`examples/ex1.subx`) that returns 42: +Here's a program (`apps/ex1.subx`) that returns 42: ```sh bb/copy-to-ebx 0x2a/imm32 # 42 in hex @@ -59,8 +59,8 @@ Here's a program (`examples/ex1.subx`) that returns 42: You can generate tiny zero-dependency ELF binaries with it that run on Linux. ```sh - $ ./subx translate init.linux examples/ex1.subx -o examples/ex1 # on Linux or BSD or Mac - $ ./examples/ex1 # only on Linux + $ ./subx translate init.linux apps/ex1.subx -o apps/ex1 # on Linux or BSD or Mac + $ ./apps/ex1 # only on Linux $ echo $? 42 ``` @@ -72,7 +72,7 @@ You can run the generated binaries on an interpreter/VM for better error messages. ```sh - $ ./subx run examples/ex1 # on Linux or BSD or Mac + $ ./subx run apps/ex1 # on Linux or BSD or Mac $ echo $? 42 ``` @@ -80,11 +80,11 @@ messages. Emulated runs can generate a trace that permits [time-travel debugging](https://github.com/akkartik/mu/blob/master/tools/browse_trace.readme.md). ```sh - $ ./subx --debug translate init.linux examples/factorial.subx -o examples/factorial + $ ./subx --debug translate init.linux apps/factorial.subx -o apps/factorial saving address->label information to 'labels' saving address->source information to 'source_lines' - $ ./subx --debug --trace run examples/factorial + $ ./subx --debug --trace run apps/factorial saving trace to 'last_run' $ tools/browse_trace last_run # text-mode debugger UI @@ -111,14 +111,14 @@ You can use SubX to translate itself. For example, running natively on Linux: $ chmod +x hex survey pack assort dquotes tests # use the generated translator phases to translate SubX programs - $ cat init.linux examples/ex1.subx |./tests |./dquotes |./assort |./pack |./survey |./hex > a.elf + $ cat init.linux apps/ex1.subx |./tests |./dquotes |./assort |./pack |./survey |./hex > a.elf $ chmod +x a.elf $ ./a.elf $ echo $? 42 # or, automating the above steps - $ ./translate_subx init.linux examples/ex1.subx + $ ./translate_subx init.linux apps/ex1.subx $ ./a.elf $ echo $? 42 @@ -142,7 +142,7 @@ work on a cloud server.) $ sudo apt install util-linux nasm xorriso # maybe also dosfstools and mtools # package up a "hello world" program with a third-party kernel into mu_soso.iso # requires sudo - $ ./gen_soso_iso init.soso examples/ex6.subx + $ ./gen_soso_iso init.soso apps/ex6.subx # try it out $ qemu-system-i386 -cdrom mu_soso.iso ``` @@ -154,7 +154,7 @@ kernel; that number will gradually go down.) ```sh $ sudo apt install build-essential flex bison wget libelf-dev libssl-dev xorriso - $ ./gen_linux_iso init.linux examples/ex6.subx + $ ./gen_linux_iso init.linux apps/ex6.subx $ qemu-system-x86_64 -m 256M -cdrom mu.iso -boot d ``` @@ -299,7 +299,7 @@ and digest it: Here's a more meaty example: -<img alt='examples/ex3.subx' src='html/ex3.png'> +<img alt='apps/ex3.subx' src='html/ex3.png'> This program sums the first 10 natural numbers. By convention I use horizontal tabstops to help read instructions, dots to help follow the long lines, @@ -313,8 +313,8 @@ like decimal numbers. Try running this example now: ```sh -$ ./subx translate init.linux examples/ex3.subx -o examples/ex3 -$ ./subx run examples/ex3 +$ ./subx translate init.linux apps/ex3.subx -o apps/ex3 +$ ./subx run apps/ex3 $ echo $? 55 ``` @@ -322,7 +322,7 @@ $ echo $? If you're on Linux you can also run it natively: ```sh -$ ./examples/ex3 +$ ./apps/ex3 $ echo $? 55 ``` @@ -413,13 +413,14 @@ SubX will transparently copy it to the `data` segment and replace it with its address. Strings are the only place where a SubX word is allowed to contain spaces. -That should be enough information for writing SubX programs. The `examples/` -directory provides some fodder for practice, giving a more gradual introduction -to SubX features. This repo includes the binary for all examples. At any -commit, an example's binary should be identical bit for bit with the result of -translating the corresponding `.subx` file. The binary should also be natively -runnable on a Linux system running on Intel x86 processors, either 32- or -64-bit. If either of these invariants is broken it's a bug on my part. +That should be enough information for writing SubX programs. The `apps/` +directory provides some fodder for practice in the `apps/ex*` files, giving a +more gradual introduction to SubX features. This repo includes binaries for +all examples. At any commit, an example's binary should be identical bit for +bit with the result of translating the corresponding `.subx` file. The binary +should also be natively runnable on a Linux system running on Intel x86 +processors, either 32- or 64-bit. If either of these invariants is broken it's +a bug on my part. ## Running diff --git a/apps/Readme.md b/apps/Readme.md index 1861d949..1e1a5685 100644 --- a/apps/Readme.md +++ b/apps/Readme.md @@ -1,2 +1,11 @@ -Larger programs than in the examples/ subdirectory, combining the techniques -demonstrated there. +Some apps written in SubX and Mu, in 3 categories: + +* `ex*`: small stand-alone examples that don't need any of the shared code at + the top-level. They each have a simple pedagogical goal. Try these first. + +* Code unique to phases of our build toolchain: + * Core SubX: `hex`, `survey`, `pack`, `dquotes`, `assort`, `tests` + * Syntax sugar for SubX: `sigils`, `calls`, `braces` + * More ambitious translator for a memory-safe language (in progress): `mu` + +* Miscellaneous test programs. diff --git a/examples/ex1 b/apps/ex1 index 5f17bc66..5f17bc66 100755 --- a/examples/ex1 +++ b/apps/ex1 Binary files differdiff --git a/examples/ex1.subx b/apps/ex1.subx index 5558d310..5558d310 100644 --- a/examples/ex1.subx +++ b/apps/ex1.subx diff --git a/examples/ex10 b/apps/ex10 index cb8973fe..cb8973fe 100755 --- a/examples/ex10 +++ b/apps/ex10 Binary files differdiff --git a/examples/ex10.subx b/apps/ex10.subx index c091fe52..c091fe52 100644 --- a/examples/ex10.subx +++ b/apps/ex10.subx diff --git a/examples/ex11 b/apps/ex11 index 1cb1aa5c..1cb1aa5c 100755 --- a/examples/ex11 +++ b/apps/ex11 Binary files differdiff --git a/examples/ex11.subx b/apps/ex11.subx index b235927d..b235927d 100644 --- a/examples/ex11.subx +++ b/apps/ex11.subx diff --git a/examples/ex12 b/apps/ex12 index 80e5deeb..80e5deeb 100755 --- a/examples/ex12 +++ b/apps/ex12 Binary files differdiff --git a/examples/ex12.subx b/apps/ex12.subx index 9c67f909..9c67f909 100644 --- a/examples/ex12.subx +++ b/apps/ex12.subx diff --git a/examples/ex2 b/apps/ex2 index 5e0c1be1..5e0c1be1 100755 --- a/examples/ex2 +++ b/apps/ex2 Binary files differdiff --git a/examples/ex2.subx b/apps/ex2.subx index 8df4c62c..8df4c62c 100644 --- a/examples/ex2.subx +++ b/apps/ex2.subx diff --git a/examples/ex3 b/apps/ex3 index af787c11..af787c11 100755 --- a/examples/ex3 +++ b/apps/ex3 Binary files differdiff --git a/examples/ex3.subx b/apps/ex3.subx index f6f8c17d..f6f8c17d 100644 --- a/examples/ex3.subx +++ b/apps/ex3.subx diff --git a/examples/ex4 b/apps/ex4 index 35ade1ee..35ade1ee 100755 --- a/examples/ex4 +++ b/apps/ex4 Binary files differdiff --git a/examples/ex4.subx b/apps/ex4.subx index 78a97433..78a97433 100644 --- a/examples/ex4.subx +++ b/apps/ex4.subx diff --git a/examples/ex5 b/apps/ex5 index 805cadc3..805cadc3 100755 --- a/examples/ex5 +++ b/apps/ex5 Binary files differdiff --git a/examples/ex5.subx b/apps/ex5.subx index bacef8d4..bacef8d4 100644 --- a/examples/ex5.subx +++ b/apps/ex5.subx diff --git a/examples/ex6 b/apps/ex6 index 06fdfd7b..06fdfd7b 100755 --- a/examples/ex6 +++ b/apps/ex6 Binary files differdiff --git a/examples/ex6.subx b/apps/ex6.subx index 42612578..42612578 100644 --- a/examples/ex6.subx +++ b/apps/ex6.subx diff --git a/examples/ex7 b/apps/ex7 index 0a535d45..0a535d45 100755 --- a/examples/ex7 +++ b/apps/ex7 Binary files differdiff --git a/examples/ex7.subx b/apps/ex7.subx index 1c551cad..1c551cad 100644 --- a/examples/ex7.subx +++ b/apps/ex7.subx diff --git a/examples/ex8 b/apps/ex8 index 78f1773d..78f1773d 100755 --- a/examples/ex8 +++ b/apps/ex8 Binary files differdiff --git a/examples/ex8.subx b/apps/ex8.subx index 0e44a883..0e44a883 100644 --- a/examples/ex8.subx +++ b/apps/ex8.subx diff --git a/examples/ex9 b/apps/ex9 index 5140cf68..5140cf68 100755 --- a/examples/ex9 +++ b/apps/ex9 Binary files differdiff --git a/examples/ex9.subx b/apps/ex9.subx index 443e443e..443e443e 100644 --- a/examples/ex9.subx +++ b/apps/ex9.subx diff --git a/edit b/edit index dc434f58..400ab370 100755 --- a/edit +++ b/edit @@ -12,12 +12,7 @@ fi if [[ $EDITOR == *'vim'* ]] then - LOCAL_SETTINGS='-S vimrc.vim' -fi - -if [[ $1 == 'ex'* ]] -then - eval $EDITOR $LOCAL_SETTINGS examples/$1.subx + $EDITOR -S vimrc.vim apps/$1.subx else - eval $EDITOR $LOCAL_SETTINGS apps/$1.subx + $EDITOR apps/$1.subx fi diff --git a/examples/Readme.md b/examples/Readme.md deleted file mode 100644 index d4bb1ff5..00000000 --- a/examples/Readme.md +++ /dev/null @@ -1,6 +0,0 @@ -Small example programs, each with a simple pedagogical goal. - -They also help to validate SubX instruction semantics against native x86 -hardware. For example, loading a single byte to a register would for some time -clear the rest of the register. This behavior was internally consistent with -unit tests. It took running an example binary natively to catch the discrepancy. diff --git a/html/examples/ex1.subx.html b/html/apps/ex1.subx.html index c4105769..c4105769 100644 --- a/html/examples/ex1.subx.html +++ b/html/apps/ex1.subx.html diff --git a/html/examples/ex10.subx.html b/html/apps/ex10.subx.html index bcf0e466..bcf0e466 100644 --- a/html/examples/ex10.subx.html +++ b/html/apps/ex10.subx.html diff --git a/html/examples/ex11.subx.html b/html/apps/ex11.subx.html index 47c0b289..47c0b289 100644 --- a/html/examples/ex11.subx.html +++ b/html/apps/ex11.subx.html diff --git a/html/examples/ex12.subx.html b/html/apps/ex12.subx.html index a6b2dc64..a6b2dc64 100644 --- a/html/examples/ex12.subx.html +++ b/html/apps/ex12.subx.html diff --git a/html/examples/ex2.subx.html b/html/apps/ex2.subx.html index c67315e9..c67315e9 100644 --- a/html/examples/ex2.subx.html +++ b/html/apps/ex2.subx.html diff --git a/html/examples/ex3.subx.html b/html/apps/ex3.subx.html index 7c3da099..7c3da099 100644 --- a/html/examples/ex3.subx.html +++ b/html/apps/ex3.subx.html diff --git a/html/examples/ex4.subx.html b/html/apps/ex4.subx.html index 43f5c705..43f5c705 100644 --- a/html/examples/ex4.subx.html +++ b/html/apps/ex4.subx.html diff --git a/html/examples/ex5.subx.html b/html/apps/ex5.subx.html index f5112fa7..f5112fa7 100644 --- a/html/examples/ex5.subx.html +++ b/html/apps/ex5.subx.html diff --git a/html/examples/ex6.subx.html b/html/apps/ex6.subx.html index c8bbdd21..c8bbdd21 100644 --- a/html/examples/ex6.subx.html +++ b/html/apps/ex6.subx.html diff --git a/html/examples/ex7.subx.html b/html/apps/ex7.subx.html index 762bf7ec..762bf7ec 100644 --- a/html/examples/ex7.subx.html +++ b/html/apps/ex7.subx.html diff --git a/html/examples/ex8.subx.html b/html/apps/ex8.subx.html index 1f57fcdf..1f57fcdf 100644 --- a/html/examples/ex8.subx.html +++ b/html/apps/ex8.subx.html diff --git a/html/examples/ex9.subx.html b/html/apps/ex9.subx.html index fbf7b76c..fbf7b76c 100644 --- a/html/examples/ex9.subx.html +++ b/html/apps/ex9.subx.html diff --git a/test_apps b/test_apps index b9b22db1..eaf102e8 100755 --- a/test_apps +++ b/test_apps @@ -28,144 +28,144 @@ echo "== translating and running using C++" # example programs echo ex1 -./subx translate init.$OS examples/ex1.subx -o examples/ex1 -test "$1" = 'record' || git diff --exit-code examples/ex1 +./subx translate init.$OS apps/ex1.subx -o apps/ex1 +test "$1" = 'record' || git diff --exit-code apps/ex1 test $EMULATED && { - ./subx run examples/ex1 || ret=$? + ./subx run apps/ex1 || ret=$? test $ret -eq 42 # life, the universe and everything } test $NATIVE && { - examples/ex1 || ret=$? + apps/ex1 || ret=$? test $ret -eq 42 # life, the universe and everything } echo ex2 -./subx translate init.$OS examples/ex2.subx -o examples/ex2 -test "$1" = 'record' || git diff --exit-code examples/ex2 +./subx translate init.$OS apps/ex2.subx -o apps/ex2 +test "$1" = 'record' || git diff --exit-code apps/ex2 test $EMULATED && { - ./subx run examples/ex2 || ret=$? + ./subx run apps/ex2 || ret=$? test $ret -eq 2 # 1 + 1 } test $NATIVE && { - examples/ex2 || ret=$? + apps/ex2 || ret=$? test $ret -eq 2 # 1 + 1 } echo ex3 -./subx translate init.$OS examples/ex3.subx -o examples/ex3 -test "$1" = 'record' || git diff --exit-code examples/ex3 +./subx translate init.$OS apps/ex3.subx -o apps/ex3 +test "$1" = 'record' || git diff --exit-code apps/ex3 test $EMULATED && { - ./subx run examples/ex3 || ret=$? + ./subx run apps/ex3 || ret=$? test $ret -eq 55 # 1 + 2 + ... + 10 } test $NATIVE && { - examples/ex3 || ret=$? + apps/ex3 || ret=$? test $ret -eq 55 # 1 + 2 + ... + 10 } echo ex4 -./subx translate init.$OS examples/ex4.subx -o examples/ex4 -test "$1" = 'record' || git diff --exit-code examples/ex4 +./subx translate init.$OS apps/ex4.subx -o apps/ex4 +test "$1" = 'record' || git diff --exit-code apps/ex4 test $EMULATED && { - echo a | ./subx run examples/ex4 >ex4.out || true + echo a | ./subx run apps/ex4 >ex4.out || true test `cat ex4.out` = 'a' } test $NATIVE && { - echo a | examples/ex4 >ex4.out || true + echo a | apps/ex4 >ex4.out || true test `cat ex4.out` = 'a' } echo ex5 -./subx translate init.$OS examples/ex5.subx -o examples/ex5 -test "$1" = 'record' || git diff --exit-code examples/ex5 +./subx translate init.$OS apps/ex5.subx -o apps/ex5 +test "$1" = 'record' || git diff --exit-code apps/ex5 test $EMULATED && { - echo a | ./subx run examples/ex5 >ex5.out || true + echo a | ./subx run apps/ex5 >ex5.out || true test `cat ex5.out` = 'a' } test $NATIVE && { - echo a | examples/ex5 >ex5.out || true + echo a | apps/ex5 >ex5.out || true test `cat ex5.out` = 'a' } echo ex6 -./subx translate init.$OS examples/ex6.subx -o examples/ex6 -test "$1" = 'record' || git diff --exit-code examples/ex6 +./subx translate init.$OS apps/ex6.subx -o apps/ex6 +test "$1" = 'record' || git diff --exit-code apps/ex6 test $EMULATED && { - ./subx run examples/ex6 >ex6.out || true + ./subx run apps/ex6 >ex6.out || true test "`cat ex6.out`" = 'Hello, world!' } test $NATIVE && { - examples/ex6 >ex6.out || true + apps/ex6 >ex6.out || true test "`cat ex6.out`" = 'Hello, world!' } echo ex7 -./subx translate init.$OS examples/ex7.subx -o examples/ex7 -test "$1" = 'record' || git diff --exit-code examples/ex7 +./subx translate init.$OS apps/ex7.subx -o apps/ex7 +test "$1" = 'record' || git diff --exit-code apps/ex7 test $EMULATED && { - ./subx run examples/ex7 || ret=$? + ./subx run apps/ex7 || ret=$? test $ret -eq 97 # 'a' } test $NATIVE && { - examples/ex7 || ret=$? + apps/ex7 || ret=$? test $ret -eq 97 # 'a' } echo ex8 -./subx translate init.$OS examples/ex8.subx -o examples/ex8 -test "$1" = 'record' || git diff --exit-code examples/ex8 +./subx translate init.$OS apps/ex8.subx -o apps/ex8 +test "$1" = 'record' || git diff --exit-code apps/ex8 test $EMULATED && { - ./subx run examples/ex8 abcd || ret=$? + ./subx run apps/ex8 abcd || ret=$? test $ret -eq 4 # length('abcd') } test $NATIVE && { - examples/ex8 abcd || ret=$? + apps/ex8 abcd || ret=$? test $ret -eq 4 # length('abcd') } echo ex9 -./subx translate init.$OS examples/ex9.subx -o examples/ex9 -test "$1" = 'record' || git diff --exit-code examples/ex9 +./subx translate init.$OS apps/ex9.subx -o apps/ex9 +test "$1" = 'record' || git diff --exit-code apps/ex9 test $EMULATED && { - ./subx run examples/ex9 z x || ret=$? + ./subx run apps/ex9 z x || ret=$? test $ret -eq 2 # 'z' - 'x' } test $NATIVE && { - examples/ex9 z x || ret=$? + apps/ex9 z x || ret=$? test $ret -eq 2 # 'z' - 'x' } echo ex10 -./subx translate init.$OS examples/ex10.subx -o examples/ex10 -test "$1" = 'record' || git diff --exit-code examples/ex10 +./subx translate init.$OS apps/ex10.subx -o apps/ex10 +test "$1" = 'record' || git diff --exit-code apps/ex10 test $EMULATED && { - ./subx run examples/ex10 abc abc || ret=$? + ./subx run apps/ex10 abc abc || ret=$? test $ret -eq 1 # equal - ./subx run examples/ex10 abc abcd # 0; not equal + ./subx run apps/ex10 abc abcd # 0; not equal } test $NATIVE && { - examples/ex10 abc abc || ret=$? + apps/ex10 abc abc || ret=$? test $ret -eq 1 # equal - examples/ex10 abc abcd # 0; not equal + apps/ex10 abc abcd # 0; not equal } echo ex11 -./subx translate init.$OS examples/ex11.subx -o examples/ex11 -test "$1" = 'record' || git diff --exit-code examples/ex11 +./subx translate init.$OS apps/ex11.subx -o apps/ex11 +test "$1" = 'record' || git diff --exit-code apps/ex11 test $EMULATED && { - ./subx run examples/ex11 + ./subx run apps/ex11 echo } test $NATIVE && { - examples/ex11 + apps/ex11 echo } echo ex12 -./subx translate init.$OS examples/ex12.subx -o examples/ex12 -test "$1" = 'record' || git diff --exit-code examples/ex12 -test $EMULATED && ./subx run examples/ex12 # final byte of mmap'd address is well-nigh guaranteed to be 0 -test $NATIVE && examples/ex12 +./subx translate init.$OS apps/ex12.subx -o apps/ex12 +test "$1" = 'record' || git diff --exit-code apps/ex12 +test $EMULATED && ./subx run apps/ex12 # final byte of mmap'd address is well-nigh guaranteed to be 0 +test $NATIVE && apps/ex12 # Larger apps that use the standard library. @@ -304,8 +304,8 @@ echo "== translating using SubX (native only)" for n in `seq 1 12` do echo ex$n - ./translate_subx init.$OS examples/ex$n.subx - diff examples/ex$n a.elf + ./translate_subx init.$OS apps/ex$n.subx + diff apps/ex$n a.elf done # Larger apps that use the standard library. diff --git a/vimrc.vim b/vimrc.vim index 0200e01c..c01ab5c5 100644 --- a/vimrc.vim +++ b/vimrc.vim @@ -44,15 +44,7 @@ else endif function! EditSubx(cmd, arg) - exec "silent! " . a:cmd . " " . SubxPath(a:arg) -endfunction - -function! SubxPath(arg) - if a:arg =~ "^ex" - return "examples/" . a:arg . ".subx" - else - return "apps/" . a:arg . ".subx" - endif + exec "silent! " . a:cmd . " apps/" . a:arg . ".subx" endfunction " we often want to crib lines of machine code from other files |