Prepare for new repl #892

Merged
zxq9 merged 3 commits from repl-prep into master 2022-07-26 01:46:54 +09:00
2 changed files with 16 additions and 5 deletions

View File

@ -14,8 +14,13 @@
-export([ infer/1 -export([ infer/1
, infer/2 , infer/2
, unfold_types_in_type/2
, unfold_types_in_type/3 , unfold_types_in_type/3
, switch_scope/2
, pp_type/2 , pp_type/2
, lookup_env1/4
, name/1
, qname/1
]). ]).
-include("aeso_utils.hrl"). -include("aeso_utils.hrl").
@ -159,6 +164,10 @@
%% -- Environment manipulation ----------------------------------------------- %% -- Environment manipulation -----------------------------------------------
-spec switch_scope(qname(), env()) -> env().
switch_scope(Scope, Env) ->
Env#env{namespace = Scope}.
-spec push_scope(namespace | contract, aeso_syntax:con(), env()) -> env(). -spec push_scope(namespace | contract, aeso_syntax:con(), env()) -> env().
push_scope(Kind, Con, Env) -> push_scope(Kind, Con, Env) ->
Ann = aeso_syntax:get_ann(Con), Ann = aeso_syntax:get_ann(Con),
@ -403,7 +412,7 @@ lookup_env(Env, Kind, Ann, Name) ->
end end
end. end.
-spec lookup_env1(env(), type | term, aeso_syntax:ann(), qname()) -> false | {qname(), fun_info()}. -spec lookup_env1(env(), type | term, aeso_syntax:ann(), qname()) -> false | {qname(), fun_info() | type_info()}.
lookup_env1(#env{ namespace = Current, used_namespaces = UsedNamespaces, scopes = Scopes }, Kind, Ann, QName) -> lookup_env1(#env{ namespace = Current, used_namespaces = UsedNamespaces, scopes = Scopes }, Kind, Ann, QName) ->
Qual = lists:droplast(QName), Qual = lists:droplast(QName),
Name = lists:last(QName), Name = lists:last(QName),
@ -1586,13 +1595,13 @@ app_t(Ann, Name, Args) -> {app_t, Ann, Name, Args}.
lookup_name(Env, As, Name) -> lookup_name(Env, As, Name) ->
lookup_name(Env, As, Name, []). lookup_name(Env, As, Name, []).
lookup_name(Env = #env{ namespace = NS, current_function = {id, _, Fun} = CurFn }, As, Id, Options) -> lookup_name(Env = #env{ namespace = NS, current_function = CurFn }, As, Id, Options) ->
case lookup_env(Env, term, As, qname(Id)) of case lookup_env(Env, term, As, qname(Id)) of
false -> false ->
type_error({unbound_variable, Id}), type_error({unbound_variable, Id}),
{Id, fresh_uvar(As)}; {Id, fresh_uvar(As)};
{QId, {_, Ty}} -> {QId, {_, Ty}} ->
when_warning(warn_unused_variables, fun() -> used_variable(NS, Fun, QId) end), when_warning(warn_unused_variables, fun() -> used_variable(NS, name(CurFn), QId) end),
when_warning(warn_unused_functions, when_warning(warn_unused_functions,
fun() -> register_function_call(NS ++ qname(CurFn), QId) end), fun() -> register_function_call(NS ++ qname(CurFn), QId) end),
Freshen = proplists:get_value(freshen, Options, false), Freshen = proplists:get_value(freshen, Options, false),
@ -1633,7 +1642,8 @@ check_stateful_named_arg(_, _, _) -> ok.
check_entrypoints(Defs) -> check_entrypoints(Defs) ->
[ ensure_first_order_entrypoint(LetFun) [ ensure_first_order_entrypoint(LetFun)
|| LetFun <- Defs, || LetFun <- Defs,
aeso_syntax:get_ann(entrypoint, LetFun, false) ]. aeso_syntax:get_ann(entrypoint, LetFun, false),
get_option(allow_higher_order_entrypoints, false) =:= false ].
ensure_first_order_entrypoint({letfun, Ann, Id = {id, _, Name}, Args, Ret, _}) -> ensure_first_order_entrypoint({letfun, Ann, Id = {id, _, Name}, Args, Ret, _}) ->
[ ensure_first_order(ArgType, {higher_order_entrypoint, AnnArg, Id, {argument, ArgId, ArgType}}) [ ensure_first_order(ArgType, {higher_order_entrypoint, AnnArg, Id, {argument, ArgId, ArgType}})

View File

@ -26,7 +26,7 @@
-type ann_format() :: '?:' | hex | infix | prefix | elif. -type ann_format() :: '?:' | hex | infix | prefix | elif.
-type ann() :: [ {line, ann_line()} | {col, ann_col()} | {format, ann_format()} | {origin, ann_origin()} -type ann() :: [ {line, ann_line()} | {col, ann_col()} | {format, ann_format()} | {origin, ann_origin()}
| stateful | private | payable | main | interface]. | stateful | private | payable | main | interface | entrypoint].
-type name() :: string(). -type name() :: string().
-type id() :: {id, ann(), name()}. -type id() :: {id, ann(), name()}.
@ -42,6 +42,7 @@
| {contract_child, ann(), con(), [con()], [decl()]} | {contract_child, ann(), con(), [con()], [decl()]}
| {contract_interface, ann(), con(), [con()], [decl()]} | {contract_interface, ann(), con(), [con()], [decl()]}
| {namespace, ann(), con(), [decl()]} | {namespace, ann(), con(), [decl()]}
| {include, ann(), {string, ann(), string()}}
| {pragma, ann(), pragma()} | {pragma, ann(), pragma()}
| {type_decl, ann(), id(), [tvar()]} % Only for error msgs | {type_decl, ann(), id(), [tvar()]} % Only for error msgs
| {type_def, ann(), id(), [tvar()], typedef()} | {type_def, ann(), id(), [tvar()], typedef()}