|
|
@ -6,7 +6,6 @@
|
|
|
|
(time (STARS (vector (λ () TOKS) ...)))))
|
|
|
|
(time (STARS (vector (λ () TOKS) ...)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define regs (make-hasheq))
|
|
|
|
(define regs (make-hasheq))
|
|
|
|
(struct offset-signal (val))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide set mul sub jnz)
|
|
|
|
(provide set mul sub jnz)
|
|
|
|
(define-macro (value VAL) #'(let ([val 'VAL]) (if (number? val) val (hash-ref! regs val 0))))
|
|
|
|
(define-macro (value VAL) #'(let ([val 'VAL]) (if (number? val) val (hash-ref! regs val 0))))
|
|
|
@ -14,14 +13,18 @@
|
|
|
|
(define-macro (sub REG VAL) #'(hash-update! regs 'REG (λ (val) (- val (value VAL))) 0))
|
|
|
|
(define-macro (sub REG VAL) #'(hash-update! regs 'REG (λ (val) (- val (value VAL))) 0))
|
|
|
|
(define-macro (mul REG VAL) #'(begin (hash-update! regs 'mul-count add1 0)
|
|
|
|
(define-macro (mul REG VAL) #'(begin (hash-update! regs 'mul-count add1 0)
|
|
|
|
(hash-update! regs 'REG (λ (val) (* val (value VAL))) 0)))
|
|
|
|
(hash-update! regs 'REG (λ (val) (* val (value VAL))) 0)))
|
|
|
|
(define-macro (jnz REG VAL) #'(when (not (zero? (value REG))) (raise (offset-signal (value VAL)))))
|
|
|
|
(define-macro (jnz REG VAL) #'(when (not (zero? (value REG))) (raise (value VAL))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (★ insts)
|
|
|
|
(define (★ insts [final-key 'mul-count])
|
|
|
|
(for/fold ([offset 0]
|
|
|
|
(for/fold ([offset 0]
|
|
|
|
#:result (hash-ref regs 'mul-count))
|
|
|
|
#:result (hash-ref regs final-key))
|
|
|
|
([i (in-naturals)]
|
|
|
|
([i (in-naturals)]
|
|
|
|
#:break (not (<= 0 offset (sub1 (vector-length insts)))))
|
|
|
|
#:break (not (<= 0 offset (sub1 (vector-length insts)))))
|
|
|
|
(with-handlers ([offset-signal? (λ (os) (+ (offset-signal-val os) offset))])
|
|
|
|
(with-handlers ([integer? (λ (num) (+ num offset))])
|
|
|
|
(define proc (vector-ref insts offset))
|
|
|
|
(define inst (vector-ref insts offset))
|
|
|
|
(proc)
|
|
|
|
(inst)
|
|
|
|
(add1 offset))))
|
|
|
|
(add1 offset))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (★★ insts)
|
|
|
|
|
|
|
|
(hash-set! regs 'a 1)
|
|
|
|
|
|
|
|
(★ insts 'h))
|