Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 38 additions & 26 deletions src/generators/cpp/gen/cppCppia.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open CppAst
open CppAstTools
open CppContext

type script_type =
type script_type =
| ScriptBool
| ScriptInt
| ScriptFloat
Expand Down Expand Up @@ -413,7 +413,7 @@ let is_extern_class_instance obj =
let rec is_dynamic_in_cpp ctx expr =
let expr_type =
type_string
(match follow expr.etype with TFun (args, ret) -> ret | _ -> expr.etype)
(match follow_with_coro expr.etype with Coro (args, ret) | NotCoro TFun (args, ret) -> ret | _ -> expr.etype)
in
if expr_type = "Dynamic" || expr_type = "cpp::ArrayBase" then true
else
Expand Down Expand Up @@ -454,8 +454,8 @@ let rec is_dynamic_in_cpp ctx expr =
in
if is_IaCall then true
else
match follow func.etype with
| TFun (args, ret) -> is_dynamic_in_cpp ctx func
match follow_with_coro func.etype with
| Coro _ | NotCoro TFun _ -> is_dynamic_in_cpp ctx func
| _ -> true)
| TParenthesis expr | TMeta (_, expr) -> is_dynamic_in_cpp ctx expr
| TCast (e, None) -> type_string expr.etype = "Dynamic"
Expand Down Expand Up @@ -1087,8 +1087,8 @@ class script_writer ctx filename asciiOut =
this#write (this#op IaCall ^ argN ^ "\n");
this#gen_expression func);
let matched_args =
match func.etype with
| TFun (args, _) -> (
match follow_with_coro func.etype with
| Coro (args, _) | NotCoro TFun (args, _) -> (
try
List.iter2
(fun (_, _, protoT) arg ->
Expand Down Expand Up @@ -1814,10 +1814,21 @@ let generate_script_class common_ctx script class_def =
^ "\n");

let generate_field isStatic field =
match (field.cf_kind, follow field.cf_type) with
| Var { v_read = AccInline; v_write = AccNever }, _ ->
let unknown() =
print_endline
("Unknown method type "
^ join_class_path class_def.cl_path "."
^ "." ^ field.cf_name)
in
let map_args_ret f = match follow_with_coro field.cf_type with
| Coro(args,ret) -> f args ret
| NotCoro (TFun(args,ret)) -> f args ret
| _ -> unknown ()
in
match field.cf_kind with
| Var { v_read = AccInline; v_write = AccNever } ->
script#writeOpLine IaInline
| Var v, _ ->
| Var v->
let mode_code mode =
match mode with
| AccNormal | AccCtor -> IaAccessNormal
Expand All @@ -1836,23 +1847,24 @@ let generate_script_class common_ctx script class_def =
let isExtern = not (is_physical_field field) in
script#var (mode_code v.v_read) (mode_code v.v_write) isExtern isStatic
field.cf_name field.cf_type field.cf_expr
| Method MethDynamic, TFun (args, ret) ->
script#func isStatic true field.cf_name ret args
(has_class_flag class_def CInterface)
field.cf_expr field.cf_pos
| Method _, TFun (args, ret) when field.cf_name = "new" ->
script#func true false "new"
(TInst (class_def, []))
args false field.cf_expr field.cf_pos
| Method _, TFun (args, ret) ->
script#func isStatic false field.cf_name ret args
(has_class_flag class_def CInterface)
field.cf_expr field.cf_pos
| Method _, _ ->
print_endline
("Unknown method type "
^ join_class_path class_def.cl_path "."
^ "." ^ field.cf_name)
| Method MethDynamic ->
map_args_ret (fun args ret ->
script#func isStatic true field.cf_name ret args
(has_class_flag class_def CInterface)
field.cf_expr field.cf_pos
)
| Method _ when field.cf_name = "new" ->
map_args_ret (fun args ret ->
script#func true false "new"
(TInst (class_def, []))
args false field.cf_expr field.cf_pos
)
| Method _ ->
map_args_ret (fun args ret ->
script#func isStatic false field.cf_name ret args
(has_class_flag class_def CInterface)
field.cf_expr field.cf_pos
)
in
(match class_def.cl_constructor with
| Some field -> generate_field true field
Expand Down
3 changes: 2 additions & 1 deletion std/cpp/cppia/HostClasses.hx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class HostClasses {
"haxe.Int64",
"haxe.Int32",
"haxe.Serializer",
"haxe.Timer",
"haxe.Unserializer",
"haxe.ds.ArraySort",
"haxe.ds.GenericStack",
Expand Down Expand Up @@ -183,7 +184,7 @@ class HostClasses {
externs.set("sys.net._Socket.SocketOutput", true);
externs.set("sys.ssl._Socket.SocketInput", true);
externs.set("sys.ssl._Socket.SocketOutput", true);
externs.set("sys.thread._Thread.HaxeThread",true);
externs.set("sys.thread._Thread.HaxeThread", true);
externs.set("haxe.ds.TreeNode", true);
externs.set("haxe.xml.XmlParserException", true);
for (e in classes)
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/Timer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Timer {
*
* The precision and epoch of the timer is platform defined.
*/
public static inline function milliseconds():Int64 {
public static #if !cppia inline #end function milliseconds():Int64 {
#if flash
return flash.Lib.getTimer();
#elseif js
Expand Down
2 changes: 1 addition & 1 deletion tests/runci/targets/Cpp.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Cpp {
final path = getHaxelibPath("hxcpp");
infoMsg('hxcpp has already been installed in $path.');
} catch(e:Dynamic) {
haxelibInstallGit("HaxeFoundation", "hxcpp", true);
haxelibInstallGit("tobil4sk", "hxcpp", "fix/missing-jit-exception-checks", true);
final oldDir = Sys.getCwd();
changeDirectory(getHaxelibPath("hxcpp") + "tools/hxcpp/");
runCommand("haxe", ["-D", "source-header=''", "compile.hxml"]);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/unit/TestMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function main() {
new TestFieldVariance(),
new TestConstrainedMonomorphs(),
new TestDefaultTypeParameters(),
#if (!flash && !hl && !cppia)
#if (!flash && !hl)
new TestCoroutines(),
#end
// new TestUnspecified(),
Expand Down
Loading