Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:26
erlang
2562-fixup-stdlib-list-local-functions-and-type...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2562-fixup-stdlib-list-local-functions-and-types.patch of Package erlang
From a1c802f001899e982b224a042ba6d7b3f05128d6 Mon Sep 17 00:00:00 2001 From: frazze-jobb <frazze@erlang.org> Date: Wed, 29 Nov 2023 21:53:50 +0100 Subject: [PATCH 2/2] fixup! stdlib: list local functions and types --- lib/stdlib/src/edlin_expand.erl | 9 ++++++--- lib/stdlib/src/shell.erl | 25 ++++++++++++++----------- lib/stdlib/test/shell_SUITE.erl | 30 ++++++++++++++++++------------ 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl index 169e3cea86..7841e3df74 100644 --- a/lib/stdlib/src/edlin_expand.erl +++ b/lib/stdlib/src/edlin_expand.erl @@ -633,18 +633,21 @@ expand_filepath(PathPrefix, Word) -> end. shell(Fun) -> - case shell:local_func(list_to_atom(Fun)) of + {ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun), + case shell:local_func(Fun1) of true -> "shell"; false -> "user_defined" end. shell_default_or_bif(Fun) -> - case lists:member(list_to_atom(Fun), [E || {E,_}<-get_exports(shell_default)]) of + {ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun), + case lists:member(Fun1, [E || {E,_}<-get_exports(shell_default)]) of true -> "shell_default"; _ -> bif(Fun) end. bif(Fun) -> - case lists:member(list_to_atom(Fun), [E || {E,A}<-get_exports(erlang), erl_internal:bif(E,A)]) of + {ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun), + case lists:member(Fun1, [E || {E,A}<-get_exports(erlang), erl_internal:bif(E,A)]) of true -> "erlang"; _ -> shell(Fun) end. diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl index 146ee97bf8..96b1f345cc 100644 --- a/lib/stdlib/src/shell.erl +++ b/lib/stdlib/src/shell.erl @@ -316,12 +316,13 @@ get_command(Prompt, Eval, Bs, RT, FT, Ds) -> [{atom, _, FunName}, {'(', _}|_] -> case erl_parse:parse_form(Toks) of {ok, FunDef} -> - case {edlin_expand:shell_default_or_bif(atom_to_list(FunName)), shell:local_func(FunName)} of + FunName1 = lists:flatten(io_lib:fwrite("~tw",[FunName])), + case {edlin_expand:shell_default_or_bif(FunName1), shell:local_func(FunName1)} of {"user_defined", false} -> FunDef1 = lists:flatten(escape_quotes(lists:flatten(erl_pp:form(FunDef)))), FakeLine = reconstruct(FunDef, FunName), {done, {ok, FakeResult, _}, _} = erl_scan:tokens( - [], "fd("++ atom_to_list(FunName) ++ ", " ++ FakeLine ++ ", \"" ++ FunDef1 ++ "\").\n", + [], "fd("++ FunName1 ++ ", " ++ FakeLine ++ ", \"" ++ FunDef1 ++ "\").\n", {1,1}, [text,{reserved_word_fun,fun erl_scan:reserved_word/1}]), erl_eval:extended_parse_exprs(FakeResult); _ -> erl_eval:extended_parse_exprs(Toks) @@ -1145,9 +1146,11 @@ local_func(lr, [], Bs, _Shell, _RT, FT, _Lf, _Ef) -> local_func(save_module, [{string,_,PathToFile}], Bs, _Shell, _RT, FT, _Lf, _Ef) -> [_Path, FileName] = string:split("/"++PathToFile, "/", trailing), [Module, _] = string:split(FileName, ".", leading), + Module1 = io_lib:fwrite("~tw",[list_to_atom(Module)]), + Exports = [lists:flatten(io_lib:fwrite("~tw",[F]))++"/"++integer_to_list(A)||{F,A}<-local_defined_functions(FT)], Output = ( - "-module("++Module++").\n\n" ++ - "-export(["++[atom_to_list(F)++"/"++integer_to_list(A)||{F,A}<-local_defined_functions(FT)]++"]).\n\n"++ + "-module("++Module1++").\n\n" ++ + "-export(["++lists:join(",",Exports)++"]).\n\n"++ local_types(FT) ++ local_records(FT) ++ local_functions(FT) @@ -1205,15 +1208,15 @@ local_func(ff, [], Bs, _Shell, _RT, FT, _Lf, _Ef) -> ets:select_delete(FT, [{{{function_type_def, '_'},'_'}, [],[true]}]), ets:select_delete(FT, [{{{function_type, '_'},'_'}, [],[true]}]), {value,ok,Bs}; -local_func(ff, [{tuple, _, [{atom, _, F}, {integer,_,A}]}], Bs, _Shell, _RT, FT, _Lf, _Ef) -> +local_func(ff, [{atom, _, F}, {integer,_,A}], Bs, _Shell, _RT, FT, _Lf, _Ef) -> M = shell_default, ets:select_delete(FT, [{{{function_def, {M, F, A}},'_'}, [],[true]}]), ets:select_delete(FT, [{{{function, {M, F, A}},'_'}, [],[true]}]), ets:select_delete(FT, [{{{function_type_def, {M, F, A}},'_'}, [],[true]}]), ets:select_delete(FT, [{{{function_type, {M, F, A}},'_'}, [],[true]}]), {value,ok,Bs}; -local_func(ff, [_], _Bs, _Shell, _RT, _FT, _Lf, _Ef) -> - erlang:raise(error, function_clause, [{shell,ff,1}]); +local_func(ff, [_,_], _Bs, _Shell, _RT, _FT, _Lf, _Ef) -> + erlang:raise(error, function_clause, [{shell,ff,2}]); local_func(td, [{string, _, TypeDef}], Bs, _Shell, _RT, FT, _Lf, _Ef) -> case erl_scan:tokens([], TypeDef, {1,1}, [text,{reserved_word_fun,fun erl_scan:reserved_word/1}]) of {done, {ok, Toks, _}, _} -> @@ -1340,18 +1343,18 @@ local_functions_and_specs(FT) -> Keys1 = maps:keys(Output_functions), Keys2 = maps:keys(Output_function_specs), Keys = lists:uniq(Keys1 ++ Keys2), - lists:join($\n,lists:map(fun(Key) -> + string:trim(lists:join($\n,lists:map(fun(Key) -> Spec = maps:get(Key, Output_function_specs, nospec), Def = maps:get(Key, Output_functions, nodef), case {Spec, Def} of {nospec, _} -> Def; {_, nodef} -> {FunName, Arity} = Key, - Spec ++ "%% " ++ atom_to_list(FunName) ++ "/" ++ integer_to_list(Arity) ++ " not implemented"; + Spec ++ "%% " ++ lists:flatten(io_lib:fwrite("~tw",[FunName]))++ "/" ++ integer_to_list(Arity) ++ " not implemented"; {_, _} -> Spec ++ Def end end, - Keys)). + Keys))). local_defined_functions(FT) -> [{F, A} ||{{function_def,{_, F, A}},_} <- ets:tab2list(FT)]. local_functions(FT) -> @@ -1375,7 +1378,7 @@ local_records(FT) -> lists:join($\n, [RecDef||{{record_def, _},RecDef} <- ets:tab2list(FT)]). write_and_compile_module(PathToFile, Output) -> - case file:write_file(PathToFile, Output) of + case file:write_file(PathToFile, unicode:characters_to_binary(Output)) of ok -> c:c(PathToFile); Error -> Error end. diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl index 6be501495a..d9b2c07879 100644 --- a/lib/stdlib/test/shell_SUITE.erl +++ b/lib/stdlib/test/shell_SUITE.erl @@ -193,7 +193,7 @@ LocalFuncs = shell:local_func(), LocalFuncs2 = [ <<"A = 1.\nv(1).">>, <<"h().">>, <<"b().">>, <<"f().">>, <<"f(A).">>, - <<"fl()">>, <<"ff()">>, <<"ff({my_func,1})">>, <<"lf()">>, <<"lr()">>, <<"lt()">>, + <<"fl()">>, <<"ff()">>, <<"ff(my_func,1)">>, <<"lf()">>, <<"lr()">>, <<"lt()">>, <<"rd(foo,{bar}).">>, <<"rf().">>, <<"rf(foo).">>, <<"rl().">>, <<"rl(foo).">>, <<"rp([hej]).">>, <<"rr(shell).">>, <<"rr(shell, shell_state).">>, <<"rr(shell,shell_state,[]).">>, <<"tf()">>, <<"tf(hej)">>, <<"save_module(\"src/my_module.erl\")">>, <<"history(20).">>, <<"results(20).">>, <<"catch_exception(0).">>], @@ -658,25 +658,31 @@ local_definitions_save_to_module_and_forget(Config) when is_list(Config) -> "ok.\n-record(svej,{a}).\n.\nok.\n" = t( <<"-record(svej, {a}).\n" "lr().">>), - "ok.\nok.\n-spec my_func(X) -> X.\nmy_func(X) ->\n X.\n\n.\nok.\n" = t( + "ok.\nok.\n-spec my_func(X) -> X.\nmy_func(X) ->\n X.\n.\nok.\n" = t( <<"-spec my_func(X) -> X.\n" "my_func(X) -> X.\n" "lf().">>), %% Save local definitions to a module - "ok.\nok.\nok.\nok.\n{ok,my_module}.\n" = t( + U = unicode:characters_to_binary("😊"), + "ok.\nok.\nok.\nok.\nok.\nok.\n{ok,'MY_MODULE'}.\n" = t({ <<"-type hej() :: integer().\n" "-record(svej, {a :: hej()}).\n" - "-spec my_func(X) -> X.\n my_func(#svej{a=A}) -> A.\n" - "save_module(\"my_module.erl\").">>), + "my_func(#svej{a=A}) -> A.\n" + "-spec not_implemented(X) -> X.\n" + "-spec 'my_func",U/binary,"'(X) -> X.\n" + "'my_func",U/binary,"'(#svej{a=A}) -> A.\n" + "save_module(\"MY_MODULE.erl\").">>, unicode}), %% Read back the newly created module - {ok,<<"-module(my_module).\n\n" - "-export([my_func/1]).\n\n" + {ok,<<"-module('MY_MODULE').\n\n" + "-export([my_func/1,'my_func",240,159,152,138,"'/1]).\n\n" "-type hej() :: integer().\n" "-record(svej,{a :: hej()}).\n" - "-spec my_func(X) -> X.\n" "my_func(#svej{a = A}) ->\n" - " A.\n">>} = file:read_file("my_module.erl"), - file:delete("my_module.erl"), + " A.\n\n" + "-spec 'my_func",240,159,152,138,"'(X) -> X.\n" + "'my_func",240,159,152,138,"'(#svej{a = A}) ->\n" + " A.\n">>} = file:read_file("MY_MODULE.erl"), + file:delete("MY_MODULE.erl"), %% Forget one locally defined type "ok.\nok.\nok.\n-type svej() :: integer().\n.\nok.\n" = t( @@ -691,12 +697,12 @@ local_definitions_save_to_module_and_forget(Config) when is_list(Config) -> "rf(svej).\n" "lr().">>), %% Forget one locally defined function - "ok.\nok.\nok.\nok.\nok.\n-spec my_func2(X) -> X.\nmy_func2(X) ->\n X.\n\n.\nok.\n" = t( + "ok.\nok.\nok.\nok.\nok.\n-spec my_func2(X) -> X.\nmy_func2(X) ->\n X.\n.\nok.\n" = t( <<"-spec my_func(X) -> X.\n" "my_func(X) -> X.\n" "-spec my_func2(X) -> X.\n" "my_func2(X) -> X.\n" - "ff({my_func,1}).\n" + "ff(my_func,1).\n" "lf().">>), %% Forget all locally defined types "ok.\nok.\nok.\n.\nok.\n" = t( -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor