Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6486909921 | ||
|
|
d252821df3 | ||
|
|
2bef03e253 | ||
|
|
1fe91be882 | ||
|
|
5cbbf9339c | ||
|
|
8365f687e7 | ||
|
|
36836cd4f2 | ||
|
|
82b499a1c8 | ||
|
|
0ef7f8fb80 | ||
|
|
c1f5005b2a | ||
|
|
def57d57c2 | ||
|
|
74479d70e6 | ||
|
|
f1cff308e6 | ||
|
|
6f878052f8 | ||
|
|
eb25c84797 | ||
|
|
2de0c80d38 | ||
|
|
151a856bf2 | ||
|
|
d5217f7db4 | ||
|
|
01e4cdea70 | ||
|
|
3c88542180 | ||
|
|
56d88ef89d | ||
|
|
5d78c8ae27 | ||
|
|
184623d81f | ||
|
|
5d56bac8d0 | ||
|
|
4a068ea452 | ||
|
|
8605c238ef | ||
|
|
4f39eaf893 | ||
|
|
4f8e1de267 | ||
|
|
6f4643ff19 | ||
|
|
bb1be9e6e1 |
@@ -26,6 +26,7 @@ matrix:
|
||||
env:
|
||||
global:
|
||||
- GO111MODULE=on
|
||||
- CI=1
|
||||
|
||||
go_import_path: github.com/containous/yaegi
|
||||
|
||||
@@ -39,7 +40,7 @@ install:
|
||||
- go mod download
|
||||
|
||||
before_script:
|
||||
- rm -f interp/op.go interp/interp_test.go
|
||||
- rm -f interp/op.go
|
||||
- make generate
|
||||
- git update-index -q --refresh
|
||||
- CHANGED=$(git diff-index --name-only HEAD --)
|
||||
|
||||
3
_test/baz-bat/baz-bat.go
Normal file
3
_test/baz-bat/baz-bat.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package baz
|
||||
|
||||
var Name = "baz-bat"
|
||||
14
_test/composite10.go
Normal file
14
_test/composite10.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
a := []map[int]int{make(map[int]int)}
|
||||
|
||||
for _, b := range a {
|
||||
fmt.Println(b)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// map[]
|
||||
14
_test/composite9.go
Normal file
14
_test/composite9.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
a := [][]int{make([]int,0)}
|
||||
|
||||
for _, b := range a {
|
||||
fmt.Println(b)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// []
|
||||
17
_test/const12.go
Normal file
17
_test/const12.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
type Kind int
|
||||
|
||||
const (
|
||||
None Kind = 0
|
||||
Left Kind = 1 << iota
|
||||
Right
|
||||
Both Kind = Left | Right
|
||||
)
|
||||
|
||||
func main() {
|
||||
println(None, Left, Right, Both)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 0 2 4 6
|
||||
16
_test/const13.go
Normal file
16
_test/const13.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const tooBig = 1267650600228229401496703205376
|
||||
const huge = 1 << 100
|
||||
const large = huge >> 38
|
||||
|
||||
fmt.Println(large)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 4611686018427387904
|
||||
12
_test/fun21.go
Normal file
12
_test/fun21.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
func Bar() string {
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
println(Bar())
|
||||
}
|
||||
|
||||
// Error:
|
||||
// 4:2: not enough arguments to return
|
||||
10
_test/fun22.go
Normal file
10
_test/fun22.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
func main() {
|
||||
time.Date()
|
||||
}
|
||||
|
||||
// Error:
|
||||
// 6:2: not enough arguments in call to time.Date
|
||||
10
_test/import9.go
Normal file
10
_test/import9.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import "github.com/containous/yaegi/_test/baz-bat"
|
||||
|
||||
func main() {
|
||||
println(baz.Name)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// baz-bat
|
||||
19
_test/interface38.go
Normal file
19
_test/interface38.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type foo struct {
|
||||
bar string
|
||||
}
|
||||
|
||||
func (f foo) String() string {
|
||||
return "Hello from " + f.bar
|
||||
}
|
||||
|
||||
func main() {
|
||||
var f fmt.Stringer = foo{bar: "bar"}
|
||||
fmt.Println(f)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Hello from bar
|
||||
19
_test/interface39.go
Normal file
19
_test/interface39.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type foo struct {
|
||||
bar string
|
||||
}
|
||||
|
||||
func (f *foo) String() string {
|
||||
return "Hello from " + f.bar
|
||||
}
|
||||
|
||||
func main() {
|
||||
var f fmt.Stringer = &foo{bar: "bar"}
|
||||
fmt.Println(f)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Hello from bar
|
||||
23
_test/interface40.go
Normal file
23
_test/interface40.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type foo struct {
|
||||
bar string
|
||||
}
|
||||
|
||||
func (f foo) String() string {
|
||||
return "Hello from " + f.bar
|
||||
}
|
||||
|
||||
func Foo(s string) fmt.Stringer {
|
||||
return foo{s}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := Foo("bar")
|
||||
fmt.Println(f)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Hello from bar
|
||||
23
_test/interface41.go
Normal file
23
_test/interface41.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type foo struct {
|
||||
bar string
|
||||
}
|
||||
|
||||
func (f *foo) String() string {
|
||||
return "Hello from " + f.bar
|
||||
}
|
||||
|
||||
func Foo(s string) fmt.Stringer {
|
||||
return &foo{s}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := Foo("bar")
|
||||
fmt.Println(f)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Hello from bar
|
||||
12
_test/interface42.go
Normal file
12
_test/interface42.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
v := interface{}(0)
|
||||
|
||||
fmt.Println(v)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 0
|
||||
12
_test/interface43.go
Normal file
12
_test/interface43.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
v := interface{}(nil)
|
||||
|
||||
fmt.Println(v)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// <nil>
|
||||
21
_test/map28.go
Normal file
21
_test/map28.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func main() {
|
||||
value1 := url.Values{}
|
||||
|
||||
value1.Set("first", "v1")
|
||||
value1.Set("second", "v2")
|
||||
|
||||
l := 0
|
||||
for k, v := range value1 {
|
||||
l += len(k) + len(v)
|
||||
}
|
||||
println(l)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 13
|
||||
26
_test/map29.go
Normal file
26
_test/map29.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
Object interface{}
|
||||
Expiry time.Duration
|
||||
}
|
||||
|
||||
func main() {
|
||||
items := map[string]Item{}
|
||||
|
||||
items["test"] = Item{
|
||||
Object: "test",
|
||||
Expiry: time.Second,
|
||||
}
|
||||
|
||||
item := items["test"]
|
||||
fmt.Println(item)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// {test 1s}
|
||||
18
_test/method32.go
Normal file
18
_test/method32.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var a = []func(string){bar}
|
||||
b := a[0]
|
||||
b("bar")
|
||||
}
|
||||
|
||||
func bar(a string) {
|
||||
fmt.Println(a)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// bar
|
||||
58
_test/method33.go
Normal file
58
_test/method33.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type T1 struct{}
|
||||
|
||||
func (t1 T1) f() {
|
||||
fmt.Println("T1.f()")
|
||||
}
|
||||
|
||||
func (t1 T1) g() {
|
||||
fmt.Println("T1.g()")
|
||||
}
|
||||
|
||||
type T2 struct {
|
||||
T1
|
||||
}
|
||||
|
||||
func (t2 T2) f() {
|
||||
fmt.Println("T2.f()")
|
||||
}
|
||||
|
||||
type I interface {
|
||||
f()
|
||||
}
|
||||
|
||||
func printType(i I) {
|
||||
if t1, ok := i.(T1); ok {
|
||||
println("T1 ok")
|
||||
t1.f()
|
||||
t1.g()
|
||||
}
|
||||
|
||||
if t2, ok := i.(T2); ok {
|
||||
println("T2 ok")
|
||||
t2.f()
|
||||
t2.g()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
println("T1")
|
||||
printType(T1{})
|
||||
println("T2")
|
||||
printType(T2{})
|
||||
}
|
||||
|
||||
// Output:
|
||||
// T1
|
||||
// T1 ok
|
||||
// T1.f()
|
||||
// T1.g()
|
||||
// T2
|
||||
// T2 ok
|
||||
// T2.f()
|
||||
// T1.g()
|
||||
23
_test/method34.go
Normal file
23
_test/method34.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
type Root struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type One struct {
|
||||
Root
|
||||
}
|
||||
|
||||
type Hi interface {
|
||||
Hello() string
|
||||
}
|
||||
|
||||
func (r *Root) Hello() string { return "Hello " + r.Name }
|
||||
|
||||
func main() {
|
||||
var one interface{} = &One{Root{Name: "test2"}}
|
||||
println(one.(Hi).Hello())
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Hello test2
|
||||
21
_test/range7.go
Normal file
21
_test/range7.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func someChan() <-chan struct{} {
|
||||
c := make(chan struct{}, 1)
|
||||
c <- struct{}{}
|
||||
return c
|
||||
}
|
||||
|
||||
func main() {
|
||||
for _ = range someChan() {
|
||||
fmt.Println("success")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// success
|
||||
16
_test/range8.go
Normal file
16
_test/range8.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for _ = range time.Tick(time.Millisecond) {
|
||||
fmt.Println("success")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// success
|
||||
15
_test/recover2.go
Normal file
15
_test/recover2.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
println("hello")
|
||||
|
||||
var r interface{} = 1
|
||||
r = recover()
|
||||
if r == nil {
|
||||
println("world")
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// hello
|
||||
// world
|
||||
22
_test/recover3.go
Normal file
22
_test/recover3.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
println("hello")
|
||||
|
||||
var r interface{} = 1
|
||||
r = recover()
|
||||
fmt.Printf("%v\n", r)
|
||||
if r == nil {
|
||||
println("world")
|
||||
}
|
||||
if r != nil {
|
||||
println("exception")
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// hello
|
||||
// <nil>
|
||||
// world
|
||||
25
_test/recover4.go
Normal file
25
_test/recover4.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func div(a, b int) (result int) {
|
||||
defer func() {
|
||||
r := recover()
|
||||
|
||||
fmt.Printf("r = %#v\n", r)
|
||||
|
||||
if r != nil {
|
||||
result = 0
|
||||
}
|
||||
}()
|
||||
|
||||
return a / b
|
||||
}
|
||||
|
||||
func main() {
|
||||
println(div(30, 2))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// r = <nil>
|
||||
// 15
|
||||
15
_test/redeclaration0.go
Normal file
15
_test/redeclaration0.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
type foo struct {
|
||||
yolo string
|
||||
}
|
||||
|
||||
var foo int
|
||||
foo = 2
|
||||
println(foo)
|
||||
}
|
||||
|
||||
// Error:
|
||||
// ../_test/redeclaration0.go:8:6: foo redeclared in this block
|
||||
// previous declaration at ../_test/redeclaration0.go:4:7
|
||||
12
_test/redeclaration1.go
Normal file
12
_test/redeclaration1.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var foo string
|
||||
|
||||
var foo int
|
||||
foo = 2
|
||||
println(foo)
|
||||
}
|
||||
|
||||
// Error:
|
||||
// ../_test/redeclaration1.go:6:6: foo redeclared in this block
|
||||
15
_test/redeclaration2.go
Normal file
15
_test/redeclaration2.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var foo struct {
|
||||
yolo string
|
||||
}
|
||||
|
||||
var foo int
|
||||
foo = 2
|
||||
println(foo)
|
||||
}
|
||||
|
||||
// Error:
|
||||
// ../_test/redeclaration2.go:8:6: foo redeclared in this block
|
||||
// previous declaration at ../_test/redeclaration2.go:4:6
|
||||
13
_test/redeclaration3.go
Normal file
13
_test/redeclaration3.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var foo int
|
||||
foo = 2
|
||||
|
||||
type foo struct{}
|
||||
var bar foo
|
||||
println(bar)
|
||||
}
|
||||
|
||||
// Error:
|
||||
// ../_test/redeclaration3.go:7:7: foo redeclared in this block
|
||||
14
_test/redeclaration4.go
Normal file
14
_test/redeclaration4.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var foo struct{
|
||||
yolo string
|
||||
}
|
||||
|
||||
type foo struct{}
|
||||
var bar foo
|
||||
println(bar)
|
||||
}
|
||||
|
||||
// Error:
|
||||
// ../_test/redeclaration4.go:8:7: foo redeclared in this block
|
||||
14
_test/redeclaration5.go
Normal file
14
_test/redeclaration5.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
type foo struct{
|
||||
yolo string
|
||||
}
|
||||
|
||||
type foo struct{}
|
||||
var bar foo
|
||||
println(bar)
|
||||
}
|
||||
|
||||
// Error:
|
||||
// ../_test/redeclaration5.go:8:7: foo redeclared in this block
|
||||
23
_test/select12.go
Normal file
23
_test/select12.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
type S struct {
|
||||
q chan struct{}
|
||||
}
|
||||
|
||||
func (s *S) Send() {
|
||||
select {
|
||||
case s.q <- struct{}{}:
|
||||
println("sent")
|
||||
default:
|
||||
println("unexpected")
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
s := &S{q: make(chan struct{}, 1)}
|
||||
s.Send()
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// sent
|
||||
// bye
|
||||
16
_test/select13.go
Normal file
16
_test/select13.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var c interface{} = int64(1)
|
||||
q := make(chan struct{})
|
||||
select {
|
||||
case q <- struct{}{}:
|
||||
println("unexpected")
|
||||
default:
|
||||
_ = c.(int64)
|
||||
}
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// bye
|
||||
21
_test/struct46.go
Normal file
21
_test/struct46.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type A struct {
|
||||
B string
|
||||
C D
|
||||
}
|
||||
|
||||
type D struct {
|
||||
E *A
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := &A{B: "b"}
|
||||
a.C = D{E: a}
|
||||
fmt.Println(a.C.E.B)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// b
|
||||
26
_test/struct47.go
Normal file
26
_test/struct47.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type A struct {
|
||||
B string
|
||||
C D
|
||||
}
|
||||
|
||||
func (a *A) Test() string {
|
||||
return "test"
|
||||
}
|
||||
|
||||
type D struct {
|
||||
E *A
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := &A{B: "b"}
|
||||
d := D{E: a}
|
||||
a.C = d
|
||||
fmt.Println(a.C.E.Test())
|
||||
}
|
||||
|
||||
// Output:
|
||||
// test
|
||||
37
_test/struct48.go
Normal file
37
_test/struct48.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
type List struct {
|
||||
Next *List
|
||||
Num int
|
||||
}
|
||||
|
||||
func add(l *List, n int) *List {
|
||||
if l == nil {
|
||||
return &List{Num: n}
|
||||
}
|
||||
l.Next = add(l.Next, n)
|
||||
return l
|
||||
}
|
||||
|
||||
func pr(l *List) {
|
||||
if l == nil {
|
||||
println("")
|
||||
return
|
||||
}
|
||||
print(l.Num)
|
||||
pr(l.Next)
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := add(nil, 0)
|
||||
pr(a)
|
||||
a = add(a, 1)
|
||||
pr(a)
|
||||
a = add(a, 2)
|
||||
pr(a)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 0
|
||||
// 01
|
||||
// 012
|
||||
17
_test/switch35.go
Normal file
17
_test/switch35.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a := 2
|
||||
switch {
|
||||
case a == 1:
|
||||
println(1)
|
||||
case a == 2:
|
||||
println(2)
|
||||
default:
|
||||
}
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 2
|
||||
// bye
|
||||
14
_test/switch36.go
Normal file
14
_test/switch36.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a := 2
|
||||
switch {
|
||||
case a == 1:
|
||||
println(1)
|
||||
case a == 2:
|
||||
}
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// bye
|
||||
15
_test/switch37.go
Normal file
15
_test/switch37.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a := 2
|
||||
switch {
|
||||
case a == 1:
|
||||
println(1)
|
||||
case a == 3:
|
||||
default:
|
||||
}
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// bye
|
||||
38
_test/type23.go
Normal file
38
_test/type23.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var v1 interface{} = 1
|
||||
var v2 interface{}
|
||||
var v3 http.ResponseWriter = httptest.NewRecorder()
|
||||
|
||||
if r1, ok := v1.(string); ok {
|
||||
_ = r1
|
||||
println("unexpected")
|
||||
}
|
||||
if _, ok := v1.(string); ok {
|
||||
println("unexpected")
|
||||
}
|
||||
if r2, ok := v2.(string); ok {
|
||||
_ = r2
|
||||
println("unexpected")
|
||||
}
|
||||
if _, ok := v2.(string); ok {
|
||||
println("unexpected")
|
||||
}
|
||||
if r3, ok := v3.(http.Pusher); ok {
|
||||
_ = r3
|
||||
println("unexpected")
|
||||
}
|
||||
if _, ok := v3.(http.Pusher); ok {
|
||||
println("unexpected")
|
||||
}
|
||||
println("bye")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// bye
|
||||
48
_test/type24.go
Normal file
48
_test/type24.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
assertInt()
|
||||
assertNil()
|
||||
assertValue()
|
||||
}
|
||||
|
||||
func assertInt() {
|
||||
defer func() {
|
||||
r := recover()
|
||||
fmt.Println(r)
|
||||
}()
|
||||
|
||||
var v interface{} = 1
|
||||
println(v.(string))
|
||||
}
|
||||
|
||||
func assertNil() {
|
||||
defer func() {
|
||||
r := recover()
|
||||
fmt.Println(r)
|
||||
}()
|
||||
|
||||
var v interface{}
|
||||
println(v.(string))
|
||||
}
|
||||
|
||||
func assertValue() {
|
||||
defer func() {
|
||||
r := recover()
|
||||
fmt.Println(r)
|
||||
}()
|
||||
|
||||
var v http.ResponseWriter = httptest.NewRecorder()
|
||||
println(v.(http.Pusher))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// interface conversion: interface {} is int, not string
|
||||
// interface conversion: interface {} is nil, not string
|
||||
// interface conversion: *httptest.ResponseRecorder is not http.Pusher: missing method Push
|
||||
20
_test/variadic7.go
Normal file
20
_test/variadic7.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var a, b string
|
||||
|
||||
pattern := "%s %s"
|
||||
dest := []interface{}{&a, &b}
|
||||
|
||||
n, err := fmt.Sscanf("test1 test2", pattern, dest...)
|
||||
if err != nil || n != len(dest) {
|
||||
println("error")
|
||||
return
|
||||
}
|
||||
println(a, b)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// test1 test2
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"go/types"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
@@ -150,7 +151,7 @@ func genContent(dest, pkgName, license string) ([]byte, error) {
|
||||
case *types.Const:
|
||||
if b, ok := o.Type().(*types.Basic); ok && (b.Info()&types.IsUntyped) != 0 {
|
||||
// convert untyped constant to right type to avoid overflow
|
||||
val[name] = Val{fixConst(pname, o.Val()), false}
|
||||
val[name] = Val{fixConst(pname, o.Val(), imports), false}
|
||||
} else {
|
||||
val[name] = Val{pname, false}
|
||||
}
|
||||
@@ -253,35 +254,35 @@ func genContent(dest, pkgName, license string) ([]byte, error) {
|
||||
}
|
||||
|
||||
// fixConst checks untyped constant value, converting it if necessary to avoid overflow
|
||||
func fixConst(name string, val constant.Value) string {
|
||||
func fixConst(name string, val constant.Value, imports map[string]bool) string {
|
||||
var (
|
||||
tok string
|
||||
str string
|
||||
)
|
||||
switch val.Kind() {
|
||||
case constant.Float:
|
||||
str := val.ExactString()
|
||||
if _, err := strconv.ParseFloat(str, 32); err == nil {
|
||||
return "float32(" + name + ")"
|
||||
}
|
||||
return name
|
||||
case constant.Int:
|
||||
str := val.ExactString()
|
||||
i, err := strconv.ParseInt(str, 0, 64)
|
||||
if err == nil {
|
||||
switch {
|
||||
case i == int64(int32(i)):
|
||||
return name
|
||||
case i == int64(uint32(i)):
|
||||
return "uint32(" + name + ")"
|
||||
default:
|
||||
return "int64(" + name + ")"
|
||||
}
|
||||
tok = "INT"
|
||||
str = val.ExactString()
|
||||
case constant.Float:
|
||||
v := constant.Val(val) // v is *big.Rat or *big.Float
|
||||
f, ok := v.(*big.Float)
|
||||
if !ok {
|
||||
f = new(big.Float).SetRat(v.(*big.Rat))
|
||||
}
|
||||
_, err = strconv.ParseUint(str, 0, 64)
|
||||
if err == nil {
|
||||
return "uint64(" + name + ")"
|
||||
}
|
||||
return name
|
||||
|
||||
tok = "FLOAT"
|
||||
str = f.Text('g', int(f.Prec()))
|
||||
case constant.Complex:
|
||||
// TODO: not sure how to parse this case
|
||||
fallthrough
|
||||
default:
|
||||
return name
|
||||
}
|
||||
|
||||
imports["go/constant"] = true
|
||||
imports["go/token"] = true
|
||||
|
||||
return fmt.Sprintf("constant.MakeFromLiteral(\"%s\", token.%s, 0)", str, tok)
|
||||
}
|
||||
|
||||
// genLicense generates the correct LICENSE header text from the provided
|
||||
|
||||
@@ -72,6 +72,11 @@ Debugging support (may be removed at any time):
|
||||
Generate and display graphviz dot of AST with dotty(1)
|
||||
YAEGI_CFG_DOT=1
|
||||
Generate and display graphviz dot of CFG with dotty(1)
|
||||
YAEGI_DOT_CMD='dot -Tsvg -ofoo.svg'
|
||||
Defines how to process the dot code generated whenever YAEGI_AST_DOT and/or
|
||||
YAEGI_CFG_DOT is enabled. If any of YAEGI_AST_DOT or YAEGI_CFG_DOT is set,
|
||||
but YAEGI_DOT_CMD is not defined, the default is to write to a .dot file
|
||||
next to the Go source file.
|
||||
*/
|
||||
package main
|
||||
|
||||
@@ -128,8 +133,7 @@ func main() {
|
||||
log.Fatal("Could not read file: ", args[0])
|
||||
}
|
||||
|
||||
s := string(b)
|
||||
if s[:2] == "#!" {
|
||||
if s := string(b); strings.HasPrefix(s, "#!") {
|
||||
// Allow executable go scripts, Have the same behavior as in interactive mode.
|
||||
s = strings.Replace(s, "#!", "//", 1)
|
||||
i.REPL(strings.NewReader(s), os.Stdout)
|
||||
|
||||
@@ -6,10 +6,34 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// CITimeoutMultiplier is the multiplier for all timeouts in the CI
|
||||
CITimeoutMultiplier = 3
|
||||
)
|
||||
|
||||
// Sleep pauses the current goroutine for at least the duration d.
|
||||
func Sleep(d time.Duration) {
|
||||
d = applyCIMultiplier(d)
|
||||
time.Sleep(d)
|
||||
}
|
||||
|
||||
func applyCIMultiplier(timeout time.Duration) time.Duration {
|
||||
ci := os.Getenv("CI")
|
||||
if ci == "" {
|
||||
return timeout
|
||||
}
|
||||
b, err := strconv.ParseBool(ci)
|
||||
if err != nil || !b {
|
||||
return timeout
|
||||
}
|
||||
return time.Duration(float64(timeout) * CITimeoutMultiplier)
|
||||
}
|
||||
|
||||
func TestYaegiCmdCancel(t *testing.T) {
|
||||
tmp, err := ioutil.TempDir("", "yaegi-")
|
||||
if err != nil {
|
||||
@@ -56,7 +80,7 @@ func TestYaegiCmdCancel(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("failed pipe test source to yaegi command: %v", err)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
Sleep(200 * time.Millisecond)
|
||||
err = cmd.Process.Signal(os.Interrupt)
|
||||
if err != nil {
|
||||
t.Errorf("failed to send os.Interrupt to yaegi command: %v", err)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"go/format"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
@@ -12,7 +13,11 @@ const model = `package interp
|
||||
|
||||
// Code generated by 'go run ../internal/genop/genop.go'. DO NOT EDIT.
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Arithmetic operators
|
||||
{{range $name, $op := .Arithmetic}}
|
||||
@@ -176,9 +181,22 @@ func {{$name}}(n *node) {
|
||||
|
||||
func {{$name}}Const(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
{{- if $op.Shift}}
|
||||
s, _ := constant.Uint64Val(vConstantValue(v1))
|
||||
v := constant.Shift(vConstantValue(v0), token.{{tokenFromName $name}}, uint(s))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
{{- else}}
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.{{tokenFromName $name}}, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
{{- end}}
|
||||
{{- if $op.Str}}
|
||||
case isString(t):
|
||||
n.rval.SetString(v0.String() {{$op.Name}} v1.String())
|
||||
@@ -354,23 +372,35 @@ func {{$name}}(n *node) {
|
||||
{{end}}
|
||||
{{range $name, $op := .Unary}}
|
||||
func {{$name}}Const(n *node) {
|
||||
v0 := n.child[0].rval
|
||||
isConst := v0.IsValid() && isConstantValue(v0.Type())
|
||||
t := n.typ.rtype
|
||||
v := n.child[0].rval
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
|
||||
{{- if $op.Bool}}
|
||||
n.rval.SetBool({{$op.Name}} v.Bool())
|
||||
if isConst {
|
||||
v := constant.UnaryOp(token.{{tokenFromName $name}}, vConstantValue(v0), 0)
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
} else {
|
||||
n.rval.SetBool({{$op.Name}} v0.Bool())
|
||||
}
|
||||
{{- else}}
|
||||
switch t.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
n.rval.SetInt({{$op.Name}} v.Int())
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
n.rval.SetUint({{$op.Name}} v.Uint())
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.UnaryOp(token.{{tokenFromName $name}}, vConstantValue(v0), 0)
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isInt(t):
|
||||
n.rval.SetInt({{$op.Name}} v0.Int())
|
||||
case isUint(t):
|
||||
n.rval.SetUint({{$op.Name}} v0.Uint())
|
||||
{{- if $op.Float}}
|
||||
case reflect.Float32, reflect.Float64:
|
||||
n.rval.SetFloat({{$op.Name}} v.Float())
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
n.rval.SetComplex({{$op.Name}} v.Complex())
|
||||
case isFloat(t):
|
||||
n.rval.SetFloat({{$op.Name}} v0.Float())
|
||||
case isComplex(t):
|
||||
n.rval.SetComplex({{$op.Name}} v0.Complex())
|
||||
{{- end}}
|
||||
}
|
||||
{{- end}}
|
||||
@@ -822,6 +852,22 @@ type Op struct {
|
||||
|
||||
func main() {
|
||||
base := template.New("goexports")
|
||||
base.Funcs(template.FuncMap{
|
||||
"tokenFromName": func(name string) string {
|
||||
switch name {
|
||||
case "andNot":
|
||||
return "AND_NOT"
|
||||
case "neg":
|
||||
return "SUB"
|
||||
case "pos":
|
||||
return "ADD"
|
||||
case "bitNot":
|
||||
return "XOR"
|
||||
default:
|
||||
return strings.ToUpper(name)
|
||||
}
|
||||
},
|
||||
})
|
||||
parse, err := base.Parse(model)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
178
interp/ast.go
178
interp/ast.go
@@ -3,6 +3,7 @@ package interp
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/constant"
|
||||
"go/parser"
|
||||
"go/scanner"
|
||||
"go/token"
|
||||
@@ -31,6 +32,7 @@ const (
|
||||
caseClause
|
||||
chanType
|
||||
commClause
|
||||
commClauseDefault
|
||||
compositeLitExpr
|
||||
constDecl
|
||||
continueStmt
|
||||
@@ -93,80 +95,81 @@ const (
|
||||
)
|
||||
|
||||
var kinds = [...]string{
|
||||
undefNode: "undefNode",
|
||||
addressExpr: "addressExpr",
|
||||
arrayType: "arrayType",
|
||||
assignStmt: "assignStmt",
|
||||
assignXStmt: "assignXStmt",
|
||||
basicLit: "basicLit",
|
||||
binaryExpr: "binaryExpr",
|
||||
blockStmt: "blockStmt",
|
||||
branchStmt: "branchStmt",
|
||||
breakStmt: "breakStmt",
|
||||
callExpr: "callExpr",
|
||||
caseBody: "caseBody",
|
||||
caseClause: "caseClause",
|
||||
chanType: "chanType",
|
||||
commClause: "commClause",
|
||||
compositeLitExpr: "compositeLitExpr",
|
||||
constDecl: "constDecl",
|
||||
continueStmt: "continueStmt",
|
||||
declStmt: "declStmt",
|
||||
deferStmt: "deferStmt",
|
||||
defineStmt: "defineStmt",
|
||||
defineXStmt: "defineXStmt",
|
||||
ellipsisExpr: "ellipsisExpr",
|
||||
exprStmt: "exprStmt",
|
||||
fallthroughtStmt: "fallthroughStmt",
|
||||
fieldExpr: "fieldExpr",
|
||||
fieldList: "fieldList",
|
||||
fileStmt: "fileStmt",
|
||||
forStmt0: "forStmt0",
|
||||
forStmt1: "forStmt1",
|
||||
forStmt2: "forStmt2",
|
||||
forStmt3: "forStmt3",
|
||||
forStmt3a: "forStmt3a",
|
||||
forStmt4: "forStmt4",
|
||||
forRangeStmt: "forRangeStmt",
|
||||
funcDecl: "funcDecl",
|
||||
funcType: "funcType",
|
||||
funcLit: "funcLit",
|
||||
goStmt: "goStmt",
|
||||
gotoStmt: "gotoStmt",
|
||||
identExpr: "identExpr",
|
||||
ifStmt0: "ifStmt0",
|
||||
ifStmt1: "ifStmt1",
|
||||
ifStmt2: "ifStmt2",
|
||||
ifStmt3: "ifStmt3",
|
||||
importDecl: "importDecl",
|
||||
importSpec: "importSpec",
|
||||
incDecStmt: "incDecStmt",
|
||||
indexExpr: "indexExpr",
|
||||
interfaceType: "interfaceType",
|
||||
keyValueExpr: "keyValueExpr",
|
||||
labeledStmt: "labeledStmt",
|
||||
landExpr: "landExpr",
|
||||
lorExpr: "lorExpr",
|
||||
mapType: "mapType",
|
||||
parenExpr: "parenExpr",
|
||||
rangeStmt: "rangeStmt",
|
||||
returnStmt: "returnStmt",
|
||||
selectStmt: "selectStmt",
|
||||
selectorExpr: "selectorExpr",
|
||||
selectorImport: "selectorImport",
|
||||
sendStmt: "sendStmt",
|
||||
sliceExpr: "sliceExpr",
|
||||
starExpr: "starExpr",
|
||||
structType: "structType",
|
||||
switchStmt: "switchStmt",
|
||||
switchIfStmt: "switchIfStmt",
|
||||
typeAssertExpr: "typeAssertExpr",
|
||||
typeDecl: "typeDecl",
|
||||
typeSpec: "typeSpec",
|
||||
typeSwitch: "typeSwitch",
|
||||
unaryExpr: "unaryExpr",
|
||||
valueSpec: "valueSpec",
|
||||
varDecl: "varDecl",
|
||||
undefNode: "undefNode",
|
||||
addressExpr: "addressExpr",
|
||||
arrayType: "arrayType",
|
||||
assignStmt: "assignStmt",
|
||||
assignXStmt: "assignXStmt",
|
||||
basicLit: "basicLit",
|
||||
binaryExpr: "binaryExpr",
|
||||
blockStmt: "blockStmt",
|
||||
branchStmt: "branchStmt",
|
||||
breakStmt: "breakStmt",
|
||||
callExpr: "callExpr",
|
||||
caseBody: "caseBody",
|
||||
caseClause: "caseClause",
|
||||
chanType: "chanType",
|
||||
commClause: "commClause",
|
||||
commClauseDefault: "commClauseDefault",
|
||||
compositeLitExpr: "compositeLitExpr",
|
||||
constDecl: "constDecl",
|
||||
continueStmt: "continueStmt",
|
||||
declStmt: "declStmt",
|
||||
deferStmt: "deferStmt",
|
||||
defineStmt: "defineStmt",
|
||||
defineXStmt: "defineXStmt",
|
||||
ellipsisExpr: "ellipsisExpr",
|
||||
exprStmt: "exprStmt",
|
||||
fallthroughtStmt: "fallthroughStmt",
|
||||
fieldExpr: "fieldExpr",
|
||||
fieldList: "fieldList",
|
||||
fileStmt: "fileStmt",
|
||||
forStmt0: "forStmt0",
|
||||
forStmt1: "forStmt1",
|
||||
forStmt2: "forStmt2",
|
||||
forStmt3: "forStmt3",
|
||||
forStmt3a: "forStmt3a",
|
||||
forStmt4: "forStmt4",
|
||||
forRangeStmt: "forRangeStmt",
|
||||
funcDecl: "funcDecl",
|
||||
funcType: "funcType",
|
||||
funcLit: "funcLit",
|
||||
goStmt: "goStmt",
|
||||
gotoStmt: "gotoStmt",
|
||||
identExpr: "identExpr",
|
||||
ifStmt0: "ifStmt0",
|
||||
ifStmt1: "ifStmt1",
|
||||
ifStmt2: "ifStmt2",
|
||||
ifStmt3: "ifStmt3",
|
||||
importDecl: "importDecl",
|
||||
importSpec: "importSpec",
|
||||
incDecStmt: "incDecStmt",
|
||||
indexExpr: "indexExpr",
|
||||
interfaceType: "interfaceType",
|
||||
keyValueExpr: "keyValueExpr",
|
||||
labeledStmt: "labeledStmt",
|
||||
landExpr: "landExpr",
|
||||
lorExpr: "lorExpr",
|
||||
mapType: "mapType",
|
||||
parenExpr: "parenExpr",
|
||||
rangeStmt: "rangeStmt",
|
||||
returnStmt: "returnStmt",
|
||||
selectStmt: "selectStmt",
|
||||
selectorExpr: "selectorExpr",
|
||||
selectorImport: "selectorImport",
|
||||
sendStmt: "sendStmt",
|
||||
sliceExpr: "sliceExpr",
|
||||
starExpr: "starExpr",
|
||||
structType: "structType",
|
||||
switchStmt: "switchStmt",
|
||||
switchIfStmt: "switchIfStmt",
|
||||
typeAssertExpr: "typeAssertExpr",
|
||||
typeDecl: "typeDecl",
|
||||
typeSpec: "typeSpec",
|
||||
typeSwitch: "typeSwitch",
|
||||
unaryExpr: "unaryExpr",
|
||||
valueSpec: "valueSpec",
|
||||
varDecl: "varDecl",
|
||||
}
|
||||
|
||||
func (k nkind) String() string {
|
||||
@@ -197,6 +200,7 @@ const (
|
||||
aBitNot
|
||||
aBranch
|
||||
aCall
|
||||
aCallSlice
|
||||
aCase
|
||||
aCompositeLit
|
||||
aConvert
|
||||
@@ -206,6 +210,7 @@ const (
|
||||
aGreaterEqual
|
||||
aGetFunc
|
||||
aGetIndex
|
||||
aGetMethod
|
||||
aGetSym
|
||||
aInc
|
||||
aLand
|
||||
@@ -257,6 +262,7 @@ var actions = [...]string{
|
||||
aBitNot: "^",
|
||||
aBranch: "branch",
|
||||
aCall: "call",
|
||||
aCallSlice: "callSlice",
|
||||
aCase: "case",
|
||||
aCompositeLit: "compositeLit",
|
||||
aConvert: "convert",
|
||||
@@ -265,6 +271,7 @@ var actions = [...]string{
|
||||
aGreater: ">",
|
||||
aGetFunc: "getFunc",
|
||||
aGetIndex: "getIndex",
|
||||
aGetMethod: "getMethod",
|
||||
aGetSym: ".",
|
||||
aInc: "++",
|
||||
aLand: "&&",
|
||||
@@ -468,14 +475,14 @@ func (interp *Interpreter) ast(src, name string) (string, *node, error) {
|
||||
v, _, _, _ := strconv.UnquoteChar(a.Value[1:len(a.Value)-1], '\'')
|
||||
n.rval = reflect.ValueOf(v)
|
||||
case token.FLOAT:
|
||||
v, _ := strconv.ParseFloat(a.Value, 64)
|
||||
v := constant.MakeFromLiteral(a.Value, a.Kind, 0)
|
||||
n.rval = reflect.ValueOf(v)
|
||||
case token.IMAG:
|
||||
v, _ := strconv.ParseFloat(a.Value[:len(a.Value)-1], 64)
|
||||
n.rval = reflect.ValueOf(complex(0, v))
|
||||
v := constant.MakeFromLiteral(a.Value, a.Kind, 0)
|
||||
n.rval = reflect.ValueOf(v)
|
||||
case token.INT:
|
||||
v, _ := strconv.ParseInt(a.Value, 0, 0)
|
||||
n.rval = reflect.ValueOf(int(v))
|
||||
v := constant.MakeFromLiteral(a.Value, a.Kind, 0)
|
||||
n.rval = reflect.ValueOf(v)
|
||||
case token.STRING:
|
||||
v, _ := strconv.Unquote(a.Value)
|
||||
n.rval = reflect.ValueOf(v)
|
||||
@@ -547,7 +554,12 @@ func (interp *Interpreter) ast(src, name string) (string, *node, error) {
|
||||
st.push(addChild(&root, anc, pos, kind, aNop), nod)
|
||||
|
||||
case *ast.CallExpr:
|
||||
st.push(addChild(&root, anc, pos, callExpr, aCall), nod)
|
||||
action := aCall
|
||||
if a.Ellipsis != token.NoPos {
|
||||
action = aCallSlice
|
||||
}
|
||||
|
||||
st.push(addChild(&root, anc, pos, callExpr, action), nod)
|
||||
|
||||
case *ast.CaseClause:
|
||||
st.push(addChild(&root, anc, pos, caseClause, aCase), nod)
|
||||
@@ -556,7 +568,11 @@ func (interp *Interpreter) ast(src, name string) (string, *node, error) {
|
||||
st.push(addChild(&root, anc, pos, chanType, aNop), nod)
|
||||
|
||||
case *ast.CommClause:
|
||||
st.push(addChild(&root, anc, pos, commClause, aNop), nod)
|
||||
kind := commClause
|
||||
if a.Comm == nil {
|
||||
kind = commClauseDefault
|
||||
}
|
||||
st.push(addChild(&root, anc, pos, kind, aNop), nod)
|
||||
|
||||
case *ast.CommentGroup:
|
||||
return false
|
||||
|
||||
277
interp/cfg.go
277
interp/cfg.go
@@ -2,6 +2,7 @@ package interp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"log"
|
||||
"math"
|
||||
"reflect"
|
||||
@@ -89,6 +90,8 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
switch typ.Kind() {
|
||||
case reflect.Map:
|
||||
n.anc.gen = rangeMap
|
||||
ityp := &itype{cat: valueT, rtype: reflect.TypeOf((*reflect.MapIter)(nil))}
|
||||
sc.add(ityp)
|
||||
ktyp = &itype{cat: valueT, rtype: typ.Key()}
|
||||
vtyp = &itype{cat: valueT, rtype: typ.Elem()}
|
||||
case reflect.String:
|
||||
@@ -201,6 +204,9 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
nod.typ = typ
|
||||
}
|
||||
|
||||
case commClauseDefault:
|
||||
sc = sc.pushBloc()
|
||||
|
||||
case commClause:
|
||||
sc = sc.pushBloc()
|
||||
if len(n.child) > 0 && n.child[0].action == aAssign {
|
||||
@@ -246,6 +252,10 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
case binaryExpr, unaryExpr:
|
||||
// Do not attempt to propagate composite type to operator expressions,
|
||||
// it breaks constant folding.
|
||||
case callExpr:
|
||||
if c.typ, err = nodeType(interp, sc, c); err != nil {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
c.typ = n.typ
|
||||
}
|
||||
@@ -349,24 +359,32 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
|
||||
case typeSpec:
|
||||
// processing already done in GTA pass for global types, only parses inlined types
|
||||
if sc.def != nil {
|
||||
typeName := n.child[0].ident
|
||||
var typ *itype
|
||||
if typ, err = nodeType(interp, sc, n.child[1]); err != nil {
|
||||
return false
|
||||
}
|
||||
if typ.incomplete {
|
||||
err = n.cfgErrorf("invalid type declaration")
|
||||
return false
|
||||
}
|
||||
if n.child[1].kind == identExpr {
|
||||
n.typ = &itype{cat: aliasT, val: typ, name: typeName}
|
||||
} else {
|
||||
n.typ = typ
|
||||
n.typ.name = typeName
|
||||
}
|
||||
sc.sym[typeName] = &symbol{kind: typeSym, typ: n.typ}
|
||||
if sc.def == nil {
|
||||
return false
|
||||
}
|
||||
typeName := n.child[0].ident
|
||||
var typ *itype
|
||||
if typ, err = nodeType(interp, sc, n.child[1]); err != nil {
|
||||
return false
|
||||
}
|
||||
if typ.incomplete {
|
||||
err = n.cfgErrorf("invalid type declaration")
|
||||
return false
|
||||
}
|
||||
|
||||
if _, exists := sc.sym[typeName]; exists {
|
||||
// TODO(mpl): find the exact location of the previous declaration
|
||||
err = n.cfgErrorf("%s redeclared in this block", typeName)
|
||||
return false
|
||||
}
|
||||
|
||||
if n.child[1].kind == identExpr {
|
||||
n.typ = &itype{cat: aliasT, val: typ, name: typeName}
|
||||
} else {
|
||||
n.typ = typ
|
||||
n.typ.name = typeName
|
||||
}
|
||||
sc.sym[typeName] = &symbol{kind: typeSym, typ: n.typ}
|
||||
return false
|
||||
|
||||
case constDecl:
|
||||
@@ -381,7 +399,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
}
|
||||
}
|
||||
|
||||
case arrayType, basicLit, chanType, funcType, mapType, structType:
|
||||
case arrayType, basicLit, chanType, funcType, interfaceType, mapType, structType:
|
||||
n.typ, err = nodeType(interp, sc, n)
|
||||
return false
|
||||
}
|
||||
@@ -493,7 +511,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
// Propagate type
|
||||
// TODO: Check that existing destination type matches source type
|
||||
switch {
|
||||
case n.action == aAssign && src.action == aCall && dest.typ.cat != interfaceT:
|
||||
case n.action == aAssign && isCall(src) && dest.typ.cat != interfaceT && !isRecursiveField(dest):
|
||||
// Call action may perform the assignment directly.
|
||||
n.gen = nop
|
||||
src.level = level
|
||||
@@ -506,7 +524,14 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
n.gen = nop
|
||||
src.findex = dest.findex // Set recv address to LHS
|
||||
dest.typ = src.typ
|
||||
case n.action == aAssign && src.action == aCompositeLit:
|
||||
case n.action == aAssign && src.action == aCompositeLit && !isMapEntry(dest):
|
||||
if dest.typ.cat == valueT && dest.typ.rtype.Kind() == reflect.Interface {
|
||||
// Skip optimisation for assigned binary interface or map entry
|
||||
// which require and additional operation to set the value
|
||||
break
|
||||
}
|
||||
// Skip the assign operation entirely, the source frame index is set
|
||||
// to destination index, avoiding extra memory alloc and duplication.
|
||||
n.gen = nop
|
||||
src.findex = dest.findex
|
||||
src.level = level
|
||||
@@ -519,8 +544,11 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
case !src.rval.IsValid():
|
||||
// Assign to nil.
|
||||
src.rval = reflect.New(dest.typ.TypeOf()).Elem()
|
||||
case n.anc.kind == constDecl:
|
||||
// Possible conversion from const to actual type will be handled later
|
||||
default:
|
||||
// Convert literal value to destination type.
|
||||
convertConstantValue(src)
|
||||
src.rval = src.rval.Convert(dest.typ.TypeOf())
|
||||
src.typ = dest.typ
|
||||
}
|
||||
@@ -535,6 +563,12 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
dest.gen = nop // skip getIndexMap
|
||||
}
|
||||
if n.anc.kind == constDecl {
|
||||
if !dest.typ.untyped {
|
||||
// If the dest is untyped, any constant rval needs to be converted
|
||||
convertConstantValue(src)
|
||||
}
|
||||
n.gen = nop
|
||||
n.findex = -1
|
||||
sc.sym[dest.ident].kind = constSym
|
||||
if childPos(n) == len(n.anc.child)-1 {
|
||||
sc.iota = 0
|
||||
@@ -701,7 +735,6 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
n.typ = t.val
|
||||
}
|
||||
n.findex = sc.add(n.typ)
|
||||
n.recv = &receiver{node: n}
|
||||
typ := t.TypeOf()
|
||||
switch k := typ.Kind(); k {
|
||||
case reflect.Map:
|
||||
@@ -812,7 +845,23 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
}
|
||||
case isBinCall(n):
|
||||
n.gen = callBin
|
||||
if typ := n.child[0].typ.rtype; typ.NumOut() > 0 {
|
||||
typ := n.child[0].typ.rtype
|
||||
numIn := len(n.child) - 1
|
||||
tni := typ.NumIn()
|
||||
if numIn == 1 && isCall(n.child[1]) {
|
||||
numIn = n.child[1].typ.numOut()
|
||||
}
|
||||
if n.child[0].action == aGetMethod {
|
||||
tni-- // The first argument is the method receiver.
|
||||
}
|
||||
if typ.IsVariadic() {
|
||||
tni-- // The last argument could be empty.
|
||||
}
|
||||
if numIn < tni {
|
||||
err = n.cfgErrorf("not enough arguments in call to %v", n.child[0].name())
|
||||
break
|
||||
}
|
||||
if typ.NumOut() > 0 {
|
||||
if funcType := n.child[0].typ.val; funcType != nil {
|
||||
// Use the original unwrapped function type, to allow future field and
|
||||
// methods resolutions, otherwise impossible on the opaque bin type.
|
||||
@@ -868,25 +917,29 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
case caseClause:
|
||||
sc = sc.pop()
|
||||
|
||||
case commClauseDefault:
|
||||
wireChild(n)
|
||||
sc = sc.pop()
|
||||
if len(n.child) == 0 {
|
||||
return
|
||||
}
|
||||
n.start = n.child[0].start
|
||||
n.lastChild().tnext = n.anc.anc // exit node is selectStmt
|
||||
|
||||
case commClause:
|
||||
wireChild(n)
|
||||
switch len(n.child) {
|
||||
case 0:
|
||||
sc.pop()
|
||||
sc = sc.pop()
|
||||
if len(n.child) == 0 {
|
||||
return
|
||||
case 1:
|
||||
n.start = n.child[0].start // default clause
|
||||
default:
|
||||
}
|
||||
if len(n.child) > 1 {
|
||||
n.start = n.child[1].start // Skip chan operation, performed by select
|
||||
}
|
||||
n.lastChild().tnext = n.anc.anc // exit node is selectStmt
|
||||
sc = sc.pop()
|
||||
|
||||
case compositeLitExpr:
|
||||
wireChild(n)
|
||||
if n.anc.action != aAssign {
|
||||
n.findex = sc.add(n.typ)
|
||||
}
|
||||
n.findex = sc.add(n.typ)
|
||||
// TODO: Check that composite literal expr matches corresponding type
|
||||
n.gen = compositeGenerator(n, sc)
|
||||
|
||||
@@ -1039,7 +1092,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
n.rval = sym.rval
|
||||
n.kind = basicLit
|
||||
case n.ident == "iota":
|
||||
n.rval = reflect.ValueOf(sc.iota)
|
||||
n.rval = reflect.ValueOf(constant.Make(int64(sc.iota)))
|
||||
n.kind = basicLit
|
||||
case n.ident == "nil":
|
||||
n.kind = basicLit
|
||||
@@ -1196,6 +1249,16 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
}
|
||||
|
||||
case returnStmt:
|
||||
if mustReturnValue(sc.def.child[2]) {
|
||||
nret := len(n.child)
|
||||
if nret == 1 && isCall(n.child[0]) {
|
||||
nret = n.child[0].child[0].typ.numOut()
|
||||
}
|
||||
if nret < sc.def.typ.numOut() {
|
||||
err = n.cfgErrorf("not enough arguments to return")
|
||||
break
|
||||
}
|
||||
}
|
||||
wireChild(n)
|
||||
n.tnext = nil
|
||||
n.val = sc.def
|
||||
@@ -1232,6 +1295,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
case ok:
|
||||
n.val = method.Index
|
||||
n.gen = getIndexBinMethod
|
||||
n.action = aGetMethod
|
||||
n.recv = &receiver{node: n.child[0]}
|
||||
n.typ = &itype{cat: valueT, rtype: method.Type, isBinMethod: true}
|
||||
case n.typ.rtype.Kind() == reflect.Ptr:
|
||||
@@ -1255,6 +1319,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
n.gen = getIndexBinPtrMethod
|
||||
n.typ = &itype{cat: valueT, rtype: m2.Type}
|
||||
n.recv = &receiver{node: n.child[0]}
|
||||
n.action = aGetMethod
|
||||
} else {
|
||||
err = n.cfgErrorf("undefined field or method: %s", n.child[1].ident)
|
||||
}
|
||||
@@ -1269,11 +1334,13 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
n.typ = &itype{cat: valueT, rtype: method.Type}
|
||||
n.recv = &receiver{node: n.child[0]}
|
||||
n.gen = getIndexBinMethod
|
||||
n.action = aGetMethod
|
||||
} else if method, ok := reflect.PtrTo(n.typ.val.rtype).MethodByName(n.child[1].ident); ok {
|
||||
n.val = method.Index
|
||||
n.gen = getIndexBinMethod
|
||||
n.typ = &itype{cat: valueT, rtype: method.Type}
|
||||
n.recv = &receiver{node: n.child[0]}
|
||||
n.action = aGetMethod
|
||||
} else if field, ok := n.typ.val.rtype.FieldByName(n.child[1].ident); ok {
|
||||
n.typ = &itype{cat: valueT, rtype: field.Type}
|
||||
n.val = field.Index
|
||||
@@ -1312,6 +1379,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
err = n.cfgErrorf("undefined selector: %s.%s", pkg, name)
|
||||
}
|
||||
} else if m, lind := n.typ.lookupMethod(n.child[1].ident); m != nil {
|
||||
n.action = aGetMethod
|
||||
if n.child[0].isType(sc) {
|
||||
// Handle method as a function with receiver in 1st argument
|
||||
n.val = m
|
||||
@@ -1328,6 +1396,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
n.recv = &receiver{node: n.child[0], index: lind}
|
||||
}
|
||||
} else if m, lind, isPtr, ok := n.typ.lookupBinMethod(n.child[1].ident); ok {
|
||||
n.action = aGetMethod
|
||||
if isPtr && n.typ.fieldSeq(lind).cat != ptrT {
|
||||
n.gen = getIndexSeqPtrMethod
|
||||
} else {
|
||||
@@ -1381,29 +1450,37 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
// Chain channel init actions in commClauses prior to invoke select.
|
||||
var cur *node
|
||||
for _, c := range n.child[0].child {
|
||||
var an *node // channel init action node
|
||||
var an, pn *node // channel init action nodes
|
||||
if len(c.child) > 0 {
|
||||
switch c0 := c.child[0]; {
|
||||
case c0.kind == exprStmt && len(c0.child) == 1 && c0.child[0].action == aRecv:
|
||||
an = c0.child[0].child[0]
|
||||
pn = an
|
||||
case c0.action == aAssign:
|
||||
an = c0.lastChild().child[0]
|
||||
pn = an
|
||||
case c0.kind == sendStmt:
|
||||
an = c0.child[0]
|
||||
pn = c0.child[1]
|
||||
}
|
||||
}
|
||||
if an != nil {
|
||||
if cur == nil {
|
||||
// First channel init action, the entry point for the select block.
|
||||
n.start = an.start
|
||||
} else {
|
||||
// Chain channel init action to the previous one.
|
||||
cur.tnext = an.start
|
||||
}
|
||||
if an == nil {
|
||||
continue
|
||||
}
|
||||
if cur == nil {
|
||||
// First channel init action, the entry point for the select block.
|
||||
n.start = an.start
|
||||
} else {
|
||||
// Chain channel init action to the previous one.
|
||||
cur.tnext = an.start
|
||||
}
|
||||
if pn != nil {
|
||||
// Chain channect init action to send data init action.
|
||||
// (already done by wireChild, but let's be explicit).
|
||||
an.tnext = pn
|
||||
cur = pn
|
||||
}
|
||||
cur = an
|
||||
}
|
||||
// Invoke select action
|
||||
if cur == nil {
|
||||
// There is no channel init action, call select directly.
|
||||
n.start = n.child[0]
|
||||
@@ -1510,24 +1587,29 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
for i := l - 1; i >= 0; i-- {
|
||||
c := clauses[i]
|
||||
c.gen = nop
|
||||
body := c.lastChild()
|
||||
if len(c.child) > 1 {
|
||||
cond := c.child[0]
|
||||
cond.tnext = body.start
|
||||
if i == l-1 {
|
||||
setFNext(cond, n)
|
||||
if len(c.child) == 0 {
|
||||
c.tnext = n
|
||||
c.fnext = n
|
||||
} else {
|
||||
body := c.lastChild()
|
||||
if len(c.child) > 1 {
|
||||
cond := c.child[0]
|
||||
cond.tnext = body.start
|
||||
if i == l-1 {
|
||||
setFNext(cond, n)
|
||||
} else {
|
||||
setFNext(cond, clauses[i+1].start)
|
||||
}
|
||||
c.start = cond.start
|
||||
} else {
|
||||
setFNext(cond, clauses[i+1].start)
|
||||
c.start = body.start
|
||||
}
|
||||
// If last case body statement is a fallthrough, then jump to next case body
|
||||
if i < l-1 && len(body.child) > 0 && body.lastChild().kind == fallthroughtStmt {
|
||||
body.tnext = clauses[i+1].lastChild().start
|
||||
} else {
|
||||
body.tnext = n
|
||||
}
|
||||
c.start = cond.start
|
||||
} else {
|
||||
c.start = body.start
|
||||
}
|
||||
// If last case body statement is a fallthrough, then jump to next case body
|
||||
if i < l-1 && len(body.child) > 0 && body.lastChild().kind == fallthroughtStmt {
|
||||
body.tnext = clauses[i+1].lastChild().start
|
||||
} else {
|
||||
body.tnext = n
|
||||
}
|
||||
}
|
||||
sbn.start = clauses[0].start
|
||||
@@ -1629,6 +1711,19 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
|
||||
// Global object allocation is already performed in GTA.
|
||||
index = sc.sym[c.ident].index
|
||||
} else {
|
||||
if sym, exists := sc.sym[c.ident]; exists {
|
||||
if sym.typ.node != nil &&
|
||||
sym.typ.node.anc != nil {
|
||||
// for non-predeclared identifiers (struct, map, etc)
|
||||
prevDecl := n.interp.fset.Position(sym.typ.node.anc.pos)
|
||||
err = n.cfgErrorf("%s redeclared in this block\n\tprevious declaration at %v", c.ident, prevDecl)
|
||||
return
|
||||
}
|
||||
// for predeclared identifiers (int, string, etc)
|
||||
// TODO(mpl): find the exact location of the previous declaration in all cases.
|
||||
err = n.cfgErrorf("%s redeclared in this block", c.ident)
|
||||
return
|
||||
}
|
||||
index = sc.add(n.typ)
|
||||
sc.sym[c.ident] = &symbol{index: index, kind: varSym, typ: n.typ}
|
||||
}
|
||||
@@ -1706,13 +1801,13 @@ func compDefineX(sc *scope, n *node) error {
|
||||
}
|
||||
|
||||
// TODO used for allocation optimization, temporarily disabled
|
||||
//func isAncBranch(n *node) bool {
|
||||
// func isAncBranch(n *node) bool {
|
||||
// switch n.anc.kind {
|
||||
// case If0, If1, If2, If3:
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
//}
|
||||
// }
|
||||
|
||||
func childPos(n *node) int {
|
||||
for i, c := range n.anc.child {
|
||||
@@ -1867,7 +1962,7 @@ func (n *node) isInteger() bool {
|
||||
if isInt(n.typ.TypeOf()) {
|
||||
return true
|
||||
}
|
||||
if n.typ.untyped && n.rval.IsValid() {
|
||||
if n.rval.IsValid() {
|
||||
t := n.rval.Type()
|
||||
if isInt(t) {
|
||||
return true
|
||||
@@ -1881,6 +1976,20 @@ func (n *node) isInteger() bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if isConstantValue(t) {
|
||||
c := n.rval.Interface().(constant.Value)
|
||||
switch c.Kind() {
|
||||
case constant.Int:
|
||||
return true
|
||||
case constant.Float:
|
||||
f, _ := constant.Float64Val(c)
|
||||
if f == math.Trunc(f) {
|
||||
n.rval = reflect.ValueOf(constant.ToInt(c))
|
||||
n.typ.rtype = n.rval.Type()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1890,7 +1999,7 @@ func (n *node) isNatural() bool {
|
||||
if isUint(n.typ.TypeOf()) {
|
||||
return true
|
||||
}
|
||||
if n.typ.untyped && n.rval.IsValid() {
|
||||
if n.rval.IsValid() {
|
||||
t := n.rval.Type()
|
||||
if isUint(t) {
|
||||
return true
|
||||
@@ -1908,6 +2017,23 @@ func (n *node) isNatural() bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if isConstantValue(t) {
|
||||
c := n.rval.Interface().(constant.Value)
|
||||
switch c.Kind() {
|
||||
case constant.Int:
|
||||
i, _ := constant.Int64Val(c)
|
||||
if i >= 0 {
|
||||
return true
|
||||
}
|
||||
case constant.Float:
|
||||
f, _ := constant.Float64Val(c)
|
||||
if f == math.Trunc(f) {
|
||||
n.rval = reflect.ValueOf(constant.ToInt(c))
|
||||
n.typ.rtype = n.rval.Type()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1953,6 +2079,10 @@ func isField(n *node) bool {
|
||||
return n.kind == selectorExpr && len(n.child) > 0 && n.child[0].typ != nil && isStruct(n.child[0].typ)
|
||||
}
|
||||
|
||||
func isRecursiveField(n *node) bool {
|
||||
return isField(n) && (n.typ.recursive || n.typ.cat == ptrT && n.typ.val.recursive)
|
||||
}
|
||||
|
||||
// isNewDefine returns true if node refers to a new definition
|
||||
func isNewDefine(n *node, sc *scope) bool {
|
||||
if n.ident == "_" {
|
||||
@@ -1981,10 +2111,26 @@ func isMapEntry(n *node) bool {
|
||||
return n.action == aGetIndex && isMap(n.child[0].typ)
|
||||
}
|
||||
|
||||
func isCall(n *node) bool {
|
||||
return n.action == aCall || n.action == aCallSlice
|
||||
}
|
||||
|
||||
func isBinCall(n *node) bool {
|
||||
return n.kind == callExpr && n.child[0].typ.cat == valueT && n.child[0].typ.rtype.Kind() == reflect.Func
|
||||
}
|
||||
|
||||
func mustReturnValue(n *node) bool {
|
||||
if len(n.child) < 2 {
|
||||
return false
|
||||
}
|
||||
for _, f := range n.child[1].child {
|
||||
if len(f.child) > 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isRegularCall(n *node) bool {
|
||||
return n.kind == callExpr && n.child[0].typ.cat == funcT
|
||||
}
|
||||
@@ -2136,5 +2282,8 @@ func isValueUntyped(v reflect.Value) bool {
|
||||
return false
|
||||
}
|
||||
t := v.Type()
|
||||
if t.Implements(constVal) {
|
||||
return true
|
||||
}
|
||||
return t.String() == t.Kind().String()
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package interp
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -58,10 +60,19 @@ func (n *node) cfgDot(out io.Writer) {
|
||||
fmt.Fprintf(out, "}\n")
|
||||
}
|
||||
|
||||
// dotX returns an output stream to a dot(1) co-process where to write data in .dot format
|
||||
func dotX() io.WriteCloser {
|
||||
cmd := exec.Command("dotty", "-")
|
||||
//cmd := exec.Command("dot", "-T", "xlib")
|
||||
type nopCloser struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (nopCloser) Close() error { return nil }
|
||||
|
||||
// dotWriter returns an output stream to a dot(1) co-process where to write data in .dot format
|
||||
func dotWriter(dotCmd string) io.WriteCloser {
|
||||
if dotCmd == "" {
|
||||
return nopCloser{ioutil.Discard}
|
||||
}
|
||||
fields := strings.Fields(dotCmd)
|
||||
cmd := exec.Command(fields[0], fields[1:]...)
|
||||
dotin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -71,3 +82,14 @@ func dotX() io.WriteCloser {
|
||||
}
|
||||
return dotin
|
||||
}
|
||||
|
||||
func defaultDotCmd(filePath, prefix string) string {
|
||||
dir, fileName := filepath.Split(filePath)
|
||||
ext := filepath.Ext(fileName)
|
||||
if ext == "" {
|
||||
fileName += ".dot"
|
||||
} else {
|
||||
fileName = strings.Replace(fileName, ext, ".dot", 1)
|
||||
}
|
||||
return "dot -Tdot -o" + dir + prefix + fileName
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ func (interp *Interpreter) gta(root *node, rpath, pkgID string) ([]*node, error)
|
||||
}
|
||||
}
|
||||
rcvrtype.method = append(rcvrtype.method, n)
|
||||
n.child[0].child[0].lastChild().typ = rcvrtype
|
||||
} else {
|
||||
// Add a function symbol in the package name space
|
||||
sc.sym[n.child[1].ident] = &symbol{kind: funcSym, typ: n.typ, node: n, index: -1}
|
||||
@@ -153,9 +154,9 @@ func (interp *Interpreter) gta(root *node, rpath, pkgID string) ([]*node, error)
|
||||
name = n.child[0].ident
|
||||
} else {
|
||||
ipath = n.child[0].rval.String()
|
||||
name = identifier.FindString(ipath)
|
||||
}
|
||||
// Try to import a binary package first, or a source package
|
||||
var pkgName string
|
||||
if interp.binPkg[ipath] != nil {
|
||||
switch name {
|
||||
case "_": // no import of symbols
|
||||
@@ -168,9 +169,13 @@ func (interp *Interpreter) gta(root *node, rpath, pkgID string) ([]*node, error)
|
||||
sc.sym[n] = &symbol{kind: binSym, typ: &itype{cat: valueT, rtype: typ, scope: sc}, rval: v}
|
||||
}
|
||||
default: // import symbols in package namespace
|
||||
if name == "" {
|
||||
name = identifier.FindString(ipath)
|
||||
}
|
||||
|
||||
sc.sym[name] = &symbol{kind: pkgSym, typ: &itype{cat: binPkgT, path: ipath, scope: sc}}
|
||||
}
|
||||
} else if err = interp.importSrc(rpath, ipath); err == nil {
|
||||
} else if pkgName, err = interp.importSrc(rpath, ipath); err == nil {
|
||||
sc.types = interp.universe.types
|
||||
switch name {
|
||||
case "_": // no import of symbols
|
||||
@@ -181,6 +186,10 @@ func (interp *Interpreter) gta(root *node, rpath, pkgID string) ([]*node, error)
|
||||
}
|
||||
}
|
||||
default: // import symbols in package namespace
|
||||
if name == "" {
|
||||
name = pkgName
|
||||
}
|
||||
|
||||
sc.sym[name] = &symbol{kind: pkgSym, typ: &itype{cat: srcPkgT, path: ipath, scope: sc}}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -104,8 +104,11 @@ type imports map[string]map[string]*symbol
|
||||
|
||||
// opt stores interpreter options
|
||||
type opt struct {
|
||||
astDot bool // display AST graph (debug)
|
||||
cfgDot bool // display CFG graph (debug)
|
||||
astDot bool // display AST graph (debug)
|
||||
cfgDot bool // display CFG graph (debug)
|
||||
// dotCmd is the command to process the dot graph produced when astDot and/or
|
||||
// cfgDot is enabled. It defaults to 'dot -Tdot -o <filename>.dot'.
|
||||
dotCmd string
|
||||
noRun bool // compile, but do not run
|
||||
fastChan bool // disable cancellable chan operations
|
||||
context build.Context // build context: GOPATH, build constraints
|
||||
@@ -133,6 +136,7 @@ type Interpreter struct {
|
||||
universe *scope // interpreter global level scope
|
||||
scopes map[string]*scope // package level scopes, indexed by package name
|
||||
srcPkg imports // source packages used in interpreter, indexed by path
|
||||
pkgNames map[string]string // package names, indexed by path
|
||||
done chan struct{} // for cancellation of channel operations
|
||||
}
|
||||
|
||||
@@ -210,6 +214,7 @@ func New(options Options) *Interpreter {
|
||||
scopes: map[string]*scope{},
|
||||
binPkg: Exports{"": map[string]reflect.Value{"_error": reflect.ValueOf((*_error)(nil))}},
|
||||
srcPkg: imports{},
|
||||
pkgNames: map[string]string{},
|
||||
rdir: map[string]bool{},
|
||||
}
|
||||
|
||||
@@ -224,6 +229,11 @@ func New(options Options) *Interpreter {
|
||||
// cfgDot activates AST graph display for the interpreter
|
||||
i.opt.cfgDot, _ = strconv.ParseBool(os.Getenv("YAEGI_CFG_DOT"))
|
||||
|
||||
// dotCmd defines how to process the dot code generated whenever astDot and/or
|
||||
// cfgDot is enabled. It defaults to 'dot -Tdot -o<filename>.dot' where filename
|
||||
// is context dependent.
|
||||
i.opt.dotCmd = os.Getenv("YAEGI_DOT_CMD")
|
||||
|
||||
// noRun disables the execution (but not the compilation) in the interpreter
|
||||
i.opt.noRun, _ = strconv.ParseBool(os.Getenv("YAEGI_NO_RUN"))
|
||||
|
||||
@@ -328,7 +338,11 @@ func (interp *Interpreter) Eval(src string) (res reflect.Value, err error) {
|
||||
}
|
||||
|
||||
if interp.astDot {
|
||||
root.astDot(dotX(), interp.Name)
|
||||
dotCmd := interp.dotCmd
|
||||
if dotCmd == "" {
|
||||
dotCmd = defaultDotCmd(interp.Name, "yaegi-ast-")
|
||||
}
|
||||
root.astDot(dotWriter(dotCmd), interp.Name)
|
||||
if interp.noRun {
|
||||
return res, err
|
||||
}
|
||||
@@ -363,7 +377,11 @@ func (interp *Interpreter) Eval(src string) (res reflect.Value, err error) {
|
||||
interp.mutex.Unlock()
|
||||
|
||||
if interp.cfgDot {
|
||||
root.cfgDot(dotX())
|
||||
dotCmd := interp.dotCmd
|
||||
if dotCmd == "" {
|
||||
dotCmd = defaultDotCmd(interp.Name, "yaegi-cfg-")
|
||||
}
|
||||
root.cfgDot(dotWriter(dotCmd))
|
||||
}
|
||||
|
||||
if interp.noRun {
|
||||
|
||||
@@ -39,6 +39,8 @@ func TestInterpConsistencyBuild(t *testing.T) {
|
||||
file.Name() == "export1.go" || // non-main package
|
||||
file.Name() == "export0.go" || // non-main package
|
||||
file.Name() == "for7.go" || // expect error
|
||||
file.Name() == "fun21.go" || // expect error
|
||||
file.Name() == "fun22.go" || // expect error
|
||||
file.Name() == "if2.go" || // expect error
|
||||
file.Name() == "import6.go" || // expect error
|
||||
file.Name() == "io0.go" || // use random number
|
||||
@@ -56,6 +58,12 @@ func TestInterpConsistencyBuild(t *testing.T) {
|
||||
file.Name() == "type5.go" || // used to illustrate a limitation with no workaround, related to the fact that the reflect package does not allow the creation of named types
|
||||
file.Name() == "type6.go" || // used to illustrate a limitation with no workaround, related to the fact that the reflect package does not allow the creation of named types
|
||||
|
||||
file.Name() == "redeclaration0.go" || // expect error
|
||||
file.Name() == "redeclaration1.go" || // expect error
|
||||
file.Name() == "redeclaration2.go" || // expect error
|
||||
file.Name() == "redeclaration3.go" || // expect error
|
||||
file.Name() == "redeclaration4.go" || // expect error
|
||||
file.Name() == "redeclaration5.go" || // expect error
|
||||
file.Name() == "server6.go" || // syntax parsing
|
||||
file.Name() == "server5.go" || // syntax parsing
|
||||
file.Name() == "server4.go" || // syntax parsing
|
||||
@@ -166,6 +174,16 @@ func TestInterpErrorConsistency(t *testing.T) {
|
||||
expectedInterp: "4:14: non-bool used as for condition",
|
||||
expectedExec: "4:2: non-bool i (type int) used as for condition",
|
||||
},
|
||||
{
|
||||
fileName: "fun21.go",
|
||||
expectedInterp: "4:2: not enough arguments to return",
|
||||
expectedExec: "4:2: not enough arguments to return",
|
||||
},
|
||||
{
|
||||
fileName: "fun22.go",
|
||||
expectedInterp: "6:2: not enough arguments in call to time.Date",
|
||||
expectedExec: "6:11: not enough arguments in call to time.Date",
|
||||
},
|
||||
{
|
||||
fileName: "op1.go",
|
||||
expectedInterp: "5:2: illegal operand types for '+=' operator",
|
||||
|
||||
@@ -40,8 +40,8 @@ func TestEvalArithmetic(t *testing.T) {
|
||||
{desc: "sub_FI", src: "7.2 - 3", res: "4.2"},
|
||||
{desc: "sub_IF", src: "7 - 3.2", res: "3.8"},
|
||||
{desc: "mul_II", src: "2 * 3", res: "6"},
|
||||
{desc: "mul_FI", src: "2.2 * 3", res: "6.6000000000000005"},
|
||||
{desc: "mul_IF", src: "3 * 2.2", res: "6.6000000000000005"},
|
||||
{desc: "mul_FI", src: "2.2 * 3", res: "6.6"},
|
||||
{desc: "mul_IF", src: "3 * 2.2", res: "6.6"},
|
||||
{desc: "rem_FI", src: "8.2 % 4", err: "1:28: illegal operand types for '%' operator"},
|
||||
{desc: "shl_II", src: "1 << 8", res: "256"},
|
||||
{desc: "shl_IN", src: "1 << -1", err: "1:28: illegal operand types for '<<' operator"},
|
||||
|
||||
190
interp/interp_test.go
Normal file
190
interp/interp_test.go
Normal file
@@ -0,0 +1,190 @@
|
||||
package interp
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() { log.SetFlags(log.Lshortfile) }
|
||||
|
||||
func TestIsNatural(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
n *node
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
desc: "positive uint var",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
var x uint = 3
|
||||
return reflect.TypeOf(x)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
var x uint = 3
|
||||
return reflect.ValueOf(x)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "positive untyped var",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
var x = 3
|
||||
return reflect.TypeOf(x)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
var x = 3
|
||||
return reflect.ValueOf(x)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "positive int var",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
var x int = 3
|
||||
return reflect.TypeOf(x)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
var x int = 3
|
||||
return reflect.ValueOf(x)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "positive float var, null decimal",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
var x float64 = 3.0
|
||||
return reflect.TypeOf(x)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
var x float64 = 3.0
|
||||
return reflect.ValueOf(x)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "positive float var, with decimal",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
var x float64 = 3.14
|
||||
return reflect.TypeOf(x)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
var x float64 = 3.14
|
||||
return reflect.ValueOf(x)
|
||||
}(),
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "negative int var",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
var x int = -3
|
||||
return reflect.TypeOf(x)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
var x int = -3
|
||||
return reflect.ValueOf(x)
|
||||
}(),
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "positive typed const",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
const a uint = 3
|
||||
return reflect.TypeOf(a)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
const a uint = 3
|
||||
return reflect.ValueOf(a)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "positive untyped const",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
const a = 3
|
||||
return reflect.TypeOf(a)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
const a = 3
|
||||
return reflect.ValueOf(a)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "positive untyped const (iota)",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
const (
|
||||
zero = iota
|
||||
a
|
||||
)
|
||||
return reflect.TypeOf(a)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
const (
|
||||
zero = iota
|
||||
a
|
||||
)
|
||||
return reflect.ValueOf(a)
|
||||
}(),
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "negative const",
|
||||
n: &node{
|
||||
typ: &itype{
|
||||
rtype: func() reflect.Type {
|
||||
const a = -3
|
||||
return reflect.TypeOf(a)
|
||||
}(),
|
||||
},
|
||||
rval: func() reflect.Value {
|
||||
const a = -3
|
||||
return reflect.ValueOf(a)
|
||||
}(),
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
got := test.n.isNatural()
|
||||
if test.expected != got {
|
||||
t.Fatalf("%s: got %v, wanted %v", test.desc, got, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
171
interp/op.go
171
interp/op.go
@@ -2,7 +2,11 @@ package interp
|
||||
|
||||
// Code generated by 'go run ../internal/genop/genop.go'. DO NOT EDIT.
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Arithmetic operators
|
||||
|
||||
@@ -150,9 +154,16 @@ func add(n *node) {
|
||||
|
||||
func addConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.ADD, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isString(t):
|
||||
n.rval.SetString(v0.String() + v1.String())
|
||||
case isComplex(t):
|
||||
@@ -234,9 +245,16 @@ func and(n *node) {
|
||||
|
||||
func andConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.AND, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) & vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -312,9 +330,16 @@ func andNot(n *node) {
|
||||
|
||||
func andNotConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.AND_NOT, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) &^ vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -442,9 +467,16 @@ func mul(n *node) {
|
||||
|
||||
func mulConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.MUL, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isComplex(t):
|
||||
n.rval.SetComplex(vComplex(v0) * vComplex(v1))
|
||||
case isFloat(t):
|
||||
@@ -524,9 +556,16 @@ func or(n *node) {
|
||||
|
||||
func orConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.OR, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) | vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -654,9 +693,16 @@ func quo(n *node) {
|
||||
|
||||
func quoConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.QUO, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isComplex(t):
|
||||
n.rval.SetComplex(vComplex(v0) / vComplex(v1))
|
||||
case isFloat(t):
|
||||
@@ -736,9 +782,16 @@ func rem(n *node) {
|
||||
|
||||
func remConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.REM, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) % vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -814,9 +867,17 @@ func shl(n *node) {
|
||||
|
||||
func shlConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
s, _ := constant.Uint64Val(vConstantValue(v1))
|
||||
v := constant.Shift(vConstantValue(v0), token.SHL, uint(s))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) << vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -892,9 +953,17 @@ func shr(n *node) {
|
||||
|
||||
func shrConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
s, _ := constant.Uint64Val(vConstantValue(v1))
|
||||
v := constant.Shift(vConstantValue(v0), token.SHR, uint(s))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) >> vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -1022,9 +1091,16 @@ func sub(n *node) {
|
||||
|
||||
func subConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.SUB, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isComplex(t):
|
||||
n.rval.SetComplex(vComplex(v0) - vComplex(v1))
|
||||
case isFloat(t):
|
||||
@@ -1104,9 +1180,16 @@ func xor(n *node) {
|
||||
|
||||
func xorConst(n *node) {
|
||||
v0, v1 := n.child[0].rval, n.child[1].rval
|
||||
isConst := (v0.IsValid() && isConstantValue(v0.Type())) && (v1.IsValid() && isConstantValue(v1.Type()))
|
||||
t := n.typ.rtype
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.BinaryOp(vConstantValue(v0), token.XOR, vConstantValue(v1))
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isUint(t):
|
||||
n.rval.SetUint(vUint(v0) ^ vUint(v1))
|
||||
case isInt(t):
|
||||
@@ -1865,53 +1948,83 @@ func inc(n *node) {
|
||||
}
|
||||
|
||||
func bitNotConst(n *node) {
|
||||
v0 := n.child[0].rval
|
||||
isConst := v0.IsValid() && isConstantValue(v0.Type())
|
||||
t := n.typ.rtype
|
||||
v := n.child[0].rval
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch t.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
n.rval.SetInt(^v.Int())
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
n.rval.SetUint(^v.Uint())
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.UnaryOp(token.XOR, vConstantValue(v0), 0)
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isInt(t):
|
||||
n.rval.SetInt(^v0.Int())
|
||||
case isUint(t):
|
||||
n.rval.SetUint(^v0.Uint())
|
||||
}
|
||||
}
|
||||
|
||||
func negConst(n *node) {
|
||||
v0 := n.child[0].rval
|
||||
isConst := v0.IsValid() && isConstantValue(v0.Type())
|
||||
t := n.typ.rtype
|
||||
v := n.child[0].rval
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch t.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
n.rval.SetInt(-v.Int())
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
n.rval.SetUint(-v.Uint())
|
||||
case reflect.Float32, reflect.Float64:
|
||||
n.rval.SetFloat(-v.Float())
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
n.rval.SetComplex(-v.Complex())
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.UnaryOp(token.SUB, vConstantValue(v0), 0)
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isInt(t):
|
||||
n.rval.SetInt(-v0.Int())
|
||||
case isUint(t):
|
||||
n.rval.SetUint(-v0.Uint())
|
||||
case isFloat(t):
|
||||
n.rval.SetFloat(-v0.Float())
|
||||
case isComplex(t):
|
||||
n.rval.SetComplex(-v0.Complex())
|
||||
}
|
||||
}
|
||||
|
||||
func notConst(n *node) {
|
||||
v0 := n.child[0].rval
|
||||
isConst := v0.IsValid() && isConstantValue(v0.Type())
|
||||
t := n.typ.rtype
|
||||
v := n.child[0].rval
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
n.rval.SetBool(!v.Bool())
|
||||
if isConst {
|
||||
v := constant.UnaryOp(token.NOT, vConstantValue(v0), 0)
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
} else {
|
||||
n.rval.SetBool(!v0.Bool())
|
||||
}
|
||||
}
|
||||
|
||||
func posConst(n *node) {
|
||||
v0 := n.child[0].rval
|
||||
isConst := v0.IsValid() && isConstantValue(v0.Type())
|
||||
t := n.typ.rtype
|
||||
v := n.child[0].rval
|
||||
if isConst {
|
||||
t = constVal
|
||||
}
|
||||
n.rval = reflect.New(t).Elem()
|
||||
switch t.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
n.rval.SetInt(+v.Int())
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
n.rval.SetUint(+v.Uint())
|
||||
case reflect.Float32, reflect.Float64:
|
||||
n.rval.SetFloat(+v.Float())
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
n.rval.SetComplex(+v.Complex())
|
||||
switch {
|
||||
case isConst:
|
||||
v := constant.UnaryOp(token.ADD, vConstantValue(v0), 0)
|
||||
n.rval.Set(reflect.ValueOf(v))
|
||||
case isInt(t):
|
||||
n.rval.SetInt(+v0.Int())
|
||||
case isUint(t):
|
||||
n.rval.SetUint(+v0.Uint())
|
||||
case isFloat(t):
|
||||
n.rval.SetFloat(+v0.Float())
|
||||
case isComplex(t):
|
||||
n.rval.SetComplex(+v0.Complex())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
436
interp/run.go
436
interp/run.go
@@ -4,6 +4,7 @@ package interp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"log"
|
||||
"reflect"
|
||||
)
|
||||
@@ -26,6 +27,7 @@ var builtin = [...]bltnGenerator{
|
||||
aAndNotAssign: andNotAssign,
|
||||
aBitNot: bitNot,
|
||||
aCall: call,
|
||||
aCallSlice: call,
|
||||
aCase: _case,
|
||||
aCompositeLit: arrayLit,
|
||||
aDec: dec,
|
||||
@@ -121,33 +123,38 @@ func runCfg(n *node, f *frame) {
|
||||
}
|
||||
|
||||
func typeAssertStatus(n *node) {
|
||||
c0, c1 := n.child[0], n.child[1]
|
||||
c0, c1 := n.child[0], n.child[1] // cO contains the input value, c1 the type to assert
|
||||
value := genValue(c0) // input value
|
||||
value1 := genValue(n.anc.child[1]) // returned status
|
||||
typ := c1.typ.rtype // type to assert
|
||||
rtype := c1.typ.rtype // type to assert
|
||||
next := getExec(n.tnext)
|
||||
|
||||
switch {
|
||||
case isInterfaceSrc(c1.typ):
|
||||
typ := c1.typ
|
||||
n.exec = func(f *frame) bltn {
|
||||
v, ok := value(f).Interface().(valueInterface)
|
||||
value1(f).SetBool(ok && v.node.typ.implements(typ))
|
||||
return next
|
||||
}
|
||||
case isInterface(c1.typ):
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f)
|
||||
ok := v.IsValid() && canAssertTypes(v.Elem().Type(), rtype)
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
case c0.typ.cat == valueT:
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f)
|
||||
if !v.IsValid() || v.IsNil() {
|
||||
value1(f).SetBool(false)
|
||||
}
|
||||
value1(f).SetBool(v.Type().Implements(typ))
|
||||
return next
|
||||
}
|
||||
case c1.typ.cat == interfaceT:
|
||||
n.exec = func(f *frame) bltn {
|
||||
_, ok := value(f).Interface().(valueInterface)
|
||||
// TODO: verify that value(f) implements asserted type.
|
||||
ok := v.IsValid() && canAssertTypes(v.Elem().Type(), rtype)
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
default:
|
||||
n.exec = func(f *frame) bltn {
|
||||
_, ok := value(f).Interface().(valueInterface)
|
||||
// TODO: verify that value(f) implements asserted type.
|
||||
v, ok := value(f).Interface().(valueInterface)
|
||||
ok = ok && v.value.IsValid() && canAssertTypes(v.value.Type(), rtype)
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
@@ -157,67 +164,147 @@ func typeAssertStatus(n *node) {
|
||||
func typeAssert(n *node) {
|
||||
c0, c1 := n.child[0], n.child[1]
|
||||
value := genValue(c0) // input value
|
||||
dest := genValue(n) // returned result
|
||||
value0 := genValue(n) // returned result
|
||||
next := getExec(n.tnext)
|
||||
|
||||
switch {
|
||||
case c0.typ.cat == valueT:
|
||||
case isInterfaceSrc(c1.typ):
|
||||
typ := n.child[1].typ
|
||||
typID := n.child[1].typ.id()
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f)
|
||||
dest(f).Set(v.Elem())
|
||||
vi, ok := v.Interface().(valueInterface)
|
||||
if !ok {
|
||||
panic(n.cfgErrorf("interface conversion: nil is not %v", typID))
|
||||
}
|
||||
if !vi.node.typ.implements(typ) {
|
||||
panic(n.cfgErrorf("interface conversion: %v is not %v", vi.node.typ.id(), typID))
|
||||
}
|
||||
value0(f).Set(v)
|
||||
return next
|
||||
}
|
||||
case c1.typ.cat == interfaceT:
|
||||
case isInterface(c1.typ):
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f).Interface().(valueInterface)
|
||||
// TODO: verify that value(f) implements asserted type.
|
||||
dest(f).Set(reflect.ValueOf(valueInterface{v.node, v.value}))
|
||||
v := value(f).Elem()
|
||||
typ := value0(f).Type()
|
||||
if !v.IsValid() {
|
||||
panic(fmt.Sprintf("interface conversion: interface {} is nil, not %s", typ.String()))
|
||||
}
|
||||
if !canAssertTypes(v.Type(), typ) {
|
||||
method := firstMissingMethod(v.Type(), typ)
|
||||
panic(fmt.Sprintf("interface conversion: %s is not %s: missing method %s", v.Type().String(), typ.String(), method))
|
||||
}
|
||||
value0(f).Set(v)
|
||||
return next
|
||||
}
|
||||
case c0.typ.cat == valueT:
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f).Elem()
|
||||
typ := value0(f).Type()
|
||||
if !v.IsValid() {
|
||||
panic(fmt.Sprintf("interface conversion: interface {} is nil, not %s", typ.String()))
|
||||
}
|
||||
if !canAssertTypes(v.Type(), typ) {
|
||||
method := firstMissingMethod(v.Type(), typ)
|
||||
panic(fmt.Sprintf("interface conversion: %s is not %s: missing method %s", v.Type().String(), typ.String(), method))
|
||||
}
|
||||
value0(f).Set(v)
|
||||
return next
|
||||
}
|
||||
default:
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f).Interface().(valueInterface)
|
||||
// TODO: verify that value(f) implements asserted type.
|
||||
dest(f).Set(v.value)
|
||||
typ := value0(f).Type()
|
||||
if !v.value.IsValid() {
|
||||
panic(fmt.Sprintf("interface conversion: interface {} is nil, not %s", typ.String()))
|
||||
}
|
||||
if !canAssertTypes(v.value.Type(), typ) {
|
||||
panic(fmt.Sprintf("interface conversion: interface {} is %s, not %s", v.value.Type().String(), typ.String()))
|
||||
}
|
||||
value0(f).Set(v.value)
|
||||
return next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func typeAssert2(n *node) {
|
||||
value := genValue(n.child[0]) // input value
|
||||
c0, c1 := n.child[0], n.child[1]
|
||||
value := genValue(c0) // input value
|
||||
value0 := genValue(n.anc.child[0]) // returned result
|
||||
value1 := genValue(n.anc.child[1]) // returned status
|
||||
typ := c1.typ // type to assert or convert to
|
||||
typID := typ.id()
|
||||
rtype := typ.rtype // type to assert
|
||||
next := getExec(n.tnext)
|
||||
|
||||
switch {
|
||||
case n.child[0].typ.cat == valueT:
|
||||
n.exec = func(f *frame) bltn {
|
||||
if value(f).IsValid() && !value(f).IsNil() {
|
||||
value0(f).Set(value(f).Elem())
|
||||
}
|
||||
value1(f).SetBool(true)
|
||||
return next
|
||||
}
|
||||
case n.child[1].typ.cat == interfaceT:
|
||||
case isInterfaceSrc(typ):
|
||||
n.exec = func(f *frame) bltn {
|
||||
v, ok := value(f).Interface().(valueInterface)
|
||||
// TODO: verify that value(f) implements asserted type.
|
||||
value0(f).Set(reflect.ValueOf(valueInterface{v.node, v.value}))
|
||||
if ok && v.node.typ.id() == typID {
|
||||
value0(f).Set(value(f))
|
||||
} else {
|
||||
ok = false
|
||||
}
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
case isInterface(typ):
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f).Elem()
|
||||
ok := v.IsValid() && canAssertTypes(v.Type(), rtype)
|
||||
if ok {
|
||||
value0(f).Set(v)
|
||||
}
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
case n.child[0].typ.cat == valueT:
|
||||
n.exec = func(f *frame) bltn {
|
||||
v := value(f).Elem()
|
||||
ok := v.IsValid() && canAssertTypes(v.Type(), rtype)
|
||||
if ok {
|
||||
value0(f).Set(v)
|
||||
}
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
default:
|
||||
n.exec = func(f *frame) bltn {
|
||||
v, ok := value(f).Interface().(valueInterface)
|
||||
// TODO: verify that value(f) implements asserted type.
|
||||
value0(f).Set(v.value)
|
||||
ok = ok && v.value.IsValid() && canAssertTypes(v.value.Type(), rtype)
|
||||
if ok {
|
||||
value0(f).Set(v.value)
|
||||
}
|
||||
value1(f).SetBool(ok)
|
||||
return next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func canAssertTypes(src, dest reflect.Type) bool {
|
||||
if src == dest {
|
||||
return true
|
||||
}
|
||||
if dest.Kind() == reflect.Interface && src.Implements(dest) {
|
||||
return true
|
||||
}
|
||||
if src.AssignableTo(dest) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func firstMissingMethod(src, dest reflect.Type) string {
|
||||
for i := 0; i < dest.NumMethod(); i++ {
|
||||
m := dest.Method(i).Name
|
||||
if _, ok := src.MethodByName(m); !ok {
|
||||
return m
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func convert(n *node) {
|
||||
dest := genValue(n)
|
||||
c := n.child[1]
|
||||
@@ -225,6 +312,9 @@ func convert(n *node) {
|
||||
next := getExec(n.tnext)
|
||||
|
||||
if c.isNil() { // convert nil to type
|
||||
if n.child[0].typ.cat == interfaceT {
|
||||
typ = reflect.TypeOf((*valueInterface)(nil)).Elem()
|
||||
}
|
||||
n.exec = func(f *frame) bltn {
|
||||
dest(f).Set(reflect.New(typ).Elem())
|
||||
return next
|
||||
@@ -459,12 +549,10 @@ func _println(n *node) {
|
||||
func _recover(n *node) {
|
||||
tnext := getExec(n.tnext)
|
||||
dest := genValue(n)
|
||||
var err error
|
||||
nilErr := reflect.ValueOf(valueInterface{n, reflect.ValueOf(&err).Elem()})
|
||||
|
||||
n.exec = func(f *frame) bltn {
|
||||
if f.anc.recovered == nil {
|
||||
dest(f).Set(nilErr)
|
||||
dest(f).Set(reflect.ValueOf(valueInterface{}))
|
||||
} else {
|
||||
dest(f).Set(reflect.ValueOf(valueInterface{n, reflect.ValueOf(f.anc.recovered)}))
|
||||
f.anc.recovered = nil
|
||||
@@ -621,7 +709,11 @@ func call(n *node) {
|
||||
var values []func(*frame) reflect.Value
|
||||
if n.child[0].recv != nil {
|
||||
// Compute method receiver value.
|
||||
values = append(values, genValueRecv(n.child[0]))
|
||||
if isRecursiveStruct(n.child[0].recv.node.typ, n.child[0].recv.node.typ.rtype) {
|
||||
values = append(values, genValueRecvInterfacePtr(n.child[0]))
|
||||
} else {
|
||||
values = append(values, genValueRecv(n.child[0]))
|
||||
}
|
||||
method = true
|
||||
} else if n.child[0].action == aMethod {
|
||||
// Add a place holder for interface method receiver.
|
||||
@@ -660,9 +752,12 @@ func call(n *node) {
|
||||
}
|
||||
convertLiteralValue(c, argType)
|
||||
}
|
||||
if len(n.child[0].typ.arg) > i && n.child[0].typ.arg[i].cat == interfaceT {
|
||||
switch {
|
||||
case len(n.child[0].typ.arg) > i && n.child[0].typ.arg[i].cat == interfaceT:
|
||||
values = append(values, genValueInterface(c))
|
||||
} else {
|
||||
case isRecursiveStruct(c.typ, c.typ.rtype):
|
||||
values = append(values, genValueDerefInterfacePtr(c))
|
||||
default:
|
||||
values = append(values, genValue(c))
|
||||
}
|
||||
}
|
||||
@@ -827,7 +922,10 @@ func call(n *node) {
|
||||
vararg.Set(reflect.Append(vararg, v(f)))
|
||||
}
|
||||
default:
|
||||
dest[i].Set(v(f))
|
||||
val := v(f)
|
||||
if !val.IsZero() {
|
||||
dest[i].Set(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -875,6 +973,12 @@ func callBin(n *node) {
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if we should use `Call` or `CallSlice` on the function Value.
|
||||
callFn := func(v reflect.Value, in []reflect.Value) []reflect.Value { return v.Call(in) }
|
||||
if n.action == aCallSlice {
|
||||
callFn = func(v reflect.Value, in []reflect.Value) []reflect.Value { return v.CallSlice(in) }
|
||||
}
|
||||
|
||||
for i, c := range child {
|
||||
defType := funcType.In(pindex(i, variadic))
|
||||
switch {
|
||||
@@ -910,6 +1014,13 @@ func callBin(n *node) {
|
||||
values = append(values, genFunctionWrapper(c))
|
||||
case interfaceT:
|
||||
values = append(values, genValueInterfaceValue(c))
|
||||
case arrayT:
|
||||
switch c.typ.val.cat {
|
||||
case interfaceT:
|
||||
values = append(values, genValueInterfaceArray(c))
|
||||
default:
|
||||
values = append(values, genInterfaceWrapper(c, defType))
|
||||
}
|
||||
default:
|
||||
values = append(values, genInterfaceWrapper(c, defType))
|
||||
}
|
||||
@@ -936,7 +1047,7 @@ func callBin(n *node) {
|
||||
for i, v := range values {
|
||||
in[i] = v(f)
|
||||
}
|
||||
go value(f).Call(in)
|
||||
go callFn(value(f), in)
|
||||
return tnext
|
||||
}
|
||||
case fnext != nil:
|
||||
@@ -947,7 +1058,7 @@ func callBin(n *node) {
|
||||
for i, v := range values {
|
||||
in[i] = v(f)
|
||||
}
|
||||
res := value(f).Call(in)
|
||||
res := callFn(value(f), in)
|
||||
b := res[0].Bool()
|
||||
f.data[index].SetBool(b)
|
||||
if b {
|
||||
@@ -972,7 +1083,7 @@ func callBin(n *node) {
|
||||
for i, v := range values {
|
||||
in[i] = v(f)
|
||||
}
|
||||
out := value(f).Call(in)
|
||||
out := callFn(value(f), in)
|
||||
for i, v := range rvalues {
|
||||
if v != nil {
|
||||
v(f).Set(out[i])
|
||||
@@ -989,7 +1100,7 @@ func callBin(n *node) {
|
||||
for i, v := range values {
|
||||
in[i] = v(f)
|
||||
}
|
||||
out := value(f).Call(in)
|
||||
out := callFn(value(f), in)
|
||||
for i, v := range out {
|
||||
f.data[b+i].Set(v)
|
||||
}
|
||||
@@ -1001,7 +1112,7 @@ func callBin(n *node) {
|
||||
for i, v := range values {
|
||||
in[i] = v(f)
|
||||
}
|
||||
out := value(f).Call(in)
|
||||
out := callFn(value(f), in)
|
||||
copy(f.data[n.findex:], out)
|
||||
return tnext
|
||||
}
|
||||
@@ -1010,7 +1121,7 @@ func callBin(n *node) {
|
||||
}
|
||||
|
||||
func getIndexBinMethod(n *node) {
|
||||
//dest := genValue(n)
|
||||
// dest := genValue(n)
|
||||
i := n.findex
|
||||
m := n.val.(int)
|
||||
value := genValue(n.child[0])
|
||||
@@ -1018,7 +1129,7 @@ func getIndexBinMethod(n *node) {
|
||||
|
||||
n.exec = func(f *frame) bltn {
|
||||
// Can not use .Set() because dest type contains the receiver and source not
|
||||
//dest(f).Set(value(f).Method(m))
|
||||
// dest(f).Set(value(f).Method(m))
|
||||
f.data[i] = value(f).Method(m)
|
||||
return next
|
||||
}
|
||||
@@ -1094,6 +1205,7 @@ func getIndexMap(n *node) {
|
||||
z := reflect.New(n.child[0].typ.frameType().Elem()).Elem()
|
||||
|
||||
if n.child[1].rval.IsValid() { // constant map index
|
||||
convertConstantValue(n.child[1])
|
||||
mi := n.child[1].rval
|
||||
|
||||
switch {
|
||||
@@ -1187,6 +1299,7 @@ func getIndexMap2(n *node) {
|
||||
return
|
||||
}
|
||||
if n.child[1].rval.IsValid() { // constant map index
|
||||
convertConstantValue(n.child[1])
|
||||
mi := n.child[1].rval
|
||||
switch {
|
||||
case !doValue:
|
||||
@@ -1595,6 +1708,12 @@ func _return(n *node) {
|
||||
values[i] = genValue(c)
|
||||
case interfaceT:
|
||||
values[i] = genValueInterface(c)
|
||||
case valueT:
|
||||
if t.rtype.Kind() == reflect.Interface {
|
||||
values[i] = genInterfaceWrapper(c, t.rtype)
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
if c.typ.untyped {
|
||||
values[i] = genValueAs(c, def.typ.ret[i].TypeOf())
|
||||
@@ -1608,7 +1727,7 @@ func _return(n *node) {
|
||||
case 0:
|
||||
n.exec = nil
|
||||
case 1:
|
||||
if child[0].kind == binaryExpr || child[0].action == aCall {
|
||||
if child[0].kind == binaryExpr || isCall(child[0]) {
|
||||
n.exec = nil
|
||||
} else {
|
||||
v := values[0]
|
||||
@@ -1854,9 +1973,12 @@ func doCompositeSparse(n *node, hasType bool) {
|
||||
c1 := c.child[1]
|
||||
field := n.typ.fieldIndex(c.child[0].ident)
|
||||
convertLiteralValue(c1, n.typ.field[field].typ.TypeOf())
|
||||
if c1.typ.cat == funcT {
|
||||
switch {
|
||||
case c1.typ.cat == funcT:
|
||||
values[field] = genFunctionWrapper(c1)
|
||||
} else {
|
||||
case isRecursiveStruct(n.typ.field[field].typ, n.typ.field[field].typ.rtype):
|
||||
values[field] = genValueInterfacePtr(c1)
|
||||
default:
|
||||
values[field] = genValue(c1)
|
||||
}
|
||||
}
|
||||
@@ -2513,6 +2635,11 @@ func convertLiteralValue(n *node, t reflect.Type) {
|
||||
// Skip non-constant values, undefined target type or interface target type.
|
||||
case n.rval.IsValid():
|
||||
// Convert constant value to target type.
|
||||
if n.typ != nil && n.typ.cat != valueT {
|
||||
convertConstantValue(n)
|
||||
} else {
|
||||
convertConstantValueTo(n, t)
|
||||
}
|
||||
n.rval = n.rval.Convert(t)
|
||||
default:
|
||||
// Create a zero value of target type.
|
||||
@@ -2520,6 +2647,199 @@ func convertLiteralValue(n *node, t reflect.Type) {
|
||||
}
|
||||
}
|
||||
|
||||
func convertConstantValue(n *node) {
|
||||
if !n.rval.IsValid() {
|
||||
return
|
||||
}
|
||||
c, ok := n.rval.Interface().(constant.Value)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
t := n.typ
|
||||
for t != nil && t.cat == aliasT {
|
||||
// If it is an alias, get the actual type
|
||||
t = t.val
|
||||
}
|
||||
|
||||
v := n.rval
|
||||
switch t.cat {
|
||||
case intT, int8T, int16T, int32T, int64T:
|
||||
i, _ := constant.Int64Val(c)
|
||||
l := constant.BitLen(c)
|
||||
switch t.cat {
|
||||
case intT:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows int", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int(i))
|
||||
case int8T:
|
||||
if l > 8 {
|
||||
panic(fmt.Sprintf("constant %s overflows int8", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int8(i))
|
||||
case int16T:
|
||||
if l > 16 {
|
||||
panic(fmt.Sprintf("constant %s overflows int16", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int16(i))
|
||||
case int32T:
|
||||
if l > 32 {
|
||||
panic(fmt.Sprintf("constant %s overflows int32", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int32(i))
|
||||
case int64T:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows int64", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(i)
|
||||
}
|
||||
case uintT, uint8T, uint16T, uint32T, uint64T:
|
||||
i, _ := constant.Uint64Val(c)
|
||||
l := constant.BitLen(c)
|
||||
switch t.cat {
|
||||
case uintT:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint(i))
|
||||
case uint8T:
|
||||
if l > 8 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint8", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint8(i))
|
||||
case uint16T:
|
||||
if l > 16 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint16", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint16(i))
|
||||
case uint32T:
|
||||
if l > 32 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint32", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint32(i))
|
||||
case uint64T:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint64", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(i)
|
||||
case uintptrT:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows uintptr", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(i)
|
||||
}
|
||||
case float32T:
|
||||
f, _ := constant.Float32Val(c)
|
||||
v = reflect.ValueOf(f)
|
||||
case float64T:
|
||||
f, _ := constant.Float64Val(c)
|
||||
v = reflect.ValueOf(f)
|
||||
case complex64T:
|
||||
r, _ := constant.Float32Val(constant.Real(c))
|
||||
i, _ := constant.Float32Val(constant.Imag(c))
|
||||
v = reflect.ValueOf(complex(r, i))
|
||||
case complex128T:
|
||||
r, _ := constant.Float64Val(constant.Real(c))
|
||||
i, _ := constant.Float64Val(constant.Imag(c))
|
||||
v = reflect.ValueOf(complex(r, i))
|
||||
}
|
||||
n.rval = v
|
||||
}
|
||||
|
||||
func convertConstantValueTo(n *node, typ reflect.Type) {
|
||||
if !n.rval.IsValid() {
|
||||
return
|
||||
}
|
||||
c, ok := n.rval.Interface().(constant.Value)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
v := n.rval
|
||||
switch typ.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
i, _ := constant.Int64Val(c)
|
||||
l := constant.BitLen(c)
|
||||
switch typ.Kind() {
|
||||
case reflect.Int:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows int", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int(i))
|
||||
case reflect.Int8:
|
||||
if l > 8 {
|
||||
panic(fmt.Sprintf("constant %s overflows int8", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int8(i))
|
||||
case reflect.Int16:
|
||||
if l > 16 {
|
||||
panic(fmt.Sprintf("constant %s overflows int16", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int16(i))
|
||||
case reflect.Int32:
|
||||
if l > 32 {
|
||||
panic(fmt.Sprintf("constant %s overflows int32", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(int32(i))
|
||||
case reflect.Int64:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows int64", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(i)
|
||||
}
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
i, _ := constant.Uint64Val(c)
|
||||
l := constant.BitLen(c)
|
||||
switch typ.Kind() {
|
||||
case reflect.Uint:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint(i))
|
||||
case reflect.Uint8:
|
||||
if l > 8 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint8", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint8(i))
|
||||
case reflect.Uint16:
|
||||
if l > 16 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint16", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint16(i))
|
||||
case reflect.Uint32:
|
||||
if l > 32 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint32", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(uint32(i))
|
||||
case reflect.Uint64:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows uint64", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(i)
|
||||
case reflect.Uintptr:
|
||||
if l > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows uintptr", c.ExactString()))
|
||||
}
|
||||
v = reflect.ValueOf(i)
|
||||
}
|
||||
case reflect.Float32:
|
||||
f, _ := constant.Float32Val(c)
|
||||
v = reflect.ValueOf(f)
|
||||
case reflect.Float64:
|
||||
f, _ := constant.Float64Val(c)
|
||||
v = reflect.ValueOf(f)
|
||||
case reflect.Complex64:
|
||||
r, _ := constant.Float32Val(constant.Real(c))
|
||||
i, _ := constant.Float32Val(constant.Imag(c))
|
||||
v = reflect.ValueOf(complex(r, i))
|
||||
case reflect.Complex128:
|
||||
r, _ := constant.Float64Val(constant.Real(c))
|
||||
i, _ := constant.Float64Val(constant.Imag(c))
|
||||
v = reflect.ValueOf(complex(r, i))
|
||||
}
|
||||
n.rval = v
|
||||
}
|
||||
|
||||
// Write to a channel
|
||||
func send(n *node) {
|
||||
next := getExec(n.tnext)
|
||||
@@ -2734,7 +3054,9 @@ func isNil(n *node) {
|
||||
fnext := getExec(n.fnext)
|
||||
if c0.typ.cat == interfaceT {
|
||||
n.exec = func(f *frame) bltn {
|
||||
if (value(f).Interface().(valueInterface) == valueInterface{}) {
|
||||
vi := value(f).Interface().(valueInterface)
|
||||
if (vi == valueInterface{} ||
|
||||
vi.node.kind == basicLit && vi.node.typ.cat == nilT) {
|
||||
dest(f).SetBool(true)
|
||||
return tnext
|
||||
}
|
||||
@@ -2781,7 +3103,9 @@ func isNotNil(n *node) {
|
||||
fnext := getExec(n.fnext)
|
||||
if c0.typ.cat == interfaceT {
|
||||
n.exec = func(f *frame) bltn {
|
||||
if (value(f).Interface().(valueInterface) == valueInterface{}) {
|
||||
vi := value(f).Interface().(valueInterface)
|
||||
if (vi == valueInterface{} ||
|
||||
vi.node.kind == basicLit && vi.node.typ.cat == nilT) {
|
||||
dest(f).SetBool(false)
|
||||
return fnext
|
||||
}
|
||||
|
||||
@@ -135,6 +135,18 @@ func (s *scope) rangeChanType(n *node) *itype {
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
||||
c := n.child[1]
|
||||
if c.typ == nil {
|
||||
return nil
|
||||
}
|
||||
switch {
|
||||
case c.typ.cat == chanT:
|
||||
return c.typ
|
||||
case c.typ.cat == valueT && c.typ.rtype.Kind() == reflect.Chan:
|
||||
return &itype{cat: chanT, val: &itype{cat: valueT, rtype: c.typ.rtype.Elem()}}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
func (interp *Interpreter) importSrc(rPath, path string) (string, error) {
|
||||
var dir string
|
||||
var err error
|
||||
|
||||
if interp.srcPkg[path] != nil {
|
||||
return nil
|
||||
return interp.pkgNames[path], nil
|
||||
}
|
||||
|
||||
// For relative import paths in the form "./xxx" or "../xxx", the initial
|
||||
@@ -27,17 +27,17 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
}
|
||||
dir = filepath.Join(filepath.Dir(interp.Name), rPath, path)
|
||||
} else if dir, rPath, err = pkgDir(interp.context.GOPATH, rPath, path); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
if interp.rdir[path] {
|
||||
return fmt.Errorf("import cycle not allowed\n\timports %s", path)
|
||||
return "", fmt.Errorf("import cycle not allowed\n\timports %s", path)
|
||||
}
|
||||
interp.rdir[path] = true
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var initNodes []*node
|
||||
@@ -57,23 +57,28 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
name = filepath.Join(dir, name)
|
||||
var buf []byte
|
||||
if buf, err = ioutil.ReadFile(name); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var pname string
|
||||
if pname, root, err = interp.ast(string(buf), name); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
if root == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if interp.astDot {
|
||||
root.astDot(dotX(), name)
|
||||
dotCmd := interp.dotCmd
|
||||
if dotCmd == "" {
|
||||
dotCmd = defaultDotCmd(name, "yaegi-ast-")
|
||||
}
|
||||
root.astDot(dotWriter(dotCmd), name)
|
||||
}
|
||||
if pkgName == "" {
|
||||
pkgName = pname
|
||||
} else if pkgName != pname {
|
||||
return fmt.Errorf("found packages %s and %s in %s", pkgName, pname, dir)
|
||||
return "", fmt.Errorf("found packages %s and %s in %s", pkgName, pname, dir)
|
||||
}
|
||||
rootNodes = append(rootNodes, root)
|
||||
|
||||
@@ -81,7 +86,7 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
var list []*node
|
||||
list, err = interp.gta(root, subRPath, path)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
revisit[subRPath] = append(revisit[subRPath], list...)
|
||||
}
|
||||
@@ -89,7 +94,7 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
// Revisit incomplete nodes where GTA could not complete.
|
||||
for pkg, nodes := range revisit {
|
||||
if err = interp.gtaRetry(nodes, pkg, path); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +102,7 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
for _, root := range rootNodes {
|
||||
var nodes []*node
|
||||
if nodes, err = interp.cfg(root, path); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
initNodes = append(initNodes, nodes...)
|
||||
}
|
||||
@@ -106,6 +111,7 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
// the global symbols in the package scope.
|
||||
interp.mutex.Lock()
|
||||
interp.srcPkg[path] = interp.scopes[path].sym
|
||||
interp.pkgNames[path] = pkgName
|
||||
|
||||
interp.frame.mutex.Lock()
|
||||
interp.resizeFrame()
|
||||
@@ -115,7 +121,7 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
// Once all package sources have been parsed, execute entry points then init functions
|
||||
for _, n := range rootNodes {
|
||||
if err = genRun(n); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
interp.run(n, nil)
|
||||
}
|
||||
@@ -129,7 +135,7 @@ func (interp *Interpreter) importSrc(rPath, path string) error {
|
||||
interp.run(n, interp.frame)
|
||||
}
|
||||
|
||||
return nil
|
||||
return pkgName, nil
|
||||
}
|
||||
|
||||
// pkgDir returns the absolute path in filesystem for a package given its name and
|
||||
@@ -185,7 +191,8 @@ func effectivePkg(root, path string) string {
|
||||
for i := 0; i < len(splitPath); i++ {
|
||||
part := splitPath[len(splitPath)-1-i]
|
||||
|
||||
if part == splitRoot[len(splitRoot)-1-rootIndex] && i != 0 {
|
||||
index := len(splitRoot) - 1 - rootIndex
|
||||
if index > 0 && part == splitRoot[index] && i != 0 {
|
||||
prevRootIndex = rootIndex
|
||||
rootIndex++
|
||||
} else if prevRootIndex == rootIndex {
|
||||
|
||||
@@ -26,6 +26,12 @@ func Test_effectivePkg(t *testing.T) {
|
||||
path: "vendor/guthib.com/containous/vin",
|
||||
expected: "github.com/foo/plugin/vendor/guthib.com/containous/fromage/vendor/guthib.com/containous/vin",
|
||||
},
|
||||
{
|
||||
desc: "path is non-existent",
|
||||
root: "foo",
|
||||
path: "githib.com/foo/app",
|
||||
expected: "foo/githib.com/foo/app",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package interp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
@@ -152,10 +154,16 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
|
||||
case arrayType:
|
||||
t.cat = arrayT
|
||||
if len(n.child) > 1 {
|
||||
v := n.child[0].rval
|
||||
switch {
|
||||
case n.child[0].rval.IsValid():
|
||||
case v.IsValid():
|
||||
// constant size
|
||||
t.size = int(n.child[0].rval.Int())
|
||||
if isConstantValue(v.Type()) {
|
||||
c := v.Interface().(constant.Value)
|
||||
t.size = constToInt(c)
|
||||
} else {
|
||||
t.size = int(v.Int())
|
||||
}
|
||||
case n.child[0].kind == ellipsisExpr:
|
||||
// [...]T expression
|
||||
t.size = arrayTypeLen(n.anc)
|
||||
@@ -165,6 +173,8 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
|
||||
if sym.typ != nil && sym.typ.cat == intT {
|
||||
if v, ok := sym.rval.Interface().(int); ok {
|
||||
t.size = v
|
||||
} else if c, ok := sym.rval.Interface().(constant.Value); ok {
|
||||
t.size = constToInt(c)
|
||||
} else {
|
||||
t.incomplete = true
|
||||
}
|
||||
@@ -231,6 +241,23 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
|
||||
t.cat = stringT
|
||||
t.name = "string"
|
||||
t.untyped = true
|
||||
case constant.Value:
|
||||
switch v.Kind() {
|
||||
case constant.Int:
|
||||
t.cat = intT
|
||||
t.name = "int"
|
||||
t.untyped = true
|
||||
case constant.Float:
|
||||
t.cat = float64T
|
||||
t.name = "float64"
|
||||
t.untyped = true
|
||||
case constant.Complex:
|
||||
t.cat = complex128T
|
||||
t.name = "complex128"
|
||||
t.untyped = true
|
||||
default:
|
||||
err = n.cfgErrorf("missing support for type %v", n.rval)
|
||||
}
|
||||
default:
|
||||
err = n.cfgErrorf("missing support for type %T: %v", v, n.rval)
|
||||
}
|
||||
@@ -706,10 +733,15 @@ func (t *itype) referTo(name string, seen map[*itype]bool) bool {
|
||||
}
|
||||
|
||||
func (t *itype) numOut() int {
|
||||
if t.cat == valueT {
|
||||
return t.rtype.NumOut()
|
||||
switch t.cat {
|
||||
case funcT:
|
||||
return len(t.ret)
|
||||
case valueT:
|
||||
if t.rtype.Kind() == reflect.Func {
|
||||
return t.rtype.NumOut()
|
||||
}
|
||||
}
|
||||
return len(t.ret)
|
||||
return 1
|
||||
}
|
||||
|
||||
func (t *itype) concrete() *itype {
|
||||
@@ -813,7 +845,7 @@ func (t *itype) methods() methodSet {
|
||||
res := make(methodSet)
|
||||
switch t.cat {
|
||||
case interfaceT:
|
||||
// Get methods from recursive analysis of interface fields
|
||||
// Get methods from recursive analysis of interface fields.
|
||||
for _, f := range t.field {
|
||||
if f.typ.cat == funcT {
|
||||
res[f.name] = f.typ.TypeOf().String()
|
||||
@@ -824,22 +856,25 @@ func (t *itype) methods() methodSet {
|
||||
}
|
||||
}
|
||||
case valueT, errorT:
|
||||
// Get method from corresponding reflect.Type
|
||||
// Get method from corresponding reflect.Type.
|
||||
for i := t.rtype.NumMethod() - 1; i >= 0; i-- {
|
||||
m := t.rtype.Method(i)
|
||||
res[m.Name] = m.Type.String()
|
||||
}
|
||||
case ptrT:
|
||||
// Consider only methods where receiver is a pointer to type t
|
||||
for _, m := range t.val.method {
|
||||
if m.child[0].child[0].lastChild().typ.cat == ptrT {
|
||||
res[m.ident] = m.typ.TypeOf().String()
|
||||
for k, v := range t.val.methods() {
|
||||
res[k] = v
|
||||
}
|
||||
case structT:
|
||||
for _, f := range t.field {
|
||||
for k, v := range f.typ.methods() {
|
||||
res[k] = v
|
||||
}
|
||||
}
|
||||
default:
|
||||
for _, m := range t.method {
|
||||
res[m.ident] = m.typ.TypeOf().String()
|
||||
}
|
||||
}
|
||||
// Get all methods defined on this type.
|
||||
for _, m := range t.method {
|
||||
res[m.ident] = m.typ.TypeOf().String()
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1055,6 +1090,7 @@ func exportName(s string) string {
|
||||
}
|
||||
|
||||
var interf = reflect.TypeOf((*interface{})(nil)).Elem()
|
||||
var constVal = reflect.TypeOf((*constant.Value)(nil)).Elem()
|
||||
|
||||
// RefType returns a reflect.Type representation from an interpereter type.
|
||||
// In simple cases, reflect types are directly mapped from the interpreter
|
||||
@@ -1187,8 +1223,15 @@ func (t *itype) implements(it *itype) bool {
|
||||
if t.cat == valueT {
|
||||
return t.TypeOf().Implements(it.TypeOf())
|
||||
}
|
||||
// TODO: implement method check for interpreted types
|
||||
return true
|
||||
return t.methods().contains(it.methods())
|
||||
}
|
||||
|
||||
func constToInt(c constant.Value) int {
|
||||
if constant.BitLen(c) > 64 {
|
||||
panic(fmt.Sprintf("constant %s overflows int64", c.ExactString()))
|
||||
}
|
||||
i, _ := constant.Int64Val(c)
|
||||
return int(i)
|
||||
}
|
||||
|
||||
func defRecvType(n *node) *itype {
|
||||
@@ -1304,5 +1347,8 @@ func isByteArray(t reflect.Type) bool {
|
||||
|
||||
func isFloat32(t reflect.Type) bool { return t != nil && t.Kind() == reflect.Float32 }
|
||||
func isFloat64(t reflect.Type) bool { return t != nil && t.Kind() == reflect.Float64 }
|
||||
func isNumber(t reflect.Type) bool { return isInt(t) || isFloat(t) || isComplex(t) }
|
||||
func isString(t reflect.Type) bool { return t != nil && t.Kind() == reflect.String }
|
||||
func isNumber(t reflect.Type) bool {
|
||||
return isInt(t) || isFloat(t) || isComplex(t) || isConstantValue(t)
|
||||
}
|
||||
func isString(t reflect.Type) bool { return t != nil && t.Kind() == reflect.String }
|
||||
func isConstantValue(t reflect.Type) bool { return t != nil && t.Implements(constVal) }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package interp
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -54,6 +55,25 @@ func genValueRecv(n *node) func(*frame) reflect.Value {
|
||||
}
|
||||
}
|
||||
|
||||
func genValueRecvInterfacePtr(n *node) func(*frame) reflect.Value {
|
||||
v := genValue(n.recv.node)
|
||||
fi := n.recv.index
|
||||
|
||||
return func(f *frame) reflect.Value {
|
||||
r := v(f)
|
||||
r = r.Elem().Elem()
|
||||
|
||||
if len(fi) == 0 {
|
||||
return r
|
||||
}
|
||||
|
||||
if r.Kind() == reflect.Ptr {
|
||||
r = r.Elem()
|
||||
}
|
||||
return r.FieldByIndex(fi)
|
||||
}
|
||||
}
|
||||
|
||||
func genValueAsFunctionWrapper(n *node) func(*frame) reflect.Value {
|
||||
value := genValue(n)
|
||||
typ := n.typ.TypeOf()
|
||||
@@ -77,6 +97,7 @@ func genValueAs(n *node, t reflect.Type) func(*frame) reflect.Value {
|
||||
func genValue(n *node) func(*frame) reflect.Value {
|
||||
switch n.kind {
|
||||
case basicLit:
|
||||
convertConstantValue(n)
|
||||
v := n.rval
|
||||
if !v.IsValid() {
|
||||
v = reflect.New(interf).Elem()
|
||||
@@ -92,6 +113,7 @@ func genValue(n *node) func(*frame) reflect.Value {
|
||||
return func(f *frame) reflect.Value { return v }
|
||||
default:
|
||||
if n.rval.IsValid() {
|
||||
convertConstantValue(n)
|
||||
v := n.rval
|
||||
return func(f *frame) reflect.Value { return v }
|
||||
}
|
||||
@@ -147,6 +169,19 @@ func genValueRangeArray(n *node) func(*frame) reflect.Value {
|
||||
}
|
||||
}
|
||||
|
||||
func genValueInterfaceArray(n *node) func(*frame) reflect.Value {
|
||||
value := genValue(n)
|
||||
return func(f *frame) reflect.Value {
|
||||
vi := value(f).Interface().([]valueInterface)
|
||||
v := reflect.MakeSlice(reflect.TypeOf([]interface{}{}), len(vi), len(vi))
|
||||
for i, vv := range vi {
|
||||
v.Index(i).Set(vv.value)
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
func genValueInterfacePtr(n *node) func(*frame) reflect.Value {
|
||||
value := genValue(n)
|
||||
|
||||
@@ -176,6 +211,18 @@ func genValueInterface(n *node) func(*frame) reflect.Value {
|
||||
}
|
||||
}
|
||||
|
||||
func genValueDerefInterfacePtr(n *node) func(*frame) reflect.Value {
|
||||
value := genValue(n)
|
||||
|
||||
return func(f *frame) reflect.Value {
|
||||
v := value(f)
|
||||
if v.IsZero() {
|
||||
return v
|
||||
}
|
||||
return v.Elem().Elem()
|
||||
}
|
||||
}
|
||||
|
||||
func zeroInterfaceValue() reflect.Value {
|
||||
n := &node{kind: basicLit, typ: &itype{cat: nilT, untyped: true}}
|
||||
v := reflect.New(interf).Elem()
|
||||
@@ -233,6 +280,10 @@ func vInt(v reflect.Value) (i int64) {
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
i = int64(real(v.Complex()))
|
||||
}
|
||||
if v.Type().Implements(constVal) {
|
||||
c := v.Interface().(constant.Value)
|
||||
i, _ = constant.Int64Val(constant.ToInt(c))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -247,6 +298,11 @@ func vUint(v reflect.Value) (i uint64) {
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
i = uint64(real(v.Complex()))
|
||||
}
|
||||
if v.Type().Implements(constVal) {
|
||||
c := v.Interface().(constant.Value)
|
||||
iv, _ := constant.Int64Val(constant.ToInt(c))
|
||||
i = uint64(iv)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,6 +317,13 @@ func vComplex(v reflect.Value) (c complex128) {
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
c = v.Complex()
|
||||
}
|
||||
if v.Type().Implements(constVal) {
|
||||
con := v.Interface().(constant.Value)
|
||||
con = constant.ToComplex(con)
|
||||
rel, _ := constant.Float64Val(constant.Real(con))
|
||||
img, _ := constant.Float64Val(constant.Imag(con))
|
||||
c = complex(rel, img)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -275,6 +338,17 @@ func vFloat(v reflect.Value) (i float64) {
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
i = real(v.Complex())
|
||||
}
|
||||
if v.Type().Implements(constVal) {
|
||||
c := v.Interface().(constant.Value)
|
||||
i, _ = constant.Float64Val(constant.ToFloat(c))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func vConstantValue(v reflect.Value) (c constant.Value) {
|
||||
if v.Type().Implements(constVal) {
|
||||
c = v.Interface().(constant.Value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -23,20 +25,20 @@ func init() {
|
||||
"FormatUnknown": reflect.ValueOf(tar.FormatUnknown),
|
||||
"NewReader": reflect.ValueOf(tar.NewReader),
|
||||
"NewWriter": reflect.ValueOf(tar.NewWriter),
|
||||
"TypeBlock": reflect.ValueOf(tar.TypeBlock),
|
||||
"TypeChar": reflect.ValueOf(tar.TypeChar),
|
||||
"TypeCont": reflect.ValueOf(tar.TypeCont),
|
||||
"TypeDir": reflect.ValueOf(tar.TypeDir),
|
||||
"TypeFifo": reflect.ValueOf(tar.TypeFifo),
|
||||
"TypeGNULongLink": reflect.ValueOf(tar.TypeGNULongLink),
|
||||
"TypeGNULongName": reflect.ValueOf(tar.TypeGNULongName),
|
||||
"TypeGNUSparse": reflect.ValueOf(tar.TypeGNUSparse),
|
||||
"TypeLink": reflect.ValueOf(tar.TypeLink),
|
||||
"TypeReg": reflect.ValueOf(tar.TypeReg),
|
||||
"TypeRegA": reflect.ValueOf(tar.TypeRegA),
|
||||
"TypeSymlink": reflect.ValueOf(tar.TypeSymlink),
|
||||
"TypeXGlobalHeader": reflect.ValueOf(tar.TypeXGlobalHeader),
|
||||
"TypeXHeader": reflect.ValueOf(tar.TypeXHeader),
|
||||
"TypeBlock": reflect.ValueOf(constant.MakeFromLiteral("52", token.INT, 0)),
|
||||
"TypeChar": reflect.ValueOf(constant.MakeFromLiteral("51", token.INT, 0)),
|
||||
"TypeCont": reflect.ValueOf(constant.MakeFromLiteral("55", token.INT, 0)),
|
||||
"TypeDir": reflect.ValueOf(constant.MakeFromLiteral("53", token.INT, 0)),
|
||||
"TypeFifo": reflect.ValueOf(constant.MakeFromLiteral("54", token.INT, 0)),
|
||||
"TypeGNULongLink": reflect.ValueOf(constant.MakeFromLiteral("75", token.INT, 0)),
|
||||
"TypeGNULongName": reflect.ValueOf(constant.MakeFromLiteral("76", token.INT, 0)),
|
||||
"TypeGNUSparse": reflect.ValueOf(constant.MakeFromLiteral("83", token.INT, 0)),
|
||||
"TypeLink": reflect.ValueOf(constant.MakeFromLiteral("49", token.INT, 0)),
|
||||
"TypeReg": reflect.ValueOf(constant.MakeFromLiteral("48", token.INT, 0)),
|
||||
"TypeRegA": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"TypeSymlink": reflect.ValueOf(constant.MakeFromLiteral("50", token.INT, 0)),
|
||||
"TypeXGlobalHeader": reflect.ValueOf(constant.MakeFromLiteral("103", token.INT, 0)),
|
||||
"TypeXHeader": reflect.ValueOf(constant.MakeFromLiteral("120", token.INT, 0)),
|
||||
|
||||
// type definitions
|
||||
"Format": reflect.ValueOf((*tar.Format)(nil)),
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -20,7 +22,7 @@ func init() {
|
||||
"ErrNegativeAdvance": reflect.ValueOf(&bufio.ErrNegativeAdvance).Elem(),
|
||||
"ErrNegativeCount": reflect.ValueOf(&bufio.ErrNegativeCount).Elem(),
|
||||
"ErrTooLong": reflect.ValueOf(&bufio.ErrTooLong).Elem(),
|
||||
"MaxScanTokenSize": reflect.ValueOf(bufio.MaxScanTokenSize),
|
||||
"MaxScanTokenSize": reflect.ValueOf(constant.MakeFromLiteral("65536", token.INT, 0)),
|
||||
"NewReadWriter": reflect.ValueOf(bufio.NewReadWriter),
|
||||
"NewReader": reflect.ValueOf(bufio.NewReader),
|
||||
"NewReaderSize": reflect.ValueOf(bufio.NewReaderSize),
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -35,7 +37,7 @@ func init() {
|
||||
"LastIndexByte": reflect.ValueOf(bytes.LastIndexByte),
|
||||
"LastIndexFunc": reflect.ValueOf(bytes.LastIndexFunc),
|
||||
"Map": reflect.ValueOf(bytes.Map),
|
||||
"MinRead": reflect.ValueOf(bytes.MinRead),
|
||||
"MinRead": reflect.ValueOf(constant.MakeFromLiteral("512", token.INT, 0)),
|
||||
"NewBuffer": reflect.ValueOf(bytes.NewBuffer),
|
||||
"NewBufferString": reflect.ValueOf(bytes.NewBufferString),
|
||||
"NewReader": reflect.ValueOf(bytes.NewReader),
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"compress/flate"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"io"
|
||||
"reflect"
|
||||
)
|
||||
@@ -13,15 +15,15 @@ import (
|
||||
func init() {
|
||||
Symbols["compress/flate"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BestCompression": reflect.ValueOf(flate.BestCompression),
|
||||
"BestSpeed": reflect.ValueOf(flate.BestSpeed),
|
||||
"DefaultCompression": reflect.ValueOf(flate.DefaultCompression),
|
||||
"HuffmanOnly": reflect.ValueOf(flate.HuffmanOnly),
|
||||
"BestCompression": reflect.ValueOf(constant.MakeFromLiteral("9", token.INT, 0)),
|
||||
"BestSpeed": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"DefaultCompression": reflect.ValueOf(constant.MakeFromLiteral("-1", token.INT, 0)),
|
||||
"HuffmanOnly": reflect.ValueOf(constant.MakeFromLiteral("-2", token.INT, 0)),
|
||||
"NewReader": reflect.ValueOf(flate.NewReader),
|
||||
"NewReaderDict": reflect.ValueOf(flate.NewReaderDict),
|
||||
"NewWriter": reflect.ValueOf(flate.NewWriter),
|
||||
"NewWriterDict": reflect.ValueOf(flate.NewWriterDict),
|
||||
"NoCompression": reflect.ValueOf(flate.NoCompression),
|
||||
"NoCompression": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
|
||||
// type definitions
|
||||
"CorruptInputError": reflect.ValueOf((*flate.CorruptInputError)(nil)),
|
||||
|
||||
@@ -6,22 +6,24 @@ package stdlib
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["compress/gzip"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BestCompression": reflect.ValueOf(gzip.BestCompression),
|
||||
"BestSpeed": reflect.ValueOf(gzip.BestSpeed),
|
||||
"DefaultCompression": reflect.ValueOf(gzip.DefaultCompression),
|
||||
"BestCompression": reflect.ValueOf(constant.MakeFromLiteral("9", token.INT, 0)),
|
||||
"BestSpeed": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"DefaultCompression": reflect.ValueOf(constant.MakeFromLiteral("-1", token.INT, 0)),
|
||||
"ErrChecksum": reflect.ValueOf(&gzip.ErrChecksum).Elem(),
|
||||
"ErrHeader": reflect.ValueOf(&gzip.ErrHeader).Elem(),
|
||||
"HuffmanOnly": reflect.ValueOf(gzip.HuffmanOnly),
|
||||
"HuffmanOnly": reflect.ValueOf(constant.MakeFromLiteral("-2", token.INT, 0)),
|
||||
"NewReader": reflect.ValueOf(gzip.NewReader),
|
||||
"NewWriter": reflect.ValueOf(gzip.NewWriter),
|
||||
"NewWriterLevel": reflect.ValueOf(gzip.NewWriterLevel),
|
||||
"NoCompression": reflect.ValueOf(gzip.NoCompression),
|
||||
"NoCompression": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
|
||||
// type definitions
|
||||
"Header": reflect.ValueOf((*gzip.Header)(nil)),
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"compress/zlib"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"io"
|
||||
"reflect"
|
||||
)
|
||||
@@ -13,19 +15,19 @@ import (
|
||||
func init() {
|
||||
Symbols["compress/zlib"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BestCompression": reflect.ValueOf(zlib.BestCompression),
|
||||
"BestSpeed": reflect.ValueOf(zlib.BestSpeed),
|
||||
"DefaultCompression": reflect.ValueOf(zlib.DefaultCompression),
|
||||
"BestCompression": reflect.ValueOf(constant.MakeFromLiteral("9", token.INT, 0)),
|
||||
"BestSpeed": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"DefaultCompression": reflect.ValueOf(constant.MakeFromLiteral("-1", token.INT, 0)),
|
||||
"ErrChecksum": reflect.ValueOf(&zlib.ErrChecksum).Elem(),
|
||||
"ErrDictionary": reflect.ValueOf(&zlib.ErrDictionary).Elem(),
|
||||
"ErrHeader": reflect.ValueOf(&zlib.ErrHeader).Elem(),
|
||||
"HuffmanOnly": reflect.ValueOf(zlib.HuffmanOnly),
|
||||
"HuffmanOnly": reflect.ValueOf(constant.MakeFromLiteral("-2", token.INT, 0)),
|
||||
"NewReader": reflect.ValueOf(zlib.NewReader),
|
||||
"NewReaderDict": reflect.ValueOf(zlib.NewReaderDict),
|
||||
"NewWriter": reflect.ValueOf(zlib.NewWriter),
|
||||
"NewWriterLevel": reflect.ValueOf(zlib.NewWriterLevel),
|
||||
"NewWriterLevelDict": reflect.ValueOf(zlib.NewWriterLevelDict),
|
||||
"NoCompression": reflect.ValueOf(zlib.NoCompression),
|
||||
"NoCompression": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
|
||||
// type definitions
|
||||
"Resetter": reflect.ValueOf((*zlib.Resetter)(nil)),
|
||||
|
||||
@@ -6,13 +6,15 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["crypto/aes"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BlockSize": reflect.ValueOf(aes.BlockSize),
|
||||
"BlockSize": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"NewCipher": reflect.ValueOf(aes.NewCipher),
|
||||
|
||||
// type definitions
|
||||
|
||||
@@ -6,13 +6,15 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/des"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["crypto/des"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BlockSize": reflect.ValueOf(des.BlockSize),
|
||||
"BlockSize": reflect.ValueOf(constant.MakeFromLiteral("8", token.INT, 0)),
|
||||
"NewCipher": reflect.ValueOf(des.NewCipher),
|
||||
"NewTripleDESCipher": reflect.ValueOf(des.NewTripleDESCipher),
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -14,11 +16,11 @@ func init() {
|
||||
// function, constant and variable definitions
|
||||
"GenerateKey": reflect.ValueOf(ed25519.GenerateKey),
|
||||
"NewKeyFromSeed": reflect.ValueOf(ed25519.NewKeyFromSeed),
|
||||
"PrivateKeySize": reflect.ValueOf(ed25519.PrivateKeySize),
|
||||
"PublicKeySize": reflect.ValueOf(ed25519.PublicKeySize),
|
||||
"SeedSize": reflect.ValueOf(ed25519.SeedSize),
|
||||
"PrivateKeySize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"PublicKeySize": reflect.ValueOf(constant.MakeFromLiteral("32", token.INT, 0)),
|
||||
"SeedSize": reflect.ValueOf(constant.MakeFromLiteral("32", token.INT, 0)),
|
||||
"Sign": reflect.ValueOf(ed25519.Sign),
|
||||
"SignatureSize": reflect.ValueOf(ed25519.SignatureSize),
|
||||
"SignatureSize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"Verify": reflect.ValueOf(ed25519.Verify),
|
||||
|
||||
// type definitions
|
||||
|
||||
@@ -6,15 +6,17 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["crypto/md5"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BlockSize": reflect.ValueOf(md5.BlockSize),
|
||||
"BlockSize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"New": reflect.ValueOf(md5.New),
|
||||
"Size": reflect.ValueOf(md5.Size),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"Sum": reflect.ValueOf(md5.Sum),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -22,8 +24,8 @@ func init() {
|
||||
"ErrVerification": reflect.ValueOf(&rsa.ErrVerification).Elem(),
|
||||
"GenerateKey": reflect.ValueOf(rsa.GenerateKey),
|
||||
"GenerateMultiPrimeKey": reflect.ValueOf(rsa.GenerateMultiPrimeKey),
|
||||
"PSSSaltLengthAuto": reflect.ValueOf(rsa.PSSSaltLengthAuto),
|
||||
"PSSSaltLengthEqualsHash": reflect.ValueOf(rsa.PSSSaltLengthEqualsHash),
|
||||
"PSSSaltLengthAuto": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"PSSSaltLengthEqualsHash": reflect.ValueOf(constant.MakeFromLiteral("-1", token.INT, 0)),
|
||||
"SignPKCS1v15": reflect.ValueOf(rsa.SignPKCS1v15),
|
||||
"SignPSS": reflect.ValueOf(rsa.SignPSS),
|
||||
"VerifyPKCS1v15": reflect.ValueOf(rsa.VerifyPKCS1v15),
|
||||
|
||||
@@ -6,15 +6,17 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["crypto/sha1"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BlockSize": reflect.ValueOf(sha1.BlockSize),
|
||||
"BlockSize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"New": reflect.ValueOf(sha1.New),
|
||||
"Size": reflect.ValueOf(sha1.Size),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("20", token.INT, 0)),
|
||||
"Sum": reflect.ValueOf(sha1.Sum),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,19 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["crypto/sha256"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BlockSize": reflect.ValueOf(sha256.BlockSize),
|
||||
"BlockSize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"New": reflect.ValueOf(sha256.New),
|
||||
"New224": reflect.ValueOf(sha256.New224),
|
||||
"Size": reflect.ValueOf(sha256.Size),
|
||||
"Size224": reflect.ValueOf(sha256.Size224),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("32", token.INT, 0)),
|
||||
"Size224": reflect.ValueOf(constant.MakeFromLiteral("28", token.INT, 0)),
|
||||
"Sum224": reflect.ValueOf(sha256.Sum224),
|
||||
"Sum256": reflect.ValueOf(sha256.Sum256),
|
||||
}
|
||||
|
||||
@@ -6,21 +6,23 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["crypto/sha512"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"BlockSize": reflect.ValueOf(sha512.BlockSize),
|
||||
"BlockSize": reflect.ValueOf(constant.MakeFromLiteral("128", token.INT, 0)),
|
||||
"New": reflect.ValueOf(sha512.New),
|
||||
"New384": reflect.ValueOf(sha512.New384),
|
||||
"New512_224": reflect.ValueOf(sha512.New512_224),
|
||||
"New512_256": reflect.ValueOf(sha512.New512_256),
|
||||
"Size": reflect.ValueOf(sha512.Size),
|
||||
"Size224": reflect.ValueOf(sha512.Size224),
|
||||
"Size256": reflect.ValueOf(sha512.Size256),
|
||||
"Size384": reflect.ValueOf(sha512.Size384),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"Size224": reflect.ValueOf(constant.MakeFromLiteral("28", token.INT, 0)),
|
||||
"Size256": reflect.ValueOf(constant.MakeFromLiteral("32", token.INT, 0)),
|
||||
"Size384": reflect.ValueOf(constant.MakeFromLiteral("48", token.INT, 0)),
|
||||
"Sum384": reflect.ValueOf(sha512.Sum384),
|
||||
"Sum512": reflect.ValueOf(sha512.Sum512),
|
||||
"Sum512_224": reflect.ValueOf(sha512.Sum512_224),
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -69,11 +71,11 @@ func init() {
|
||||
"TLS_RSA_WITH_AES_256_GCM_SHA384": reflect.ValueOf(tls.TLS_RSA_WITH_AES_256_GCM_SHA384),
|
||||
"TLS_RSA_WITH_RC4_128_SHA": reflect.ValueOf(tls.TLS_RSA_WITH_RC4_128_SHA),
|
||||
"VerifyClientCertIfGiven": reflect.ValueOf(tls.VerifyClientCertIfGiven),
|
||||
"VersionSSL30": reflect.ValueOf(tls.VersionSSL30),
|
||||
"VersionTLS10": reflect.ValueOf(tls.VersionTLS10),
|
||||
"VersionTLS11": reflect.ValueOf(tls.VersionTLS11),
|
||||
"VersionTLS12": reflect.ValueOf(tls.VersionTLS12),
|
||||
"VersionTLS13": reflect.ValueOf(tls.VersionTLS13),
|
||||
"VersionSSL30": reflect.ValueOf(constant.MakeFromLiteral("768", token.INT, 0)),
|
||||
"VersionTLS10": reflect.ValueOf(constant.MakeFromLiteral("769", token.INT, 0)),
|
||||
"VersionTLS11": reflect.ValueOf(constant.MakeFromLiteral("770", token.INT, 0)),
|
||||
"VersionTLS12": reflect.ValueOf(constant.MakeFromLiteral("771", token.INT, 0)),
|
||||
"VersionTLS13": reflect.ValueOf(constant.MakeFromLiteral("772", token.INT, 0)),
|
||||
"X25519": reflect.ValueOf(tls.X25519),
|
||||
"X509KeyPair": reflect.ValueOf(tls.X509KeyPair),
|
||||
|
||||
|
||||
@@ -6,13 +6,15 @@ package stdlib
|
||||
|
||||
import (
|
||||
"debug/elf"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["debug/elf"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"ARM_MAGIC_TRAMP_NUMBER": reflect.ValueOf(elf.ARM_MAGIC_TRAMP_NUMBER),
|
||||
"ARM_MAGIC_TRAMP_NUMBER": reflect.ValueOf(constant.MakeFromLiteral("1543503875", token.INT, 0)),
|
||||
"COMPRESS_HIOS": reflect.ValueOf(elf.COMPRESS_HIOS),
|
||||
"COMPRESS_HIPROC": reflect.ValueOf(elf.COMPRESS_HIPROC),
|
||||
"COMPRESS_LOOS": reflect.ValueOf(elf.COMPRESS_LOOS),
|
||||
@@ -64,13 +66,13 @@ func init() {
|
||||
"DT_VERNEED": reflect.ValueOf(elf.DT_VERNEED),
|
||||
"DT_VERNEEDNUM": reflect.ValueOf(elf.DT_VERNEEDNUM),
|
||||
"DT_VERSYM": reflect.ValueOf(elf.DT_VERSYM),
|
||||
"EI_ABIVERSION": reflect.ValueOf(elf.EI_ABIVERSION),
|
||||
"EI_CLASS": reflect.ValueOf(elf.EI_CLASS),
|
||||
"EI_DATA": reflect.ValueOf(elf.EI_DATA),
|
||||
"EI_NIDENT": reflect.ValueOf(elf.EI_NIDENT),
|
||||
"EI_OSABI": reflect.ValueOf(elf.EI_OSABI),
|
||||
"EI_PAD": reflect.ValueOf(elf.EI_PAD),
|
||||
"EI_VERSION": reflect.ValueOf(elf.EI_VERSION),
|
||||
"EI_ABIVERSION": reflect.ValueOf(constant.MakeFromLiteral("8", token.INT, 0)),
|
||||
"EI_CLASS": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"EI_DATA": reflect.ValueOf(constant.MakeFromLiteral("5", token.INT, 0)),
|
||||
"EI_NIDENT": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"EI_OSABI": reflect.ValueOf(constant.MakeFromLiteral("7", token.INT, 0)),
|
||||
"EI_PAD": reflect.ValueOf(constant.MakeFromLiteral("9", token.INT, 0)),
|
||||
"EI_VERSION": reflect.ValueOf(constant.MakeFromLiteral("6", token.INT, 0)),
|
||||
"ELFCLASS32": reflect.ValueOf(elf.ELFCLASS32),
|
||||
"ELFCLASS64": reflect.ValueOf(elf.ELFCLASS64),
|
||||
"ELFCLASSNONE": reflect.ValueOf(elf.ELFCLASSNONE),
|
||||
@@ -1190,8 +1192,8 @@ func init() {
|
||||
"ST_INFO": reflect.ValueOf(elf.ST_INFO),
|
||||
"ST_TYPE": reflect.ValueOf(elf.ST_TYPE),
|
||||
"ST_VISIBILITY": reflect.ValueOf(elf.ST_VISIBILITY),
|
||||
"Sym32Size": reflect.ValueOf(elf.Sym32Size),
|
||||
"Sym64Size": reflect.ValueOf(elf.Sym64Size),
|
||||
"Sym32Size": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"Sym64Size": reflect.ValueOf(constant.MakeFromLiteral("24", token.INT, 0)),
|
||||
|
||||
// type definitions
|
||||
"Chdr32": reflect.ValueOf((*elf.Chdr32)(nil)),
|
||||
|
||||
@@ -6,50 +6,52 @@ package stdlib
|
||||
|
||||
import (
|
||||
"debug/pe"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["debug/pe"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"COFFSymbolSize": reflect.ValueOf(pe.COFFSymbolSize),
|
||||
"IMAGE_DIRECTORY_ENTRY_ARCHITECTURE": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_ARCHITECTURE),
|
||||
"IMAGE_DIRECTORY_ENTRY_BASERELOC": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_BASERELOC),
|
||||
"IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT),
|
||||
"IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR),
|
||||
"IMAGE_DIRECTORY_ENTRY_DEBUG": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_DEBUG),
|
||||
"IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT),
|
||||
"IMAGE_DIRECTORY_ENTRY_EXCEPTION": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_EXCEPTION),
|
||||
"IMAGE_DIRECTORY_ENTRY_EXPORT": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_EXPORT),
|
||||
"IMAGE_DIRECTORY_ENTRY_GLOBALPTR": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_GLOBALPTR),
|
||||
"IMAGE_DIRECTORY_ENTRY_IAT": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_IAT),
|
||||
"IMAGE_DIRECTORY_ENTRY_IMPORT": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_IMPORT),
|
||||
"IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG),
|
||||
"IMAGE_DIRECTORY_ENTRY_RESOURCE": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_RESOURCE),
|
||||
"IMAGE_DIRECTORY_ENTRY_SECURITY": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_SECURITY),
|
||||
"IMAGE_DIRECTORY_ENTRY_TLS": reflect.ValueOf(pe.IMAGE_DIRECTORY_ENTRY_TLS),
|
||||
"IMAGE_FILE_MACHINE_AM33": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_AM33),
|
||||
"IMAGE_FILE_MACHINE_AMD64": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_AMD64),
|
||||
"IMAGE_FILE_MACHINE_ARM": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_ARM),
|
||||
"IMAGE_FILE_MACHINE_ARM64": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_ARM64),
|
||||
"IMAGE_FILE_MACHINE_ARMNT": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_ARMNT),
|
||||
"IMAGE_FILE_MACHINE_EBC": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_EBC),
|
||||
"IMAGE_FILE_MACHINE_I386": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_I386),
|
||||
"IMAGE_FILE_MACHINE_IA64": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_IA64),
|
||||
"IMAGE_FILE_MACHINE_M32R": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_M32R),
|
||||
"IMAGE_FILE_MACHINE_MIPS16": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_MIPS16),
|
||||
"IMAGE_FILE_MACHINE_MIPSFPU": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_MIPSFPU),
|
||||
"IMAGE_FILE_MACHINE_MIPSFPU16": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_MIPSFPU16),
|
||||
"IMAGE_FILE_MACHINE_POWERPC": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_POWERPC),
|
||||
"IMAGE_FILE_MACHINE_POWERPCFP": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_POWERPCFP),
|
||||
"IMAGE_FILE_MACHINE_R4000": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_R4000),
|
||||
"IMAGE_FILE_MACHINE_SH3": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_SH3),
|
||||
"IMAGE_FILE_MACHINE_SH3DSP": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_SH3DSP),
|
||||
"IMAGE_FILE_MACHINE_SH4": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_SH4),
|
||||
"IMAGE_FILE_MACHINE_SH5": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_SH5),
|
||||
"IMAGE_FILE_MACHINE_THUMB": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_THUMB),
|
||||
"IMAGE_FILE_MACHINE_UNKNOWN": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_UNKNOWN),
|
||||
"IMAGE_FILE_MACHINE_WCEMIPSV2": reflect.ValueOf(pe.IMAGE_FILE_MACHINE_WCEMIPSV2),
|
||||
"COFFSymbolSize": reflect.ValueOf(constant.MakeFromLiteral("18", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_ARCHITECTURE": reflect.ValueOf(constant.MakeFromLiteral("7", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_BASERELOC": reflect.ValueOf(constant.MakeFromLiteral("5", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT": reflect.ValueOf(constant.MakeFromLiteral("11", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR": reflect.ValueOf(constant.MakeFromLiteral("14", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_DEBUG": reflect.ValueOf(constant.MakeFromLiteral("6", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT": reflect.ValueOf(constant.MakeFromLiteral("13", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_EXCEPTION": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_EXPORT": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_GLOBALPTR": reflect.ValueOf(constant.MakeFromLiteral("8", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_IAT": reflect.ValueOf(constant.MakeFromLiteral("12", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_IMPORT": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG": reflect.ValueOf(constant.MakeFromLiteral("10", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_RESOURCE": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_SECURITY": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"IMAGE_DIRECTORY_ENTRY_TLS": reflect.ValueOf(constant.MakeFromLiteral("9", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_AM33": reflect.ValueOf(constant.MakeFromLiteral("467", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_AMD64": reflect.ValueOf(constant.MakeFromLiteral("34404", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_ARM": reflect.ValueOf(constant.MakeFromLiteral("448", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_ARM64": reflect.ValueOf(constant.MakeFromLiteral("43620", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_ARMNT": reflect.ValueOf(constant.MakeFromLiteral("452", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_EBC": reflect.ValueOf(constant.MakeFromLiteral("3772", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_I386": reflect.ValueOf(constant.MakeFromLiteral("332", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_IA64": reflect.ValueOf(constant.MakeFromLiteral("512", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_M32R": reflect.ValueOf(constant.MakeFromLiteral("36929", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_MIPS16": reflect.ValueOf(constant.MakeFromLiteral("614", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_MIPSFPU": reflect.ValueOf(constant.MakeFromLiteral("870", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_MIPSFPU16": reflect.ValueOf(constant.MakeFromLiteral("1126", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_POWERPC": reflect.ValueOf(constant.MakeFromLiteral("496", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_POWERPCFP": reflect.ValueOf(constant.MakeFromLiteral("497", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_R4000": reflect.ValueOf(constant.MakeFromLiteral("358", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_SH3": reflect.ValueOf(constant.MakeFromLiteral("418", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_SH3DSP": reflect.ValueOf(constant.MakeFromLiteral("419", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_SH4": reflect.ValueOf(constant.MakeFromLiteral("422", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_SH5": reflect.ValueOf(constant.MakeFromLiteral("424", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_THUMB": reflect.ValueOf(constant.MakeFromLiteral("450", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_UNKNOWN": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"IMAGE_FILE_MACHINE_WCEMIPSV2": reflect.ValueOf(constant.MakeFromLiteral("361", token.INT, 0)),
|
||||
"NewFile": reflect.ValueOf(pe.NewFile),
|
||||
"Open": reflect.ValueOf(pe.Open),
|
||||
|
||||
|
||||
@@ -6,16 +6,18 @@ package stdlib
|
||||
|
||||
import (
|
||||
"debug/plan9obj"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["debug/plan9obj"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"Magic386": reflect.ValueOf(plan9obj.Magic386),
|
||||
"Magic64": reflect.ValueOf(plan9obj.Magic64),
|
||||
"MagicAMD64": reflect.ValueOf(plan9obj.MagicAMD64),
|
||||
"MagicARM": reflect.ValueOf(plan9obj.MagicARM),
|
||||
"Magic386": reflect.ValueOf(constant.MakeFromLiteral("491", token.INT, 0)),
|
||||
"Magic64": reflect.ValueOf(constant.MakeFromLiteral("32768", token.INT, 0)),
|
||||
"MagicAMD64": reflect.ValueOf(constant.MakeFromLiteral("35479", token.INT, 0)),
|
||||
"MagicARM": reflect.ValueOf(constant.MakeFromLiteral("1607", token.INT, 0)),
|
||||
"NewFile": reflect.ValueOf(plan9obj.NewFile),
|
||||
"Open": reflect.ValueOf(plan9obj.Open),
|
||||
|
||||
|
||||
@@ -6,37 +6,39 @@ package stdlib
|
||||
|
||||
import (
|
||||
"encoding/asn1"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["encoding/asn1"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"ClassApplication": reflect.ValueOf(asn1.ClassApplication),
|
||||
"ClassContextSpecific": reflect.ValueOf(asn1.ClassContextSpecific),
|
||||
"ClassPrivate": reflect.ValueOf(asn1.ClassPrivate),
|
||||
"ClassUniversal": reflect.ValueOf(asn1.ClassUniversal),
|
||||
"ClassApplication": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"ClassContextSpecific": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"ClassPrivate": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"ClassUniversal": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"Marshal": reflect.ValueOf(asn1.Marshal),
|
||||
"MarshalWithParams": reflect.ValueOf(asn1.MarshalWithParams),
|
||||
"NullBytes": reflect.ValueOf(&asn1.NullBytes).Elem(),
|
||||
"NullRawValue": reflect.ValueOf(&asn1.NullRawValue).Elem(),
|
||||
"TagBitString": reflect.ValueOf(asn1.TagBitString),
|
||||
"TagBoolean": reflect.ValueOf(asn1.TagBoolean),
|
||||
"TagEnum": reflect.ValueOf(asn1.TagEnum),
|
||||
"TagGeneralString": reflect.ValueOf(asn1.TagGeneralString),
|
||||
"TagGeneralizedTime": reflect.ValueOf(asn1.TagGeneralizedTime),
|
||||
"TagIA5String": reflect.ValueOf(asn1.TagIA5String),
|
||||
"TagInteger": reflect.ValueOf(asn1.TagInteger),
|
||||
"TagNull": reflect.ValueOf(asn1.TagNull),
|
||||
"TagNumericString": reflect.ValueOf(asn1.TagNumericString),
|
||||
"TagOID": reflect.ValueOf(asn1.TagOID),
|
||||
"TagOctetString": reflect.ValueOf(asn1.TagOctetString),
|
||||
"TagPrintableString": reflect.ValueOf(asn1.TagPrintableString),
|
||||
"TagSequence": reflect.ValueOf(asn1.TagSequence),
|
||||
"TagSet": reflect.ValueOf(asn1.TagSet),
|
||||
"TagT61String": reflect.ValueOf(asn1.TagT61String),
|
||||
"TagUTCTime": reflect.ValueOf(asn1.TagUTCTime),
|
||||
"TagUTF8String": reflect.ValueOf(asn1.TagUTF8String),
|
||||
"TagBitString": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"TagBoolean": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"TagEnum": reflect.ValueOf(constant.MakeFromLiteral("10", token.INT, 0)),
|
||||
"TagGeneralString": reflect.ValueOf(constant.MakeFromLiteral("27", token.INT, 0)),
|
||||
"TagGeneralizedTime": reflect.ValueOf(constant.MakeFromLiteral("24", token.INT, 0)),
|
||||
"TagIA5String": reflect.ValueOf(constant.MakeFromLiteral("22", token.INT, 0)),
|
||||
"TagInteger": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"TagNull": reflect.ValueOf(constant.MakeFromLiteral("5", token.INT, 0)),
|
||||
"TagNumericString": reflect.ValueOf(constant.MakeFromLiteral("18", token.INT, 0)),
|
||||
"TagOID": reflect.ValueOf(constant.MakeFromLiteral("6", token.INT, 0)),
|
||||
"TagOctetString": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"TagPrintableString": reflect.ValueOf(constant.MakeFromLiteral("19", token.INT, 0)),
|
||||
"TagSequence": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"TagSet": reflect.ValueOf(constant.MakeFromLiteral("17", token.INT, 0)),
|
||||
"TagT61String": reflect.ValueOf(constant.MakeFromLiteral("20", token.INT, 0)),
|
||||
"TagUTCTime": reflect.ValueOf(constant.MakeFromLiteral("23", token.INT, 0)),
|
||||
"TagUTF8String": reflect.ValueOf(constant.MakeFromLiteral("12", token.INT, 0)),
|
||||
"Unmarshal": reflect.ValueOf(asn1.Unmarshal),
|
||||
"UnmarshalWithParams": reflect.ValueOf(asn1.UnmarshalWithParams),
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -14,9 +16,9 @@ func init() {
|
||||
// function, constant and variable definitions
|
||||
"BigEndian": reflect.ValueOf(&binary.BigEndian).Elem(),
|
||||
"LittleEndian": reflect.ValueOf(&binary.LittleEndian).Elem(),
|
||||
"MaxVarintLen16": reflect.ValueOf(binary.MaxVarintLen16),
|
||||
"MaxVarintLen32": reflect.ValueOf(binary.MaxVarintLen32),
|
||||
"MaxVarintLen64": reflect.ValueOf(binary.MaxVarintLen64),
|
||||
"MaxVarintLen16": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"MaxVarintLen32": reflect.ValueOf(constant.MakeFromLiteral("5", token.INT, 0)),
|
||||
"MaxVarintLen64": reflect.ValueOf(constant.MakeFromLiteral("10", token.INT, 0)),
|
||||
"PutUvarint": reflect.ValueOf(binary.PutUvarint),
|
||||
"PutVarint": reflect.ValueOf(binary.PutVarint),
|
||||
"Read": reflect.ValueOf(binary.Read),
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
@@ -45,7 +46,7 @@ func init() {
|
||||
"GO": reflect.ValueOf(token.GO),
|
||||
"GOTO": reflect.ValueOf(token.GOTO),
|
||||
"GTR": reflect.ValueOf(token.GTR),
|
||||
"HighestPrec": reflect.ValueOf(token.HighestPrec),
|
||||
"HighestPrec": reflect.ValueOf(constant.MakeFromLiteral("7", token.INT, 0)),
|
||||
"IDENT": reflect.ValueOf(token.IDENT),
|
||||
"IF": reflect.ValueOf(token.IF),
|
||||
"ILLEGAL": reflect.ValueOf(token.ILLEGAL),
|
||||
@@ -65,7 +66,7 @@ func init() {
|
||||
"LPAREN": reflect.ValueOf(token.LPAREN),
|
||||
"LSS": reflect.ValueOf(token.LSS),
|
||||
"Lookup": reflect.ValueOf(token.Lookup),
|
||||
"LowestPrec": reflect.ValueOf(token.LowestPrec),
|
||||
"LowestPrec": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"MAP": reflect.ValueOf(token.MAP),
|
||||
"MUL": reflect.ValueOf(token.MUL),
|
||||
"MUL_ASSIGN": reflect.ValueOf(token.MUL_ASSIGN),
|
||||
@@ -98,7 +99,7 @@ func init() {
|
||||
"SUB_ASSIGN": reflect.ValueOf(token.SUB_ASSIGN),
|
||||
"SWITCH": reflect.ValueOf(token.SWITCH),
|
||||
"TYPE": reflect.ValueOf(token.TYPE),
|
||||
"UnaryPrec": reflect.ValueOf(token.UnaryPrec),
|
||||
"UnaryPrec": reflect.ValueOf(constant.MakeFromLiteral("6", token.INT, 0)),
|
||||
"VAR": reflect.ValueOf(token.VAR),
|
||||
"XOR": reflect.ValueOf(token.XOR),
|
||||
"XOR_ASSIGN": reflect.ValueOf(token.XOR_ASSIGN),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"hash/adler32"
|
||||
"reflect"
|
||||
)
|
||||
@@ -14,6 +16,6 @@ func init() {
|
||||
// function, constant and variable definitions
|
||||
"Checksum": reflect.ValueOf(adler32.Checksum),
|
||||
"New": reflect.ValueOf(adler32.New),
|
||||
"Size": reflect.ValueOf(adler32.Size),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"hash/crc32"
|
||||
"reflect"
|
||||
)
|
||||
@@ -12,16 +14,16 @@ import (
|
||||
func init() {
|
||||
Symbols["hash/crc32"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"Castagnoli": reflect.ValueOf(uint32(crc32.Castagnoli)),
|
||||
"Castagnoli": reflect.ValueOf(constant.MakeFromLiteral("2197175160", token.INT, 0)),
|
||||
"Checksum": reflect.ValueOf(crc32.Checksum),
|
||||
"ChecksumIEEE": reflect.ValueOf(crc32.ChecksumIEEE),
|
||||
"IEEE": reflect.ValueOf(uint32(crc32.IEEE)),
|
||||
"IEEE": reflect.ValueOf(constant.MakeFromLiteral("3988292384", token.INT, 0)),
|
||||
"IEEETable": reflect.ValueOf(&crc32.IEEETable).Elem(),
|
||||
"Koopman": reflect.ValueOf(uint32(crc32.Koopman)),
|
||||
"Koopman": reflect.ValueOf(constant.MakeFromLiteral("3945912366", token.INT, 0)),
|
||||
"MakeTable": reflect.ValueOf(crc32.MakeTable),
|
||||
"New": reflect.ValueOf(crc32.New),
|
||||
"NewIEEE": reflect.ValueOf(crc32.NewIEEE),
|
||||
"Size": reflect.ValueOf(crc32.Size),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"Update": reflect.ValueOf(crc32.Update),
|
||||
|
||||
// type definitions
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"hash/crc64"
|
||||
"reflect"
|
||||
)
|
||||
@@ -13,11 +15,11 @@ func init() {
|
||||
Symbols["hash/crc64"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"Checksum": reflect.ValueOf(crc64.Checksum),
|
||||
"ECMA": reflect.ValueOf(uint64(crc64.ECMA)),
|
||||
"ISO": reflect.ValueOf(uint64(crc64.ISO)),
|
||||
"ECMA": reflect.ValueOf(constant.MakeFromLiteral("14514072000185962306", token.INT, 0)),
|
||||
"ISO": reflect.ValueOf(constant.MakeFromLiteral("15564440312192434176", token.INT, 0)),
|
||||
"MakeTable": reflect.ValueOf(crc64.MakeTable),
|
||||
"New": reflect.ValueOf(crc64.New),
|
||||
"Size": reflect.ValueOf(crc64.Size),
|
||||
"Size": reflect.ValueOf(constant.MakeFromLiteral("8", token.INT, 0)),
|
||||
"Update": reflect.ValueOf(crc64.Update),
|
||||
|
||||
// type definitions
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"image/gif"
|
||||
"reflect"
|
||||
)
|
||||
@@ -15,9 +17,9 @@ func init() {
|
||||
"Decode": reflect.ValueOf(gif.Decode),
|
||||
"DecodeAll": reflect.ValueOf(gif.DecodeAll),
|
||||
"DecodeConfig": reflect.ValueOf(gif.DecodeConfig),
|
||||
"DisposalBackground": reflect.ValueOf(gif.DisposalBackground),
|
||||
"DisposalNone": reflect.ValueOf(gif.DisposalNone),
|
||||
"DisposalPrevious": reflect.ValueOf(gif.DisposalPrevious),
|
||||
"DisposalBackground": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"DisposalNone": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"DisposalPrevious": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"Encode": reflect.ValueOf(gif.Encode),
|
||||
"EncodeAll": reflect.ValueOf(gif.EncodeAll),
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"image/jpeg"
|
||||
"reflect"
|
||||
)
|
||||
@@ -14,7 +16,7 @@ func init() {
|
||||
// function, constant and variable definitions
|
||||
"Decode": reflect.ValueOf(jpeg.Decode),
|
||||
"DecodeConfig": reflect.ValueOf(jpeg.DecodeConfig),
|
||||
"DefaultQuality": reflect.ValueOf(jpeg.DefaultQuality),
|
||||
"DefaultQuality": reflect.ValueOf(constant.MakeFromLiteral("75", token.INT, 0)),
|
||||
"Encode": reflect.ValueOf(jpeg.Encode),
|
||||
|
||||
// type definitions
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"io"
|
||||
"reflect"
|
||||
)
|
||||
@@ -28,9 +30,9 @@ func init() {
|
||||
"Pipe": reflect.ValueOf(io.Pipe),
|
||||
"ReadAtLeast": reflect.ValueOf(io.ReadAtLeast),
|
||||
"ReadFull": reflect.ValueOf(io.ReadFull),
|
||||
"SeekCurrent": reflect.ValueOf(io.SeekCurrent),
|
||||
"SeekEnd": reflect.ValueOf(io.SeekEnd),
|
||||
"SeekStart": reflect.ValueOf(io.SeekStart),
|
||||
"SeekCurrent": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"SeekEnd": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"SeekStart": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"TeeReader": reflect.ValueOf(io.TeeReader),
|
||||
"WriteString": reflect.ValueOf(io.WriteString),
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"log"
|
||||
"reflect"
|
||||
)
|
||||
@@ -16,13 +18,13 @@ func init() {
|
||||
"Fatalf": reflect.ValueOf(log.Fatalf),
|
||||
"Fatalln": reflect.ValueOf(log.Fatalln),
|
||||
"Flags": reflect.ValueOf(log.Flags),
|
||||
"LUTC": reflect.ValueOf(log.LUTC),
|
||||
"Ldate": reflect.ValueOf(log.Ldate),
|
||||
"Llongfile": reflect.ValueOf(log.Llongfile),
|
||||
"Lmicroseconds": reflect.ValueOf(log.Lmicroseconds),
|
||||
"Lshortfile": reflect.ValueOf(log.Lshortfile),
|
||||
"LstdFlags": reflect.ValueOf(log.LstdFlags),
|
||||
"Ltime": reflect.ValueOf(log.Ltime),
|
||||
"LUTC": reflect.ValueOf(constant.MakeFromLiteral("32", token.INT, 0)),
|
||||
"Ldate": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"Llongfile": reflect.ValueOf(constant.MakeFromLiteral("8", token.INT, 0)),
|
||||
"Lmicroseconds": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"Lshortfile": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"LstdFlags": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"Ltime": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"New": reflect.ValueOf(log.New),
|
||||
"Output": reflect.ValueOf(log.Output),
|
||||
"Panic": reflect.ValueOf(log.Panic),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"math"
|
||||
"reflect"
|
||||
)
|
||||
@@ -26,7 +28,7 @@ func init() {
|
||||
"Cos": reflect.ValueOf(math.Cos),
|
||||
"Cosh": reflect.ValueOf(math.Cosh),
|
||||
"Dim": reflect.ValueOf(math.Dim),
|
||||
"E": reflect.ValueOf(math.E),
|
||||
"E": reflect.ValueOf(constant.MakeFromLiteral("2.71828182845904523536028747135266249775724709369995957496696762566337824315673231520670375558666729784504486779277967997696994772644702281675346915668215131895555530285035761295375777990557253360748291015625", token.FLOAT, 0)),
|
||||
"Erf": reflect.ValueOf(math.Erf),
|
||||
"Erfc": reflect.ValueOf(math.Erfc),
|
||||
"Erfcinv": reflect.ValueOf(math.Erfcinv),
|
||||
@@ -51,38 +53,38 @@ func init() {
|
||||
"Jn": reflect.ValueOf(math.Jn),
|
||||
"Ldexp": reflect.ValueOf(math.Ldexp),
|
||||
"Lgamma": reflect.ValueOf(math.Lgamma),
|
||||
"Ln10": reflect.ValueOf(math.Ln10),
|
||||
"Ln2": reflect.ValueOf(math.Ln2),
|
||||
"Ln10": reflect.ValueOf(constant.MakeFromLiteral("2.30258509299404568401799145468436420760110148862877297603332784146804725494827975466552490443295866962642372461496758838959542646932914211937012833592062802600362869664962772731087170541286468505859375", token.FLOAT, 0)),
|
||||
"Ln2": reflect.ValueOf(constant.MakeFromLiteral("0.6931471805599453094172321214581765680755001343602552541206800092715999496201383079363438206637927920954189307729314303884387720696314608777673678644642390655170150035209453154294578780536539852619171142578125", token.FLOAT, 0)),
|
||||
"Log": reflect.ValueOf(math.Log),
|
||||
"Log10": reflect.ValueOf(math.Log10),
|
||||
"Log10E": reflect.ValueOf(math.Log10E),
|
||||
"Log10E": reflect.ValueOf(constant.MakeFromLiteral("0.43429448190325182765112891891660508229439700580366656611445378416636798190620320263064286300825210972160277489744884502676719847561509639618196799746596688688378591625127711495224502868950366973876953125", token.FLOAT, 0)),
|
||||
"Log1p": reflect.ValueOf(math.Log1p),
|
||||
"Log2": reflect.ValueOf(math.Log2),
|
||||
"Log2E": reflect.ValueOf(math.Log2E),
|
||||
"Log2E": reflect.ValueOf(constant.MakeFromLiteral("1.44269504088896340735992468100189213742664595415298593413544940772066427768997545329060870636212628972710992130324953463427359402479619301286929040235571747101382214539290471666532766903401352465152740478515625", token.FLOAT, 0)),
|
||||
"Logb": reflect.ValueOf(math.Logb),
|
||||
"Max": reflect.ValueOf(math.Max),
|
||||
"MaxFloat32": reflect.ValueOf(float32(math.MaxFloat32)),
|
||||
"MaxFloat64": reflect.ValueOf(math.MaxFloat64),
|
||||
"MaxInt16": reflect.ValueOf(math.MaxInt16),
|
||||
"MaxInt32": reflect.ValueOf(math.MaxInt32),
|
||||
"MaxInt64": reflect.ValueOf(int64(math.MaxInt64)),
|
||||
"MaxInt8": reflect.ValueOf(math.MaxInt8),
|
||||
"MaxUint16": reflect.ValueOf(math.MaxUint16),
|
||||
"MaxUint32": reflect.ValueOf(uint32(math.MaxUint32)),
|
||||
"MaxUint64": reflect.ValueOf(uint64(math.MaxUint64)),
|
||||
"MaxUint8": reflect.ValueOf(math.MaxUint8),
|
||||
"MaxFloat32": reflect.ValueOf(constant.MakeFromLiteral("340282346638528859811704183484516925440", token.FLOAT, 0)),
|
||||
"MaxFloat64": reflect.ValueOf(constant.MakeFromLiteral("179769313486231570814527423731704356798100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", token.FLOAT, 0)),
|
||||
"MaxInt16": reflect.ValueOf(constant.MakeFromLiteral("32767", token.INT, 0)),
|
||||
"MaxInt32": reflect.ValueOf(constant.MakeFromLiteral("2147483647", token.INT, 0)),
|
||||
"MaxInt64": reflect.ValueOf(constant.MakeFromLiteral("9223372036854775807", token.INT, 0)),
|
||||
"MaxInt8": reflect.ValueOf(constant.MakeFromLiteral("127", token.INT, 0)),
|
||||
"MaxUint16": reflect.ValueOf(constant.MakeFromLiteral("65535", token.INT, 0)),
|
||||
"MaxUint32": reflect.ValueOf(constant.MakeFromLiteral("4294967295", token.INT, 0)),
|
||||
"MaxUint64": reflect.ValueOf(constant.MakeFromLiteral("18446744073709551615", token.INT, 0)),
|
||||
"MaxUint8": reflect.ValueOf(constant.MakeFromLiteral("255", token.INT, 0)),
|
||||
"Min": reflect.ValueOf(math.Min),
|
||||
"MinInt16": reflect.ValueOf(math.MinInt16),
|
||||
"MinInt32": reflect.ValueOf(math.MinInt32),
|
||||
"MinInt64": reflect.ValueOf(int64(math.MinInt64)),
|
||||
"MinInt8": reflect.ValueOf(math.MinInt8),
|
||||
"MinInt16": reflect.ValueOf(constant.MakeFromLiteral("-32768", token.INT, 0)),
|
||||
"MinInt32": reflect.ValueOf(constant.MakeFromLiteral("-2147483648", token.INT, 0)),
|
||||
"MinInt64": reflect.ValueOf(constant.MakeFromLiteral("-9223372036854775808", token.INT, 0)),
|
||||
"MinInt8": reflect.ValueOf(constant.MakeFromLiteral("-128", token.INT, 0)),
|
||||
"Mod": reflect.ValueOf(math.Mod),
|
||||
"Modf": reflect.ValueOf(math.Modf),
|
||||
"NaN": reflect.ValueOf(math.NaN),
|
||||
"Nextafter": reflect.ValueOf(math.Nextafter),
|
||||
"Nextafter32": reflect.ValueOf(math.Nextafter32),
|
||||
"Phi": reflect.ValueOf(math.Phi),
|
||||
"Pi": reflect.ValueOf(math.Pi),
|
||||
"Phi": reflect.ValueOf(constant.MakeFromLiteral("1.6180339887498948482045868343656381177203091798057628621354486119746080982153796619881086049305501566952211682590824739205931370737029882996587050475921915678674035433959321750307935872115194797515869140625", token.FLOAT, 0)),
|
||||
"Pi": reflect.ValueOf(constant.MakeFromLiteral("3.141592653589793238462643383279502884197169399375105820974944594789982923695635954704435713335896673485663389728754819466702315787113662862838515639906529162340867271374644786874341662041842937469482421875", token.FLOAT, 0)),
|
||||
"Pow": reflect.ValueOf(math.Pow),
|
||||
"Pow10": reflect.ValueOf(math.Pow10),
|
||||
"Remainder": reflect.ValueOf(math.Remainder),
|
||||
@@ -92,13 +94,13 @@ func init() {
|
||||
"Sin": reflect.ValueOf(math.Sin),
|
||||
"Sincos": reflect.ValueOf(math.Sincos),
|
||||
"Sinh": reflect.ValueOf(math.Sinh),
|
||||
"SmallestNonzeroFloat32": reflect.ValueOf(math.SmallestNonzeroFloat32),
|
||||
"SmallestNonzeroFloat64": reflect.ValueOf(math.SmallestNonzeroFloat64),
|
||||
"SmallestNonzeroFloat32": reflect.ValueOf(constant.MakeFromLiteral("1.40129846432481707092372958328991613128000000000000000000000000000000000000000000001246655487714533538006789189734126694785975183981128816138510360971472225738624150874949653910667523779981133927289771669016713539217953030564201688027906006008453304556102801950542906382507e-45", token.FLOAT, 0)),
|
||||
"SmallestNonzeroFloat64": reflect.ValueOf(constant.MakeFromLiteral("4.94065645841246544176568792868221372365099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999916206614696136086629714037163874026187912451674985660337336755242863513549746484310667379088263176934591818322489862214324814281481943599945502119376688748731948897748561110123901991443297110206447991752071007926740839424145013355231935665542622515363894390826799291671723318261174778903704064716351336223785714389641180220184242018383103204287325861250404139399888498504162666394779407509786431980433771341978183418568838015304951087487907666317075235615216699116844779095660202193409146032665221882798856203896125090454090026556150624798681464913851491093798848436664885581161128190046248588053014958829424991704801027040654863867512297941601850496672190315253109308532379657238854928816482120688440415705411555019932096150435627305446214567713171657554140575630917301482608119551500514805985376055777894871863446222606532650275466165274006e-324", token.FLOAT, 0)),
|
||||
"Sqrt": reflect.ValueOf(math.Sqrt),
|
||||
"Sqrt2": reflect.ValueOf(math.Sqrt2),
|
||||
"SqrtE": reflect.ValueOf(math.SqrtE),
|
||||
"SqrtPhi": reflect.ValueOf(math.SqrtPhi),
|
||||
"SqrtPi": reflect.ValueOf(math.SqrtPi),
|
||||
"Sqrt2": reflect.ValueOf(constant.MakeFromLiteral("1.414213562373095048801688724209698078569671875376948073176679739576083351575381440094441524123797447886801949755143139115339040409162552642832693297721230919563348109313505318596071447245776653289794921875", token.FLOAT, 0)),
|
||||
"SqrtE": reflect.ValueOf(constant.MakeFromLiteral("1.64872127070012814684865078781416357165377610071014801157507931167328763229187870850146925823776361770041160388013884200789716007979526823569827080974091691342077871211546646890155898290686309337615966796875", token.FLOAT, 0)),
|
||||
"SqrtPhi": reflect.ValueOf(constant.MakeFromLiteral("1.2720196495140689642524224617374914917156080418400962486166403754616080542166459302584536396369727769747312116100875915825863540562126478288118732191412003988041797518382391984914647764526307582855224609375", token.FLOAT, 0)),
|
||||
"SqrtPi": reflect.ValueOf(constant.MakeFromLiteral("1.772453850905516027298167483341145182797549456122387128213807789740599698370237052541269446184448945647349951047154197675245574635259260134350885938555625028620527962319730619356050738133490085601806640625", token.FLOAT, 0)),
|
||||
"Tan": reflect.ValueOf(math.Tan),
|
||||
"Tanh": reflect.ValueOf(math.Tanh),
|
||||
"Trunc": reflect.ValueOf(math.Trunc),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"math/big"
|
||||
"reflect"
|
||||
)
|
||||
@@ -17,10 +19,10 @@ func init() {
|
||||
"Below": reflect.ValueOf(big.Below),
|
||||
"Exact": reflect.ValueOf(big.Exact),
|
||||
"Jacobi": reflect.ValueOf(big.Jacobi),
|
||||
"MaxBase": reflect.ValueOf(big.MaxBase),
|
||||
"MaxExp": reflect.ValueOf(big.MaxExp),
|
||||
"MaxPrec": reflect.ValueOf(uint32(big.MaxPrec)),
|
||||
"MinExp": reflect.ValueOf(big.MinExp),
|
||||
"MaxBase": reflect.ValueOf(constant.MakeFromLiteral("62", token.INT, 0)),
|
||||
"MaxExp": reflect.ValueOf(constant.MakeFromLiteral("2147483647", token.INT, 0)),
|
||||
"MaxPrec": reflect.ValueOf(constant.MakeFromLiteral("4294967295", token.INT, 0)),
|
||||
"MinExp": reflect.ValueOf(constant.MakeFromLiteral("-2147483648", token.INT, 0)),
|
||||
"NewFloat": reflect.ValueOf(big.NewFloat),
|
||||
"NewInt": reflect.ValueOf(big.NewInt),
|
||||
"NewRat": reflect.ValueOf(big.NewRat),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"math/bits"
|
||||
"reflect"
|
||||
)
|
||||
@@ -58,6 +60,6 @@ func init() {
|
||||
"TrailingZeros32": reflect.ValueOf(bits.TrailingZeros32),
|
||||
"TrailingZeros64": reflect.ValueOf(bits.TrailingZeros64),
|
||||
"TrailingZeros8": reflect.ValueOf(bits.TrailingZeros8),
|
||||
"UintSize": reflect.ValueOf(bits.UintSize),
|
||||
"UintSize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"net"
|
||||
"reflect"
|
||||
"time"
|
||||
@@ -35,10 +37,10 @@ func init() {
|
||||
"IPv4allrouter": reflect.ValueOf(&net.IPv4allrouter).Elem(),
|
||||
"IPv4allsys": reflect.ValueOf(&net.IPv4allsys).Elem(),
|
||||
"IPv4bcast": reflect.ValueOf(&net.IPv4bcast).Elem(),
|
||||
"IPv4len": reflect.ValueOf(net.IPv4len),
|
||||
"IPv4len": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"IPv4zero": reflect.ValueOf(&net.IPv4zero).Elem(),
|
||||
"IPv6interfacelocalallnodes": reflect.ValueOf(&net.IPv6interfacelocalallnodes).Elem(),
|
||||
"IPv6len": reflect.ValueOf(net.IPv6len),
|
||||
"IPv6len": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"IPv6linklocalallnodes": reflect.ValueOf(&net.IPv6linklocalallnodes).Elem(),
|
||||
"IPv6linklocalallrouters": reflect.ValueOf(&net.IPv6linklocalallrouters).Elem(),
|
||||
"IPv6loopback": reflect.ValueOf(&net.IPv6loopback).Elem(),
|
||||
|
||||
@@ -6,6 +6,8 @@ package stdlib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -18,8 +20,8 @@ func init() {
|
||||
// function, constant and variable definitions
|
||||
"CanonicalHeaderKey": reflect.ValueOf(http.CanonicalHeaderKey),
|
||||
"DefaultClient": reflect.ValueOf(&http.DefaultClient).Elem(),
|
||||
"DefaultMaxHeaderBytes": reflect.ValueOf(http.DefaultMaxHeaderBytes),
|
||||
"DefaultMaxIdleConnsPerHost": reflect.ValueOf(http.DefaultMaxIdleConnsPerHost),
|
||||
"DefaultMaxHeaderBytes": reflect.ValueOf(constant.MakeFromLiteral("1048576", token.INT, 0)),
|
||||
"DefaultMaxIdleConnsPerHost": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"DefaultServeMux": reflect.ValueOf(&http.DefaultServeMux).Elem(),
|
||||
"DefaultTransport": reflect.ValueOf(&http.DefaultTransport).Elem(),
|
||||
"DetectContentType": reflect.ValueOf(http.DetectContentType),
|
||||
@@ -95,69 +97,69 @@ func init() {
|
||||
"StateHijacked": reflect.ValueOf(http.StateHijacked),
|
||||
"StateIdle": reflect.ValueOf(http.StateIdle),
|
||||
"StateNew": reflect.ValueOf(http.StateNew),
|
||||
"StatusAccepted": reflect.ValueOf(http.StatusAccepted),
|
||||
"StatusAlreadyReported": reflect.ValueOf(http.StatusAlreadyReported),
|
||||
"StatusBadGateway": reflect.ValueOf(http.StatusBadGateway),
|
||||
"StatusBadRequest": reflect.ValueOf(http.StatusBadRequest),
|
||||
"StatusConflict": reflect.ValueOf(http.StatusConflict),
|
||||
"StatusContinue": reflect.ValueOf(http.StatusContinue),
|
||||
"StatusCreated": reflect.ValueOf(http.StatusCreated),
|
||||
"StatusEarlyHints": reflect.ValueOf(http.StatusEarlyHints),
|
||||
"StatusExpectationFailed": reflect.ValueOf(http.StatusExpectationFailed),
|
||||
"StatusFailedDependency": reflect.ValueOf(http.StatusFailedDependency),
|
||||
"StatusForbidden": reflect.ValueOf(http.StatusForbidden),
|
||||
"StatusFound": reflect.ValueOf(http.StatusFound),
|
||||
"StatusGatewayTimeout": reflect.ValueOf(http.StatusGatewayTimeout),
|
||||
"StatusGone": reflect.ValueOf(http.StatusGone),
|
||||
"StatusHTTPVersionNotSupported": reflect.ValueOf(http.StatusHTTPVersionNotSupported),
|
||||
"StatusIMUsed": reflect.ValueOf(http.StatusIMUsed),
|
||||
"StatusInsufficientStorage": reflect.ValueOf(http.StatusInsufficientStorage),
|
||||
"StatusInternalServerError": reflect.ValueOf(http.StatusInternalServerError),
|
||||
"StatusLengthRequired": reflect.ValueOf(http.StatusLengthRequired),
|
||||
"StatusLocked": reflect.ValueOf(http.StatusLocked),
|
||||
"StatusLoopDetected": reflect.ValueOf(http.StatusLoopDetected),
|
||||
"StatusMethodNotAllowed": reflect.ValueOf(http.StatusMethodNotAllowed),
|
||||
"StatusMisdirectedRequest": reflect.ValueOf(http.StatusMisdirectedRequest),
|
||||
"StatusMovedPermanently": reflect.ValueOf(http.StatusMovedPermanently),
|
||||
"StatusMultiStatus": reflect.ValueOf(http.StatusMultiStatus),
|
||||
"StatusMultipleChoices": reflect.ValueOf(http.StatusMultipleChoices),
|
||||
"StatusNetworkAuthenticationRequired": reflect.ValueOf(http.StatusNetworkAuthenticationRequired),
|
||||
"StatusNoContent": reflect.ValueOf(http.StatusNoContent),
|
||||
"StatusNonAuthoritativeInfo": reflect.ValueOf(http.StatusNonAuthoritativeInfo),
|
||||
"StatusNotAcceptable": reflect.ValueOf(http.StatusNotAcceptable),
|
||||
"StatusNotExtended": reflect.ValueOf(http.StatusNotExtended),
|
||||
"StatusNotFound": reflect.ValueOf(http.StatusNotFound),
|
||||
"StatusNotImplemented": reflect.ValueOf(http.StatusNotImplemented),
|
||||
"StatusNotModified": reflect.ValueOf(http.StatusNotModified),
|
||||
"StatusOK": reflect.ValueOf(http.StatusOK),
|
||||
"StatusPartialContent": reflect.ValueOf(http.StatusPartialContent),
|
||||
"StatusPaymentRequired": reflect.ValueOf(http.StatusPaymentRequired),
|
||||
"StatusPermanentRedirect": reflect.ValueOf(http.StatusPermanentRedirect),
|
||||
"StatusPreconditionFailed": reflect.ValueOf(http.StatusPreconditionFailed),
|
||||
"StatusPreconditionRequired": reflect.ValueOf(http.StatusPreconditionRequired),
|
||||
"StatusProcessing": reflect.ValueOf(http.StatusProcessing),
|
||||
"StatusProxyAuthRequired": reflect.ValueOf(http.StatusProxyAuthRequired),
|
||||
"StatusRequestEntityTooLarge": reflect.ValueOf(http.StatusRequestEntityTooLarge),
|
||||
"StatusRequestHeaderFieldsTooLarge": reflect.ValueOf(http.StatusRequestHeaderFieldsTooLarge),
|
||||
"StatusRequestTimeout": reflect.ValueOf(http.StatusRequestTimeout),
|
||||
"StatusRequestURITooLong": reflect.ValueOf(http.StatusRequestURITooLong),
|
||||
"StatusRequestedRangeNotSatisfiable": reflect.ValueOf(http.StatusRequestedRangeNotSatisfiable),
|
||||
"StatusResetContent": reflect.ValueOf(http.StatusResetContent),
|
||||
"StatusSeeOther": reflect.ValueOf(http.StatusSeeOther),
|
||||
"StatusServiceUnavailable": reflect.ValueOf(http.StatusServiceUnavailable),
|
||||
"StatusSwitchingProtocols": reflect.ValueOf(http.StatusSwitchingProtocols),
|
||||
"StatusTeapot": reflect.ValueOf(http.StatusTeapot),
|
||||
"StatusTemporaryRedirect": reflect.ValueOf(http.StatusTemporaryRedirect),
|
||||
"StatusAccepted": reflect.ValueOf(constant.MakeFromLiteral("202", token.INT, 0)),
|
||||
"StatusAlreadyReported": reflect.ValueOf(constant.MakeFromLiteral("208", token.INT, 0)),
|
||||
"StatusBadGateway": reflect.ValueOf(constant.MakeFromLiteral("502", token.INT, 0)),
|
||||
"StatusBadRequest": reflect.ValueOf(constant.MakeFromLiteral("400", token.INT, 0)),
|
||||
"StatusConflict": reflect.ValueOf(constant.MakeFromLiteral("409", token.INT, 0)),
|
||||
"StatusContinue": reflect.ValueOf(constant.MakeFromLiteral("100", token.INT, 0)),
|
||||
"StatusCreated": reflect.ValueOf(constant.MakeFromLiteral("201", token.INT, 0)),
|
||||
"StatusEarlyHints": reflect.ValueOf(constant.MakeFromLiteral("103", token.INT, 0)),
|
||||
"StatusExpectationFailed": reflect.ValueOf(constant.MakeFromLiteral("417", token.INT, 0)),
|
||||
"StatusFailedDependency": reflect.ValueOf(constant.MakeFromLiteral("424", token.INT, 0)),
|
||||
"StatusForbidden": reflect.ValueOf(constant.MakeFromLiteral("403", token.INT, 0)),
|
||||
"StatusFound": reflect.ValueOf(constant.MakeFromLiteral("302", token.INT, 0)),
|
||||
"StatusGatewayTimeout": reflect.ValueOf(constant.MakeFromLiteral("504", token.INT, 0)),
|
||||
"StatusGone": reflect.ValueOf(constant.MakeFromLiteral("410", token.INT, 0)),
|
||||
"StatusHTTPVersionNotSupported": reflect.ValueOf(constant.MakeFromLiteral("505", token.INT, 0)),
|
||||
"StatusIMUsed": reflect.ValueOf(constant.MakeFromLiteral("226", token.INT, 0)),
|
||||
"StatusInsufficientStorage": reflect.ValueOf(constant.MakeFromLiteral("507", token.INT, 0)),
|
||||
"StatusInternalServerError": reflect.ValueOf(constant.MakeFromLiteral("500", token.INT, 0)),
|
||||
"StatusLengthRequired": reflect.ValueOf(constant.MakeFromLiteral("411", token.INT, 0)),
|
||||
"StatusLocked": reflect.ValueOf(constant.MakeFromLiteral("423", token.INT, 0)),
|
||||
"StatusLoopDetected": reflect.ValueOf(constant.MakeFromLiteral("508", token.INT, 0)),
|
||||
"StatusMethodNotAllowed": reflect.ValueOf(constant.MakeFromLiteral("405", token.INT, 0)),
|
||||
"StatusMisdirectedRequest": reflect.ValueOf(constant.MakeFromLiteral("421", token.INT, 0)),
|
||||
"StatusMovedPermanently": reflect.ValueOf(constant.MakeFromLiteral("301", token.INT, 0)),
|
||||
"StatusMultiStatus": reflect.ValueOf(constant.MakeFromLiteral("207", token.INT, 0)),
|
||||
"StatusMultipleChoices": reflect.ValueOf(constant.MakeFromLiteral("300", token.INT, 0)),
|
||||
"StatusNetworkAuthenticationRequired": reflect.ValueOf(constant.MakeFromLiteral("511", token.INT, 0)),
|
||||
"StatusNoContent": reflect.ValueOf(constant.MakeFromLiteral("204", token.INT, 0)),
|
||||
"StatusNonAuthoritativeInfo": reflect.ValueOf(constant.MakeFromLiteral("203", token.INT, 0)),
|
||||
"StatusNotAcceptable": reflect.ValueOf(constant.MakeFromLiteral("406", token.INT, 0)),
|
||||
"StatusNotExtended": reflect.ValueOf(constant.MakeFromLiteral("510", token.INT, 0)),
|
||||
"StatusNotFound": reflect.ValueOf(constant.MakeFromLiteral("404", token.INT, 0)),
|
||||
"StatusNotImplemented": reflect.ValueOf(constant.MakeFromLiteral("501", token.INT, 0)),
|
||||
"StatusNotModified": reflect.ValueOf(constant.MakeFromLiteral("304", token.INT, 0)),
|
||||
"StatusOK": reflect.ValueOf(constant.MakeFromLiteral("200", token.INT, 0)),
|
||||
"StatusPartialContent": reflect.ValueOf(constant.MakeFromLiteral("206", token.INT, 0)),
|
||||
"StatusPaymentRequired": reflect.ValueOf(constant.MakeFromLiteral("402", token.INT, 0)),
|
||||
"StatusPermanentRedirect": reflect.ValueOf(constant.MakeFromLiteral("308", token.INT, 0)),
|
||||
"StatusPreconditionFailed": reflect.ValueOf(constant.MakeFromLiteral("412", token.INT, 0)),
|
||||
"StatusPreconditionRequired": reflect.ValueOf(constant.MakeFromLiteral("428", token.INT, 0)),
|
||||
"StatusProcessing": reflect.ValueOf(constant.MakeFromLiteral("102", token.INT, 0)),
|
||||
"StatusProxyAuthRequired": reflect.ValueOf(constant.MakeFromLiteral("407", token.INT, 0)),
|
||||
"StatusRequestEntityTooLarge": reflect.ValueOf(constant.MakeFromLiteral("413", token.INT, 0)),
|
||||
"StatusRequestHeaderFieldsTooLarge": reflect.ValueOf(constant.MakeFromLiteral("431", token.INT, 0)),
|
||||
"StatusRequestTimeout": reflect.ValueOf(constant.MakeFromLiteral("408", token.INT, 0)),
|
||||
"StatusRequestURITooLong": reflect.ValueOf(constant.MakeFromLiteral("414", token.INT, 0)),
|
||||
"StatusRequestedRangeNotSatisfiable": reflect.ValueOf(constant.MakeFromLiteral("416", token.INT, 0)),
|
||||
"StatusResetContent": reflect.ValueOf(constant.MakeFromLiteral("205", token.INT, 0)),
|
||||
"StatusSeeOther": reflect.ValueOf(constant.MakeFromLiteral("303", token.INT, 0)),
|
||||
"StatusServiceUnavailable": reflect.ValueOf(constant.MakeFromLiteral("503", token.INT, 0)),
|
||||
"StatusSwitchingProtocols": reflect.ValueOf(constant.MakeFromLiteral("101", token.INT, 0)),
|
||||
"StatusTeapot": reflect.ValueOf(constant.MakeFromLiteral("418", token.INT, 0)),
|
||||
"StatusTemporaryRedirect": reflect.ValueOf(constant.MakeFromLiteral("307", token.INT, 0)),
|
||||
"StatusText": reflect.ValueOf(http.StatusText),
|
||||
"StatusTooEarly": reflect.ValueOf(http.StatusTooEarly),
|
||||
"StatusTooManyRequests": reflect.ValueOf(http.StatusTooManyRequests),
|
||||
"StatusUnauthorized": reflect.ValueOf(http.StatusUnauthorized),
|
||||
"StatusUnavailableForLegalReasons": reflect.ValueOf(http.StatusUnavailableForLegalReasons),
|
||||
"StatusUnprocessableEntity": reflect.ValueOf(http.StatusUnprocessableEntity),
|
||||
"StatusUnsupportedMediaType": reflect.ValueOf(http.StatusUnsupportedMediaType),
|
||||
"StatusUpgradeRequired": reflect.ValueOf(http.StatusUpgradeRequired),
|
||||
"StatusUseProxy": reflect.ValueOf(http.StatusUseProxy),
|
||||
"StatusVariantAlsoNegotiates": reflect.ValueOf(http.StatusVariantAlsoNegotiates),
|
||||
"StatusTooEarly": reflect.ValueOf(constant.MakeFromLiteral("425", token.INT, 0)),
|
||||
"StatusTooManyRequests": reflect.ValueOf(constant.MakeFromLiteral("429", token.INT, 0)),
|
||||
"StatusUnauthorized": reflect.ValueOf(constant.MakeFromLiteral("401", token.INT, 0)),
|
||||
"StatusUnavailableForLegalReasons": reflect.ValueOf(constant.MakeFromLiteral("451", token.INT, 0)),
|
||||
"StatusUnprocessableEntity": reflect.ValueOf(constant.MakeFromLiteral("422", token.INT, 0)),
|
||||
"StatusUnsupportedMediaType": reflect.ValueOf(constant.MakeFromLiteral("415", token.INT, 0)),
|
||||
"StatusUpgradeRequired": reflect.ValueOf(constant.MakeFromLiteral("426", token.INT, 0)),
|
||||
"StatusUseProxy": reflect.ValueOf(constant.MakeFromLiteral("305", token.INT, 0)),
|
||||
"StatusVariantAlsoNegotiates": reflect.ValueOf(constant.MakeFromLiteral("506", token.INT, 0)),
|
||||
"StripPrefix": reflect.ValueOf(http.StripPrefix),
|
||||
"TimeFormat": reflect.ValueOf(http.TimeFormat),
|
||||
"TimeoutHandler": reflect.ValueOf(http.TimeoutHandler),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
@@ -84,8 +86,8 @@ func init() {
|
||||
"O_WRONLY": reflect.ValueOf(os.O_WRONLY),
|
||||
"Open": reflect.ValueOf(os.Open),
|
||||
"OpenFile": reflect.ValueOf(os.OpenFile),
|
||||
"PathListSeparator": reflect.ValueOf(os.PathListSeparator),
|
||||
"PathSeparator": reflect.ValueOf(os.PathSeparator),
|
||||
"PathListSeparator": reflect.ValueOf(constant.MakeFromLiteral("58", token.INT, 0)),
|
||||
"PathSeparator": reflect.ValueOf(constant.MakeFromLiteral("47", token.INT, 0)),
|
||||
"Pipe": reflect.ValueOf(os.Pipe),
|
||||
"Readlink": reflect.ValueOf(os.Readlink),
|
||||
"Remove": reflect.ValueOf(os.Remove),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
)
|
||||
@@ -24,10 +26,10 @@ func init() {
|
||||
"HasPrefix": reflect.ValueOf(filepath.HasPrefix),
|
||||
"IsAbs": reflect.ValueOf(filepath.IsAbs),
|
||||
"Join": reflect.ValueOf(filepath.Join),
|
||||
"ListSeparator": reflect.ValueOf(filepath.ListSeparator),
|
||||
"ListSeparator": reflect.ValueOf(constant.MakeFromLiteral("58", token.INT, 0)),
|
||||
"Match": reflect.ValueOf(filepath.Match),
|
||||
"Rel": reflect.ValueOf(filepath.Rel),
|
||||
"Separator": reflect.ValueOf(filepath.Separator),
|
||||
"Separator": reflect.ValueOf(constant.MakeFromLiteral("47", token.INT, 0)),
|
||||
"SkipDir": reflect.ValueOf(&filepath.SkipDir).Elem(),
|
||||
"Split": reflect.ValueOf(filepath.Split),
|
||||
"SplitList": reflect.ValueOf(filepath.SplitList),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
@@ -30,7 +32,7 @@ func init() {
|
||||
"FormatFloat": reflect.ValueOf(strconv.FormatFloat),
|
||||
"FormatInt": reflect.ValueOf(strconv.FormatInt),
|
||||
"FormatUint": reflect.ValueOf(strconv.FormatUint),
|
||||
"IntSize": reflect.ValueOf(strconv.IntSize),
|
||||
"IntSize": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"IsGraphic": reflect.ValueOf(strconv.IsGraphic),
|
||||
"IsPrint": reflect.ValueOf(strconv.IsPrint),
|
||||
"Itoa": reflect.ValueOf(strconv.Itoa),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
"text/scanner"
|
||||
)
|
||||
@@ -12,24 +14,24 @@ import (
|
||||
func init() {
|
||||
Symbols["text/scanner"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"Char": reflect.ValueOf(scanner.Char),
|
||||
"Comment": reflect.ValueOf(scanner.Comment),
|
||||
"EOF": reflect.ValueOf(scanner.EOF),
|
||||
"Float": reflect.ValueOf(scanner.Float),
|
||||
"GoTokens": reflect.ValueOf(scanner.GoTokens),
|
||||
"GoWhitespace": reflect.ValueOf(int64(scanner.GoWhitespace)),
|
||||
"Ident": reflect.ValueOf(scanner.Ident),
|
||||
"Int": reflect.ValueOf(scanner.Int),
|
||||
"RawString": reflect.ValueOf(scanner.RawString),
|
||||
"ScanChars": reflect.ValueOf(scanner.ScanChars),
|
||||
"ScanComments": reflect.ValueOf(scanner.ScanComments),
|
||||
"ScanFloats": reflect.ValueOf(scanner.ScanFloats),
|
||||
"ScanIdents": reflect.ValueOf(scanner.ScanIdents),
|
||||
"ScanInts": reflect.ValueOf(scanner.ScanInts),
|
||||
"ScanRawStrings": reflect.ValueOf(scanner.ScanRawStrings),
|
||||
"ScanStrings": reflect.ValueOf(scanner.ScanStrings),
|
||||
"SkipComments": reflect.ValueOf(scanner.SkipComments),
|
||||
"String": reflect.ValueOf(scanner.String),
|
||||
"Char": reflect.ValueOf(constant.MakeFromLiteral("-5", token.INT, 0)),
|
||||
"Comment": reflect.ValueOf(constant.MakeFromLiteral("-8", token.INT, 0)),
|
||||
"EOF": reflect.ValueOf(constant.MakeFromLiteral("-1", token.INT, 0)),
|
||||
"Float": reflect.ValueOf(constant.MakeFromLiteral("-4", token.INT, 0)),
|
||||
"GoTokens": reflect.ValueOf(constant.MakeFromLiteral("1012", token.INT, 0)),
|
||||
"GoWhitespace": reflect.ValueOf(constant.MakeFromLiteral("4294977024", token.INT, 0)),
|
||||
"Ident": reflect.ValueOf(constant.MakeFromLiteral("-2", token.INT, 0)),
|
||||
"Int": reflect.ValueOf(constant.MakeFromLiteral("-3", token.INT, 0)),
|
||||
"RawString": reflect.ValueOf(constant.MakeFromLiteral("-7", token.INT, 0)),
|
||||
"ScanChars": reflect.ValueOf(constant.MakeFromLiteral("32", token.INT, 0)),
|
||||
"ScanComments": reflect.ValueOf(constant.MakeFromLiteral("256", token.INT, 0)),
|
||||
"ScanFloats": reflect.ValueOf(constant.MakeFromLiteral("16", token.INT, 0)),
|
||||
"ScanIdents": reflect.ValueOf(constant.MakeFromLiteral("4", token.INT, 0)),
|
||||
"ScanInts": reflect.ValueOf(constant.MakeFromLiteral("8", token.INT, 0)),
|
||||
"ScanRawStrings": reflect.ValueOf(constant.MakeFromLiteral("128", token.INT, 0)),
|
||||
"ScanStrings": reflect.ValueOf(constant.MakeFromLiteral("64", token.INT, 0)),
|
||||
"SkipComments": reflect.ValueOf(constant.MakeFromLiteral("512", token.INT, 0)),
|
||||
"String": reflect.ValueOf(constant.MakeFromLiteral("-6", token.INT, 0)),
|
||||
"TokenString": reflect.ValueOf(scanner.TokenString),
|
||||
|
||||
// type definitions
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
"text/tabwriter"
|
||||
)
|
||||
@@ -15,7 +17,7 @@ func init() {
|
||||
"AlignRight": reflect.ValueOf(tabwriter.AlignRight),
|
||||
"Debug": reflect.ValueOf(tabwriter.Debug),
|
||||
"DiscardEmptyColumns": reflect.ValueOf(tabwriter.DiscardEmptyColumns),
|
||||
"Escape": reflect.ValueOf(tabwriter.Escape),
|
||||
"Escape": reflect.ValueOf(constant.MakeFromLiteral("255", token.INT, 0)),
|
||||
"FilterHTML": reflect.ValueOf(tabwriter.FilterHTML),
|
||||
"NewWriter": reflect.ValueOf(tabwriter.NewWriter),
|
||||
"StripEscape": reflect.ValueOf(tabwriter.StripEscape),
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package stdlib
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
"unicode"
|
||||
)
|
||||
@@ -129,7 +131,7 @@ func init() {
|
||||
"Lo": reflect.ValueOf(&unicode.Lo).Elem(),
|
||||
"Logical_Order_Exception": reflect.ValueOf(&unicode.Logical_Order_Exception).Elem(),
|
||||
"Lower": reflect.ValueOf(&unicode.Lower).Elem(),
|
||||
"LowerCase": reflect.ValueOf(unicode.LowerCase),
|
||||
"LowerCase": reflect.ValueOf(constant.MakeFromLiteral("1", token.INT, 0)),
|
||||
"Lt": reflect.ValueOf(&unicode.Lt).Elem(),
|
||||
"Lu": reflect.ValueOf(&unicode.Lu).Elem(),
|
||||
"Lycian": reflect.ValueOf(&unicode.Lycian).Elem(),
|
||||
@@ -143,10 +145,10 @@ func init() {
|
||||
"Marchen": reflect.ValueOf(&unicode.Marchen).Elem(),
|
||||
"Mark": reflect.ValueOf(&unicode.Mark).Elem(),
|
||||
"Masaram_Gondi": reflect.ValueOf(&unicode.Masaram_Gondi).Elem(),
|
||||
"MaxASCII": reflect.ValueOf(unicode.MaxASCII),
|
||||
"MaxCase": reflect.ValueOf(unicode.MaxCase),
|
||||
"MaxLatin1": reflect.ValueOf(unicode.MaxLatin1),
|
||||
"MaxRune": reflect.ValueOf(unicode.MaxRune),
|
||||
"MaxASCII": reflect.ValueOf(constant.MakeFromLiteral("127", token.INT, 0)),
|
||||
"MaxCase": reflect.ValueOf(constant.MakeFromLiteral("3", token.INT, 0)),
|
||||
"MaxLatin1": reflect.ValueOf(constant.MakeFromLiteral("255", token.INT, 0)),
|
||||
"MaxRune": reflect.ValueOf(constant.MakeFromLiteral("1114111", token.INT, 0)),
|
||||
"Mc": reflect.ValueOf(&unicode.Mc).Elem(),
|
||||
"Me": reflect.ValueOf(&unicode.Me).Elem(),
|
||||
"Medefaidrin": reflect.ValueOf(&unicode.Medefaidrin).Elem(),
|
||||
@@ -218,7 +220,7 @@ func init() {
|
||||
"Radical": reflect.ValueOf(&unicode.Radical).Elem(),
|
||||
"Regional_Indicator": reflect.ValueOf(&unicode.Regional_Indicator).Elem(),
|
||||
"Rejang": reflect.ValueOf(&unicode.Rejang).Elem(),
|
||||
"ReplacementChar": reflect.ValueOf(unicode.ReplacementChar),
|
||||
"ReplacementChar": reflect.ValueOf(constant.MakeFromLiteral("65533", token.INT, 0)),
|
||||
"Runic": reflect.ValueOf(&unicode.Runic).Elem(),
|
||||
"S": reflect.ValueOf(&unicode.S).Elem(),
|
||||
"STerm": reflect.ValueOf(&unicode.STerm).Elem(),
|
||||
@@ -261,7 +263,7 @@ func init() {
|
||||
"Tifinagh": reflect.ValueOf(&unicode.Tifinagh).Elem(),
|
||||
"Tirhuta": reflect.ValueOf(&unicode.Tirhuta).Elem(),
|
||||
"Title": reflect.ValueOf(&unicode.Title).Elem(),
|
||||
"TitleCase": reflect.ValueOf(unicode.TitleCase),
|
||||
"TitleCase": reflect.ValueOf(constant.MakeFromLiteral("2", token.INT, 0)),
|
||||
"To": reflect.ValueOf(unicode.To),
|
||||
"ToLower": reflect.ValueOf(unicode.ToLower),
|
||||
"ToTitle": reflect.ValueOf(unicode.ToTitle),
|
||||
@@ -270,8 +272,8 @@ func init() {
|
||||
"Ugaritic": reflect.ValueOf(&unicode.Ugaritic).Elem(),
|
||||
"Unified_Ideograph": reflect.ValueOf(&unicode.Unified_Ideograph).Elem(),
|
||||
"Upper": reflect.ValueOf(&unicode.Upper).Elem(),
|
||||
"UpperCase": reflect.ValueOf(unicode.UpperCase),
|
||||
"UpperLower": reflect.ValueOf(unicode.UpperLower),
|
||||
"UpperCase": reflect.ValueOf(constant.MakeFromLiteral("0", token.INT, 0)),
|
||||
"UpperLower": reflect.ValueOf(constant.MakeFromLiteral("1114112", token.INT, 0)),
|
||||
"Vai": reflect.ValueOf(&unicode.Vai).Elem(),
|
||||
"Variation_Selector": reflect.ValueOf(&unicode.Variation_Selector).Elem(),
|
||||
"Version": reflect.ValueOf(unicode.Version),
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user