about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-12-30 23:38:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-12-30 23:53:28 -0800
commit6195c0ad656f20e62a4924970b90ce4b345512eb (patch)
tree199f261f0bdfcf82306472943e8d82c79036d9b2
parent3af0919dc6af96454bbab5b2f070fe33e57bc9a8 (diff)
downloadmu-6195c0ad656f20e62a4924970b90ce4b345512eb.tar.gz
472
-rw-r--r--chessboard.mu47
-rw-r--r--mu.arc13
2 files changed, 50 insertions, 10 deletions
diff --git a/chessboard.mu b/chessboard.mu
index bba3a3ad..efbec20c 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -9,17 +9,52 @@
                                               p:literal p:literal p:literal p:literal p:literal p:literal p:literal p:literal
                                               r:literal n:literal b:literal q:literal k:literal b:literal n:literal r:literal)
   ; assert(length(initial-position) == 64)
+;?   (print-primitive (("list-length\n" literal)))
   (len:integer <- list-length initial-position:list-address)
-  (print-primitive len:integer)
-  (reply)
-;?   (b:board <- read-board initial-position:list)
-;?   (print-board b:board)
+  (correct-length?:boolean <- equal len:integer 64:literal)
+  (assert correct-length?:boolean "chessboard had incorrect size")
+  (b:board-address <- new board:literal 8:literal)
+  (col:integer <- copy 0:literal)
+  (curr:list-address <- copy initial-position:list-address)
+  { begin
+    (done?:boolean <- equal col:integer 8:literal)
+    (break-if done?:boolean)
+;?     (print-primitive col:integer)
+;?     (print-primitive (("\n" literal)))
+    (file:file-address-address <- index-address b:board-address/deref col:integer)
+    (file:file-address-address/deref curr:list-address <- read-file curr:list-address)
+    (col:integer <- add col:integer 1:literal)
+    (loop)
+  }
+  (reply b:board-address)
 ])
 
-(function print-board [
+(function read-file [
+  (default-scope:scope-address <- new scope:literal 30:literal)
+  (cursor:list-address <- next-input)
+  (result:file-address <- new file:literal 8:literal)
+  (row:integer <- copy 0:literal)
+  { begin
+    (done?:boolean <- equal row:integer 8:literal)
+    (break-if done?:boolean)
+;?     (print-primitive (("  " literal)))
+;?     (print-primitive row:integer)
+;?     (print-primitive (("\n" literal)))
+    (src:tagged-value-address <- list-value-address cursor:list-address)
+    (dest:square-address <- index-address result:file-address/deref row:integer)
+    (dest:square-address/deref <- get src:tagged-value-address/deref payload:offset)  ; unsafe typecast
+    (cursor:list-address <- list-next cursor:list-address)
+    (row:integer <- add row:integer 1:literal)
+    (loop)
+  }
+  (reply result:file-address cursor:list-address)
+])
 
+(function print-board [
+  (reply)
 ])
 
 (function main [
-  (read-board)
+  (b:board-address <- read-board)
+  (print-board b:board-address)
 ])
diff --git a/mu.arc b/mu.arc
index dd8c5655..1259a87e 100644
--- a/mu.arc
+++ b/mu.arc
@@ -147,9 +147,12 @@
               screen-address (obj size 1  address t  elem '(screen))
               ; chessboard
               square (obj size 1)
-              file (obj array t  elem '(square))
-              file-address (obj address t  elem '(file))
+              square-address (obj size 1  address t  elem '(square))
+              file (obj array t  elem '(square))  ; todo: include array dimensions in type table
+              file-address (obj size 1  address t  elem '(file))
+              file-address-address (obj size 1  address t  elem '(file-address))
               board (obj array t  elem '(file-address))
+              board-address (obj size 1  address t  elem '(board))
               )))
 
 ;; managing concurrent routines
@@ -317,6 +320,7 @@
 ; routines consist of instrs
 ; instrs consist of oargs, op and args
 (def parse-instr (instr)
+;?   (prn instr)
   (iflet delim (pos '<- instr)
     (list (cut instr 0 delim)  ; oargs
           (v (instr (+ delim 1)))  ; op
@@ -1258,13 +1262,13 @@
   (x:tagged-value-address <- new tagged-value:literal)
   (x:tagged-value-address/deref <- next-input)
   (p:type <- next-input)
-  (xtype:type <- get x:tagged-value-address/deref 0:offset)
+  (xtype:type <- get x:tagged-value-address/deref type:offset)
   (match?:boolean <- equal xtype:type p:type)
   { begin
     (break-if match?:boolean)
     (reply 0:literal nil:literal)
   }
-  (xvalue:location <- get x:tagged-value-address/deref 1:offset)
+  (xvalue:location <- get x:tagged-value-address/deref payload:offset)
   (reply xvalue:location match?:boolean))
 
 (init-fn init-tagged-value
@@ -1705,6 +1709,7 @@
 (awhen (pos "--" argv)
   (map add-code:readfile (cut argv (+ it 1)))
 ;?   (= dump-trace* (obj whitelist '("run" "schedule" "add")))
+;?   (= dump-trace* (obj whitelist '("cn0")))
 ;?   (set dump-trace*)
 ;?   (freeze function*)
 ;?   (prn function*!factorial)