(node ast.Node)
| 429 | } |
| 430 | |
| 431 | func (c *codegen) VisitAfter(node ast.Node) ast.Node { |
| 432 | switch n := node.(type) { |
| 433 | case *ast.BuiltinExpr: |
| 434 | arglen := 0 |
| 435 | if n.Args != nil { |
| 436 | arglen = len(n.Args.(*ast.ExprList).Children) |
| 437 | } |
| 438 | switch n.Name { |
| 439 | case "bool": |
| 440 | // TODO(jaq): Nothing, no support in VM yet. |
| 441 | |
| 442 | case "int", "float", "string": |
| 443 | // len args should be 1 |
| 444 | if arglen > 1 { |
| 445 | c.errorf(n.Pos(), "too many arguments to builtin %q: %#v", n.Name, n) |
| 446 | return n |
| 447 | } |
| 448 | if err := c.emitConversion(n, n.Args.(*ast.ExprList).Children[0].Type(), n.Type()); err != nil { |
| 449 | c.errorf(n.Pos(), "%s on node %v", err.Error(), n) |
| 450 | return n |
| 451 | } |
| 452 | case "subst": |
| 453 | if types.Equals(n.Args.(*ast.ExprList).Children[0].Type(), types.Pattern) { |
| 454 | index := n.Args.(*ast.ExprList).Children[0].(*ast.PatternExpr).Index |
| 455 | c.emit(n, code.Push, index) |
| 456 | c.emit(n, code.Rsubst, arglen) |
| 457 | } else { |
| 458 | c.emit(n, code.Subst, arglen) |
| 459 | } |
| 460 | |
| 461 | default: |
| 462 | c.emit(n, builtin[n.Name], arglen) |
| 463 | } |
| 464 | case *ast.UnaryExpr: |
| 465 | switch n.Op { |
| 466 | case parser.INC: |
| 467 | c.emit(n, code.Inc, nil) |
| 468 | case parser.DEC: |
| 469 | c.emit(n, code.Dec, nil) |
| 470 | case parser.NOT: |
| 471 | c.emit(n, code.Neg, nil) |
| 472 | case parser.MATCH: |
| 473 | index := n.Expr.(*ast.PatternExpr).Index |
| 474 | c.emit(n, code.Match, index) |
| 475 | } |
| 476 | case *ast.BinaryExpr: |
| 477 | switch n.Op { |
| 478 | case parser.LT, parser.GT, parser.LE, parser.GE, parser.EQ, parser.NE: |
| 479 | lFail := c.newLabel() |
| 480 | lEnd := c.newLabel() |
| 481 | var cmpArg int |
| 482 | var jumpOp code.Opcode |
| 483 | switch n.Op { |
| 484 | case parser.LT: |
| 485 | cmpArg = -1 |
| 486 | jumpOp = code.Jnm |
| 487 | case parser.GT: |
| 488 | cmpArg = 1 |
nothing calls this directly
no test coverage detected