UNB/ CS/ David Bremner/ teaching/ cs4613/ lectures/ lecture11/ numtags.rkt
#lang plait
(require (typed-in racket/base
                   [quotient : (Number Number -> Number)]))

(define NUMBER-TAG 2) ; 10 binary
(define STRING-TAG 1) ; 01 binary

(define (ref->tag ref)
  (modulo ref 4))

(define (ref->word loc)
  (quotient loc 4))

(define (tag-word word tag)
  (+ tag (* 4 word)))

(let ([str-ref (tag-word 0 STRING-TAG)]
      [num-ref (tag-word 7 NUMBER-TAG)])
  (begin
    (test (ref->tag str-ref) STRING-TAG)
    (test (ref->word str-ref) 0)
    (test (ref->tag num-ref) NUMBER-TAG)
    (test (ref->word num-ref) 7)))