Files
uwrap/include/proxy/proxy2cs.wrp

88 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

2020-07-26 21:59:32 -04:00
import proxy.proxy;
import cs.wrappers;
2020-08-20 23:33:39 -04:00
function native_type (type) do
pick "System.IntPtr";
match type("int32") pick "int";
match type("void") pick "void";
end;
function cs_type (type) do
pick type;
match type("int32") pick "int";
match type("void") pick "void";
end;
2020-08-04 19:10:01 -04:00
template generate_proxy2cs pick origin do
match not parent ()
2020-07-26 21:59:32 -04:00
wrap w: w_Unit (name => child (name ("name")).value);
match parent (\ name ("functions"))
do
2020-08-20 23:33:39 -04:00
var type: text => child (\ name ("type")).value;
var ret_type_native: text => native_type (type);
var ret_type_cs: text => cs_type (type);
2020-07-26 21:59:32 -04:00
wrap n: w_FunctionCall (
name => child (\ name ("name")).value,
2020-08-20 23:33:39 -04:00
returned_type => ret_type_cs,
2020-08-31 14:30:45 +02:00
call => defer (child (\ name ("symbol")).value & "("
& n.child (w_ParamCall ()).fold ("", @ & actual_value, @ & ", ") & ")"),
2020-07-26 21:59:32 -04:00
static => "static");
2020-08-31 14:30:45 +02:00
match type ("void") do
weave w: w_FunctionCall (call_stmt => defer ("\e<w.call>;"));
2020-08-20 23:33:39 -04:00
elsmatch type ("int32") do
weave w: w_FunctionCall (call_stmt => defer ("return \e<w.call>;"));
2020-08-20 23:33:39 -04:00
else
weave w: w_FunctionCall (
pre_call_decl => defer ("\e<ret_type_cs> res = new \e<ret_type_cs> ();"),
pre_call_stmt => defer ("res.handle = \e<w.call>;"),
2020-08-20 23:33:39 -04:00
call_stmt => "return res;"
);
end;
2020-07-26 21:59:32 -04:00
wrap w_DllImportFunction (
name => child (\ name ("symbol")).value,
returned_type => defer (ret_type_native),
2020-07-26 21:59:32 -04:00
static => "static");
end;
match parent (\ name ("parameters")) do
2020-08-20 23:33:39 -04:00
var type: text => child (\ name ("type")).value;
var ret_type_native: text => native_type (type);
var ret_type_cs: text => cs_type (type);
2020-07-26 21:59:32 -04:00
wrap w_ParamCall (
name => child (\ name ("name")).value,
type_expr => defer (ret_type_cs)
2020-08-20 23:33:39 -04:00
);
match type ("int32") do
weave w: w_ParamCall (
actual_value => defer ("\e<w.name>")
2020-08-20 23:33:39 -04:00
);
else
weave w: w_ParamCall (
actual_value => defer ("\e<w.name>.handle")
2020-08-20 23:33:39 -04:00
);
end;
wrap w_ParamDll (
name => child (\ name ("name")).value,
type_expr => ret_type_native
);
end;
match parent (\ name ("classes")) do
wrap w_Class (
name => child (\ name ("name")).value
2020-07-26 21:59:32 -04:00
);
end;
2020-08-04 19:10:01 -04:00
end;