From: plugd Date: Fri, 15 Nov 2019 10:11:59 +0000 (+0100) Subject: Drafted MOV. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=71145a5fd1ff3f563ad7307285580cc9cc733641;p=jars.git Drafted MOV. --- diff --git a/mars.scm b/mars.scm index 7dac46d..994a2b8 100644 --- a/mars.scm +++ b/mars.scm @@ -20,6 +20,14 @@ (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)) + (('copy-from! other n) + (set! opcode (other 'opcode)) + (set! modifier (other 'modifier)) + (set! A-mode (other 'A-mode)) + (set! A-num (other 'A-num)) + (set! B-mode (other 'B-mode)) + (set! B-num (other 'B-num)) + (set! name n)) (('opcode) opcode) (('modifier) modifier) (('A-mode) A-mode) @@ -126,6 +134,9 @@ (define (make-player name ptr) (list name ptr)) +(define (player-name player) (car player)) +(define (player-ptrs player) (cdr player)) + (define (player-set-ptrs! player ptrs) (set-cdr! prog-queue ptrs)) @@ -141,14 +152,14 @@ (let ((player (car players)) (other-players (cdr players)) (ptrs (player-ptrs player))) - (let ((new-ptrs (execute-instr (car ptrs)))) + (let ((new-ptrs (execute-instr (car ptrs) (player-name player)))) (if (null? new-ptrs) (run other-players (+ step 1)) (begin (player-set-ptrs! (append (cdr ptrs) new-ptrs)) (run (append other-players (list player)) (+ step 1))))))))) -(define (execute-instr ptr) +(define (execute-instr ptr name) (let* ((instr (core-get ptr)) (A-pointer (eval-operand (instr 'A-mode) (instr 'A-num) ptr)) (B-pointer (eval-operand (instr 'B-mode) (instr 'B-num) ptr)) @@ -157,12 +168,16 @@ ((DAT) '()) ;Game over, man, game over! ((MOV) (case modifier - ((A)) - ((B)) - ((AB)) - ((BA)) - ((F)) - ((X)))) + ((A) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'A-num) name)) + ((B) ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'B-num) name)) + ((AB) ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'A-num) name)) + ((BA) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'B-num) name)) + ((F) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'A-num) name) + ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'B-num) name)) + ((X) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'B-num) name) + ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'A-num) name)) + ((I) ((core-get B-pointer) 'copy-from! (core-get A-pointer) name))) + (list (addr+ ptr 1))) ((ADD) (case modifier ((A))