about summary refs log tree commit diff stats
path: root/apps/advent2020
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-02-07 00:17:17 -0800
committerKartik Agaram <vc@akkartik.com>2021-02-07 00:20:29 -0800
commit74f1512ff113cf35706af57e9d40c78b7d77f49e (patch)
tree7c7acb23e1a26387117e464ec6ab01126dbc8ae8 /apps/advent2020
parent6c4c25555c7df0d78ad41c813345f63cae1819de (diff)
downloadmu-74f1512ff113cf35706af57e9d40c78b7d77f49e.tar.gz
7690
Convert comments about magic constants into metadata.
Diffstat (limited to 'apps/advent2020')
-rw-r--r--apps/advent2020/1a.mu12
-rw-r--r--apps/advent2020/1b.mu12
-rw-r--r--apps/advent2020/2a.mu12
-rw-r--r--apps/advent2020/2b.mu10
-rw-r--r--apps/advent2020/3a.mu8
-rw-r--r--apps/advent2020/3b.mu8
-rw-r--r--apps/advent2020/4a.mu8
-rw-r--r--apps/advent2020/4b.mu42
-rw-r--r--apps/advent2020/5a.mu6
-rw-r--r--apps/advent2020/5b.mu6
10 files changed, 62 insertions, 62 deletions
diff --git a/apps/advent2020/1a.mu b/apps/advent2020/1a.mu
index 05aa58bf..67fdc358 100644
--- a/apps/advent2020/1a.mu
+++ b/apps/advent2020/1a.mu
@@ -27,7 +27,7 @@ fn main -> _/ebx: int {
       read-line-from-real-keyboard line
       # if line is empty (not even a newline), quit
       var done?/eax: boolean <- stream-empty? line
-      compare done?, 0  # false
+      compare done?, 0/false
       break-if-!=
 #?       print-stream-to-real-screen line
       # convert line to int and append it to numbers
@@ -56,7 +56,7 @@ fn main -> _/ebx: int {
     target <- subtract *src
     {
       var found?/eax: boolean <- find-after numbers, i, target
-      compare found?, 0  # false
+      compare found?, 0/false
       break-if-=
       print-string 0, "found\n"
       print-int32-decimal 0, *src
@@ -66,12 +66,12 @@ fn main -> _/ebx: int {
       target <- multiply *src
       print-int32-decimal 0, target
       print-string 0, "\n"
-      return 0  # success
+      return 0/success
     }
     i <- increment
     loop
   }
-  return 1  # not found
+  return 1/not-found
 }
 
 fn find-after _numbers: (addr array int), start: int, _target: int -> _/eax: boolean {
@@ -88,10 +88,10 @@ fn find-after _numbers: (addr array int), start: int, _target: int -> _/eax: boo
     compare *src, target
     {
       break-if-!=
-      return 1  # true
+      return 1/true
     }
     i <- increment
     loop
   }
-  return 0  # false
+  return 0/false
 }
diff --git a/apps/advent2020/1b.mu b/apps/advent2020/1b.mu
index aa2d21f1..a638d228 100644
--- a/apps/advent2020/1b.mu
+++ b/apps/advent2020/1b.mu
@@ -27,7 +27,7 @@ fn main -> _/ebx: int {
       read-line-from-real-keyboard line
       # if line is empty (not even a newline), quit
       var done?/eax: boolean <- stream-empty? line
-      compare done?, 0  # false
+      compare done?, 0/false
       break-if-!=
 #?       print-stream-to-real-screen line
       # convert line to int and append it to numbers
@@ -65,7 +65,7 @@ fn main -> _/ebx: int {
         target <- subtract *src2
         {
           var found?/eax: boolean <- find-after numbers, j, target
-          compare found?, 0  # false
+          compare found?, 0/false
           break-if-=
           print-string 0, "found\n"
           print-int32-decimal 0, *src
@@ -78,7 +78,7 @@ fn main -> _/ebx: int {
           target <- multiply *src2
           print-int32-decimal 0, target
           print-string 0, "\n"
-          return 0  # success
+          return 0/success
         }
       }
       j <- increment
@@ -87,7 +87,7 @@ fn main -> _/ebx: int {
     i <- increment
     loop
   }
-  return 1  # not found
+  return 1/not-found
 }
 
 fn find-after _numbers: (addr array int), start: int, _target: int -> _/eax: boolean {
@@ -104,10 +104,10 @@ fn find-after _numbers: (addr array int), start: int, _target: int -> _/eax: boo
     compare *src, target
     {
       break-if-!=
-      return 1  # true
+      return 1/true
     }
     i <- increment
     loop
   }
-  return 0  # false
+  return 0/false
 }
diff --git a/apps/advent2020/2a.mu b/apps/advent2020/2a.mu
index aad94be4..dc67b94a 100644
--- a/apps/advent2020/2a.mu
+++ b/apps/advent2020/2a.mu
@@ -20,7 +20,7 @@ fn main -> _/ebx: int {
     read-line-from-real-keyboard line
     # if line is empty (not even a newline), quit
     var done?/eax: boolean <- stream-empty? line
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     print-stream-to-real-screen line
     # slice = next-token(line, '-')
@@ -47,7 +47,7 @@ fn main -> _/ebx: int {
     skip-chars-matching-whitespace line
     # now check the rest of the line
     var is-valid?/eax: boolean <- is-valid? start, end, letter, line
-    compare is-valid?, 0  # false
+    compare is-valid?, 0/false
     {
       break-if-=
       print-string 0, "valid!\n"
@@ -67,7 +67,7 @@ fn is-valid? start: int, end: int, letter: byte, password: (addr stream byte) ->
   #     ++letter-count
   {
     var done?/eax: boolean <- stream-empty? password
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     var c/eax: byte <- read-byte password
     compare c, letter
@@ -81,12 +81,12 @@ fn is-valid? start: int, end: int, letter: byte, password: (addr stream byte) ->
   compare letter-count, start
   {
     break-if->=
-    return 0  # false
+    return 0/false
   }
   compare letter-count, end
   {
     break-if-<=
-    return 0  # false
+    return 0/false
   }
-  return 1  # true
+  return 1/true
 }
diff --git a/apps/advent2020/2b.mu b/apps/advent2020/2b.mu
index 116029b0..13f60f0f 100644
--- a/apps/advent2020/2b.mu
+++ b/apps/advent2020/2b.mu
@@ -20,7 +20,7 @@ fn main -> _/ebx: int {
     read-line-from-real-keyboard line
     # if line is empty (not even a newline), quit
     var done?/eax: boolean <- stream-empty? line
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     print-stream-to-real-screen line
     # slice = next-token(line, '-')
@@ -53,7 +53,7 @@ fn main -> _/ebx: int {
     skip-chars-matching-whitespace line
     # now check the rest of the line
     var is-valid?/eax: boolean <- is-valid? pos1, pos2, letter, line
-    compare is-valid?, 0  # false
+    compare is-valid?, 0/false
     {
       break-if-=
       print-string 0, "valid!\n"
@@ -85,7 +85,7 @@ fn is-valid? pos1: int, pos2: int, letter: byte, password: (addr stream byte) ->
 #?     print-int32-decimal 0, i
 #?     print-string 0, "\n"
     var done?/eax: boolean <- stream-empty? password
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     var c/eax: byte <- read-byte password
 #?     {
@@ -116,7 +116,7 @@ fn is-valid? pos1: int, pos2: int, letter: byte, password: (addr stream byte) ->
   compare letter-count, 1
   {
     break-if-!=
-    return 1  # true
+    return 1/true
   }
-  return 0  # false
+  return 0/false
 }
diff --git a/apps/advent2020/3a.mu b/apps/advent2020/3a.mu
index 777a7be0..76bda961 100644
--- a/apps/advent2020/3a.mu
+++ b/apps/advent2020/3a.mu
@@ -26,7 +26,7 @@ fn main -> _/ebx: int {
       read-line-from-real-keyboard line
       # if line is empty (not even a newline), quit
       var done?/eax: boolean <- stream-empty? line
-      compare done?, 0  # false
+      compare done?, 0/false
       break-if-!=
       # wastefully recompute width on every line
       # zero error-checking; we assume input lines are all equally long
@@ -34,7 +34,7 @@ fn main -> _/ebx: int {
       # turn each byte into a tree and append it
       $main:line-loop: {
         var done?/eax: boolean <- stream-empty? line
-        compare done?, 0  # false
+        compare done?, 0/false
         break-if-!=
 #?         print-int32-decimal 0, num-rows
 #?         print-string 0, " "
@@ -43,10 +43,10 @@ fn main -> _/ebx: int {
         var dest/ebx: (addr int) <- index trees, trees-length
         var c/eax: byte <- read-byte line
         # newline comes only at end of line
-        compare c, 0xa  # newline
+        compare c, 0xa/newline
         break-if-=
         # '#' = tree
-        compare c, 0x23  # '#'
+        compare c, 0x23/hash
         {
           break-if-!=
           copy-to *dest, 1
diff --git a/apps/advent2020/3b.mu b/apps/advent2020/3b.mu
index 531d18fb..fcc9261a 100644
--- a/apps/advent2020/3b.mu
+++ b/apps/advent2020/3b.mu
@@ -26,7 +26,7 @@ fn main -> _/ebx: int {
       read-line-from-real-keyboard line
       # if line is empty (not even a newline), quit
       var done?/eax: boolean <- stream-empty? line
-      compare done?, 0  # false
+      compare done?, 0/false
       break-if-!=
       # wastefully recompute width on every line
       # zero error-checking; we assume input lines are all equally long
@@ -34,7 +34,7 @@ fn main -> _/ebx: int {
       # turn each byte into a tree and append it
       $main:line-loop: {
         var done?/eax: boolean <- stream-empty? line
-        compare done?, 0  # false
+        compare done?, 0/false
         break-if-!=
 #?         print-int32-decimal 0, num-rows
 #?         print-string 0, " "
@@ -43,10 +43,10 @@ fn main -> _/ebx: int {
         var dest/ebx: (addr int) <- index trees, trees-length
         var c/eax: byte <- read-byte line
         # newline comes only at end of line
-        compare c, 0xa  # newline
+        compare c, 0xa/newline
         break-if-=
         # '#' = tree
-        compare c, 0x23  # '#'
+        compare c, 0x23/hash
         {
           break-if-!=
           copy-to *dest, 1
diff --git a/apps/advent2020/4a.mu b/apps/advent2020/4a.mu
index 59dada2b..e645da24 100644
--- a/apps/advent2020/4a.mu
+++ b/apps/advent2020/4a.mu
@@ -21,14 +21,14 @@ fn main -> _/ebx: int {
     read-line-from-real-keyboard line
     # if line is empty (not even a newline), quit
     var done?/eax: boolean <- stream-empty? line
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     print-stream-to-real-screen line
     # if line has just a newline, process passport
     skip-chars-matching-whitespace line
     var new-passport?/eax: boolean <- stream-empty? line
     {
-      compare new-passport?, 0  # false
+      compare new-passport?, 0/false
       break-if-=
       compare curr-passport-field-count, 7
       {
@@ -44,13 +44,13 @@ fn main -> _/ebx: int {
     $main:word-loop: {
       next-word line, slice
       var done?/eax: boolean <- slice-empty? slice
-      compare done?, 0  # false
+      compare done?, 0/false
       break-if-!=
       print-string 0, "  "
       print-slice-to-real-screen slice
       # treat cid as optional
       var optional?/eax: boolean <- slice-starts-with? slice, "cid:"
-      compare optional?, 0  # false
+      compare optional?, 0/false
       {
         break-if-!=
         # otherwise assume there are no invalid fields and no duplicate fields
diff --git a/apps/advent2020/4b.mu b/apps/advent2020/4b.mu
index 8625ff93..1ab29456 100644
--- a/apps/advent2020/4b.mu
+++ b/apps/advent2020/4b.mu
@@ -23,14 +23,14 @@ fn main -> _/ebx: int {
     read-line-from-real-keyboard line
     # if line is empty (not even a newline), quit
     var done?/eax: boolean <- stream-empty? line
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     print-stream-to-real-screen line
     # if line has just a newline, process passport
     skip-chars-matching-whitespace line
     var new-passport?/eax: boolean <- stream-empty? line
     {
-      compare new-passport?, 0  # false
+      compare new-passport?, 0/false
       break-if-=
       compare curr-passport-field-count, 7
       {
@@ -46,7 +46,7 @@ fn main -> _/ebx: int {
     $main:word-loop: {
       skip-chars-matching-whitespace line
       var done?/eax: boolean <- stream-empty? line
-      compare done?, 0  # false
+      compare done?, 0/false
       break-if-!=
       next-token line, 0x3a, key-slice  # ':'
       var dummy/eax: byte <- read-byte line  # skip ':'
@@ -57,7 +57,7 @@ fn main -> _/ebx: int {
       print-string 0, "\n"
       # treat cid as optional
       var cid?/eax: boolean <- slice-equal? key-slice, "cid"
-      compare cid?, 0  # false
+      compare cid?, 0/false
       loop-if-!=
       # increment field count
       curr-passport-field-count <- increment
@@ -65,7 +65,7 @@ fn main -> _/ebx: int {
       # byr
       {
         var byr?/eax: boolean <- slice-equal? key-slice, "byr"
-        compare byr?, 0  # false
+        compare byr?, 0/false
         break-if-=
         # 1920 <= byr <= 2002
         var byr/eax: int <- parse-decimal-int-from-slice val-slice
@@ -85,7 +85,7 @@ fn main -> _/ebx: int {
       # iyr
       {
         var iyr?/eax: boolean <- slice-equal? key-slice, "iyr"
-        compare iyr?, 0  # false
+        compare iyr?, 0/false
         break-if-=
         # 2010 <= iyr <= 2020
         var iyr/eax: int <- parse-decimal-int-from-slice val-slice
@@ -105,7 +105,7 @@ fn main -> _/ebx: int {
       # eyr
       {
         var eyr?/eax: boolean <- slice-equal? key-slice, "eyr"
-        compare eyr?, 0  # false
+        compare eyr?, 0/false
         break-if-=
         # 2020 <= eyr <= 2030
         var eyr/eax: int <- parse-decimal-int-from-slice val-slice
@@ -125,7 +125,7 @@ fn main -> _/ebx: int {
       # hgt
       {
         var hgt?/eax: boolean <- slice-equal? key-slice, "hgt"
-        compare hgt?, 0  # false
+        compare hgt?, 0/false
         break-if-=
         # convert val
         var s: (handle array byte)
@@ -143,7 +143,7 @@ fn main -> _/ebx: int {
           var suffix/eax: (addr array byte) <- lookup *suffix-ah
           {
             var match?/eax: boolean <- string-equal? suffix, "in"
-            compare match?, 0  # false
+            compare match?, 0/false
             break-if-=
             # if suffix is "in", 59 <= val <= 96
             var num-h: (handle array byte)
@@ -167,7 +167,7 @@ fn main -> _/ebx: int {
           }
           {
             var match?/eax: boolean <- string-equal? suffix, "cm"
-            compare match?, 0  # false
+            compare match?, 0/false
             break-if-=
             # if suffix is "cm", 150 <= val <= 193
             var num-h: (handle array byte)
@@ -197,7 +197,7 @@ fn main -> _/ebx: int {
       # hcl
       {
         var hcl?/eax: boolean <- slice-equal? key-slice, "hcl"
-        compare hcl?, 0  # false
+        compare hcl?, 0/false
         break-if-=
         # convert val
         var s: (handle array byte)
@@ -217,7 +217,7 @@ fn main -> _/ebx: int {
         {
           var c/eax: (addr byte) <- index s3, 0
           var c2/eax: byte <- copy-byte *c
-          compare c2, 0x23  # '#'
+          compare c2, 0x23/hash
           break-if-=
           print-string 0, "invalid2\n"
           curr-passport-field-count <- copy 8
@@ -242,28 +242,28 @@ fn main -> _/ebx: int {
       # ecl
       {
         var ecl?/eax: boolean <- slice-equal? key-slice, "ecl"
-        compare ecl?, 0  # false
+        compare ecl?, 0/false
         break-if-=
         var amb?/eax: boolean <- slice-equal? val-slice, "amb"
-        compare amb?, 0  # false
+        compare amb?, 0/false
         loop-if-!= $main:word-loop
         var blu?/eax: boolean <- slice-equal? val-slice, "blu"
-        compare blu?, 0  # false
+        compare blu?, 0/false
         loop-if-!= $main:word-loop
         var brn?/eax: boolean <- slice-equal? val-slice, "brn"
-        compare brn?, 0  # false
+        compare brn?, 0/false
         loop-if-!= $main:word-loop
         var gry?/eax: boolean <- slice-equal? val-slice, "gry"
-        compare gry?, 0  # false
+        compare gry?, 0/false
         loop-if-!= $main:word-loop
         var grn?/eax: boolean <- slice-equal? val-slice, "grn"
-        compare grn?, 0  # false
+        compare grn?, 0/false
         loop-if-!= $main:word-loop
         var hzl?/eax: boolean <- slice-equal? val-slice, "hzl"
-        compare hzl?, 0  # false
+        compare hzl?, 0/false
         loop-if-!= $main:word-loop
         var oth?/eax: boolean <- slice-equal? val-slice, "oth"
-        compare oth?, 0  # false
+        compare oth?, 0/false
         loop-if-!= $main:word-loop
         print-string 0, "invalid\n"
         curr-passport-field-count <- copy 8
@@ -271,7 +271,7 @@ fn main -> _/ebx: int {
       # pid
       {
         var pid?/eax: boolean <- slice-equal? key-slice, "pid"
-        compare pid?, 0  # false
+        compare pid?, 0/false
         break-if-=
         # convert val
         var s: (handle array byte)
diff --git a/apps/advent2020/5a.mu b/apps/advent2020/5a.mu
index f933dd16..5a456608 100644
--- a/apps/advent2020/5a.mu
+++ b/apps/advent2020/5a.mu
@@ -19,7 +19,7 @@ fn main -> _/ebx: int {
     print-stream-to-real-screen line
     # if line is empty (not even a newline), quit
     var done?/eax: boolean <- stream-empty? line
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     # process line
     var seat-id/eax: int <- convert-from-binary line
@@ -50,12 +50,12 @@ fn convert-from-binary in: (addr stream byte) -> _/eax: int {
 #?     print-string 0, "\n"
     var bit/edx: int <- copy 0
     {
-      compare c, 0x42  # 'B'
+      compare c, 0x42/B
       break-if-!=
       bit <- copy 1
     }
     {
-      compare c, 0x52  # 'R'
+      compare c, 0x52/R
       break-if-!=
       bit <- copy 1
     }
diff --git a/apps/advent2020/5b.mu b/apps/advent2020/5b.mu
index 215b0a66..fbc0d618 100644
--- a/apps/advent2020/5b.mu
+++ b/apps/advent2020/5b.mu
@@ -20,7 +20,7 @@ fn main -> _/ebx: int {
     read-line-from-real-keyboard line
     # if line is empty (not even a newline), quit
     var done?/eax: boolean <- stream-empty? line
-    compare done?, 0  # false
+    compare done?, 0/false
     break-if-!=
     # process line
     var seat-id/eax: int <- convert-from-binary line
@@ -63,12 +63,12 @@ fn convert-from-binary in: (addr stream byte) -> _/eax: int {
     var c/eax: byte <- read-byte in
     var bit/edx: int <- copy 0
     {
-      compare c, 0x42  # 'B'
+      compare c, 0x42/B
       break-if-!=
       bit <- copy 1
     }
     {
-      compare c, 0x52  # 'R'
+      compare c, 0x52/R
       break-if-!=
       bit <- copy 1
     }