parser: fix multiple output modifiers in asm (#10347)

pull/10354/head
crthpl 2021-06-04 13:18:11 -07:00 committed by GitHub
parent 751b1cffd3
commit 9553c5a4e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 3 deletions

View File

@ -1577,7 +1577,7 @@ pub fn (expr Expr) is_expr() bool {
pub fn (expr Expr) is_lit() bool {
return match expr {
BoolLiteral, StringLiteral, IntegerLiteral { true }
BoolLiteral, CharLiteral, StringLiteral, IntegerLiteral { true }
else { false }
}
}

View File

@ -1558,7 +1558,9 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
return '', pos
}
else {
c.error('unexpected expression `$expr.type_name()`', expr.position())
if !expr.is_lit() {
c.error('unexpected expression `$expr.type_name()`', expr.position())
}
}
}
if explicit_lock_needed {

View File

@ -1411,7 +1411,7 @@ fn (mut p Parser) asm_ios(output bool) []ast.AsmIO {
if mut expr is ast.ParExpr {
expr = expr.expr
} else {
p.error('asm in/output must be incolsed in brackets $expr.type_name()')
p.error('asm in/output must be incolsed in brackets')
}
mut alias := ''
if p.tok.kind == .key_as {

View File

@ -352,6 +352,9 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_ident bool) ast.Expr {
mut node := left
if p.inside_asm && p.prev_tok.position().line_nr < p.tok.position().line_nr {
return node
}
// Infix
for precedence < p.tok.precedence() {
if p.tok.kind == .dot {

View File

@ -169,4 +169,17 @@ fn test_flag_output() {
; r (zero)
}
assert out
mut maybe_four := 4
mut four := 4
asm amd64 {
subl four, maybe_four
testl four, maybe_four
movl maybe_four, 9
; +m (maybe_four)
+r (four)
=@ccz (out)
}
assert out
assert maybe_four == 9
}

View File

@ -151,4 +151,17 @@ fn test_flag_output() {
; r (zero)
}
assert out
mut maybe_four := 4
mut four := 4
asm amd64 {
subl four, maybe_four
testl four, maybe_four
movl maybe_four, 9
; +m (maybe_four)
+r (four)
=@ccz (out)
}
assert out
assert maybe_four == 9
}