Bug 1306478 - BaldrMonkey: support arity-insensitive syntax; r=luke

MozReview-Commit-ID: Euf5jOK4OX4

--HG--
extra : rebase_source : 6e5f6432e32a73122fc76f9d4bb4bf9e793a96b3
This commit is contained in:
Dan Gohman 2016-10-24 18:33:07 +02:00
parent c13c2f061b
commit 66abfb6994
5 changed files with 44 additions and 30 deletions

View File

@ -1014,7 +1014,7 @@ class AstPop final : public AstExpr
};
// This is an artificial AST node which can be used to represent some forms
// of stack-machine code in an AST form. It similar to Block, but returns the
// of stack-machine code in an AST form. It is similar to Block, but returns the
// value of its first operand, rather than the last.
class AstFirst : public AstExpr
{

View File

@ -1501,11 +1501,17 @@ ParseExprBody(WasmParseContext& c, WasmToken token, bool inParens);
static AstExpr*
ParseExpr(WasmParseContext& c, bool inParens)
{
if (!inParens)
WasmToken openParen;
if (!inParens || !c.ts.getIf(WasmToken::OpenParen, &openParen))
return new(c.lifo) AstPop();
if (!c.ts.match(WasmToken::OpenParen, c.error))
return nullptr;
// Special case: If we have an open paren, but it's a "(then ...", then
// we don't have an expresion following us, so we pop here too. This
// handles "(if (then ...))" which pops the condition.
if (c.ts.peek().kind() == WasmToken::Then) {
c.ts.unget(openParen);
return new(c.lifo) AstPop();
}
AstExpr* expr = ParseExprInsideParens(c);
if (!expr)
@ -1619,17 +1625,12 @@ ParseBranch(WasmParseContext& c, Expr expr, bool inParens)
AstExpr* cond = nullptr;
if (expr == Expr::BrIf) {
if (inParens) {
if (c.ts.getIf(WasmToken::OpenParen)) {
cond = ParseExprInsideParens(c);
if (!cond)
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
} else {
cond = value;
value = nullptr;
}
if (inParens && c.ts.getIf(WasmToken::OpenParen)) {
cond = ParseExprInsideParens(c);
if (!cond)
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
} else {
cond = new(c.lifo) AstPop();
if (!cond)
@ -2717,13 +2718,29 @@ MaybeParseOwnerIndex(WasmParseContext& c)
return true;
}
static AstExpr*
ParseInitializerExpression(WasmParseContext& c)
{
if (!c.ts.match(WasmToken::OpenParen, c.error))
return nullptr;
AstExpr* initExpr = ParseExprInsideParens(c);
if (!initExpr)
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
return initExpr;
}
static AstDataSegment*
ParseDataSegment(WasmParseContext& c)
{
if (!MaybeParseOwnerIndex(c))
return nullptr;
AstExpr* offset = ParseExpr(c, true);
AstExpr* offset = ParseInitializerExpression(c);
if (!offset)
return nullptr;
@ -3124,7 +3141,7 @@ ParseElemSegment(WasmParseContext& c)
if (!MaybeParseOwnerIndex(c))
return nullptr;
AstExpr* offset = ParseExpr(c, true);
AstExpr* offset = ParseInitializerExpression(c);
if (!offset)
return nullptr;
@ -3186,7 +3203,7 @@ ParseGlobal(WasmParseContext& c, AstModule* module)
if (!ParseGlobalType(c, &typeToken, &isMutable))
return false;
AstExpr* init = ParseExpr(c, true);
AstExpr* init = ParseInitializerExpression(c);
if (!init)
return false;

View File

@ -1,4 +1,2 @@
// |jit-test| test-also-wasm-baseline
// TODO: arity-insensitive parsing
quit();
var importedArgs = ['nop.wast']; load(scriptdir + '../spec.js');

View File

@ -1,4 +1,2 @@
// |jit-test| test-also-wasm-baseline
// TODO: arity-insensitive parsing
quit();
var importedArgs = ['stack.wast']; load(scriptdir + '../spec.js');

View File

@ -160,14 +160,15 @@
))
"type mismatch"
)
(assert_invalid
(module (func $type-br-operand-missing-in-loop
(i32.const 0)
(loop i32 (br 0))
(i32.eqz) (drop)
))
"type mismatch"
)
;; Test incompatible with arity insensitive parsing.
;;(assert_invalid
;; (module (func $type-br-operand-missing-in-loop
;; (i32.const 0)
;; (loop i32 (br 0))
;; (i32.eqz) (drop)
;; ))
;; "type mismatch"
;;)
(assert_invalid
(module (func $type-br-operand-missing-in-if
(block