Просмотр исходного кода

[eval] remove hlmacro leftovers

Simon Krajewski 7 лет назад
Родитель
Сommit
49cea34fb1

+ 0 - 4
src/compiler/main.ml

@@ -951,10 +951,6 @@ with
 		end
 	| Error.Error (m,p) ->
 		error ctx (Error.error_msg m) p
-	| Hlmacro.Error (msg,p :: l) ->
-		message ctx (CMError(msg,p));
-		List.iter (fun p -> message ctx (CMError("Called from",p))) l;
-		error ctx "Aborted" null_pos;
 	| Generic.Generic_Exception(m,p) ->
 		error ctx m p
 	| Arg.Bad msg ->

+ 1 - 1
src/macro/eval/evalDebugMisc.ml

@@ -223,7 +223,7 @@ let rec expr_to_value ctx env e =
 			encode_array vl
 		| EObjectDecl fl ->
 			let fl = List.map (fun ((s,_,_),e) -> s,loop e) fl in
-			encode_obj_s None fl
+			encode_obj_s fl
 		| EBinop(op,e1,e2) ->
 			begin match op with
 			| OpAssign ->

+ 3 - 3
src/macro/eval/evalEncode.ml

@@ -113,7 +113,7 @@ let vfun5 f = vstatic_function (fun vl -> match vl with
 
 (* Objects *)
 
-let encode_obj _ l =
+let encode_obj l =
 	let ctx = get_ctx() in
 	let proto,sorted = ctx.get_object_prototype ctx l in
 	vobject {
@@ -121,8 +121,8 @@ let encode_obj _ l =
 		oproto = proto;
 	}
 
-let encode_obj_s k l =
-	encode_obj k (List.map (fun (s,v) -> (hash s),v) l)
+let encode_obj_s l =
+	encode_obj (List.map (fun (s,v) -> (hash s),v) l)
 
 (* Enum values *)
 

+ 1 - 1
src/macro/eval/evalPrototype.ml

@@ -239,7 +239,7 @@ let create_static_prototype ctx mt =
 			let key = hash s in
 			let v2 = EvalField.field v key in
 			let v2 = match v2 with
-				| VNull -> encode_obj None []
+				| VNull -> encode_obj []
 				| _ -> v2
 			in
 			set_field v key v2;

+ 12 - 12
src/macro/eval/evalStdLib.ml

@@ -136,7 +136,7 @@ module StdArray = struct
 	let iterator = vifun0 (fun vthis ->
 		let this = this vthis in
 		let f_has_next,f_next = EvalArray.iterator this in
-		encode_obj None [
+		encode_obj [
 			key_hasNext,vifun0 (fun _ -> vbool (f_has_next()));
 			key_next,vifun0 (fun _ -> f_next())
 		]
@@ -581,7 +581,7 @@ module StdCompress = struct
 		let dst = decode_bytes dst in
 		let dstPos = decode_int dstPos in
 		let r = try f this.z (Bytes.unsafe_to_string src) srcPos (Bytes.length src - srcPos) dst dstPos (Bytes.length dst - dstPos) this.z_flush with _ -> exc_string "oops" in
-		encode_obj None [
+		encode_obj [
 			key_done,vbool r.z_finish;
 			key_read,vint r.z_read;
 			key_write,vint r.z_wrote
@@ -654,7 +654,7 @@ module StdContext = struct
 			| None ->
 				vnull
 			| Some l ->
-				encode_obj_s None l
+				encode_obj_s l
 	)
 end
 
@@ -861,7 +861,7 @@ module StdEReg = struct
 		maybe_run this 0 (fun (first,last) ->
 			let first = byte_offset_to_char_offset_lol this.r_string first 0 0 in
 			let last = byte_offset_to_char_offset_lol this.r_string last 0 0 in
-			encode_obj None [key_pos,vint first;key_len,vint (last - first)]
+			encode_obj [key_pos,vint first;key_len,vint (last - first)]
 		)
 	)
 
@@ -1177,7 +1177,7 @@ module StdFileSystem = struct
 	let stat = vfun1 (fun path ->
 		let s = try Unix.stat (patch_path (decode_string path)) with Unix.Unix_error (_,cmd,msg) -> exc_string (cmd ^ " " ^ msg) in
 		let open Unix in
-		encode_obj None [
+		encode_obj [
 			key_gid,vint s.st_gid;
 			key_uid,vint s.st_uid;
 			key_atime,StdDate.encode_date s.st_atime;
@@ -1221,7 +1221,7 @@ module StdGc = struct
 	let key_stack_size = hash "stack_size"
 
 	let encode_stats stats =
-		encode_obj None [
+		encode_obj [
 			key_minor_words,vfloat stats.minor_words;
 			key_promoted_words,vfloat stats.promoted_words;
 			key_major_words,vfloat stats.major_words;
@@ -1246,7 +1246,7 @@ module StdGc = struct
 
 	let counters = vfun0 (fun () ->
 		let (minor_words,promoted_words,major_words) = Gc.counters() in
-		encode_obj None [
+		encode_obj [
 			key_minor_words,vfloat minor_words;
 			key_promoted_words,vfloat promoted_words;
 			key_major_words,vfloat major_words;
@@ -1270,7 +1270,7 @@ module StdGc = struct
 
 	let get = vfun0 (fun () ->
 		let control = Gc.get() in
-		encode_obj None [
+		encode_obj [
 			key_minor_heap_size,vint control.minor_heap_size;
 			key_major_heap_increment,vint control.major_heap_increment;
 			key_space_overhead,vint control.space_overhead;
@@ -1373,7 +1373,7 @@ end
 
 let encode_list_iterator l =
 	let l = ref l in
-	encode_obj None [
+	encode_obj [
 		key_hasNext,vifun0 (fun _ ->
 			match !l with [] -> vfalse | _ -> vtrue
 		);
@@ -1863,7 +1863,7 @@ module StdSocket = struct
 	let host = vifun0 (fun vthis ->
 		match getsockname (this vthis) with
 		| ADDR_INET (addr,port) ->
-			encode_obj None [
+			encode_obj [
 				key_ip,vint32 (inet_addr_to_int32 addr);
 				key_port,vint port;
 			]
@@ -1880,7 +1880,7 @@ module StdSocket = struct
 	let peer = vifun0 (fun vthis ->
 		match getpeername (this vthis) with
 		| ADDR_INET (addr,port) ->
-			encode_obj None [
+			encode_obj [
 				key_ip,vint32 (inet_addr_to_int32 addr);
 				key_port,vint port;
 			]
@@ -1921,7 +1921,7 @@ module StdSocket = struct
 		let read = List.map (fun sock -> List.assq sock read) read' in
 		let write = List.map (fun sock -> List.assq sock write) write' in
 		let others = List.map (fun sock -> List.assq sock others) others' in
-		encode_obj None [
+		encode_obj [
 			key_read,encode_array read;
 			key_write,encode_array write;
 			key_others,encode_array others;

+ 0 - 557
src/macro/hlmacro.ml

@@ -1,557 +0,0 @@
-(*
-	The Haxe Compiler
-	Copyright (C) 2005-2018  Haxe Foundation
-
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
-
-	This program is distributed in the hope that it will be useful,
-	but WITHOUT ANY WARRANTY; without even the implied warranty of
-	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-	GNU General Public License for more details.
-
-	You should have received a copy of the GNU General Public License
-	along with this program; if not, write to the Free Software
-	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *)
-open Globals
-open Type
-open Ast
-open Hlcode
-open Hlinterp
-open MacroApi
-
-type value = Hlinterp.value
-
-type context = {
-	com : Common.context; (* macro one *)
-	mutable gen : Genhl.context option;
-	interp : Hlinterp.context;
-	types : (Globals.path,int) Hashtbl.t;
-	cached_protos : (obj_type, (virtual_proto * vfield array)) Hashtbl.t;
-	cached_enums : (enum_type, ttype) Hashtbl.t;
-	mutable curapi : value MacroApi.compiler_api;
-	mutable has_error : bool;
-}
-
-exception Error of string * Globals.pos list
-
-let debug = true (* TODO !!! set to false for speed++ ! *)
-
-let get_ctx_ref = ref (fun() -> assert false)
-let get_ctx() : context = (!get_ctx_ref)()
-let macro_lib = Hashtbl.create 0
-let interp() = (get_ctx()).interp
-
-let setup get_api =
-	let api = get_api (fun() -> (get_ctx()).curapi.get_com()) (fun() -> (get_ctx()).curapi) in
-	List.iter (fun (n,v) -> Hashtbl.replace macro_lib n (match v with VClosure (FNativeFun (_,v,_),None) -> v | _ -> assert false)) api;
-	Globals.macro_platform := Globals.Hl
-
-let select ctx =
-	get_ctx_ref := (fun() -> ctx)
-
-let error_handler ctx v stack =
-	let make_pos st =
-		let file, line = Hlinterp.make_stack ctx.interp st in
-		let low = line land 0xFFFFF in
-		{
-			Globals.pfile = file;
-			Globals.pmin = low;
-			Globals.pmax = low + (line lsr 20);
-		}
-	in
-	(*let rec loop o =
-		if o == ctx.error_proto then true else match o.oproto with None -> false | Some p -> loop p
-	in
-	(match v with
-	| VObject o when loop o ->
-		(match get_field o (hash "message"), get_field o (hash "pos") with
-		| VObject msg, VAbstract (APos pos) ->
-			(match get_field msg h_s with
-			| VString msg -> raise (Error.Error (Error.Custom msg,pos))
-			| _ -> ());
-		| _ -> ());
-	| _ -> ());*)
-	raise (Error (Hlinterp.vstr ctx.interp v Hlcode.HDyn,List.map make_pos stack))
-
-let create com api _ =
-	let ctx = {
-		com = com;
-		gen = None;
-		interp = Hlinterp.create debug;
-		curapi = api;
-		types = Hashtbl.create 0;
-		has_error = false;
-		cached_protos = Hashtbl.create 0;
-		cached_enums = Hashtbl.create 0;
-	} in
-	select ctx;
-	Hlinterp.set_error_handler ctx.interp (error_handler ctx);
-	Hlinterp.set_macro_api ctx.interp (fun name -> try Some (Hashtbl.find macro_lib name) with Not_found -> None);
-	ctx
-
-let init ctx =
-	if ctx.gen = None then ctx.gen <- Some (Genhl.create_context ctx.com true false)
-
-let set_error ctx e =
-	ctx.has_error <- e
-
-let add_types ctx types ready =
-	let types = List.filter (fun t -> match t with
-		| TAbstractDecl a when not (Meta.has Meta.CoreType a.a_meta) ->
-			(* A @:native on an abstract causes the implementation class and the abstract
-			   to have the same path. Let's skip all abstracts so this doesn't matter. *)
-			false
-		| _ ->
-			let path = Type.t_path t in
-			if Hashtbl.mem ctx.types path then false else begin
-				Hashtbl.add ctx.types path (Type.t_infos t).mt_module.m_id;
-				true;
-			end
-	) types in
-	List.iter ready types;
-	if ctx.gen = None then init ctx;
-	match ctx.gen with
-	| None -> assert false
-	| Some gen ->
-		Genhl.add_types gen types;
-		if debug then Genhl.check gen;
-		let code = Genhl.build_code gen types None in
-		if debug then begin
-			try
-				Hlinterp.check code true
-			with Failure _ | Common.Abort _ as exn ->
-				let ch = open_out_bin "hlcode.txt" in
-				Hlcode.dump (fun s -> output_string ch (s ^ "\n")) code;
-				close_out ch;
-				raise exn
-		end;
-		Hlinterp.add_code ctx.interp code
-
-let do_reuse ctx api =
-	ctx.curapi <- api
-
-let can_reuse ctx types =
-	let has_old_version t =
-		let inf = Type.t_infos t in
-		try
-			Hashtbl.find ctx.types inf.mt_path <> inf.mt_module.m_id
-		with Not_found ->
-			false
-	in
-	not (List.exists has_old_version types)
-
-let catch_errors ctx ?(final=(fun() -> ())) f =
-	let prev = get_ctx() in (* switch context in case we have an older one, see #5676 *)
-	select ctx;
-	try
-		let v = f() in
-		final();
-		select prev;
-		Some v
-	with Error _ as e ->
-		final();
-		select prev;
-		raise e
-	|  Abort ->
-		final();
-		select prev;
-		None
-
-let call_path ctx cpath (f:string) args api =
-	if ctx.has_error then
-		None
-	else let old = ctx.curapi in
-	ctx.curapi <- api;
-	let gid = Genhl.resolve_class_global (match ctx.gen with None -> assert false | Some ctx -> ctx) (String.concat "." cpath) in
-	let gval = ctx.interp.Hlinterp.t_globals.(gid) in
-	let fval = Hlinterp.dyn_get_field ctx.interp gval f Hlcode.HDyn in
-	match fval with
-	| Hlinterp.VClosure (f,None) ->
-		catch_errors ~final:(fun() -> ctx.curapi <- old) ctx (fun() -> call_wrap ctx.interp f args)
-	| _ ->
-		prerr_endline (Hlinterp.vstr_d ctx.interp gval);
-		assert false
-
-let vnull = VNull
-let vbool b = VBool b
-let vint i = VInt (Int32.of_int i)
-let vint32 i = VInt i
-let vfloat f = VFloat f
-
-let vfun0 f =
-	let callb args = match args with [] -> f() | _ -> assert false in
-	VClosure(FNativeFun ("fun0",callb,HVoid), None)
-
-let vfun1 f =
-	let callb args = match args with [a] -> f a | _ -> assert false in
-	VClosure(FNativeFun ("fun1",callb,HVoid), None)
-
-let vfun2 f =
-	let callb args = match args with [a;b] -> f a b | _ -> assert false in
-	VClosure(FNativeFun ("fun2",callb,HVoid), None)
-
-let vfun3 f =
-	let callb args = match args with [a;b;c] -> f a b c | _ -> assert false in
-	VClosure(FNativeFun ("fun3",callb,HVoid), None)
-
-let vfun4 f =
-	let callb args = match args with [a;b;c;d] -> f a b c d | _ -> assert false in
-	VClosure(FNativeFun ("fun4",callb,HVoid), None)
-
-let vfun5 f =
-	let callb args = match args with [a;b;c;d;e] -> f a b c d e | _ -> assert false in
-	VClosure(FNativeFun ("fun5",callb,HVoid), None)
-
-let exc_string msg =
-	Hlinterp.throw_msg (interp()) msg
-
-let compiler_error msg pos =
-	assert false (* TODO : raise haxe.macro.Error(msg,pos) *)
-
-let eval_expr ctx (e:texpr) =
-	assert false
-
-let eval_delayed _ _ =
-	assert false (* macro - in - macro *)
-
-let prepare_callback f n =
-	assert false
-
-let encode_pos p = VAbstract (APos p)
-
-let decode_pos = function
-	| VAbstract (APos p) -> p
-	| _ -> raise Invalid_expr
-
-let last_enum_type = ref IExpr
-
-let encode_enum t pos tag pl =
-	last_enum_type := t;
-	assert false (* todo : list enum prototypes *)
-	(*
-	match pos with
-	| None -> VEnum (tag,Array.of_list pl)
-	| Some p -> VEnum (tag,Array.of_list (List.rev (encode_pos p :: List.rev pl)))
-	*)
-
-let decode_enum = function
-	| VEnum (_,tag,arr) -> tag, Array.to_list arr
-	| _ -> raise Invalid_expr
-
-let decode_enum_with_pos = function
-	| VEnum (_,tag,arr) when Array.length arr > 0 && (match arr.(Array.length arr - 1) with VAbstract (APos _) -> true | _ -> false) ->
-		let rec loop i =
-			if i = Array.length arr - 1 then [] else arr.(i) :: loop (i + 1)
-		in
-		(tag, loop 0), decode_pos arr.(Array.length arr - 1)
-	| e ->
-		decode_enum e, Globals.null_pos
-
-
-let encode_tdecl t = VAbstract (ATDecl t)
-let encode_unsafe o = VAbstract (AUnsafe o)
-
-let decode_unsafe = function
-	| VAbstract (AUnsafe v) -> v
-	| _ -> raise Invalid_expr
-
-let decode_tdecl = function
-	| VAbstract (ATDecl t) -> t
-	| _ -> raise Invalid_expr
-
-let decode_int = function
-	| VInt i -> Int32.to_int i
-	| _ -> raise Invalid_expr
-
-let decode_i32 = function
-	| VInt i -> i
-	| _ -> raise Invalid_expr
-
-let decode_bool = function
-	| VBool b -> b
-	| _ -> raise Invalid_expr
-
-let field o n =
-	match o with
-	| VDynObj _ | VVirtual _ | VObj _ -> Hlinterp.dyn_get_field (interp()) o n HDyn
-	| _ -> raise Invalid_expr
-
-let decode_string = function
-	| VObj { ofields = [|VBytes s;VInt _|] } -> Hlinterp.hl_to_caml s
-	| _ -> raise Invalid_expr
-
-let decode_array = function
-	| VObj { ofields = [|VInt len;VArray (arr,_)|] } ->
-		let len = Int32.to_int len in
-		let rec loop i =
-			if i = len then [] else arr.(i) :: loop (i+1)
-		in
-		loop 0
-	| v ->
-		raise Invalid_expr
-
-let encode_lazytype f t = VAbstract (ALazyType (f,t))
-
-let decode_lazytype = function
-	| VAbstract (ALazyType (t,_)) -> t
-	| _ -> raise Invalid_expr
-
-let encode_obj t fields =
-	match t with
-	| OMetaAccess ->
-		let h = Hashtbl.create 0 in
-		let rec loop i = function
-			| [] -> ()
-			| (n,_) :: l ->
-				Hashtbl.add h n i;
-				loop (i + 1) l
-		in
-		loop 0 fields;
-		let values = Array.of_list (List.map snd fields) in
-		VDynObj {
-			dfields = h;
-			dvalues = values;
-			dtypes = Array.make (Array.length values) HDyn;
-			dvirtuals = [];
-		}
-	| _ ->
-	let ctx = get_ctx() in
-	let to_str (name,f) =
-		match f with
-		| None -> name
-		| Some f -> name ^ "." ^ f
-	in
-	let vp, idx = try
-		Hashtbl.find ctx.cached_protos t
-	with Not_found ->
-		let name, field = proto_name t in
-		let gen = (match ctx.gen with None -> assert false | Some gen -> gen) in
-		let vt = (try
-			let t = Hashtbl.find gen.Genhl.macro_typedefs name in
-			(match t, field with
-			| _, None -> t
-			| HVirtual v, Some f ->
-				let idx = (try PMap.find f v.vindex with Not_found -> failwith (name ^ " has no field definition " ^ f)) in
-				let _,_, t = v.vfields.(idx) in
-				(match t with
-				| HVirtual _ -> t
-				| _ -> failwith ("Unexpected type " ^ tstr t ^ " for definition " ^ to_str (name,field)))
-			| _ ->
-				assert false
-			)
-		with Not_found -> try
-			let t = PMap.find (["haxe";"macro"],name) gen.Genhl.cached_types in
-			(match t, field with
-			| HEnum e, Some f ->
-				let rec loop i =
-					if i = Array.length e.efields then raise Not_found;
-					let n, _, tl = e.efields.(i) in
-					if n = f then
-						tl.(0)
-					else
-						loop (i + 1)
-				in
-				loop 0
-			| _ ->
-				failwith ("Unexpected type " ^ tstr t ^ " for definition " ^ to_str (name,field)))
-		with Not_found ->
-			failwith ("Macro definition missing " ^ to_str (name,field))
-		) in
-		match vt with
-		| HVirtual vp ->
-			let vindexes = Array.map (fun (n,_,_) ->
-				let rec loop i = function
-					| [] -> VFNone
-					| (n2,_) :: _ when n = n2 -> VFIndex i
-					| _ :: l -> loop (i + 1) l
-				in
-				loop 0 fields
-			) vp.vfields in
-			Hashtbl.replace ctx.cached_protos t (vp, vindexes);
-			vp, vindexes
-		| _ ->
-			failwith (to_str (name,field) ^ " returned invalid type " ^ tstr vt)
-	in
-	if debug then begin
-		let farr = Array.of_list fields in
-		Array.iteri (fun i idx ->
-			let name, _ ,_ = vp.vfields.(i) in
-			match idx with
-			| VFNone ->
-				if List.mem_assoc name fields then failwith ("Field " ^ name ^ " is present in "  ^ to_str (proto_name t))
-			| VFIndex i when i >= Array.length farr ->
-				failwith ("Missing field " ^ name ^ " of "  ^ to_str (proto_name t))
-			| VFIndex i when fst farr.(i) <> name ->
-				failwith ("Field " ^ name ^ " of "  ^ to_str (proto_name t) ^ " is wrongly mapped on " ^ fst farr.(i))
-			| _ ->
-				()
-		) idx;
-		List.iter (fun (n,_) ->
-			if n <> "name_pos" && not (PMap.mem n vp.vindex) then failwith ("Field " ^ n ^ " has data but is not part of type " ^ to_str (proto_name t));
-		) fields;
-	end;
-	VVirtual {
-		vtype = vp;
-		vindexes = idx;
-		vtable = Array.map snd (Array.of_list fields);
-		vvalue = VNull;
-	}
-
-let encode_inst path fields =
-	let ctx = get_ctx() in
-	let t = (match ctx.gen with None -> assert false | Some gen -> try Genhl.resolve_type gen path with Not_found -> assert false) in
-	match t with
-	| HObj o ->
-		let proto, _, _ = Hlinterp.get_proto ctx.interp o in
-		VObj { oproto = proto; ofields = fields }
-	| _ ->
-		assert false
-
-let encode_string s =
-	encode_inst ([],"String") [|VBytes (caml_to_hl s);VInt (Int32.of_int (String.length s))|]
-
-let encode_array vl =
-	let arr = Array.of_list (List.map (fun v ->
-		match v with
-		| VNull | VObj _ | VVirtual _ -> v
-		| VEnum _ ->
-			let ctx = get_ctx() in
-			let et = !last_enum_type in
-			let t = try
-				Hashtbl.find ctx.cached_enums et
-			with Not_found ->
-				let name = enum_name et in
-				let t = (match ctx.gen with
-				| None -> assert false
-				| Some gen -> try PMap.find (["haxe";"macro"],name) gen.Genhl.cached_types with Not_found -> failwith ("Missing enum type " ^ name)
-				) in
-				Hashtbl.replace ctx.cached_enums et t;
-				t
-			in
-			VDyn (v,t)
-		| _ -> failwith "Invalid array value"
-	) vl) in
-	encode_inst (["hl";"types"],"ArrayObj") [|VInt (Int32.of_int (Array.length arr));VArray (arr,HDyn)|]
-
-let encode_bytes s =
-	encode_inst (["haxe";"io"],"Bytes") [|VInt (Int32.of_int (String.length s)); VBytes s|]
-
-let encode_string_map convert pmap =
-	let h = Hashtbl.create 0 in
-	PMap.iter (fun k v -> Hashtbl.add h k (convert v)) pmap;
-	encode_inst (["haxe";"ds"],"StringMap") [|VAbstract (AHashBytes h)|]
-
-let decode_bytes = function
-	| VObj { ofields = [|VInt _;VBytes s|] } -> s
-	| _ -> raise Invalid_expr
-
-let encode_ref v convert tostr =
-	let h = Hashtbl.create 0 in
-	Hashtbl.add h "get" 0;
-	Hashtbl.add h "__string" 1;
-	Hashtbl.add h "toString" 2;
-	Hashtbl.add h "$" 3;
-	VDynObj {
-		dfields = h;
-		dvalues = [|
-			vfun0 (fun() -> convert v);
-			vfun0 (fun() -> VBytes (caml_to_hl (tostr())));
-			vfun0 (fun() -> encode_string (tostr()));
-			VAbstract (AUnsafe (Obj.repr v))
-		|];
-		dtypes = [|
-			HFun ([],HDyn);
-			HFun ([],HBytes);
-			HFun ([],HDyn);
-			HDyn;
-		|];
-		dvirtuals = [];
-	}
-
-let decode_ref v : 'a =
-	match field v "$" with
-	| VAbstract (AUnsafe t) -> Obj.obj t
-	| _ -> raise Invalid_expr
-
-let value_string v =
-	Hlinterp.vstr (get_ctx()).interp v HDyn
-
-let value_signature v =
-	failwith "signature() not supported in HL macros"
-
-let value_to_expr v p =
-	let ctx = get_ctx() in
-	let error v = failwith ("Unsupported value " ^ vstr ctx.interp v Hlcode.HDyn) in
-	(*
-	let h_enum = hash "__enum__" and h_et = hash "__et__" and h_ct = hash "__ct__" in
-	let h_tag = hash "tag" and h_args = hash "args" in
-	let h_length = hash "length" in
-	let make_path t =
-		let rec loop = function
-			| [] -> assert false
-			| [name] -> (Ast.EConst (Ast.Ident name),p)
-			| name :: l -> (Ast.EField (loop l,name),p)
-		in
-		let t = t_infos t in
-		loop (List.rev (if t.mt_module.m_path = t.mt_path then fst t.mt_path @ [snd t.mt_path] else fst t.mt_module.m_path @ [snd t.mt_module.m_path;snd t.mt_path]))
-	in*)
-	let rec loop = function
-		| VNull -> (Ast.EConst (Ast.Ident "null"),p)
-		| VBool b -> (Ast.EConst (Ast.Ident (if b then "true" else "false")),p)
-		| VInt i -> (Ast.EConst (Ast.Int (Int32.to_string i)),p)
-		| VFloat f ->
-			let std = (Ast.EConst (Ast.Ident "std"), p) in
-			let math = (Ast.EField (std, "Math"), p) in
-			if (f = infinity) then
-				(Ast.EField (math, "POSITIVE_INFINITY"), p)
-			else if (f = neg_infinity) then
-				(Ast.EField (math, "NEGATIVE_INFINITY"), p)
-			else if (f <> f) then
-				(Ast.EField (math, "NaN"), p)
-			else
-				(Ast.EConst (Ast.Float (Numeric.float_repres f)), p)
-		| VAbstract (APos p) ->
-			(Ast.EObjectDecl (
-				(("fileName",Globals.null_pos,NoQuotes) , (Ast.EConst (Ast.String p.Globals.pfile) , p)) ::
-				(("lineNumber",Globals.null_pos,NoQuotes) , (Ast.EConst (Ast.Int (string_of_int (Lexer.get_error_line p))),p)) ::
-				(("className",Globals.null_pos,NoQuotes) , (Ast.EConst (Ast.String ("")),p)) ::
-				[]
-			), p)
-		| VObj { oproto = { pclass = { pname = "String" } }; ofields = [|VBytes content;VInt _|] } ->
-			(Ast.EConst (Ast.String (hl_to_caml content)),p)
-		| v ->
-			error v
-		(*
-		| VObject o as v ->
-			match o.oproto with
-			| None ->
-				(match get_field_opt o h_ct with
-				| Some (VAbstract (ATDecl t)) ->
-					make_path t
-				| _ ->
-					let fields = List.fold_left (fun acc (fid,v) -> ((field_name ctx fid,Globals.null_pos), loop v) :: acc) [] (Array.to_list o.ofields) in
-					(Ast.EObjectDecl fields, p))
-			| Some proto ->
-				match get_field_opt proto h_enum, get_field_opt o h_a, get_field_opt o h_s, get_field_opt o h_length with
-				| _, Some (VArray a), _, Some (VInt len) ->
-					(Ast.EArrayDecl (List.map loop (Array.to_list (Array.sub a 0 len))),p)
-				| Some (VObject en), _, _, _ ->
-					(match get_field en h_et, get_field o h_tag with
-					| VAbstract (ATDecl t), VString tag ->
-						let e = (Ast.EField (make_path t,tag),p) in
-						(match get_field_opt o h_args with
-						| Some (VArray args) ->
-							let args = List.map loop (Array.to_list args) in
-							(Ast.ECall (e,args),p)
-						| _ -> e)
-					| _ ->
-						error v)
-				| _ ->
-					error v
-			*)
-	in
-	loop v

+ 49 - 143
src/macro/macroApi.ml

@@ -80,55 +80,6 @@ type enum_type =
 	| IQuoteStatus
 	| IImportMode
 
-type obj_type =
-	(* make_const *)
-	| O__Const
-	(* Expr *)
-	| OImportExpr
-	| OImportExpr_path
-	| OTypePath
-	| OMetadataEntry
-	| OField
-	| OTypeParamDecl
-	| OFunction
-	| OFunctionArg
-	| OExprDef_fields
-	| OVar
-	| OCase
-	| OCatch
-	| OExpr
-	(* Type *)
-	| OMetaAccess
-	| OTypeParameter
-	| OClassType
-	| OAbstractType
-	| OAnonType
-	| ODefType
-	| OEnumType
-	| OClassField
-	| OAbstractType_binops
-	| OAbstractType_unops
-	| OAbstractType_from
-	| OAbstractType_to
-	| OEnumField
-	| OClassType_superClass
-	| OClassType_interfaces
-	| OType_args
-	| OTVar
-	| OTVar_extra
-	| OTFunc
-	| OTFunc_args
-	| OFieldAccess_c
-	| OTypedExprDef
-	| OTypedExprDef_fields
-	| OTypedExprDef_cases
-	| OTypedExprDef_catches
-	| OJSGenApi
-	| OContext_getPosInfos
-	| OCompiler_getDisplayPos
-	| ORef
-(* ---- ^^^^^ please exactly match the name of the typedef or use TypeName_field if it's a anonymous *)
-
 (**
 	Our access to the interpreter from the macro api
 **)
@@ -144,7 +95,7 @@ module type InterpApi = sig
 
 	val encode_array : value list -> value
 	val encode_string  : string -> value
-	val encode_obj : obj_type -> (string * value) list -> value
+	val encode_obj : (string * value) list -> value
 	val encode_lazy : (unit -> value) -> value
 
 	val vfun0 : (unit -> value) -> value
@@ -221,51 +172,6 @@ let enum_name = function
 	| IImportMode -> "ImportMode"
 	| IQuoteStatus -> "QuoteStatus"
 
-let proto_name = function
-	| O__Const -> assert false
-	| OImportExpr -> "ImportExpr", None
-	| OImportExpr_path -> "ImportExpr", Some "path"
-	| OTypePath -> "TypePath", None
-	| OMetadataEntry -> "MetadataEntry", None
-	| OField -> "Field", None
-	| OTypeParamDecl -> "TypeParamDecl", None
-	| OFunction -> "Function", None
-	| OFunctionArg -> "FunctionArg", None
-	| OExprDef_fields -> "ExprDef", Some "fields"
-	| OVar -> "Var", None
-	| OCase -> "Case", None
-	| OCatch -> "Catch", None
-	| OExpr -> "Expr", None
-	| OMetaAccess -> "MetaAccess", None
-	| OTypeParameter -> "TypeParameter", None
-	| OClassType -> "ClassType", None
-	| OAbstractType -> "AbstracType", None
-	| OAnonType -> "AnonType", None
-	| ODefType -> "DefType", None
-	| OEnumType -> "EnumType", None
-	| OClassField -> "ClassField", None
-	| OAbstractType_binops -> "AbstractType", Some "binops"
-	| OAbstractType_unops -> "AbstractType", Some "unops"
-	| OAbstractType_from -> "AbstractType", Some "from"
-	| OAbstractType_to -> "AbstractType", Some "to"
-	| OEnumField -> "EnumField", None
-	| OClassType_superClass -> "ClassType", Some "superClass"
-	| OClassType_interfaces -> "ClassType", Some "interfaces"
-	| OType_args -> "Type", Some "args"
-	| OTVar -> "TVar", None
-	| OTVar_extra -> "TVar", Some "extra"
-	| OTFunc -> "TFunc", None
-	| OTFunc_args -> "TFunc", Some "args"
-	| OFieldAccess_c -> "FieldAccess", Some "c"
-	| OTypedExprDef -> "TypedExprDef", None
-	| OTypedExprDef_fields -> "TypedExprDef", Some "fields"
-	| OTypedExprDef_cases -> "TypedExprDef", Some "cases"
-	| OTypedExprDef_catches -> "TypedExprDef", Some "catches"
-	| OJSGenApi -> "JSGenApi", None
-	| OContext_getPosInfos -> "Context", Some "getPosInfos"
-	| OCompiler_getDisplayPos -> "Compiler", Some "getDisplayPos"
-	| ORef -> "Ref", None
-
 let all_enums =
 	let last = IImportMode in
 	let rec loop i =
@@ -363,8 +269,8 @@ let encode_import (path,mode) =
 		| IAll -> 2,[]
 	in
 	let mode = encode_enum IImportMode tag pl in
-	encode_obj OImportExpr [
-		"path", encode_array (List.map (fun (name,p) -> encode_obj OImportExpr_path [ "pos", encode_pos p; "name", encode_string name]) path);
+	encode_obj [
+		"path", encode_array (List.map (fun (name,p) -> encode_obj [ "pos", encode_pos p; "name", encode_string name]) path);
 		"mode", mode
 	]
 
@@ -377,7 +283,7 @@ let rec encode_path (t,_) =
 		"name", encode_string t.tname;
 		"params", encode_array (List.map encode_tparam t.tparams);
 	] in
-	encode_obj OTypePath (match t.tsub with
+	encode_obj (match t.tsub with
 		| None -> fields
 		| Some s -> ("sub", encode_string s) :: fields)
 
@@ -400,7 +306,7 @@ and encode_access a =
 	encode_enum ~pos:(Some (pos a)) IAccess tag []
 
 and encode_meta_entry (m,ml,p) =
-	encode_obj OMetadataEntry [
+	encode_obj [
 		"name", encode_string (Meta.to_string m);
 		"params", encode_array (List.map encode_expr ml);
 		"pos", encode_pos p;
@@ -415,7 +321,7 @@ and encode_field (f:class_field) =
 		| FFun f -> 1, [encode_fun f]
 		| FProp (get,set, t, e) -> 2, [encode_placed_name get; encode_placed_name set; null encode_ctype t; null encode_expr e]
 	in
-	encode_obj OField [
+	encode_obj [
 		"name",encode_placed_name f.cff_name;
 		"name_pos", encode_pos (pos f.cff_name);
 		"doc", null encode_string f.cff_doc;
@@ -447,7 +353,7 @@ and encode_ctype t =
 	encode_enum ~pos:(Some (pos t)) ICType tag pl
 
 and encode_tparam_decl tp =
-	encode_obj OTypeParamDecl [
+	encode_obj [
 		"name", encode_placed_name tp.tp_name;
 		"name_pos", encode_pos (pos tp.tp_name);
 		"params", encode_array (List.map encode_tparam_decl tp.tp_params);
@@ -458,10 +364,10 @@ and encode_tparam_decl tp =
 	]
 
 and encode_fun f =
-	encode_obj OFunction [
+	encode_obj [
 		"params", encode_array (List.map encode_tparam_decl f.f_params);
 		"args", encode_array (List.map (fun (n,opt,m,t,e) ->
-			encode_obj OFunctionArg [
+			encode_obj [
 				"name", encode_placed_name n;
 				"name_pos", encode_pos (pos n);
 				"opt", vbool opt;
@@ -498,7 +404,7 @@ and encode_expr e =
 			| EParenthesis e ->
 				4, [loop e]
 			| EObjectDecl fl ->
-				5, [encode_array (List.map (fun ((f,p,qs),e) -> encode_obj OExprDef_fields [
+				5, [encode_array (List.map (fun ((f,p,qs),e) -> encode_obj [
 					"field",encode_string f;
 					"name_pos",encode_pos p;
 					"quotes",encode_enum IQuoteStatus (match qs with NoQuotes -> 0 | DoubleQuotes -> 1) [];
@@ -514,7 +420,7 @@ and encode_expr e =
 				9, [encode_unop op; vbool (match flag with Prefix -> false | Postfix -> true); loop e]
 			| EVars vl ->
 				10, [encode_array (List.map (fun (v,final,t,eo) ->
-					encode_obj OVar [
+					encode_obj [
 						"name",encode_placed_name v;
 						"name_pos",encode_pos (pos v);
 						"isFinal",vbool final;
@@ -534,7 +440,7 @@ and encode_expr e =
 				15, [loop econd;loop e;vbool (match flag with NormalWhile -> true | DoWhile -> false)]
 			| ESwitch (e,cases,eopt) ->
 				16, [loop e;encode_array (List.map (fun (ecl,eg,e,p) ->
-					encode_obj OCase [
+					encode_obj [
 						"values",encode_array (List.map loop ecl);
 						"guard",null loop eg;
 						"expr",null loop e;
@@ -543,7 +449,7 @@ and encode_expr e =
 				) cases);null (fun (e,_) -> encode_null_expr e) eopt]
 			| ETry (e,catches) ->
 				17, [loop e;encode_array (List.map (fun (v,t,e,p) ->
-					encode_obj OCatch [
+					encode_obj [
 						"name",encode_placed_name v;
 						"name_pos",encode_pos (pos v);
 						"type",encode_ctype t;
@@ -574,7 +480,7 @@ and encode_expr e =
 			| EMeta (m,e) ->
 				28, [encode_meta_entry m;loop e]
 		in
-		encode_obj OExpr [
+		encode_obj [
 			"pos", encode_pos p;
 			"expr", encode_enum IExpr tag pl;
 		]
@@ -584,7 +490,7 @@ and encode_expr e =
 and encode_null_expr e =
 	match e with
 	| None ->
-		encode_obj OExpr ["pos", vnull;"expr",vnull]
+		encode_obj ["pos", vnull;"expr",vnull]
 	| Some e ->
 		encode_expr e
 
@@ -890,7 +796,7 @@ let vopt f v = match v with
 
 let encode_meta m set =
 	let meta = ref m in
-	encode_obj OMetaAccess [
+	encode_obj [
 		"get", vfun0 (fun() ->
 			encode_meta_content (!meta)
 		);
@@ -919,9 +825,9 @@ let encode_meta m set =
 		);
 	]
 
-let rec encode_mtype ot t fields =
+let rec encode_mtype t fields =
 	let i = t_infos t in
-	encode_obj ot ([
+	encode_obj ([
 		"__t", 	encode_tdecl t;
 		"pack", encode_array (List.map encode_string (fst i.mt_path));
 		"name", encode_string (snd i.mt_path);
@@ -934,10 +840,10 @@ let rec encode_mtype ot t fields =
 	] @ fields)
 
 and encode_type_params tl =
-	encode_array (List.map (fun (n,t) -> encode_obj OTypeParameter ["name",encode_string n;"t",encode_type t]) tl)
+	encode_array (List.map (fun (n,t) -> encode_obj ["name",encode_string n;"t",encode_type t]) tl)
 
 and encode_tenum e =
-	encode_mtype OEnumType (TEnumDecl e) [
+	encode_mtype (TEnumDecl e) [
 		"isExtern", vbool e.e_extern;
 		"exclude", vfun0 (fun() -> e.e_extern <- true; vnull);
 		"constructs", encode_string_map encode_efield e.e_constrs;
@@ -945,20 +851,20 @@ and encode_tenum e =
 	]
 
 and encode_tabstract a =
-	encode_mtype OAbstractType (TAbstractDecl a) [
+	encode_mtype (TAbstractDecl a) [
 		"type", encode_type a.a_this;
 		"impl", (match a.a_impl with None -> vnull | Some c -> encode_clref c);
-		"binops", encode_array (List.map (fun (op,cf) -> encode_obj OAbstractType_binops [ "op",encode_binop op; "field",encode_cfield cf]) a.a_ops);
-		"unops", encode_array (List.map (fun (op,postfix,cf) -> encode_obj OAbstractType_unops [ "op",encode_unop op; "isPostfix",vbool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
-		"from", encode_array ((List.map (fun t -> encode_obj OAbstractType_from [ "t",encode_type t; "field",vnull]) a.a_from) @ (List.map (fun (t,cf) -> encode_obj OAbstractType_from [ "t",encode_type t; "field",encode_cfield cf]) a.a_from_field));
-		"to", encode_array ((List.map (fun t -> encode_obj OAbstractType_to [ "t",encode_type t; "field",vnull]) a.a_to) @ (List.map (fun (t,cf) -> encode_obj OAbstractType_to [ "t",encode_type t; "field",encode_cfield cf]) a.a_to_field));
+		"binops", encode_array (List.map (fun (op,cf) -> encode_obj [ "op",encode_binop op; "field",encode_cfield cf]) a.a_ops);
+		"unops", encode_array (List.map (fun (op,postfix,cf) -> encode_obj [ "op",encode_unop op; "isPostfix",vbool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
+		"from", encode_array ((List.map (fun t -> encode_obj [ "t",encode_type t; "field",vnull]) a.a_from) @ (List.map (fun (t,cf) -> encode_obj [ "t",encode_type t; "field",encode_cfield cf]) a.a_from_field));
+		"to", encode_array ((List.map (fun t -> encode_obj [ "t",encode_type t; "field",vnull]) a.a_to) @ (List.map (fun (t,cf) -> encode_obj [ "t",encode_type t; "field",encode_cfield cf]) a.a_to_field));
 		"array", encode_array (List.map encode_cfield a.a_array);
 		"resolve", (match a.a_read with None -> vnull | Some cf -> encode_cfref cf);
 		"resolveWrite", (match a.a_write with None -> vnull | Some cf -> encode_cfref cf)
 	]
 
 and encode_efield f =
-	encode_obj OEnumField [
+	encode_obj [
 		"name", encode_string f.ef_name;
 		"type", encode_type f.ef_type;
 		"pos", encode_pos f.ef_pos;
@@ -970,7 +876,7 @@ and encode_efield f =
 	]
 
 and encode_cfield f =
-	encode_obj OClassField [
+	encode_obj [
 		"name", encode_string f.cf_name;
 		"type", encode_lazy_type f.cf_type;
 		"isPublic", vbool f.cf_public;
@@ -1034,7 +940,7 @@ and encode_class_kind k =
 
 and encode_tclass c =
 	ignore(c.cl_build());
-	encode_mtype OClassType (TClassDecl c) [
+	encode_mtype (TClassDecl c) [
 		"kind", encode_class_kind c.cl_kind;
 		"isExtern", vbool c.cl_extern;
 		"exclude", vfun0 (fun() -> c.cl_extern <- true; c.cl_init <- None; vnull);
@@ -1042,9 +948,9 @@ and encode_tclass c =
 		"isFinal", vbool c.cl_final;
 		"superClass", (match c.cl_super with
 			| None -> vnull
-			| Some (c,pl) -> encode_obj OClassType_superClass ["t",encode_clref c;"params",encode_tparams pl]
+			| Some (c,pl) -> encode_obj ["t",encode_clref c;"params",encode_tparams pl]
 		);
-		"interfaces", encode_array (List.map (fun (c,pl) -> encode_obj OClassType_interfaces ["t",encode_clref c;"params",encode_tparams pl]) c.cl_implements);
+		"interfaces", encode_array (List.map (fun (c,pl) -> encode_obj ["t",encode_clref c;"params",encode_tparams pl]) c.cl_implements);
 		"fields", encode_ref c.cl_ordered_fields (encode_and_map_array encode_cfield) (fun() -> "class fields");
 		"statics", encode_ref c.cl_ordered_statics (encode_and_map_array encode_cfield) (fun() -> "class fields");
 		"constructor", (match c.cl_constructor with None -> vnull | Some cf -> encode_cfref cf);
@@ -1053,14 +959,14 @@ and encode_tclass c =
 	]
 
 and encode_ttype t =
-	encode_mtype ODefType (TTypeDecl t) [
+	encode_mtype (TTypeDecl t) [
 		"isExtern", vbool false;
 		"exclude", vfun0 (fun() -> vnull);
 		"type", encode_type t.t_type;
 	]
 
 and encode_tanon a =
-	encode_obj OAnonType [
+	encode_obj [
 		"fields", encode_pmap_array encode_cfield a.a_fields;
 		"status", encode_anon_status !(a.a_status);
 	]
@@ -1107,7 +1013,7 @@ and encode_type t =
 			3 , [encode_ref t encode_ttype (fun() -> s_type_path t.t_path); encode_tparams pl]
 		| TFun (pl,ret) ->
 			let pl = List.map (fun (n,o,t) ->
-				encode_obj OType_args [
+				encode_obj [
 					"name",encode_string n;
 					"opt",vbool o;
 					"t",encode_type t
@@ -1189,13 +1095,13 @@ and encode_tconst c =
 
 and encode_tvar v =
 	let f_extra (pl,e,inline) =
-		encode_obj OTVar_extra [
+		encode_obj [
 			"params",encode_type_params pl;
 			"expr",encode_texpr e;
 			"isInline",vbool inline;
 		]
 	in
-	encode_obj OTVar [
+	encode_obj [
 		"id", vint v.v_id;
 		"name", encode_string v.v_name;
 		"t", encode_type v.v_type;
@@ -1215,9 +1121,9 @@ and encode_module_type mt =
 	encode_enum IModuleType tag pl
 
 and encode_tfunc func =
-	encode_obj OTFunc [
+	encode_obj [
 		"args",encode_array (List.map (fun (v,c) ->
-			encode_obj OTFunc_args [
+			encode_obj [
 				"v",encode_tvar v;
 				"value",match c with None -> vnull | Some c -> encode_tconst c
 			]
@@ -1228,7 +1134,7 @@ and encode_tfunc func =
 
 and encode_field_access fa =
 	let encode_instance c tl =
-		encode_obj OFieldAccess_c [
+		encode_obj [
 			"c",encode_clref c;
 			"params",encode_tparams tl
 		]
@@ -1254,7 +1160,7 @@ and encode_texpr e =
 			| TTypeExpr mt -> 5,[encode_module_type mt]
 			| TParenthesis e1 -> 6,[loop e1]
 			| TObjectDecl fl -> 7, [encode_array (List.map (fun ((f,_,_),e) ->
-				encode_obj OTypedExprDef_fields [
+				encode_obj [
 					"name",encode_string f;
 					"expr",loop e;
 				]) fl)]
@@ -1270,13 +1176,13 @@ and encode_texpr e =
 			| TWhile(econd,e1,flag) -> 17,[loop econd;loop e1;vbool (flag = NormalWhile)]
 			| TSwitch(e1,cases,edef) -> 18,[
 				loop e1;
-				encode_array (List.map (fun (el,e) -> encode_obj OTypedExprDef_cases ["values",encode_texpr_list el;"expr",loop e]) cases);
+				encode_array (List.map (fun (el,e) -> encode_obj ["values",encode_texpr_list el;"expr",loop e]) cases);
 				vopt encode_texpr edef
 				]
 			| TTry(e1,catches) -> 19,[
 				loop e1;
 				encode_array (List.map (fun (v,e) ->
-					encode_obj OTypedExprDef_catches [
+					encode_obj [
 						"v",encode_tvar v;
 						"expr",loop e
 					]) catches
@@ -1291,7 +1197,7 @@ and encode_texpr e =
 			| TEnumIndex e1 -> 27,[loop e1]
 			| TIdent s -> 28,[encode_string s]
 		in
-		encode_obj OTypedExprDef [
+		encode_obj [
 			"pos", encode_pos e.epos;
 			"expr", encode_enum ITypedExpr tag pl;
 			"t", encode_type e.etype
@@ -1543,7 +1449,7 @@ let rec make_const e =
 	| TParenthesis e | TMeta(_,e) | TCast(e,None) ->
 		make_const e
 	| TObjectDecl el ->
-		encode_obj O__Const (List.map (fun ((f,_,_),e) -> f, make_const e) el)
+		encode_obj (List.map (fun ((f,_,_),e) -> f, make_const e) el)
 	| TArrayDecl al ->
 		encode_array (List.map make_const al)
 	| _ ->
@@ -1693,7 +1599,7 @@ let macro_api ccom get_api =
 			let f = prepare_callback f 1 in
 			(get_api()).set_js_generator (fun js_ctx ->
 				let com = ccom() in
-				let api = encode_obj OJSGenApi [
+				let api = encode_obj [
 					"outputFile", encode_string com.file;
 					"types", encode_array (List.map (fun t -> encode_type (type_of_module_type t)) com.types);
 					"main", (match com.main with None -> vnull | Some e -> encode_texpr e);
@@ -1743,7 +1649,7 @@ let macro_api ccom get_api =
 		);
 		"get_pos_infos", vfun1 (fun p ->
 			let p = decode_pos p in
-			encode_obj OContext_getPosInfos ["min",vint p.Globals.pmin;"max",vint p.Globals.pmax;"file",encode_string p.Globals.pfile]
+			encode_obj ["min",vint p.Globals.pmin;"max",vint p.Globals.pmax;"file",encode_string p.Globals.pfile]
 		);
 		"make_position", vfun3 (fun min max file ->
 			encode_pos { Globals.pmin = decode_int min; Globals.pmax = decode_int max; Globals.pfile = decode_string file }
@@ -1914,7 +1820,7 @@ let macro_api ccom get_api =
 			if p = Globals.null_pos then
 				vnull
 			else
-				encode_obj OCompiler_getDisplayPos ["file",encode_string p.Globals.pfile;"pos",vint p.Globals.pmin]
+				encode_obj ["file",encode_string p.Globals.pfile;"pos",vint p.Globals.pmin]
 		);
 		"pattern_locals", vfun2 (fun e t ->
 			let loc = (get_api()).get_pattern_locals (decode_expr e) (decode_type t) in
@@ -1973,18 +1879,18 @@ let macro_api ccom get_api =
 			let p = decode_pos p in
 			let l1,c1,l2,c2 = Lexer.get_pos_coords p in
 			let make_pos line character =
-				encode_obj O__Const [
+				encode_obj [
 					"line",vint line;
 					"character",vint character;
 				]
 			in
 			let pos_start = make_pos l1 c1 in
 			let pos_end = make_pos l2 c2 in
-			let range = encode_obj O__Const [
+			let range = encode_obj [
 				"start",pos_start;
 				"end",pos_end;
 			] in
-			let location = encode_obj O__Const [
+			let location = encode_obj [
 				"file",encode_string p.Globals.pfile;
 				"range",range
 			] in