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
26 changes: 26 additions & 0 deletions src/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4276,6 +4276,11 @@ and compile_start_func env (progs : Ir.prog list) : E.func_with_names =
Func.of_body env [] [] (fun env1 ->
let rec go env = function
| [] -> G.nop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this mean that program with no actor has no exports and is just executed for side effects, or not exectured at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executed for side effects, just as before. In fact, every actor has a method called start that contains the side-effects.

(* If the last program ends with an actor, then consider this the current actor *)
| [((decls, {it = ActorE (i, ds, fs, _); _}), _flavor)] ->
let (env', code1) = compile_decs env ds in
let code2 = main_actor env' i ds fs in
code1 ^^ code2
| ((prog, _flavor) :: progs) ->
let (env1, code1) = compile_prog env prog in
let code2 = go env1 progs in
Expand Down Expand Up @@ -4315,6 +4320,7 @@ and export_actor_field env ((f : Ir.field), ptr) =
});
fill (FuncDec.compile_static_message env cc ptr);

(* Local actor *)
and actor_lit outer_env this ds fs at =
if E.mode outer_env <> DfinityMode then G.i Unreachable else

Expand Down Expand Up @@ -4356,6 +4362,26 @@ and actor_lit outer_env this ds fs at =
G.i (Call (nr (Dfinity.module_new_i outer_env))) ^^
G.i (Call (nr (Dfinity.actor_new_i outer_env)))

(* Main actor: Just return the initialization code, and export functions as needed *)
and main_actor env this ds fs =
if E.mode env <> DfinityMode then G.i Unreachable else

(* Allocate static positions for exported functions *)
let located_ids = allocate_actor_fields env fs in

List.iter (export_actor_field env) located_ids;

(* Add this pointer *)
let env2 = E.add_local_deferred_vanilla env this.it Dfinity.get_self_reference in

(* Compile the declarations *)
let (env3, decls_code) = compile_decs env2 ds in

(* fill the static export references *)
let fill_code = fill_actor_fields env3 located_ids in

decls_code ^^ fill_code

and actor_fake_object_idx env name =
Dfinity.compile_databuf_of_bytes env (name.it) ^^
G.i (Call (nr (Dfinity.actor_export_i env)))
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ let infer_prog_unit senv prog =
(Typing.check_prog senv prog)

let check_string senv s = check_with (parse_string s) Typing.infer_prog senv
let check_file senv n = check_with parse_file infer_prog_unit senv n
let check_file senv n = check_with parse_file Typing.infer_prog senv n
let check_files senv = function
| [n] -> check_file senv n
| ns -> check_with (fun _n -> parse_files ns) infer_prog_unit senv "all"
| ns -> check_with (fun _n -> parse_files ns) Typing.infer_prog senv "all"


(* Interpretation *)
Expand Down
12 changes: 11 additions & 1 deletion test/dvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if [ -z "$1" ]
then
echo "Usage: $0 <name>.wasm"
echo "Usage: $0 <name>.wasm [call-script]"
exit 1
fi

Expand All @@ -25,3 +25,13 @@ function dvm_ () {
dvm_ -q --db $DVM_TMP reset
dvm_ -q --db $DVM_TMP new $1
dvm_ -q --db $DVM_TMP run $name start

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this let you pass arguments too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add your comments below the interesting lines; the conversation view only shows the marked line and the three lines above…

Yes, it simply dumps whatever follows //CALL onto the shell, and whatever syntax dvm supports for arguments can be used here.

if [ -n "$2" ]
then
grep '^//CALL ' $2 | cut -c7- |
while read call
do
echo "DVM: Calling method $call"
dvm_ -q --db $DVM_TMP run $name $call
done
fi
7 changes: 7 additions & 0 deletions test/run-dfinity/hello-world-message.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
actor {
hello () {
print("Hello World!\n");
}
}

//CALL hello
1 change: 0 additions & 1 deletion test/run-dfinity/ok/AST-64.dvm-run.ok

This file was deleted.

1 change: 0 additions & 1 deletion test/run-dfinity/ok/AST-66.dvm-run.ok

This file was deleted.

1 change: 0 additions & 1 deletion test/run-dfinity/ok/array-out-of-bounds.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
W, hypervisor: call failed with trap message: Uncaught RuntimeError: unreachable
W, hypervisor: call failed with trap message: Uncaught RuntimeError: unreachable
Top-level code done.
1 change: 0 additions & 1 deletion test/run-dfinity/ok/async-loop-while.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
012345678910012345678910012345678910012345678910
1 change: 0 additions & 1 deletion test/run-dfinity/ok/async-loop.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
012345678910012345678910012345678910012345678910
1 change: 0 additions & 1 deletion test/run-dfinity/ok/async-new-obj.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
aaab
babb
cacb
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/async-obj-mut.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
123
done creating
345
1 change: 0 additions & 1 deletion test/run-dfinity/ok/async-while.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
012345678910012345678910012345678910012345678910
1 change: 0 additions & 1 deletion test/run-dfinity/ok/chat.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
bob received hello from bob
bob received goodbye from bob
alice received hello from alice
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/chatpp.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
(unsubscribe 0)
(unsubscribe 1)
(unsubscribe 2)
1 change: 0 additions & 1 deletion test/run-dfinity/ok/closure-params.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
1
1
3
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/counter.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
2344
1 change: 0 additions & 1 deletion test/run-dfinity/ok/data-params.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
1
3
6
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/empty-actor.dvm-run.ok

This file was deleted.

2 changes: 1 addition & 1 deletion test/run-dfinity/ok/fac.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120Top-level code done.
120
1 change: 0 additions & 1 deletion test/run-dfinity/ok/flatten-awaitables.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.

first-order
,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/generic-tail-rec.dvm-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ done 1
done 2
done 3
done 4
Top-level code done.
1 change: 0 additions & 1 deletion test/run-dfinity/ok/hello-concat-world.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Hello World!
Top-level code done.
1 change: 0 additions & 1 deletion test/run-dfinity/ok/hello-world-async.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
Hello World!
1 change: 0 additions & 1 deletion test/run-dfinity/ok/hello-world-await.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
Hello World!
2 changes: 2 additions & 0 deletions test/run-dfinity/ok/hello-world-message.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DVM: Calling method hello
Hello World!
1 change: 0 additions & 1 deletion test/run-dfinity/ok/hello-world.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Hello World!
Top-level code done.
1 change: 0 additions & 1 deletion test/run-dfinity/ok/hello-world2.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
Hello World!
1 change: 0 additions & 1 deletion test/run-dfinity/ok/hello-world3.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
Hello World!
1 change: 0 additions & 1 deletion test/run-dfinity/ok/indirect-counter.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Top-level code done.
2344
1 change: 0 additions & 1 deletion test/run-dfinity/ok/large-mem.dvm-run.ok

This file was deleted.

1 change: 0 additions & 1 deletion test/run-dfinity/ok/nary-async.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
0_0
1_0
2_0
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/no-boxed-references.dvm-run.ok

This file was deleted.

1 change: 0 additions & 1 deletion test/run-dfinity/ok/overflow.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
W, hypervisor: call failed with trap message: Uncaught RuntimeError: unreachable
W, hypervisor: call failed with trap message: Uncaught RuntimeError: unreachable
Top-level code done.
This is reachable.
This is reachable.
This is reachable.
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/reference-params.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Top-level code done.
Hello World!
Hello World!
Hello World!
Expand Down
1 change: 0 additions & 1 deletion test/run-dfinity/ok/selftail.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ok1
ok2
Top-level code done.
1 change: 0 additions & 1 deletion test/run-dfinity/ok/tailpositions.dvm-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ done 4
done 5
done 6
done 7
Top-level code done.
2 changes: 1 addition & 1 deletion test/run-dfinity/ok/the-answer.dvm-run.ok
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42Top-level code done.
42
9 changes: 2 additions & 7 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ do

# Compile
$ECHO -n " [wasm]"
if [ $DFINITY = 'yes' ]
then
$ASC $ASC_FLAGS $EXTRA_ASC_FLAGS --map -c $base.as <(echo 'print("Top-level code done.\n")') -o $out/$base.wasm 2> $out/$base.wasm.stderr
else
$ASC $ASC_FLAGS $EXTRA_ASC_FLAGS --map -c $base.as -o $out/$base.wasm 2> $out/$base.wasm.stderr
fi
$ASC $ASC_FLAGS $EXTRA_ASC_FLAGS --map -c $base.as -o $out/$base.wasm 2> $out/$base.wasm.stderr
normalize $out/$base.wasm.stderr
diff_files="$diff_files $base.wasm.stderr"

Expand All @@ -154,7 +149,7 @@ do
if [ $DFINITY = 'yes' ]
then
$ECHO -n " [dvm]"
$DVM_WRAPPER $out/$base.wasm > $out/$base.dvm-run 2>&1
$DVM_WRAPPER $out/$base.wasm $base.as > $out/$base.dvm-run 2>&1
normalize $out/$base.dvm-run
diff_files="$diff_files $base.dvm-run"
else
Expand Down
2 changes: 2 additions & 0 deletions test/run/type-equivalence.as
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,5 @@ func f2(x : A2<Nat, Bool>) : A2<Nat, Bool> = x : B2<Bool, Nat>;
func g1(x : A1<Nat, Bool>) : A1<Nat, Bool> = x : C1<Nat, Bool>;
func g2(x : A2<Nat, Bool>) : A2<Nat, Bool> = x : C2<Bool, Nat>;
};

()
2 changes: 2 additions & 0 deletions test/run/type-inclusion.as
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,5 @@ func f2(x : A2<Bool>) : B2<Bool> = x;
func g1(x : A1<Bool>) : C1<Bool> = x;
func g2(x : A2<Bool>) : C2<Bool> = x;
};

()