;;; Constants
;;
-(define core-size 8000)
+(define core-size 20)
(define max-steps 10000)
;;; Instructions
;;
-(define ((blah x y) . args)
- (match args
- (('x q) (+ x q) q)
- (('y q) y)))
-
(define ((make-instr opcode modifier A-mode A-num B-mode B-num name) . args)
(match args
(('copy n) (make-instr opcode modifier A-mode A-num B-mode B-num n))
(('B-num) B-num)
(('name) name)
(('print) (print opcode
- (if (null? modifier) "" (concat "." modifier))
+ (if (null? modifier) "" (conc "." modifier))
" " (mode-string A-mode) A-num
", " (mode-string B-mode) B-num
- (if (null? name) "" (concat " ; " name))))
+ (if (null? name) "" (conc " ; " name))))
(('set-opcode! x n) (set! opcode x) (set! name n))
(('set-modifier! x n) (set! modifier x) (set! name n))
(('set-A-mode! x n) (set! A-mode x) (set! name n))
(define initial-instruction
(make-instr 'DAT '() 'immediate 0 'immediate 0 '()))
+
;;; Memory setup and addressing
;;
(define (initialize-core)
(let loop ((i 0))
- (unless (< i core-size)
+ (unless (>= i core-size)
(vector-set! core i (initial-instruction 'copy '()))
(loop (+ i 1)))))
+(define (core-dump)
+ (let loop ((i 0))
+ (unless (>= i core-size)
+ ((vector-ref core i) 'print)
+ (loop (+ i 1)))))
+
(define (addr+ . args)
(foldl (lambda (a b)
(modulo (+ a b core-size) core-size))
;;
(define (make-prog name instrs offset)
- (list name instructions offset))
+ (list name instrs offset))
(define (prog-name prog) (list-ref prog 0))
(define (prog-instrs prog) (list-ref prog 1))
(let loop ((ptr addr)
(instrs (prog-instrs prog)))
(unless (null? instrs)
- (vector-set! core ptr (instr-copy (car instrs)))
+ (vector-set! core ptr ((car instrs) 'copy (prog-name prog)))
(loop (addr+ ptr 1) (cdr instrs))))
(make-player (prog-name prog)
(addr+ addr (prog-offset prog))))
(remaining prog-len))
(if (= remaining 0)
#t
- (if ((vector-ref core ptr) 'name)
- #f
+ (if (null? ((vector-ref core ptr) 'name))
(loop (addr+ ptr 1)
- (- remaining 1))))))
+ (- remaining 1))
+ #f))))
(define (install-progs progs)
(let loop ((players '())