2
0
Simon Krajewski 10 жил өмнө
parent
commit
5f66110900
4 өөрчлөгдсөн 21 нэмэгдсэн , 22 устгасан
  1. 8 0
      codegen.ml
  2. 2 11
      interp.ml
  3. 9 0
      type.ml
  4. 2 11
      typer.ml

+ 8 - 0
codegen.ml

@@ -684,6 +684,14 @@ let on_inherit ctx c p h =
 	| _ ->
 		true
 
+let push_this ctx e = match e.eexpr with
+	| TConst ((TInt _ | TFloat _ | TString _ | TBool _) as ct) ->
+		(EConst (tconst_to_const ct),e.epos),fun () -> ()
+	| _ ->
+		ctx.this_stack <- e :: ctx.this_stack;
+		let er = EMeta((Meta.This,[],e.epos), (EConst(Ident "this"),e.epos)),e.epos in
+		er,fun () -> ctx.this_stack <- List.tl ctx.this_stack
+
 (* -------------------------------------------------------------------------- *)
 (* ABSTRACT CASTS *)
 

+ 2 - 11
interp.ml

@@ -5034,15 +5034,6 @@ let rec make_ast e =
 		if snd mp = snd p then p else (fst mp) @ [snd mp],snd p
 	in
 	let mk_path = expr_of_type_path in
-	let mk_const = function
-		| TInt i -> Int (Int32.to_string i)
-		| TFloat s -> Float s
-		| TString s -> String s
-		| TBool b -> Ident (if b then "true" else "false")
-		| TNull -> Ident "null"
-		| TThis -> Ident "this"
-		| TSuper -> Ident "super"
-	in
 	let mk_ident = function
 		| "`trace" -> Ident "trace"
 		| n -> Ident n
@@ -5050,7 +5041,7 @@ let rec make_ast e =
 	let eopt = function None -> None | Some e -> Some (make_ast e) in
 	((match e.eexpr with
 	| TConst c ->
-		EConst (mk_const c)
+		EConst (tconst_to_const c)
 	| TLocal v -> EConst (mk_ident v.v_name)
 	| TArray (e1,e2) -> EArray (make_ast e1,make_ast e2)
 	| TBinop (op,e1,e2) -> EBinop (op, make_ast e1, make_ast e2)
@@ -5063,7 +5054,7 @@ let rec make_ast e =
 	| TNew (c,pl,el) -> ENew ((match (try make_type (TInst (c,pl)) with Exit -> make_type (TInst (c,[]))) with CTPath p -> p | _ -> assert false),List.map make_ast el)
 	| TUnop (op,p,e) -> EUnop (op,p,make_ast e)
 	| TFunction f ->
-		let arg (v,c) = v.v_name, false, mk_ot v.v_type, (match c with None -> None | Some c -> Some (EConst (mk_const c),e.epos)) in
+		let arg (v,c) = v.v_name, false, mk_ot v.v_type, (match c with None -> None | Some c -> Some (EConst (tconst_to_const c),e.epos)) in
 		EFunction (None,{ f_params = []; f_args = List.map arg f.tf_args; f_type = mk_ot f.tf_type; f_expr = Some (make_ast f.tf_expr) })
 	| TVar (v,eo) ->
 		EVars ([v.v_name, mk_ot v.v_type, eopt eo])

+ 9 - 0
type.ml

@@ -677,6 +677,15 @@ let type_of_module_type = function
 	| TTypeDecl t -> TType (t,List.map snd t.t_params)
 	| TAbstractDecl a -> TAbstract (a,List.map snd a.a_params)
 
+let tconst_to_const = function
+	| TInt i -> Int (Int32.to_string i)
+	| TFloat s -> Float s
+	| TString s -> String s
+	| TBool b -> Ident (if b then "true" else "false")
+	| TNull -> Ident "null"
+	| TThis -> Ident "this"
+	| TSuper -> Ident "super"
+
 (* ======= Field utility ======= *)
 
 let field_name f =

+ 2 - 11
typer.ml

@@ -3994,15 +3994,6 @@ and type_call ctx e el (with_type:with_type) p =
 		def ()
 
 and build_call ctx acc el (with_type:with_type) p =
-	let push_this e =
-		match e.eexpr with
-			| TConst (TInt _ | TFloat _ | TString _ | TBool _) ->
-				(Interp.make_ast e),fun () -> ()
-			| _ ->
-				ctx.this_stack <- e :: ctx.this_stack;
-				let er = EMeta((Meta.This,[],e.epos), (EConst(Ident "this"),e.epos)),e.epos in
-				er,fun () -> ctx.this_stack <- List.tl ctx.this_stack
-	in
 	match acc with
  	| AKInline (ethis,f,fmode,t) when Meta.has Meta.Generic f.cf_meta ->
 		type_generic_function ctx (ethis,fmode) el with_type p
@@ -4023,7 +4014,7 @@ and build_call ctx acc el (with_type:with_type) p =
 		begin match ef.cf_kind with
 		| Method MethMacro ->
 			let ethis = type_module_type ctx (TClassDecl cl) None p in
-			let eparam,f = push_this eparam in
+			let eparam,f = Codegen.push_this ctx eparam in
 			let e = build_call ctx (AKMacro (ethis,ef)) (eparam :: el) with_type p in
 			f();
 			e
@@ -4064,7 +4055,7 @@ and build_call ctx acc el (with_type:with_type) p =
 			| TInst (c,_) ->
 				let rec loop c =
 					if PMap.mem cf.cf_name c.cl_fields then
-						let eparam,f = push_this ethis in
+						let eparam,f = Codegen.push_this ctx ethis in
 						ethis_f := f;
 						let e = match ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name (eparam :: el) p with
 							| None -> (fun() -> type_expr ctx (EConst (Ident "null"),p) Value)