Skip to content

Commit

Permalink
no more Module.concat
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoa-xu committed Jan 12, 2023
1 parent 09a9081 commit 9dbfde2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion c_src/modules/evision_mat_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static ERL_NIF_TERM _evision_make_mat_resource_into_map(ErlNifEnv *env, const cv
item_index++;

keys[item_index] = evision::nif::atom(env, "class");
values[item_index] = evision::nif::atom(env, "Mat");
values[item_index] = evision::nif::atom(env, "Elixir.Evision.Mat");
item_index++;

ERL_NIF_TERM map;
Expand Down
7 changes: 5 additions & 2 deletions lib/evision_structurise.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ defmodule Evision.Internal.Structurise do
def to_struct({:ok, ret}), do: to_struct_ok(ret)

def to_struct(ret = %{:class => module_name}) when is_atom(module_name) do
module = Module.concat([Evision, Atom.to_string(module_name)])
module.__to_struct__(ret)
if Code.ensure_loaded?(module_name) do
module_name.__to_struct__(ret)
else
ret
end
end

def to_struct(tuple) when is_tuple(tuple) do
Expand Down
6 changes: 3 additions & 3 deletions py_src/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def gen_code(self, codegen):
membertype=p.tp,
access=access_op,
storage_name=self.cname if self.issimple else "Ptr<{}>".format(self.cname),
elixir_module_name=get_elixir_module_name(self.cname, double_quote_if_has_dot=True).replace('"', '\\"')
elixir_module_name=get_elixir_module_name(self.cname)
))
else:
if self.issimple:
Expand All @@ -215,7 +215,7 @@ def gen_code(self, codegen):
access=access_op,
cname=self.cname,
storage_name=self.cname,
elixir_module_name=get_elixir_module_name(self.cname, double_quote_if_has_dot=True).replace('"', '\\"')
elixir_module_name=get_elixir_module_name(self.cname)
))
else:
getset_code.write(ET.gen_template_set_prop_cv_ptr.substitute(
Expand All @@ -225,7 +225,7 @@ def gen_code(self, codegen):
access=access_op,
cname=self.cname,
storage_name="Ptr<{}>".format(self.cname),
elixir_module_name=get_elixir_module_name(self.cname, double_quote_if_has_dot=True).replace('"', '\\"')
elixir_module_name=get_elixir_module_name(self.cname)
))
getset_inits.write(ET.gen_template_rw_prop_init.substitute(
name=self.name, member=pname,
Expand Down
10 changes: 5 additions & 5 deletions py_src/evision_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
alias __MODULE__, as: T
@doc false
def __to_struct__(cap = %{:class => :VideoCapture, :ref => ref}) do
def __to_struct__(cap = %{:class => Evision.VideoCapture, :ref => ref}) do
%T{
fps: cap.fps,
frame_count: cap.frame_count,
Expand All @@ -57,7 +57,7 @@ def __to_struct__(cap = %{:class => :VideoCapture, :ref => ref}) do
}
end
def __to_struct__({:ok, cap = %{:class => :VideoCapture}}) do
def __to_struct__({:ok, cap = %{:class => Evision.VideoCapture}}) do
{:ok, __to_struct__(cap)}
end
Expand All @@ -77,7 +77,7 @@ def __to_struct__(pass_through) do

generic_struct_template_elixir = Template(
' @typedoc """\n'
' Type that represents an `Evision.${elixir_module_name}` struct.\n\n'
' Type that represents an `${elixir_module_name}` struct.\n\n'
' - **ref**. `reference()`\n\n'
' The underlying erlang resource variable.\n\n'
' """\n'
Expand All @@ -89,11 +89,11 @@ def __to_struct__(pass_through) do
alias __MODULE__, as: T
@doc false
def __to_struct__({:ok, %{class: :${atom_elixir_module_name}, ref: ref}}) do
def __to_struct__({:ok, %{class: ${atom_elixir_module_name}, ref: ref}}) do
{:ok, %T{ref: ref}}
end
def __to_struct__(%{class: :${atom_elixir_module_name}, ref: ref}) do
def __to_struct__(%{class: ${atom_elixir_module_name}, ref: ref}) do
%T{
ref: ref
}
Expand Down
10 changes: 5 additions & 5 deletions py_src/evision_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ def load_nif do
code_ret_constructor = """ERL_NIF_TERM ret = enif_make_resource(env, self);
enif_release_resource(self);
bool success;
return evision_from_as_map<%s>(env, self->val, ret, "%s", success);"""
return evision_from_as_map<%s>(env, self->val, ret, "Elixir.Evision.%s", success);"""

code_ret_dnn_setter = Template("""bool success;
return evision_from_as_map<${storage_name} *>(env, _self_, self, "${elixir_module_name}", success)""")
return evision_from_as_map<${storage_name} *>(env, _self_, self, "Elixir.Evision.${elixir_module_name}", success)""")

elixir_property_getter = Template(""" @spec get_${property_name}(${self_spec}) :: ${prop_spec}
def get_${property_name}(self) do
Expand Down Expand Up @@ -493,7 +493,7 @@ def __enabled_modules__ do
if (evision_to_safe(env, argv[1], self_ptr->${member}, ArgInfo("${member}", false))) {
bool success;
return evision_from_as_map<${storage_name}>(env, *self_ptr, self, "${elixir_module_name}", success);
return evision_from_as_map<${storage_name}>(env, *self_ptr, self, "Elixir.Evision.${elixir_module_name}", success);
}
return failmsgp(env, "cannot assign new value, mismatched type?");
Expand All @@ -517,7 +517,7 @@ def __enabled_modules__ do
if (evision_to_safe(env, evision_get_kw(env, erl_terms, "${member}"), _self_${access}${member}, ArgInfo("${member}", false))) {
bool success;
return evision_from_as_map<${storage_name}>(env, _self_, self, "${elixir_module_name}", success);
return evision_from_as_map<${storage_name}>(env, _self_, self, "Elixir.Evision.${elixir_module_name}", success);
}
return failmsgp(env, "cannot assign new value, mismatched type?");
Expand All @@ -540,7 +540,7 @@ def __enabled_modules__ do
if (evision_to_safe(env, argv[1], _self_algo_${access}${member}, ArgInfo("${member}", false))) {
bool success;
return evision_from_as_map<${storage_name}>(env, *self_ptr, self, "${elixir_module_name}", success);
return evision_from_as_map<${storage_name}>(env, *self_ptr, self, "Elixir.Evision.${elixir_module_name}", success);
}
return failmsgp(env, "cannot assign new value, mismatched type?");
Expand Down
6 changes: 3 additions & 3 deletions py_src/func_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def gen_code(self, codegen):
if not v.isphantom and ismethod and not self.is_static:
module_name = get_elixir_module_name(selfinfo.cname)
code_ret = "bool success;\n" \
f" return evision_from_as_map(env, _self_, self, \"{module_name}\", success)"
f" return evision_from_as_map(env, _self_, self, \"Elixir.Evision.{module_name}\", success)"
elif len(v.py_outlist) == 1:
if self.isconstructor:
selftype = selfinfo.cname
Expand All @@ -385,14 +385,14 @@ def gen_code(self, codegen):
elixir_module_name = get_elixir_module_name(selfinfo.cname)
code_ret = f"""return evision_from(env, {aname});"""
# bool success;
# return evision_from_as_map<decltype({aname})>(env, {aname}, retval_term, "{elixir_module_name}", success)"""
# return evision_from_as_map<decltype({aname})>(env, {aname}, retval_term, "Elixir.Evision.{elixir_module_name}", success)"""
# elixir_module_name = get_elixir_module_name(selfinfo.cname)
# selftype = selfinfo.cname
# # if not selfinfo.issimple:
# # selftype = "Ptr<{}>".format(selfinfo.cname)
# code_ret = f"""bool success;
# ERL_NIF_TERM retval_term = evision_from(env, {aname});
# return evision_from_as_map<{selftype}>(env, {aname}, retval_term, "{elixir_module_name}", success)"""
# return evision_from_as_map<{selftype}>(env, {aname}, retval_term, "Elixir.Evision.{elixir_module_name}", success)"""
else:
code_ret = f"return evision_from(env, {aname})"
else:
Expand Down
6 changes: 2 additions & 4 deletions py_src/gen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,8 @@ def get_module_writer(self, module_name, wname, name, is_ns):

if elixir_module_name not in evision_structrised_classes:
mapped_elixir_module_name = get_elixir_module_name(elixir_module_name)
atom_elixir_module_name = mapped_elixir_module_name
atom_elixir_module_name = f"Evision.{mapped_elixir_module_name}"
atom_erlang_module_name = elixir_module_name
if '.' in atom_elixir_module_name:
atom_elixir_module_name = f'"{atom_elixir_module_name}"'
module_file_generator.write_elixir(
ES.generic_struct_template_elixir.substitute(
atom_elixir_module_name=atom_elixir_module_name,
Expand All @@ -392,7 +390,7 @@ def get_module_writer(self, module_name, wname, name, is_ns):
atom_erlang_module_name = f"evision_{atom_erlang_module_name}"
module_file_generator.write_erlang(
ES.generic_struct_template_erlang.substitute(
atom_elixir_module_name=mapped_elixir_module_name,
atom_elixir_module_name=f"Elixir.{mapped_elixir_module_name}",
atom_erlang_module_name=atom_erlang_module_name
)
)
Expand Down
2 changes: 1 addition & 1 deletion py_src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def get_elixir_module_name(cname, double_quote_if_has_dot=False):
module_name = module_name_classname[0]
if module_name in module_name_map:
mapped_module_name = module_name_map[module_name]
cname = "cv::" + mapped_module_name + cname[len(module_name):]
cname = "cv::" + mapped_module_name + cname[4+len(module_name):]
# elif cname.startswith("cv::") and 'a' <= cname[4] <= 'z':
# print("warning cname=", cname)

Expand Down

0 comments on commit 9dbfde2

Please sign in to comment.