Implement namespaces

This includes a massive refactoring of the type checker, getting
rid of most of the ets tables and keeping a proper environment.
This commit is contained in:
Ulf Norell
2019-01-21 14:20:57 +01:00
parent 026ff52528
commit 367f87b612
14 changed files with 863 additions and 457 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
// Test more advanced chain interactions
contract Chain =
contract ChainTest =
record state = { last_bf : address }
@@ -10,4 +10,4 @@ contract Chain =
function miner() = Chain.coinbase
function save_coinbase() =
put(state{last_bf = Chain.coinbase})
put(state{last_bf = Chain.coinbase})
+5
View File
@@ -0,0 +1,5 @@
// You can't shadow existing contracts or namespaces.
contract Call =
function whatever() = ()
+31
View File
@@ -0,0 +1,31 @@
namespace Lib =
// namespace Internal =
// function rev(xs, ys) =
// switch(xs)
// [] => ys
// x :: xs => rev(xs, x :: ys)
private
function rev(xs, ys) =
switch(xs)
[] => ys
x :: xs => rev(xs, x :: ys)
function reverse(xs : list('a)) : list('a) = rev(xs, [])
function eqlist(xs : list(int), ys : list(int)) =
switch((xs, ys))
([], []) => true
(x :: xs, y :: ys) => x == y && eqlist(xs, ys)
_ => false
contract TestNamespaces =
record state = { x : int }
function init() = { x = 0 }
function palindrome(xs : list(int)) : bool =
Lib.eqlist(xs, Lib.reverse(xs))