Permalink
Browse files

Symmetrise import/export syntax

  • Loading branch information...
rossberg committed Aug 30, 2016
1 parent 7e981f6 commit b5730287efdfc3c4388583f9e780b1f34a4fc8e7
Showing with 1,334 additions and 1,271 deletions.
  1. +73 −24 ml-proto/host/parser.mly
  2. +2 −2 ml-proto/test/address.wast
  3. +14 −14 ml-proto/test/block.wast
  4. +57 −57 ml-proto/test/br.wast
  5. +16 −16 ml-proto/test/br_if.wast
  6. +64 −64 ml-proto/test/br_table.wast
  7. +3 −3 ml-proto/test/break-drop.wast
  8. +19 −19 ml-proto/test/call.wast
  9. +21 −21 ml-proto/test/call_indirect.wast
  10. +25 −25 ml-proto/test/conversions.wast
  11. +17 −17 ml-proto/test/endianness.wast
  12. +4 −0 ml-proto/test/expected-output/imports.wast.log
  13. +12 −12 ml-proto/test/exports.wast
  14. +14 −14 ml-proto/test/f32.wast
  15. +6 −6 ml-proto/test/f32_cmp.wast
  16. +14 −14 ml-proto/test/f64.wast
  17. +6 −6 ml-proto/test/f64_cmp.wast
  18. +5 −5 ml-proto/test/fac.wast
  19. +224 −224 ml-proto/test/float_exprs.wast
  20. +60 −60 ml-proto/test/float_literals.wast
  21. +30 −30 ml-proto/test/float_memory.wast
  22. +29 −29 ml-proto/test/float_misc.wast
  23. +2 −2 ml-proto/test/forward.wast
  24. +55 −55 ml-proto/test/func.wast
  25. +8 −8 ml-proto/test/func_ptrs.wast
  26. +10 −10 ml-proto/test/get_local.wast
  27. +9 −9 ml-proto/test/globals.wast
  28. +29 −29 ml-proto/test/i32.wast
  29. +29 −29 ml-proto/test/i64.wast
  30. +14 −2 ml-proto/test/imports.wast
  31. +54 −54 ml-proto/test/int_exprs.wast
  32. +22 −22 ml-proto/test/int_literals.wast
  33. +17 −17 ml-proto/test/labels.wast
  34. +99 −99 ml-proto/test/left-to-right.wast
  35. +18 −18 ml-proto/test/loop.wast
  36. +17 −17 ml-proto/test/memory.wast
  37. +4 −4 ml-proto/test/memory_redundancy.wast
  38. +3 −3 ml-proto/test/memory_trap.wast
  39. +15 −15 ml-proto/test/names.wast
  40. +32 −32 ml-proto/test/nan-propagation.wast
  41. +11 −11 ml-proto/test/nop.wast
  42. +8 −8 ml-proto/test/resizing.wast
  43. +53 −53 ml-proto/test/return.wast
  44. +6 −6 ml-proto/test/select.wast
  45. +10 −10 ml-proto/test/set_local.wast
  46. +6 −8 ml-proto/test/start.wast
  47. +4 −4 ml-proto/test/switch.wast
  48. +11 −11 ml-proto/test/tee_local.wast
  49. +20 −20 ml-proto/test/traps.wast
  50. +53 −53 ml-proto/test/unreachable.wast
View
@@ -347,18 +347,32 @@ func_body :
{f with locals = $4 :: f.locals} }
;
func :
| LPAR FUNC export_name_opt bind_var_opt type_use func_fields RPAR
| LPAR FUNC bind_var_opt inline_export type_use func_fields RPAR
{ let at = at () in
fun c -> $4 c anon_func bind_func;
fun c -> $3 c anon_func bind_func;
let t = explicit_sig c $5 (fst $6) at in
(fun () -> {(snd $6 (enter_func c)) with ftype = t} @@ at),
$3 FuncExport c.funcs.count c }
| LPAR FUNC export_name_opt bind_var_opt func_fields RPAR /* Sugar */
$4 FuncExport c.funcs.count c }
/* Need to duplicate above for empty inline_export_opt to avoid LR(1) conflict. */
| LPAR FUNC bind_var_opt type_use func_fields RPAR
{ let at = at () in
fun c -> $4 c anon_func bind_func;
fun c -> $3 c anon_func bind_func;
let t = explicit_sig c $4 (fst $5) at in
(fun () -> {(snd $5 (enter_func c)) with ftype = t} @@ at),
[] }
| LPAR FUNC bind_var_opt inline_export func_fields RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_func bind_func;
let t = inline_type c (fst $5) at in
(fun () -> {(snd $5 (enter_func c)) with ftype = t} @@ at),
$3 FuncExport c.funcs.count c }
$4 FuncExport c.funcs.count c }
/* Need to duplicate above for empty inline_export_opt to avoid LR(1) conflict. */
| LPAR FUNC bind_var_opt func_fields RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_func bind_func;
let t = inline_type c (fst $4) at in
(fun () -> {(snd $4 (enter_func c)) with ftype = t} @@ at),
[] }
;
@@ -380,17 +394,17 @@ elem :
;
table :
| LPAR TABLE export_name_opt bind_var_opt limits elem_type RPAR
| LPAR TABLE bind_var_opt inline_export_opt limits elem_type RPAR
{ let at = at () in
fun c -> $4 c anon_table bind_table;
{tlimits = $5; etype = $6} @@ at, [], $3 TableExport c.tables.count c }
| LPAR TABLE export_name_opt bind_var_opt elem_type LPAR ELEM var_list RPAR RPAR /* Sugar */
fun c -> $3 c anon_table bind_table;
{tlimits = $5; etype = $6} @@ at, [], $4 TableExport c.tables.count c }
| LPAR TABLE bind_var_opt inline_export_opt elem_type LPAR ELEM var_list RPAR RPAR /* Sugar */
{ let at = at () in
fun c -> $4 c anon_table bind_table;
fun c -> $3 c anon_table bind_table;
let init = $8 c func in let size = Int32.of_int (List.length init) in
{tlimits = {min = size; max = Some size} @@ at; etype = $5} @@ at,
[{index = c.tables.count - 1 @@ at; offset = I32_const (0l @@ at) @@ at; init} @@ at],
$3 TableExport c.tables.count c }
$4 TableExport c.tables.count c }
;
data :
@@ -403,16 +417,24 @@ data :
;
memory :
| LPAR MEMORY export_name_opt bind_var_opt limits RPAR
{ fun c -> $4 c anon_memory bind_memory;
{mlimits = $5} @@ at (), [], $3 MemoryExport c.memories.count c }
| LPAR MEMORY export_name_opt bind_var_opt LPAR DATA text_list RPAR RPAR /* Sugar */
| LPAR MEMORY bind_var_opt inline_export_opt limits RPAR
{ fun c -> $3 c anon_memory bind_memory;
{mlimits = $5} @@ at (), [], $4 MemoryExport c.memories.count c }
| LPAR MEMORY bind_var_opt inline_export LPAR DATA text_list RPAR RPAR /* Sugar */
{ let at = at () in
fun c -> $4 c anon_memory bind_memory;
fun c -> $3 c anon_memory bind_memory;
let size = Int32.(div (add (of_int (String.length $7)) 65535l) 65536l) in
{mlimits = {min = size; max = Some size} @@ at} @@ at,
[{index = c.memories.count - 1 @@ at; offset = I32_const (0l @@ at) @@ at; init = $7} @@ at],
$3 MemoryExport c.memories.count c }
$4 MemoryExport c.memories.count c }
/* Need to duplicate above for empty inline_export_opt to avoid LR(1) conflict. */
| LPAR MEMORY bind_var_opt LPAR DATA text_list RPAR RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_memory bind_memory;
let size = Int32.(div (add (of_int (String.length $6)) 65535l) 65536l) in
{mlimits = {min = size; max = Some size} @@ at} @@ at,
[{index = c.memories.count - 1 @@ at; offset = I32_const (0l @@ at) @@ at; init = $6} @@ at],
[] }
;
@@ -436,6 +458,30 @@ import :
{ let at = at () and at6 = ati 6 in
fun c -> let bind, anon, k = $6 c in
$3 c anon bind; {module_name = $4; item_name = $5; ikind = k @@ at6} @@ at }
| LPAR FUNC bind_var_opt inline_import type_use RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_func bind_func;
{module_name = fst $4; item_name = snd $4; ikind = FuncImport ($5 c type_) @@ at} @@ at }
| LPAR FUNC bind_var_opt inline_import func_type RPAR /* Sugar */
{ let at = at () and at5 = ati 5 in
fun c -> $3 c anon_func bind_func;
{module_name = fst $4; item_name = snd $4; ikind = FuncImport (inline_type c $5 at5) @@ at} @@ at }
| LPAR TABLE bind_var_opt inline_import limits elem_type RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_table bind_table;
{module_name = fst $4; item_name = snd $4; ikind = TableImport ($5, $6) @@ at} @@ at }
| LPAR MEMORY bind_var_opt inline_import limits RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_memory bind_memory;
{module_name = fst $4; item_name = snd $4; ikind = MemoryImport $5 @@ at} @@ at }
| LPAR GLOBAL bind_var_opt inline_import VALUE_TYPE RPAR /* Sugar */
{ let at = at () in
fun c -> $3 c anon_global bind_global;
{module_name = fst $4; item_name = snd $4; ikind = GlobalImport $5 @@ at} @@ at }
;
inline_import :
| LPAR IMPORT TEXT TEXT RPAR { $3, $4 }
;
export_kind :
@@ -451,11 +497,14 @@ export :
{name = $3; ekind = k @@ at4; item = x} @@ at }
;
export_name_opt :
inline_export_opt :
| /* empty */ { fun k count c -> [] }
| TEXT
| inline_export { $1 }
;
inline_export :
| LPAR EXPORT TEXT RPAR
{ let at = at () in
fun k count c -> [{name = $1; ekind = k @@ at; item = count - 1 @@ at} @@ at] }
fun k count c -> [{name = $3; ekind = k @@ at; item = count - 1 @@ at} @@ at] }
;
@@ -469,11 +518,11 @@ type_def :
;
global :
| LPAR GLOBAL export_name_opt bind_var_opt VALUE_TYPE expr RPAR
| LPAR GLOBAL bind_var_opt inline_export_opt VALUE_TYPE expr RPAR
{ let at = at () in
fun c -> $4 c anon_global bind_global;
fun c -> $3 c anon_global bind_global;
(fun () -> {gtype = $5; value = $6 c} @@ at),
$3 GlobalExport c.globals.count c }
$4 GlobalExport c.globals.count c }
;
start :
@@ -4,7 +4,7 @@
(memory 1)
(data (i32.const 0) "abcdefghijklmnopqrstuvwxyz")
(func "good" (param $i i32)
(func (export "good") (param $i i32)
(call $print (i32.load8_u offset=0 (get_local $i))) ;; 97 'a'
(call $print (i32.load8_u offset=1 (get_local $i))) ;; 98 'b'
(call $print (i32.load8_u offset=2 (get_local $i))) ;; 99 'c'
@@ -22,7 +22,7 @@
(call $print (i32.load offset=25 align=1 (get_local $i))) ;; 122 'z\0\0\0'
)
(func "bad" (param $i i32) (drop (i32.load offset=4294967295 (get_local $i))))
(func (export "bad") (param $i i32) (drop (i32.load offset=4294967295 (get_local $i))))
)
(invoke "good" (i32.const 0))
View
@@ -4,29 +4,29 @@
;; Auxiliary definition
(func $dummy)
(func "empty"
(func (export "empty")
(block)
(block $l)
)
(func "singular" (result i32)
(func (export "singular") (result i32)
(block (nop))
(block (i32.const 7))
)
(func "multi" (result i32)
(func (export "multi") (result i32)
(block (call $dummy) (call $dummy) (call $dummy) (call $dummy))
(block (call $dummy) (call $dummy) (call $dummy) (i32.const 8))
)
(func "nested" (result i32)
(func (export "nested") (result i32)
(block
(block (call $dummy) (block) (nop))
(block (call $dummy) (i32.const 9))
)
)
(func "deep" (result i32)
(func (export "deep") (result i32)
(block (block (block (block (block (block (block (block (block (block
(block (block (block (block (block (block (block (block (block (block
(block (block (block (block (block (block (block (block (block (block
@@ -38,36 +38,36 @@
))))))))))
)
(func "as-unary-operand" (result i32)
(func (export "as-unary-operand") (result i32)
(i32.ctz (block (call $dummy) (i32.const 13)))
)
(func "as-binary-operand" (result i32)
(func (export "as-binary-operand") (result i32)
(i32.mul
(block (call $dummy) (i32.const 3))
(block (call $dummy) (i32.const 4))
)
)
(func "as-test-operand" (result i32)
(func (export "as-test-operand") (result i32)
(i32.eqz (block (call $dummy) (i32.const 13)))
)
(func "as-compare-operand" (result i32)
(func (export "as-compare-operand") (result i32)
(f32.gt
(block (call $dummy) (f32.const 3))
(block (call $dummy) (f32.const 3))
)
)
(func "break-bare" (result i32)
(func (export "break-bare") (result i32)
(block (br 0) (unreachable))
(block (br_if 0 (i32.const 1)) (unreachable))
(block (br_table 0 (i32.const 0)) (unreachable))
(block (br_table 0 0 0 (i32.const 1)) (unreachable))
(i32.const 19)
)
(func "break-value" (result i32)
(func (export "break-value") (result i32)
(block (br 0 (i32.const 18)) (i32.const 19))
)
(func "break-repeated" (result i32)
(func (export "break-repeated") (result i32)
(block
(br 0 (i32.const 18))
(br 0 (i32.const 19))
@@ -79,7 +79,7 @@
(i32.const 21)
)
)
(func "break-inner" (result i32)
(func (export "break-inner") (result i32)
(local i32)
(set_local 0 (i32.const 0))
(set_local 0 (i32.add (get_local 0) (block (block (br 1 (i32.const 0x1))))))
@@ -93,7 +93,7 @@
(get_local 0)
)
(func "effects" $fx (result i32)
(func (export "effects") (result i32)
(local i32)
(block
(set_local 0 (i32.const 1))
Oops, something went wrong.

0 comments on commit b573028

Please sign in to comment.