Skip to content

Commit

Permalink
Add beam dump
Browse files Browse the repository at this point in the history
  • Loading branch information
davoclavo committed Oct 17, 2016
1 parent 91636e1 commit 8e5f7b3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
30 changes: 19 additions & 11 deletions src/elmer_compiler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ compile_elmo_file(ElmoFile, Output) ->
Erl = elmer_to_erl:from_file(ElmoFile),
dump(Output, ElmoFile, Erl).

dump(absform, Filename, Erl) ->
{Filename, Erl};
dump(absform, ElmoFile, Erl) ->
{ElmoFile, Erl};

dump(erlsrc, Filename, Erl) ->
dump(erlsrc, ElmoFile, Erl) ->
Src = lists:map(fun erl_pp:form/1, Erl),
Bin = erlang:iolist_to_binary(Src),
{Filename, Bin};

dump(binary, Filename, Erl) ->
Bin = compile:forms(Erl, [report_errors, report_warnings]),
{Filename, Bin};

dump(stdout, Filename, Erl) ->
{ElmoFile, Bin};

dump({beam, OutputDir}, ElmoFile, Erl) ->
io:format("~s~n", [ElmoFile]),
%% io:format("~p~n", [Erl]),
{ok, Module, Bin} = compile:forms(Erl, [report_errors, report_warnings]),
%% OutputFilename = filename:basename(ElmoFile, ".elmo") ++ ".beam",
OutputFilename = filename:basename(ElmoFile, ".elmo") ++ ".beam",
OutputFilepath = filename:join(filename:absname(OutputDir), OutputFilename),
io:format("~s~n", [OutputFilepath]),
io:format("~s~n", [Module]),
ok = file:write_file(OutputFilepath, io_lib:fwrite("~p.\n", [Bin])),
{ElmoFile, Bin};

dump(stdout, ElmoFile, Erl) ->
io:format("-----~n|~s~n-----~n~s~n", [
Filename,
ElmoFile,
lists:concat(lists:map(fun erl_pp:form/1, Erl))]).

2 changes: 1 addition & 1 deletion src/elmer_to_erl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ compile(?JSON_DEF(Name, Value), Elmo = #elmo{ defs = Defs }) ->
Def = to_erl({def, Name, to_erl(Value)}),
Elmo#elmo{ defs = [Def | Defs]};

compile(?JSON_TAILDEF(Name, Args, Content), Elmo = #elmo{ defs = Defs })->
compile(?JSON_TAILDEF(Name, Args, Content), Elmo = #elmo{ defs = Defs }) ->
VArgs = [{var, ?ELINE, elmer_util:var(A)} || A <- Args],
Fun = {'fun', ?ELINE, {clauses, [{clause, ?ELINE, VArgs, [], exps(to_erl(Content))}]}},
Def = to_erl({def, Name, ?ELMER_PARTIAL(Fun, length(Args))}),
Expand Down
5 changes: 0 additions & 5 deletions test/elmer_to_erl_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,5 @@ compiles_ImportExposing_testPending() ->
compiles_TailDef_test() ->
assert_elm_compiles_to_erl("TailDef").

runs_RunExample_test() ->
elm_load_module("RunExample"),
Result = 'Elm.RunExample':greet(),
?assertEqual(<<"Howdy">>, Result).

-endif. %% TEST

3 changes: 1 addition & 2 deletions test/native_elmer_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ core_build_filepath(ElmModuleName) ->
?CORE_BUILD_DIR ++ "/" ++ ElmModuleName ++ ".elmo".

elm_load_module(ElmModuleName, CoreModuleName) ->
Compiled = elm_compile(ElmModuleName, binary),
Compiled = elm_compile(ElmModuleName, {beam, "build"}),
UserElmoFileName = user_build_filepath(ElmModuleName),
{ok, Module, CompiledBinary} = proplists:get_value(UserElmoFileName, Compiled, elm_not_compiled),
{module, Module} = code:load_binary(Module, ElmModuleName, CompiledBinary),
Expand All @@ -41,7 +41,6 @@ elm_load_module(ElmModuleName, CoreModuleName) ->
runs_RunExample_test() ->
elm_load_module("RunExample", "Basics"),
%% TODO Figure out where to put Native modules
%% TODO Namespace loaded modules to 'Elm.ModuleName'
Result = ('Elm.RunExample':greet())([<<"doodie">>]),
?assertEqual(<<"Howdy, doodie">>, Result),
Result2 = ('Elm.Native.Utils':append())([[1,2],[3,4]]),
Expand Down

0 comments on commit 8e5f7b3

Please sign in to comment.