Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse hex literals #61

Merged
merged 1 commit into from
Sep 16, 2015
Merged
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
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))