Keno / ASTInterpreter.jl

Gallium's AST interpreter as a separate package to simplify development
Other
16 stars 10 forks source link

use normal expression printer when we don't have source code #19

Open JeffBezanson opened 8 years ago

JeffBezanson commented 8 years ago

The terminal graphic tree display is really cool but it's too verbose for most purposes. We should just show the expressions the way julia usually does. Example:

julia> f() = [i+1 for i = 1:2]
f (generic function with 1 method)

julia> @enter f()
Body
├─ none: 1
├─ :(GenSym(0) = (Main.colon)(1,2))
│  ├─ GenSym(0)
│  └─ Call
│     ├─ Main.colon
│     ├─ 1
│     └─ 2
├─ :(GenSym(1) = (top(length))(GenSym(0)))
│  ├─ GenSym(1)
│  └─ Call
│     ├─ top(length)
│     └─ GenSym(0)
├─ 0: 
├─ :(GenSym(2) = (top(Array))($(Expr(:static_typeof, GenSym(3))),GenSym(1)))
│  ├─ GenSym(2)
│  └─ Call
│     ├─ top(Array)
│     ├─ :($(Expr(:static_typeof, GenSym(3))))
│     │  └─ GenSym(3)
│     └─ GenSym(1)
├─ :(#s54 = 1)
│  ├─ #s54
│  └─ 1
├─ :(#s53 = (top(start))(GenSym(0)))
│  ├─ #s53
│  └─ Call
│     ├─ top(start)
│     └─ GenSym(0)
├─ :(#s52 = (top(typeassert))((top(convert))((top(typeof))(GenSym(1)),0),(top(typeof))(GenSym(1))))
│  ├─ #s52
│  └─ Call
│     ├─ top(typeassert)
│     ├─ Call
│     │  ├─ top(convert)
│     │  ├─ Call
│     │  │  ├─ top(typeof)
│     │  │  └─ GenSym(1)
│     │  └─ 0
│     └─ Call
│        ├─ top(typeof)
│        └─ GenSym(1)
├─ 3: 
├─ :(unless (top(!=))(#s52,GenSym(1)) goto 2)
│  ├─ Call
│  │  ├─ top(!=)
│  │  ├─ #s52
│  │  └─ GenSym(1)
│  └─ 2
├─ :(GenSym(4) = (top(+))(#s52,1))
│  ├─ GenSym(4)
│  └─ Call
│     ├─ top(+)
│     ├─ #s52
│     └─ 1
├─ :(#s52 = (top(typeassert))((top(convert))((top(typeof))(GenSym(1)),GenSym(4)),(top(typeof))(GenSym(1))))
│  ├─ #s52
│  └─ Call
│     ├─ top(typeassert)
│     ├─ Call
│     │  ├─ top(convert)
│     │  ├─ Call
│     │  │  ├─ top(typeof)
│     │  │  └─ GenSym(1)
│     │  └─ GenSym(4)
│     └─ Call
│        ├─ top(typeof)
│        └─ GenSym(1)
├─ :(GenSym(5) = (top(next))(GenSym(0),#s53))
│  ├─ GenSym(5)
│  └─ Call
│     ├─ top(next)
│     ├─ GenSym(0)
│     └─ #s53
├─ :(#s51 = (top(start))(GenSym(5)))
│  ├─ #s51
│  └─ Call
│     ├─ top(start)
│     └─ GenSym(5)
├─ :(GenSym(6) = (top(indexed_next))(GenSym(5),1,#s51))
│  ├─ GenSym(6)
│  └─ Call
│     ├─ top(indexed_next)
│     ├─ GenSym(5)
│     ├─ 1
│     └─ #s51
├─ :(i = (top(getfield))(GenSym(6),1))
│  ├─ i
│  └─ Call
│     ├─ top(getfield)
│     ├─ GenSym(6)
│     └─ 1
├─ :(#s51 = (top(getfield))(GenSym(6),2))
│  ├─ #s51
│  └─ Call
│     ├─ top(getfield)
│     ├─ GenSym(6)
│     └─ 2
├─ :(GenSym(7) = (top(indexed_next))(GenSym(5),2,#s51))
│  ├─ GenSym(7)
│  └─ Call
│     ├─ top(indexed_next)
│     ├─ GenSym(5)
│     ├─ 2
│     └─ #s51
├─ :(#s53 = (top(getfield))(GenSym(7),1))
│  ├─ #s53
│  └─ Call
│     ├─ top(getfield)
│     ├─ GenSym(7)
│     └─ 1
├─ :(#s51 = (top(getfield))(GenSym(7),2))
│  ├─ #s51
│  └─ Call
│     ├─ top(getfield)
│     ├─ GenSym(7)
│     └─ 2
├─ :(GenSym(3) = i + 1)
│  ├─ GenSym(3)
│  └─ Call
│     ├─ Main.+
│     ├─ i
│     └─ 1
├─ :($(Expr(:type_goto, 0, GenSym(3))))
│  ├─ 0
│  └─ GenSym(3)
├─ :($(Expr(:inbounds, true)))
│  └─ true
├─ Call
│  ├─ top(setindex!)
│  ├─ GenSym(2)
│  ├─ GenSym(3)
│  └─ #s54
├─ :($(Expr(:inbounds, :(Main.pop))))
│  └─ Main.pop
├─ :(#s54 = (top(+))(#s54,1))
│  ├─ #s54
│  └─ Call
│     ├─ top(+)
│     ├─ #s54
│     └─ 1
├─ 4: 
├─ goto 3
├─ 2: 
├─ 1: 
└─ Return
   └─ GenSym(2)
Keno commented 8 years ago

Yes, I agree ;)

JeffBezanson commented 8 years ago

Alternative idea: don't vertically expand nodes that are "simple" according to some heuristic. For example x = 1, or calls whose child nodes are leaf nodes like symbols and numbers.