Skip to content

Commit

Permalink
Remove 'types', use individual 'type' defs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Oct 14, 2015
1 parent 4baf913 commit 5666cee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
1 change: 0 additions & 1 deletion ml-proto/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ rule token = parse
| "grow_memory" { GROW_MEMORY }

| "type" { TYPE }
| "types" { TYPES }
| "func" { FUNC }
| "param" { PARAM }
| "result" { RESULT }
Expand Down
28 changes: 13 additions & 15 deletions ml-proto/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ let implicit_decl c t at =
%token GET_LOCAL SET_LOCAL LOAD STORE
%token CONST UNARY BINARY COMPARE CONVERT
%token FUNC TYPE PARAM RESULT LOCAL
%token MODULE MEMORY TYPES SEGMENT IMPORT EXPORT TABLE
%token MODULE MEMORY SEGMENT IMPORT EXPORT TABLE
%token PAGE_SIZE MEMORY_SIZE GROW_MEMORY
%token ASSERT_INVALID ASSERT_RETURN ASSERT_RETURN_NAN ASSERT_TRAP INVOKE
%token EOF
Expand Down Expand Up @@ -304,15 +304,15 @@ func_fields :
fun c -> bind_local c $3; let f = (snd $6) c in
{f with locals = $4 :: f.locals} }
;
type_decl :
type_use :
| LPAR TYPE var RPAR { $3 }
;
func :
| LPAR FUNC type_decl func_fields RPAR
| LPAR FUNC type_use func_fields RPAR
{ let at = at () in
fun c -> anon_func c; let t = explicit_decl c $3 (fst $4) at in
fun () -> {((snd $4) (enter_func c)) with ftype = t} @@ at }
| LPAR FUNC bind_var type_decl func_fields RPAR /* Sugar */
| LPAR FUNC bind_var type_use func_fields RPAR /* Sugar */
{ let at = at () in
fun c -> bind_func c $3; let t = explicit_decl c $4 (fst $5) at in
fun () -> {((snd $5) (enter_func c)) with ftype = t} @@ at }
Expand Down Expand Up @@ -347,21 +347,19 @@ memory :
@@ at () }
;
type_list :
| /* empty */
{ fun c -> () }
| LPAR FUNC func_type RPAR type_list
{ fun c -> anon_type c $3; $5 c }
| LPAR FUNC bind_var func_type RPAR type_list /* Sugar */
{ fun c -> bind_type c $3 $4; $6 c }
type_def :
| LPAR TYPE LPAR FUNC func_type RPAR RPAR
{ fun c -> anon_type c $5 }
| LPAR TYPE bind_var LPAR FUNC func_type RPAR RPAR
{ fun c -> bind_type c $3 $6 }
;
import :
| LPAR IMPORT TEXT TEXT type_decl RPAR
| LPAR IMPORT TEXT TEXT type_use RPAR
{ let at = at () in
fun c -> anon_import c; let itype = explicit_decl c $5 empty_type at in
{itype; module_name = $3; func_name = $4} @@ at }
| LPAR IMPORT bind_var TEXT TEXT type_decl RPAR /* Sugar */
| LPAR IMPORT bind_var TEXT TEXT type_use RPAR /* Sugar */
{ let at = at () in
fun c -> bind_import c $3; let itype = explicit_decl c $6 empty_type at in
{itype; module_name = $4; func_name = $5} @@ at }
Expand Down Expand Up @@ -397,8 +395,8 @@ module_fields :
| LPAR TABLE var_list RPAR module_fields
{ fun c -> let m = $5 c in
{m with tables = ($3 c func @@ ati 3) :: m.tables} }
| LPAR TYPES type_list RPAR module_fields
{ fun c -> $3 c; $5 c }
| type_def module_fields
{ fun c -> $1 c; $2 c }
| memory module_fields
{ fun c -> let m = $2 c in
match m.memory with
Expand Down
22 changes: 10 additions & 12 deletions ml-proto/test/func_ptrs.wast
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
(module
(types
(func) ;; 0: void -> void
(func $A) ;; 1: void -> void
(func (param)) ;; 2: void -> void
(func (result i32)) ;; 3: void -> i32
(func (param) (result i32)) ;; 4: void -> i32
(func $T (param i32) (result i32)) ;; 5: i32 -> i32
(func $U (param i32)) ;; 6: i32 -> void
)
(type (func)) ;; 0: void -> void
(type $S (func)) ;; 1: void -> void
(type (func (param))) ;; 2: void -> void
(type (func (result i32))) ;; 3: void -> i32
(type (func (param) (result i32))) ;; 4: void -> i32
(type $T (func (param i32) (result i32))) ;; 5: i32 -> i32
(type $U (func (param i32))) ;; 6: i32 -> void

(func (type 0))
(func (type $S))

(func $one (type 4) (i32.const 13))
(export "one" $one)
Expand All @@ -23,9 +24,6 @@
(import $print "stdio" "print" (type 6))
(func $four (type $U) (call_import $print (get_local 0)))
(export "four" $four)

(func (type 0))
(func (type $A))
)
(assert_return (invoke "one") (i32.const 13))
(assert_return (invoke "two" (i32.const 13)) (i32.const 14))
Expand Down

0 comments on commit 5666cee

Please sign in to comment.