; Build an initial alist with the environment component preloaded with the ; built-in atomic types and datatype operations. Note the convention of ; tagging environment bindings using a distinguished last element. ; Specifically, the following tags are used: type, var, fun, and bfun, where ; bfun designates a built-in (as opposed to xdefun'd function). Note further ; that the body of a built-in function is not a list of sexprs as for an ; xdefun, but two atoms of the form check-X and eval-X that are the names of ; the functions that type check and evaluate the built-in. ; ; The tagging convention is better than relying solely on the length of a ; binding to determine what kind of binding it is. In particular, with the ; addition of type bindings to the environment, without tagging it would not be ; possible to distinguish a two-element var binding from a two-element type ; binding. Even though this is not an issue in our test data, tagging is a ; cleaner solution in general. ; (defun preload-built-ins () '( ((type-check-lev top-level nil) ;preloaded type checking level (a global envir var); ;value is pair of the form ; (fun-name or "top-level", expr num or nil if "top-level") ) ( ;preloaded environment (sym sym type) (int int type) (real real type) (string string type) (bool bool type) (index ((a (array ?x ?y)) (i int)) ((?y)) check-index eval-index bfun) (setelem ((a (array ?x ?y)) (i int) (val ?z)) ((array ?x ?y)) check-setelem eval-setelem bfun) (dot ((r (record ?x)) (f sym)) ((?y)) (suchthat (field-type-of ?y (record ?x))) check-dot eval-dot bfun) (setfield ((r (record ?x)) (f sym) (val ?y)) ((record ?x)) check-setfield eval-setfield bfun) (isa ((u (union ?x)) (f sym)) ((bool)) check-isa eval-isa bfun) (dot ((u (union ?x)) (f sym)) ((?y)) check-dot eval-dot bfun) (typeof ((x ?x)) ((t ?t)) check-typeof eval-typeof bfun) (equiv ((t1 ?t1) (t2 ?t2)) ((bool)) equiv bfun) ) () ;empty stack store ) ) ; If you can figure out how to use the following two functions, you can ; eliminate the check-X and eval-X elements in the bfun bindings. If you can't ; figure out how to use these functions, fuhgedaboutit. (defun make-check-name (raw-fun-name) (read (make-string-input-stream (concatenate 'string "check-" (symbol-name raw-fun-name))))) (defun make-eval-name (raw-fun-name) (read (make-string-input-stream (concatenate 'string "eval-" (symbol-name raw-fun-name)))))