Other implementation of vm?
This commit is contained in:
35
scmvm/vm2.scm
Normal file
35
scmvm/vm2.scm
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
(define-module (scmvm vm2)
|
||||||
|
#:use-module (ice-9 hash-table)
|
||||||
|
#:export (define-instruction-set
|
||||||
|
instruction-lookup
|
||||||
|
instruction-name
|
||||||
|
instruction-code
|
||||||
|
register-set))
|
||||||
|
|
||||||
|
;;; Instructions
|
||||||
|
(define-syntax define-instruction-set
|
||||||
|
(syntax-rules (define-instruction)
|
||||||
|
[(_ (set-name reg ...) (define-instruction (name opcode) impl ...) ...)
|
||||||
|
(define (set-name dispatch)
|
||||||
|
(case dispatch
|
||||||
|
[(lookup)
|
||||||
|
(lambda (lookup)
|
||||||
|
(case lookup
|
||||||
|
[(name) '(name opcode)] ...
|
||||||
|
[else #f]))]
|
||||||
|
[(call)
|
||||||
|
(lambda (registers)
|
||||||
|
(let ([reg (assq-ref registers 'reg)] ...)
|
||||||
|
(parameterize ([reg #f] ...)
|
||||||
|
(lambda (op)
|
||||||
|
(case op
|
||||||
|
[(opcode) impl ...] ...)))))]))]))
|
||||||
|
|
||||||
|
(define (instruction-lookup isa name)
|
||||||
|
((isa 'lookup) name))
|
||||||
|
|
||||||
|
(define instruction-name car)
|
||||||
|
(define instruction-code cadr)
|
||||||
|
|
||||||
|
(define (register-set names)
|
||||||
|
(alist->hash-table (map (lambda (n) (cons n (make-parameter #f))) names)))
|
||||||
Reference in New Issue
Block a user