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 { pub fn (expr Expr) is_lit() bool {
return match expr { return match expr {
BoolLiteral, StringLiteral, IntegerLiteral { true } BoolLiteral, CharLiteral, StringLiteral, IntegerLiteral { true }
else { false } else { false }
} }
} }

View File

@ -1558,9 +1558,11 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
return '', pos return '', pos
} }
else { else {
if !expr.is_lit() {
c.error('unexpected expression `$expr.type_name()`', expr.position()) c.error('unexpected expression `$expr.type_name()`', expr.position())
} }
} }
}
if explicit_lock_needed { if explicit_lock_needed {
c.error('`$to_lock` is `shared` and needs explicit lock for `$expr.type_name()`', c.error('`$to_lock` is `shared` and needs explicit lock for `$expr.type_name()`',
pos) pos)

View File

@ -1411,7 +1411,7 @@ fn (mut p Parser) asm_ios(output bool) []ast.AsmIO {
if mut expr is ast.ParExpr { if mut expr is ast.ParExpr {
expr = expr.expr expr = expr.expr
} else { } 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 := '' mut alias := ''
if p.tok.kind == .key_as { 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 { pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_ident bool) ast.Expr {
mut node := left mut node := left
if p.inside_asm && p.prev_tok.position().line_nr < p.tok.position().line_nr {
return node
}
// Infix // Infix
for precedence < p.tok.precedence() { for precedence < p.tok.precedence() {
if p.tok.kind == .dot { if p.tok.kind == .dot {

View File

@ -169,4 +169,17 @@ fn test_flag_output() {
; r (zero) ; r (zero)
} }
assert out 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) ; r (zero)
} }
assert out 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
} }