Commits

Anonymous committed 9517cdb

Crashing on identifier lookup failure is a little too harsh. Resolve issue #2.

Comments (0)

Files changed (1)

 open Blub_types
 open Blub_environment
 
+exception Var_not_found of variable * environment
+
+
 module Vm = struct
   open Format
 
       | B_ref ((var, Gbinding idx), next) ->
 	  let r = globals.vals.(idx) in
 	  if (r = Sunbound) then begin
-	    printf "Lookup of global '%s' failed\n%!" var.var_uname;
-	    assert false
+	    raise (Var_not_found (var, env))
 	  end;
 	  eval r globals env rib stack next
       | B_ref ((var, Lbinding (f, idx)), next) ->
 	  let r = (List.nth env f).vals.(idx) in
 	  if (r = Sunbound) then begin
-	    printf "Lookup of local '%s' failed\n%!" var.var_uname;
-	    assert false
+	    raise (Var_not_found (var, env))
 	  end;
 	  eval r globals env rib stack next
       | B_set ((_, Gbinding idx), next) ->
 	    
   ;;
   let topeval globals code = 
-    eval Sunbound globals [] [||] [] code
-
+    try
+      eval Sunbound globals [] [||] [] code
+    with
+	Var_not_found (var, env) ->
+	  printf "Variable@ %a@ not found@ in environment@ %a@\n%!"
+	    pp_var var pp_env env;
+	  Sunbound
+  ;;
 
 end