diff --git a/rebar.config b/rebar.config index e88c3f0..29eeeac 100644 --- a/rebar.config +++ b/rebar.config @@ -2,7 +2,7 @@ {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"} , {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}} diff --git a/rebar.lock b/rebar.lock index 70c7bae..9096a27 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,7 @@ {"1.1.0", [{<<"aebytecode">>, {git,"https://github.com/aeternity/aebytecode.git", - {ref,"e321882b9830eea5ce5ab8801e8b19fd350a4e00"}}, + {ref,"9dfc5f4f1d1a9676cb6b9577af74a4566cc3f3f4"}}, 0}, {<<"aeserialization">>, {git,"https://github.com/aeternity/aeserialization.git", diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 7d7f8a8..26b4c1d 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -477,8 +477,14 @@ expr_to_fcode(Env, Type, {app, _Ann, Fun = {typed, _, _, {fun_t, _, NamedArgsT, Args1 = get_named_args(NamedArgsT, Args), FArgs = [expr_to_fcode(Env, Arg) || Arg <- Args1], case expr_to_fcode(Env, Fun) of - {builtin_u, oracle_register = B, _} -> - {oracle, QType, RType} = type_to_fcode(Env, Type), + {builtin_u, B, _} when B =:= oracle_query; + 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}}], builtin_to_fcode(B, FArgs ++ TypeArgs); {builtin_u, B, _Ar} -> builtin_to_fcode(B, FArgs); @@ -545,6 +551,13 @@ make_if(Cond, Then, Else) -> X = fresh_name(), {'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 -- -spec alts_to_fcode(env(), ftype(), var_name(), [aeso_syntax:alt()]) -> fsplit(). diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 7f994eb..5441ae3 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -505,22 +505,22 @@ builtin_to_scode(_Env, call_gas_price, []) -> [aeb_fate_ops:gasprice(?a)]; builtin_to_scode(_Env, call_gas_left, []) -> [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); builtin_to_scode(Env, oracle_query_fee, [_Oracle] = 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) -> - call_to_scode(Env, aeb_fate_ops:oracle_query(?a, ?a, ?a, ?a, ?a, ?a), Args); -builtin_to_scode(Env, oracle_get_question, [_Oracle, _QueryId] = Args) -> - call_to_scode(Env, aeb_fate_ops:oracle_get_question(?a, ?a, ?a), Args); -builtin_to_scode(Env, oracle_respond, [_Sign, _Oracle, _QueryId, _Response] = Args) -> - call_to_scode(Env, [aeb_fate_ops:oracle_respond(?a, ?a, ?a, ?a), +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, ?a, ?a), 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, ?a, ?a), 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, ?a, ?a), tuple(0)], Args); builtin_to_scode(Env, oracle_extend, [_Sign, _Oracle, _TTL] = Args) -> call_to_scode(Env, [aeb_fate_ops:oracle_extend(?a, ?a, ?a), tuple(0)], Args); -builtin_to_scode(Env, oracle_get_answer, [_Oracle, _QueryId] = Args) -> - call_to_scode(Env, aeb_fate_ops:oracle_get_answer(?a, ?a, ?a), 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, ?a, ?a), Args); builtin_to_scode(_Env, aens_resolve, [_, _] = _Args) -> ?TODO(fate_aens_resolve_instruction); builtin_to_scode(_Env, aens_preclaim, [_, _, _] = _Args) -> @@ -827,11 +827,11 @@ attributes(I) -> {'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_QUERY', A, B, C, D, E, F} -> Impure(A, [B, C, D, E, F]); - {'ORACLE_RESPOND', A, B, C, D} -> Impure(none, [A, B, C, D]); + {'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, E, F} -> Impure(none, [A, B, C, D, E, F]); {'ORACLE_EXTEND', A, B, C} -> Impure(none, [A, B, C]); - {'ORACLE_GET_ANSWER', A, B, C} -> Impure(A, [B, C]); - {'ORACLE_GET_QUESTION', 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, D, E}-> Impure(A, [B, C, D, E]); {'ORACLE_QUERY_FEE', A, B} -> Impure(A, [B]); 'AENS_RESOLVE' -> Impure(?a, []); %% TODO 'AENS_PRECLAIM' -> Impure(?a, []); %% TODO