Simon Krajewski 4 lat temu
rodzic
commit
9f8b3e7709
2 zmienionych plików z 9 dodań i 5 usunięć
  1. 6 2
      src/context/common.ml
  2. 3 3
      src/typing/typerBase.ml

+ 6 - 2
src/context/common.ml

@@ -182,6 +182,8 @@ type platform_config = {
 	pf_exceptions : exceptions_config;
 	pf_exceptions : exceptions_config;
 	(** the scoping of local variables *)
 	(** the scoping of local variables *)
 	pf_scoping : var_scoping_config;
 	pf_scoping : var_scoping_config;
+	(** whether or not the target needs a variable to capture `this` *)
+	pf_can_capture_this : bool;
 }
 }
 
 
 class compiler_callbacks = object(self)
 class compiler_callbacks = object(self)
@@ -421,7 +423,8 @@ let default_config =
 		pf_scoping = {
 		pf_scoping = {
 			vs_scope = BlockScope;
 			vs_scope = BlockScope;
 			vs_flags = [];
 			vs_flags = [];
-		}
+		};
+		pf_can_capture_this = true;
 	}
 	}
 
 
 let get_config com =
 let get_config com =
@@ -578,7 +581,7 @@ let get_config com =
 					{
 					{
 						vs_scope = FunctionScope;
 						vs_scope = FunctionScope;
 						vs_flags = [NoShadowing; ReserveAllTopLevelSymbols; ReserveNames(["_"])];
 						vs_flags = [NoShadowing; ReserveAllTopLevelSymbols; ReserveNames(["_"])];
-					}
+					};
 		}
 		}
 	| Python ->
 	| Python ->
 		{
 		{
@@ -625,6 +628,7 @@ let get_config com =
 			pf_uses_utf16 = false;
 			pf_uses_utf16 = false;
 			pf_supports_threads = true;
 			pf_supports_threads = true;
 			pf_capture_policy = CPWrapRef;
 			pf_capture_policy = CPWrapRef;
+			pf_can_capture_this = false;
 		}
 		}
 
 
 let memory_marker = [|Unix.time()|]
 let memory_marker = [|Unix.time()|]

+ 3 - 3
src/typing/typerBase.ml

@@ -39,7 +39,7 @@ let get_this ctx p =
 	match ctx.curfun with
 	match ctx.curfun with
 	| FunStatic ->
 	| FunStatic ->
 		error "Cannot access this from a static function" p
 		error "Cannot access this from a static function" p
-	| FunMemberClassLocal | FunMemberAbstractLocal ->
+	| FunMemberClassLocal | FunMemberAbstractLocal when not ctx.com.config.pf_can_capture_this ->
 		let v = match ctx.vthis with
 		let v = match ctx.vthis with
 			| None ->
 			| None ->
 				let v = if ctx.curfun = FunMemberAbstractLocal then
 				let v = if ctx.curfun = FunMemberAbstractLocal then
@@ -54,10 +54,10 @@ let get_this ctx p =
 				v
 				v
 		in
 		in
 		mk (TLocal v) ctx.tthis p
 		mk (TLocal v) ctx.tthis p
-	| FunMemberAbstract ->
+	| FunMemberAbstract | FunMemberAbstractLocal ->
 		let v = (try PMap.find "this" ctx.locals with Not_found -> die "" __LOC__) in
 		let v = (try PMap.find "this" ctx.locals with Not_found -> die "" __LOC__) in
 		mk (TLocal v) v.v_type p
 		mk (TLocal v) v.v_type p
-	| FunConstructor | FunMember ->
+	| FunConstructor | FunMember | FunMemberClassLocal ->
 		mk (TConst TThis) ctx.tthis p
 		mk (TConst TThis) ctx.tthis p
 
 
 let assign_to_this_is_allowed ctx =
 let assign_to_this_is_allowed ctx =