Merge pull request #92 from aeternity/PT-166786424-check-oracle-types
Add type information to oracle instructions
This commit is contained in:
commit
69fa03ca9f
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{erl_opts, [debug_info]}.
|
{erl_opts, [debug_info]}.
|
||||||
|
|
||||||
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"e321882"}}}
|
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"9dfc5f4"}}}
|
||||||
, {getopt, "1.0.1"}
|
, {getopt, "1.0.1"}
|
||||||
, {jsx, {git, "https://github.com/talentdeficit/jsx.git",
|
, {jsx, {git, "https://github.com/talentdeficit/jsx.git",
|
||||||
{tag, "2.8.0"}}}
|
{tag, "2.8.0"}}}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{"1.1.0",
|
{"1.1.0",
|
||||||
[{<<"aebytecode">>,
|
[{<<"aebytecode">>,
|
||||||
{git,"https://github.com/aeternity/aebytecode.git",
|
{git,"https://github.com/aeternity/aebytecode.git",
|
||||||
{ref,"e321882b9830eea5ce5ab8801e8b19fd350a4e00"}},
|
{ref,"9dfc5f4f1d1a9676cb6b9577af74a4566cc3f3f4"}},
|
||||||
0},
|
0},
|
||||||
{<<"aeserialization">>,
|
{<<"aeserialization">>,
|
||||||
{git,"https://github.com/aeternity/aeserialization.git",
|
{git,"https://github.com/aeternity/aeserialization.git",
|
||||||
|
@ -477,8 +477,14 @@ expr_to_fcode(Env, Type, {app, _Ann, Fun = {typed, _, _, {fun_t, _, NamedArgsT,
|
|||||||
Args1 = get_named_args(NamedArgsT, Args),
|
Args1 = get_named_args(NamedArgsT, Args),
|
||||||
FArgs = [expr_to_fcode(Env, Arg) || Arg <- Args1],
|
FArgs = [expr_to_fcode(Env, Arg) || Arg <- Args1],
|
||||||
case expr_to_fcode(Env, Fun) of
|
case expr_to_fcode(Env, Fun) of
|
||||||
{builtin_u, oracle_register = B, _} ->
|
{builtin_u, B, _} when B =:= oracle_query;
|
||||||
{oracle, QType, RType} = type_to_fcode(Env, Type),
|
B =:= oracle_get_question;
|
||||||
|
B =:= oracle_get_answer;
|
||||||
|
B =:= oracle_respond;
|
||||||
|
B =:= oracle_register ->
|
||||||
|
%% Get the type of the oracle from the args or the expression itself
|
||||||
|
OType = get_oracle_type(B, Type, Args1),
|
||||||
|
{oracle, QType, RType} = type_to_fcode(Env, OType),
|
||||||
TypeArgs = [{lit, {typerep, QType}}, {lit, {typerep, RType}}],
|
TypeArgs = [{lit, {typerep, QType}}, {lit, {typerep, RType}}],
|
||||||
builtin_to_fcode(B, FArgs ++ TypeArgs);
|
builtin_to_fcode(B, FArgs ++ TypeArgs);
|
||||||
{builtin_u, B, _Ar} -> builtin_to_fcode(B, FArgs);
|
{builtin_u, B, _Ar} -> builtin_to_fcode(B, FArgs);
|
||||||
@ -545,6 +551,13 @@ make_if(Cond, Then, Else) ->
|
|||||||
X = fresh_name(),
|
X = fresh_name(),
|
||||||
{'let', X, Cond, make_if({var, X}, Then, Else)}.
|
{'let', X, Cond, make_if({var, X}, Then, Else)}.
|
||||||
|
|
||||||
|
|
||||||
|
get_oracle_type(oracle_register, OType, _Args) -> OType;
|
||||||
|
get_oracle_type(oracle_query, _Type, [{typed, _,_Expr, OType}|_]) -> OType;
|
||||||
|
get_oracle_type(oracle_get_question, _Type, [{typed, _,_Expr, OType}|_]) -> OType;
|
||||||
|
get_oracle_type(oracle_get_answer, _Type, [{typed, _,_Expr, OType}|_]) -> OType;
|
||||||
|
get_oracle_type(oracle_respond, _Type, [_,{typed, _,_Expr, OType}|_]) -> OType.
|
||||||
|
|
||||||
%% -- Pattern matching --
|
%% -- Pattern matching --
|
||||||
|
|
||||||
-spec alts_to_fcode(env(), ftype(), var_name(), [aeso_syntax:alt()]) -> fsplit().
|
-spec alts_to_fcode(env(), ftype(), var_name(), [aeso_syntax:alt()]) -> fsplit().
|
||||||
|
@ -505,22 +505,22 @@ builtin_to_scode(_Env, call_gas_price, []) ->
|
|||||||
[aeb_fate_ops:gasprice(?a)];
|
[aeb_fate_ops:gasprice(?a)];
|
||||||
builtin_to_scode(_Env, call_gas_left, []) ->
|
builtin_to_scode(_Env, call_gas_left, []) ->
|
||||||
[aeb_fate_ops:gas(?a)];
|
[aeb_fate_ops:gas(?a)];
|
||||||
builtin_to_scode(Env, oracle_register, [_Sign,_Account,_QFee,_TTL,_QType,_RTYpe] = Args) ->
|
builtin_to_scode(Env, oracle_register, [_Sign,_Account,_QFee,_TTL,_QType,_RType] = Args) ->
|
||||||
call_to_scode(Env, aeb_fate_ops:oracle_register(?a, ?a, ?a, ?a, ?a, ?a, ?a), Args);
|
call_to_scode(Env, aeb_fate_ops:oracle_register(?a, ?a, ?a, ?a, ?a, ?a, ?a), Args);
|
||||||
builtin_to_scode(Env, oracle_query_fee, [_Oracle] = Args) ->
|
builtin_to_scode(Env, oracle_query_fee, [_Oracle] = Args) ->
|
||||||
call_to_scode(Env, aeb_fate_ops:oracle_query_fee(?a, ?a), Args);
|
call_to_scode(Env, aeb_fate_ops:oracle_query_fee(?a, ?a), Args);
|
||||||
builtin_to_scode(Env, oracle_query, [_Oracle, _Question, _QFee, _QTTL, _RTTL] = Args) ->
|
builtin_to_scode(Env, oracle_query, [_Oracle, _Question, _QFee, _QTTL, _RTTL, _QType, _RType] = Args) ->
|
||||||
call_to_scode(Env, aeb_fate_ops:oracle_query(?a, ?a, ?a, ?a, ?a, ?a), Args);
|
call_to_scode(Env, aeb_fate_ops:oracle_query(?a, ?a, ?a, ?a, ?a, ?a, ?a, ?a), Args);
|
||||||
builtin_to_scode(Env, oracle_get_question, [_Oracle, _QueryId] = Args) ->
|
builtin_to_scode(Env, oracle_get_question, [_Oracle, _QueryId, _QType, _RType] = Args) ->
|
||||||
call_to_scode(Env, aeb_fate_ops:oracle_get_question(?a, ?a, ?a), Args);
|
call_to_scode(Env, aeb_fate_ops:oracle_get_question(?a, ?a, ?a, ?a, ?a), Args);
|
||||||
builtin_to_scode(Env, oracle_respond, [_Sign, _Oracle, _QueryId, _Response] = Args) ->
|
builtin_to_scode(Env, oracle_respond, [_Sign, _Oracle, _QueryId, _Response, _QType, _RType] = Args) ->
|
||||||
call_to_scode(Env, [aeb_fate_ops:oracle_respond(?a, ?a, ?a, ?a),
|
call_to_scode(Env, [aeb_fate_ops:oracle_respond(?a, ?a, ?a, ?a, ?a, ?a),
|
||||||
tuple(0)], Args);
|
tuple(0)], Args);
|
||||||
builtin_to_scode(Env, oracle_extend, [_Sign, _Oracle, _TTL] = Args) ->
|
builtin_to_scode(Env, oracle_extend, [_Sign, _Oracle, _TTL] = Args) ->
|
||||||
call_to_scode(Env, [aeb_fate_ops:oracle_extend(?a, ?a, ?a),
|
call_to_scode(Env, [aeb_fate_ops:oracle_extend(?a, ?a, ?a),
|
||||||
tuple(0)], Args);
|
tuple(0)], Args);
|
||||||
builtin_to_scode(Env, oracle_get_answer, [_Oracle, _QueryId] = Args) ->
|
builtin_to_scode(Env, oracle_get_answer, [_Oracle, _QueryId, _QType, _RType] = Args) ->
|
||||||
call_to_scode(Env, aeb_fate_ops:oracle_get_answer(?a, ?a, ?a), Args);
|
call_to_scode(Env, aeb_fate_ops:oracle_get_answer(?a, ?a, ?a, ?a, ?a), Args);
|
||||||
builtin_to_scode(_Env, aens_resolve, [_, _] = _Args) ->
|
builtin_to_scode(_Env, aens_resolve, [_, _] = _Args) ->
|
||||||
?TODO(fate_aens_resolve_instruction);
|
?TODO(fate_aens_resolve_instruction);
|
||||||
builtin_to_scode(_Env, aens_preclaim, [_, _, _] = _Args) ->
|
builtin_to_scode(_Env, aens_preclaim, [_, _, _] = _Args) ->
|
||||||
@ -827,11 +827,11 @@ attributes(I) ->
|
|||||||
{'SPEND', A, B} -> Impure(none, [A, B]);
|
{'SPEND', A, B} -> Impure(none, [A, B]);
|
||||||
|
|
||||||
{'ORACLE_REGISTER', A, B, C, D, E, F, G} -> Impure(A, [B, C, D, E, F, G]);
|
{'ORACLE_REGISTER', A, B, C, D, E, F, G} -> Impure(A, [B, C, D, E, F, G]);
|
||||||
{'ORACLE_QUERY', A, B, C, D, E, F} -> Impure(A, [B, C, D, E, F]);
|
{'ORACLE_QUERY', A, B, C, D, E, F, G, H} -> Impure(A, [B, C, D, E, F, G, H]);
|
||||||
{'ORACLE_RESPOND', A, B, C, D} -> Impure(none, [A, B, C, D]);
|
{'ORACLE_RESPOND', A, B, C, D, E, F} -> Impure(none, [A, B, C, D, E, F]);
|
||||||
{'ORACLE_EXTEND', A, B, C} -> Impure(none, [A, B, C]);
|
{'ORACLE_EXTEND', A, B, C} -> Impure(none, [A, B, C]);
|
||||||
{'ORACLE_GET_ANSWER', A, B, C} -> Impure(A, [B, C]);
|
{'ORACLE_GET_ANSWER', A, B, C, D, E} -> Impure(A, [B, C, D, E]);
|
||||||
{'ORACLE_GET_QUESTION', A, B, C} -> Impure(A, [B, C]);
|
{'ORACLE_GET_QUESTION', A, B, C, D, E}-> Impure(A, [B, C, D, E]);
|
||||||
{'ORACLE_QUERY_FEE', A, B} -> Impure(A, [B]);
|
{'ORACLE_QUERY_FEE', A, B} -> Impure(A, [B]);
|
||||||
'AENS_RESOLVE' -> Impure(?a, []); %% TODO
|
'AENS_RESOLVE' -> Impure(?a, []); %% TODO
|
||||||
'AENS_PRECLAIM' -> Impure(?a, []); %% TODO
|
'AENS_PRECLAIM' -> Impure(?a, []); %% TODO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user