From ab69cd9ba61092650abdff6484b12021182385ce Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 3 Mar 2025 10:49:27 +0100 Subject: fix: improve struct Use 'unsafe' to modify private struct fields, allowing to keep unmodified field names: before they were prefixed with a capital. Parse package statement. Provide a also a default package name for REPL and tests. The support of packages is still incomplete. --- vm/type.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'vm/type.go') diff --git a/vm/type.go b/vm/type.go index 49215db..7c33cd2 100644 --- a/vm/type.go +++ b/vm/type.go @@ -6,12 +6,16 @@ import "reflect" // Type is the representation of a runtime type. type Type struct { - Name string - Rtype reflect.Type + PkgPath string + Name string + Rtype reflect.Type } func (t *Type) String() string { if t.Name != "" { + if t.PkgPath != "" { + return t.PkgPath + "." + t.Name + } return t.Name } return t.Rtype.String() @@ -84,7 +88,8 @@ func FuncOf(arg, ret []*Type, variadic bool) *Type { func StructOf(fields []*Type) *Type { rf := make([]reflect.StructField, len(fields)) for i, f := range fields { - rf[i].Name = "X" + f.Name + rf[i].Name = f.Name + rf[i].PkgPath = f.PkgPath rf[i].Type = f.Rtype } return &Type{Rtype: reflect.StructOf(rf)} -- cgit v1.2.3