Add the tiger source code bundle from the book site

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2024-12-18 15:18:45 -08:00
parent 915660c8a7
commit 33d8bac511
87 changed files with 3252 additions and 0 deletions

43
tiger/chap4/symbol.sml Normal file
View file

@ -0,0 +1,43 @@
signature SYMBOL =
sig
eqtype symbol
val symbol : string -> symbol
val name : symbol -> string
type 'a table
val empty : 'a table
val enter : 'a table * symbol * 'a -> 'a table
val look : 'a table * symbol -> 'a option
end
structure Symbol :> SYMBOL =
struct
type symbol = string * int
structure H = HashTable
exception Symbol
val nextsym = ref 0
val sizeHint = 128
val hashtable : (string,int) H.hash_table =
H.mkTable(HashString.hashString, op = ) (sizeHint,Symbol)
fun symbol name =
case H.find hashtable name
of SOME i => (name,i)
| NONE => let val i = !nextsym
in nextsym := i+1;
H.insert hashtable (name,i);
(name,i)
end
fun name(s,n) = s
structure Table = IntMapTable(type key = symbol
fun getInt(s,n) = n)
type 'a table= 'a Table.table
val empty = Table.empty
val enter = Table.enter
val look = Table.look
end