From 2df5900844d0fbe872ca6ea36f694311edb13052 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Tue, 23 Jul 2024 16:33:30 +0200 Subject: [PATCH] parse inline quoted module in scripts --- src/ast/text.ml | 2 ++ src/parser/text_parser.mly | 8 ++++++-- src/script/script.ml | 10 ++++++++-- test/script/passing.t | 1 + test/script/passing/quoted.wast | 3 +++ test/script/reference.t | 2 -- test/script/reference_opt.t | 2 -- 7 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 test/script/passing/quoted.wast diff --git a/src/ast/text.ml b/src/ast/text.ml index bc9baa8cb..00425caeb 100644 --- a/src/ast/text.ml +++ b/src/ast/text.ml @@ -178,6 +178,7 @@ type register = string * string option let pp_register fmt (s, _name) = pf fmt "(register %s)" s type cmd = + | Quoted_module of string | Binary_module of string option * string | Text_module of modul | Assert of assertion @@ -185,6 +186,7 @@ type cmd = | Action of action let pp_cmd fmt = function + | Quoted_module m -> pf fmt "(module %S)" m | Binary_module (id, m) -> Fmt.pf fmt "(module %a %S)" Types.pp_id_opt id m | Text_module m -> pp_modul fmt m | Assert a -> pp_assertion fmt a diff --git a/src/parser/text_parser.mly b/src/parser/text_parser.mly index be0567347..9fad2eec4 100644 --- a/src/parser/text_parser.mly +++ b/src/parser/text_parser.mly @@ -1002,8 +1002,6 @@ let inline_module := let modul := | LPAR; MODULE; id = ioption(id); ~ = inline_module_inner; RPAR; { - (* TODO: handle fields_bin - let fields_bin = String.concat "" l in *) { inline_module_inner with id } } @@ -1012,6 +1010,11 @@ let module_binary := id, String.concat "" lines } +let module_quoted := + | MODULE; QUOTE; lines = list(NAME); { + String.concat "" lines + } + let literal_const == | I32_CONST; num = NUM; { Const_I32 (i32 num) } | I64_CONST; num = NUM; { Const_I64 (i64 num) } @@ -1078,6 +1081,7 @@ let action == let cmd == | ~ = modul; + | ~ = par(module_quoted); | bm = par(module_binary); { let id, m = bm in Binary_module (id, m) diff --git a/src/script/script.ml b/src/script/script.ml index dc452b7e8..7a0f7f009 100644 --- a/src/script/script.ml +++ b/src/script/script.ml @@ -161,8 +161,15 @@ let run ~no_exhaustion ~optimize script = in Log.debug_on := debug_on; link_state + | Text.Quoted_module m -> + Log.debug0 "*** quoted module@\n"; + incr curr_module; + let* m = Parse.Text.Inline_module.from_string m in + let+ link_state = + Compile.Text.until_interpret link_state ~unsafe ~optimize ~name:None m + in + link_state | Text.Binary_module (id, m) -> - if !curr_module = 0 then Log.debug_on := false; Log.debug0 "*** binary module@\n"; incr curr_module; let* m = Parse.Binary.Module.from_string m in @@ -171,7 +178,6 @@ let run ~no_exhaustion ~optimize script = Compile.Binary.until_interpret link_state ~unsafe ~optimize ~name:None m in - Log.debug_on := debug_on; link_state | Assert (Assert_trap_module (m, expected)) -> Log.debug0 "*** assert_trap@\n"; diff --git a/test/script/passing.t b/test/script/passing.t index 1fe374791..afa8785af 100644 --- a/test/script/passing.t +++ b/test/script/passing.t @@ -43,3 +43,4 @@ $ owi script --no-exhaustion passing/typecheck4.wast $ owi script --no-exhaustion passing/typecheckbis.wast $ owi script --no-exhaustion passing/typecheck.wast + $ owi script --no-exhaustion passing/quoted.wast diff --git a/test/script/passing/quoted.wast b/test/script/passing/quoted.wast new file mode 100644 index 000000000..a9cdf9d0f --- /dev/null +++ b/test/script/passing/quoted.wast @@ -0,0 +1,3 @@ +(module quote + "(func )" +) diff --git a/test/script/reference.t b/test/script/reference.t index 706600b2c..0014a00e0 100644 --- a/test/script/reference.t +++ b/test/script/reference.t @@ -12,8 +12,6 @@ $ owi script --no-exhaustion reference/call_indirect.wast $ owi script --no-exhaustion reference/call.wast $ owi script --no-exhaustion reference/comments.wast - unexpected token "\"(func (export \"f1\") (result i32)\"" - [40] $ owi script --no-exhaustion reference/const.wast $ owi script --no-exhaustion reference/conversions.wast $ owi script --no-exhaustion reference/custom.wast diff --git a/test/script/reference_opt.t b/test/script/reference_opt.t index 73be5f4fa..030425184 100644 --- a/test/script/reference_opt.t +++ b/test/script/reference_opt.t @@ -12,8 +12,6 @@ $ owi script --no-exhaustion --optimize reference/call_indirect.wast $ owi script --no-exhaustion --optimize reference/call.wast $ owi script --no-exhaustion --optimize reference/comments.wast - unexpected token "\"(func (export \"f1\") (result i32)\"" - [40] $ owi script --no-exhaustion --optimize reference/const.wast $ owi script --no-exhaustion --optimize reference/conversions.wast $ owi script --no-exhaustion --optimize reference/custom.wast