Commits

Anonymous committed d2ec15c

stdlib

  • Participants
  • Parent commits bdc92b0

Comments (0)

Files changed (1)

File stdlib.ml

-open Util
-open Parser
-
-let top_level_class_name = "__TopLevelClass"
-
-type context = (string * obj) list
-and state = [ Parser.st | `External of (context -> unit) ]
-and obj = { name: string; fields: (string * (string list * state list)) list }
-
-let null_obj = { name="Null"; fields = [] }
-let string_obj s = { name="String"; fields = [ ]}
-let int_obj i = { name="Int"; fields = []}
-let bool_obj b = { name="Bool"; fields = []}
-let todo_obj = { name="TODO"; fields = []}
-
-let show obj = obj.name
-
-
-       
-let get_value ctx vname =
-  try List.assoc vname ctx with
-  | Not_found -> failwith @@ "get_value: notfound: " ^ vname
-
-let set_ctx ctx vname obj =
-  (vname, obj) :: (List.remove_assoc vname ctx)
-
-let init_ctx =
-    [ (top_level_class_name,
-       { name="";
-	 fields=[
-	 ("puts", (["x"], [
-		   `External (fun ctx -> p "%s\n" (show @@ get_value ctx "x"))
-		 ])) ] }) ]
-
-
-let add_field cls (fname, argnames, fbody) =
-  { cls with fields = (fname, (argnames, fbody)) ::cls.fields }
-
-let add_class_method ctx class_name f =
-  let cls = List.assoc class_name ctx in
-  set_ctx ctx class_name (add_field cls f)
-
-let add_function ctx f =
-  add_class_method ctx top_level_class_name f
-