parser: fix prefix precedence
parent
c00ec77737
commit
eb78396307
|
@ -29,6 +29,8 @@ fn test_float_equal_operator() {
|
|||
assert a.gtbit(1)
|
||||
assert a >= 1
|
||||
assert a.gebit(1)
|
||||
assert -1 == 1 * -1
|
||||
assert -1.0 == 1.0 * -1.0
|
||||
|
||||
a = f64(1)
|
||||
a += 0.000001
|
||||
|
|
|
@ -848,7 +848,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
|||
type_sym := c.table.get_type_symbol(it.typ)
|
||||
if expr_type_sym.kind == .sum_type {
|
||||
info := expr_type_sym.info as table.SumType
|
||||
if !it.typ in info.variants {
|
||||
if !(it.typ in info.variants) {
|
||||
c.error('cannot cast `$expr_type_sym.name` to `$type_sym.name`', it.pos)
|
||||
// c.error('only $info.variants can be casted to `$typ`', it.pos)
|
||||
}
|
||||
|
|
|
@ -840,9 +840,9 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
|
|||
g.writeln('free(_const_os__args.data); // empty, inited in _vinit()')
|
||||
}
|
||||
if g.pref.os == .windows {
|
||||
g.writeln('_const_os__args = os__init_os_args_wide(___argc, ___argv);')
|
||||
g.writeln('\t_const_os__args = os__init_os_args_wide(___argc, ___argv);')
|
||||
} else {
|
||||
g.writeln('_const_os__args = os__init_os_args(___argc, (byteptr*)___argv);')
|
||||
g.writeln('\t_const_os__args = os__init_os_args(___argc, (byteptr*)___argv);')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1123,7 +1123,9 @@ fn (g mut Gen) expr(node ast.Expr) {
|
|||
}
|
||||
// g.write('/*pref*/')
|
||||
g.write(it.op.str())
|
||||
//g.write('(')
|
||||
g.expr(it.right)
|
||||
//g.write(')')
|
||||
g.is_amp = false
|
||||
}
|
||||
ast.SizeOf {
|
||||
|
@ -1390,7 +1392,8 @@ fn (g mut Gen) infix_expr(node ast.InfixExpr) {
|
|||
g.expr(node.right)
|
||||
g.write('), $tmp, $elem_type_str)')
|
||||
}
|
||||
} else if (node.left_type == node.right_type ) && node.left_type in [ table.f32_type_idx, table.f64_type_idx ] && node.op in [ .eq, .ne ] {
|
||||
} else if (node.left_type == node.right_type) && node.left_type in [table.f32_type_idx,
|
||||
table.f64_type_idx] && node.op in [.eq, .ne] {
|
||||
// floats should be compared with epsilon
|
||||
if node.left_type == table.f64_type_idx {
|
||||
if node.op == .eq {
|
||||
|
@ -1398,7 +1401,7 @@ fn (g mut Gen) infix_expr(node ast.InfixExpr) {
|
|||
} else {
|
||||
g.write('f64_ne(')
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
if node.op == .eq {
|
||||
g.write('f32_eq(')
|
||||
} else {
|
||||
|
|
|
@ -863,7 +863,7 @@ fn (p mut Parser) prefix_expr() ast.PrefixExpr {
|
|||
p.is_amp = true
|
||||
}
|
||||
p.next()
|
||||
right := p.expr(1)
|
||||
right := p.expr(token.Precedence.prefix)
|
||||
p.is_amp = false
|
||||
return ast.PrefixExpr{
|
||||
op: op
|
||||
|
|
|
@ -303,7 +303,7 @@ pub enum Precedence {
|
|||
product // * or /
|
||||
// mod // %
|
||||
prefix // -X or !X
|
||||
postfix
|
||||
postfix // ++ or --
|
||||
call // func(X) or foo.method(X)
|
||||
index // array[index], map[key]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue