From 614d0ecff4b47fd94d86c764f99f8008493e7a50 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 15 Jun 2021 20:56:41 -0700 Subject: . --- html/linux/advent2017/1a.mu.html | 173 +++++++++++++++++++++++---------------- linux/advent2017/1a.mu | 1 - tools/update_html | 2 +- 3 files changed, 103 insertions(+), 73 deletions(-) diff --git a/html/linux/advent2017/1a.mu.html b/html/linux/advent2017/1a.mu.html index f3579b5d..3b9e8592 100644 --- a/html/linux/advent2017/1a.mu.html +++ b/html/linux/advent2017/1a.mu.html @@ -2,20 +2,22 @@ -~/play/mu/linux/advent2017/1a.mu.html +Mu - linux/advent2017/1a.mu - + - - -
-# Advent of code 2017, problem 1a
-#   https://adventofcode.com/2017/day/1
-#
-# Mu solution by Sumeet Agarwal and Kartik Agaram
-#   https://github.com/akkartik/mu/blob/main/linux/advent2017/1a.mu
-#   https://archive.org/details/2021-06-02-akkartik-sumeet
-#
-# To build on Linux:
-#   $ git clone https://github.com/akkartik/mu
-#   $ cd mu/linux
-#   $ ./translate advent2017/1a.mu            # emits a.elf
-# To run on Linux:
-#   Download https://adventofcode.com/2017/day/1/input
-#   $ ./a.elf < input
-# Type in the number returned at https://adventofcode.com/2017/day/1
-
-fn main -> _/ebx: int {
-  var input_stream: (stream byte 0x8000)
-  var input_stream_addr/esi: (addr stream byte) <- address input_stream
-
-  var sum/edi: int <- copy 0
-  read-line-from-real-keyboard input_stream_addr
-
-  var temp/eax: int <- read_digit input_stream_addr
-  var first_digit/ebx: int <- copy temp
-  var this_digit/edx: int <- copy temp
 
-  {
-    var done?/eax: boolean <- stream-empty? input_stream_addr
-    compare done?, 1
-    break-if-=
-
-    var next_digit/eax: int <- read_digit input_stream_addr
-    # hacky newline check
-    compare next_digit, 0
-    break-if-<
-
-    {
-      compare this_digit, next_digit
-      break-if-!=
-      sum <- add this_digit
-    }
-
-    this_digit <- copy next_digit
-
-    loop
-  }
-
-  # the last iteration will need to compare the last number to the first
-  {
-    compare this_digit, first_digit
-    break-if-!=
-    sum <- add this_digit
-  }
+
+
+
+https://github.com/akkartik/mu/blob/main/linux/advent2017/1a.mu
+
+ 1 # Advent of code 2017, problem 1a
+ 2 #   https://adventofcode.com/2017/day/1
+ 3 #
+ 4 # Mu solution by Sumeet Agarwal and Kartik Agaram
+ 5 #   https://archive.org/details/2021-06-02-akkartik-sumeet
+ 6 #
+ 7 # To build on Linux:
+ 8 #   $ git clone https://github.com/akkartik/mu
+ 9 #   $ cd mu/linux
+10 #   $ ./translate advent2017/1a.mu            # emits a.elf
+11 # To run on Linux:
+12 #   Download https://adventofcode.com/2017/day/1/input
+13 #   $ ./a.elf < input
+14 # Type in the number returned at https://adventofcode.com/2017/day/1
+15 
+16 fn main -> _/ebx: int {
+17   var input_stream: (stream byte 0x8000)
+18   var input_stream_addr/esi: (addr stream byte) <- address input_stream
+19 
+20   var sum/edi: int <- copy 0
+21   read-line-from-real-keyboard input_stream_addr
+22 
+23   var temp/eax: int <- read_digit input_stream_addr
+24   var first_digit/ebx: int <- copy temp
+25   var this_digit/edx: int <- copy temp
+26 
+27   {
+28     var done?/eax: boolean <- stream-empty? input_stream_addr
+29     compare done?, 1
+30     break-if-=
+31 
+32     var next_digit/eax: int <- read_digit input_stream_addr
+33     # hacky newline check
+34     compare next_digit, 0
+35     break-if-<
+36 
+37     {
+38       compare this_digit, next_digit
+39       break-if-!=
+40       sum <- add this_digit
+41     }
+42 
+43     this_digit <- copy next_digit
+44 
+45     loop
+46   }
+47 
+48   # the last iteration will need to compare the last number to the first
+49   {
+50     compare this_digit, first_digit
+51     break-if-!=
+52     sum <- add this_digit
+53   }
+54 
+55   print-int32-decimal 0, sum
+56 
+57   return 0/ok
+58 }
+59 
+60 fn read_digit input_stream_addr: (addr stream byte) -> _/eax: int {
+61   var next_digit/eax: byte <- read-byte input_stream_addr
+62   next_digit <- subtract 0x30
+63   var next_digit/eax: int <- copy next_digit
+64   return next_digit
+65 }
 
diff --git a/linux/advent2017/1a.mu b/linux/advent2017/1a.mu index 4ce92c9d..2f639080 100644 --- a/linux/advent2017/1a.mu +++ b/linux/advent2017/1a.mu @@ -2,7 +2,6 @@ # https://adventofcode.com/2017/day/1 # # Mu solution by Sumeet Agarwal and Kartik Agaram -# https://github.com/akkartik/mu/blob/main/linux/advent2017/1a.mu # https://archive.org/details/2021-06-02-akkartik-sumeet # # To build on Linux: diff --git a/tools/update_html b/tools/update_html index c395f675..6fadd0e9 100755 --- a/tools/update_html +++ b/tools/update_html @@ -78,7 +78,7 @@ do process $f done -for f in linux/advent2020/*.mu +for f in linux/advent2020/*.mu linux/advent2017/*.mu do ( cd $(dirname $f) ctags -x ../[0-9]*.subx ../[0-9]*.mu $(basename $f) > /tmp/tags -- cgit 1.4.1-2-gfad0