diff --git a/src/compile.ml b/src/compile.ml index f5f688c5f81..e5a8ee3f373 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -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 + (* 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 @@ -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 @@ -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))) diff --git a/src/pipeline.ml b/src/pipeline.ml index acc7aa1f637..cd920c83e51 100644 --- a/src/pipeline.ml +++ b/src/pipeline.ml @@ -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 *) diff --git a/test/dvm.sh b/test/dvm.sh index 3af0e0e5468..16037510060 100755 --- a/test/dvm.sh +++ b/test/dvm.sh @@ -2,7 +2,7 @@ if [ -z "$1" ] then - echo "Usage: $0 .wasm" + echo "Usage: $0 .wasm [call-script]" exit 1 fi @@ -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 + +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 diff --git a/test/run-dfinity/hello-world-message.as b/test/run-dfinity/hello-world-message.as new file mode 100644 index 00000000000..5ea1e82608e --- /dev/null +++ b/test/run-dfinity/hello-world-message.as @@ -0,0 +1,7 @@ +actor { + hello () { + print("Hello World!\n"); + } +} + +//CALL hello diff --git a/test/run-dfinity/ok/AST-64.dvm-run.ok b/test/run-dfinity/ok/AST-64.dvm-run.ok deleted file mode 100644 index 3b7e66c4381..00000000000 --- a/test/run-dfinity/ok/AST-64.dvm-run.ok +++ /dev/null @@ -1 +0,0 @@ -Top-level code done. diff --git a/test/run-dfinity/ok/AST-66.dvm-run.ok b/test/run-dfinity/ok/AST-66.dvm-run.ok deleted file mode 100644 index 3b7e66c4381..00000000000 --- a/test/run-dfinity/ok/AST-66.dvm-run.ok +++ /dev/null @@ -1 +0,0 @@ -Top-level code done. diff --git a/test/run-dfinity/ok/array-out-of-bounds.dvm-run.ok b/test/run-dfinity/ok/array-out-of-bounds.dvm-run.ok index e6d1727cfb6..e5307f7818f 100644 --- a/test/run-dfinity/ok/array-out-of-bounds.dvm-run.ok +++ b/test/run-dfinity/ok/array-out-of-bounds.dvm-run.ok @@ -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. diff --git a/test/run-dfinity/ok/async-loop-while.dvm-run.ok b/test/run-dfinity/ok/async-loop-while.dvm-run.ok index 48962aa5514..ac6ac408923 100644 --- a/test/run-dfinity/ok/async-loop-while.dvm-run.ok +++ b/test/run-dfinity/ok/async-loop-while.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. 012345678910012345678910012345678910012345678910 diff --git a/test/run-dfinity/ok/async-loop.dvm-run.ok b/test/run-dfinity/ok/async-loop.dvm-run.ok index 48962aa5514..ac6ac408923 100644 --- a/test/run-dfinity/ok/async-loop.dvm-run.ok +++ b/test/run-dfinity/ok/async-loop.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. 012345678910012345678910012345678910012345678910 diff --git a/test/run-dfinity/ok/async-new-obj.dvm-run.ok b/test/run-dfinity/ok/async-new-obj.dvm-run.ok index 7e362ebf28b..9dfdfbb5120 100644 --- a/test/run-dfinity/ok/async-new-obj.dvm-run.ok +++ b/test/run-dfinity/ok/async-new-obj.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. aaab babb cacb diff --git a/test/run-dfinity/ok/async-obj-mut.dvm-run.ok b/test/run-dfinity/ok/async-obj-mut.dvm-run.ok index 4adf0505adb..98f29c526f9 100644 --- a/test/run-dfinity/ok/async-obj-mut.dvm-run.ok +++ b/test/run-dfinity/ok/async-obj-mut.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. 123 done creating 345 diff --git a/test/run-dfinity/ok/async-while.dvm-run.ok b/test/run-dfinity/ok/async-while.dvm-run.ok index 48962aa5514..ac6ac408923 100644 --- a/test/run-dfinity/ok/async-while.dvm-run.ok +++ b/test/run-dfinity/ok/async-while.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. 012345678910012345678910012345678910012345678910 diff --git a/test/run-dfinity/ok/chat.dvm-run.ok b/test/run-dfinity/ok/chat.dvm-run.ok index 14b104cf323..40f6822b967 100644 --- a/test/run-dfinity/ok/chat.dvm-run.ok +++ b/test/run-dfinity/ok/chat.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. bob received hello from bob bob received goodbye from bob alice received hello from alice diff --git a/test/run-dfinity/ok/chatpp.dvm-run.ok b/test/run-dfinity/ok/chatpp.dvm-run.ok index 308b1aac58e..42e2059e8d8 100644 --- a/test/run-dfinity/ok/chatpp.dvm-run.ok +++ b/test/run-dfinity/ok/chatpp.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. (unsubscribe 0) (unsubscribe 1) (unsubscribe 2) diff --git a/test/run-dfinity/ok/closure-params.dvm-run.ok b/test/run-dfinity/ok/closure-params.dvm-run.ok index ebca8e760cd..17b4c77d5c9 100644 --- a/test/run-dfinity/ok/closure-params.dvm-run.ok +++ b/test/run-dfinity/ok/closure-params.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. 1 1 3 diff --git a/test/run-dfinity/ok/counter.dvm-run.ok b/test/run-dfinity/ok/counter.dvm-run.ok index a3480e087a1..dc01807c8fe 100644 --- a/test/run-dfinity/ok/counter.dvm-run.ok +++ b/test/run-dfinity/ok/counter.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. 2344 diff --git a/test/run-dfinity/ok/data-params.dvm-run.ok b/test/run-dfinity/ok/data-params.dvm-run.ok index 9884ed33c7f..9a40c228b71 100644 --- a/test/run-dfinity/ok/data-params.dvm-run.ok +++ b/test/run-dfinity/ok/data-params.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. 1 3 6 diff --git a/test/run-dfinity/ok/empty-actor.dvm-run.ok b/test/run-dfinity/ok/empty-actor.dvm-run.ok deleted file mode 100644 index 3b7e66c4381..00000000000 --- a/test/run-dfinity/ok/empty-actor.dvm-run.ok +++ /dev/null @@ -1 +0,0 @@ -Top-level code done. diff --git a/test/run-dfinity/ok/fac.dvm-run.ok b/test/run-dfinity/ok/fac.dvm-run.ok index 6332b8b5e87..52bd8e43afb 100644 --- a/test/run-dfinity/ok/fac.dvm-run.ok +++ b/test/run-dfinity/ok/fac.dvm-run.ok @@ -1 +1 @@ -120Top-level code done. +120 diff --git a/test/run-dfinity/ok/flatten-awaitables.dvm-run.ok b/test/run-dfinity/ok/flatten-awaitables.dvm-run.ok index c8ab234ed8e..4c1b1bd6651 100644 --- a/test/run-dfinity/ok/flatten-awaitables.dvm-run.ok +++ b/test/run-dfinity/ok/flatten-awaitables.dvm-run.ok @@ -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, diff --git a/test/run-dfinity/ok/generic-tail-rec.dvm-run.ok b/test/run-dfinity/ok/generic-tail-rec.dvm-run.ok index 1cfb8645d12..6d96c93ceef 100644 --- a/test/run-dfinity/ok/generic-tail-rec.dvm-run.ok +++ b/test/run-dfinity/ok/generic-tail-rec.dvm-run.ok @@ -2,4 +2,3 @@ done 1 done 2 done 3 done 4 -Top-level code done. diff --git a/test/run-dfinity/ok/hello-concat-world.dvm-run.ok b/test/run-dfinity/ok/hello-concat-world.dvm-run.ok index 8d9d4c9eb23..980a0d5f19a 100644 --- a/test/run-dfinity/ok/hello-concat-world.dvm-run.ok +++ b/test/run-dfinity/ok/hello-concat-world.dvm-run.ok @@ -1,2 +1 @@ Hello World! -Top-level code done. diff --git a/test/run-dfinity/ok/hello-world-async.dvm-run.ok b/test/run-dfinity/ok/hello-world-async.dvm-run.ok index 9c393e21691..980a0d5f19a 100644 --- a/test/run-dfinity/ok/hello-world-async.dvm-run.ok +++ b/test/run-dfinity/ok/hello-world-async.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. Hello World! diff --git a/test/run-dfinity/ok/hello-world-await.dvm-run.ok b/test/run-dfinity/ok/hello-world-await.dvm-run.ok index 9c393e21691..980a0d5f19a 100644 --- a/test/run-dfinity/ok/hello-world-await.dvm-run.ok +++ b/test/run-dfinity/ok/hello-world-await.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. Hello World! diff --git a/test/run-dfinity/ok/hello-world-message.dvm-run.ok b/test/run-dfinity/ok/hello-world-message.dvm-run.ok new file mode 100644 index 00000000000..f01f4492e8f --- /dev/null +++ b/test/run-dfinity/ok/hello-world-message.dvm-run.ok @@ -0,0 +1,2 @@ +DVM: Calling method hello +Hello World! diff --git a/test/run-dfinity/ok/hello-world.dvm-run.ok b/test/run-dfinity/ok/hello-world.dvm-run.ok index 8d9d4c9eb23..980a0d5f19a 100644 --- a/test/run-dfinity/ok/hello-world.dvm-run.ok +++ b/test/run-dfinity/ok/hello-world.dvm-run.ok @@ -1,2 +1 @@ Hello World! -Top-level code done. diff --git a/test/run-dfinity/ok/hello-world2.dvm-run.ok b/test/run-dfinity/ok/hello-world2.dvm-run.ok index 9c393e21691..980a0d5f19a 100644 --- a/test/run-dfinity/ok/hello-world2.dvm-run.ok +++ b/test/run-dfinity/ok/hello-world2.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. Hello World! diff --git a/test/run-dfinity/ok/hello-world3.dvm-run.ok b/test/run-dfinity/ok/hello-world3.dvm-run.ok index 9c393e21691..980a0d5f19a 100644 --- a/test/run-dfinity/ok/hello-world3.dvm-run.ok +++ b/test/run-dfinity/ok/hello-world3.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. Hello World! diff --git a/test/run-dfinity/ok/indirect-counter.dvm-run.ok b/test/run-dfinity/ok/indirect-counter.dvm-run.ok index a3480e087a1..dc01807c8fe 100644 --- a/test/run-dfinity/ok/indirect-counter.dvm-run.ok +++ b/test/run-dfinity/ok/indirect-counter.dvm-run.ok @@ -1,2 +1 @@ -Top-level code done. 2344 diff --git a/test/run-dfinity/ok/large-mem.dvm-run.ok b/test/run-dfinity/ok/large-mem.dvm-run.ok deleted file mode 100644 index 3b7e66c4381..00000000000 --- a/test/run-dfinity/ok/large-mem.dvm-run.ok +++ /dev/null @@ -1 +0,0 @@ -Top-level code done. diff --git a/test/run-dfinity/ok/nary-async.dvm-run.ok b/test/run-dfinity/ok/nary-async.dvm-run.ok index b4dbdd9a6ee..5b2baf03eb2 100644 --- a/test/run-dfinity/ok/nary-async.dvm-run.ok +++ b/test/run-dfinity/ok/nary-async.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. 0_0 1_0 2_0 diff --git a/test/run-dfinity/ok/no-boxed-references.dvm-run.ok b/test/run-dfinity/ok/no-boxed-references.dvm-run.ok deleted file mode 100644 index 3b7e66c4381..00000000000 --- a/test/run-dfinity/ok/no-boxed-references.dvm-run.ok +++ /dev/null @@ -1 +0,0 @@ -Top-level code done. diff --git a/test/run-dfinity/ok/overflow.dvm-run.ok b/test/run-dfinity/ok/overflow.dvm-run.ok index 5db4566da42..8ca337c71a9 100644 --- a/test/run-dfinity/ok/overflow.dvm-run.ok +++ b/test/run-dfinity/ok/overflow.dvm-run.ok @@ -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. diff --git a/test/run-dfinity/ok/reference-params.dvm-run.ok b/test/run-dfinity/ok/reference-params.dvm-run.ok index 9a57656f7a1..8650e0ef3bf 100644 --- a/test/run-dfinity/ok/reference-params.dvm-run.ok +++ b/test/run-dfinity/ok/reference-params.dvm-run.ok @@ -1,4 +1,3 @@ -Top-level code done. Hello World! Hello World! Hello World! diff --git a/test/run-dfinity/ok/selftail.dvm-run.ok b/test/run-dfinity/ok/selftail.dvm-run.ok index d58ee786174..acb397e19f2 100644 --- a/test/run-dfinity/ok/selftail.dvm-run.ok +++ b/test/run-dfinity/ok/selftail.dvm-run.ok @@ -1,3 +1,2 @@ ok1 ok2 -Top-level code done. diff --git a/test/run-dfinity/ok/tailpositions.dvm-run.ok b/test/run-dfinity/ok/tailpositions.dvm-run.ok index a0ef19cc3e9..025c12b0e9a 100644 --- a/test/run-dfinity/ok/tailpositions.dvm-run.ok +++ b/test/run-dfinity/ok/tailpositions.dvm-run.ok @@ -5,4 +5,3 @@ done 4 done 5 done 6 done 7 -Top-level code done. diff --git a/test/run-dfinity/ok/the-answer.dvm-run.ok b/test/run-dfinity/ok/the-answer.dvm-run.ok index 911d4f5b36f..d81cc0710eb 100644 --- a/test/run-dfinity/ok/the-answer.dvm-run.ok +++ b/test/run-dfinity/ok/the-answer.dvm-run.ok @@ -1 +1 @@ -42Top-level code done. +42 diff --git a/test/run.sh b/test/run.sh index cebe0283ca6..e922b3bc660 100755 --- a/test/run.sh +++ b/test/run.sh @@ -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" @@ -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 diff --git a/test/run/type-equivalence.as b/test/run/type-equivalence.as index b3256842fe9..0610b069f84 100644 --- a/test/run/type-equivalence.as +++ b/test/run/type-equivalence.as @@ -224,3 +224,5 @@ func f2(x : A2) : A2 = x : B2; func g1(x : A1) : A1 = x : C1; func g2(x : A2) : A2 = x : C2; }; + +() diff --git a/test/run/type-inclusion.as b/test/run/type-inclusion.as index 44b8e818c8f..14217da15eb 100644 --- a/test/run/type-inclusion.as +++ b/test/run/type-inclusion.as @@ -237,3 +237,5 @@ func f2(x : A2) : B2 = x; func g1(x : A1) : C1 = x; func g2(x : A2) : C2 = x; }; + +()