Selaa lähdekoodia

deal with `decode_type` somehow

Simon Krajewski 5 vuotta sitten
vanhempi
commit
603679bb09
5 muutettua tiedostoa jossa 11 lisäystä ja 2 poistoa
  1. 1 0
      src/context/common.ml
  2. 1 0
      src/core/tType.ml
  3. 3 1
      src/macro/macroApi.ml
  4. 3 0
      src/typing/macroContext.ml
  5. 3 1
      src/typing/typer.ml

+ 1 - 0
src/context/common.ml

@@ -690,6 +690,7 @@ let create version s_version args =
 			tnull = (fun _ -> die "" __LOC__);
 			tstring = m;
 			tarray = (fun _ -> die "" __LOC__);
+			tdynamic = (fun _ -> die "" __LOC__);
 		};
 		file_lookup_cache = Hashtbl.create 0;
 		file_keys = new file_keys;

+ 1 - 0
src/core/tType.ml

@@ -373,6 +373,7 @@ type basic_types = {
 	mutable tnull : t -> t;
 	mutable tstring : t;
 	mutable tarray : t -> t;
+	mutable tdynamic : t -> t;
 }
 
 type class_field_scope =

+ 3 - 1
src/macro/macroApi.ml

@@ -148,6 +148,8 @@ module type InterpApi = sig
 	val handle_decoding_error : (string -> unit) -> value -> Type.t -> (string * int) list
 
 	val get_api_call_pos : unit -> pos
+
+	val make_dynamic : (Type.t -> Type.t) ref
 end
 
 let enum_name = function
@@ -1120,7 +1122,7 @@ and decode_type t =
 	| 3, [t; pl] -> TType (decode_ref t, List.map decode_type (decode_array pl))
 	| 4, [pl; r] -> TFun (List.map (fun p -> decode_string (field p "name"), decode_bool (field p "opt"), decode_type (field p "t")) (decode_array pl), decode_type r)
 	| 5, [a] -> TAnon (decode_ref a)
-	| 6, [t] -> t_dynamic (* DYNAMICTODO *)
+	| 6, [t] -> if t == vnull then t_dynamic else (!make_dynamic) (decode_type t)
 	| 7, [f] -> TLazy (decode_lazytype f)
 	| 8, [a; pl] -> TAbstract (decode_ref a, List.map decode_type (decode_array pl))
 	| _ -> raise Invalid_expr

+ 3 - 0
src/typing/macroContext.ml

@@ -31,6 +31,8 @@ module Eval = struct
 	include EvalValue
 	include EvalContext
 	include EvalMain
+
+	let make_dynamic = ref (fun _ -> die "" __LOC__)
 end
 
 module InterpImpl = Eval (* Hlmacro *)
@@ -139,6 +141,7 @@ let make_macro_api ctx p =
 		with _ ->
 			error "Malformed metadata string" p
 	in
+	Eval.make_dynamic := ctx.com.basic.tdynamic;
 	{
 		MacroApi.pos = p;
 		MacroApi.get_com = (fun() -> ctx.com);

+ 3 - 1
src/typing/typer.ml

@@ -2749,7 +2749,9 @@ let rec create com =
 			| "Float" -> ctx.t.tfloat <- TAbstract (a,[]);
 			| "Int" -> ctx.t.tint <- TAbstract (a,[])
 			| "Bool" -> ctx.t.tbool <- TAbstract (a,[])
-			| "Dynamic" -> t_dynamic_def := TAbstract(a,List.map snd a.a_params);
+			| "Dynamic" ->
+				t_dynamic_def := TAbstract(a,List.map snd a.a_params);
+				ctx.t.tdynamic <- (fun t -> TAbstract(a,[t]))
 			| "Null" ->
 				let mk_null t =
 					try