Prepared for REPL usage
Exposed expr parsing ets init in constant Exposing and fixing exposed expr This will be squashed either Expose letdef Error handling exposed autoimport remove unnecessary changes Fix types
This commit is contained in:
parent
34c10e1518
commit
9cfc620a6b
@ -12,7 +12,11 @@
|
|||||||
|
|
||||||
-module(aeso_ast_infer_types).
|
-module(aeso_ast_infer_types).
|
||||||
|
|
||||||
-export([infer/1, infer/2, unfold_types_in_type/3]).
|
-export([ infer/1
|
||||||
|
, infer/2
|
||||||
|
, unfold_types_in_type/3
|
||||||
|
, pp_type/2
|
||||||
|
]).
|
||||||
|
|
||||||
-type utype() :: {fun_t, aeso_syntax:ann(), named_args_t(), [utype()], utype()}
|
-type utype() :: {fun_t, aeso_syntax:ann(), named_args_t(), [utype()], utype()}
|
||||||
| {app_t, aeso_syntax:ann(), utype(), [utype()]}
|
| {app_t, aeso_syntax:ann(), utype(), [utype()]}
|
||||||
|
@ -650,8 +650,9 @@ pp_fate_type(T) -> io_lib:format("~w", [T]).
|
|||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
||||||
|
-spec sophia_type_to_typerep(string()) -> {error, bad_type} | {ok, aeb_aevm_data:type()}.
|
||||||
sophia_type_to_typerep(String) ->
|
sophia_type_to_typerep(String) ->
|
||||||
{ok, Ast} = aeso_parser:type(String),
|
Ast = aeso_parser:type(String),
|
||||||
try aeso_ast_to_icode:ast_typerep(Ast) of
|
try aeso_ast_to_icode:ast_typerep(Ast) of
|
||||||
Type -> {ok, Type}
|
Type -> {ok, Type}
|
||||||
catch _:_ -> {error, bad_type}
|
catch _:_ -> {error, bad_type}
|
||||||
|
@ -7,16 +7,25 @@
|
|||||||
-export([string/1,
|
-export([string/1,
|
||||||
string/2,
|
string/2,
|
||||||
string/3,
|
string/3,
|
||||||
|
auto_imports/1,
|
||||||
hash_include/2,
|
hash_include/2,
|
||||||
|
body/1,
|
||||||
|
letdef/1,
|
||||||
type/1]).
|
type/1]).
|
||||||
|
|
||||||
-include("aeso_parse_lib.hrl").
|
-include("aeso_parse_lib.hrl").
|
||||||
-import(aeso_parse_lib, [current_file/0, set_current_file/1]).
|
-import(aeso_parse_lib, [current_file/0, set_current_file/1]).
|
||||||
|
|
||||||
-type parse_result() :: aeso_syntax:ast() | none().
|
-type parse_result() :: aeso_syntax:ast() | {aeso_syntax:ast(), sets:set(include_hash())} | none().
|
||||||
|
|
||||||
-type include_hash() :: {string(), binary()}.
|
-type include_hash() :: {string(), binary()}.
|
||||||
|
|
||||||
|
|
||||||
|
escape_errors({ok, Ok}) ->
|
||||||
|
Ok;
|
||||||
|
escape_errors({error, Err}) ->
|
||||||
|
parse_error(Err).
|
||||||
|
|
||||||
-spec string(string()) -> parse_result().
|
-spec string(string()) -> parse_result().
|
||||||
string(String) ->
|
string(String) ->
|
||||||
string(String, sets:new(), []).
|
string(String, sets:new(), []).
|
||||||
@ -30,21 +39,20 @@ string(String, Opts) ->
|
|||||||
|
|
||||||
-spec string(string(), sets:set(include_hash()), aeso_compiler:options()) -> parse_result().
|
-spec string(string(), sets:set(include_hash()), aeso_compiler:options()) -> parse_result().
|
||||||
string(String, Included, Opts) ->
|
string(String, Included, Opts) ->
|
||||||
case parse_and_scan(file(), String, Opts) of
|
AST = escape_errors(parse_and_scan(file(), String, Opts)),
|
||||||
{ok, AST} ->
|
case expand_includes(AST, Included, Opts) of
|
||||||
case expand_includes(AST, Included, Opts) of
|
{ok, AST1} -> AST1;
|
||||||
{ok, AST1} -> AST1;
|
{error, Err} -> parse_error(Err)
|
||||||
{error, Err} -> parse_error(Err)
|
|
||||||
end;
|
|
||||||
{error, Err} ->
|
|
||||||
parse_error(Err)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
type(String) ->
|
type(String) ->
|
||||||
case parse_and_scan(type(), String, []) of
|
escape_errors(parse_and_scan(type(), String, [])).
|
||||||
{ok, AST} -> {ok, AST};
|
|
||||||
{error, Err} -> {error, [mk_error(Err)]}
|
body(String) ->
|
||||||
end.
|
escape_errors(parse_and_scan(body(), String, [])).
|
||||||
|
|
||||||
|
letdef(String) ->
|
||||||
|
escape_errors(parse_and_scan(letdef(), String, [])).
|
||||||
|
|
||||||
parse_and_scan(P, S, Opts) ->
|
parse_and_scan(P, S, Opts) ->
|
||||||
set_current_file(proplists:get_value(src_file, Opts, no_file)),
|
set_current_file(proplists:get_value(src_file, Opts, no_file)),
|
||||||
@ -596,8 +604,13 @@ expand_includes(AST, Included, Opts) ->
|
|||||||
|| File <- lists:usort(auto_imports(AST)) ] ++ AST,
|
|| File <- lists:usort(auto_imports(AST)) ] ++ AST,
|
||||||
expand_includes(AST1, Included, [], Opts).
|
expand_includes(AST1, Included, [], Opts).
|
||||||
|
|
||||||
expand_includes([], _Included, Acc, _Opts) ->
|
expand_includes([], Included, Acc, Opts) ->
|
||||||
{ok, lists:reverse(Acc)};
|
case lists:member(keep_included, Opts) of
|
||||||
|
false ->
|
||||||
|
{ok, lists:reverse(Acc)};
|
||||||
|
true ->
|
||||||
|
{ok, {lists:reverse(Acc), Included}}
|
||||||
|
end;
|
||||||
expand_includes([{include, Ann, {string, _SAnn, File}} | AST], Included, Acc, Opts) ->
|
expand_includes([{include, Ann, {string, _SAnn, File}} | AST], Included, Acc, Opts) ->
|
||||||
case get_include_code(File, Ann, Opts) of
|
case get_include_code(File, Ann, Opts) of
|
||||||
{ok, Code} ->
|
{ok, Code} ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user