diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-11-02 19:50:34 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-11-02 19:50:52 -0800 |
commit | a3f779158626b9ad3c81959b85cbfbbce17425fd (patch) | |
tree | 10c9da6ee8783a2ed2a3e6e928fb5d70024d1bcc /apps/raytracing | |
parent | 951c3f4c92358d3962154a4ef24a19366ea8a619 (diff) | |
download | mu-a3f779158626b9ad3c81959b85cbfbbce17425fd.tar.gz |
7159 - explicitly use 'return' everywhere
https://github.com/akkartik/mu/issues/45#issuecomment-719990879, task 2.
Diffstat (limited to 'apps/raytracing')
-rw-r--r-- | apps/raytracing/1.mu | 4 | ||||
-rw-r--r-- | apps/raytracing/2.mu | 4 | ||||
-rw-r--r-- | apps/raytracing/3.mu | 14 | ||||
-rw-r--r-- | apps/raytracing/vec.mu | 10 |
4 files changed, 18 insertions, 14 deletions
diff --git a/apps/raytracing/1.mu b/apps/raytracing/1.mu index 539332ea..fbc76f1d 100644 --- a/apps/raytracing/1.mu +++ b/apps/raytracing/1.mu @@ -7,7 +7,7 @@ # $ ./translate_mu apps/raytracing/1.mu # $ ./a.elf > 1.ppm -fn main -> exit-status/ebx: int { +fn main -> _/ebx: int { print-string 0, "P3\n256 256\n255\n" var j/ecx: int <- copy 0xff { @@ -27,5 +27,5 @@ fn main -> exit-status/ebx: int { j <- decrement loop } - exit-status <- copy 1 + return 0 } diff --git a/apps/raytracing/2.mu b/apps/raytracing/2.mu index 69bc9a40..e23ce3b4 100644 --- a/apps/raytracing/2.mu +++ b/apps/raytracing/2.mu @@ -6,7 +6,7 @@ # $ ./translate_mu apps/raytracing/2.mu # $ ./a.elf > 2.ppm -fn main -> exit-status/ebx: int { +fn main -> _/ebx: int { print-string 0, "P3\n256 256\n255\n" var _four/edx: int <- copy 4 var four/xmm1: float <- convert _four @@ -47,7 +47,7 @@ fn main -> exit-status/ebx: int { j <- decrement loop } - exit-status <- copy 1 + return 0 } type rgb { diff --git a/apps/raytracing/3.mu b/apps/raytracing/3.mu index acc2df33..5b87f344 100644 --- a/apps/raytracing/3.mu +++ b/apps/raytracing/3.mu @@ -59,7 +59,7 @@ fn ray-color _in: (addr ray), _out: (addr rgb) { #? print-string 0, "\n" } -fn main -> exit-status/ebx: int { +fn main -> _/ebx: int { # image # width = 400 @@ -221,7 +221,7 @@ fn main -> exit-status/ebx: int { j <- decrement loop } - exit-status <- copy 1 + return 0 } type ray { @@ -457,18 +457,19 @@ fn vec3-unit in: (addr vec3), out: (addr vec3) { vec3-scale-down out, len } -fn vec3-length v: (addr vec3) -> result/xmm0: float { - result <- vec3-length-squared v +fn vec3-length v: (addr vec3) -> _/xmm0: float { + var result/xmm0: float <- vec3-length-squared v result <- square-root result + return result } -fn vec3-length-squared _v: (addr vec3) -> result/xmm0: float { +fn vec3-length-squared _v: (addr vec3) -> _/xmm0: float { var v/esi: (addr vec3) <- copy _v # result = v.x * v.x var src/eax: (addr float) <- get v, x var tmp/xmm1: float <- copy *src tmp <- multiply tmp - result <- copy tmp + var result/xmm0: float <- copy tmp # result += v.y * v.y src <- get v, y tmp <- copy *src @@ -479,4 +480,5 @@ fn vec3-length-squared _v: (addr vec3) -> result/xmm0: float { tmp <- copy *src tmp <- multiply tmp result <- add tmp + return result } diff --git a/apps/raytracing/vec.mu b/apps/raytracing/vec.mu index ce745a15..c93bab91 100644 --- a/apps/raytracing/vec.mu +++ b/apps/raytracing/vec.mu @@ -102,18 +102,19 @@ fn vec3-unit in: (addr vec3), out: (addr vec3) { vec3-scale-down out, len } -fn vec3-length v: (addr vec3) -> result/xmm0: float { - result <- vec3-length-squared v +fn vec3-length v: (addr vec3) -> _/xmm0: float { + var result/xmm0: float <- vec3-length-squared v result <- square-root result + return result } -fn vec3-length-squared _v: (addr vec3) -> result/xmm0: float { +fn vec3-length-squared _v: (addr vec3) -> _/xmm0: float { var v/esi: (addr vec3) <- copy _v # result = v.x * v.x var src/eax: (addr float) <- get v, x var tmp/xmm1: float <- copy *src tmp <- multiply tmp - result <- copy tmp + var result/xmm0: float <- copy tmp # result += v.y * v.y src <- get v, y tmp <- copy *src @@ -124,6 +125,7 @@ fn vec3-length-squared _v: (addr vec3) -> result/xmm0: float { tmp <- copy *src tmp <- multiply tmp result <- add tmp + return result } fn vec3-dot _v1: (addr vec3), _v2: (addr vec3) -> result/xmm0: float { |