Advertisement
Guest User

Untitled

a guest
Mar 29th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 2.15 KB | None | 0 0
  1.  
  2. (define (JMP stack-machine target)
  3.   (run-stack-machine (make-stack-machine (get-stack stack-machine)
  4.                                          (get-varnames stack-machine)
  5.                                          (get-consts stack-machine)
  6.                                          (get-names stack-machine)
  7.                                          (get-code stack-machine)
  8.                                          (quotient target 2))))
  9.  
  10.  
  11. (define cmpcodes (list < <= eq? (compose not eq?) > >= member (compose not member)))
  12.  
  13. (define (CMP stack-machine i)
  14.   (let ((TOS (top (get-stack stack-machine)))
  15.         (TOS1 (top (pop (get-stack stack-machine)))))
  16.     (let ((f (car (drop cmpcodes i))))
  17.       (let ((res (f TOS1 TOS)))      
  18.         (run-stack-machine (make-stack-machine (push res (cddr (get-stack stack-machine)))
  19.                                                (get-varnames stack-machine)
  20.                                                (get-consts stack-machine)
  21.                                                (get-names stack-machine)
  22.                                                (get-code stack-machine)
  23.                                                (add1 (get-IC stack-machine))))))))
  24.  
  25. (define (IF_JMP stack-machine target bool)
  26.   (if (eq? bool (top (get-stack stack-machine)))
  27.       (run-stack-machine (make-stack-machine (pop(get-stack stack-machine))
  28.                                              (get-varnames stack-machine)
  29.                                              (get-consts stack-machine)
  30.                                              (get-names stack-machine)
  31.                                              (get-code stack-machine)
  32.                                              (quotient target 2)))
  33.       (run-stack-machine (make-stack-machine (pop(get-stack stack-machine))
  34.                                              (get-varnames stack-machine)
  35.                                              (get-consts stack-machine)
  36.                                              (get-names stack-machine)
  37.                                              (get-code stack-machine)
  38.                                              (add1 (get-IC stack-machine))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement