Skip to content

Commit

Permalink
[spec] Fix float text format (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg authored Sep 17, 2019
1 parent 352edf4 commit c94f0c1
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 0 deletions.
4 changes: 4 additions & 0 deletions document/core/text/values.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ Floating-Point
h{:}\Thexdigit~~q{:}\Thexfrac &\Rightarrow& (h+q)/16 \\ &&|&
h{:}\Thexdigit~~\text{\_}~~~~p{:}\Thexdigit~~q{:}\Thexfrac &\Rightarrow& (h+(p+q)/16)/16 \\
\production{decimal floating-point number} & \Tfloat &::=&
p{:}\Tnum
&\Rightarrow& p \\ &&|&
p{:}\Tnum~\text{.}~q{:}\Tfrac
&\Rightarrow& p+q \\ &&|&
p{:}\Tnum~(\text{E}~|~\text{e})~{\pm}{:}\Tsign~e{:}\Tnum
&\Rightarrow& p\cdot 10^{\pm e} \\ &&|&
p{:}\Tnum~\text{.}~q{:}\Tfrac~(\text{E}~|~\text{e})~{\pm}{:}\Tsign~e{:}\Tnum
&\Rightarrow& (p+q)\cdot 10^{\pm e} \\
\production{hexadecimal floating-point number} & \Thexfloat &::=&
\text{0x}~p{:}\Thexnum
&\Rightarrow& p \\ &&|&
\text{0x}~p{:}\Thexnum~\text{.}~q{:}\Thexfrac
&\Rightarrow& p+q \\ &&|&
\text{0x}~p{:}\Thexnum~(\text{P}~|~\text{p})~{\pm}{:}\Tsign~e{:}\Tnum
Expand Down
1 change: 1 addition & 0 deletions interpreter/exec/float.ml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ struct
let m = logor (logand bits 0xf_ffff_ffff_ffffL) 0x10_0000_0000_0000L in
(* Shift mantissa to match msb position in most significant hex digit *)
let i = skip_zeroes (String.uppercase s) 0 in
if i = String.length s then Printf.sprintf "%.*g" (String.length s) z else
let sh =
match s.[i] with '1' -> 0 | '2'..'3' -> 1 | '4'..'7' -> 2 | _ -> 3 in
Printf.sprintf "%Lx" (shift_left m sh)
Expand Down
244 changes: 244 additions & 0 deletions test/core/const.wast
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,250 @@

;; Syntax error

(module (func (i32.const 0_123_456_789) drop))
(module (func (i32.const 0x0_9acf_fBDF) drop))
(assert_malformed
(module quote "(func (i32.const) drop)")
"unexpected token"
)
(assert_malformed
(module quote "(func (i32.const 0x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (i32.const 1x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (i32.const 0xg) drop)")
"unknown operator"
)

(module (func (i64.const 0_123_456_789) drop))
(module (func (i64.const 0x0125_6789_ADEF_bcef) drop))
(assert_malformed
(module quote "(func (i64.const) drop)")
"unexpected token"
)
(assert_malformed
(module quote "(func (i64.const 0x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (i64.const 1x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (i64.const 0xg) drop)")
"unknown operator"
)

(module (func (f32.const 0123456789) drop))
(module (func (f32.const 0123456789e019) drop))
(module (func (f32.const 0123456789e+019) drop))
(module (func (f32.const 0123456789e-019) drop))
(module (func (f32.const 0123456789.) drop))
(module (func (f32.const 0123456789.e019) drop))
(module (func (f32.const 0123456789.e+019) drop))
(module (func (f32.const 0123456789.e-019) drop))
(module (func (f32.const 0123456789.0123456789) drop))
(module (func (f32.const 0123456789.0123456789e019) drop))
(module (func (f32.const 0123456789.0123456789e+019) drop))
(module (func (f32.const 0123456789.0123456789e-019) drop))
(module (func (f32.const 0x0123456789ABCDEF) drop))
(module (func (f32.const 0x0123456789ABCDEFp019) drop))
(module (func (f32.const 0x0123456789ABCDEFp+019) drop))
(module (func (f32.const 0x0123456789ABCDEFp-019) drop))
(module (func (f32.const 0x0123456789ABCDEF.) drop))
(module (func (f32.const 0x0123456789ABCDEF.p019) drop))
(module (func (f32.const 0x0123456789ABCDEF.p+019) drop))
(module (func (f32.const 0x0123456789ABCDEF.p-019) drop))
(module (func (f32.const 0x0123456789ABCDEF.019aF) drop))
(module (func (f32.const 0x0123456789ABCDEF.019aFp019) drop))
(module (func (f32.const 0x0123456789ABCDEF.019aFp+019) drop))
(module (func (f32.const 0x0123456789ABCDEF.019aFp-019) drop))
(assert_malformed
(module quote "(func (f32.const) drop)")
"unexpected token"
)
(assert_malformed
(module quote "(func (f32.const .0) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const .0e0) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0e) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0e+) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0.0e) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0.0e-) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 1x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0xg) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x.) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0.g) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0p) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0p+) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0p-) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0.0p) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0.0p+) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0.0p-) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f32.const 0x0pA) drop)")
"unknown operator"
)


(module (func (f64.const 0123456789) drop))
(module (func (f64.const 0123456789e019) drop))
(module (func (f64.const 0123456789e+019) drop))
(module (func (f64.const 0123456789e-019) drop))
(module (func (f64.const 0123456789.) drop))
(module (func (f64.const 0123456789.e019) drop))
(module (func (f64.const 0123456789.e+019) drop))
(module (func (f64.const 0123456789.e-019) drop))
(module (func (f64.const 0123456789.0123456789) drop))
(module (func (f64.const 0123456789.0123456789e019) drop))
(module (func (f64.const 0123456789.0123456789e+019) drop))
(module (func (f64.const 0123456789.0123456789e-019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdefp019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdefp+019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdefp-019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.p019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.p+019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.p-019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.0123456789ABCDEFabcdef) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.0123456789ABCDEFabcdefp019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.0123456789ABCDEFabcdefp+019) drop))
(module (func (f64.const 0x0123456789ABCDEFabcdef.0123456789ABCDEFabcdefp-019) drop))
(assert_malformed
(module quote "(func (f64.const) drop)")
"unexpected token"
)
(assert_malformed
(module quote "(func (f64.const .0) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const .0e0) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0e) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0e+) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0.0e) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0.0e-) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 1x) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0xg) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x.) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0.g) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0p) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0p+) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0p-) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0.0p) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0.0p+) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0.0p-) drop)")
"unknown operator"
)
(assert_malformed
(module quote "(func (f64.const 0x0pA) drop)")
"unknown operator"
)


;; Range error

(module (func (i32.const 0xffffffff) drop))
(module (func (i32.const -0x80000000) drop))
(assert_malformed
Expand Down

0 comments on commit c94f0c1

Please sign in to comment.