Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
334 changes: 187 additions & 147 deletions src/compile.ml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/instrList.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let to_instr_list (is : t) : instr list =
let to_nested_list d pos is =
optimize (is Int32.(add d 1l) pos [])


(* The concatenation operator *)
let nop : t = fun _ _ rest -> rest
let (^^) (is1 : t) (is2 : t) : t = fun d pos rest -> is1 d pos (is2 d pos rest)
Expand Down Expand Up @@ -111,3 +112,8 @@ let branch_to_ (p : depth) : t =

let labeled_block_ (ty : block_type) depth (body : t) : t =
block_ ty (remember_depth depth body)

(* Intended to be used within assert *)

let is_nop (is :t) =
is 0l Wasm.Source.no_region [] = []
4 changes: 2 additions & 2 deletions test/compare-wat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ do

rm -rf compare-out/$base.old
mkdir compare-out/$base.old
old-asc/bin/asc --dfinity $file --map -o compare-out/$base.old/$base.wasm 2> compare-out/$base.old/$base.stderr
old-asc/bin/asc --dfinity $file -o compare-out/$base.old/$base.wasm 2> compare-out/$base.old/$base.stderr
test ! -e compare-out/$base.old/$base.wasm ||
$WASM2WAT compare-out/$base.old/$base.wasm >& compare-out/$base.old/$base.wat

rm -rf compare-out/$base.new
mkdir compare-out/$base.new
new-asc/bin/asc --dfinity $file --map -o compare-out/$base.new/$base.wasm 2> compare-out/$base.new/$base.stderr
new-asc/bin/asc --dfinity $file -o compare-out/$base.new/$base.wasm 2> compare-out/$base.new/$base.stderr
test ! -e compare-out/$base.new/$base.wasm ||
$WASM2WAT compare-out/$base.new/$base.wasm >& compare-out/$base.new/$base.wat

Expand Down
21 changes: 0 additions & 21 deletions test/run-dfinity/actor-reexport.as

This file was deleted.

8 changes: 4 additions & 4 deletions test/run-dfinity/counter-class.as
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
actor class Counter(i : Int) {
private var c = i;
private var j = i;

dec() {
showCounter(c);
c -= 1;
showCounter(j);
j -= 1;
};

read() : async Int { c };
read() : async Int { j };
};

func showCounter(c : Int) {};
Expand Down
18 changes: 14 additions & 4 deletions test/run-dfinity/counter.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ let a = actor {
private var c = 1;
inc() {
c += 1;
printInt(c)
printInt c; print "\n";
};
print () {
printInt(c)
printCounter () {
printInt c; print "\n";
}
};

a.inc();
a.inc();
a.inc();
a.print()
a.printCounter();

func test() {
var i : Int = 10;
while (i > 0) {
a.inc();
i -= 1;
}
};

let _ = test();
14 changes: 14 additions & 0 deletions test/run-dfinity/counter2.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
actor {
private var c = 1;
inc() {
c += 1;
printInt c; print "\n";
};
printCounter () {
printInt c; print "\n";
}
}
//CALL inc
//CALL inc
//CALL inc
//CALL printCounter
2 changes: 0 additions & 2 deletions test/run-dfinity/ok/actor-reexport.dvm-run.ok

This file was deleted.

5 changes: 0 additions & 5 deletions test/run-dfinity/ok/actor-reexport.run-ir.ok

This file was deleted.

5 changes: 0 additions & 5 deletions test/run-dfinity/ok/actor-reexport.run-low.ok

This file was deleted.

5 changes: 0 additions & 5 deletions test/run-dfinity/ok/actor-reexport.run.ok

This file was deleted.

19 changes: 0 additions & 19 deletions test/run-dfinity/ok/actor-reexport.wasm.stderr.ok

This file was deleted.

8 changes: 4 additions & 4 deletions test/run-dfinity/ok/counter-class.wasm.stderr.ok
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
non-closed actor: (ActorE
anon-object-1.30
(VarD c (VarE i))
(VarD j (VarE i))
(LetD
(VarP dec)
(FuncE
dec
(shared 0 -> 0)
()
(BlockE
(LetD WildP (CallE ( 1 -> 0) (VarE showCounter) (VarE c)))
(AssignE (VarE c) (BinE Int (VarE c) SubOp (LitE (IntLit 1))))
(LetD WildP (CallE ( 1 -> 0) (VarE showCounter) (VarE j)))
(AssignE (VarE j) (BinE Int (VarE j) SubOp (LitE (IntLit 1))))
)
)
)
Expand Down Expand Up @@ -39,7 +39,7 @@ non-closed actor: (ActorE
( 1 -> 0)
(params $cont/0)
()
(CallE ( 1 -> 0) (VarE $cont/0) (VarE c))
(CallE ( 1 -> 0) (VarE $cont/0) (VarE j))
)
(FuncE
$lambda
Expand Down
15 changes: 14 additions & 1 deletion test/run-dfinity/ok/counter.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
2344
2
3
4
4
5
6
7
8
9
10
11
12
13
14
15 changes: 14 additions & 1 deletion test/run-dfinity/ok/counter.run-ir.ok
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
2344
2
3
4
4
5
6
7
8
9
10
11
12
13
14
15 changes: 14 additions & 1 deletion test/run-dfinity/ok/counter.run-low.ok
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
2344
2
3
4
4
5
6
7
8
9
10
11
12
13
14
15 changes: 14 additions & 1 deletion test/run-dfinity/ok/counter.run.ok
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
2344
2
3
4
4
5
6
7
8
9
10
11
12
13
14
8 changes: 8 additions & 0 deletions test/run-dfinity/ok/counter2.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DVM: Calling method inc
2
DVM: Calling method inc
3
DVM: Calling method inc
4
DVM: Calling method printCounter
4
35 changes: 35 additions & 0 deletions test/run/mutrec3.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Like mutrec2, but now the functions capture static variables

var step = 0;

func even(n : Nat) : Bool {
if (n == 0) {
return true;
} else
return odd(n-step);
};

func odd(n : Nat) : Bool {
if (n == 0) {
return false;
} else
return even(n-step);
};

// There should be a bunch of calls to known functions here, but
// no indirect calls
// CHECK: func $start
// CHECK: call $even
// CHECK: call $even
// CHECK: call $even
// CHECK: call $even
// CHECK: call $odd
// CHECK: call $odd

step := 1;
assert(even(0));
assert(even(2));
assert(even(4));
assert(even(6));
assert(odd(5));
assert(not odd(6));