3imp 読んでみる (12)

ええと、test なインストラクションは

	       [test (then else)
		     (VM a (if a then else) e r s)]

となるので、accumulator には条件式が格納されてりゃ良いのか、と浅はかな類推。
でも compile 側では

		 [if (test then else)
		     (let ([thenc (compile then next)]
			   [elsec (compile else next)])
		       (compile test (list 'test thenc elsec)))]

なソレなんだよねぇ。test は基本的に手続き適用なんだよなぁ。あらら、extend って手続きがあるな。SICP と同じ方式でナニしてみる??

(define primitive-proc
  (list (list '= =)
	(list 'car car)
	(list 'cdr cdr)
	))
(define primitive-procedure-names
  (map car primitive-proc))
(define primitive-procedure-objs
  (map cadr primitive-proc))
(define (init-env)
  (extend '() primitive-procedure-names primitive-procedure-objs))

を盛り込んで云々。で、以下な試験を書いてみたけど駄目。

(test* "(VM '() (compile '(if (= 1 1) 0 1) '(halt)) (init-env) '() '())"
       0
       (VM '() (compile '(if (= 1 1) 0 1) '(halt)) (init-env) '() '()))
discrepancies found.  Errors are:
test (VM '() (compile '(if (= 1 1) 0 1) '(halt)) (init-env) '() '()): 
  expects 0 => 
  got #<error "improper list not allowed: #<subr =>">

うーん。ちょっとドロ沼。primitive なソレ、が鍵??

どうやって primitive なナニを盛り込むか

宿題、とゆーコトで。(を