Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Collapse assert_return_canonical_nan and assert_return_arithmetic_nan to assert_return #142

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 1 addition & 5 deletions interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,7 @@ let of_assertion mods ass =
"assert_uninstantiable(" ^ of_definition def ^ ");"
| AssertReturn (act, lits) ->
of_assertion' mods act "assert_return" (List.map of_literal lits)
(Some (assert_return lits))
| AssertReturnCanonicalNaN act ->
of_assertion' mods act "assert_return_canonical_nan" [] (Some assert_return_canonical_nan)
| AssertReturnArithmeticNaN act ->
of_assertion' mods act "assert_return_arithmetic_nan" [] (Some assert_return_arithmetic_nan)
(Some (assert_return lits)) (* TODO *)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly sure if I understand what this is for; is it generating JS code? If that is the case, I likely need to match and emit different code for each branch.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is for generating a JS version of the test.

| AssertTrap (act, _) ->
of_assertion' mods act "assert_trap" [] None
| AssertExhaustion (act, _) ->
Expand Down
2 changes: 1 addition & 1 deletion interpreter/script/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ let run_assertion ass =
| _ -> Assert.error ass.at "expected instantiation error"
)

| AssertReturn (act, vs) ->
| AssertReturn (act, vs, modifier) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I foresee vs going away and matching on modifier here

Copy link
Member

Choose a reason for hiding this comment

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

There wouldn't be a modifier here. Instead, vs would change from a list of values to a list of "results", which would be a new type.

trace ("Asserting return...");
let got_vs = run_action act in
let expect_vs = List.map (fun v -> v.it) vs in
Expand Down
11 changes: 8 additions & 3 deletions interpreter/script/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ and action' =
| Invoke of var option * Ast.name * Ast.literal list
| Get of var option * Ast.name

type assert_return_comparison = comparison' Source.phrase
and comparison' =
| AssertReturnConstant of Ast.literal list
| AssertReturnArithmeticNan (* TODO f32x4 | f64x2 *)
| AssertReturnCanonicalNan (* TODO f32x4 | f64x2 *)
(* TODO (ref.any) | (ref.func) *)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't seem to find types for ref.any or ref.func?

Copy link
Member

Choose a reason for hiding this comment

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

Those would be added the reference types proposal.


type assertion = assertion' Source.phrase
and assertion' =
| AssertMalformed of definition * string
| AssertInvalid of definition * string
| AssertUnlinkable of definition * string
| AssertUninstantiable of definition * string
| AssertReturn of action * Ast.literal list
| AssertReturnCanonicalNaN of action
| AssertReturnArithmeticNaN of action
| AssertReturn of action * assert_return_comparison
| AssertTrap of action * string
| AssertExhaustion of action * string

Expand Down
6 changes: 1 addition & 5 deletions interpreter/text/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,7 @@ let assertion mode ass =
| AssertUninstantiable (def, re) ->
Node ("assert_trap", [definition mode None def; Atom (string re)])
| AssertReturn (act, lits) ->
Node ("assert_return", action act :: List.map literal lits)
| AssertReturnCanonicalNaN act ->
Node ("assert_return_canonical_nan", [action act])
| AssertReturnArithmeticNaN act ->
Node ("assert_return_arithmetic_nan", [action act])
Node ("assert_return", [action act]) (* TODO :: List.map literal lits) *)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will need to handle modifier (or whatever we want to call it) instead of a list of literals but, to make sure, this is a serializer of the AST?

| AssertTrap (act, re) ->
Node ("assert_trap", [action act; Atom (string re)])
| AssertExhaustion (act, re) ->
Expand Down
4 changes: 2 additions & 2 deletions interpreter/text/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ rule token = parse
| "assert_invalid" { ASSERT_INVALID }
| "assert_unlinkable" { ASSERT_UNLINKABLE }
| "assert_return" { ASSERT_RETURN }
| "assert_return_canonical_nan" { ASSERT_RETURN_CANONICAL_NAN }
| "assert_return_arithmetic_nan" { ASSERT_RETURN_ARITHMETIC_NAN }
| "canonical_nan" { CANONICAL_NAN }
| "arithmetic_nan" { ARITHMETIC_NAN }
| "assert_trap" { ASSERT_TRAP }
| "assert_exhaustion" { ASSERT_EXHAUSTION }
| "input" { INPUT }
Expand Down
12 changes: 8 additions & 4 deletions interpreter/text/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ let inline_type_explicit (c : context) x ft at =
%token MODULE BIN QUOTE
%token SCRIPT REGISTER INVOKE GET
%token ASSERT_MALFORMED ASSERT_INVALID ASSERT_SOFT_INVALID ASSERT_UNLINKABLE
%token ASSERT_RETURN ASSERT_RETURN_CANONICAL_NAN ASSERT_RETURN_ARITHMETIC_NAN ASSERT_TRAP ASSERT_EXHAUSTION
%token ASSERT_RETURN CANONICAL_NAN ARITHMETIC_NAN ASSERT_TRAP ASSERT_EXHAUSTION
%token INPUT OUTPUT
%token EOF

Expand Down Expand Up @@ -795,12 +795,16 @@ assertion :
{ AssertUnlinkable (snd $3, $4) @@ at () }
| LPAR ASSERT_TRAP script_module STRING RPAR
{ AssertUninstantiable (snd $3, $4) @@ at () }
| LPAR ASSERT_RETURN action const_list RPAR { AssertReturn ($3, $4) @@ at () }
| LPAR ASSERT_RETURN_CANONICAL_NAN action RPAR { AssertReturnCanonicalNaN $3 @@ at () }
| LPAR ASSERT_RETURN_ARITHMETIC_NAN action RPAR { AssertReturnArithmeticNaN $3 @@ at () }
| LPAR ASSERT_RETURN action assert_return_modifier RPAR { AssertReturn ($3, $4) @@ at () }
| LPAR ASSERT_TRAP action STRING RPAR { AssertTrap ($3, $4) @@ at () }
| LPAR ASSERT_EXHAUSTION action STRING RPAR { AssertExhaustion ($3, $4) @@ at () }

assert_return_modifier :
| const_list { AssertReturnConstant ($1) @@ at () }
| LPAR ARITHMETIC_NAN /* TODO f32x4 | f64x2 */ RPAR { AssertReturnArithmeticNan @@ at () }
| LPAR CANONICAL_NAN /* TODO f32x4 | f64x2 */ RPAR { AssertReturnCanonicalNan @@ at () }
/* TODO (ref.any) | (ref.func) */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I be able to implement the branches for ref.any and ref.func?


cmd :
| action { Action $1 @@ at () }
| assertion { Assertion $1 @@ at () }
Expand Down