neugram / ng

scripting language integrated with Go
https://neugram.io
BSD 2-Clause "Simplified" License
917 stars 43 forks source link

ng: implement untyped-float divisions #191

Closed sbinet closed 6 years ago

sbinet commented 6 years ago

the following fails in ng:

ng> x:=4.0
ng> y:=2.0
ng> x/y
float64(2)
ng> 4.0/2.0
ng eval panic: binOp type mismatch Left: +4 (eval.UntypedFloat), Right: +2 (eval.UntypedFloat) op: /
goroutine 1 [running]:
runtime/debug.Stack(0x65, 0x0, 0x0)
    /usr/lib/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
    /usr/lib/go/src/runtime/debug/stack.go:16 +0x22
neugram.io/ng/eval.(*Program).Eval.func1(0xc4200ae480, 0xc420113610, 0xc4201135f8)
    /home/binet/work/gonum/src/neugram.io/ng/eval/eval.go:516 +0x222
panic(0xb88620, 0xc420011260)
    /usr/lib/go/src/runtime/panic.go:491 +0x283
neugram.io/ng/eval.binOp(0xb, 0xc41fc0, 0xc42016e4b0, 0xc41fc0, 0xc42016e510, 0x1, 0xc4200e81e0, 0x8e, 0x0)
    /home/binet/work/gonum/src/neugram.io/ng/eval/op.go:577 +0x6c79
neugram.io/ng/eval.(*Program).evalExpr(0xc4200ae480, 0x1151c40, 0xc42005b800, 0x0, 0x0, 0x0)
    /home/binet/work/gonum/src/neugram.io/ng/eval/eval.go:1521 +0x360d
neugram.io/ng/eval.(*Program).evalStmt(0xc4200ae480, 0x1152640, 0xc42016e570, 0x0, 0x0, 0x0)
    /home/binet/work/gonum/src/neugram.io/ng/eval/eval.go:925 +0x4655
neugram.io/ng/eval.(*Program).Eval(0xc4200ae480, 0x1152640, 0xc42016e570, 0xc4200761e0, 0x0, 0x0, 0x0, 0x114b5c0, 0xc420011270)
    /home/binet/work/gonum/src/neugram.io/ng/eval/eval.go:537 +0x38c
main.handleResult(0x1, 0xc420011250, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/binet/work/gonum/src/neugram.io/ng/ng.go:393 +0x7ff
main.loop(0xc400000000)
    /home/binet/work/gonum/src/neugram.io/ng/ng.go:385 +0x611
main.main()
    /home/binet/work/gonum/src/neugram.io/ng/ng.go:147 +0x641
ng: ng eval panic: binOp type mismatch Left: +4 (eval.UntypedFloat), Right: +2 (eval.UntypedFloat) op: /