(define retval 0) ; a global register
(define (return x) (set! retval x))
(define (return-from-procedure) '())
(define call
  (lambda (fn . args)
    (apply fn args)))

(define (getchar)
  (let
    ((ch (read-char)))
    (if (eof-object? ch)
      -1
      (char->integer ch))))
(define (putchar ch)
  (if (number? ch)
    (display (integer->char ch))
    (write-char ch)))

(define (shl a b)
  (arithmetic-shift a b))
(define (shr a b)
  (arithmetic-shift a (- b)))
(define (!= a b)
  (! (= a b)))

(define (n->bool n)
  (if (number? n)
    (if (zero? n)
      #f
      #t)
    n)) ; assume its a bool

(define (bool->n b)
  (if (boolean? b)
    (if b
      1
      0)
    b)) ; assume its a num

(define cc 0) ; global register
(define (not-condition-code cc)
  (= cc 0))
    
(define (! n)
  (bool->n (not (n->bool n))))
(define (&& a b)
  (bool->n (and (n->bool a) (n->bool b))))
(define (|| a b)
  (bool->n (or (n->bool a) (n->bool b))))
(define (__test n)
  (n->bool n))
(define (___test n)
  (bool->n n))

(define branch-table
  (lambda (n . args)
    (apply (list-ref args n) '())))


