Skip to content

Commit

Permalink
parse inline quoted module in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Jul 23, 2024
1 parent 7439f3a commit 2df5900
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/ast/text.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ 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
| Register of string * string option
| 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
Expand Down
8 changes: 6 additions & 2 deletions src/parser/text_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand All @@ -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) }
Expand Down Expand Up @@ -1078,6 +1081,7 @@ let action ==

let cmd ==
| ~ = modul; <Text_module>
| ~ = par(module_quoted); <Quoted_module>
| bm = par(module_binary); {
let id, m = bm in
Binary_module (id, m)
Expand Down
10 changes: 8 additions & 2 deletions src/script/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
1 change: 1 addition & 0 deletions test/script/passing.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions test/script/passing/quoted.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(module quote
"(func )"
)
2 changes: 0 additions & 2 deletions test/script/reference.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/script/reference_opt.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2df5900

Please sign in to comment.