This commit is contained in:
parent
ac45f09715
commit
44d26b77c4
|
@ -12,7 +12,7 @@ Here's the Mu computer running [Conway's Game of Life](https://en.wikipedia.org/
|
|||
```sh
|
||||
git clone https://github.com/akkartik/mu
|
||||
cd mu
|
||||
./translate life.mu # emit a bootable code.img
|
||||
./translate apps/life.mu # emit a bootable code.img
|
||||
qemu-system-i386 code.img
|
||||
```
|
||||
|
||||
|
@ -94,7 +94,7 @@ Mu programs build natively either on Linux or on Windows using [WSL 2](https://d
|
|||
For Macs and other Unix-like systems, use the (much slower) emulator:
|
||||
|
||||
```sh
|
||||
./translate_emulated ex2.mu # ~2 mins to emit code.img
|
||||
./translate_emulated apps/ex2.mu # ~2 mins to emit code.img
|
||||
```
|
||||
|
||||
Mu programs can be written for two very different environments:
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# To convert to a disk image, first prepare a realistically sized disk image:
|
||||
# dd if=/dev/zero of=code.img count=20160 # 512-byte sectors, so 10MB
|
||||
# Now fill in sectors:
|
||||
# bootstrap/bootstrap run hex < boot0.hex > boot.bin
|
||||
# linux/bootstrap/bootstrap run linux/hex < apps/boot0.hex > boot.bin
|
||||
# dd if=boot.bin of=code.img conv=notrunc
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
|
@ -2,7 +2,7 @@
|
|||
# If we did this rigorously we'd need to implement cosines. So we won't.
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate colors.mu
|
||||
# $ ./translate apps/colors.mu
|
||||
#
|
||||
# Example session:
|
||||
# $ qemu-system-i386 code.img
|
|
@ -0,0 +1,14 @@
|
|||
# The simplest possible bare-metal program.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate apps/ex1.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output: blank screen with no errors
|
||||
|
||||
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
||||
loop
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
# Demo of mouse support.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex10.mu # emits code.img
|
||||
# ./translate apps/ex10.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -0,0 +1,176 @@
|
|||
# Demo of mouse support.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex10.mu # emits disk.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
|
||||
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
||||
#? var x/esi: int <- copy 0x200
|
||||
#? var y/edi: int <- copy 0x180
|
||||
#? render-grid x, y
|
||||
$main:event-loop: {
|
||||
# read deltas from mouse
|
||||
var dx/eax: int <- copy 0
|
||||
var dy/ecx: int <- copy 0
|
||||
dx, dy <- read-mouse-event
|
||||
# loop if deltas are both 0
|
||||
{
|
||||
compare dx, 0
|
||||
break-if-!=
|
||||
compare dy, 0
|
||||
break-if-!=
|
||||
loop $main:event-loop
|
||||
}
|
||||
# render unclamped deltas
|
||||
#? render-grid x, y
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, dx, 7/fg, 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, dy, 7/fg, 0/bg
|
||||
move-cursor-to-left-margin-of-next-line screen
|
||||
#? {
|
||||
#? var dummy1/eax: int <- copy 0
|
||||
#? var dummy2/ecx: int <- copy 0
|
||||
#? dummy1, dummy2 <- draw-text-wrapping-right-then-down-over-full-screen screen, " ", 0/x, 0x10/y, 0x31/fg, 0/bg
|
||||
#? }
|
||||
#? {
|
||||
#? var ephemeral-dx/eax: int <- copy dx
|
||||
#? var dummy/ecx: int <- copy 0
|
||||
#? ephemeral-dx, dummy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, ephemeral-dx, 0/x, 0x10/y, 0x31/fg, 0/bg
|
||||
#? }
|
||||
#? {
|
||||
#? var dummy/eax: int <- copy 0
|
||||
#? var ephemeral-dy/ecx: int <- copy dy
|
||||
#? dummy, ephemeral-dy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, ephemeral-dy, 5/x, 0x10/y, 0x31/fg, 0/bg
|
||||
#? }
|
||||
#? # clamp deltas
|
||||
#? $clamp-dx: {
|
||||
#? compare dx, -0xa
|
||||
#? {
|
||||
#? break-if->
|
||||
#? dx <- copy -0xa
|
||||
#? break $clamp-dx
|
||||
#? }
|
||||
#? compare dx, 0xa
|
||||
#? {
|
||||
#? break-if-<
|
||||
#? dx <- copy 0xa
|
||||
#? break $clamp-dx
|
||||
#? }
|
||||
#? dx <- copy 0
|
||||
#? }
|
||||
#? $clamp-dy: {
|
||||
#? compare dy, -0xa
|
||||
#? {
|
||||
#? break-if->
|
||||
#? dy <- copy -0xa
|
||||
#? break $clamp-dy
|
||||
#? }
|
||||
#? compare dy, 0xa
|
||||
#? {
|
||||
#? break-if-<
|
||||
#? dy <- copy 0xa
|
||||
#? break $clamp-dy
|
||||
#? }
|
||||
#? dy <- copy 0
|
||||
#? }
|
||||
#? # render clamped deltas
|
||||
#? {
|
||||
#? var dummy1/eax: int <- copy 0
|
||||
#? var dummy2/ecx: int <- copy 0
|
||||
#? dummy1, dummy2 <- draw-text-wrapping-right-then-down-over-full-screen screen, " ", 0/x, 0x20/y, 0x31/fg, 0/bg
|
||||
#? }
|
||||
#? {
|
||||
#? var save-dx/eax: int <- copy dx
|
||||
#? var dummy/ecx: int <- copy 0
|
||||
#? save-dx, dummy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, save-dx, 0/x, 0x20/y, 0x31/fg, 0/bg
|
||||
#? }
|
||||
#? {
|
||||
#? var dummy/eax: int <- copy 0
|
||||
#? var save-dy/ecx: int <- copy dy
|
||||
#? dummy, save-dy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, save-dy, 5/x, 0x20/y, 0x31/fg, 0/bg
|
||||
#? }
|
||||
#? # loop if deltas are both 0
|
||||
#? {
|
||||
#? compare dx, 0
|
||||
#? break-if-!=
|
||||
#? compare dy, 0
|
||||
#? break-if-!=
|
||||
#? loop $main:event-loop
|
||||
#? }
|
||||
#? # accumulate deltas and clamp result within screen bounds
|
||||
#? x <- add dx
|
||||
#? compare x, 0
|
||||
#? {
|
||||
#? break-if->=
|
||||
#? x <- copy 0
|
||||
#? }
|
||||
#? compare x, 0x400
|
||||
#? {
|
||||
#? break-if-<
|
||||
#? x <- copy 0x3ff
|
||||
#? }
|
||||
#? y <- subtract dy # mouse y coordinates are reverse compared to screen
|
||||
#? compare y, 0
|
||||
#? {
|
||||
#? break-if->=
|
||||
#? y <- copy 0
|
||||
#? }
|
||||
#? compare y, 0x300
|
||||
#? {
|
||||
#? break-if-<
|
||||
#? y <- copy 0x2ff
|
||||
#? }
|
||||
loop
|
||||
}
|
||||
}
|
||||
|
||||
#? fn render-grid curr-x: int, curr-y: int {
|
||||
#? and-with curr-x, 0xfffffffc
|
||||
#? and-with curr-y, 0xfffffffc
|
||||
#? var y/eax: int <- copy 0
|
||||
#? {
|
||||
#? compare y, 0x300/screen-height=768
|
||||
#? break-if->=
|
||||
#? var x/edx: int <- copy 0
|
||||
#? {
|
||||
#? compare x, 0x400/screen-width=1024
|
||||
#? break-if->=
|
||||
#? var color/ecx: int <- copy 0
|
||||
#? # set color if either x or y is divisible by 4
|
||||
#? var tmp/ebx: int <- copy y
|
||||
#? tmp <- and 3
|
||||
#? compare tmp, 0
|
||||
#? {
|
||||
#? break-if-!=
|
||||
#? color <- copy 3
|
||||
#? }
|
||||
#? tmp <- copy x
|
||||
#? tmp <- and 3
|
||||
#? compare tmp, 0
|
||||
#? {
|
||||
#? break-if-!=
|
||||
#? color <- copy 3
|
||||
#? }
|
||||
#? # highlight color if x and y match curr-x and curr-y (quantized)
|
||||
#? {
|
||||
#? var xq/edx: int <- copy x
|
||||
#? xq <- and 0xfffffffc
|
||||
#? var yq/eax: int <- copy y
|
||||
#? yq <- and 0xfffffffc
|
||||
#? compare xq, curr-x
|
||||
#? break-if-!=
|
||||
#? compare yq, curr-y
|
||||
#? break-if-!=
|
||||
#? color <- copy 0xc
|
||||
#? }
|
||||
#? pixel-on-real-screen x, y, color
|
||||
#? x <- increment
|
||||
#? loop
|
||||
#? }
|
||||
#? y <- increment
|
||||
#? loop
|
||||
#? }
|
||||
#? }
|
|
@ -1,7 +1,7 @@
|
|||
# Demo of an interactive app: controlling a Bezier curve on screen
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex11.mu # emits code.img
|
||||
# ./translate apps/ex11.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -1,7 +1,7 @@
|
|||
# Checking the timer.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex12.mu # emits code.img
|
||||
# ./translate apps/ex12.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -1,7 +1,7 @@
|
|||
# Test out the video mode by filling in the screen with pixels.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex2.mu # emits code.img
|
||||
# ./translate apps/ex2.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -2,7 +2,7 @@
|
|||
# and in raster order.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex3.mu # emits code.img
|
||||
# ./translate apps/ex3.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -1,7 +1,7 @@
|
|||
# Draw a character using the built-in font (GNU unifont)
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex4.mu # emits code.img
|
||||
# ./translate apps/ex4.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -2,7 +2,7 @@
|
|||
# Also demonstrates bounds-checking _before_ drawing.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex5.mu # emits code.img
|
||||
# ./translate apps/ex5.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -1,7 +1,7 @@
|
|||
# Drawing ASCII text incrementally.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex6.mu # emits code.img
|
||||
# ./translate apps/ex6.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -1,7 +1,7 @@
|
|||
# Cursor-based motions.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex7.mu # emits code.img
|
||||
# ./translate apps/ex7.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
|
@ -1,7 +1,7 @@
|
|||
# Demo of floating-point support.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex8.mu # emits code.img
|
||||
# ./translate apps/ex8.mu # emits code.img
|
||||
# To run:
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
# Set a breakpoint at 0x7c00 and start stepping.
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# Steps for trying it out:
|
||||
# 1. Translate this example into a disk image code.img.
|
||||
# ./translate ex9.mu
|
||||
# ./translate apps/ex9.mu
|
||||
# 2. Build a second disk image data.img containing some text.
|
||||
# dd if=/dev/zero of=data.img count=20160
|
||||
# echo 'abc def ghi' |dd of=data.img conv=notrunc
|
|
@ -3,14 +3,14 @@
|
|||
# https://ivanish.ca/hest-podcast
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate hest-life.mu
|
||||
# $ ./translate apps/hest-life.mu
|
||||
# I run it on my 2.5GHz Linux laptop like this:
|
||||
# $ qemu-system-i386 -enable-kvm code.img
|
||||
# $ qemu-system-i386 code.img
|
||||
#
|
||||
# If things seem too fast or too slow on your computer, adjust the loop bounds
|
||||
# in the function `linger` at the bottom. Its value will depend on how you
|
||||
# accelerate Qemu. Mu will eventually get a clock to obviate the need for this
|
||||
# tuning.
|
||||
# accelerate Qemu (`-accel help`). Mu will eventually get a clock to obviate
|
||||
# the need for this tuning.
|
||||
#
|
||||
# Keyboard shortcuts:
|
||||
# space: pause/resume
|
|
@ -1,7 +1,7 @@
|
|||
# load an image from disk and display it on screen
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate img.mu # generates code.img
|
||||
# $ ./translate apps/img.mu # generates code.img
|
||||
# Load a pbm, pgm or ppm image (no more than 255 levels) in the data disk
|
||||
# $ dd if=/dev/zero of=data.img count=20160
|
||||
# $ dd if=x.pbm of=data.img conv=notrunc
|
|
@ -1,7 +1,7 @@
|
|||
# Conway's Game of Life
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate life.mu
|
||||
# $ ./translate apps/life.mu
|
||||
# To run:
|
||||
# $ qemu-system-i386 code.img
|
||||
|
|
@ -4,9 +4,9 @@
|
|||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# Build on Linux:
|
||||
# $ ./translate mandelbrot-fixed.mu
|
||||
# $ ./translate apps/mandelbrot-fixed.mu
|
||||
# Build on other platforms (slow):
|
||||
# $ ./translate_emulated mandelbrot-fixed.mu
|
||||
# $ ./translate_emulated apps/mandelbrot-fixed.mu
|
||||
# Run:
|
||||
# $ qemu-system-i386 code.img
|
||||
|
|
@ -4,9 +4,9 @@
|
|||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# Build on Linux:
|
||||
# $ ./translate mandelbrot.mu
|
||||
# $ ./translate apps/mandelbrot.mu
|
||||
# Build on other platforms (slow):
|
||||
# $ ./translate_emulated mandelbrot.mu
|
||||
# $ ./translate_emulated apps/mandelbrot.mu
|
||||
# Run:
|
||||
# $ qemu-system-i386 code.img
|
||||
|
|
@ -4,9 +4,9 @@
|
|||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# Build on Linux:
|
||||
# $ ./translate mandelbrot.mu
|
||||
# $ ./translate apps/mandelbrot.mu
|
||||
# Build on other platforms (slow):
|
||||
# $ ./translate_emulated mandelbrot.mu
|
||||
# $ ./translate_emulated apps/mandelbrot.mu
|
||||
# Run:
|
||||
# $ qemu-system-i386 code.img
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
# Division not implemented yet.
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate rpn.mu
|
||||
# $ ./translate apps/rpn.mu
|
||||
#
|
||||
# Example session:
|
||||
# $ qemu-system-i386 code.img
|
3
ex1.mu
3
ex1.mu
|
@ -1,3 +0,0 @@
|
|||
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
||||
loop
|
||||
}
|
|
@ -3,7 +3,7 @@ kernel. To run programs under this directory, you must first `cd` into it.
|
|||
|
||||
```sh
|
||||
$ cd linux/
|
||||
$ ./translate hello.mu # generates a.elf
|
||||
$ ./translate apps/hello.mu # generates a.elf
|
||||
$ ./a.elf
|
||||
Hello world!
|
||||
```
|
||||
|
@ -22,11 +22,11 @@ Some programs to try out:
|
|||
|
||||
* `browse`: [A text-mode browser for a tiny subset of Markdown](https://mastodon.social/@akkartik/104845344081779025).
|
||||
|
||||
* `ex*`: small stand-alone examples that don't need any of the shared code at
|
||||
* `apps/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. Read these first.
|
||||
|
||||
* `factorial*`: A simple program to compute factorials in 5 versions, showing
|
||||
all the different syntax sugars and what they expand to.
|
||||
* `apps/factorial*`: A simple program to compute factorials in 5 versions,
|
||||
showing all the different syntax sugars and what they expand to.
|
||||
|
||||
The Mu compiler toolchain is also here in the following phases:
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# To build on Linux:
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu/linux
|
||||
# $ ./translate advent2017/1a.mu # emits a.elf
|
||||
# $ ./translate apps/advent2017/1a.mu # emits a.elf
|
||||
# To run on Linux:
|
||||
# Download https://adventofcode.com/2017/day/1/input
|
||||
# $ ./a.elf < input
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/1a.mu
|
||||
# $ ./translate apps/advent2020/1a.mu
|
||||
# $ ./a.elf < input
|
||||
# found
|
||||
# 1353 667
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/1b.mu
|
||||
# $ ./translate apps/advent2020/1b.mu
|
||||
# $ ./a.elf < input
|
||||
# found
|
||||
# 143 407 1470
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/2a.mu
|
||||
# $ ./translate apps/advent2020/2a.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/2b.mu
|
||||
# $ ./translate apps/advent2020/2b.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/3a.mu
|
||||
# $ ./translate apps/advent2020/3a.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/3a.mu
|
||||
# $ ./translate apps/advent2020/3a.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/4a.mu
|
||||
# $ ./translate apps/advent2020/4a.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/4b.mu
|
||||
# $ ./translate apps/advent2020/4b.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/5a.mu
|
||||
# $ ./translate apps/advent2020/5a.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate advent2020/5b.mu
|
||||
# $ ./translate apps/advent2020/5b.mu
|
||||
# $ ./a.elf < input
|
||||
#
|
||||
# You'll need to register to download the 'input' file for yourself.
|
|
@ -7,7 +7,7 @@
|
|||
# No division yet.
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate arith.mu
|
||||
# $ ./translate apps/arith.mu
|
||||
#
|
||||
# Example session:
|
||||
# $ ./a.elf
|
|
@ -3,7 +3,7 @@
|
|||
# except that we support hex digits.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate [01]*.subx crenshaw2-1.subx -o crenshaw2-1
|
||||
# $ bootstrap/bootstrap translate [01]*.subx apps/crenshaw2-1.subx -o crenshaw2-1
|
||||
# $ echo '3' |bootstrap/bootstrap run crenshaw2-1
|
||||
# Expected output:
|
||||
# # syscall(exit, 3)
|
|
@ -3,7 +3,7 @@
|
|||
# except that we support hex numbers of multiple digits.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate [01]*.subx crenshaw2-1b.subx -o crenshaw2-1b
|
||||
# $ bootstrap/bootstrap translate [01]*.subx apps/crenshaw2-1b.subx -o crenshaw2-1b
|
||||
# $ echo '1a' |bootstrap/bootstrap run crenshaw2-1b
|
||||
# Expected output:
|
||||
# # syscall(exit, 1a)
|
|
@ -1,8 +1,10 @@
|
|||
# First example: return the answer to the Ultimate Question of Life, the
|
||||
# Universe, and Everything.
|
||||
#
|
||||
# Same as https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate ex1.mu
|
||||
# $ ./translate apps/ex1.mu
|
||||
# $ ./a.elf
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -0,0 +1,20 @@
|
|||
# First example: return the answer to the Ultimate Question of Life, the
|
||||
# Universe, and Everything.
|
||||
#
|
||||
# Same as https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate apps/ex1.subx -o ex1
|
||||
# $ bootstrap/bootstrap run ex1
|
||||
# Expected result:
|
||||
# $ echo $?
|
||||
# 42
|
||||
|
||||
== code
|
||||
|
||||
Entry:
|
||||
# exit(42)
|
||||
bb/copy-to-ebx 0x2a/imm32 # 42 in hex
|
||||
e8/call syscall_exit/disp32
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
|
@ -1,7 +1,7 @@
|
|||
# String comparison: return 1 iff the two args passed in at the commandline are equal.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex10.subx -o ex10
|
||||
# $ bootstrap/bootstrap translate apps/ex10.subx -o ex10
|
||||
# $ bootstrap/bootstrap run ex10 abc abd
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -6,7 +6,7 @@
|
|||
# a null-terminated 'kernel string' with a size-prefixed 'SubX string'.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex11.subx -o ex11
|
||||
# $ bootstrap/bootstrap translate apps/ex11.subx -o ex11
|
||||
# $ bootstrap/bootstrap run ex11 # runs a series of tests
|
||||
# ...... # all tests pass
|
||||
#
|
|
@ -2,7 +2,7 @@
|
|||
# Create a new segment using mmap, save the address, write to it.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex12.subx -o ex12
|
||||
# $ bootstrap/bootstrap translate apps/ex12.subx -o ex12
|
||||
# $ bootstrap/bootstrap run ex12
|
||||
# You shouldn't get a segmentation fault.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# Compare 3 and 3.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex13.subx -o ex13
|
||||
# $ bootstrap/bootstrap translate apps/ex13.subx -o ex13
|
||||
# $ bootstrap/bootstrap run ex13
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Multiply 2 numbers.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex14.subx -o ex14
|
||||
# $ bootstrap/bootstrap translate apps/ex14.subx -o ex14
|
||||
# $ bootstrap/bootstrap run ex14
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Add 3 and 4, and return the result in the exit code.
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate ex2.mu
|
||||
# $ ./translate apps/ex2.mu
|
||||
# $ ./a.elf
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Add 3 and 4, and return the result in the exit code.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex2.subx -o ex2
|
||||
# $ bootstrap/bootstrap translate apps/ex2.subx -o ex2
|
||||
# $ bootstrap/bootstrap run ex2
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Unnecessarily use an array to sum 1..10
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate ex3.2.mu
|
||||
# $ ./translate apps/ex3.2.mu
|
||||
# $ ./a.elf
|
||||
# $ echo $?
|
||||
# 55
|
|
@ -1,7 +1,7 @@
|
|||
# Add the first 10 numbers, and return the result in the exit code.
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate browse.mu
|
||||
# $ ./translate ex3.mu
|
||||
# $ ./a.elf
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Add the first 10 numbers, and return the result in the exit code.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex3.subx -o ex3
|
||||
# $ bootstrap/bootstrap translate apps/ex3.subx -o ex3
|
||||
# $ bootstrap/bootstrap run ex3
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Read a character from stdin, save it to a global, write it to stdout.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex4.subx -o ex4
|
||||
# $ bootstrap/bootstrap translate apps/ex4.subx -o ex4
|
||||
# $ bootstrap/bootstrap run ex4
|
||||
|
||||
== data
|
|
@ -1,7 +1,7 @@
|
|||
# Read a character from stdin, save it to a local on the stack, write it to stdout.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex5.subx -o ex5
|
||||
# $ bootstrap/bootstrap translate apps/ex5.subx -o ex5
|
||||
# $ bootstrap/bootstrap run ex5
|
||||
|
||||
== code
|
|
@ -1,7 +1,7 @@
|
|||
# Print out a (global variable) string to stdout.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex6.subx -o ex6
|
||||
# $ bootstrap/bootstrap translate apps/ex6.subx -o ex6
|
||||
# $ bootstrap/bootstrap run ex6
|
||||
# Hello, world!
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
# the character read.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex7.subx -o ex7
|
||||
# $ bootstrap/bootstrap translate apps/ex7.subx -o ex7
|
||||
# $ bootstrap/bootstrap run ex7
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Example reading commandline arguments: compute length of first arg.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex8.subx -o ex8
|
||||
# $ bootstrap/bootstrap translate apps/ex8.subx -o ex8
|
||||
# $ bootstrap/bootstrap run ex8 abc de fghi
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -4,7 +4,7 @@
|
|||
# letter of second arg.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex9.subx -o ex9
|
||||
# $ bootstrap/bootstrap translate apps/ex9.subx -o ex9
|
||||
# $ bootstrap/bootstrap run ex9 z x
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# compute the factorial of 5, and return the result in the exit code
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate factorial.mu
|
||||
# $ ./translate apps/factorial.mu
|
||||
# $ ./a.elf
|
||||
# $ echo $?
|
||||
# 120
|
|
@ -1,7 +1,7 @@
|
|||
## compute the factorial of 5, and print the result
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate [01]*.subx factorial.subx -o factorial
|
||||
# $ bootstrap/bootstrap translate [01]*.subx apps/factorial.subx -o factorial
|
||||
# $ bootstrap/bootstrap run factorial
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -4,7 +4,7 @@
|
|||
# rm32 operands
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate_subx init.linux [01]*.subx factorial.subx -o factorial
|
||||
# $ ./translate_subx init.linux [01]*.subx apps/factorial2.subx -o factorial
|
||||
# $ bootstrap/bootstrap run factorial
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -5,7 +5,7 @@
|
|||
# function calls
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate_subx init.linux [01]*.subx factorial.subx -o factorial
|
||||
# $ ./translate_subx init.linux [01]*.subx apps/factorial3.subx -o factorial
|
||||
# $ bootstrap/bootstrap run factorial
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -6,7 +6,7 @@
|
|||
# control flow
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate_subx init.linux [01]*.subx factorial.subx -o factorial
|
||||
# $ ./translate_subx init.linux [01]*.subx apps/factorial4.subx -o factorial
|
||||
# $ bootstrap/bootstrap run factorial
|
||||
# Expected result:
|
||||
# $ echo $?
|
|
@ -1,7 +1,7 @@
|
|||
# Meaningless conventional example.
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate hello.mu
|
||||
# $ ./translate apps/hello.mu
|
||||
# $ ./a.elf
|
||||
|
||||
fn main -> _/ebx: int {
|
|
@ -1,7 +1,7 @@
|
|||
# parse a decimal int at the commandline
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate parse-int.mu
|
||||
# $ ./translate apps/parse-int.mu
|
||||
# $ ./a.elf 123
|
||||
# $ echo $?
|
||||
# 123
|
|
@ -2,7 +2,7 @@
|
|||
# only ascii right now, just like the rest of Mu
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate print-file.mu
|
||||
# $ ./translate apps/print-file.mu
|
||||
# $ echo abc > x
|
||||
# $ ./a.elf x
|
||||
# abc
|
|
@ -3,8 +3,8 @@
|
|||
#
|
||||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate raytracing/1.mu
|
||||
# $ cd mu/linux
|
||||
# $ ./translate apps/raytracing/1.mu
|
||||
# $ ./a.elf > 1.ppm
|
||||
|
||||
fn main -> _/ebx: int {
|
|
@ -2,8 +2,8 @@
|
|||
#
|
||||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate raytracing/2.mu
|
||||
# $ cd mu/linux
|
||||
# $ ./translate apps/raytracing/2.mu
|
||||
# $ ./a.elf > 2.ppm
|
||||
|
||||
fn main -> _/ebx: int {
|
|
@ -2,8 +2,8 @@
|
|||
#
|
||||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate raytracing/3.mu
|
||||
# $ cd mu/linux
|
||||
# $ ./translate apps/raytracing/3.mu
|
||||
# $ ./a.elf > 3.ppm
|
||||
|
||||
fn ray-color _in: (addr ray), _out: (addr rgb) {
|
|
@ -4,7 +4,7 @@
|
|||
# No division yet.
|
||||
#
|
||||
# To build:
|
||||
# $ ./translate rpn.mu
|
||||
# $ ./translate apps/rpn.mu
|
||||
#
|
||||
# Example session:
|
||||
# $ ./a.elf
|
|
@ -3,7 +3,7 @@
|
|||
# To run (on Linux):
|
||||
# $ git clone https://github.com/akkartik/mu
|
||||
# $ cd mu
|
||||
# $ ./translate texture.mu
|
||||
# $ ./translate apps/texture.mu
|
||||
# $ ./a.elf > a.ppm
|
||||
|
||||
fn main -> _/ebx: int {
|
|
@ -1,7 +1,7 @@
|
|||
# Test some primitives for text-mode.
|
||||
#
|
||||
# To run:
|
||||
# $ ./translate tui.mu
|
||||
# $ ./translate apps/tui.mu
|
||||
# $ ./a.elf
|
||||
|
||||
fn main -> _/ebx: int {
|
|
@ -99,7 +99,7 @@ grep -h "^\s*void test_" bootstrap.cc |sed 's/^\s*void \(.*\)() {.*/"\1",/' |u
|
|||
|
||||
older_than bootstrap_bin bootstrap.cc *_list && {
|
||||
$CXX $CXXFLAGS bootstrap.cc -o bootstrap_bin
|
||||
echo
|
||||
echo >&2
|
||||
}
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# First program: same as https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
|
||||
# Just return 42.
|
||||
#
|
||||
# To run:
|
||||
# $ bootstrap/bootstrap translate ex1.subx -o ex1
|
||||
# $ bootstrap/bootstrap run ex1
|
||||
# Expected result:
|
||||
# $ echo $?
|
||||
# 42
|
||||
|
||||
== code
|
||||
|
||||
Entry:
|
||||
# exit(42)
|
||||
bb/copy-to-ebx 0x2a/imm32 # 42 in hex
|
||||
e8/call syscall_exit/disp32
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
Loading…
Reference in New Issue