Skip to content

Commit

Permalink
Parse hex literals
Browse files Browse the repository at this point in the history
  • Loading branch information
binji committed Sep 14, 2015
1 parent 3d2937a commit c78a45c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ml-proto/src/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ let escape = ['n''t''\\''\'''\"']
let character = [^'"''\\''\n'] | '\\'escape | '\\'hexdigit hexdigit

let num = ('+' | '-')? digit+
let int = num
let hexnum = ('+' | '-')? "0x" hexdigit+
let int = num | hexnum
let float = (num '.' digit+) | num ('.' digit+)? ('e' | 'E') num
let text = '"' character* '"'
let name = '$' (letter | digit | '_' | tick | symbol)+
Expand Down
39 changes: 39 additions & 0 deletions ml-proto/test/hexnum.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(module
(func $test32 (result i32)
(return (i32.const 0x0badd00d))
)

(func $max32 (result i32)
(return (i32.const 0xffffffff))
)

(func $neg32 (result i32)
(return (i32.const -0x7fffffff))
)

(func $test64 (result i64)
(return (i64.const 0x0cabba6e0ba66a6e))
)

(func $max64 (result i64)
(return (i64.const 0xffffffffffffffff))
)

(func $neg64 (result i64)
(return (i64.const -0x7fffffffffffffff))
)

(export "test32" $test32)
(export "max32" $max32)
(export "neg32" $neg32)
(export "test64" $test64)
(export "max64" $max64)
(export "neg64" $neg64)
)

(assert_eq (invoke "test32") (i32.const 195940365))
(assert_eq (invoke "max32") (i32.const -1))
(assert_eq (invoke "neg32") (i32.const -2147483647))
(assert_eq (invoke "test64") (i64.const 913028331277281902))
(assert_eq (invoke "max64") (i64.const -1))
(assert_eq (invoke "neg64") (i64.const -9223372036854775807))

0 comments on commit c78a45c

Please sign in to comment.