From 3ea374b452c6d6b6f94ac627f70a52fde0e0cc89 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 14 Sep 2015 11:36:06 -0700 Subject: [PATCH] Parse hex literals --- ml-proto/src/host/lexer.mll | 3 ++- ml-proto/test/hexnum.wasm | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 ml-proto/test/hexnum.wasm diff --git a/ml-proto/src/host/lexer.mll b/ml-proto/src/host/lexer.mll index 92b87eefe0..e4e1040e59 100644 --- a/ml-proto/src/host/lexer.mll +++ b/ml-proto/src/host/lexer.mll @@ -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)+ diff --git a/ml-proto/test/hexnum.wasm b/ml-proto/test/hexnum.wasm new file mode 100644 index 0000000000..403d11de74 --- /dev/null +++ b/ml-proto/test/hexnum.wasm @@ -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))