Browse Source

[hl] some mess

Dan Korostelev 4 years ago
parent
commit
b19fe34252
2 changed files with 11 additions and 4 deletions
  1. 2 0
      src/generators/genhl.ml
  2. 9 4
      src/generators/hl2c.ml

+ 2 - 0
src/generators/genhl.ml

@@ -2901,6 +2901,8 @@ and eval_expr ctx e =
 		List.iter (fun j -> j()) (loop catches);
 		List.iter (fun j -> j()) (loop catches);
 		j();
 		j();
 		result
 		result
+	| TTypeExpr (TAbstractDecl { a_path = [],"Void" }) ->
+		alloc_tmp ctx HVoid
 	| TTypeExpr t ->
 	| TTypeExpr t ->
 		type_value ctx t e.epos
 		type_value ctx t e.epos
 	| TCast (ev,Some _) ->
 	| TCast (ev,Some _) ->

+ 9 - 4
src/generators/hl2c.ml

@@ -158,8 +158,11 @@ let ctype t =
 	let t, nptr = ctype_no_ptr t in
 	let t, nptr = ctype_no_ptr t in
 	if nptr = 0 then t else t ^ String.make nptr '*'
 	if nptr = 0 then t else t ^ String.make nptr '*'
 
 
+let val_type t =
+	ctype (if t = HVoid then HDyn else t)
+
 let args_repr args =
 let args_repr args =
-	if args = [] then "void" else String.concat "," (List.map ctype args)
+	if args = [] then "void" else String.concat "," (List.map val_type args)
 
 
 let cast_fun s args t =
 let cast_fun s args t =
 	sprintf "((%s (*)(%s))%s)" (ctype t) (args_repr args) s
 	sprintf "((%s (*)(%s))%s)" (ctype t) (args_repr args) s
@@ -201,7 +204,7 @@ let type_id t =
 	| HStruct _  -> "HSTRUCT"
 	| HStruct _  -> "HSTRUCT"
 
 
 let var_type n t =
 let var_type n t =
-	ctype t ^ " " ^ ident n
+	val_type t ^ " " ^ ident n
 
 
 let block ctx =
 let block ctx =
 	ctx.tabs <- ctx.tabs ^ "\t"
 	ctx.tabs <- ctx.tabs ^ "\t"
@@ -535,8 +538,10 @@ let generate_function ctx f =
 	let funname fid = define_function ctx fid in
 	let funname fid = define_function ctx fid in
 
 
 	let rcast r t =
 	let rcast r t =
-		if tsame (rtype r) t then (reg r)
-		else Printf.sprintf "((%s)%s)" (ctype t) (reg r)
+		let tr = rtype r in
+		let r = if tr = HVoid then "NULL" else reg r in
+		if tsame tr t then r
+		else Printf.sprintf "((%s)%s)" (ctype t) r
 	in
 	in
 
 
 	let rfun r args t =
 	let rfun r args t =