Browse Source

[eval] add explicit prototypes for Vector and Array

Simon Krajewski 8 years ago
parent
commit
bc712b4610

+ 2 - 0
src/macro/eval/evalContext.ml

@@ -131,7 +131,9 @@ type context = {
 	mutable type_cache : Type.module_type IntMap.t;
 	mutable type_cache : Type.module_type IntMap.t;
 	overrides : (Type.path * string,bool) Hashtbl.t;
 	overrides : (Type.path * string,bool) Hashtbl.t;
 	(* prototypes *)
 	(* prototypes *)
+	mutable array_prototype : vprototype;
 	mutable string_prototype : vprototype;
 	mutable string_prototype : vprototype;
+	mutable vector_prototype : vprototype;
 	mutable instance_prototypes : vprototype IntMap.t;
 	mutable instance_prototypes : vprototype IntMap.t;
 	mutable static_prototypes : vprototype IntMap.t;
 	mutable static_prototypes : vprototype IntMap.t;
 	mutable constructors : value Lazy.t IntMap.t;
 	mutable constructors : value Lazy.t IntMap.t;

+ 2 - 0
src/macro/eval/evalEmitter.ml

@@ -544,6 +544,8 @@ let emit_method_call exec name execs p =
 	let vf vthis = match vthis with
 	let vf vthis = match vthis with
 		| VInstance {iproto = proto} | VPrototype proto -> proto_field_raise proto name
 		| VInstance {iproto = proto} | VPrototype proto -> proto_field_raise proto name
 		| VString _ -> proto_field_raise (get_ctx()).string_prototype name
 		| VString _ -> proto_field_raise (get_ctx()).string_prototype name
+		| VArray _ -> proto_field_raise (get_ctx()).array_prototype name
+		| VVector _ -> proto_field_raise (get_ctx()).vector_prototype name
 		| _ -> unexpected_value_p vthis "instance" p
 		| _ -> unexpected_value_p vthis "instance" p
 	in
 	in
 	match execs with
 	match execs with

+ 2 - 2
src/macro/eval/evalField.ml

@@ -51,10 +51,10 @@ let field_raise v f =
 	| VPrototype proto -> proto_field_raise proto f
 	| VPrototype proto -> proto_field_raise proto f
 	| VArray va ->
 	| VArray va ->
 		if f = key_length then vint (va.alength)
 		if f = key_length then vint (va.alength)
-		else proto_field_direct (get_instance_prototype_raise (get_ctx()) key_Array) f
+		else proto_field_direct (get_ctx()).array_prototype f
 	| VVector vv ->
 	| VVector vv ->
 		if f = key_length then vint (Array.length vv)
 		if f = key_length then vint (Array.length vv)
-		else proto_field_direct (get_instance_prototype_raise (get_ctx()) key_eval_Vector) f
+		else proto_field_direct (get_ctx()).vector_prototype f
 	| VString (_,s) ->
 	| VString (_,s) ->
 		if f = key_length then vint (String.length (Lazy.force s))
 		if f = key_length then vint (String.length (Lazy.force s))
 		else proto_field_direct (get_ctx()).string_prototype f
 		else proto_field_direct (get_ctx()).string_prototype f

+ 2 - 0
src/macro/eval/evalMain.ml

@@ -115,6 +115,8 @@ let create com api is_macro =
 		had_error = false;
 		had_error = false;
 		(* prototypes *)
 		(* prototypes *)
 		string_prototype = fake_proto key_String;
 		string_prototype = fake_proto key_String;
+		array_prototype = fake_proto key_Array;
+		vector_prototype = fake_proto key_eval_Vector;
 		static_prototypes = IntMap.empty;
 		static_prototypes = IntMap.empty;
 		instance_prototypes = IntMap.empty;
 		instance_prototypes = IntMap.empty;
 		constructors = IntMap.empty;
 		constructors = IntMap.empty;

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

@@ -160,7 +160,9 @@ module PrototypeBuilder = struct
 			ctx.static_prototypes <- IntMap.add pctx.key proto ctx.static_prototypes
 			ctx.static_prototypes <- IntMap.add pctx.key proto ctx.static_prototypes
 		else begin
 		else begin
 			ctx.instance_prototypes <- IntMap.add pctx.key proto ctx.instance_prototypes;
 			ctx.instance_prototypes <- IntMap.add pctx.key proto ctx.instance_prototypes;
-			if pctx.key = key_String then ctx.string_prototype <- proto;
+			if pctx.key = key_String then ctx.string_prototype <- proto
+			else if pctx.key = key_Array then ctx.array_prototype <- proto
+			else if pctx.key = key_eval_Vector then ctx.vector_prototype <- proto
 		end;
 		end;
 		proto,f
 		proto,f
 end
 end