This commit is contained in:
Kartik K. Agaram 2014-12-30 23:38:50 -08:00
parent 3af0919dc6
commit 6195c0ad65
2 changed files with 50 additions and 10 deletions

View File

@ -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 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)
])

13
mu.arc
View File

@ -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)