From b03471271bbf8240b9a7e2cf3049a0eadc7866f9 Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Sat, 20 Jan 2018 22:39:16 -0800 Subject: [PATCH] add more toplevel definitions --- src/Language/Wasm/Parser.y | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Language/Wasm/Parser.y b/src/Language/Wasm/Parser.y index 249bd7d..3b2588b 100644 --- a/src/Language/Wasm/Parser.y +++ b/src/Language/Wasm/Parser.y @@ -521,6 +521,8 @@ importdesc :: { ImportDesc } import :: { Import } : '(' 'import' name name importdesc ')' { Import $3 $4 $5 } | '(' 'func' opt(ident) '(' 'import' name name ')' typeuse ')' { Import $6 $7 $ ImportFunc $3 $9 } + | '(' 'global' opt(ident) '(' 'import' name name ')' globaltype ')' { Import $6 $7 $ ImportGlobal $3 $9 } + | '(' 'memory' opt(ident) '(' 'import' name name ')' limits ')' { Import $6 $7 $ ImportMemory $3 $9 } localtypes :: { [LocalType] } : list(localtype) { concat $1 } @@ -532,6 +534,15 @@ localtype :: { [LocalType] } function :: { Function } : '(' 'func' opt(ident) typeuse localtypes list(foldedinstr) ')' { Function $3 $4 $5 (concat $6) } +global :: { Global } + : '(' 'global' opt(ident) globaltype list(foldedinstr) ')' { Global $3 $4 (concat $5) } + +memory :: { Memory } + : '(' 'memory' opt(ident) limits ')' { Memory $3 $4 } + +table :: { Table } + : '(' 'table' opt(ident) tabletype ')' { Table $3 $4 } + -- utils rev_list(p) @@ -855,6 +866,17 @@ data Function = Function { } deriving (Show, Eq) +data Global = Global { + ident :: Maybe Ident, + globalType :: GlobalType, + initializer :: [Instruction] + } + deriving (Show, Eq) + +data Memory = Memory (Maybe Ident) Limit deriving (Show, Eq) + +data Table = Table (Maybe Ident) TableType deriving (Show, Eq) + happyError tokens = error $ "Error occuried: " ++ show tokens } \ No newline at end of file