Skip to content

Commit

Permalink
fixed erlang types
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoa-xu committed Jun 8, 2024
1 parent 59795c9 commit c94897a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion py_src/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def gen_def(self, codegen, evision_modules, evision_erlang_hrl):
module_file_generator.write_erlang(f'-module({atom_erlang_module_name.lower()}).\n-compile(nowarn_export_all).\n-compile([export_all]).\n-include("evision.hrl").\n\n')
module_file_generator.write_erlang(
ES.generic_struct_template_erlang.substitute(
atom_elixir_module_name=atom_elixir_module_name.replace('"', ''),
atom_elixir_module_name=f"Elixir1.{atom_elixir_module_name.replace('"', '')}",
atom_erlang_module_name=atom_erlang_module_name
)
)
Expand Down
4 changes: 2 additions & 2 deletions py_src/gen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def clear(self):
self.evision_constant_elixir.write(ET.gen_cv_types_elixir)

self.evision_erlang.write('-module(evision).\n-compile(nowarn_export_all).\n-compile([export_all]).\n-include("evision.hrl").\n\n')
self.evision_erlang.write('\'__to_struct__\'(Any) ->\n evision_internal_structurise:from_struct(Any).\n\n')
self.evision_erlang.write('\'__to_struct__\'(Any) ->\n evision_internal_structurise:to_struct(Any).\n\n')

self.evision_constant_erlang.write('-module(evision_constant).\n-compile(nowarn_export_all).\n-compile([export_all]).\n\n')

Expand Down Expand Up @@ -442,7 +442,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=f"Elixir.{mapped_elixir_module_name}",
atom_elixir_module_name=f"Elixir.{atom_elixir_module_name}",
atom_erlang_module_name=atom_erlang_module_name
)
)
Expand Down
17 changes: 12 additions & 5 deletions src/evision_internal_structurise.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ to_struct(Ret) when is_map(Ret) ->
case maps:is_key(class, Ret) of
true ->
Class = maps:get(class, Ret),
Module = list_to_atom(string:to_lower(io_lib:fwrite("evision_~s", [Class]))),
case erlang:function_exported(Module, '__to_struct__', 1) of
true ->
Module:'__to_struct__'(Ret);
false ->
ClassName = atom_to_list(Class),
Module = case string:prefix(ClassName, "Elixir.Evision.") of
nomatch ->
list_to_atom(string:to_lower(io_lib:fwrite("evision_~s", [ClassName])));
Name ->
list_to_atom(string:to_lower("evision_" ++ Name))
end,
try Module:'__to_struct__'(Ret) of
Result ->
Result
catch
_ ->
Ret
end;
false ->
Expand Down
2 changes: 1 addition & 1 deletion src/evision_mat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-include("generated/evision.hrl").

'__to_struct__'(#{class := 'Mat', channels := Channels, dims := Dims, type := Type, raw_type := RawType, shape := Shape, ref := Ref}) ->
'__to_struct__'(#{class := 'Elixir.Evision.Mat', channels := Channels, dims := Dims, type := Type, raw_type := RawType, shape := Shape, ref := Ref}) ->
#evision_mat{
channels = Channels,
dims = Dims,
Expand Down

0 comments on commit c94897a

Please sign in to comment.