Bug 1243626 - Baldr: tweak block text format (r=bbouvier)

This commit is contained in:
Luke Wagner 2016-01-28 09:19:22 -06:00
parent 2adafba403
commit db8de9d9e1
2 changed files with 48 additions and 56 deletions

View File

@ -476,11 +476,6 @@ class WasmTokenStream
} while (*cur_++ != '"');
return WasmToken(WasmToken::Text, begin, cur_);
case 'b':
if (consume(end_, MOZ_UTF16("lock")))
return WasmToken(WasmToken::Block, begin, cur_);
break;
case '$':
while (cur_ != end_ && IsNameAfterDollar(*cur_))
cur_++;
@ -505,6 +500,11 @@ class WasmTokenStream
return WasmToken(u32.value(), begin, cur_);
}
case 'b':
if (consume(end_, MOZ_UTF16("lock")))
return WasmToken(WasmToken::Block, begin, cur_);
break;
case 'e':
if (consume(end_, MOZ_UTF16("xport")))
return WasmToken(WasmToken::Export, begin, cur_);
@ -661,7 +661,39 @@ struct WasmParseContext
};
static WasmAstExpr*
ParseExpr(WasmParseContext& c);
ParseExprInsideParens(WasmParseContext& c);
static WasmAstExpr*
ParseExpr(WasmParseContext& c)
{
if (!c.ts.match(WasmToken::OpenParen, c.error))
return nullptr;
WasmAstExpr* expr = ParseExprInsideParens(c);
if (!expr)
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
return expr;
}
static WasmAstBlock*
ParseBlock(WasmParseContext& c)
{
WasmAstExprVector exprs(c.lifo);
while (c.ts.getIf(WasmToken::OpenParen)) {
WasmAstExpr* expr = ParseExprInsideParens(c);
if (!expr || !exprs.append(expr))
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
}
return new(c.lifo) WasmAstBlock(Move(exprs));
}
static WasmAstConst*
ParseConst(WasmParseContext& c, WasmToken constToken)
@ -703,27 +735,6 @@ ParseSetLocal(WasmParseContext& c)
return new(c.lifo) WasmAstSetLocal(localIndex.integer(), *value);
}
static WasmAstBlock*
ParseBlock(WasmParseContext& c)
{
WasmToken numExprs;
if (!c.ts.match(WasmToken::Integer, &numExprs, c.error))
return nullptr;
WasmAstExprVector exprs(c.lifo);
if (!exprs.reserve(numExprs.integer()))
return nullptr;
for (uint32_t i = 0; i < numExprs.integer(); i++) {
WasmAstExpr* value = ParseExpr(c);
if (!value)
return nullptr;
exprs.infallibleAppend(value);
}
return new(c.lifo) WasmAstBlock(Move(exprs));
}
static WasmAstExpr*
ParseExprInsideParens(WasmParseContext& c)
{
@ -746,22 +757,6 @@ ParseExprInsideParens(WasmParseContext& c)
}
}
static WasmAstExpr*
ParseExpr(WasmParseContext& c)
{
if (!c.ts.match(WasmToken::OpenParen, c.error))
return nullptr;
WasmAstExpr* expr = ParseExprInsideParens(c);
if (!expr)
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
return expr;
}
static WasmAstFunc*
ParseFunc(WasmParseContext& c, WasmAstModule* module)
{

View File

@ -130,20 +130,17 @@ assertErrorMessage(() => wasmEvalText('(module (func (local i64)))'), Error, /NY
// ----------------------------------------------------------------------------
// blocks
assertThrowsInstanceOf(() => wasmEvalText('(module (block))'), Error);
assertThrowsInstanceOf(() => wasmEvalText('(module (block -1 (i32.const 42)))'), Error);
assertEq(wasmEvalText('(module (func (block 0)) (export "" 0))')(), undefined);
assertEq(wasmEvalText('(module (func (block)) (export "" 0))')(), undefined);
assertErrorMessage(() => wasmEvalText('(module (func (result i32) (block 0)))'), Error, mismatchError("void", "i32"));
assertErrorMessage(() => wasmEvalText('(module (func (result i32) (block 1 (block 0))))'), Error, mismatchError("void", "i32"));
assertErrorMessage(() => wasmEvalText('(module (func (local i32) (set_local 0 (block 0))))'), Error, mismatchError("void", "i32"));
assertErrorMessage(() => wasmEvalText('(module (func (result i32) (block)))'), Error, mismatchError("void", "i32"));
assertErrorMessage(() => wasmEvalText('(module (func (result i32) (block (block))))'), Error, mismatchError("void", "i32"));
assertErrorMessage(() => wasmEvalText('(module (func (local i32) (set_local 0 (block))))'), Error, mismatchError("void", "i32"));
assertThrowsInstanceOf(() => wasmEvalText('(module (block 1))'), Error);
assertEq(wasmEvalText('(module (func (block 1 (block 0))) (export "" 0))')(), undefined);
assertEq(wasmEvalText('(module (func (result i32) (block 1 (i32.const 42))) (export "" 0))')(), 42);
assertEq(wasmEvalText('(module (func (result i32) (block 1 (block 1 (i32.const 42)))) (export "" 0))')(), 42);
assertErrorMessage(() => wasmEvalText('(module (func (result f32) (block 1 (i32.const 0))))'), Error, mismatchError("i32", "f32"));
assertEq(wasmEvalText('(module (func (block (block))) (export "" 0))')(), undefined);
assertEq(wasmEvalText('(module (func (result i32) (block (i32.const 42))) (export "" 0))')(), 42);
assertEq(wasmEvalText('(module (func (result i32) (block (block (i32.const 42)))) (export "" 0))')(), 42);
assertErrorMessage(() => wasmEvalText('(module (func (result f32) (block (i32.const 0))))'), Error, mismatchError("i32", "f32"));
assertEq(wasmEvalText('(module (func (result i32) (block 2 (i32.const 13) (block 1 (i32.const 42)))) (export "" 0))')(), 42);
assertErrorMessage(() => wasmEvalText('(module (func (result f32) (param f32) (block 2 (get_local 0) (i32.const 0))))'), Error, mismatchError("i32", "f32"));
assertEq(wasmEvalText('(module (func (result i32) (block (i32.const 13) (block (i32.const 42)))) (export "" 0))')(), 42);
assertErrorMessage(() => wasmEvalText('(module (func (result f32) (param f32) (block (get_local 0) (i32.const 0))))'), Error, mismatchError("i32", "f32"));