Eshell V5.10.2 (abort with ^G) 1> Code = "-module(t).\n-export([say/0]).\n\nsay() -> \"Hello world!!\". ". "-module(t).\n-export([say/0]).\n\nsay() -> \"Hello world!!\". " 2> {ok,Tokens,_} =erl_scan:string(Code). {ok,[{'-',1}, {atom,1,module}, {'(',1}, {atom,1,t}, {')',1}, {dot,1}, {'-',2}, {atom,2,export}, {'(',2}, {'[',2}, {atom,2,say}, {'/',2}, {integer,2,0}, {']',2}, {')',2}, {dot,2}, {atom,4,say}, {'(',4}, {')',4}, {'->',4}, {string,4,"Hello world!!"}, {dot,4}], 4}
4> erl_scan:tokens([],Code,1). {done,{ok,[{'-',1}, {atom,1,module}, {'(',1}, {atom,1,t}, {')',1}, {dot,1}], 2}, "-export([say/0]).\n\nsay() -> \"Hello world!!\". "}
Eshell V5.10.2 (abort with ^G) 1> Code = "-module(t).\n-export([say/0]).\n\nsay() -> \"Hello world!!\". ". "-module(t).\n-export([say/0]).\n\nsay() -> \"Hello world!!\". " 2> dynamic_compile:load_from_string(Code). {module,t} 3> t:say(). "Hello world!!" 4>
Eshell V5.10.2 (abort with ^G) 1> M = erl_syntax:attribute(erl_syntax:atom(module),[erl_syntax:atom(t)]). {tree,attribute, {attr,0,[],none}, {attribute,{tree,atom,{attr,0,[],none},module}, [{tree,atom,{attr,0,[],none},t}]}} 2> MF = erl_syntax:revert(M). {attribute,0,module,t} 3> E = erl_syntax:attribute(erl_syntax:atom(export),[erl_syntax:list([erl_syntax:arity_qualifier(erl_syntax:atom(say),erl_syntax:integer(0))])]). {tree,attribute, {attr,0,[],none}, {attribute, {tree,atom,{attr,0,[],none},export}, [{tree,list, {attr,0,[],none}, {list, [{tree,arity_qualifier, {attr,0,[],none}, {arity_qualifier, {tree,atom,{attr,0,[],none},say}, {tree,integer,{attr,0,[],none},0}}}], none}}]}} 4> ExportForm = erl_syntax:revert(E). {attribute,0,export,[{say,0}]} 5> 5> 5> Clause= erl_syntax:clause([],[],[erl_syntax:atom(hello_world)]). {tree,clause, {attr,0,[],none}, {clause,[],none,[{tree,atom,{attr,0,[],none},hello_world}]}} 6> 6> Function = erl_syntax:function(erl_syntax:atom(say),[Clause]). {tree,function, {attr,0,[],none}, {func,{tree,atom,{attr,0,[],none},say}, [{tree,clause, {attr,0,[],none}, {clause,[],none, [{tree,atom,{attr,0,[],none},hello_world}]}}]}} 7> FunctionForm = erl_syntax:revert(Function). {function,0,say,0,[{clause,0,[],[],[{atom,0,hello_world}]}]} 8> {ok, Mod, Bin1} = compile:forms([MF,ExportForm, FunctionForm]). {ok,t, <<70,79,82,49,0,0,1,208,66,69,65,77,65,116,111,109,0,0,0, 57,0,0,0,6,1,116,...>>} 9> t:say(). ** exception error: undefined function t:say/0 10> code:load_binary(Mod, [], Bin1). {module,t} 11> t:say(). hello_world 12>
test_smerl() -> M1 = smerl:new(foo), {ok, M2} = smerl:add_func(M1, "bar() -> 1 + 1."), smerl:compile(M2), foo:bar(), % returns 2`` smerl:has_func(M2, bar, 0). % returns true
-module(print_form). -export([parse_transform/2]). parse_transform(Forms, _Options) -> io:format("forms: ~p~n", [Forms]), Forms.
[root@nimbus demo]# cat a.erl -module(a). -compile({parse_transform,print_form}). -export([test/0]). test()-> "hello world!". [root@nimbus demo]# erlc -o . -pa . a.erl forms: [{attribute,1,file,{"a.erl",1}}, {attribute,1,module,a}, {attribute,3,export,[{test,0}]}, {function,5,test,0,[{clause,5,[],[],[{string,6,"hello world!"}]}]}, {eof,10}]