Skip to content

Commit

Permalink
Merge pull request #2728 from aeternity/polymorphism-checks
Browse files Browse the repository at this point in the history
Polymorphism and higher-order checks
  • Loading branch information
UlfNorell committed Sep 2, 2019
2 parents f51187e + 447fca8 commit d05785c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/aefate/test/aefa_sophia_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ remote() ->
"contract Remote =\n"
" entrypoint remote : int => int\n"
"contract Main =\n"
" entrypoint bla(r : Remote) = r.remote\n"
" function bla(r : Remote) = r.remote\n"
" stateful entrypoint test(r : Remote) =\n"
" r.remote(42)\n"
" + r.remote(value = 10, 100)\n"
Expand Down
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{aeminer, {git, "https://github.com/aeternity/aeminer.git",
{ref, "0a82f0f"}}},

{aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "c6475fe"}}},
{aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "e7f2be7"}}},

{aeserialization, {git, "https://github.com/aeternity/aeserialization.git",
{ref,"e24650d"}}},
Expand Down Expand Up @@ -197,7 +197,7 @@
{sname, 'aeternity_ct@localhost'}]},
{deps, [{meck, "0.8.12"},
{websocket_client, {git, "git://github.com/aeternity/websocket_client", {ref, "a4fb3db"}}},
{aesophia, {git, "https://github.com/aeternity/aesophia.git", {ref,"c51531f"}}},
{aesophia, {git, "https://github.com/aeternity/aesophia.git", {ref,"062309e"}}},
{aesophia_cli, {git, "git://github.com/aeternity/aesophia_cli", {tag, "v3.2.0"}}},
{aestratum_client, {git, "git://github.com/aeternity/aestratum_client", {tag, "v0.1.1"}}}
]}
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{"1.1.0",
[{<<"aebytecode">>,
{git,"https://github.com/aeternity/aebytecode.git",
{ref,"c6475fe1c2bbc2acaf973f207f99f2dd472d534d"}},
{ref,"e7f2be7ce878b1e22bad287f3342f32579e98599"}},
0},
{<<"aecuckoo">>,
{git,"https://github.com/aeternity/aecuckoo.git",
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/complex_types.aes
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract ComplexTypes =
entrypoint remote_pair(n : int, s : string) : int * string =
state.worker.pair(gas = 10000, n, s)

entrypoint map(f, xs) =
function map(f, xs) =
switch(xs)
[] => []
x :: xs => f(x) :: map(f, xs)
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/polymorphism_test.aes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

contract Identity =

entrypoint zip_with(f, xs, ys) =
function zip_with(f, xs, ys) =
switch((xs, ys))
(x :: xs, y :: ys) => f(x, y) :: zip_with(f, xs, ys)
_ => []
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/remote_gas_test.aes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract RemoteCall =

entrypoint init(x) = { i = x }

entrypoint bogus_return(x) = x
entrypoint bogus_return(x : int) = x

payable entrypoint bogus_remote(r : Remote1, x : int, g : int) =
r.bogus_return(gas = g, x)
Expand Down
38 changes: 38 additions & 0 deletions test/contracts/sophia_4_aevm/operators.aes
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// - + * / mod arithmetic operators
// bnot band bor bxor bsl bsr bitwise operators
// ! && || logical operators
// == != < > =< >= comparison operators
// :: ++ list operators

contract Operators =
entrypoint int_op(a : int, b : int, op : string) =
switch(op)
"+" => a + b
"-" => a - b
"*" => a * b
"/" => a / b
"mod" => a mod b
"^" => a ^ b

entrypoint bool_op(a : bool, b : bool, op : string) =
switch(op)
"!" => !a
"&&" => a && b
"||" => a || b

entrypoint cmp_op(a : int, b : int, op : string) =
switch(op)
"==" => a == b
"!=" => a != b
"<" => a < b
">" => a > b
"=<" => a =< b
">=" => a >= b

entrypoint cons(a : int, l) = a :: l
entrypoint concat(l1, l2) : list(int) = l1 ++ l2

entrypoint hash(s) = // String.sha3(s)
let x = String.sha3(s)
let y = String.sha3(s)
(x, y)
53 changes: 53 additions & 0 deletions test/contracts/sophia_4_aevm/remote_type_check.aes
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
contract Remote =
entrypoint id : ('a) => 'a
entrypoint missing : ('a) => 'a
entrypoint bogus_string_string_arg : (string) => string
entrypoint bogus_string_string_ret : (string) => string
entrypoint bogus_id : ('a) => ('a)

contract Main =

type state = int

entrypoint init() = 0

entrypoint next_state() = state + 1

entrypoint id(x : int) =
x

entrypoint bogus_id(x : int) =
(x, x)

entrypoint bogus_string_string_arg(x : int) =
"hello"

entrypoint bogus_string_string_ret(x : string) =
42

entrypoint remote_id(r : Remote, x : int) =
r.id(x)

entrypoint remote_missing(r : Remote, x : int) =
r.missing(x)

entrypoint remote_wrong_arg(r : Remote, x) =
r.bogus_string_string_arg(x)

entrypoint remote_wrong_ret(r : Remote, x) =
(r.bogus_string_string_ret(x), r.bogus_string_string_ret(x))

entrypoint remote_wrong_ret_tailcall(r : Remote, x) : string =
r.bogus_string_string_ret(x)

entrypoint remote_wrong_ret_tailcall_type_vars(r : Remote, x : string) =
r.bogus_id(x)

stateful entrypoint remote_wrong_put(r : Remote, x : int) =
put(r.bogus_id(x))

function call_bogus_id(r : Remote, x : int) : int = r.bogus_id(x)

stateful entrypoint remote_wrong_put_polymorphic(r : Remote, x : int) =
put(call_bogus_id(r, x))

0 comments on commit d05785c

Please sign in to comment.