From 44eb66637fbd9c298fdd0947746d821c7d83d25c Mon Sep 17 00:00:00 2001 From: Thomas Wood <thomas.wood09@imperial.ac.uk> Date: Tue, 15 Sep 2015 15:56:04 +0100 Subject: [PATCH] Add list datatype into generator type table. --- generator/js_of_ast.ml | 9 ++++++++- generator/stdlib_ml/stdlib.mli | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml index 7bf7f95..4e823e2 100644 --- a/generator/js_of_ast.ml +++ b/generator/js_of_ast.ml @@ -14,13 +14,20 @@ open Types open Typedtree let hashtbl_size = 256 + +(* val type_tbl : (string, string list * string list) Hashtbl.t + * Mapping constructor names to a pair of module list and constructor names list *) let type_tbl = Hashtbl.create hashtbl_size +(* Hard-code the special-syntax of the list datatype *) +let _ = Hashtbl.add type_tbl "[]" ([], []) +let _ = Hashtbl.add type_tbl "::" ([], ["head"; "tail"]) + let record_tbl = Hashtbl.create hashtbl_size let module_list = ref [] let module_code = ref [] let module_created = ref [] module L = Logged (Token_generator) (struct let size = 256 end) - + (** * Debug-purpose functions *) diff --git a/generator/stdlib_ml/stdlib.mli b/generator/stdlib_ml/stdlib.mli index 232b07f..d85d152 100644 --- a/generator/stdlib_ml/stdlib.mli +++ b/generator/stdlib_ml/stdlib.mli @@ -1,3 +1,9 @@ +(* Following type definition for lists hardcoded into OCaml/generator: +type 'a list = +| [] +| :: [@f head, tail] of 'a * 'a list +*) + val add : 'a -> 'b -> 'c val ( + ) : 'a -> 'b -> 'c val sub : 'a -> 'a -> 'a -- GitLab