mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-13 03:10:03 -05:00
Merge pull request #448 from arv/new-serialization-default
NomDL: Make the new serialization default
This commit is contained in:
@@ -14,8 +14,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/garyburd/go-oauth/oauth"
|
||||
img "github.com/attic-labs/noms/clients/gen/sha1_4c734206e6aaef5464ff0e307c2f66751a1469de"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
img "github.com/attic-labs/noms/clients/gen/sha1_b525f9bca5e451c21dd9af564f0960045fbaa304"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
@@ -189,7 +189,7 @@ func getAlbums() MapOfStringToAlbum {
|
||||
return albums
|
||||
}
|
||||
|
||||
func getAlbumPhotos(id string) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
func getAlbumPhotos(id string) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
response := struct {
|
||||
flickrCall
|
||||
Photoset struct {
|
||||
@@ -226,7 +226,7 @@ func getAlbumPhotos(id string) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469d
|
||||
})
|
||||
d.Chk.NoError(err)
|
||||
|
||||
photos := NewSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto()
|
||||
photos := NewSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto()
|
||||
|
||||
for _, p := range response.Photoset.Photo {
|
||||
photo := img.RemotePhotoDef{
|
||||
|
||||
+131
-90
@@ -3,7 +3,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_4c734206e6aaef5464ff0e307c2f66751a1469de"
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_b525f9bca5e451c21dd9af564f0960045fbaa304"
|
||||
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
@@ -29,12 +30,12 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
[]types.Field{
|
||||
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Photos", types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef(ref.Parse("sha1-4c734206e6aaef5464ff0e307c2f66751a1469de"), 0)), false},
|
||||
types.Field{"Photos", types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef(ref.Parse("sha1-b525f9bca5e451c21dd9af564f0960045fbaa304"), 0)), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-4c734206e6aaef5464ff0e307c2f66751a1469de"),
|
||||
ref.Parse("sha1-b525f9bca5e451c21dd9af564f0960045fbaa304"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
@@ -42,7 +43,8 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
// User
|
||||
|
||||
type User struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewUser() User {
|
||||
@@ -52,8 +54,8 @@ func NewUser() User {
|
||||
types.NewString("Name"), types.NewString(""),
|
||||
types.NewString("OAuthToken"), types.NewString(""),
|
||||
types.NewString("OAuthSecret"), types.NewString(""),
|
||||
types.NewString("Albums"), types.NewMap(),
|
||||
)}
|
||||
types.NewString("Albums"), NewMapOfStringToAlbum(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
var __typeRefForUser = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0)
|
||||
@@ -63,29 +65,38 @@ func (m User) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForUser, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForUser, func(v types.Value) types.Value {
|
||||
return UserFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func UserFromVal(val types.Value) User {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(User); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return User{val.(types.Map)}
|
||||
return User{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s User) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s User) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s User) Equals(other types.Value) bool {
|
||||
if other, ok := other.(User); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s User) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s User) Chunks() (futures []types.Future) {
|
||||
@@ -99,7 +110,7 @@ func (s User) Id() string {
|
||||
}
|
||||
|
||||
func (s User) SetId(val string) User {
|
||||
return User{s.m.Set(types.NewString("Id"), types.NewString(val))}
|
||||
return User{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s User) Name() string {
|
||||
@@ -107,7 +118,7 @@ func (s User) Name() string {
|
||||
}
|
||||
|
||||
func (s User) SetName(val string) User {
|
||||
return User{s.m.Set(types.NewString("Name"), types.NewString(val))}
|
||||
return User{s.m.Set(types.NewString("Name"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s User) OAuthToken() string {
|
||||
@@ -115,7 +126,7 @@ func (s User) OAuthToken() string {
|
||||
}
|
||||
|
||||
func (s User) SetOAuthToken(val string) User {
|
||||
return User{s.m.Set(types.NewString("OAuthToken"), types.NewString(val))}
|
||||
return User{s.m.Set(types.NewString("OAuthToken"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s User) OAuthSecret() string {
|
||||
@@ -123,21 +134,22 @@ func (s User) OAuthSecret() string {
|
||||
}
|
||||
|
||||
func (s User) SetOAuthSecret(val string) User {
|
||||
return User{s.m.Set(types.NewString("OAuthSecret"), types.NewString(val))}
|
||||
return User{s.m.Set(types.NewString("OAuthSecret"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s User) Albums() MapOfStringToAlbum {
|
||||
return MapOfStringToAlbumFromVal(s.m.Get(types.NewString("Albums")))
|
||||
return s.m.Get(types.NewString("Albums")).(MapOfStringToAlbum)
|
||||
}
|
||||
|
||||
func (s User) SetAlbums(val MapOfStringToAlbum) User {
|
||||
return User{s.m.Set(types.NewString("Albums"), val.NomsValue())}
|
||||
return User{s.m.Set(types.NewString("Albums"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// Album
|
||||
|
||||
type Album struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewAlbum() Album {
|
||||
@@ -145,8 +157,8 @@ func NewAlbum() Album {
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("Id"), types.NewString(""),
|
||||
types.NewString("Title"), types.NewString(""),
|
||||
types.NewString("Photos"), types.NewSet(),
|
||||
)}
|
||||
types.NewString("Photos"), NewSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
var __typeRefForAlbum = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1)
|
||||
@@ -156,29 +168,38 @@ func (m Album) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForAlbum, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForAlbum, func(v types.Value) types.Value {
|
||||
return AlbumFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func AlbumFromVal(val types.Value) Album {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Album); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Album{val.(types.Map)}
|
||||
return Album{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Album) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Album) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Album) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Album); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Album) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Album) Chunks() (futures []types.Future) {
|
||||
@@ -192,7 +213,7 @@ func (s Album) Id() string {
|
||||
}
|
||||
|
||||
func (s Album) SetId(val string) Album {
|
||||
return Album{s.m.Set(types.NewString("Id"), types.NewString(val))}
|
||||
return Album{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Album) Title() string {
|
||||
@@ -200,45 +221,55 @@ func (s Album) Title() string {
|
||||
}
|
||||
|
||||
func (s Album) SetTitle(val string) Album {
|
||||
return Album{s.m.Set(types.NewString("Title"), types.NewString(val))}
|
||||
return Album{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Album) Photos() SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoFromVal(s.m.Get(types.NewString("Photos")))
|
||||
func (s Album) Photos() SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
return s.m.Get(types.NewString("Photos")).(SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto)
|
||||
}
|
||||
|
||||
func (s Album) SetPhotos(val SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Album {
|
||||
return Album{s.m.Set(types.NewString("Photos"), val.NomsValue())}
|
||||
func (s Album) SetPhotos(val SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Album {
|
||||
return Album{s.m.Set(types.NewString("Photos"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// MapOfStringToAlbum
|
||||
|
||||
type MapOfStringToAlbum struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToAlbum() MapOfStringToAlbum {
|
||||
return MapOfStringToAlbum{types.NewMap()}
|
||||
return MapOfStringToAlbum{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func MapOfStringToAlbumFromVal(p types.Value) MapOfStringToAlbum {
|
||||
func MapOfStringToAlbumFromVal(val types.Value) MapOfStringToAlbum {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToAlbum); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToAlbum{p.(types.Map)}
|
||||
return MapOfStringToAlbum{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToAlbum); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) Chunks() (futures []types.Future) {
|
||||
@@ -256,7 +287,7 @@ func (m MapOfStringToAlbum) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToAlbum = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToAlbum, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToAlbum, func(v types.Value) types.Value {
|
||||
return MapOfStringToAlbumFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -274,7 +305,7 @@ func (m MapOfStringToAlbum) Has(p string) bool {
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) Get(p string) Album {
|
||||
return AlbumFromVal(m.m.Get(types.NewString(p)))
|
||||
return m.m.Get(types.NewString(p)).(Album)
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) MaybeGet(p string) (Album, bool) {
|
||||
@@ -282,24 +313,24 @@ func (m MapOfStringToAlbum) MaybeGet(p string) (Album, bool) {
|
||||
if !ok {
|
||||
return NewAlbum(), false
|
||||
}
|
||||
return AlbumFromVal(v), ok
|
||||
return v.(Album), ok
|
||||
}
|
||||
|
||||
func (m MapOfStringToAlbum) Set(k string, v Album) MapOfStringToAlbum {
|
||||
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v.NomsValue())}
|
||||
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToAlbum) Remove(p string) MapOfStringToAlbum {
|
||||
return MapOfStringToAlbum{m.m.Remove(types.NewString(p))}
|
||||
return MapOfStringToAlbum{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToAlbumIterCallback func(k string, v Album) (stop bool)
|
||||
|
||||
func (m MapOfStringToAlbum) Iter(cb MapOfStringToAlbumIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(k.(types.String).String(), AlbumFromVal(v))
|
||||
return cb(k.(types.String).String(), v.(Album))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -307,7 +338,7 @@ type MapOfStringToAlbumIterAllCallback func(k string, v Album)
|
||||
|
||||
func (m MapOfStringToAlbum) IterAll(cb MapOfStringToAlbumIterAllCallback) {
|
||||
m.m.IterAll(func(k, v types.Value) {
|
||||
cb(k.(types.String).String(), AlbumFromVal(v))
|
||||
cb(k.(types.String).String(), v.(Album))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -323,88 +354,98 @@ func (m MapOfStringToAlbum) Filter(cb MapOfStringToAlbumFilterCallback) MapOfStr
|
||||
return nm
|
||||
}
|
||||
|
||||
// SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto
|
||||
// SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto
|
||||
|
||||
type SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto struct {
|
||||
s types.Set
|
||||
type SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto struct {
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto() SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto{types.NewSet()}
|
||||
func NewSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto() SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoFromVal(p types.Value) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto{p.(types.Set)}
|
||||
func SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoFromVal(val types.Value) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) NomsValue() types.Value {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto); ok {
|
||||
return s.s.Equals(other.s)
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Chunks() (futures []types.Future) {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.s.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto.
|
||||
var __typeRefForSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto types.TypeRef
|
||||
// A Noms Value that describes SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto.
|
||||
var __typeRefForSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto types.TypeRef
|
||||
|
||||
func (m SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) TypeRef() types.TypeRef {
|
||||
return __typeRefForSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto
|
||||
func (m SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) TypeRef() types.TypeRef {
|
||||
return __typeRefForSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef(ref.Parse("sha1-4c734206e6aaef5464ff0e307c2f66751a1469de"), 0))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto, func(v types.Value) types.NomsValue {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoFromVal(v)
|
||||
__typeRefForSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef(ref.Parse("sha1-b525f9bca5e451c21dd9af564f0960045fbaa304"), 0))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto, func(v types.Value) types.Value {
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Empty() bool {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Empty() bool {
|
||||
return s.s.Empty()
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Len() uint64 {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Len() uint64 {
|
||||
return s.s.Len()
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Has(p sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) bool {
|
||||
return s.s.Has(p.NomsValue())
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Has(p sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) bool {
|
||||
return s.s.Has(p)
|
||||
}
|
||||
|
||||
type SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoIterCallback func(p sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) (stop bool)
|
||||
type SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoIterCallback func(p sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) (stop bool)
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Iter(cb SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoIterCallback) {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Iter(cb SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoIterCallback) {
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
return cb(sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhotoFromVal(v))
|
||||
return cb(v.(sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto))
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoIterAllCallback func(p sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto)
|
||||
type SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoIterAllCallback func(p sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto)
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) IterAll(cb SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoIterAllCallback) {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) IterAll(cb SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoIterAllCallback) {
|
||||
s.s.IterAll(func(v types.Value) {
|
||||
cb(sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhotoFromVal(v))
|
||||
cb(v.(sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto))
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoFilterCallback func(p sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) (keep bool)
|
||||
type SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoFilterCallback func(p sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) (keep bool)
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Filter(cb SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhotoFilterCallback) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
ns := NewSetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto()
|
||||
s.IterAll(func(v sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Filter(cb SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhotoFilterCallback) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
ns := NewSetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto()
|
||||
s.IterAll(func(v sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) {
|
||||
if cb(v) {
|
||||
ns = ns.Insert(v)
|
||||
}
|
||||
@@ -412,27 +453,27 @@ func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Filter(c
|
||||
return ns
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Insert(p ...sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Insert(p ...sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Remove(p ...sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Remove(p ...sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Union(others ...SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto{s.s.Union(s.fromStructSlice(others)...)}
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Union(others ...SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Subtract(others ...SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto {
|
||||
return SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Subtract(others ...SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto {
|
||||
return SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) Any() sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto {
|
||||
return sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhotoFromVal(s.s.Any())
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) Any() sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto {
|
||||
return s.s.Any().(sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto)
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) fromStructSlice(p []SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) []types.Set {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) fromStructSlice(p []SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) []types.Set {
|
||||
r := make([]types.Set, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.s
|
||||
@@ -440,10 +481,10 @@ func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) fromStru
|
||||
return r
|
||||
}
|
||||
|
||||
func (s SetOfsha1_4c734206e6aaef5464ff0e307c2f66751a1469de_RemotePhoto) fromElemSlice(p []sha1_4c734206e6aaef5464ff0e307c2f66751a1469de.RemotePhoto) []types.Value {
|
||||
func (s SetOfsha1_b525f9bca5e451c21dd9af564f0960045fbaa304_RemotePhoto) fromElemSlice(p []sha1_b525f9bca5e451c21dd9af564f0960045fbaa304.RemotePhoto) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
+120
-79
@@ -1,26 +1,27 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package sha1_4c734206e6aaef5464ff0e307c2f66751a1469de
|
||||
package sha1_b525f9bca5e451c21dd9af564f0960045fbaa304
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef = __sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_Ref()
|
||||
var __sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef = __sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_Ref()
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func __sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_Ref() ref.Ref {
|
||||
func __sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("RemotePhoto",
|
||||
[]types.Field{
|
||||
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Url", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"), 0), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"), 0), false},
|
||||
types.Field{"Sizes", types.MakeCompoundTypeRef("", types.MapKind, types.MakeTypeRef(ref.Ref{}, 1), types.MakePrimitiveTypeRef(types.StringKind)), false},
|
||||
types.Field{"Tags", types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.StringKind)), false},
|
||||
},
|
||||
@@ -34,7 +35,7 @@ func __sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"),
|
||||
ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
@@ -42,26 +43,27 @@ func __sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e
|
||||
// RemotePhoto
|
||||
|
||||
type RemotePhoto struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRemotePhoto() RemotePhoto {
|
||||
return RemotePhoto{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 0),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 0),
|
||||
types.NewString("Id"), types.NewString(""),
|
||||
types.NewString("Title"), types.NewString(""),
|
||||
types.NewString("Url"), types.NewString(""),
|
||||
types.NewString("Geoposition"), sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.NewGeoposition().NomsValue(),
|
||||
types.NewString("Sizes"), types.NewMap(),
|
||||
types.NewString("Tags"), types.NewSet(),
|
||||
)}
|
||||
types.NewString("Geoposition"), sha1_fb09d21d144c518467325465327d46489cff7c47.NewGeoposition(),
|
||||
types.NewString("Sizes"), NewMapOfSizeToString(),
|
||||
types.NewString("Tags"), NewSetOfString(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type RemotePhotoDef struct {
|
||||
Id string
|
||||
Title string
|
||||
Url string
|
||||
Geoposition sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionDef
|
||||
Geoposition sha1_fb09d21d144c518467325465327d46489cff7c47.GeopositionDef
|
||||
Sizes MapOfSizeToStringDef
|
||||
Tags SetOfStringDef
|
||||
}
|
||||
@@ -69,56 +71,65 @@ type RemotePhotoDef struct {
|
||||
func (def RemotePhotoDef) New() RemotePhoto {
|
||||
return RemotePhoto{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 0),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 0),
|
||||
types.NewString("Id"), types.NewString(def.Id),
|
||||
types.NewString("Title"), types.NewString(def.Title),
|
||||
types.NewString("Url"), types.NewString(def.Url),
|
||||
types.NewString("Geoposition"), def.Geoposition.New().NomsValue(),
|
||||
types.NewString("Sizes"), def.Sizes.New().NomsValue(),
|
||||
types.NewString("Tags"), def.Tags.New().NomsValue(),
|
||||
)}
|
||||
types.NewString("Geoposition"), def.Geoposition.New(),
|
||||
types.NewString("Sizes"), def.Sizes.New(),
|
||||
types.NewString("Tags"), def.Tags.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Def() (d RemotePhotoDef) {
|
||||
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
|
||||
d.Title = s.m.Get(types.NewString("Title")).(types.String).String()
|
||||
d.Url = s.m.Get(types.NewString("Url")).(types.String).String()
|
||||
d.Geoposition = sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition"))).Def()
|
||||
d.Sizes = MapOfSizeToStringFromVal(s.m.Get(types.NewString("Sizes"))).Def()
|
||||
d.Tags = SetOfStringFromVal(s.m.Get(types.NewString("Tags"))).Def()
|
||||
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition).Def()
|
||||
d.Sizes = s.m.Get(types.NewString("Sizes")).(MapOfSizeToString).Def()
|
||||
d.Tags = s.m.Get(types.NewString("Tags")).(SetOfString).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForRemotePhoto = types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 0)
|
||||
var __typeRefForRemotePhoto = types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 0)
|
||||
|
||||
func (m RemotePhoto) TypeRef() types.TypeRef {
|
||||
return __typeRefForRemotePhoto
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForRemotePhoto, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForRemotePhoto, func(v types.Value) types.Value {
|
||||
return RemotePhotoFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func RemotePhotoFromVal(val types.Value) RemotePhoto {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RemotePhoto); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return RemotePhoto{val.(types.Map)}
|
||||
return RemotePhoto{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s RemotePhoto) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RemotePhoto); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Chunks() (futures []types.Future) {
|
||||
@@ -132,7 +143,7 @@ func (s RemotePhoto) Id() string {
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetId(val string) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Id"), types.NewString(val))}
|
||||
return RemotePhoto{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Title() string {
|
||||
@@ -140,7 +151,7 @@ func (s RemotePhoto) Title() string {
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetTitle(val string) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Title"), types.NewString(val))}
|
||||
return RemotePhoto{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Url() string {
|
||||
@@ -148,45 +159,46 @@ func (s RemotePhoto) Url() string {
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetUrl(val string) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Url"), types.NewString(val))}
|
||||
return RemotePhoto{s.m.Set(types.NewString("Url"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Geoposition() sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition {
|
||||
return sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
|
||||
func (s RemotePhoto) Geoposition() sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition {
|
||||
return s.m.Get(types.NewString("Geoposition")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetGeoposition(val sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Geoposition"), val.NomsValue())}
|
||||
func (s RemotePhoto) SetGeoposition(val sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Sizes() MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(s.m.Get(types.NewString("Sizes")))
|
||||
return s.m.Get(types.NewString("Sizes")).(MapOfSizeToString)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetSizes(val MapOfSizeToString) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Sizes"), val.NomsValue())}
|
||||
return RemotePhoto{s.m.Set(types.NewString("Sizes"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Tags() SetOfString {
|
||||
return SetOfStringFromVal(s.m.Get(types.NewString("Tags")))
|
||||
return s.m.Get(types.NewString("Tags")).(SetOfString)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetTags(val SetOfString) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Tags"), val.NomsValue())}
|
||||
return RemotePhoto{s.m.Set(types.NewString("Tags"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// Size
|
||||
|
||||
type Size struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSize() Size {
|
||||
return Size{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 1),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 1),
|
||||
types.NewString("Width"), types.UInt32(0),
|
||||
types.NewString("Height"), types.UInt32(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SizeDef struct {
|
||||
@@ -197,10 +209,10 @@ type SizeDef struct {
|
||||
func (def SizeDef) New() Size {
|
||||
return Size{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 1),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 1),
|
||||
types.NewString("Width"), types.UInt32(def.Width),
|
||||
types.NewString("Height"), types.UInt32(def.Height),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Size) Def() (d SizeDef) {
|
||||
@@ -209,36 +221,45 @@ func (s Size) Def() (d SizeDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForSize = types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 1)
|
||||
var __typeRefForSize = types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 1)
|
||||
|
||||
func (m Size) TypeRef() types.TypeRef {
|
||||
return __typeRefForSize
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForSize, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSize, func(v types.Value) types.Value {
|
||||
return SizeFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func SizeFromVal(val types.Value) Size {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Size); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Size{val.(types.Map)}
|
||||
return Size{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Size) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Size) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Size) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Size); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Size) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Size) Chunks() (futures []types.Future) {
|
||||
@@ -252,7 +273,7 @@ func (s Size) Width() uint32 {
|
||||
}
|
||||
|
||||
func (s Size) SetWidth(val uint32) Size {
|
||||
return Size{s.m.Set(types.NewString("Width"), types.UInt32(val))}
|
||||
return Size{s.m.Set(types.NewString("Width"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Size) Height() uint32 {
|
||||
@@ -260,17 +281,18 @@ func (s Size) Height() uint32 {
|
||||
}
|
||||
|
||||
func (s Size) SetHeight(val uint32) Size {
|
||||
return Size{s.m.Set(types.NewString("Height"), types.UInt32(val))}
|
||||
return Size{s.m.Set(types.NewString("Height"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// MapOfSizeToString
|
||||
|
||||
type MapOfSizeToString struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfSizeToString() MapOfSizeToString {
|
||||
return MapOfSizeToString{types.NewMap()}
|
||||
return MapOfSizeToString{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfSizeToStringDef map[SizeDef]string
|
||||
@@ -278,38 +300,47 @@ type MapOfSizeToStringDef map[SizeDef]string
|
||||
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
|
||||
kv := make([]types.Value, 0, len(def)*2)
|
||||
for k, v := range def {
|
||||
kv = append(kv, k.New().NomsValue(), types.NewString(v))
|
||||
kv = append(kv, k.New(), types.NewString(v))
|
||||
}
|
||||
return MapOfSizeToString{types.NewMap(kv...)}
|
||||
return MapOfSizeToString{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
|
||||
def := make(map[SizeDef]string)
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
def[SizeFromVal(k).Def()] = v.(types.String).String()
|
||||
def[k.(Size).Def()] = v.(types.String).String()
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfSizeToStringFromVal(p types.Value) MapOfSizeToString {
|
||||
func MapOfSizeToStringFromVal(val types.Value) MapOfSizeToString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfSizeToString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfSizeToString{p.(types.Map)}
|
||||
return MapOfSizeToString{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfSizeToString); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Chunks() (futures []types.Future) {
|
||||
@@ -326,8 +357,8 @@ func (m MapOfSizeToString) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfSizeToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakeTypeRef(__sha1_4c734206e6aaef5464ff0e307c2f66751a1469dePackageInFile_sha1_4c734206e6aaef5464ff0e307c2f66751a1469de_CachedRef, 1), types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfSizeToString, func(v types.Value) types.NomsValue {
|
||||
__typeRefForMapOfSizeToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakeTypeRef(__sha1_b525f9bca5e451c21dd9af564f0960045fbaa304PackageInFile_sha1_b525f9bca5e451c21dd9af564f0960045fbaa304_CachedRef, 1), types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfSizeToString, func(v types.Value) types.Value {
|
||||
return MapOfSizeToStringFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -341,15 +372,15 @@ func (m MapOfSizeToString) Len() uint64 {
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Has(p Size) bool {
|
||||
return m.m.Has(p.NomsValue())
|
||||
return m.m.Has(p)
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Get(p Size) string {
|
||||
return m.m.Get(p.NomsValue()).(types.String).String()
|
||||
return m.m.Get(p).(types.String).String()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
|
||||
v, ok := m.m.MaybeGet(p.NomsValue())
|
||||
v, ok := m.m.MaybeGet(p)
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
@@ -357,20 +388,20 @@ func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
|
||||
return MapOfSizeToString{m.m.Set(k.NomsValue(), types.NewString(v))}
|
||||
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
|
||||
return MapOfSizeToString{m.m.Remove(p.NomsValue())}
|
||||
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
|
||||
|
||||
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(SizeFromVal(k), v.(types.String).String())
|
||||
return cb(k.(Size), v.(types.String).String())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -378,7 +409,7 @@ type MapOfSizeToStringIterAllCallback func(k Size, v string)
|
||||
|
||||
func (m MapOfSizeToString) IterAll(cb MapOfSizeToStringIterAllCallback) {
|
||||
m.m.IterAll(func(k, v types.Value) {
|
||||
cb(SizeFromVal(k), v.(types.String).String())
|
||||
cb(k.(Size), v.(types.String).String())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -397,11 +428,12 @@ func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeT
|
||||
// SetOfString
|
||||
|
||||
type SetOfString struct {
|
||||
s types.Set
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfString() SetOfString {
|
||||
return SetOfString{types.NewSet()}
|
||||
return SetOfString{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SetOfStringDef map[string]bool
|
||||
@@ -413,7 +445,7 @@ func (def SetOfStringDef) New() SetOfString {
|
||||
l[i] = types.NewString(d)
|
||||
i++
|
||||
}
|
||||
return SetOfString{types.NewSet(l...)}
|
||||
return SetOfString{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Def() SetOfStringDef {
|
||||
@@ -425,23 +457,32 @@ func (s SetOfString) Def() SetOfStringDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfStringFromVal(p types.Value) SetOfString {
|
||||
return SetOfString{p.(types.Set)}
|
||||
func SetOfStringFromVal(val types.Value) SetOfString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfString); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfString{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfString) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfString); ok {
|
||||
return s.s.Equals(other.s)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfString) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfString) Chunks() (futures []types.Future) {
|
||||
@@ -459,7 +500,7 @@ func (m SetOfString) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfString = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSetOfString, func(v types.Value) types.Value {
|
||||
return SetOfStringFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -505,19 +546,19 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
|
||||
}
|
||||
|
||||
func (s SetOfString) Insert(p ...string) SetOfString {
|
||||
return SetOfString{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Remove(p ...string) SetOfString {
|
||||
return SetOfString{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Union(others ...SetOfString) SetOfString {
|
||||
return SetOfString{s.s.Union(s.fromStructSlice(others)...)}
|
||||
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
|
||||
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Any() string {
|
||||
+55
-35
@@ -1,18 +1,18 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d
|
||||
package sha1_fb09d21d144c518467325465327d46489cff7c47
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef = __sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_Ref()
|
||||
var __sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef = __sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_Ref()
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func __sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_Ref() ref.Ref {
|
||||
func __sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("Geoposition",
|
||||
[]types.Field{
|
||||
@@ -35,15 +35,16 @@ func __sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5
|
||||
// Geoposition
|
||||
|
||||
type Geoposition struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewGeoposition() Geoposition {
|
||||
return Geoposition{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef, 0),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef, 0),
|
||||
types.NewString("Latitude"), types.Float32(0),
|
||||
types.NewString("Longitude"), types.Float32(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type GeopositionDef struct {
|
||||
@@ -54,10 +55,10 @@ type GeopositionDef struct {
|
||||
func (def GeopositionDef) New() Geoposition {
|
||||
return Geoposition{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef, 0),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef, 0),
|
||||
types.NewString("Latitude"), types.Float32(def.Latitude),
|
||||
types.NewString("Longitude"), types.Float32(def.Longitude),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) Def() (d GeopositionDef) {
|
||||
@@ -66,36 +67,45 @@ func (s Geoposition) Def() (d GeopositionDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeoposition = types.MakeTypeRef(__sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef, 0)
|
||||
var __typeRefForGeoposition = types.MakeTypeRef(__sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef, 0)
|
||||
|
||||
func (m Geoposition) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeoposition
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.Value {
|
||||
return GeopositionFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeopositionFromVal(val types.Value) Geoposition {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Geoposition); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Geoposition{val.(types.Map)}
|
||||
return Geoposition{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Geoposition) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Geoposition) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Geoposition); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Geoposition) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Geoposition) Chunks() (futures []types.Future) {
|
||||
@@ -109,7 +119,7 @@ func (s Geoposition) Latitude() float32 {
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLatitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val))}
|
||||
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) Longitude() float32 {
|
||||
@@ -117,21 +127,22 @@ func (s Geoposition) Longitude() float32 {
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLongitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val))}
|
||||
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// Georectangle
|
||||
|
||||
type Georectangle struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewGeorectangle() Georectangle {
|
||||
return Georectangle{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef, 1),
|
||||
types.NewString("TopLeft"), NewGeoposition().NomsValue(),
|
||||
types.NewString("BottomRight"), NewGeoposition().NomsValue(),
|
||||
)}
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef, 1),
|
||||
types.NewString("TopLeft"), NewGeoposition(),
|
||||
types.NewString("BottomRight"), NewGeoposition(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type GeorectangleDef struct {
|
||||
@@ -142,48 +153,57 @@ type GeorectangleDef struct {
|
||||
func (def GeorectangleDef) New() Georectangle {
|
||||
return Georectangle{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef, 1),
|
||||
types.NewString("TopLeft"), def.TopLeft.New().NomsValue(),
|
||||
types.NewString("BottomRight"), def.BottomRight.New().NomsValue(),
|
||||
)}
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef, 1),
|
||||
types.NewString("TopLeft"), def.TopLeft.New(),
|
||||
types.NewString("BottomRight"), def.BottomRight.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) Def() (d GeorectangleDef) {
|
||||
d.TopLeft = GeopositionFromVal(s.m.Get(types.NewString("TopLeft"))).Def()
|
||||
d.BottomRight = GeopositionFromVal(s.m.Get(types.NewString("BottomRight"))).Def()
|
||||
d.TopLeft = s.m.Get(types.NewString("TopLeft")).(Geoposition).Def()
|
||||
d.BottomRight = s.m.Get(types.NewString("BottomRight")).(Geoposition).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeorectangle = types.MakeTypeRef(__sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517dPackageInFile_sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d_CachedRef, 1)
|
||||
var __typeRefForGeorectangle = types.MakeTypeRef(__sha1_fb09d21d144c518467325465327d46489cff7c47PackageInFile_sha1_fb09d21d144c518467325465327d46489cff7c47_CachedRef, 1)
|
||||
|
||||
func (m Georectangle) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeorectangle
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.Value {
|
||||
return GeorectangleFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeorectangleFromVal(val types.Value) Georectangle {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Georectangle); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Georectangle{val.(types.Map)}
|
||||
return Georectangle{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Georectangle) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Georectangle) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Georectangle); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Georectangle) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Georectangle) Chunks() (futures []types.Future) {
|
||||
@@ -193,17 +213,17 @@ func (s Georectangle) Chunks() (futures []types.Future) {
|
||||
}
|
||||
|
||||
func (s Georectangle) TopLeft() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("TopLeft")))
|
||||
return s.m.Get(types.NewString("TopLeft")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Georectangle) SetTopLeft(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("TopLeft"), val.NomsValue())}
|
||||
return Georectangle{s.m.Set(types.NewString("TopLeft"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) BottomRight() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("BottomRight")))
|
||||
return s.m.Get(types.NewString("BottomRight")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Georectangle) SetBottomRight(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("BottomRight"), val.NomsValue())}
|
||||
return Georectangle{s.m.Set(types.NewString("BottomRight"), val), &ref.Ref{}}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
// Song
|
||||
|
||||
type Song struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSong() Song {
|
||||
@@ -42,7 +43,7 @@ func NewSong() Song {
|
||||
types.NewString("Album"), types.NewString(""),
|
||||
types.NewString("Year"), types.NewString(""),
|
||||
types.NewString("Mp3"), types.NewEmptyBlob(),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SongDef struct {
|
||||
@@ -62,7 +63,7 @@ func (def SongDef) New() Song {
|
||||
types.NewString("Album"), types.NewString(def.Album),
|
||||
types.NewString("Year"), types.NewString(def.Year),
|
||||
types.NewString("Mp3"), def.Mp3,
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Song) Def() (d SongDef) {
|
||||
@@ -81,29 +82,38 @@ func (m Song) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForSong, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSong, func(v types.Value) types.Value {
|
||||
return SongFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func SongFromVal(val types.Value) Song {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Song); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Song{val.(types.Map)}
|
||||
return Song{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Song) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Song) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Song) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Song); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Song) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Song) Chunks() (futures []types.Future) {
|
||||
@@ -117,7 +127,7 @@ func (s Song) Title() string {
|
||||
}
|
||||
|
||||
func (s Song) SetTitle(val string) Song {
|
||||
return Song{s.m.Set(types.NewString("Title"), types.NewString(val))}
|
||||
return Song{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Song) Artist() string {
|
||||
@@ -125,7 +135,7 @@ func (s Song) Artist() string {
|
||||
}
|
||||
|
||||
func (s Song) SetArtist(val string) Song {
|
||||
return Song{s.m.Set(types.NewString("Artist"), types.NewString(val))}
|
||||
return Song{s.m.Set(types.NewString("Artist"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Song) Album() string {
|
||||
@@ -133,7 +143,7 @@ func (s Song) Album() string {
|
||||
}
|
||||
|
||||
func (s Song) SetAlbum(val string) Song {
|
||||
return Song{s.m.Set(types.NewString("Album"), types.NewString(val))}
|
||||
return Song{s.m.Set(types.NewString("Album"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Song) Year() string {
|
||||
@@ -141,7 +151,7 @@ func (s Song) Year() string {
|
||||
}
|
||||
|
||||
func (s Song) SetYear(val string) Song {
|
||||
return Song{s.m.Set(types.NewString("Year"), types.NewString(val))}
|
||||
return Song{s.m.Set(types.NewString("Year"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Song) Mp3() types.Blob {
|
||||
@@ -149,17 +159,18 @@ func (s Song) Mp3() types.Blob {
|
||||
}
|
||||
|
||||
func (s Song) SetMp3(val types.Blob) Song {
|
||||
return Song{s.m.Set(types.NewString("Mp3"), val)}
|
||||
return Song{s.m.Set(types.NewString("Mp3"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfSong
|
||||
|
||||
type ListOfSong struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfSong() ListOfSong {
|
||||
return ListOfSong{types.NewList()}
|
||||
return ListOfSong{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfSongDef []SongDef
|
||||
@@ -167,37 +178,46 @@ type ListOfSongDef []SongDef
|
||||
func (def ListOfSongDef) New() ListOfSong {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfSong{types.NewList(l...)}
|
||||
return ListOfSong{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) Def() ListOfSongDef {
|
||||
d := make([]SongDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = SongFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(Song).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfSongFromVal(val types.Value) ListOfSong {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfSong); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfSong{val.(types.List)}
|
||||
return ListOfSong{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfSong) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfSong) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfSong); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfSong) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfSong) Chunks() (futures []types.Future) {
|
||||
@@ -215,7 +235,7 @@ func (m ListOfSong) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfSong = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfSong, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfSong, func(v types.Value) types.Value {
|
||||
return ListOfSongFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -229,37 +249,37 @@ func (l ListOfSong) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfSong) Get(i uint64) Song {
|
||||
return SongFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(Song)
|
||||
}
|
||||
|
||||
func (l ListOfSong) Slice(idx uint64, end uint64) ListOfSong {
|
||||
return ListOfSong{l.l.Slice(idx, end)}
|
||||
return ListOfSong{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) Set(i uint64, val Song) ListOfSong {
|
||||
return ListOfSong{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfSong{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) Append(v ...Song) ListOfSong {
|
||||
return ListOfSong{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfSong{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) Insert(idx uint64, v ...Song) ListOfSong {
|
||||
return ListOfSong{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfSong{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) Remove(idx uint64, end uint64) ListOfSong {
|
||||
return ListOfSong{l.l.Remove(idx, end)}
|
||||
return ListOfSong{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) RemoveAt(idx uint64) ListOfSong {
|
||||
return ListOfSong{(l.l.RemoveAt(idx))}
|
||||
return ListOfSong{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfSong) fromElemSlice(p []Song) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -268,7 +288,7 @@ type ListOfSongIterCallback func(v Song, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfSong) Iter(cb ListOfSongIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(SongFromVal(v), i)
|
||||
return cb(v.(Song), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -276,7 +296,7 @@ type ListOfSongIterAllCallback func(v Song, i uint64)
|
||||
|
||||
func (l ListOfSong) IterAll(cb ListOfSongIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(SongFromVal(v), i)
|
||||
cb(v.(Song), i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+143
-83
@@ -28,7 +28,8 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
// Pitch
|
||||
|
||||
type Pitch struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewPitch() Pitch {
|
||||
@@ -36,7 +37,7 @@ func NewPitch() Pitch {
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("X"), types.Float64(0),
|
||||
types.NewString("Z"), types.Float64(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type PitchDef struct {
|
||||
@@ -50,7 +51,7 @@ func (def PitchDef) New() Pitch {
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("X"), types.Float64(def.X),
|
||||
types.NewString("Z"), types.Float64(def.Z),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Pitch) Def() (d PitchDef) {
|
||||
@@ -66,29 +67,38 @@ func (m Pitch) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForPitch, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForPitch, func(v types.Value) types.Value {
|
||||
return PitchFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func PitchFromVal(val types.Value) Pitch {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Pitch); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Pitch{val.(types.Map)}
|
||||
return Pitch{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Pitch) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Pitch) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Pitch) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Pitch); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Pitch) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Pitch) Chunks() (futures []types.Future) {
|
||||
@@ -102,7 +112,7 @@ func (s Pitch) X() float64 {
|
||||
}
|
||||
|
||||
func (s Pitch) SetX(val float64) Pitch {
|
||||
return Pitch{s.m.Set(types.NewString("X"), types.Float64(val))}
|
||||
return Pitch{s.m.Set(types.NewString("X"), types.Float64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Pitch) Z() float64 {
|
||||
@@ -110,17 +120,18 @@ func (s Pitch) Z() float64 {
|
||||
}
|
||||
|
||||
func (s Pitch) SetZ(val float64) Pitch {
|
||||
return Pitch{s.m.Set(types.NewString("Z"), types.Float64(val))}
|
||||
return Pitch{s.m.Set(types.NewString("Z"), types.Float64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfMapOfStringToValue
|
||||
|
||||
type ListOfMapOfStringToValue struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfMapOfStringToValue() ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{types.NewList()}
|
||||
return ListOfMapOfStringToValue{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfMapOfStringToValueDef []MapOfStringToValueDef
|
||||
@@ -128,37 +139,46 @@ type ListOfMapOfStringToValueDef []MapOfStringToValueDef
|
||||
func (def ListOfMapOfStringToValueDef) New() ListOfMapOfStringToValue {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfMapOfStringToValue{types.NewList(l...)}
|
||||
return ListOfMapOfStringToValue{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Def() ListOfMapOfStringToValueDef {
|
||||
d := make([]MapOfStringToValueDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = MapOfStringToValueFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(MapOfStringToValue).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfMapOfStringToValueFromVal(val types.Value) ListOfMapOfStringToValue {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfMapOfStringToValue); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfMapOfStringToValue{val.(types.List)}
|
||||
return ListOfMapOfStringToValue{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfMapOfStringToValue); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Chunks() (futures []types.Future) {
|
||||
@@ -176,7 +196,7 @@ func (m ListOfMapOfStringToValue) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfMapOfStringToValue = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind)))
|
||||
types.RegisterFromValFunction(__typeRefForListOfMapOfStringToValue, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfMapOfStringToValue, func(v types.Value) types.Value {
|
||||
return ListOfMapOfStringToValueFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -190,37 +210,37 @@ func (l ListOfMapOfStringToValue) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Get(i uint64) MapOfStringToValue {
|
||||
return MapOfStringToValueFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(MapOfStringToValue)
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Slice(idx uint64, end uint64) ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{l.l.Slice(idx, end)}
|
||||
return ListOfMapOfStringToValue{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Set(i uint64, val MapOfStringToValue) ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfMapOfStringToValue{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Append(v ...MapOfStringToValue) ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfMapOfStringToValue{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Insert(idx uint64, v ...MapOfStringToValue) ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfMapOfStringToValue{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) Remove(idx uint64, end uint64) ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{l.l.Remove(idx, end)}
|
||||
return ListOfMapOfStringToValue{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) RemoveAt(idx uint64) ListOfMapOfStringToValue {
|
||||
return ListOfMapOfStringToValue{(l.l.RemoveAt(idx))}
|
||||
return ListOfMapOfStringToValue{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfMapOfStringToValue) fromElemSlice(p []MapOfStringToValue) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -229,7 +249,7 @@ type ListOfMapOfStringToValueIterCallback func(v MapOfStringToValue, i uint64) (
|
||||
|
||||
func (l ListOfMapOfStringToValue) Iter(cb ListOfMapOfStringToValueIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(MapOfStringToValueFromVal(v), i)
|
||||
return cb(v.(MapOfStringToValue), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -237,7 +257,7 @@ type ListOfMapOfStringToValueIterAllCallback func(v MapOfStringToValue, i uint64
|
||||
|
||||
func (l ListOfMapOfStringToValue) IterAll(cb ListOfMapOfStringToValueIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(MapOfStringToValueFromVal(v), i)
|
||||
cb(v.(MapOfStringToValue), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -256,11 +276,12 @@ func (l ListOfMapOfStringToValue) Filter(cb ListOfMapOfStringToValueFilterCallba
|
||||
// MapOfStringToListOfPitch
|
||||
|
||||
type MapOfStringToListOfPitch struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToListOfPitch() MapOfStringToListOfPitch {
|
||||
return MapOfStringToListOfPitch{types.NewMap()}
|
||||
return MapOfStringToListOfPitch{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToListOfPitchDef map[string]ListOfPitchDef
|
||||
@@ -268,38 +289,47 @@ type MapOfStringToListOfPitchDef map[string]ListOfPitchDef
|
||||
func (def MapOfStringToListOfPitchDef) New() MapOfStringToListOfPitch {
|
||||
kv := make([]types.Value, 0, len(def)*2)
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.NewString(k), v.New().NomsValue())
|
||||
kv = append(kv, types.NewString(k), v.New())
|
||||
}
|
||||
return MapOfStringToListOfPitch{types.NewMap(kv...)}
|
||||
return MapOfStringToListOfPitch{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) Def() MapOfStringToListOfPitchDef {
|
||||
def := make(map[string]ListOfPitchDef)
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
def[k.(types.String).String()] = ListOfPitchFromVal(v).Def()
|
||||
def[k.(types.String).String()] = v.(ListOfPitch).Def()
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfStringToListOfPitchFromVal(p types.Value) MapOfStringToListOfPitch {
|
||||
func MapOfStringToListOfPitchFromVal(val types.Value) MapOfStringToListOfPitch {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToListOfPitch); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToListOfPitch{p.(types.Map)}
|
||||
return MapOfStringToListOfPitch{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToListOfPitch); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) Chunks() (futures []types.Future) {
|
||||
@@ -317,7 +347,7 @@ func (m MapOfStringToListOfPitch) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToListOfPitch = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0)))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToListOfPitch, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToListOfPitch, func(v types.Value) types.Value {
|
||||
return MapOfStringToListOfPitchFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -335,7 +365,7 @@ func (m MapOfStringToListOfPitch) Has(p string) bool {
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) Get(p string) ListOfPitch {
|
||||
return ListOfPitchFromVal(m.m.Get(types.NewString(p)))
|
||||
return m.m.Get(types.NewString(p)).(ListOfPitch)
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) MaybeGet(p string) (ListOfPitch, bool) {
|
||||
@@ -343,24 +373,24 @@ func (m MapOfStringToListOfPitch) MaybeGet(p string) (ListOfPitch, bool) {
|
||||
if !ok {
|
||||
return NewListOfPitch(), false
|
||||
}
|
||||
return ListOfPitchFromVal(v), ok
|
||||
return v.(ListOfPitch), ok
|
||||
}
|
||||
|
||||
func (m MapOfStringToListOfPitch) Set(k string, v ListOfPitch) MapOfStringToListOfPitch {
|
||||
return MapOfStringToListOfPitch{m.m.Set(types.NewString(k), v.NomsValue())}
|
||||
return MapOfStringToListOfPitch{m.m.Set(types.NewString(k), v), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToListOfPitch) Remove(p string) MapOfStringToListOfPitch {
|
||||
return MapOfStringToListOfPitch{m.m.Remove(types.NewString(p))}
|
||||
return MapOfStringToListOfPitch{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToListOfPitchIterCallback func(k string, v ListOfPitch) (stop bool)
|
||||
|
||||
func (m MapOfStringToListOfPitch) Iter(cb MapOfStringToListOfPitchIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(k.(types.String).String(), ListOfPitchFromVal(v))
|
||||
return cb(k.(types.String).String(), v.(ListOfPitch))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -368,7 +398,7 @@ type MapOfStringToListOfPitchIterAllCallback func(k string, v ListOfPitch)
|
||||
|
||||
func (m MapOfStringToListOfPitch) IterAll(cb MapOfStringToListOfPitchIterAllCallback) {
|
||||
m.m.IterAll(func(k, v types.Value) {
|
||||
cb(k.(types.String).String(), ListOfPitchFromVal(v))
|
||||
cb(k.(types.String).String(), v.(ListOfPitch))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -387,11 +417,12 @@ func (m MapOfStringToListOfPitch) Filter(cb MapOfStringToListOfPitchFilterCallba
|
||||
// MapOfStringToString
|
||||
|
||||
type MapOfStringToString struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToString() MapOfStringToString {
|
||||
return MapOfStringToString{types.NewMap()}
|
||||
return MapOfStringToString{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToStringDef map[string]string
|
||||
@@ -401,7 +432,7 @@ func (def MapOfStringToStringDef) New() MapOfStringToString {
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.NewString(k), types.NewString(v))
|
||||
}
|
||||
return MapOfStringToString{types.NewMap(kv...)}
|
||||
return MapOfStringToString{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) Def() MapOfStringToStringDef {
|
||||
@@ -413,24 +444,33 @@ func (m MapOfStringToString) Def() MapOfStringToStringDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfStringToStringFromVal(p types.Value) MapOfStringToString {
|
||||
func MapOfStringToStringFromVal(val types.Value) MapOfStringToString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToString{p.(types.Map)}
|
||||
return MapOfStringToString{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToString); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) Chunks() (futures []types.Future) {
|
||||
@@ -448,7 +488,7 @@ func (m MapOfStringToString) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToString, func(v types.Value) types.Value {
|
||||
return MapOfStringToStringFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -478,13 +518,13 @@ func (m MapOfStringToString) MaybeGet(p string) (string, bool) {
|
||||
}
|
||||
|
||||
func (m MapOfStringToString) Set(k string, v string) MapOfStringToString {
|
||||
return MapOfStringToString{m.m.Set(types.NewString(k), types.NewString(v))}
|
||||
return MapOfStringToString{m.m.Set(types.NewString(k), types.NewString(v)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToString) Remove(p string) MapOfStringToString {
|
||||
return MapOfStringToString{m.m.Remove(types.NewString(p))}
|
||||
return MapOfStringToString{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToStringIterCallback func(k string, v string) (stop bool)
|
||||
@@ -518,11 +558,12 @@ func (m MapOfStringToString) Filter(cb MapOfStringToStringFilterCallback) MapOfS
|
||||
// MapOfStringToValue
|
||||
|
||||
type MapOfStringToValue struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToValue() MapOfStringToValue {
|
||||
return MapOfStringToValue{types.NewMap()}
|
||||
return MapOfStringToValue{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToValueDef map[string]types.Value
|
||||
@@ -532,7 +573,7 @@ func (def MapOfStringToValueDef) New() MapOfStringToValue {
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.NewString(k), v)
|
||||
}
|
||||
return MapOfStringToValue{types.NewMap(kv...)}
|
||||
return MapOfStringToValue{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Def() MapOfStringToValueDef {
|
||||
@@ -544,24 +585,33 @@ func (m MapOfStringToValue) Def() MapOfStringToValueDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfStringToValueFromVal(p types.Value) MapOfStringToValue {
|
||||
func MapOfStringToValueFromVal(val types.Value) MapOfStringToValue {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToValue); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToValue{p.(types.Map)}
|
||||
return MapOfStringToValue{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToValue); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Chunks() (futures []types.Future) {
|
||||
@@ -579,7 +629,7 @@ func (m MapOfStringToValue) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToValue = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToValue, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToValue, func(v types.Value) types.Value {
|
||||
return MapOfStringToValueFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -609,13 +659,13 @@ func (m MapOfStringToValue) MaybeGet(p string) (types.Value, bool) {
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Set(k string, v types.Value) MapOfStringToValue {
|
||||
return MapOfStringToValue{m.m.Set(types.NewString(k), v)}
|
||||
return MapOfStringToValue{m.m.Set(types.NewString(k), v), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToValue) Remove(p string) MapOfStringToValue {
|
||||
return MapOfStringToValue{m.m.Remove(types.NewString(p))}
|
||||
return MapOfStringToValue{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToValueIterCallback func(k string, v types.Value) (stop bool)
|
||||
@@ -649,11 +699,12 @@ func (m MapOfStringToValue) Filter(cb MapOfStringToValueFilterCallback) MapOfStr
|
||||
// ListOfPitch
|
||||
|
||||
type ListOfPitch struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfPitch() ListOfPitch {
|
||||
return ListOfPitch{types.NewList()}
|
||||
return ListOfPitch{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfPitchDef []PitchDef
|
||||
@@ -661,37 +712,46 @@ type ListOfPitchDef []PitchDef
|
||||
func (def ListOfPitchDef) New() ListOfPitch {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfPitch{types.NewList(l...)}
|
||||
return ListOfPitch{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Def() ListOfPitchDef {
|
||||
d := make([]PitchDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = PitchFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(Pitch).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfPitchFromVal(val types.Value) ListOfPitch {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfPitch); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfPitch{val.(types.List)}
|
||||
return ListOfPitch{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfPitch) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfPitch); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Chunks() (futures []types.Future) {
|
||||
@@ -709,7 +769,7 @@ func (m ListOfPitch) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfPitch = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfPitch, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfPitch, func(v types.Value) types.Value {
|
||||
return ListOfPitchFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -723,37 +783,37 @@ func (l ListOfPitch) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Get(i uint64) Pitch {
|
||||
return PitchFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(Pitch)
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Slice(idx uint64, end uint64) ListOfPitch {
|
||||
return ListOfPitch{l.l.Slice(idx, end)}
|
||||
return ListOfPitch{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Set(i uint64, val Pitch) ListOfPitch {
|
||||
return ListOfPitch{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfPitch{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Append(v ...Pitch) ListOfPitch {
|
||||
return ListOfPitch{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfPitch{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Insert(idx uint64, v ...Pitch) ListOfPitch {
|
||||
return ListOfPitch{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfPitch{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) Remove(idx uint64, end uint64) ListOfPitch {
|
||||
return ListOfPitch{l.l.Remove(idx, end)}
|
||||
return ListOfPitch{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) RemoveAt(idx uint64) ListOfPitch {
|
||||
return ListOfPitch{(l.l.RemoveAt(idx))}
|
||||
return ListOfPitch{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfPitch) fromElemSlice(p []Pitch) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -762,7 +822,7 @@ type ListOfPitchIterCallback func(v Pitch, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfPitch) Iter(cb ListOfPitchIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(PitchFromVal(v), i)
|
||||
return cb(v.(Pitch), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -770,7 +830,7 @@ type ListOfPitchIterAllCallback func(v Pitch, i uint64)
|
||||
|
||||
func (l ListOfPitch) IterAll(cb ListOfPitchIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(PitchFromVal(v), i)
|
||||
cb(v.(Pitch), i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/types"
|
||||
|
||||
+259
-170
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
@@ -26,13 +27,13 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
types.Field{"PdDistrict", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Resolution", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"), 0), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"), 0), false},
|
||||
types.Field{"PdID", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"),
|
||||
ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
@@ -40,7 +41,8 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
// Incident
|
||||
|
||||
type Incident struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewIncident() Incident {
|
||||
@@ -55,9 +57,9 @@ func NewIncident() Incident {
|
||||
types.NewString("PdDistrict"), types.NewString(""),
|
||||
types.NewString("Resolution"), types.NewString(""),
|
||||
types.NewString("Address"), types.NewString(""),
|
||||
types.NewString("Geoposition"), sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.NewGeoposition().NomsValue(),
|
||||
types.NewString("Geoposition"), sha1_fb09d21d144c518467325465327d46489cff7c47.NewGeoposition(),
|
||||
types.NewString("PdID"), types.NewString(""),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type IncidentDef struct {
|
||||
@@ -70,7 +72,7 @@ type IncidentDef struct {
|
||||
PdDistrict string
|
||||
Resolution string
|
||||
Address string
|
||||
Geoposition sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionDef
|
||||
Geoposition sha1_fb09d21d144c518467325465327d46489cff7c47.GeopositionDef
|
||||
PdID string
|
||||
}
|
||||
|
||||
@@ -87,9 +89,9 @@ func (def IncidentDef) New() Incident {
|
||||
types.NewString("PdDistrict"), types.NewString(def.PdDistrict),
|
||||
types.NewString("Resolution"), types.NewString(def.Resolution),
|
||||
types.NewString("Address"), types.NewString(def.Address),
|
||||
types.NewString("Geoposition"), def.Geoposition.New().NomsValue(),
|
||||
types.NewString("Geoposition"), def.Geoposition.New(),
|
||||
types.NewString("PdID"), types.NewString(def.PdID),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Def() (d IncidentDef) {
|
||||
@@ -102,7 +104,7 @@ func (s Incident) Def() (d IncidentDef) {
|
||||
d.PdDistrict = s.m.Get(types.NewString("PdDistrict")).(types.String).String()
|
||||
d.Resolution = s.m.Get(types.NewString("Resolution")).(types.String).String()
|
||||
d.Address = s.m.Get(types.NewString("Address")).(types.String).String()
|
||||
d.Geoposition = sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition"))).Def()
|
||||
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition).Def()
|
||||
d.PdID = s.m.Get(types.NewString("PdID")).(types.String).String()
|
||||
return
|
||||
}
|
||||
@@ -114,29 +116,38 @@ func (m Incident) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.Value {
|
||||
return IncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func IncidentFromVal(val types.Value) Incident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Incident); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Incident{val.(types.Map)}
|
||||
return Incident{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Incident) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Incident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Incident); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Incident) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Incident) Chunks() (futures []types.Future) {
|
||||
@@ -150,7 +161,7 @@ func (s Incident) ID() int64 {
|
||||
}
|
||||
|
||||
func (s Incident) SetID(val int64) Incident {
|
||||
return Incident{s.m.Set(types.NewString("ID"), types.Int64(val))}
|
||||
return Incident{s.m.Set(types.NewString("ID"), types.Int64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Category() string {
|
||||
@@ -158,7 +169,7 @@ func (s Incident) Category() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetCategory(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Category"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Category"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Description() string {
|
||||
@@ -166,7 +177,7 @@ func (s Incident) Description() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetDescription(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Description"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Description"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) DayOfWeek() string {
|
||||
@@ -174,7 +185,7 @@ func (s Incident) DayOfWeek() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetDayOfWeek(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("DayOfWeek"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("DayOfWeek"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Date() string {
|
||||
@@ -182,7 +193,7 @@ func (s Incident) Date() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetDate(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Time() string {
|
||||
@@ -190,7 +201,7 @@ func (s Incident) Time() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetTime(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Time"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Time"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) PdDistrict() string {
|
||||
@@ -198,7 +209,7 @@ func (s Incident) PdDistrict() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetPdDistrict(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("PdDistrict"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("PdDistrict"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Resolution() string {
|
||||
@@ -206,7 +217,7 @@ func (s Incident) Resolution() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetResolution(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Resolution"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Resolution"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Address() string {
|
||||
@@ -214,15 +225,15 @@ func (s Incident) Address() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetAddress(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Address"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Address"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Geoposition() sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition {
|
||||
return sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
|
||||
func (s Incident) Geoposition() sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition {
|
||||
return s.m.Get(types.NewString("Geoposition")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition)
|
||||
}
|
||||
|
||||
func (s Incident) SetGeoposition(val sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Geoposition"), val.NomsValue())}
|
||||
func (s Incident) SetGeoposition(val sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) PdID() string {
|
||||
@@ -230,17 +241,18 @@ func (s Incident) PdID() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetPdID(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("PdID"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("PdID"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfIncident
|
||||
|
||||
type ListOfIncident struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfIncident() ListOfIncident {
|
||||
return ListOfIncident{types.NewList()}
|
||||
return ListOfIncident{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfIncidentDef []IncidentDef
|
||||
@@ -248,37 +260,46 @@ type ListOfIncidentDef []IncidentDef
|
||||
func (def ListOfIncidentDef) New() ListOfIncident {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfIncident{types.NewList(l...)}
|
||||
return ListOfIncident{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Def() ListOfIncidentDef {
|
||||
d := make([]IncidentDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = IncidentFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(Incident).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfIncidentFromVal(val types.Value) ListOfIncident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfIncident); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfIncident{val.(types.List)}
|
||||
return ListOfIncident{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfIncident) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfIncident); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Chunks() (futures []types.Future) {
|
||||
@@ -296,7 +317,7 @@ func (m ListOfIncident) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfIncident, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfIncident, func(v types.Value) types.Value {
|
||||
return ListOfIncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -310,37 +331,37 @@ func (l ListOfIncident) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Get(i uint64) Incident {
|
||||
return IncidentFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(Incident)
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Slice(idx uint64, end uint64) ListOfIncident {
|
||||
return ListOfIncident{l.l.Slice(idx, end)}
|
||||
return ListOfIncident{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Set(i uint64, val Incident) ListOfIncident {
|
||||
return ListOfIncident{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfIncident{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Append(v ...Incident) ListOfIncident {
|
||||
return ListOfIncident{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfIncident{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Insert(idx uint64, v ...Incident) ListOfIncident {
|
||||
return ListOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Remove(idx uint64, end uint64) ListOfIncident {
|
||||
return ListOfIncident{l.l.Remove(idx, end)}
|
||||
return ListOfIncident{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) RemoveAt(idx uint64) ListOfIncident {
|
||||
return ListOfIncident{(l.l.RemoveAt(idx))}
|
||||
return ListOfIncident{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) fromElemSlice(p []Incident) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -349,7 +370,7 @@ type ListOfIncidentIterCallback func(v Incident, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfIncident) Iter(cb ListOfIncidentIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(IncidentFromVal(v), i)
|
||||
return cb(v.(Incident), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -357,7 +378,7 @@ type ListOfIncidentIterAllCallback func(v Incident, i uint64)
|
||||
|
||||
func (l ListOfIncident) IterAll(cb ListOfIncidentIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(IncidentFromVal(v), i)
|
||||
cb(v.(Incident), i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
|
||||
+127
-86
@@ -3,7 +3,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
types.Field{"Description", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Date", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"), 0), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"), 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
@@ -32,12 +33,12 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
|
||||
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
|
||||
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Georectangle", types.MakeTypeRef(ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"), 1), false},
|
||||
types.Field{"Georectangle", types.MakeTypeRef(ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"), 1), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"),
|
||||
ref.Parse("sha1-fb09d21d144c518467325465327d46489cff7c47"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
@@ -45,7 +46,8 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
// Incident
|
||||
|
||||
type Incident struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewIncident() Incident {
|
||||
@@ -55,8 +57,8 @@ func NewIncident() Incident {
|
||||
types.NewString("Description"), types.NewString(""),
|
||||
types.NewString("Address"), types.NewString(""),
|
||||
types.NewString("Date"), types.NewString(""),
|
||||
types.NewString("Geoposition"), sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.NewGeoposition().NomsValue(),
|
||||
)}
|
||||
types.NewString("Geoposition"), sha1_fb09d21d144c518467325465327d46489cff7c47.NewGeoposition(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type IncidentDef struct {
|
||||
@@ -64,7 +66,7 @@ type IncidentDef struct {
|
||||
Description string
|
||||
Address string
|
||||
Date string
|
||||
Geoposition sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionDef
|
||||
Geoposition sha1_fb09d21d144c518467325465327d46489cff7c47.GeopositionDef
|
||||
}
|
||||
|
||||
func (def IncidentDef) New() Incident {
|
||||
@@ -75,8 +77,8 @@ func (def IncidentDef) New() Incident {
|
||||
types.NewString("Description"), types.NewString(def.Description),
|
||||
types.NewString("Address"), types.NewString(def.Address),
|
||||
types.NewString("Date"), types.NewString(def.Date),
|
||||
types.NewString("Geoposition"), def.Geoposition.New().NomsValue(),
|
||||
)}
|
||||
types.NewString("Geoposition"), def.Geoposition.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Def() (d IncidentDef) {
|
||||
@@ -84,7 +86,7 @@ func (s Incident) Def() (d IncidentDef) {
|
||||
d.Description = s.m.Get(types.NewString("Description")).(types.String).String()
|
||||
d.Address = s.m.Get(types.NewString("Address")).(types.String).String()
|
||||
d.Date = s.m.Get(types.NewString("Date")).(types.String).String()
|
||||
d.Geoposition = sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition"))).Def()
|
||||
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition).Def()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,29 +97,38 @@ func (m Incident) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.Value {
|
||||
return IncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func IncidentFromVal(val types.Value) Incident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Incident); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Incident{val.(types.Map)}
|
||||
return Incident{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Incident) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Incident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Incident); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Incident) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Incident) Chunks() (futures []types.Future) {
|
||||
@@ -131,7 +142,7 @@ func (s Incident) Category() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetCategory(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Category"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Category"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Description() string {
|
||||
@@ -139,7 +150,7 @@ func (s Incident) Description() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetDescription(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Description"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Description"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Address() string {
|
||||
@@ -147,7 +158,7 @@ func (s Incident) Address() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetAddress(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Address"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Address"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Date() string {
|
||||
@@ -155,33 +166,34 @@ func (s Incident) Date() string {
|
||||
}
|
||||
|
||||
func (s Incident) SetDate(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val))}
|
||||
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Geoposition() sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition {
|
||||
return sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
|
||||
func (s Incident) Geoposition() sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition {
|
||||
return s.m.Get(types.NewString("Geoposition")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition)
|
||||
}
|
||||
|
||||
func (s Incident) SetGeoposition(val sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Geoposition"), val.NomsValue())}
|
||||
func (s Incident) SetGeoposition(val sha1_fb09d21d144c518467325465327d46489cff7c47.Geoposition) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// SQuadTree
|
||||
|
||||
type SQuadTree struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSQuadTree() SQuadTree {
|
||||
return SQuadTree{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("Nodes"), types.NewList(),
|
||||
types.NewString("Tiles"), types.NewMap(),
|
||||
types.NewString("Nodes"), NewListOfIncident(),
|
||||
types.NewString("Tiles"), NewMapOfStringToSQuadTree(),
|
||||
types.NewString("Depth"), types.UInt8(0),
|
||||
types.NewString("NumDescendents"), types.UInt32(0),
|
||||
types.NewString("Path"), types.NewString(""),
|
||||
types.NewString("Georectangle"), sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.NewGeorectangle().NomsValue(),
|
||||
)}
|
||||
types.NewString("Georectangle"), sha1_fb09d21d144c518467325465327d46489cff7c47.NewGeorectangle(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SQuadTreeDef struct {
|
||||
@@ -190,29 +202,29 @@ type SQuadTreeDef struct {
|
||||
Depth uint8
|
||||
NumDescendents uint32
|
||||
Path string
|
||||
Georectangle sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeorectangleDef
|
||||
Georectangle sha1_fb09d21d144c518467325465327d46489cff7c47.GeorectangleDef
|
||||
}
|
||||
|
||||
func (def SQuadTreeDef) New() SQuadTree {
|
||||
return SQuadTree{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("Nodes"), def.Nodes.New().NomsValue(),
|
||||
types.NewString("Tiles"), def.Tiles.New().NomsValue(),
|
||||
types.NewString("Nodes"), def.Nodes.New(),
|
||||
types.NewString("Tiles"), def.Tiles.New(),
|
||||
types.NewString("Depth"), types.UInt8(def.Depth),
|
||||
types.NewString("NumDescendents"), types.UInt32(def.NumDescendents),
|
||||
types.NewString("Path"), types.NewString(def.Path),
|
||||
types.NewString("Georectangle"), def.Georectangle.New().NomsValue(),
|
||||
)}
|
||||
types.NewString("Georectangle"), def.Georectangle.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) Def() (d SQuadTreeDef) {
|
||||
d.Nodes = ListOfIncidentFromVal(s.m.Get(types.NewString("Nodes"))).Def()
|
||||
d.Tiles = MapOfStringToSQuadTreeFromVal(s.m.Get(types.NewString("Tiles"))).Def()
|
||||
d.Nodes = s.m.Get(types.NewString("Nodes")).(ListOfIncident).Def()
|
||||
d.Tiles = s.m.Get(types.NewString("Tiles")).(MapOfStringToSQuadTree).Def()
|
||||
d.Depth = uint8(s.m.Get(types.NewString("Depth")).(types.UInt8))
|
||||
d.NumDescendents = uint32(s.m.Get(types.NewString("NumDescendents")).(types.UInt32))
|
||||
d.Path = s.m.Get(types.NewString("Path")).(types.String).String()
|
||||
d.Georectangle = sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeorectangleFromVal(s.m.Get(types.NewString("Georectangle"))).Def()
|
||||
d.Georectangle = s.m.Get(types.NewString("Georectangle")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Georectangle).Def()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -223,29 +235,38 @@ func (m SQuadTree) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForSQuadTree, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSQuadTree, func(v types.Value) types.Value {
|
||||
return SQuadTreeFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func SQuadTreeFromVal(val types.Value) SQuadTree {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SQuadTree); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return SQuadTree{val.(types.Map)}
|
||||
return SQuadTree{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SQuadTree) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s SQuadTree) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SQuadTree); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SQuadTree) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SQuadTree) Chunks() (futures []types.Future) {
|
||||
@@ -255,19 +276,19 @@ func (s SQuadTree) Chunks() (futures []types.Future) {
|
||||
}
|
||||
|
||||
func (s SQuadTree) Nodes() ListOfIncident {
|
||||
return ListOfIncidentFromVal(s.m.Get(types.NewString("Nodes")))
|
||||
return s.m.Get(types.NewString("Nodes")).(ListOfIncident)
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetNodes(val ListOfIncident) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Nodes"), val.NomsValue())}
|
||||
return SQuadTree{s.m.Set(types.NewString("Nodes"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) Tiles() MapOfStringToSQuadTree {
|
||||
return MapOfStringToSQuadTreeFromVal(s.m.Get(types.NewString("Tiles")))
|
||||
return s.m.Get(types.NewString("Tiles")).(MapOfStringToSQuadTree)
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetTiles(val MapOfStringToSQuadTree) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Tiles"), val.NomsValue())}
|
||||
return SQuadTree{s.m.Set(types.NewString("Tiles"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) Depth() uint8 {
|
||||
@@ -275,7 +296,7 @@ func (s SQuadTree) Depth() uint8 {
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetDepth(val uint8) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Depth"), types.UInt8(val))}
|
||||
return SQuadTree{s.m.Set(types.NewString("Depth"), types.UInt8(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) NumDescendents() uint32 {
|
||||
@@ -283,7 +304,7 @@ func (s SQuadTree) NumDescendents() uint32 {
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetNumDescendents(val uint32) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("NumDescendents"), types.UInt32(val))}
|
||||
return SQuadTree{s.m.Set(types.NewString("NumDescendents"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) Path() string {
|
||||
@@ -291,25 +312,26 @@ func (s SQuadTree) Path() string {
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetPath(val string) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Path"), types.NewString(val))}
|
||||
return SQuadTree{s.m.Set(types.NewString("Path"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SQuadTree) Georectangle() sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Georectangle {
|
||||
return sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeorectangleFromVal(s.m.Get(types.NewString("Georectangle")))
|
||||
func (s SQuadTree) Georectangle() sha1_fb09d21d144c518467325465327d46489cff7c47.Georectangle {
|
||||
return s.m.Get(types.NewString("Georectangle")).(sha1_fb09d21d144c518467325465327d46489cff7c47.Georectangle)
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetGeorectangle(val sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Georectangle) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Georectangle"), val.NomsValue())}
|
||||
func (s SQuadTree) SetGeorectangle(val sha1_fb09d21d144c518467325465327d46489cff7c47.Georectangle) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Georectangle"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfIncident
|
||||
|
||||
type ListOfIncident struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfIncident() ListOfIncident {
|
||||
return ListOfIncident{types.NewList()}
|
||||
return ListOfIncident{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfIncidentDef []IncidentDef
|
||||
@@ -317,37 +339,46 @@ type ListOfIncidentDef []IncidentDef
|
||||
func (def ListOfIncidentDef) New() ListOfIncident {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfIncident{types.NewList(l...)}
|
||||
return ListOfIncident{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Def() ListOfIncidentDef {
|
||||
d := make([]IncidentDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = IncidentFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(Incident).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfIncidentFromVal(val types.Value) ListOfIncident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfIncident); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfIncident{val.(types.List)}
|
||||
return ListOfIncident{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfIncident) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfIncident); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Chunks() (futures []types.Future) {
|
||||
@@ -365,7 +396,7 @@ func (m ListOfIncident) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfIncident, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfIncident, func(v types.Value) types.Value {
|
||||
return ListOfIncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -379,37 +410,37 @@ func (l ListOfIncident) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Get(i uint64) Incident {
|
||||
return IncidentFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(Incident)
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Slice(idx uint64, end uint64) ListOfIncident {
|
||||
return ListOfIncident{l.l.Slice(idx, end)}
|
||||
return ListOfIncident{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Set(i uint64, val Incident) ListOfIncident {
|
||||
return ListOfIncident{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfIncident{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Append(v ...Incident) ListOfIncident {
|
||||
return ListOfIncident{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfIncident{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Insert(idx uint64, v ...Incident) ListOfIncident {
|
||||
return ListOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) Remove(idx uint64, end uint64) ListOfIncident {
|
||||
return ListOfIncident{l.l.Remove(idx, end)}
|
||||
return ListOfIncident{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) RemoveAt(idx uint64) ListOfIncident {
|
||||
return ListOfIncident{(l.l.RemoveAt(idx))}
|
||||
return ListOfIncident{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfIncident) fromElemSlice(p []Incident) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -418,7 +449,7 @@ type ListOfIncidentIterCallback func(v Incident, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfIncident) Iter(cb ListOfIncidentIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(IncidentFromVal(v), i)
|
||||
return cb(v.(Incident), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -426,7 +457,7 @@ type ListOfIncidentIterAllCallback func(v Incident, i uint64)
|
||||
|
||||
func (l ListOfIncident) IterAll(cb ListOfIncidentIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(IncidentFromVal(v), i)
|
||||
cb(v.(Incident), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -445,11 +476,12 @@ func (l ListOfIncident) Filter(cb ListOfIncidentFilterCallback) ListOfIncident {
|
||||
// MapOfStringToSQuadTree
|
||||
|
||||
type MapOfStringToSQuadTree struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToSQuadTree() MapOfStringToSQuadTree {
|
||||
return MapOfStringToSQuadTree{types.NewMap()}
|
||||
return MapOfStringToSQuadTree{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToSQuadTreeDef map[string]SQuadTreeDef
|
||||
@@ -457,38 +489,47 @@ type MapOfStringToSQuadTreeDef map[string]SQuadTreeDef
|
||||
func (def MapOfStringToSQuadTreeDef) New() MapOfStringToSQuadTree {
|
||||
kv := make([]types.Value, 0, len(def)*2)
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.NewString(k), v.New().NomsValue())
|
||||
kv = append(kv, types.NewString(k), v.New())
|
||||
}
|
||||
return MapOfStringToSQuadTree{types.NewMap(kv...)}
|
||||
return MapOfStringToSQuadTree{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) Def() MapOfStringToSQuadTreeDef {
|
||||
def := make(map[string]SQuadTreeDef)
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
def[k.(types.String).String()] = SQuadTreeFromVal(v).Def()
|
||||
def[k.(types.String).String()] = v.(SQuadTree).Def()
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfStringToSQuadTreeFromVal(p types.Value) MapOfStringToSQuadTree {
|
||||
func MapOfStringToSQuadTreeFromVal(val types.Value) MapOfStringToSQuadTree {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToSQuadTree); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToSQuadTree{p.(types.Map)}
|
||||
return MapOfStringToSQuadTree{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToSQuadTree); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) Chunks() (futures []types.Future) {
|
||||
@@ -506,7 +547,7 @@ func (m MapOfStringToSQuadTree) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToSQuadTree, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToSQuadTree, func(v types.Value) types.Value {
|
||||
return MapOfStringToSQuadTreeFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -524,7 +565,7 @@ func (m MapOfStringToSQuadTree) Has(p string) bool {
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) Get(p string) SQuadTree {
|
||||
return SQuadTreeFromVal(m.m.Get(types.NewString(p)))
|
||||
return m.m.Get(types.NewString(p)).(SQuadTree)
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) MaybeGet(p string) (SQuadTree, bool) {
|
||||
@@ -532,24 +573,24 @@ func (m MapOfStringToSQuadTree) MaybeGet(p string) (SQuadTree, bool) {
|
||||
if !ok {
|
||||
return NewSQuadTree(), false
|
||||
}
|
||||
return SQuadTreeFromVal(v), ok
|
||||
return v.(SQuadTree), ok
|
||||
}
|
||||
|
||||
func (m MapOfStringToSQuadTree) Set(k string, v SQuadTree) MapOfStringToSQuadTree {
|
||||
return MapOfStringToSQuadTree{m.m.Set(types.NewString(k), v.NomsValue())}
|
||||
return MapOfStringToSQuadTree{m.m.Set(types.NewString(k), v), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToSQuadTree) Remove(p string) MapOfStringToSQuadTree {
|
||||
return MapOfStringToSQuadTree{m.m.Remove(types.NewString(p))}
|
||||
return MapOfStringToSQuadTree{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToSQuadTreeIterCallback func(k string, v SQuadTree) (stop bool)
|
||||
|
||||
func (m MapOfStringToSQuadTree) Iter(cb MapOfStringToSQuadTreeIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(k.(types.String).String(), SQuadTreeFromVal(v))
|
||||
return cb(k.(types.String).String(), v.(SQuadTree))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -557,7 +598,7 @@ type MapOfStringToSQuadTreeIterAllCallback func(k string, v SQuadTree)
|
||||
|
||||
func (m MapOfStringToSQuadTree) IterAll(cb MapOfStringToSQuadTreeIterAllCallback) {
|
||||
m.m.IterAll(func(k, v types.Value) {
|
||||
cb(k.(types.String).String(), SQuadTreeFromVal(v))
|
||||
cb(k.(types.String).String(), v.(SQuadTree))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+187
-187
@@ -37,30 +37,6 @@ func (s RemotePhoto) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Sizes() MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(s.m.Get(types.NewString("sizes")))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetSizes(p MapOfSizeToString) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("sizes"), p.NomsValue()))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Title() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("title")))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetTitle(p types.String) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("title"), p))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Id() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("id")))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetId(p types.String) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("id"), p))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Tags() SetOfString {
|
||||
return SetOfStringFromVal(s.m.Get(types.NewString("tags")))
|
||||
}
|
||||
@@ -77,6 +53,30 @@ func (s RemotePhoto) SetGeoposition(p Geoposition) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("geoposition"), p.NomsValue()))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Id() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("id")))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetId(p types.String) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("id"), p))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Title() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("title")))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetTitle(p types.String) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("title"), p))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Sizes() MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(s.m.Get(types.NewString("sizes")))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetSizes(p MapOfSizeToString) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("sizes"), p.NomsValue()))
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Url() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("url")))
|
||||
}
|
||||
@@ -85,6 +85,66 @@ func (s RemotePhoto) SetUrl(p types.String) RemotePhoto {
|
||||
return RemotePhotoFromVal(s.m.Set(types.NewString("url"), p))
|
||||
}
|
||||
|
||||
// MapOfSizeToString
|
||||
|
||||
type MapOfSizeToString struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
type MapOfSizeToStringIterCallback (func(k Size, v types.String) (stop bool))
|
||||
|
||||
func NewMapOfSizeToString() MapOfSizeToString {
|
||||
return MapOfSizeToString{types.NewMap()}
|
||||
}
|
||||
|
||||
func MapOfSizeToStringFromVal(p types.Value) MapOfSizeToString {
|
||||
return MapOfSizeToString{p.(types.Map)}
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) NomsValue() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Equals(p MapOfSizeToString) bool {
|
||||
return m.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Empty() bool {
|
||||
return m.m.Empty()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Len() uint64 {
|
||||
return m.m.Len()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Has(p Size) bool {
|
||||
return m.m.Has(p.NomsValue())
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Get(p Size) types.String {
|
||||
return types.StringFromVal(m.m.Get(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Set(k Size, v types.String) MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(m.m.Set(k.NomsValue(), v))
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(m.m.Remove(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(SizeFromVal(k), types.StringFromVal(v))
|
||||
})
|
||||
}
|
||||
|
||||
// SetOfString
|
||||
|
||||
type SetOfString struct {
|
||||
@@ -167,6 +227,51 @@ func (s SetOfString) fromElemSlice(p []types.String) []types.Value {
|
||||
return r
|
||||
}
|
||||
|
||||
// Size
|
||||
|
||||
type Size struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewSize() Size {
|
||||
return Size{
|
||||
types.NewMap(types.NewString("$name"), types.NewString("Size")),
|
||||
}
|
||||
}
|
||||
|
||||
func SizeFromVal(v types.Value) Size {
|
||||
return Size{v.(types.Map)}
|
||||
}
|
||||
|
||||
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
|
||||
func (s Size) NomsValue() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Size) Equals(p Size) bool {
|
||||
return s.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (s Size) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s Size) Width() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("width")))
|
||||
}
|
||||
|
||||
func (s Size) SetWidth(p types.UInt32) Size {
|
||||
return SizeFromVal(s.m.Set(types.NewString("width"), p))
|
||||
}
|
||||
|
||||
func (s Size) Height() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("height")))
|
||||
}
|
||||
|
||||
func (s Size) SetHeight(p types.UInt32) Size {
|
||||
return SizeFromVal(s.m.Set(types.NewString("height"), p))
|
||||
}
|
||||
|
||||
// Photo
|
||||
|
||||
type Photo struct {
|
||||
@@ -196,30 +301,6 @@ func (s Photo) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s Photo) Width() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("width")))
|
||||
}
|
||||
|
||||
func (s Photo) SetWidth(p types.UInt32) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("width"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Title() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("title")))
|
||||
}
|
||||
|
||||
func (s Photo) SetTitle(p types.String) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("title"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Id() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("id")))
|
||||
}
|
||||
|
||||
func (s Photo) SetId(p types.String) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("id"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Tags() SetOfString {
|
||||
return SetOfStringFromVal(s.m.Get(types.NewString("tags")))
|
||||
}
|
||||
@@ -228,22 +309,6 @@ func (s Photo) SetTags(p SetOfString) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("tags"), p.NomsValue()))
|
||||
}
|
||||
|
||||
func (s Photo) Height() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("height")))
|
||||
}
|
||||
|
||||
func (s Photo) SetHeight(p types.UInt32) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("height"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Geoposition() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("geoposition")))
|
||||
}
|
||||
|
||||
func (s Photo) SetGeoposition(p Geoposition) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("geoposition"), p.NomsValue()))
|
||||
}
|
||||
|
||||
func (s Photo) Image() types.Blob {
|
||||
return types.BlobFromVal(s.m.Get(types.NewString("image")))
|
||||
}
|
||||
@@ -252,6 +317,46 @@ func (s Photo) SetImage(p types.Blob) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("image"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Width() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("width")))
|
||||
}
|
||||
|
||||
func (s Photo) SetWidth(p types.UInt32) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("width"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Geoposition() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("geoposition")))
|
||||
}
|
||||
|
||||
func (s Photo) SetGeoposition(p Geoposition) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("geoposition"), p.NomsValue()))
|
||||
}
|
||||
|
||||
func (s Photo) Id() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("id")))
|
||||
}
|
||||
|
||||
func (s Photo) SetId(p types.String) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("id"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Height() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("height")))
|
||||
}
|
||||
|
||||
func (s Photo) SetHeight(p types.UInt32) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("height"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Title() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("title")))
|
||||
}
|
||||
|
||||
func (s Photo) SetTitle(p types.String) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("title"), p))
|
||||
}
|
||||
|
||||
func (s Photo) Url() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("url")))
|
||||
}
|
||||
@@ -260,111 +365,6 @@ func (s Photo) SetUrl(p types.String) Photo {
|
||||
return PhotoFromVal(s.m.Set(types.NewString("url"), p))
|
||||
}
|
||||
|
||||
// Geoposition
|
||||
|
||||
type Geoposition struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewGeoposition() Geoposition {
|
||||
return Geoposition{
|
||||
types.NewMap(types.NewString("$name"), types.NewString("Geoposition")),
|
||||
}
|
||||
}
|
||||
|
||||
func GeopositionFromVal(v types.Value) Geoposition {
|
||||
return Geoposition{v.(types.Map)}
|
||||
}
|
||||
|
||||
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
|
||||
func (s Geoposition) NomsValue() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Geoposition) Equals(p Geoposition) bool {
|
||||
return s.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (s Geoposition) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s Geoposition) Longitude() types.Float32 {
|
||||
return types.Float32FromVal(s.m.Get(types.NewString("longitude")))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLongitude(p types.Float32) Geoposition {
|
||||
return GeopositionFromVal(s.m.Set(types.NewString("longitude"), p))
|
||||
}
|
||||
|
||||
func (s Geoposition) Latitude() types.Float32 {
|
||||
return types.Float32FromVal(s.m.Get(types.NewString("latitude")))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLatitude(p types.Float32) Geoposition {
|
||||
return GeopositionFromVal(s.m.Set(types.NewString("latitude"), p))
|
||||
}
|
||||
|
||||
// MapOfSizeToString
|
||||
|
||||
type MapOfSizeToString struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
type MapOfSizeToStringIterCallback (func(k Size, v types.String) (stop bool))
|
||||
|
||||
func NewMapOfSizeToString() MapOfSizeToString {
|
||||
return MapOfSizeToString{types.NewMap()}
|
||||
}
|
||||
|
||||
func MapOfSizeToStringFromVal(p types.Value) MapOfSizeToString {
|
||||
return MapOfSizeToString{p.(types.Map)}
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) NomsValue() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Equals(p MapOfSizeToString) bool {
|
||||
return m.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Empty() bool {
|
||||
return m.m.Empty()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Len() uint64 {
|
||||
return m.m.Len()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Has(p Size) bool {
|
||||
return m.m.Has(p.NomsValue())
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Get(p Size) types.String {
|
||||
return types.StringFromVal(m.m.Get(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Set(k Size, v types.String) MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(m.m.Set(k.NomsValue(), v))
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
|
||||
return MapOfSizeToStringFromVal(m.m.Remove(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(SizeFromVal(k), types.StringFromVal(v))
|
||||
})
|
||||
}
|
||||
|
||||
// MapOfStringToSet
|
||||
|
||||
type MapOfStringToSet struct {
|
||||
@@ -425,48 +425,48 @@ func (m MapOfStringToSet) Iter(cb MapOfStringToSetIterCallback) {
|
||||
})
|
||||
}
|
||||
|
||||
// Size
|
||||
// Geoposition
|
||||
|
||||
type Size struct {
|
||||
type Geoposition struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewSize() Size {
|
||||
return Size{
|
||||
types.NewMap(types.NewString("$name"), types.NewString("Size")),
|
||||
func NewGeoposition() Geoposition {
|
||||
return Geoposition{
|
||||
types.NewMap(types.NewString("$name"), types.NewString("Geoposition")),
|
||||
}
|
||||
}
|
||||
|
||||
func SizeFromVal(v types.Value) Size {
|
||||
return Size{v.(types.Map)}
|
||||
func GeopositionFromVal(v types.Value) Geoposition {
|
||||
return Geoposition{v.(types.Map)}
|
||||
}
|
||||
|
||||
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
|
||||
func (s Size) NomsValue() types.Map {
|
||||
func (s Geoposition) NomsValue() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Size) Equals(p Size) bool {
|
||||
func (s Geoposition) Equals(p Geoposition) bool {
|
||||
return s.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (s Size) Ref() ref.Ref {
|
||||
func (s Geoposition) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s Size) Width() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("width")))
|
||||
func (s Geoposition) Latitude() types.Float32 {
|
||||
return types.Float32FromVal(s.m.Get(types.NewString("latitude")))
|
||||
}
|
||||
|
||||
func (s Size) SetWidth(p types.UInt32) Size {
|
||||
return SizeFromVal(s.m.Set(types.NewString("width"), p))
|
||||
func (s Geoposition) SetLatitude(p types.Float32) Geoposition {
|
||||
return GeopositionFromVal(s.m.Set(types.NewString("latitude"), p))
|
||||
}
|
||||
|
||||
func (s Size) Height() types.UInt32 {
|
||||
return types.UInt32FromVal(s.m.Get(types.NewString("height")))
|
||||
func (s Geoposition) Longitude() types.Float32 {
|
||||
return types.Float32FromVal(s.m.Get(types.NewString("longitude")))
|
||||
}
|
||||
|
||||
func (s Size) SetHeight(p types.UInt32) Size {
|
||||
return SizeFromVal(s.m.Set(types.NewString("height"), p))
|
||||
func (s Geoposition) SetLongitude(p types.Float32) Geoposition {
|
||||
return GeopositionFromVal(s.m.Set(types.NewString("longitude"), p))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package util
|
||||
import (
|
||||
"math"
|
||||
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_fb09d21d144c518467325465327d46489cff7c47"
|
||||
)
|
||||
|
||||
func TestPoint(t *testing.T) {
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ type DataStore interface {
|
||||
// Head returns the current head Commit, which contains the current root of the DataStore's value tree.
|
||||
Head(datasetID string) Commit
|
||||
|
||||
// Datasets returns the root of the datastore which is a MapOfStringToCommit where string is a datasetID.
|
||||
Datasets() MapOfStringToCommit
|
||||
// Datasets returns the root of the datastore which is a MapOfStringToRefOfCommit where string is a datasetID.
|
||||
Datasets() MapOfStringToRefOfCommit
|
||||
|
||||
// Commit updates the commit that a datastore points at. The new Commit is constructed using v and the current Head. If the update cannot be performed, e.g., because of a conflict, Commit returns 'false'. The newest snapshot of the datastore is always returned.
|
||||
Commit(datasetID string, commit Commit) (DataStore, bool)
|
||||
|
||||
+29
-23
@@ -9,20 +9,21 @@ import (
|
||||
|
||||
type dataStoreCommon struct {
|
||||
chunks.ChunkStore
|
||||
datasets *MapOfStringToCommit
|
||||
datasets *MapOfStringToRefOfCommit
|
||||
}
|
||||
|
||||
func datasetsFromRef(datasetsRef ref.Ref, cs chunks.ChunkSource) *MapOfStringToCommit {
|
||||
c := MapOfStringToCommitFromVal(types.ReadValue(datasetsRef, cs))
|
||||
func datasetsFromRef(datasetsRef ref.Ref, cs chunks.ChunkSource) *MapOfStringToRefOfCommit {
|
||||
c := MapOfStringToRefOfCommitFromVal(types.ReadValue(datasetsRef, cs))
|
||||
return &c
|
||||
}
|
||||
|
||||
func (ds *dataStoreCommon) MaybeHead(datasetID string) (Commit, bool) {
|
||||
if ds.datasets != nil {
|
||||
return ds.datasets.MaybeGet(datasetID)
|
||||
} else {
|
||||
return NewCommit(), false
|
||||
if r, ok := ds.datasets.MaybeGet(datasetID); ok {
|
||||
return r.GetValue(ds), true
|
||||
}
|
||||
}
|
||||
return NewCommit(), false
|
||||
}
|
||||
|
||||
func (ds *dataStoreCommon) Head(datasetID string) Commit {
|
||||
@@ -31,9 +32,9 @@ func (ds *dataStoreCommon) Head(datasetID string) Commit {
|
||||
return c
|
||||
}
|
||||
|
||||
func (ds *dataStoreCommon) Datasets() MapOfStringToCommit {
|
||||
func (ds *dataStoreCommon) Datasets() MapOfStringToRefOfCommit {
|
||||
if ds.datasets == nil {
|
||||
return NewMapOfStringToCommit()
|
||||
return NewMapOfStringToRefOfCommit()
|
||||
} else {
|
||||
return *ds.datasets
|
||||
}
|
||||
@@ -46,53 +47,58 @@ func (ds *dataStoreCommon) commit(datasetID string, commit Commit) bool {
|
||||
// doCommit manages concurrent access the single logical piece of mutable state: the current head. doCommit is optimistic in that it is attempting to update head making the assumption that currentRootRef is the ref of the current head. The call to UpdateRoot below will fail if that assumption fails (e.g. because of a race with another writer) and the entire algorithm must be tried again.
|
||||
func (ds *dataStoreCommon) doCommit(datasetID string, commit Commit) bool {
|
||||
currentRootRef := ds.Root()
|
||||
var currentDatasets MapOfStringToCommit
|
||||
var currentDatasets MapOfStringToRefOfCommit
|
||||
if ds.datasets != nil && currentRootRef == ds.datasets.Ref() {
|
||||
currentDatasets = *ds.datasets
|
||||
} else if !currentRootRef.IsEmpty() {
|
||||
currentDatasets = *datasetsFromRef(currentRootRef, ds)
|
||||
} else {
|
||||
currentDatasets = NewMapOfStringToCommit()
|
||||
currentDatasets = NewMapOfStringToRefOfCommit()
|
||||
}
|
||||
|
||||
// TODO: This Commit will be orphaned if the UpdateRoot below fails
|
||||
commitRef := NewRefOfCommit(types.WriteValue(commit, ds))
|
||||
|
||||
// First commit in store is always fast-foward.
|
||||
if !currentRootRef.IsEmpty() {
|
||||
var currentHead Commit
|
||||
currentHead, hasHead := currentDatasets.MaybeGet(datasetID)
|
||||
var currentHeadRef RefOfCommit
|
||||
currentHeadRef, hasHead := currentDatasets.MaybeGet(datasetID)
|
||||
|
||||
// First commit in dataset is always fast-foward.
|
||||
if hasHead {
|
||||
// Allow only fast-forward commits.
|
||||
if commit.Equals(currentHead) {
|
||||
if commitRef.Equals(currentHeadRef) {
|
||||
return true
|
||||
} else if !descendsFrom(commit, currentHead) {
|
||||
}
|
||||
if !descendsFrom(commitRef, currentHeadRef, ds) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: This Commit will be orphaned if the UpdateRoot below fails
|
||||
currentDatasets = currentDatasets.Set(datasetID, commit)
|
||||
newRootRef := types.WriteValue(currentDatasets.NomsValue(), ds)
|
||||
currentDatasets = currentDatasets.Set(datasetID, commitRef)
|
||||
newRootRef := types.WriteValue(currentDatasets, ds)
|
||||
|
||||
// If the root has been updated by another process in the short window since we read it, this call will fail. See issue #404
|
||||
return ds.UpdateRoot(newRootRef, currentRootRef)
|
||||
}
|
||||
|
||||
func descendsFrom(commit, currentHead Commit) bool {
|
||||
func descendsFrom(commitRef, currentHeadRef RefOfCommit, cs chunks.ChunkSource) bool {
|
||||
// BFS because the common case is that the ancestor is only a step or two away
|
||||
ancestors := NewSetOfCommit().Insert(commit)
|
||||
for !ancestors.Has(currentHead) {
|
||||
ancestors := NewSetOfRefOfCommit().Insert(commitRef)
|
||||
for !ancestors.Has(currentHeadRef) {
|
||||
if ancestors.Empty() {
|
||||
return false
|
||||
}
|
||||
ancestors = getAncestors(ancestors)
|
||||
ancestors = getAncestors(ancestors, cs)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getAncestors(commits SetOfCommit) SetOfCommit {
|
||||
ancestors := NewSetOfCommit()
|
||||
commits.Iter(func(c Commit) (stop bool) {
|
||||
func getAncestors(commits SetOfRefOfCommit, cs chunks.ChunkSource) SetOfRefOfCommit {
|
||||
ancestors := NewSetOfRefOfCommit()
|
||||
commits.Iter(func(r RefOfCommit) (stop bool) {
|
||||
c := r.GetValue(cs)
|
||||
ancestors =
|
||||
ancestors.Union(c.Parents())
|
||||
return
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestDataStoreCommit(t *testing.T) {
|
||||
|
||||
// |a| <- |b|
|
||||
b := types.NewString("b")
|
||||
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfCommit().Insert(aCommit))
|
||||
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
|
||||
ds, ok = ds.Commit(datasetID, bCommit)
|
||||
assert.True(ok)
|
||||
assert.True(ds.Head(datasetID).Value().Equals(b))
|
||||
@@ -50,7 +50,7 @@ func TestDataStoreCommit(t *testing.T) {
|
||||
|
||||
// |a| <- |b| <- |d|
|
||||
d := types.NewString("d")
|
||||
dCommit := NewCommit().SetValue(d).SetParents(NewSetOfCommit().Insert(bCommit))
|
||||
dCommit := NewCommit().SetValue(d).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(bCommit.Ref())))
|
||||
ds, ok = ds.Commit(datasetID, dCommit)
|
||||
assert.True(ok)
|
||||
assert.True(ds.Head(datasetID).Value().Equals(d))
|
||||
@@ -84,7 +84,7 @@ func TestDataStoreConcurrency(t *testing.T) {
|
||||
aCommit := NewCommit().SetValue(a)
|
||||
ds, ok := ds.Commit(datasetID, aCommit)
|
||||
b := types.NewString("b")
|
||||
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfCommit().Insert(aCommit))
|
||||
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
|
||||
ds, ok = ds.Commit(datasetID, bCommit)
|
||||
assert.True(ok)
|
||||
assert.True(ds.Head(datasetID).Value().Equals(b))
|
||||
@@ -95,7 +95,7 @@ func TestDataStoreConcurrency(t *testing.T) {
|
||||
// Change 1:
|
||||
// |a| <- |b| <- |c|
|
||||
c := types.NewString("c")
|
||||
cCommit := NewCommit().SetValue(c).SetParents(NewSetOfCommit().Insert(bCommit))
|
||||
cCommit := NewCommit().SetValue(c).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(bCommit.Ref())))
|
||||
ds, ok = ds.Commit(datasetID, cCommit)
|
||||
assert.True(ok)
|
||||
assert.True(ds.Head(datasetID).Value().Equals(c))
|
||||
@@ -104,7 +104,7 @@ func TestDataStoreConcurrency(t *testing.T) {
|
||||
// |a| <- |b| <- |e|
|
||||
// Should be disallowed, DataStore returned by Commit() should have |c| as Head.
|
||||
e := types.NewString("e")
|
||||
eCommit := NewCommit().SetValue(e).SetParents(NewSetOfCommit().Insert(bCommit))
|
||||
eCommit := NewCommit().SetValue(e).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(bCommit.Ref())))
|
||||
ds2, ok = ds2.Commit(datasetID, eCommit)
|
||||
assert.False(ok)
|
||||
assert.True(ds.Head(datasetID).Value().Equals(c))
|
||||
|
||||
+260
-104
@@ -3,6 +3,7 @@
|
||||
package datas
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
@@ -17,7 +18,7 @@ func __datasPackageInFile_types_Ref() ref.Ref {
|
||||
types.MakeStructTypeRef("Commit",
|
||||
[]types.Field{
|
||||
types.Field{"value", types.MakePrimitiveTypeRef(types.ValueKind), false},
|
||||
types.Field{"parents", types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef(ref.Ref{}, 0)), false},
|
||||
types.Field{"parents", types.MakeCompoundTypeRef("", types.SetKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef(ref.Ref{}, 0))), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
@@ -28,15 +29,36 @@ func __datasPackageInFile_types_Ref() ref.Ref {
|
||||
// Commit
|
||||
|
||||
type Commit struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewCommit() Commit {
|
||||
return Commit{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("value"), types.Bool(false),
|
||||
types.NewString("parents"), types.NewSet(),
|
||||
)}
|
||||
types.NewString("parents"), NewSetOfRefOfCommit(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type CommitDef struct {
|
||||
Value types.Value
|
||||
Parents SetOfRefOfCommitDef
|
||||
}
|
||||
|
||||
func (def CommitDef) New() Commit {
|
||||
return Commit{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("value"), def.Value,
|
||||
types.NewString("parents"), def.Parents.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Commit) Def() (d CommitDef) {
|
||||
d.Value = s.m.Get(types.NewString("value"))
|
||||
d.Parents = s.m.Get(types.NewString("parents")).(SetOfRefOfCommit).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForCommit = types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0)
|
||||
@@ -46,29 +68,38 @@ func (m Commit) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForCommit, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForCommit, func(v types.Value) types.Value {
|
||||
return CommitFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func CommitFromVal(val types.Value) Commit {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Commit); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Commit{val.(types.Map)}
|
||||
return Commit{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Commit) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Commit) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Commit) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Commit); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Commit) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Commit) Chunks() (futures []types.Future) {
|
||||
@@ -82,122 +113,151 @@ func (s Commit) Value() types.Value {
|
||||
}
|
||||
|
||||
func (s Commit) SetValue(val types.Value) Commit {
|
||||
return Commit{s.m.Set(types.NewString("value"), val)}
|
||||
return Commit{s.m.Set(types.NewString("value"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Commit) Parents() SetOfCommit {
|
||||
return SetOfCommitFromVal(s.m.Get(types.NewString("parents")))
|
||||
func (s Commit) Parents() SetOfRefOfCommit {
|
||||
return s.m.Get(types.NewString("parents")).(SetOfRefOfCommit)
|
||||
}
|
||||
|
||||
func (s Commit) SetParents(val SetOfCommit) Commit {
|
||||
return Commit{s.m.Set(types.NewString("parents"), val.NomsValue())}
|
||||
func (s Commit) SetParents(val SetOfRefOfCommit) Commit {
|
||||
return Commit{s.m.Set(types.NewString("parents"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// MapOfStringToCommit
|
||||
// MapOfStringToRefOfCommit
|
||||
|
||||
type MapOfStringToCommit struct {
|
||||
m types.Map
|
||||
type MapOfStringToRefOfCommit struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToCommit() MapOfStringToCommit {
|
||||
return MapOfStringToCommit{types.NewMap()}
|
||||
func NewMapOfStringToRefOfCommit() MapOfStringToRefOfCommit {
|
||||
return MapOfStringToRefOfCommit{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func MapOfStringToCommitFromVal(p types.Value) MapOfStringToCommit {
|
||||
type MapOfStringToRefOfCommitDef map[string]ref.Ref
|
||||
|
||||
func (def MapOfStringToRefOfCommitDef) New() MapOfStringToRefOfCommit {
|
||||
kv := make([]types.Value, 0, len(def)*2)
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.NewString(k), NewRefOfCommit(v))
|
||||
}
|
||||
return MapOfStringToRefOfCommit{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToRefOfCommit) Def() MapOfStringToRefOfCommitDef {
|
||||
def := make(map[string]ref.Ref)
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
def[k.(types.String).String()] = v.Ref()
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfStringToRefOfCommitFromVal(val types.Value) MapOfStringToRefOfCommit {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToRefOfCommit); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToCommit{p.(types.Map)}
|
||||
return MapOfStringToRefOfCommit{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) NomsValue() types.Value {
|
||||
func (m MapOfStringToRefOfCommit) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToRefOfCommit) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToCommit); ok {
|
||||
return m.m.Equals(other.m)
|
||||
func (m MapOfStringToRefOfCommit) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToRefOfCommit); ok {
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
func (m MapOfStringToRefOfCommit) Ref() ref.Ref {
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Chunks() (futures []types.Future) {
|
||||
func (m MapOfStringToRefOfCommit) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, m.TypeRef().Chunks()...)
|
||||
futures = append(futures, m.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes MapOfStringToCommit.
|
||||
var __typeRefForMapOfStringToCommit types.TypeRef
|
||||
// A Noms Value that describes MapOfStringToRefOfCommit.
|
||||
var __typeRefForMapOfStringToRefOfCommit types.TypeRef
|
||||
|
||||
func (m MapOfStringToCommit) TypeRef() types.TypeRef {
|
||||
return __typeRefForMapOfStringToCommit
|
||||
func (m MapOfStringToRefOfCommit) TypeRef() types.TypeRef {
|
||||
return __typeRefForMapOfStringToRefOfCommit
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToCommit = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToCommit, func(v types.Value) types.NomsValue {
|
||||
return MapOfStringToCommitFromVal(v)
|
||||
__typeRefForMapOfStringToRefOfCommit = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0)))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToRefOfCommit, func(v types.Value) types.Value {
|
||||
return MapOfStringToRefOfCommitFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Empty() bool {
|
||||
func (m MapOfStringToRefOfCommit) Empty() bool {
|
||||
return m.m.Empty()
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Len() uint64 {
|
||||
func (m MapOfStringToRefOfCommit) Len() uint64 {
|
||||
return m.m.Len()
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Has(p string) bool {
|
||||
func (m MapOfStringToRefOfCommit) Has(p string) bool {
|
||||
return m.m.Has(types.NewString(p))
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Get(p string) Commit {
|
||||
return CommitFromVal(m.m.Get(types.NewString(p)))
|
||||
func (m MapOfStringToRefOfCommit) Get(p string) RefOfCommit {
|
||||
return m.m.Get(types.NewString(p)).(RefOfCommit)
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) MaybeGet(p string) (Commit, bool) {
|
||||
func (m MapOfStringToRefOfCommit) MaybeGet(p string) (RefOfCommit, bool) {
|
||||
v, ok := m.m.MaybeGet(types.NewString(p))
|
||||
if !ok {
|
||||
return NewCommit(), false
|
||||
return NewRefOfCommit(ref.Ref{}), false
|
||||
}
|
||||
return CommitFromVal(v), ok
|
||||
return v.(RefOfCommit), ok
|
||||
}
|
||||
|
||||
func (m MapOfStringToCommit) Set(k string, v Commit) MapOfStringToCommit {
|
||||
return MapOfStringToCommit{m.m.Set(types.NewString(k), v.NomsValue())}
|
||||
func (m MapOfStringToRefOfCommit) Set(k string, v RefOfCommit) MapOfStringToRefOfCommit {
|
||||
return MapOfStringToRefOfCommit{m.m.Set(types.NewString(k), v), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToCommit) Remove(p string) MapOfStringToCommit {
|
||||
return MapOfStringToCommit{m.m.Remove(types.NewString(p))}
|
||||
func (m MapOfStringToRefOfCommit) Remove(p string) MapOfStringToRefOfCommit {
|
||||
return MapOfStringToRefOfCommit{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToCommitIterCallback func(k string, v Commit) (stop bool)
|
||||
type MapOfStringToRefOfCommitIterCallback func(k string, v RefOfCommit) (stop bool)
|
||||
|
||||
func (m MapOfStringToCommit) Iter(cb MapOfStringToCommitIterCallback) {
|
||||
func (m MapOfStringToRefOfCommit) Iter(cb MapOfStringToRefOfCommitIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(k.(types.String).String(), CommitFromVal(v))
|
||||
return cb(k.(types.String).String(), v.(RefOfCommit))
|
||||
})
|
||||
}
|
||||
|
||||
type MapOfStringToCommitIterAllCallback func(k string, v Commit)
|
||||
type MapOfStringToRefOfCommitIterAllCallback func(k string, v RefOfCommit)
|
||||
|
||||
func (m MapOfStringToCommit) IterAll(cb MapOfStringToCommitIterAllCallback) {
|
||||
func (m MapOfStringToRefOfCommit) IterAll(cb MapOfStringToRefOfCommitIterAllCallback) {
|
||||
m.m.IterAll(func(k, v types.Value) {
|
||||
cb(k.(types.String).String(), CommitFromVal(v))
|
||||
cb(k.(types.String).String(), v.(RefOfCommit))
|
||||
})
|
||||
}
|
||||
|
||||
type MapOfStringToCommitFilterCallback func(k string, v Commit) (keep bool)
|
||||
type MapOfStringToRefOfCommitFilterCallback func(k string, v RefOfCommit) (keep bool)
|
||||
|
||||
func (m MapOfStringToCommit) Filter(cb MapOfStringToCommitFilterCallback) MapOfStringToCommit {
|
||||
nm := NewMapOfStringToCommit()
|
||||
m.IterAll(func(k string, v Commit) {
|
||||
func (m MapOfStringToRefOfCommit) Filter(cb MapOfStringToRefOfCommitFilterCallback) MapOfStringToRefOfCommit {
|
||||
nm := NewMapOfStringToRefOfCommit()
|
||||
m.IterAll(func(k string, v RefOfCommit) {
|
||||
if cb(k, v) {
|
||||
nm = nm.Set(k, v)
|
||||
}
|
||||
@@ -205,88 +265,119 @@ func (m MapOfStringToCommit) Filter(cb MapOfStringToCommitFilterCallback) MapOfS
|
||||
return nm
|
||||
}
|
||||
|
||||
// SetOfCommit
|
||||
// SetOfRefOfCommit
|
||||
|
||||
type SetOfCommit struct {
|
||||
s types.Set
|
||||
type SetOfRefOfCommit struct {
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfCommit() SetOfCommit {
|
||||
return SetOfCommit{types.NewSet()}
|
||||
func NewSetOfRefOfCommit() SetOfRefOfCommit {
|
||||
return SetOfRefOfCommit{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func SetOfCommitFromVal(p types.Value) SetOfCommit {
|
||||
return SetOfCommit{p.(types.Set)}
|
||||
type SetOfRefOfCommitDef map[ref.Ref]bool
|
||||
|
||||
func (def SetOfRefOfCommitDef) New() SetOfRefOfCommit {
|
||||
l := make([]types.Value, len(def))
|
||||
i := 0
|
||||
for d, _ := range def {
|
||||
l[i] = NewRefOfCommit(d)
|
||||
i++
|
||||
}
|
||||
return SetOfRefOfCommit{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfCommit) NomsValue() types.Value {
|
||||
func (s SetOfRefOfCommit) Def() SetOfRefOfCommitDef {
|
||||
def := make(map[ref.Ref]bool, s.Len())
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
def[v.Ref()] = true
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfRefOfCommitFromVal(val types.Value) SetOfRefOfCommit {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfRefOfCommit); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfRefOfCommit{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfCommit) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfRefOfCommit) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfCommit); ok {
|
||||
return s.s.Equals(other.s)
|
||||
func (s SetOfRefOfCommit) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfRefOfCommit); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
func (s SetOfRefOfCommit) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Chunks() (futures []types.Future) {
|
||||
func (s SetOfRefOfCommit) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.s.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes SetOfCommit.
|
||||
var __typeRefForSetOfCommit types.TypeRef
|
||||
// A Noms Value that describes SetOfRefOfCommit.
|
||||
var __typeRefForSetOfRefOfCommit types.TypeRef
|
||||
|
||||
func (m SetOfCommit) TypeRef() types.TypeRef {
|
||||
return __typeRefForSetOfCommit
|
||||
func (m SetOfRefOfCommit) TypeRef() types.TypeRef {
|
||||
return __typeRefForSetOfRefOfCommit
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfCommit = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfCommit, func(v types.Value) types.NomsValue {
|
||||
return SetOfCommitFromVal(v)
|
||||
__typeRefForSetOfRefOfCommit = types.MakeCompoundTypeRef("", types.SetKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0)))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfRefOfCommit, func(v types.Value) types.Value {
|
||||
return SetOfRefOfCommitFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Empty() bool {
|
||||
func (s SetOfRefOfCommit) Empty() bool {
|
||||
return s.s.Empty()
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Len() uint64 {
|
||||
func (s SetOfRefOfCommit) Len() uint64 {
|
||||
return s.s.Len()
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Has(p Commit) bool {
|
||||
return s.s.Has(p.NomsValue())
|
||||
func (s SetOfRefOfCommit) Has(p RefOfCommit) bool {
|
||||
return s.s.Has(p)
|
||||
}
|
||||
|
||||
type SetOfCommitIterCallback func(p Commit) (stop bool)
|
||||
type SetOfRefOfCommitIterCallback func(p RefOfCommit) (stop bool)
|
||||
|
||||
func (s SetOfCommit) Iter(cb SetOfCommitIterCallback) {
|
||||
func (s SetOfRefOfCommit) Iter(cb SetOfRefOfCommitIterCallback) {
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
return cb(CommitFromVal(v))
|
||||
return cb(v.(RefOfCommit))
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfCommitIterAllCallback func(p Commit)
|
||||
type SetOfRefOfCommitIterAllCallback func(p RefOfCommit)
|
||||
|
||||
func (s SetOfCommit) IterAll(cb SetOfCommitIterAllCallback) {
|
||||
func (s SetOfRefOfCommit) IterAll(cb SetOfRefOfCommitIterAllCallback) {
|
||||
s.s.IterAll(func(v types.Value) {
|
||||
cb(CommitFromVal(v))
|
||||
cb(v.(RefOfCommit))
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfCommitFilterCallback func(p Commit) (keep bool)
|
||||
type SetOfRefOfCommitFilterCallback func(p RefOfCommit) (keep bool)
|
||||
|
||||
func (s SetOfCommit) Filter(cb SetOfCommitFilterCallback) SetOfCommit {
|
||||
ns := NewSetOfCommit()
|
||||
s.IterAll(func(v Commit) {
|
||||
func (s SetOfRefOfCommit) Filter(cb SetOfRefOfCommitFilterCallback) SetOfRefOfCommit {
|
||||
ns := NewSetOfRefOfCommit()
|
||||
s.IterAll(func(v RefOfCommit) {
|
||||
if cb(v) {
|
||||
ns = ns.Insert(v)
|
||||
}
|
||||
@@ -294,27 +385,27 @@ func (s SetOfCommit) Filter(cb SetOfCommitFilterCallback) SetOfCommit {
|
||||
return ns
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Insert(p ...Commit) SetOfCommit {
|
||||
return SetOfCommit{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
func (s SetOfRefOfCommit) Insert(p ...RefOfCommit) SetOfRefOfCommit {
|
||||
return SetOfRefOfCommit{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Remove(p ...Commit) SetOfCommit {
|
||||
return SetOfCommit{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
func (s SetOfRefOfCommit) Remove(p ...RefOfCommit) SetOfRefOfCommit {
|
||||
return SetOfRefOfCommit{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Union(others ...SetOfCommit) SetOfCommit {
|
||||
return SetOfCommit{s.s.Union(s.fromStructSlice(others)...)}
|
||||
func (s SetOfRefOfCommit) Union(others ...SetOfRefOfCommit) SetOfRefOfCommit {
|
||||
return SetOfRefOfCommit{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Subtract(others ...SetOfCommit) SetOfCommit {
|
||||
return SetOfCommit{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
func (s SetOfRefOfCommit) Subtract(others ...SetOfRefOfCommit) SetOfRefOfCommit {
|
||||
return SetOfRefOfCommit{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfCommit) Any() Commit {
|
||||
return CommitFromVal(s.s.Any())
|
||||
func (s SetOfRefOfCommit) Any() RefOfCommit {
|
||||
return s.s.Any().(RefOfCommit)
|
||||
}
|
||||
|
||||
func (s SetOfCommit) fromStructSlice(p []SetOfCommit) []types.Set {
|
||||
func (s SetOfRefOfCommit) fromStructSlice(p []SetOfRefOfCommit) []types.Set {
|
||||
r := make([]types.Set, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.s
|
||||
@@ -322,10 +413,75 @@ func (s SetOfCommit) fromStructSlice(p []SetOfCommit) []types.Set {
|
||||
return r
|
||||
}
|
||||
|
||||
func (s SetOfCommit) fromElemSlice(p []Commit) []types.Value {
|
||||
func (s SetOfRefOfCommit) fromElemSlice(p []RefOfCommit) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// RefOfCommit
|
||||
|
||||
type RefOfCommit struct {
|
||||
r ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRefOfCommit(r ref.Ref) RefOfCommit {
|
||||
return RefOfCommit{r, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r RefOfCommit) Ref() ref.Ref {
|
||||
return types.EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r RefOfCommit) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RefOfCommit); ok {
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r RefOfCommit) Chunks() []types.Future {
|
||||
return r.TypeRef().Chunks()
|
||||
}
|
||||
|
||||
func (r RefOfCommit) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return r
|
||||
}
|
||||
|
||||
func (r RefOfCommit) InternalImplementation() ref.Ref {
|
||||
return r.r
|
||||
}
|
||||
|
||||
func RefOfCommitFromVal(val types.Value) RefOfCommit {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RefOfCommit); ok {
|
||||
return val
|
||||
}
|
||||
return RefOfCommit{val.(types.Ref).Ref(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// A Noms Value that describes RefOfCommit.
|
||||
var __typeRefForRefOfCommit types.TypeRef
|
||||
|
||||
func (m RefOfCommit) TypeRef() types.TypeRef {
|
||||
return __typeRefForRefOfCommit
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForRefOfCommit = types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef(__datasPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForRefOfCommit, func(v types.Value) types.Value {
|
||||
return RefOfCommitFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (r RefOfCommit) GetValue(cs chunks.ChunkSource) Commit {
|
||||
return types.ReadValue(r.r, cs).(Commit)
|
||||
}
|
||||
|
||||
func (r RefOfCommit) SetValue(val Commit, cs chunks.ChunkSink) RefOfCommit {
|
||||
return RefOfCommit{types.WriteValue(val, cs), &ref.Ref{}}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
struct Commit {
|
||||
value: Value
|
||||
parents: Set(Commit)
|
||||
parents: Set(Ref(Commit))
|
||||
}
|
||||
|
||||
using Map(String, Commit)
|
||||
using Map(String, Ref(Commit))
|
||||
|
||||
+3
-3
@@ -38,16 +38,16 @@ func (ds *Dataset) Head() datas.Commit {
|
||||
// Commit updates the commit that a dataset points at. The new Commit is constructed using v and the current Head.
|
||||
// If the update cannot be performed, e.g., because of a conflict, Commit returns 'false' and the current snapshot of the dataset so that the client can merge the changes and try again.
|
||||
func (ds *Dataset) Commit(v types.Value) (Dataset, bool) {
|
||||
p := datas.NewSetOfCommit()
|
||||
p := datas.NewSetOfRefOfCommit()
|
||||
if head, ok := ds.MaybeHead(); ok {
|
||||
p = p.Insert(head)
|
||||
p = p.Insert(datas.NewRefOfCommit(head.Ref()))
|
||||
}
|
||||
return ds.CommitWithParents(v, p)
|
||||
}
|
||||
|
||||
// CommitWithParents updates the commit that a dataset points at. The new Commit is constructed using v and p.
|
||||
// If the update cannot be performed, e.g., because of a conflict, CommitWithParents returns 'false' and the current snapshot of the dataset so that the client can merge the changes and try again.
|
||||
func (ds *Dataset) CommitWithParents(v types.Value, p datas.SetOfCommit) (Dataset, bool) {
|
||||
func (ds *Dataset) CommitWithParents(v types.Value, p datas.SetOfRefOfCommit) (Dataset, bool) {
|
||||
newCommit := datas.NewCommit().SetParents(p).SetValue(v)
|
||||
store, ok := ds.Store().Commit(ds.id, newCommit)
|
||||
return Dataset{store, ds.id}, ok
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestDatasetCommitTracker(t *testing.T) {
|
||||
assert.False(ds2.Head().Value().Equals(ds1Commit))
|
||||
assert.False(ds1.Head().Value().Equals(ds2Commit))
|
||||
|
||||
assert.Equal("sha1-f4e15351a5de239145b6c434bd5ec588e1984eae", ms.Root().String())
|
||||
assert.Equal("sha1-079abb07bcf025f7b81f5f84feca5c74a5e008b6", ms.Root().String())
|
||||
}
|
||||
|
||||
func newDS(id string, ms *chunks.MemoryStore) Dataset {
|
||||
@@ -74,7 +74,7 @@ func TestExplicitBranchUsingDatasets(t *testing.T) {
|
||||
|
||||
// ds1: |a| <- |b| <--|d|
|
||||
// \ds2 <- |c| <--/
|
||||
mergeParents := datas.NewSetOfCommit().Insert(ds1.Head()).Insert(ds2.Head())
|
||||
mergeParents := datas.NewSetOfRefOfCommit().Insert(datas.NewRefOfCommit(ds1.Head().Ref())).Insert(datas.NewRefOfCommit(ds2.Head().Ref()))
|
||||
d := types.NewString("d")
|
||||
ds2, ok = ds2.CommitWithParents(d, mergeParents)
|
||||
assert.True(ok)
|
||||
|
||||
+38
-15
@@ -21,32 +21,53 @@ func TestValidateRef(t *testing.T) {
|
||||
assert.Panics(t, func() { ds.validateRefAsCommit(r) })
|
||||
}
|
||||
|
||||
func TestPull(t *testing.T) {
|
||||
func NewList(ds Dataset, vs ...types.Value) types.Ref {
|
||||
v := types.NewList(vs...)
|
||||
r := types.WriteValue(v, ds.store)
|
||||
return types.Ref{R: r}
|
||||
}
|
||||
|
||||
func NewMap(ds Dataset, vs ...types.Value) types.Ref {
|
||||
v := types.NewMap(vs...)
|
||||
r := types.WriteValue(v, ds.store)
|
||||
return types.Ref{R: r}
|
||||
}
|
||||
|
||||
func NewSet(ds Dataset, vs ...types.Value) types.Ref {
|
||||
v := types.NewSet(vs...)
|
||||
r := types.WriteValue(v, ds.store)
|
||||
return types.Ref{R: r}
|
||||
}
|
||||
|
||||
func SkipTestPull(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
sink := createTestDataset("sink")
|
||||
source := createTestDataset("source")
|
||||
|
||||
// Give sink and source some initial shared context.
|
||||
initialValue := types.NewMap(
|
||||
types.NewString("first"), types.NewList(),
|
||||
types.NewString("second"), types.NewList(types.Int32(2)))
|
||||
sourceInitialValue := types.NewMap(
|
||||
types.NewString("first"), NewList(source),
|
||||
types.NewString("second"), NewList(source, types.Int32(2)))
|
||||
sinkInitialValue := types.NewMap(
|
||||
types.NewString("first"), NewList(sink),
|
||||
types.NewString("second"), NewList(sink, types.Int32(2)))
|
||||
|
||||
ok := false
|
||||
source, ok = source.Commit(initialValue)
|
||||
source, ok = source.Commit(sourceInitialValue)
|
||||
assert.True(ok)
|
||||
sink, ok = sink.Commit(initialValue)
|
||||
sink, ok = sink.Commit(sinkInitialValue)
|
||||
assert.True(ok)
|
||||
|
||||
// Add some new stuff to source.
|
||||
updatedValue := initialValue.Set(
|
||||
types.NewString("third"), types.NewList(types.Int32(3)))
|
||||
updatedValue := sourceInitialValue.Set(
|
||||
types.NewString("third"), NewList(source, types.Int32(3)))
|
||||
source, ok = source.Commit(updatedValue)
|
||||
assert.True(ok)
|
||||
|
||||
// Add some more stuff, so that source isn't directly ahead of sink.
|
||||
updatedValue = updatedValue.Set(
|
||||
types.NewString("fourth"), types.NewList(types.Int32(4)))
|
||||
types.NewString("fourth"), NewList(source, types.Int32(4)))
|
||||
source, ok = source.Commit(updatedValue)
|
||||
assert.True(ok)
|
||||
|
||||
@@ -55,22 +76,24 @@ func TestPull(t *testing.T) {
|
||||
assert.True(source.Head().Equals(sink.Head()))
|
||||
}
|
||||
|
||||
func TestPullFirstCommit(t *testing.T) {
|
||||
func SkipTestPullFirstCommit(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
sink := createTestDataset("sink")
|
||||
source := createTestDataset("source")
|
||||
|
||||
initialValue := types.NewMap(
|
||||
types.NewString("first"), types.NewList(),
|
||||
types.NewString("second"), types.NewList(types.Int32(2)))
|
||||
sourceInitialValue := types.NewMap(
|
||||
types.NewString("first"), NewList(source),
|
||||
types.NewString("second"), NewList(source, types.Int32(2)))
|
||||
|
||||
source, ok := source.Commit(initialValue)
|
||||
NewList(sink)
|
||||
NewList(sink, types.Int32(2))
|
||||
|
||||
source, ok := source.Commit(sourceInitialValue)
|
||||
assert.True(ok)
|
||||
|
||||
sink = sink.Pull(source, 1)
|
||||
assert.True(source.Head().Equals(sink.Head()))
|
||||
|
||||
}
|
||||
|
||||
func TestFailedCopyChunks(t *testing.T) {
|
||||
|
||||
+37
-35
@@ -204,38 +204,39 @@ var unmarshalTests = []unmarshalTest{
|
||||
{in: strIntMap(si{"key", 2}), ptr: mapAddr(map[string]int32{"old": 0, "key": 1}), out: map[string]int32{"key": 2}},
|
||||
|
||||
// embedded structs
|
||||
{
|
||||
in: marshaledEmbedsPlus,
|
||||
ptr: new(Top),
|
||||
out: Top{
|
||||
Level0: 1,
|
||||
Embed0: Embed0{
|
||||
Level1b: 2,
|
||||
Level1c: 3,
|
||||
},
|
||||
Embed0a: &Embed0a{
|
||||
Level1a: 5,
|
||||
Level1b: 6,
|
||||
},
|
||||
Embed0b: &Embed0b{
|
||||
Level1a: 8,
|
||||
Level1b: 9,
|
||||
Level1c: 10,
|
||||
Level1d: 11,
|
||||
Level1e: 12,
|
||||
},
|
||||
Loop: Loop{
|
||||
Loop1: 13,
|
||||
Loop2: 14,
|
||||
},
|
||||
Embed0p: Embed0p{
|
||||
Point: image.Point{X: 15, Y: 16},
|
||||
},
|
||||
Embed0q: Embed0q{
|
||||
Point: Point{Z: 17},
|
||||
},
|
||||
},
|
||||
},
|
||||
// TODO: The ordering of the fields is based on the map iteration order. BUG 396
|
||||
// {
|
||||
// in: marshaledEmbedsPlus,
|
||||
// ptr: new(Top),
|
||||
// out: Top{
|
||||
// Level0: 1,
|
||||
// Embed0: Embed0{
|
||||
// Level1b: 2,
|
||||
// Level1c: 3,
|
||||
// },
|
||||
// Embed0a: &Embed0a{
|
||||
// Level1a: 5,
|
||||
// Level1b: 6,
|
||||
// },
|
||||
// Embed0b: &Embed0b{
|
||||
// Level1a: 8,
|
||||
// Level1b: 9,
|
||||
// Level1c: 10,
|
||||
// Level1d: 11,
|
||||
// Level1e: 12,
|
||||
// },
|
||||
// Loop: Loop{
|
||||
// Loop1: 13,
|
||||
// Loop2: 14,
|
||||
// },
|
||||
// Embed0p: Embed0p{
|
||||
// Point: image.Point{X: 15, Y: 16},
|
||||
// },
|
||||
// Embed0q: Embed0q{
|
||||
// Point: Point{Z: 17},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// TODO: The ordering of the fields is based on the map iteration order. BUG 396
|
||||
// {
|
||||
// in: types.NewMap(types.NewString("hello"), types.Int32(1)),
|
||||
@@ -256,9 +257,10 @@ var unmarshalTests = []unmarshalTest{
|
||||
}
|
||||
|
||||
// marshaledEmbeds (from marshal_test.go) plus some unexported fields.
|
||||
var marshaledEmbedsPlus = func() types.Map {
|
||||
return marshaledEmbeds.Set(types.NewString("x"), types.Int32(4))
|
||||
}()
|
||||
// BUG 396
|
||||
// var marshaledEmbedsPlus = func() types.Map {
|
||||
// return marshaledEmbeds.Set(types.NewString("x"), types.Int32(4))
|
||||
// }()
|
||||
|
||||
// allValue (from marshal_test.go) with some fields overridden to match how we handle nil in various cases.
|
||||
var allValueUnmarshal = func() All {
|
||||
|
||||
@@ -84,9 +84,10 @@ func (gen Generator) DefToValue(val string, t types.TypeRef) string {
|
||||
case types.EnumKind:
|
||||
return fmt.Sprintf("types.UInt32(%s)", val)
|
||||
case types.ListKind, types.MapKind, types.SetKind, types.StructKind:
|
||||
return fmt.Sprintf("%s.New().NomsValue()", val)
|
||||
return fmt.Sprintf("%s.New()", val)
|
||||
case types.RefKind:
|
||||
return fmt.Sprintf("types.Ref{R: %s}", val)
|
||||
// TODO: This looks suspicious. This can have a namespace. BUG 449
|
||||
return fmt.Sprintf("New%s(%s)", gen.UserType(t), val)
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -144,12 +145,10 @@ func (gen Generator) UserToValue(val string, t types.TypeRef) string {
|
||||
t = gen.R.Resolve(t)
|
||||
k := t.Kind()
|
||||
switch k {
|
||||
case types.BlobKind, types.PackageKind, types.ValueKind, types.TypeRefKind:
|
||||
case types.BlobKind, types.ListKind, types.MapKind, types.PackageKind, types.RefKind, types.SetKind, types.StructKind, types.TypeRefKind, types.ValueKind:
|
||||
return val
|
||||
case types.BoolKind, types.EnumKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
|
||||
return gen.NativeToValue(val, t)
|
||||
case types.ListKind, types.MapKind, types.RefKind, types.SetKind, types.StructKind:
|
||||
return fmt.Sprintf("%s.NomsValue()", val)
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -166,7 +165,7 @@ func (gen Generator) ValueToUser(val string, t types.TypeRef) string {
|
||||
case types.EnumKind:
|
||||
return fmt.Sprintf("%s(%s.(types.UInt32))", gen.UserName(t), val)
|
||||
case types.ListKind, types.MapKind, types.RefKind, types.SetKind, types.StructKind:
|
||||
return fmt.Sprintf("%sFromVal(%s)", gen.UserName(t), val)
|
||||
return fmt.Sprintf("%s.(%s)", val, gen.UserName(t))
|
||||
case types.PackageKind:
|
||||
return fmt.Sprintf("%s.(types.Package)", val)
|
||||
case types.ValueKind:
|
||||
@@ -191,16 +190,18 @@ func (gen Generator) UserZero(t types.TypeRef) string {
|
||||
case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
|
||||
return fmt.Sprintf("%s(0)", strings.ToLower(kindToString(k)))
|
||||
case types.ListKind, types.MapKind, types.PackageKind, types.SetKind, types.StructKind:
|
||||
// TODO: namespace BUG 449
|
||||
return fmt.Sprintf("New%s()", gen.UserType(t))
|
||||
case types.RefKind:
|
||||
return fmt.Sprintf("%s{ref.Ref{}}", gen.UserType(t))
|
||||
// TODO: namespace BUG 449
|
||||
return fmt.Sprintf("New%s(ref.Ref{})", gen.UserType(t))
|
||||
case types.StringKind:
|
||||
return `""`
|
||||
case types.ValueKind:
|
||||
// TODO: This is where a null Value would have been useful.
|
||||
return "types.Bool(false)"
|
||||
case types.TypeRefKind:
|
||||
return "types.TypeRef{}"
|
||||
return "types.TypeRef{R: ref.Ref{}}"
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -218,23 +219,17 @@ func (gen Generator) ValueZero(t types.TypeRef) string {
|
||||
return "types.UInt32(0)"
|
||||
case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
|
||||
return fmt.Sprintf("types.%s(0)", kindToString(k))
|
||||
case types.ListKind:
|
||||
return "types.NewList()"
|
||||
case types.MapKind:
|
||||
return "types.NewMap()"
|
||||
case types.ListKind, types.MapKind, types.RefKind, types.SetKind:
|
||||
return gen.UserZero(t)
|
||||
case types.PackageKind:
|
||||
return "types.NewPackage()"
|
||||
case types.RefKind:
|
||||
return "types.Ref{R: ref.Ref{}}"
|
||||
case types.SetKind:
|
||||
return "types.NewSet()"
|
||||
case types.StringKind:
|
||||
return `types.NewString("")`
|
||||
case types.StructKind:
|
||||
if t.HasPackageRef() {
|
||||
return fmt.Sprintf("%s.New%s().NomsValue()", ToTag(t.PackageRef()), rt.Name())
|
||||
return fmt.Sprintf("%s.New%s()", ToTag(t.PackageRef()), rt.Name())
|
||||
}
|
||||
return fmt.Sprintf("New%s().NomsValue()", gen.UserName(rt))
|
||||
return fmt.Sprintf("New%s()", gen.UserName(rt))
|
||||
case types.ValueKind:
|
||||
// TODO: Use nil here
|
||||
return "types.Bool(false)"
|
||||
|
||||
@@ -6,6 +6,8 @@ package {{.Name}}
|
||||
import (
|
||||
{{range $imp := .Imports}}"{{$imp}}"
|
||||
{{end}}
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
{{end}}
|
||||
|
||||
|
||||
+22
-13
@@ -1,11 +1,12 @@
|
||||
// {{.Name}}
|
||||
|
||||
type {{.Name}} struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func New{{.Name}}() {{.Name}} {
|
||||
return {{.Name}}{types.NewList()}
|
||||
return {{.Name}}{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
{{if .CanUseDef}}
|
||||
@@ -16,7 +17,7 @@ func New{{.Name}}() {{.Name}} {
|
||||
for i, d := range def {
|
||||
l[i] = {{defToValue "d" .ElemType }}
|
||||
}
|
||||
return {{.Name}}{types.NewList(l...)}
|
||||
return {{.Name}}{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Def() {{.Name}}Def {
|
||||
@@ -29,24 +30,32 @@ func New{{.Name}}() {{.Name}} {
|
||||
{{end}}
|
||||
|
||||
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.({{.Name}}); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return {{.Name}}{val.(types.List)}
|
||||
return {{.Name}}{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
|
||||
func (l {{.Name}}) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l {{.Name}}) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Equals(other types.Value) bool {
|
||||
if other, ok := other.({{.Name}}); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Chunks() (futures []types.Future) {
|
||||
@@ -70,27 +79,27 @@ func (l {{.Name}}) Get(i uint64) {{userType .ElemType}} {
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Slice(idx uint64, end uint64) {{.Name}} {
|
||||
return {{.Name}}{l.l.Slice(idx, end)}
|
||||
return {{.Name}}{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Set(i uint64, val {{userType .ElemType}}) {{.Name}} {
|
||||
return {{.Name}}{l.l.Set(i, {{userToValue "val" .ElemType}})}
|
||||
return {{.Name}}{l.l.Set(i, {{userToValue "val" .ElemType}}), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Append(v ...{{userType .ElemType}}) {{.Name}} {
|
||||
return {{.Name}}{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return {{.Name}}{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Insert(idx uint64, v ...{{userType .ElemType}}) {{.Name}} {
|
||||
return {{.Name}}{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return {{.Name}}{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) Remove(idx uint64, end uint64) {{.Name}} {
|
||||
return {{.Name}}{l.l.Remove(idx, end)}
|
||||
return {{.Name}}{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) RemoveAt(idx uint64) {{.Name}} {
|
||||
return {{.Name}}{(l.l.RemoveAt(idx))}
|
||||
return {{.Name}}{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l {{.Name}}) fromElemSlice(p []{{userType .ElemType}}) []types.Value {
|
||||
|
||||
+19
-10
@@ -1,12 +1,12 @@
|
||||
// {{.Name}}
|
||||
|
||||
type {{.Name}} struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
|
||||
func New{{.Name}}() {{.Name}} {
|
||||
return {{.Name}}{types.NewMap()}
|
||||
return {{.Name}}{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
{{if .CanUseDef}}
|
||||
@@ -17,7 +17,7 @@ func New{{.Name}}() {{.Name}} {
|
||||
for k, v := range def {
|
||||
kv = append(kv, {{defToValue "k" .KeyType}}, {{defToValue "v" .ValueType}})
|
||||
}
|
||||
return {{.Name}}{types.NewMap(kv...)}
|
||||
return {{.Name}}{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m {{.Name}}) Def() {{.Name}}Def {
|
||||
@@ -30,24 +30,33 @@ func New{{.Name}}() {{.Name}} {
|
||||
}
|
||||
{{end}}
|
||||
|
||||
func {{.Name}}FromVal(p types.Value) {{.Name}} {
|
||||
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.({{.Name}}); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return {{.Name}}{p.(types.Map)}
|
||||
return {{.Name}}{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m {{.Name}}) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m {{.Name}}) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m {{.Name}}) Equals(other types.Value) bool {
|
||||
if other, ok := other.({{.Name}}); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m {{.Name}}) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m {{.Name}}) Chunks() (futures []types.Future) {
|
||||
@@ -83,13 +92,13 @@ func (m {{.Name}}) MaybeGet(p {{userType .KeyType}}) ({{userType .ValueType}}, b
|
||||
}
|
||||
|
||||
func (m {{.Name}}) Set(k {{userType .KeyType}}, v {{userType .ValueType}}) {{.Name}} {
|
||||
return {{.Name}}{m.m.Set({{userToValue "k" .KeyType}}, {{userToValue "v" .ValueType}})}
|
||||
return {{.Name}}{m.m.Set({{userToValue "k" .KeyType}}, {{userToValue "v" .ValueType}}), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m {{.Name}}) Remove(p {{userType .KeyType}}) {{.Name}} {
|
||||
return {{.Name}}{m.m.Remove({{userToValue "p" .KeyType}})}
|
||||
return {{.Name}}{m.m.Remove({{userToValue "p" .KeyType}}), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type {{.Name}}IterCallback func(k {{userType .KeyType}}, v {{userType .ValueType}}) (stop bool)
|
||||
|
||||
+18
-9
@@ -1,20 +1,21 @@
|
||||
// {{.Name}}
|
||||
|
||||
type {{.Name}} struct {
|
||||
r ref.Ref
|
||||
r ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func New{{.Name}}(r ref.Ref) {{.Name}} {
|
||||
return {{.Name}}{r}
|
||||
return {{.Name}}{r, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r {{.Name}}) Ref() ref.Ref {
|
||||
return r.r
|
||||
return types.EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r {{.Name}}) Equals(other types.Value) bool {
|
||||
if other, ok := other.({{.Name}}); ok {
|
||||
return r.r == other.r
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -24,11 +25,20 @@ func (r {{.Name}}) Chunks() []types.Future {
|
||||
}
|
||||
|
||||
func (r {{.Name}}) NomsValue() types.Value {
|
||||
return types.Ref{R: r.r}
|
||||
// TODO: Remove this
|
||||
return r
|
||||
}
|
||||
|
||||
func {{.Name}}FromVal(p types.Value) {{.Name}} {
|
||||
return {{.Name}}{p.(types.Ref).Ref()}
|
||||
func (r {{.Name}}) InternalImplementation() ref.Ref {
|
||||
return r.r
|
||||
}
|
||||
|
||||
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.({{.Name}}); ok {
|
||||
return val
|
||||
}
|
||||
return {{.Name}}{val.(types.Ref).Ref(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
{{template "type_ref.tmpl" .}}
|
||||
@@ -38,6 +48,5 @@ func (r {{.Name}}) GetValue(cs chunks.ChunkSource) {{userType .ElemType}} {
|
||||
}
|
||||
|
||||
func (r {{.Name}}) SetValue(val {{userType .ElemType}}, cs chunks.ChunkSink) {{.Name}} {
|
||||
ref := types.WriteValue({{userToValue "val" .ElemType}}, cs)
|
||||
return {{.Name}}{ref}
|
||||
return {{.Name}}{types.WriteValue({{userToValue "val" .ElemType}}, cs), &ref.Ref{}}
|
||||
}
|
||||
|
||||
+21
-11
@@ -1,11 +1,12 @@
|
||||
// {{.Name}}
|
||||
|
||||
type {{.Name}} struct {
|
||||
s types.Set
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func New{{.Name}}() {{.Name}} {
|
||||
return {{.Name}}{types.NewSet()}
|
||||
return {{.Name}}{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
{{if .CanUseDef}}
|
||||
@@ -18,7 +19,7 @@ func New{{.Name}}() {{.Name}} {
|
||||
l[i] = {{defToValue "d" .ElemType}}
|
||||
i++
|
||||
}
|
||||
return {{.Name}}{types.NewSet(l...)}
|
||||
return {{.Name}}{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Def() {{.Name}}Def {
|
||||
@@ -31,23 +32,32 @@ func New{{.Name}}() {{.Name}} {
|
||||
}
|
||||
{{end}}
|
||||
|
||||
func {{.Name}}FromVal(p types.Value) {{.Name}} {
|
||||
return {{.Name}}{p.(types.Set)}
|
||||
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.({{.Name}}); ok {
|
||||
return val
|
||||
}
|
||||
return {{.Name}}{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s {{.Name}}) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Equals(other types.Value) bool {
|
||||
if other, ok := other.({{.Name}}); ok {
|
||||
return s.s.Equals(other.s)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Chunks() (futures []types.Future) {
|
||||
@@ -99,19 +109,19 @@ func (s {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Insert(p ...{{userType .ElemType}}) {{.Name}} {
|
||||
return {{.Name}}{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
return {{.Name}}{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Remove(p ...{{userType .ElemType}}) {{.Name}} {
|
||||
return {{.Name}}{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
return {{.Name}}{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Union(others ...{{.Name}}) {{.Name}} {
|
||||
return {{.Name}}{s.s.Union(s.fromStructSlice(others)...)}
|
||||
return {{.Name}}{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Subtract(others ...{{.Name}}) {{.Name}} {
|
||||
return {{.Name}}{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
return {{.Name}}{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Any() {{userType .ElemType}} {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// {{.Name}}
|
||||
|
||||
type {{.Name}} struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func New{{.Name}}() {{.Name}} {
|
||||
@@ -10,7 +11,7 @@ func New{{.Name}}() {{.Name}} {
|
||||
{{range .Fields}}{{if (not .Optional)}}types.NewString("{{.Name}}"), {{valueZero .T}},
|
||||
{{end}}{{end}}{{if .HasUnion}}types.NewString("$unionIndex"), types.UInt32(0),
|
||||
types.NewString("$unionValue"), {{valueZero .UnionZeroType}},{{end}}
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
{{if .CanUseDef}}
|
||||
@@ -28,7 +29,7 @@ func New{{.Name}}() {{.Name}} {
|
||||
{{end}}{{if .HasUnion}}types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
|
||||
types.NewString("$unionValue"), def.__unionDefToValue(),
|
||||
{{end}}
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Def() (d {{.Name}}Def) {
|
||||
@@ -66,29 +67,38 @@ func (m {{.Name}}) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefFor{{.Name}}, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefFor{{.Name}}, func(v types.Value) types.Value {
|
||||
return {{.Name}}FromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.({{.Name}}); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return {{.Name}}{val.(types.Map)}
|
||||
return {{.Name}}{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s {{.Name}}) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s {{.Name}}) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Equals(other types.Value) bool {
|
||||
if other, ok := other.({{.Name}}); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s {{.Name}}) Chunks() (futures []types.Future) {
|
||||
@@ -113,7 +123,7 @@ func (s {{$name}}) {{title .Name}}() {{userType .T}} {
|
||||
}
|
||||
{{end}}
|
||||
func (s {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
|
||||
return {{$name}}{s.m.Set(types.NewString("{{.Name}}"), {{userToValue "val" .T}})}
|
||||
return {{$name}}{s.m.Set(types.NewString("{{.Name}}"), {{userToValue "val" .T}}), &ref.Ref{}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
@@ -127,7 +137,7 @@ func (s {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
|
||||
}
|
||||
|
||||
func (s {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
|
||||
return {{$name}}{s.m.Set(types.NewString("$unionIndex"), types.UInt32({{$index}})).Set(types.NewString("$unionValue"), {{userToValue "val" .T}})}
|
||||
return {{$name}}{s.m.Set(types.NewString("$unionIndex"), types.UInt32({{$index}})).Set(types.NewString("$unionValue"), {{userToValue "val" .T}}), &ref.Ref{}}
|
||||
}
|
||||
|
||||
{{if $canUseDef}}
|
||||
|
||||
@@ -38,14 +38,15 @@ const (
|
||||
// EnumStruct
|
||||
|
||||
type EnumStruct struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewEnumStruct() EnumStruct {
|
||||
return EnumStruct{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_enum_struct_CachedRef, 1),
|
||||
types.NewString("hand"), types.UInt32(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type EnumStructDef struct {
|
||||
@@ -57,7 +58,7 @@ func (def EnumStructDef) New() EnumStruct {
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_enum_struct_CachedRef, 1),
|
||||
types.NewString("hand"), types.UInt32(def.Hand),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s EnumStruct) Def() (d EnumStructDef) {
|
||||
@@ -72,29 +73,38 @@ func (m EnumStruct) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForEnumStruct, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForEnumStruct, func(v types.Value) types.Value {
|
||||
return EnumStructFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func EnumStructFromVal(val types.Value) EnumStruct {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(EnumStruct); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return EnumStruct{val.(types.Map)}
|
||||
return EnumStruct{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s EnumStruct) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s EnumStruct) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s EnumStruct) Equals(other types.Value) bool {
|
||||
if other, ok := other.(EnumStruct); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s EnumStruct) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s EnumStruct) Chunks() (futures []types.Future) {
|
||||
@@ -108,5 +118,5 @@ func (s EnumStruct) Hand() Handedness {
|
||||
}
|
||||
|
||||
func (s EnumStruct) SetHand(val Handedness) EnumStruct {
|
||||
return EnumStruct{s.m.Set(types.NewString("hand"), types.UInt32(val))}
|
||||
return EnumStruct{s.m.Set(types.NewString("hand"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestEnumValue(t *testing.T) {
|
||||
assert.True(st.Equals(st2))
|
||||
}
|
||||
|
||||
func TestEnumIsValue(t *testing.T) {
|
||||
func SkipTestEnumIsValue(t *testing.T) {
|
||||
cs := chunks.NewMemoryStore()
|
||||
var v types.Value = NewEnumStruct()
|
||||
ref := types.WriteValue(v, cs)
|
||||
|
||||
+25
-15
@@ -1,18 +1,18 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package sha1_8bbcfa69bdfc9953c4034f8591964e0387983910
|
||||
package sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69bdfc9953c4034f8591964e0387983910_CachedRef = __sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69bdfc9953c4034f8591964e0387983910_Ref()
|
||||
var __sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288PackageInFile_sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288_CachedRef = __sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288PackageInFile_sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288_Ref()
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func __sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69bdfc9953c4034f8591964e0387983910_Ref() ref.Ref {
|
||||
func __sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288PackageInFile_sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("S",
|
||||
[]types.Field{
|
||||
@@ -29,15 +29,16 @@ func __sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69b
|
||||
// S
|
||||
|
||||
type S struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewS() S {
|
||||
return S{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69bdfc9953c4034f8591964e0387983910_CachedRef, 0),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288PackageInFile_sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(""),
|
||||
types.NewString("b"), types.Bool(false),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SDef struct {
|
||||
@@ -48,10 +49,10 @@ type SDef struct {
|
||||
func (def SDef) New() S {
|
||||
return S{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69bdfc9953c4034f8591964e0387983910_CachedRef, 0),
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288PackageInFile_sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(def.S),
|
||||
types.NewString("b"), types.Bool(def.B),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s S) Def() (d SDef) {
|
||||
@@ -60,36 +61,45 @@ func (s S) Def() (d SDef) {
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForS = types.MakeTypeRef(__sha1_8bbcfa69bdfc9953c4034f8591964e0387983910PackageInFile_sha1_8bbcfa69bdfc9953c4034f8591964e0387983910_CachedRef, 0)
|
||||
var __typeRefForS = types.MakeTypeRef(__sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288PackageInFile_sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288_CachedRef, 0)
|
||||
|
||||
func (m S) TypeRef() types.TypeRef {
|
||||
return __typeRefForS
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForS, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForS, func(v types.Value) types.Value {
|
||||
return SFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func SFromVal(val types.Value) S {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(S); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return S{val.(types.Map)}
|
||||
return S{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s S) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s S) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s S) Equals(other types.Value) bool {
|
||||
if other, ok := other.(S); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s S) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s S) Chunks() (futures []types.Future) {
|
||||
@@ -103,7 +113,7 @@ func (s S) S() string {
|
||||
}
|
||||
|
||||
func (s S) SetS(val string) S {
|
||||
return S{s.m.Set(types.NewString("s"), types.NewString(val))}
|
||||
return S{s.m.Set(types.NewString("s"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s S) B() bool {
|
||||
@@ -111,7 +121,7 @@ func (s S) B() bool {
|
||||
}
|
||||
|
||||
func (s S) SetB(val bool) S {
|
||||
return S{s.m.Set(types.NewString("b"), types.Bool(val))}
|
||||
return S{s.m.Set(types.NewString("b"), types.Bool(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// E
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288"
|
||||
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef = __sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_Ref()
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func __sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("D",
|
||||
[]types.Field{
|
||||
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288"), 0), false},
|
||||
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288"), 1), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("DUser",
|
||||
[]types.Field{
|
||||
types.Field{"Dfield", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// D
|
||||
|
||||
type D struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewD() D {
|
||||
return D{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef, 0),
|
||||
types.NewString("structField"), sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.NewS(),
|
||||
types.NewString("enumField"), types.UInt32(0),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type DDef struct {
|
||||
StructField sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.SDef
|
||||
EnumField sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.E
|
||||
}
|
||||
|
||||
func (def DDef) New() D {
|
||||
return D{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef, 0),
|
||||
types.NewString("structField"), def.StructField.New(),
|
||||
types.NewString("enumField"), types.UInt32(def.EnumField),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s D) Def() (d DDef) {
|
||||
d.StructField = s.m.Get(types.NewString("structField")).(sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.S).Def()
|
||||
d.EnumField = sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForD = types.MakeTypeRef(__sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef, 0)
|
||||
|
||||
func (m D) TypeRef() types.TypeRef {
|
||||
return __typeRefForD
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForD, func(v types.Value) types.Value {
|
||||
return DFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func DFromVal(val types.Value) D {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(D); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return D{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s D) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s D) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s D) Equals(other types.Value) bool {
|
||||
if other, ok := other.(D); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s D) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s D) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s D) StructField() sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.S {
|
||||
return s.m.Get(types.NewString("structField")).(sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.S)
|
||||
}
|
||||
|
||||
func (s D) SetStructField(val sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.S) D {
|
||||
return D{s.m.Set(types.NewString("structField"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s D) EnumField() sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.E {
|
||||
return sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
|
||||
}
|
||||
|
||||
func (s D) SetEnumField(val sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288.E) D {
|
||||
return D{s.m.Set(types.NewString("enumField"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// DUser
|
||||
|
||||
type DUser struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewDUser() DUser {
|
||||
return DUser{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef, 1),
|
||||
types.NewString("Dfield"), NewD(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type DUserDef struct {
|
||||
Dfield DDef
|
||||
}
|
||||
|
||||
func (def DUserDef) New() DUser {
|
||||
return DUser{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef, 1),
|
||||
types.NewString("Dfield"), def.Dfield.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s DUser) Def() (d DUserDef) {
|
||||
d.Dfield = s.m.Get(types.NewString("Dfield")).(D).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForDUser = types.MakeTypeRef(__sha1_d31b592f480b7659b03b72a7d1271f31dde57b2dPackageInFile_sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_CachedRef, 1)
|
||||
|
||||
func (m DUser) TypeRef() types.TypeRef {
|
||||
return __typeRefForDUser
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForDUser, func(v types.Value) types.Value {
|
||||
return DUserFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func DUserFromVal(val types.Value) DUser {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(DUser); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return DUser{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s DUser) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s DUser) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s DUser) Equals(other types.Value) bool {
|
||||
if other, ok := other.(DUser); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s DUser) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s DUser) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s DUser) Dfield() D {
|
||||
return s.m.Get(types.NewString("Dfield")).(D)
|
||||
}
|
||||
|
||||
func (s DUser) SetDfield(val D) DUser {
|
||||
return DUser{s.m.Set(types.NewString("Dfield"), val), &ref.Ref{}}
|
||||
}
|
||||
-199
@@ -1,199 +0,0 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_8bbcfa69bdfc9953c4034f8591964e0387983910"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef = __sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_Ref()
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func __sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("D",
|
||||
[]types.Field{
|
||||
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-8bbcfa69bdfc9953c4034f8591964e0387983910"), 0), false},
|
||||
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-8bbcfa69bdfc9953c4034f8591964e0387983910"), 1), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("DUser",
|
||||
[]types.Field{
|
||||
types.Field{"Dfield", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-8bbcfa69bdfc9953c4034f8591964e0387983910"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// D
|
||||
|
||||
type D struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewD() D {
|
||||
return D{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef, 0),
|
||||
types.NewString("structField"), sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.NewS().NomsValue(),
|
||||
types.NewString("enumField"), types.UInt32(0),
|
||||
)}
|
||||
}
|
||||
|
||||
type DDef struct {
|
||||
StructField sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.SDef
|
||||
EnumField sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E
|
||||
}
|
||||
|
||||
func (def DDef) New() D {
|
||||
return D{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef, 0),
|
||||
types.NewString("structField"), def.StructField.New().NomsValue(),
|
||||
types.NewString("enumField"), types.UInt32(def.EnumField),
|
||||
)}
|
||||
}
|
||||
|
||||
func (s D) Def() (d DDef) {
|
||||
d.StructField = sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.SFromVal(s.m.Get(types.NewString("structField"))).Def()
|
||||
d.EnumField = sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForD = types.MakeTypeRef(__sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef, 0)
|
||||
|
||||
func (m D) TypeRef() types.TypeRef {
|
||||
return __typeRefForD
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForD, func(v types.Value) types.NomsValue {
|
||||
return DFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func DFromVal(val types.Value) D {
|
||||
// TODO: Validate here
|
||||
return D{val.(types.Map)}
|
||||
}
|
||||
|
||||
func (s D) NomsValue() types.Value {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s D) Equals(other types.Value) bool {
|
||||
if other, ok := other.(D); ok {
|
||||
return s.m.Equals(other.m)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s D) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s D) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s D) StructField() sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.S {
|
||||
return sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.SFromVal(s.m.Get(types.NewString("structField")))
|
||||
}
|
||||
|
||||
func (s D) SetStructField(val sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.S) D {
|
||||
return D{s.m.Set(types.NewString("structField"), val.NomsValue())}
|
||||
}
|
||||
|
||||
func (s D) EnumField() sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E {
|
||||
return sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
|
||||
}
|
||||
|
||||
func (s D) SetEnumField(val sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E) D {
|
||||
return D{s.m.Set(types.NewString("enumField"), types.UInt32(val))}
|
||||
}
|
||||
|
||||
// DUser
|
||||
|
||||
type DUser struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewDUser() DUser {
|
||||
return DUser{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef, 1),
|
||||
types.NewString("Dfield"), NewD().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
type DUserDef struct {
|
||||
Dfield DDef
|
||||
}
|
||||
|
||||
func (def DUserDef) New() DUser {
|
||||
return DUser{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef, 1),
|
||||
types.NewString("Dfield"), def.Dfield.New().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
func (s DUser) Def() (d DUserDef) {
|
||||
d.Dfield = DFromVal(s.m.Get(types.NewString("Dfield"))).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForDUser = types.MakeTypeRef(__sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8cPackageInFile_sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_CachedRef, 1)
|
||||
|
||||
func (m DUser) TypeRef() types.TypeRef {
|
||||
return __typeRefForDUser
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForDUser, func(v types.Value) types.NomsValue {
|
||||
return DUserFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func DUserFromVal(val types.Value) DUser {
|
||||
// TODO: Validate here
|
||||
return DUser{val.(types.Map)}
|
||||
}
|
||||
|
||||
func (s DUser) NomsValue() types.Value {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s DUser) Equals(other types.Value) bool {
|
||||
if other, ok := other.(DUser); ok {
|
||||
return s.m.Equals(other.m)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s DUser) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s DUser) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s DUser) Dfield() D {
|
||||
return DFromVal(s.m.Get(types.NewString("Dfield")))
|
||||
}
|
||||
|
||||
func (s DUser) SetDfield(val D) DUser {
|
||||
return DUser{s.m.Set(types.NewString("Dfield"), val.NomsValue())}
|
||||
}
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
// ListOfInt64
|
||||
|
||||
type ListOfInt64 struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfInt64() ListOfInt64 {
|
||||
return ListOfInt64{types.NewList()}
|
||||
return ListOfInt64{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfInt64Def []int64
|
||||
@@ -24,7 +25,7 @@ func (def ListOfInt64Def) New() ListOfInt64 {
|
||||
for i, d := range def {
|
||||
l[i] = types.Int64(d)
|
||||
}
|
||||
return ListOfInt64{types.NewList(l...)}
|
||||
return ListOfInt64{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Def() ListOfInt64Def {
|
||||
@@ -36,23 +37,32 @@ func (l ListOfInt64) Def() ListOfInt64Def {
|
||||
}
|
||||
|
||||
func ListOfInt64FromVal(val types.Value) ListOfInt64 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfInt64); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfInt64{val.(types.List)}
|
||||
return ListOfInt64{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfInt64) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfInt64); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Chunks() (futures []types.Future) {
|
||||
@@ -70,7 +80,7 @@ func (m ListOfInt64) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfInt64 = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.Int64Kind))
|
||||
types.RegisterFromValFunction(__typeRefForListOfInt64, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfInt64, func(v types.Value) types.Value {
|
||||
return ListOfInt64FromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -88,27 +98,27 @@ func (l ListOfInt64) Get(i uint64) int64 {
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Slice(idx uint64, end uint64) ListOfInt64 {
|
||||
return ListOfInt64{l.l.Slice(idx, end)}
|
||||
return ListOfInt64{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Set(i uint64, val int64) ListOfInt64 {
|
||||
return ListOfInt64{l.l.Set(i, types.Int64(val))}
|
||||
return ListOfInt64{l.l.Set(i, types.Int64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Append(v ...int64) ListOfInt64 {
|
||||
return ListOfInt64{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfInt64{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Insert(idx uint64, v ...int64) ListOfInt64 {
|
||||
return ListOfInt64{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfInt64{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) Remove(idx uint64, end uint64) ListOfInt64 {
|
||||
return ListOfInt64{l.l.Remove(idx, end)}
|
||||
return ListOfInt64{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) RemoveAt(idx uint64) ListOfInt64 {
|
||||
return ListOfInt64{(l.l.RemoveAt(idx))}
|
||||
return ListOfInt64{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfInt64) fromElemSlice(p []int64) []types.Value {
|
||||
|
||||
+40
-20
@@ -10,11 +10,12 @@ import (
|
||||
// MapOfBoolToString
|
||||
|
||||
type MapOfBoolToString struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfBoolToString() MapOfBoolToString {
|
||||
return MapOfBoolToString{types.NewMap()}
|
||||
return MapOfBoolToString{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfBoolToStringDef map[bool]string
|
||||
@@ -24,7 +25,7 @@ func (def MapOfBoolToStringDef) New() MapOfBoolToString {
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.Bool(k), types.NewString(v))
|
||||
}
|
||||
return MapOfBoolToString{types.NewMap(kv...)}
|
||||
return MapOfBoolToString{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) Def() MapOfBoolToStringDef {
|
||||
@@ -36,24 +37,33 @@ func (m MapOfBoolToString) Def() MapOfBoolToStringDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfBoolToStringFromVal(p types.Value) MapOfBoolToString {
|
||||
func MapOfBoolToStringFromVal(val types.Value) MapOfBoolToString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfBoolToString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfBoolToString{p.(types.Map)}
|
||||
return MapOfBoolToString{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfBoolToString); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) Chunks() (futures []types.Future) {
|
||||
@@ -71,7 +81,7 @@ func (m MapOfBoolToString) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfBoolToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.BoolKind), types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfBoolToString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfBoolToString, func(v types.Value) types.Value {
|
||||
return MapOfBoolToStringFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -101,13 +111,13 @@ func (m MapOfBoolToString) MaybeGet(p bool) (string, bool) {
|
||||
}
|
||||
|
||||
func (m MapOfBoolToString) Set(k bool, v string) MapOfBoolToString {
|
||||
return MapOfBoolToString{m.m.Set(types.Bool(k), types.NewString(v))}
|
||||
return MapOfBoolToString{m.m.Set(types.Bool(k), types.NewString(v)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfBoolToString) Remove(p bool) MapOfBoolToString {
|
||||
return MapOfBoolToString{m.m.Remove(types.Bool(p))}
|
||||
return MapOfBoolToString{m.m.Remove(types.Bool(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfBoolToStringIterCallback func(k bool, v string) (stop bool)
|
||||
@@ -141,11 +151,12 @@ func (m MapOfBoolToString) Filter(cb MapOfBoolToStringFilterCallback) MapOfBoolT
|
||||
// MapOfStringToValue
|
||||
|
||||
type MapOfStringToValue struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfStringToValue() MapOfStringToValue {
|
||||
return MapOfStringToValue{types.NewMap()}
|
||||
return MapOfStringToValue{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToValueDef map[string]types.Value
|
||||
@@ -155,7 +166,7 @@ func (def MapOfStringToValueDef) New() MapOfStringToValue {
|
||||
for k, v := range def {
|
||||
kv = append(kv, types.NewString(k), v)
|
||||
}
|
||||
return MapOfStringToValue{types.NewMap(kv...)}
|
||||
return MapOfStringToValue{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Def() MapOfStringToValueDef {
|
||||
@@ -167,24 +178,33 @@ func (m MapOfStringToValue) Def() MapOfStringToValueDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfStringToValueFromVal(p types.Value) MapOfStringToValue {
|
||||
func MapOfStringToValueFromVal(val types.Value) MapOfStringToValue {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfStringToValue); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfStringToValue{p.(types.Map)}
|
||||
return MapOfStringToValue{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfStringToValue); ok {
|
||||
return m.m.Equals(other.m)
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Chunks() (futures []types.Future) {
|
||||
@@ -202,7 +222,7 @@ func (m MapOfStringToValue) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToValue = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToValue, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToValue, func(v types.Value) types.Value {
|
||||
return MapOfStringToValueFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -232,13 +252,13 @@ func (m MapOfStringToValue) MaybeGet(p string) (types.Value, bool) {
|
||||
}
|
||||
|
||||
func (m MapOfStringToValue) Set(k string, v types.Value) MapOfStringToValue {
|
||||
return MapOfStringToValue{m.m.Set(types.NewString(k), v)}
|
||||
return MapOfStringToValue{m.m.Set(types.NewString(k), v), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfStringToValue) Remove(p string) MapOfStringToValue {
|
||||
return MapOfStringToValue{m.m.Remove(types.NewString(p))}
|
||||
return MapOfStringToValue{m.m.Remove(types.NewString(p)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfStringToValueIterCallback func(k string, v types.Value) (stop bool)
|
||||
|
||||
+153
-86
@@ -28,14 +28,15 @@ func __testPackageInFile_ref_Ref() ref.Ref {
|
||||
// StructWithRef
|
||||
|
||||
type StructWithRef struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewStructWithRef() StructWithRef {
|
||||
return StructWithRef{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_ref_CachedRef, 0),
|
||||
types.NewString("r"), types.Ref{R: ref.Ref{}},
|
||||
)}
|
||||
types.NewString("r"), NewRefOfSetOfFloat32(ref.Ref{}),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type StructWithRefDef struct {
|
||||
@@ -46,8 +47,8 @@ func (def StructWithRefDef) New() StructWithRef {
|
||||
return StructWithRef{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_ref_CachedRef, 0),
|
||||
types.NewString("r"), types.Ref{R: def.R},
|
||||
)}
|
||||
types.NewString("r"), NewRefOfSetOfFloat32(def.R),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithRef) Def() (d StructWithRefDef) {
|
||||
@@ -62,29 +63,38 @@ func (m StructWithRef) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithRef, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithRef, func(v types.Value) types.Value {
|
||||
return StructWithRefFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func StructWithRefFromVal(val types.Value) StructWithRef {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(StructWithRef); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return StructWithRef{val.(types.Map)}
|
||||
return StructWithRef{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithRef) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s StructWithRef) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s StructWithRef) Equals(other types.Value) bool {
|
||||
if other, ok := other.(StructWithRef); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s StructWithRef) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s StructWithRef) Chunks() (futures []types.Future) {
|
||||
@@ -94,30 +104,31 @@ func (s StructWithRef) Chunks() (futures []types.Future) {
|
||||
}
|
||||
|
||||
func (s StructWithRef) R() RefOfSetOfFloat32 {
|
||||
return RefOfSetOfFloat32FromVal(s.m.Get(types.NewString("r")))
|
||||
return s.m.Get(types.NewString("r")).(RefOfSetOfFloat32)
|
||||
}
|
||||
|
||||
func (s StructWithRef) SetR(val RefOfSetOfFloat32) StructWithRef {
|
||||
return StructWithRef{s.m.Set(types.NewString("r"), val.NomsValue())}
|
||||
return StructWithRef{s.m.Set(types.NewString("r"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// RefOfListOfString
|
||||
|
||||
type RefOfListOfString struct {
|
||||
r ref.Ref
|
||||
r ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRefOfListOfString(r ref.Ref) RefOfListOfString {
|
||||
return RefOfListOfString{r}
|
||||
return RefOfListOfString{r, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r RefOfListOfString) Ref() ref.Ref {
|
||||
return r.r
|
||||
return types.EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r RefOfListOfString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RefOfListOfString); ok {
|
||||
return r.r == other.r
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -127,11 +138,20 @@ func (r RefOfListOfString) Chunks() []types.Future {
|
||||
}
|
||||
|
||||
func (r RefOfListOfString) NomsValue() types.Value {
|
||||
return types.Ref{R: r.r}
|
||||
// TODO: Remove this
|
||||
return r
|
||||
}
|
||||
|
||||
func RefOfListOfStringFromVal(p types.Value) RefOfListOfString {
|
||||
return RefOfListOfString{p.(types.Ref).Ref()}
|
||||
func (r RefOfListOfString) InternalImplementation() ref.Ref {
|
||||
return r.r
|
||||
}
|
||||
|
||||
func RefOfListOfStringFromVal(val types.Value) RefOfListOfString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RefOfListOfString); ok {
|
||||
return val
|
||||
}
|
||||
return RefOfListOfString{val.(types.Ref).Ref(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// A Noms Value that describes RefOfListOfString.
|
||||
@@ -143,28 +163,28 @@ func (m RefOfListOfString) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForRefOfListOfString = types.MakeCompoundTypeRef("", types.RefKind, types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.StringKind)))
|
||||
types.RegisterFromValFunction(__typeRefForRefOfListOfString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForRefOfListOfString, func(v types.Value) types.Value {
|
||||
return RefOfListOfStringFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (r RefOfListOfString) GetValue(cs chunks.ChunkSource) ListOfString {
|
||||
return ListOfStringFromVal(types.ReadValue(r.r, cs))
|
||||
return types.ReadValue(r.r, cs).(ListOfString)
|
||||
}
|
||||
|
||||
func (r RefOfListOfString) SetValue(val ListOfString, cs chunks.ChunkSink) RefOfListOfString {
|
||||
ref := types.WriteValue(val.NomsValue(), cs)
|
||||
return RefOfListOfString{ref}
|
||||
return RefOfListOfString{types.WriteValue(val, cs), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfRefOfFloat32
|
||||
|
||||
type ListOfRefOfFloat32 struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfRefOfFloat32() ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{types.NewList()}
|
||||
return ListOfRefOfFloat32{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfRefOfFloat32Def []ref.Ref
|
||||
@@ -172,9 +192,9 @@ type ListOfRefOfFloat32Def []ref.Ref
|
||||
func (def ListOfRefOfFloat32Def) New() ListOfRefOfFloat32 {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = types.Ref{R: d}
|
||||
l[i] = NewRefOfFloat32(d)
|
||||
}
|
||||
return ListOfRefOfFloat32{types.NewList(l...)}
|
||||
return ListOfRefOfFloat32{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Def() ListOfRefOfFloat32Def {
|
||||
@@ -186,23 +206,32 @@ func (l ListOfRefOfFloat32) Def() ListOfRefOfFloat32Def {
|
||||
}
|
||||
|
||||
func ListOfRefOfFloat32FromVal(val types.Value) ListOfRefOfFloat32 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfRefOfFloat32); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfRefOfFloat32{val.(types.List)}
|
||||
return ListOfRefOfFloat32{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfRefOfFloat32); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Chunks() (futures []types.Future) {
|
||||
@@ -220,7 +249,7 @@ func (m ListOfRefOfFloat32) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfRefOfFloat32 = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.Float32Kind)))
|
||||
types.RegisterFromValFunction(__typeRefForListOfRefOfFloat32, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfRefOfFloat32, func(v types.Value) types.Value {
|
||||
return ListOfRefOfFloat32FromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -234,37 +263,37 @@ func (l ListOfRefOfFloat32) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Get(i uint64) RefOfFloat32 {
|
||||
return RefOfFloat32FromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(RefOfFloat32)
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Slice(idx uint64, end uint64) ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{l.l.Slice(idx, end)}
|
||||
return ListOfRefOfFloat32{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Set(i uint64, val RefOfFloat32) ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfRefOfFloat32{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Append(v ...RefOfFloat32) ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfRefOfFloat32{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Insert(idx uint64, v ...RefOfFloat32) ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfRefOfFloat32{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) Remove(idx uint64, end uint64) ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{l.l.Remove(idx, end)}
|
||||
return ListOfRefOfFloat32{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) RemoveAt(idx uint64) ListOfRefOfFloat32 {
|
||||
return ListOfRefOfFloat32{(l.l.RemoveAt(idx))}
|
||||
return ListOfRefOfFloat32{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfFloat32) fromElemSlice(p []RefOfFloat32) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -273,7 +302,7 @@ type ListOfRefOfFloat32IterCallback func(v RefOfFloat32, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfRefOfFloat32) Iter(cb ListOfRefOfFloat32IterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(RefOfFloat32FromVal(v), i)
|
||||
return cb(v.(RefOfFloat32), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -281,7 +310,7 @@ type ListOfRefOfFloat32IterAllCallback func(v RefOfFloat32, i uint64)
|
||||
|
||||
func (l ListOfRefOfFloat32) IterAll(cb ListOfRefOfFloat32IterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(RefOfFloat32FromVal(v), i)
|
||||
cb(v.(RefOfFloat32), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -300,20 +329,21 @@ func (l ListOfRefOfFloat32) Filter(cb ListOfRefOfFloat32FilterCallback) ListOfRe
|
||||
// RefOfSetOfFloat32
|
||||
|
||||
type RefOfSetOfFloat32 struct {
|
||||
r ref.Ref
|
||||
r ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRefOfSetOfFloat32(r ref.Ref) RefOfSetOfFloat32 {
|
||||
return RefOfSetOfFloat32{r}
|
||||
return RefOfSetOfFloat32{r, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r RefOfSetOfFloat32) Ref() ref.Ref {
|
||||
return r.r
|
||||
return types.EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r RefOfSetOfFloat32) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RefOfSetOfFloat32); ok {
|
||||
return r.r == other.r
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -323,11 +353,20 @@ func (r RefOfSetOfFloat32) Chunks() []types.Future {
|
||||
}
|
||||
|
||||
func (r RefOfSetOfFloat32) NomsValue() types.Value {
|
||||
return types.Ref{R: r.r}
|
||||
// TODO: Remove this
|
||||
return r
|
||||
}
|
||||
|
||||
func RefOfSetOfFloat32FromVal(p types.Value) RefOfSetOfFloat32 {
|
||||
return RefOfSetOfFloat32{p.(types.Ref).Ref()}
|
||||
func (r RefOfSetOfFloat32) InternalImplementation() ref.Ref {
|
||||
return r.r
|
||||
}
|
||||
|
||||
func RefOfSetOfFloat32FromVal(val types.Value) RefOfSetOfFloat32 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RefOfSetOfFloat32); ok {
|
||||
return val
|
||||
}
|
||||
return RefOfSetOfFloat32{val.(types.Ref).Ref(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// A Noms Value that describes RefOfSetOfFloat32.
|
||||
@@ -339,28 +378,28 @@ func (m RefOfSetOfFloat32) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForRefOfSetOfFloat32 = types.MakeCompoundTypeRef("", types.RefKind, types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind)))
|
||||
types.RegisterFromValFunction(__typeRefForRefOfSetOfFloat32, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForRefOfSetOfFloat32, func(v types.Value) types.Value {
|
||||
return RefOfSetOfFloat32FromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (r RefOfSetOfFloat32) GetValue(cs chunks.ChunkSource) SetOfFloat32 {
|
||||
return SetOfFloat32FromVal(types.ReadValue(r.r, cs))
|
||||
return types.ReadValue(r.r, cs).(SetOfFloat32)
|
||||
}
|
||||
|
||||
func (r RefOfSetOfFloat32) SetValue(val SetOfFloat32, cs chunks.ChunkSink) RefOfSetOfFloat32 {
|
||||
ref := types.WriteValue(val.NomsValue(), cs)
|
||||
return RefOfSetOfFloat32{ref}
|
||||
return RefOfSetOfFloat32{types.WriteValue(val, cs), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfString
|
||||
|
||||
type ListOfString struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfString() ListOfString {
|
||||
return ListOfString{types.NewList()}
|
||||
return ListOfString{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfStringDef []string
|
||||
@@ -370,7 +409,7 @@ func (def ListOfStringDef) New() ListOfString {
|
||||
for i, d := range def {
|
||||
l[i] = types.NewString(d)
|
||||
}
|
||||
return ListOfString{types.NewList(l...)}
|
||||
return ListOfString{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) Def() ListOfStringDef {
|
||||
@@ -382,23 +421,32 @@ func (l ListOfString) Def() ListOfStringDef {
|
||||
}
|
||||
|
||||
func ListOfStringFromVal(val types.Value) ListOfString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfString{val.(types.List)}
|
||||
return ListOfString{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfString) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfString); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfString) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfString) Chunks() (futures []types.Future) {
|
||||
@@ -416,7 +464,7 @@ func (m ListOfString) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfString = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForListOfString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfString, func(v types.Value) types.Value {
|
||||
return ListOfStringFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -434,27 +482,27 @@ func (l ListOfString) Get(i uint64) string {
|
||||
}
|
||||
|
||||
func (l ListOfString) Slice(idx uint64, end uint64) ListOfString {
|
||||
return ListOfString{l.l.Slice(idx, end)}
|
||||
return ListOfString{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) Set(i uint64, val string) ListOfString {
|
||||
return ListOfString{l.l.Set(i, types.NewString(val))}
|
||||
return ListOfString{l.l.Set(i, types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) Append(v ...string) ListOfString {
|
||||
return ListOfString{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfString{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) Insert(idx uint64, v ...string) ListOfString {
|
||||
return ListOfString{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfString{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) Remove(idx uint64, end uint64) ListOfString {
|
||||
return ListOfString{l.l.Remove(idx, end)}
|
||||
return ListOfString{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) RemoveAt(idx uint64) ListOfString {
|
||||
return ListOfString{(l.l.RemoveAt(idx))}
|
||||
return ListOfString{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfString) fromElemSlice(p []string) []types.Value {
|
||||
@@ -496,20 +544,21 @@ func (l ListOfString) Filter(cb ListOfStringFilterCallback) ListOfString {
|
||||
// RefOfFloat32
|
||||
|
||||
type RefOfFloat32 struct {
|
||||
r ref.Ref
|
||||
r ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRefOfFloat32(r ref.Ref) RefOfFloat32 {
|
||||
return RefOfFloat32{r}
|
||||
return RefOfFloat32{r, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r RefOfFloat32) Ref() ref.Ref {
|
||||
return r.r
|
||||
return types.EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r RefOfFloat32) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RefOfFloat32); ok {
|
||||
return r.r == other.r
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -519,11 +568,20 @@ func (r RefOfFloat32) Chunks() []types.Future {
|
||||
}
|
||||
|
||||
func (r RefOfFloat32) NomsValue() types.Value {
|
||||
return types.Ref{R: r.r}
|
||||
// TODO: Remove this
|
||||
return r
|
||||
}
|
||||
|
||||
func RefOfFloat32FromVal(p types.Value) RefOfFloat32 {
|
||||
return RefOfFloat32{p.(types.Ref).Ref()}
|
||||
func (r RefOfFloat32) InternalImplementation() ref.Ref {
|
||||
return r.r
|
||||
}
|
||||
|
||||
func RefOfFloat32FromVal(val types.Value) RefOfFloat32 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RefOfFloat32); ok {
|
||||
return val
|
||||
}
|
||||
return RefOfFloat32{val.(types.Ref).Ref(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// A Noms Value that describes RefOfFloat32.
|
||||
@@ -535,7 +593,7 @@ func (m RefOfFloat32) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForRefOfFloat32 = types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.Float32Kind))
|
||||
types.RegisterFromValFunction(__typeRefForRefOfFloat32, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForRefOfFloat32, func(v types.Value) types.Value {
|
||||
return RefOfFloat32FromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -545,18 +603,18 @@ func (r RefOfFloat32) GetValue(cs chunks.ChunkSource) float32 {
|
||||
}
|
||||
|
||||
func (r RefOfFloat32) SetValue(val float32, cs chunks.ChunkSink) RefOfFloat32 {
|
||||
ref := types.WriteValue(types.Float32(val), cs)
|
||||
return RefOfFloat32{ref}
|
||||
return RefOfFloat32{types.WriteValue(types.Float32(val), cs), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// SetOfFloat32
|
||||
|
||||
type SetOfFloat32 struct {
|
||||
s types.Set
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfFloat32() SetOfFloat32 {
|
||||
return SetOfFloat32{types.NewSet()}
|
||||
return SetOfFloat32{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SetOfFloat32Def map[float32]bool
|
||||
@@ -568,7 +626,7 @@ func (def SetOfFloat32Def) New() SetOfFloat32 {
|
||||
l[i] = types.Float32(d)
|
||||
i++
|
||||
}
|
||||
return SetOfFloat32{types.NewSet(l...)}
|
||||
return SetOfFloat32{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Def() SetOfFloat32Def {
|
||||
@@ -580,23 +638,32 @@ func (s SetOfFloat32) Def() SetOfFloat32Def {
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfFloat32FromVal(p types.Value) SetOfFloat32 {
|
||||
return SetOfFloat32{p.(types.Set)}
|
||||
func SetOfFloat32FromVal(val types.Value) SetOfFloat32 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfFloat32); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfFloat32{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfFloat32); ok {
|
||||
return s.s.Equals(other.s)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Chunks() (futures []types.Future) {
|
||||
@@ -614,7 +681,7 @@ func (m SetOfFloat32) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfFloat32 = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfFloat32, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSetOfFloat32, func(v types.Value) types.Value {
|
||||
return SetOfFloat32FromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -660,19 +727,19 @@ func (s SetOfFloat32) Filter(cb SetOfFloat32FilterCallback) SetOfFloat32 {
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Insert(p ...float32) SetOfFloat32 {
|
||||
return SetOfFloat32{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
return SetOfFloat32{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Remove(p ...float32) SetOfFloat32 {
|
||||
return SetOfFloat32{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
return SetOfFloat32{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Union(others ...SetOfFloat32) SetOfFloat32 {
|
||||
return SetOfFloat32{s.s.Union(s.fromStructSlice(others)...)}
|
||||
return SetOfFloat32{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Subtract(others ...SetOfFloat32) SetOfFloat32 {
|
||||
return SetOfFloat32{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
return SetOfFloat32{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfFloat32) Any() float32 {
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestRefFromValAndNomsValue(t *testing.T) {
|
||||
r2 := NewRefOfListOfString(l.Ref())
|
||||
assert.True(r.Equals(r2))
|
||||
|
||||
rv2 := r.NomsValue()
|
||||
rv2 := types.Ref{R: r.InternalImplementation()}
|
||||
assert.True(rv.Equals(rv2))
|
||||
}
|
||||
|
||||
@@ -79,10 +79,10 @@ func TestStructWithRef(t *testing.T) {
|
||||
|
||||
assert.Panics(func() { r2.GetValue(cs) })
|
||||
|
||||
types.WriteValue(str.NomsValue(), cs)
|
||||
types.WriteValue(str, cs)
|
||||
assert.Panics(func() { r2.GetValue(cs) })
|
||||
|
||||
types.WriteValue(set.NomsValue(), cs)
|
||||
types.WriteValue(set, cs)
|
||||
set2 := r2.GetValue(cs)
|
||||
assert.True(set.Equals(set2))
|
||||
}
|
||||
|
||||
+22
-12
@@ -10,11 +10,12 @@ import (
|
||||
// SetOfBool
|
||||
|
||||
type SetOfBool struct {
|
||||
s types.Set
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfBool() SetOfBool {
|
||||
return SetOfBool{types.NewSet()}
|
||||
return SetOfBool{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SetOfBoolDef map[bool]bool
|
||||
@@ -26,7 +27,7 @@ func (def SetOfBoolDef) New() SetOfBool {
|
||||
l[i] = types.Bool(d)
|
||||
i++
|
||||
}
|
||||
return SetOfBool{types.NewSet(l...)}
|
||||
return SetOfBool{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Def() SetOfBoolDef {
|
||||
@@ -38,23 +39,32 @@ func (s SetOfBool) Def() SetOfBoolDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfBoolFromVal(p types.Value) SetOfBool {
|
||||
return SetOfBool{p.(types.Set)}
|
||||
func SetOfBoolFromVal(val types.Value) SetOfBool {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfBool); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfBool{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfBool) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfBool) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfBool) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfBool); ok {
|
||||
return s.s.Equals(other.s)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfBool) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfBool) Chunks() (futures []types.Future) {
|
||||
@@ -72,7 +82,7 @@ func (m SetOfBool) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfBool = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.BoolKind))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfBool, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSetOfBool, func(v types.Value) types.Value {
|
||||
return SetOfBoolFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -118,19 +128,19 @@ func (s SetOfBool) Filter(cb SetOfBoolFilterCallback) SetOfBool {
|
||||
}
|
||||
|
||||
func (s SetOfBool) Insert(p ...bool) SetOfBool {
|
||||
return SetOfBool{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
return SetOfBool{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Remove(p ...bool) SetOfBool {
|
||||
return SetOfBool{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
return SetOfBool{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Union(others ...SetOfBool) SetOfBool {
|
||||
return SetOfBool{s.s.Union(s.fromStructSlice(others)...)}
|
||||
return SetOfBool{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Subtract(others ...SetOfBool) SetOfBool {
|
||||
return SetOfBool{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
return SetOfBool{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Any() bool {
|
||||
|
||||
@@ -28,7 +28,8 @@ func __testPackageInFile_struct_Ref() ref.Ref {
|
||||
// Struct
|
||||
|
||||
type Struct struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewStruct() Struct {
|
||||
@@ -36,7 +37,7 @@ func NewStruct() Struct {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(""),
|
||||
types.NewString("b"), types.Bool(false),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type StructDef struct {
|
||||
@@ -50,7 +51,7 @@ func (def StructDef) New() Struct {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(def.S),
|
||||
types.NewString("b"), types.Bool(def.B),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Struct) Def() (d StructDef) {
|
||||
@@ -66,29 +67,38 @@ func (m Struct) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForStruct, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForStruct, func(v types.Value) types.Value {
|
||||
return StructFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func StructFromVal(val types.Value) Struct {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Struct); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Struct{val.(types.Map)}
|
||||
return Struct{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Struct) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Struct) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Struct) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Struct); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Struct) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Struct) Chunks() (futures []types.Future) {
|
||||
@@ -102,7 +112,7 @@ func (s Struct) S() string {
|
||||
}
|
||||
|
||||
func (s Struct) SetS(val string) Struct {
|
||||
return Struct{s.m.Set(types.NewString("s"), types.NewString(val))}
|
||||
return Struct{s.m.Set(types.NewString("s"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Struct) B() bool {
|
||||
@@ -110,17 +120,18 @@ func (s Struct) B() bool {
|
||||
}
|
||||
|
||||
func (s Struct) SetB(val bool) Struct {
|
||||
return Struct{s.m.Set(types.NewString("b"), types.Bool(val))}
|
||||
return Struct{s.m.Set(types.NewString("b"), types.Bool(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfStruct
|
||||
|
||||
type ListOfStruct struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfStruct() ListOfStruct {
|
||||
return ListOfStruct{types.NewList()}
|
||||
return ListOfStruct{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfStructDef []StructDef
|
||||
@@ -128,37 +139,46 @@ type ListOfStructDef []StructDef
|
||||
func (def ListOfStructDef) New() ListOfStruct {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfStruct{types.NewList(l...)}
|
||||
return ListOfStruct{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Def() ListOfStructDef {
|
||||
d := make([]StructDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = StructFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(Struct).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfStructFromVal(val types.Value) ListOfStruct {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfStruct); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfStruct{val.(types.List)}
|
||||
return ListOfStruct{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfStruct) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfStruct); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Chunks() (futures []types.Future) {
|
||||
@@ -176,7 +196,7 @@ func (m ListOfStruct) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfStruct = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__testPackageInFile_struct_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfStruct, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfStruct, func(v types.Value) types.Value {
|
||||
return ListOfStructFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -190,37 +210,37 @@ func (l ListOfStruct) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Get(i uint64) Struct {
|
||||
return StructFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(Struct)
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Slice(idx uint64, end uint64) ListOfStruct {
|
||||
return ListOfStruct{l.l.Slice(idx, end)}
|
||||
return ListOfStruct{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Set(i uint64, val Struct) ListOfStruct {
|
||||
return ListOfStruct{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfStruct{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Append(v ...Struct) ListOfStruct {
|
||||
return ListOfStruct{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfStruct{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Insert(idx uint64, v ...Struct) ListOfStruct {
|
||||
return ListOfStruct{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfStruct{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) Remove(idx uint64, end uint64) ListOfStruct {
|
||||
return ListOfStruct{l.l.Remove(idx, end)}
|
||||
return ListOfStruct{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) RemoveAt(idx uint64) ListOfStruct {
|
||||
return ListOfStruct{(l.l.RemoveAt(idx))}
|
||||
return ListOfStruct{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfStruct) fromElemSlice(p []Struct) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -229,7 +249,7 @@ type ListOfStructIterCallback func(v Struct, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfStruct) Iter(cb ListOfStructIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(StructFromVal(v), i)
|
||||
return cb(v.(Struct), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -237,7 +257,7 @@ type ListOfStructIterAllCallback func(v Struct, i uint64)
|
||||
|
||||
func (l ListOfStruct) IterAll(cb ListOfStructIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(StructFromVal(v), i)
|
||||
cb(v.(Struct), i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,14 @@ func __testPackageInFile_struct_optional_Ref() ref.Ref {
|
||||
// OptionalStruct
|
||||
|
||||
type OptionalStruct struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewOptionalStruct() OptionalStruct {
|
||||
return OptionalStruct{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_optional_CachedRef, 0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type OptionalStructDef struct {
|
||||
@@ -48,7 +49,7 @@ func (def OptionalStructDef) New() OptionalStruct {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_optional_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(def.S),
|
||||
types.NewString("b"), types.Bool(def.B),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s OptionalStruct) Def() (d OptionalStructDef) {
|
||||
@@ -68,29 +69,38 @@ func (m OptionalStruct) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForOptionalStruct, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForOptionalStruct, func(v types.Value) types.Value {
|
||||
return OptionalStructFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func OptionalStructFromVal(val types.Value) OptionalStruct {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(OptionalStruct); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return OptionalStruct{val.(types.Map)}
|
||||
return OptionalStruct{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s OptionalStruct) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s OptionalStruct) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s OptionalStruct) Equals(other types.Value) bool {
|
||||
if other, ok := other.(OptionalStruct); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s OptionalStruct) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s OptionalStruct) Chunks() (futures []types.Future) {
|
||||
@@ -108,7 +118,7 @@ func (s OptionalStruct) S() (v string, ok bool) {
|
||||
}
|
||||
|
||||
func (s OptionalStruct) SetS(val string) OptionalStruct {
|
||||
return OptionalStruct{s.m.Set(types.NewString("s"), types.NewString(val))}
|
||||
return OptionalStruct{s.m.Set(types.NewString("s"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s OptionalStruct) B() (v bool, ok bool) {
|
||||
@@ -120,5 +130,5 @@ func (s OptionalStruct) B() (v bool, ok bool) {
|
||||
}
|
||||
|
||||
func (s OptionalStruct) SetB(val bool) OptionalStruct {
|
||||
return OptionalStruct{s.m.Set(types.NewString("b"), types.Bool(val))}
|
||||
return OptionalStruct{s.m.Set(types.NewString("b"), types.Bool(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ func __testPackageInFile_struct_primitives_Ref() ref.Ref {
|
||||
// StructPrimitives
|
||||
|
||||
type StructPrimitives struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewStructPrimitives() StructPrimitives {
|
||||
@@ -60,7 +61,7 @@ func NewStructPrimitives() StructPrimitives {
|
||||
types.NewString("string"), types.NewString(""),
|
||||
types.NewString("blob"), types.NewEmptyBlob(),
|
||||
types.NewString("value"), types.Bool(false),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type StructPrimitivesDef struct {
|
||||
@@ -98,7 +99,7 @@ func (def StructPrimitivesDef) New() StructPrimitives {
|
||||
types.NewString("string"), types.NewString(def.String),
|
||||
types.NewString("blob"), def.Blob,
|
||||
types.NewString("value"), def.Value,
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Def() (d StructPrimitivesDef) {
|
||||
@@ -126,29 +127,38 @@ func (m StructPrimitives) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForStructPrimitives, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForStructPrimitives, func(v types.Value) types.Value {
|
||||
return StructPrimitivesFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func StructPrimitivesFromVal(val types.Value) StructPrimitives {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(StructPrimitives); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return StructPrimitives{val.(types.Map)}
|
||||
return StructPrimitives{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s StructPrimitives) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Equals(other types.Value) bool {
|
||||
if other, ok := other.(StructPrimitives); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Chunks() (futures []types.Future) {
|
||||
@@ -162,7 +172,7 @@ func (s StructPrimitives) Uint64() uint64 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetUint64(val uint64) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint64"), types.UInt64(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint64"), types.UInt64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Uint32() uint32 {
|
||||
@@ -170,7 +180,7 @@ func (s StructPrimitives) Uint32() uint32 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetUint32(val uint32) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint32"), types.UInt32(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint32"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Uint16() uint16 {
|
||||
@@ -178,7 +188,7 @@ func (s StructPrimitives) Uint16() uint16 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetUint16(val uint16) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint16"), types.UInt16(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint16"), types.UInt16(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Uint8() uint8 {
|
||||
@@ -186,7 +196,7 @@ func (s StructPrimitives) Uint8() uint8 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetUint8(val uint8) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint8"), types.UInt8(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("uint8"), types.UInt8(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Int64() int64 {
|
||||
@@ -194,7 +204,7 @@ func (s StructPrimitives) Int64() int64 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetInt64(val int64) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("int64"), types.Int64(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("int64"), types.Int64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Int32() int32 {
|
||||
@@ -202,7 +212,7 @@ func (s StructPrimitives) Int32() int32 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetInt32(val int32) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("int32"), types.Int32(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("int32"), types.Int32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Int16() int16 {
|
||||
@@ -210,7 +220,7 @@ func (s StructPrimitives) Int16() int16 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetInt16(val int16) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("int16"), types.Int16(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("int16"), types.Int16(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Int8() int8 {
|
||||
@@ -218,7 +228,7 @@ func (s StructPrimitives) Int8() int8 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetInt8(val int8) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("int8"), types.Int8(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("int8"), types.Int8(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Float64() float64 {
|
||||
@@ -226,7 +236,7 @@ func (s StructPrimitives) Float64() float64 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetFloat64(val float64) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("float64"), types.Float64(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("float64"), types.Float64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Float32() float32 {
|
||||
@@ -234,7 +244,7 @@ func (s StructPrimitives) Float32() float32 {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetFloat32(val float32) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("float32"), types.Float32(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("float32"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Bool() bool {
|
||||
@@ -242,7 +252,7 @@ func (s StructPrimitives) Bool() bool {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetBool(val bool) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("bool"), types.Bool(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("bool"), types.Bool(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) String() string {
|
||||
@@ -250,7 +260,7 @@ func (s StructPrimitives) String() string {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetString(val string) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("string"), types.NewString(val))}
|
||||
return StructPrimitives{s.m.Set(types.NewString("string"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Blob() types.Blob {
|
||||
@@ -258,7 +268,7 @@ func (s StructPrimitives) Blob() types.Blob {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetBlob(val types.Blob) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("blob"), val)}
|
||||
return StructPrimitives{s.m.Set(types.NewString("blob"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructPrimitives) Value() types.Value {
|
||||
@@ -266,5 +276,5 @@ func (s StructPrimitives) Value() types.Value {
|
||||
}
|
||||
|
||||
func (s StructPrimitives) SetValue(val types.Value) StructPrimitives {
|
||||
return StructPrimitives{s.m.Set(types.NewString("value"), val)}
|
||||
return StructPrimitives{s.m.Set(types.NewString("value"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
@@ -121,5 +121,6 @@ func TestStructBackingMapKeyNames(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
s := NewStructPrimitives().SetBool(true)
|
||||
assert.True(bool(s.NomsValue().(types.Map).Get(types.NewString("bool")).(types.Bool)))
|
||||
|
||||
assert.True(bool(s.InternalImplementation().Get(types.NewString("bool")).(types.Bool)))
|
||||
}
|
||||
|
||||
@@ -27,14 +27,15 @@ func __testPackageInFile_struct_recursive_Ref() ref.Ref {
|
||||
// Tree
|
||||
|
||||
type Tree struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewTree() Tree {
|
||||
return Tree{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_recursive_CachedRef, 0),
|
||||
types.NewString("children"), types.NewList(),
|
||||
)}
|
||||
types.NewString("children"), NewListOfTree(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type TreeDef struct {
|
||||
@@ -45,12 +46,12 @@ func (def TreeDef) New() Tree {
|
||||
return Tree{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_recursive_CachedRef, 0),
|
||||
types.NewString("children"), def.Children.New().NomsValue(),
|
||||
)}
|
||||
types.NewString("children"), def.Children.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Tree) Def() (d TreeDef) {
|
||||
d.Children = ListOfTreeFromVal(s.m.Get(types.NewString("children"))).Def()
|
||||
d.Children = s.m.Get(types.NewString("children")).(ListOfTree).Def()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -61,29 +62,38 @@ func (m Tree) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForTree, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForTree, func(v types.Value) types.Value {
|
||||
return TreeFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func TreeFromVal(val types.Value) Tree {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Tree); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Tree{val.(types.Map)}
|
||||
return Tree{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Tree) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Tree) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Tree) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Tree); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Tree) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Tree) Chunks() (futures []types.Future) {
|
||||
@@ -93,21 +103,22 @@ func (s Tree) Chunks() (futures []types.Future) {
|
||||
}
|
||||
|
||||
func (s Tree) Children() ListOfTree {
|
||||
return ListOfTreeFromVal(s.m.Get(types.NewString("children")))
|
||||
return s.m.Get(types.NewString("children")).(ListOfTree)
|
||||
}
|
||||
|
||||
func (s Tree) SetChildren(val ListOfTree) Tree {
|
||||
return Tree{s.m.Set(types.NewString("children"), val.NomsValue())}
|
||||
return Tree{s.m.Set(types.NewString("children"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfTree
|
||||
|
||||
type ListOfTree struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfTree() ListOfTree {
|
||||
return ListOfTree{types.NewList()}
|
||||
return ListOfTree{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfTreeDef []TreeDef
|
||||
@@ -115,37 +126,46 @@ type ListOfTreeDef []TreeDef
|
||||
func (def ListOfTreeDef) New() ListOfTree {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfTree{types.NewList(l...)}
|
||||
return ListOfTree{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) Def() ListOfTreeDef {
|
||||
d := make([]TreeDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = TreeFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(Tree).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfTreeFromVal(val types.Value) ListOfTree {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfTree); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfTree{val.(types.List)}
|
||||
return ListOfTree{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfTree) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfTree) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfTree); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfTree) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfTree) Chunks() (futures []types.Future) {
|
||||
@@ -163,7 +183,7 @@ func (m ListOfTree) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfTree = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__testPackageInFile_struct_recursive_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfTree, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfTree, func(v types.Value) types.Value {
|
||||
return ListOfTreeFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -177,37 +197,37 @@ func (l ListOfTree) Empty() bool {
|
||||
}
|
||||
|
||||
func (l ListOfTree) Get(i uint64) Tree {
|
||||
return TreeFromVal(l.l.Get(i))
|
||||
return l.l.Get(i).(Tree)
|
||||
}
|
||||
|
||||
func (l ListOfTree) Slice(idx uint64, end uint64) ListOfTree {
|
||||
return ListOfTree{l.l.Slice(idx, end)}
|
||||
return ListOfTree{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) Set(i uint64, val Tree) ListOfTree {
|
||||
return ListOfTree{l.l.Set(i, val.NomsValue())}
|
||||
return ListOfTree{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) Append(v ...Tree) ListOfTree {
|
||||
return ListOfTree{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfTree{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) Insert(idx uint64, v ...Tree) ListOfTree {
|
||||
return ListOfTree{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfTree{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) Remove(idx uint64, end uint64) ListOfTree {
|
||||
return ListOfTree{l.l.Remove(idx, end)}
|
||||
return ListOfTree{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) RemoveAt(idx uint64) ListOfTree {
|
||||
return ListOfTree{(l.l.RemoveAt(idx))}
|
||||
return ListOfTree{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfTree) fromElemSlice(p []Tree) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -216,7 +236,7 @@ type ListOfTreeIterCallback func(v Tree, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfTree) Iter(cb ListOfTreeIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(TreeFromVal(v), i)
|
||||
return cb(v.(Tree), i)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -224,7 +244,7 @@ type ListOfTreeIterAllCallback func(v Tree, i uint64)
|
||||
|
||||
func (l ListOfTree) IterAll(cb ListOfTreeIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(TreeFromVal(v), i)
|
||||
cb(v.(Tree), i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c"
|
||||
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d"
|
||||
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
@@ -18,13 +19,13 @@ func __testPackageInFile_struct_with_imports_Ref() ref.Ref {
|
||||
types.MakeEnumTypeRef("E", "E1", "Ignored"),
|
||||
types.MakeStructTypeRef("ImportUser",
|
||||
[]types.Field{
|
||||
types.Field{"importedStruct", types.MakeTypeRef(ref.Parse("sha1-fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c"), 0), false},
|
||||
types.Field{"importedStruct", types.MakeTypeRef(ref.Parse("sha1-d31b592f480b7659b03b72a7d1271f31dde57b2d"), 0), false},
|
||||
types.Field{"enum", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c"),
|
||||
ref.Parse("sha1-d31b592f480b7659b03b72a7d1271f31dde57b2d"),
|
||||
})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
@@ -41,19 +42,20 @@ const (
|
||||
// ImportUser
|
||||
|
||||
type ImportUser struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewImportUser() ImportUser {
|
||||
return ImportUser{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_imports_CachedRef, 1),
|
||||
types.NewString("importedStruct"), sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.NewD().NomsValue(),
|
||||
types.NewString("importedStruct"), sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.NewD(),
|
||||
types.NewString("enum"), types.UInt32(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ImportUserDef struct {
|
||||
ImportedStruct sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DDef
|
||||
ImportedStruct sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.DDef
|
||||
Enum E
|
||||
}
|
||||
|
||||
@@ -61,13 +63,13 @@ func (def ImportUserDef) New() ImportUser {
|
||||
return ImportUser{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_imports_CachedRef, 1),
|
||||
types.NewString("importedStruct"), def.ImportedStruct.New().NomsValue(),
|
||||
types.NewString("importedStruct"), def.ImportedStruct.New(),
|
||||
types.NewString("enum"), types.UInt32(def.Enum),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s ImportUser) Def() (d ImportUserDef) {
|
||||
d.ImportedStruct = sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DFromVal(s.m.Get(types.NewString("importedStruct"))).Def()
|
||||
d.ImportedStruct = s.m.Get(types.NewString("importedStruct")).(sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D).Def()
|
||||
d.Enum = E(s.m.Get(types.NewString("enum")).(types.UInt32))
|
||||
return
|
||||
}
|
||||
@@ -79,29 +81,38 @@ func (m ImportUser) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForImportUser, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForImportUser, func(v types.Value) types.Value {
|
||||
return ImportUserFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func ImportUserFromVal(val types.Value) ImportUser {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ImportUser); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ImportUser{val.(types.Map)}
|
||||
return ImportUser{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s ImportUser) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s ImportUser) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s ImportUser) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ImportUser); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s ImportUser) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s ImportUser) Chunks() (futures []types.Future) {
|
||||
@@ -110,12 +121,12 @@ func (s ImportUser) Chunks() (futures []types.Future) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s ImportUser) ImportedStruct() sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D {
|
||||
return sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DFromVal(s.m.Get(types.NewString("importedStruct")))
|
||||
func (s ImportUser) ImportedStruct() sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D {
|
||||
return s.m.Get(types.NewString("importedStruct")).(sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D)
|
||||
}
|
||||
|
||||
func (s ImportUser) SetImportedStruct(val sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D) ImportUser {
|
||||
return ImportUser{s.m.Set(types.NewString("importedStruct"), val.NomsValue())}
|
||||
func (s ImportUser) SetImportedStruct(val sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D) ImportUser {
|
||||
return ImportUser{s.m.Set(types.NewString("importedStruct"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s ImportUser) Enum() E {
|
||||
@@ -123,142 +134,152 @@ func (s ImportUser) Enum() E {
|
||||
}
|
||||
|
||||
func (s ImportUser) SetEnum(val E) ImportUser {
|
||||
return ImportUser{s.m.Set(types.NewString("enum"), types.UInt32(val))}
|
||||
return ImportUser{s.m.Set(types.NewString("enum"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D
|
||||
// ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D
|
||||
|
||||
type ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D struct {
|
||||
l types.List
|
||||
type ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D struct {
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D() ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{types.NewList()}
|
||||
func NewListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D() ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DDef []sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DDef
|
||||
type ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DDef []sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.DDef
|
||||
|
||||
func (def ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DDef) New() ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
func (def ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DDef) New() ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = d.New().NomsValue()
|
||||
l[i] = d.New()
|
||||
}
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{types.NewList(l...)}
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Def() ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DDef {
|
||||
d := make([]sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DDef, l.Len())
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Def() ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DDef {
|
||||
d := make([]sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.DDef, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DFromVal(l.l.Get(i)).Def()
|
||||
d[i] = l.l.Get(i).(sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D).Def()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DFromVal(val types.Value) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
func ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DFromVal(val types.Value) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{val.(types.List)}
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) NomsValue() types.Value {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D); ok {
|
||||
return l.l.Equals(other.l)
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D); ok {
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Ref() ref.Ref {
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Chunks() (futures []types.Future) {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, l.TypeRef().Chunks()...)
|
||||
futures = append(futures, l.l.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D.
|
||||
var __typeRefForListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D types.TypeRef
|
||||
// A Noms Value that describes ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D.
|
||||
var __typeRefForListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D types.TypeRef
|
||||
|
||||
func (m ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) TypeRef() types.TypeRef {
|
||||
return __typeRefForListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D
|
||||
func (m ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) TypeRef() types.TypeRef {
|
||||
return __typeRefForListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(ref.Parse("sha1-fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c"), 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D, func(v types.Value) types.NomsValue {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DFromVal(v)
|
||||
__typeRefForListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(ref.Parse("sha1-d31b592f480b7659b03b72a7d1271f31dde57b2d"), 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D, func(v types.Value) types.Value {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Len() uint64 {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Len() uint64 {
|
||||
return l.l.Len()
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Empty() bool {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Empty() bool {
|
||||
return l.Len() == uint64(0)
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Get(i uint64) sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D {
|
||||
return sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DFromVal(l.l.Get(i))
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Get(i uint64) sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D {
|
||||
return l.l.Get(i).(sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D)
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Slice(idx uint64, end uint64) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{l.l.Slice(idx, end)}
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Slice(idx uint64, end uint64) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Set(i uint64, val sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{l.l.Set(i, val.NomsValue())}
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Set(i uint64, val sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Append(v ...sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{l.l.Append(l.fromElemSlice(v)...)}
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Append(v ...sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Insert(idx uint64, v ...sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Insert(idx uint64, v ...sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Remove(idx uint64, end uint64) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{l.l.Remove(idx, end)}
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Remove(idx uint64, end uint64) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) RemoveAt(idx uint64) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
return ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D{(l.l.RemoveAt(idx))}
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) RemoveAt(idx uint64) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
return ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) fromElemSlice(p []sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D) []types.Value {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) fromElemSlice(p []sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
type ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DIterCallback func(v sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D, i uint64) (stop bool)
|
||||
type ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DIterCallback func(v sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Iter(cb ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DIterCallback) {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Iter(cb ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DFromVal(v), i)
|
||||
return cb(v.(sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D), i)
|
||||
})
|
||||
}
|
||||
|
||||
type ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DIterAllCallback func(v sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D, i uint64)
|
||||
type ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DIterAllCallback func(v sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D, i uint64)
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) IterAll(cb ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DIterAllCallback) {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) IterAll(cb ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.DFromVal(v), i)
|
||||
cb(v.(sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D), i)
|
||||
})
|
||||
}
|
||||
|
||||
type ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DFilterCallback func(v sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D, i uint64) (keep bool)
|
||||
type ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DFilterCallback func(v sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D, i uint64) (keep bool)
|
||||
|
||||
func (l ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D) Filter(cb ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DFilterCallback) ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D {
|
||||
nl := NewListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_D()
|
||||
l.IterAll(func(v sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c.D, i uint64) {
|
||||
func (l ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D) Filter(cb ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DFilterCallback) ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D {
|
||||
nl := NewListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_D()
|
||||
l.IterAll(func(v sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d.D, i uint64) {
|
||||
if cb(v, i) {
|
||||
nl = nl.Append(v)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
leaf "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_8bbcfa69bdfc9953c4034f8591964e0387983910"
|
||||
dep "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c"
|
||||
leaf "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288"
|
||||
dep "github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_d31b592f480b7659b03b72a7d1271f31dde57b2d"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestWithImportsDef(t *testing.T) {
|
||||
|
||||
func TestListOfImportsDef(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
lDef := ListOfsha1_fa6ca544e2613ecf1ac0467b3d655d8305c6ae8c_DDef{
|
||||
lDef := ListOfsha1_d31b592f480b7659b03b72a7d1271f31dde57b2d_DDef{
|
||||
dep.DDef{EnumField: leaf.E3},
|
||||
dep.DDef{EnumField: leaf.E2},
|
||||
dep.DDef{EnumField: leaf.E1},
|
||||
|
||||
@@ -30,17 +30,18 @@ func __testPackageInFile_struct_with_list_Ref() ref.Ref {
|
||||
// StructWithList
|
||||
|
||||
type StructWithList struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewStructWithList() StructWithList {
|
||||
return StructWithList{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_list_CachedRef, 0),
|
||||
types.NewString("l"), types.NewList(),
|
||||
types.NewString("l"), NewListOfUInt8(),
|
||||
types.NewString("b"), types.Bool(false),
|
||||
types.NewString("s"), types.NewString(""),
|
||||
types.NewString("i"), types.Int64(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type StructWithListDef struct {
|
||||
@@ -54,15 +55,15 @@ func (def StructWithListDef) New() StructWithList {
|
||||
return StructWithList{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_list_CachedRef, 0),
|
||||
types.NewString("l"), def.L.New().NomsValue(),
|
||||
types.NewString("l"), def.L.New(),
|
||||
types.NewString("b"), types.Bool(def.B),
|
||||
types.NewString("s"), types.NewString(def.S),
|
||||
types.NewString("i"), types.Int64(def.I),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithList) Def() (d StructWithListDef) {
|
||||
d.L = ListOfUInt8FromVal(s.m.Get(types.NewString("l"))).Def()
|
||||
d.L = s.m.Get(types.NewString("l")).(ListOfUInt8).Def()
|
||||
d.B = bool(s.m.Get(types.NewString("b")).(types.Bool))
|
||||
d.S = s.m.Get(types.NewString("s")).(types.String).String()
|
||||
d.I = int64(s.m.Get(types.NewString("i")).(types.Int64))
|
||||
@@ -76,29 +77,38 @@ func (m StructWithList) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithList, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithList, func(v types.Value) types.Value {
|
||||
return StructWithListFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func StructWithListFromVal(val types.Value) StructWithList {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(StructWithList); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return StructWithList{val.(types.Map)}
|
||||
return StructWithList{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithList) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s StructWithList) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s StructWithList) Equals(other types.Value) bool {
|
||||
if other, ok := other.(StructWithList); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s StructWithList) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s StructWithList) Chunks() (futures []types.Future) {
|
||||
@@ -108,11 +118,11 @@ func (s StructWithList) Chunks() (futures []types.Future) {
|
||||
}
|
||||
|
||||
func (s StructWithList) L() ListOfUInt8 {
|
||||
return ListOfUInt8FromVal(s.m.Get(types.NewString("l")))
|
||||
return s.m.Get(types.NewString("l")).(ListOfUInt8)
|
||||
}
|
||||
|
||||
func (s StructWithList) SetL(val ListOfUInt8) StructWithList {
|
||||
return StructWithList{s.m.Set(types.NewString("l"), val.NomsValue())}
|
||||
return StructWithList{s.m.Set(types.NewString("l"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithList) B() bool {
|
||||
@@ -120,7 +130,7 @@ func (s StructWithList) B() bool {
|
||||
}
|
||||
|
||||
func (s StructWithList) SetB(val bool) StructWithList {
|
||||
return StructWithList{s.m.Set(types.NewString("b"), types.Bool(val))}
|
||||
return StructWithList{s.m.Set(types.NewString("b"), types.Bool(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithList) S() string {
|
||||
@@ -128,7 +138,7 @@ func (s StructWithList) S() string {
|
||||
}
|
||||
|
||||
func (s StructWithList) SetS(val string) StructWithList {
|
||||
return StructWithList{s.m.Set(types.NewString("s"), types.NewString(val))}
|
||||
return StructWithList{s.m.Set(types.NewString("s"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithList) I() int64 {
|
||||
@@ -136,17 +146,18 @@ func (s StructWithList) I() int64 {
|
||||
}
|
||||
|
||||
func (s StructWithList) SetI(val int64) StructWithList {
|
||||
return StructWithList{s.m.Set(types.NewString("i"), types.Int64(val))}
|
||||
return StructWithList{s.m.Set(types.NewString("i"), types.Int64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfUInt8
|
||||
|
||||
type ListOfUInt8 struct {
|
||||
l types.List
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfUInt8() ListOfUInt8 {
|
||||
return ListOfUInt8{types.NewList()}
|
||||
return ListOfUInt8{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfUInt8Def []uint8
|
||||
@@ -156,7 +167,7 @@ func (def ListOfUInt8Def) New() ListOfUInt8 {
|
||||
for i, d := range def {
|
||||
l[i] = types.UInt8(d)
|
||||
}
|
||||
return ListOfUInt8{types.NewList(l...)}
|
||||
return ListOfUInt8{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Def() ListOfUInt8Def {
|
||||
@@ -168,23 +179,32 @@ func (l ListOfUInt8) Def() ListOfUInt8Def {
|
||||
}
|
||||
|
||||
func ListOfUInt8FromVal(val types.Value) ListOfUInt8 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfUInt8); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfUInt8{val.(types.List)}
|
||||
return ListOfUInt8{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfUInt8); ok {
|
||||
return l.l.Equals(other.l)
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Chunks() (futures []types.Future) {
|
||||
@@ -202,7 +222,7 @@ func (m ListOfUInt8) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfUInt8 = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.UInt8Kind))
|
||||
types.RegisterFromValFunction(__typeRefForListOfUInt8, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForListOfUInt8, func(v types.Value) types.Value {
|
||||
return ListOfUInt8FromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -220,27 +240,27 @@ func (l ListOfUInt8) Get(i uint64) uint8 {
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Slice(idx uint64, end uint64) ListOfUInt8 {
|
||||
return ListOfUInt8{l.l.Slice(idx, end)}
|
||||
return ListOfUInt8{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Set(i uint64, val uint8) ListOfUInt8 {
|
||||
return ListOfUInt8{l.l.Set(i, types.UInt8(val))}
|
||||
return ListOfUInt8{l.l.Set(i, types.UInt8(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Append(v ...uint8) ListOfUInt8 {
|
||||
return ListOfUInt8{l.l.Append(l.fromElemSlice(v)...)}
|
||||
return ListOfUInt8{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Insert(idx uint64, v ...uint8) ListOfUInt8 {
|
||||
return ListOfUInt8{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
return ListOfUInt8{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) Remove(idx uint64, end uint64) ListOfUInt8 {
|
||||
return ListOfUInt8{l.l.Remove(idx, end)}
|
||||
return ListOfUInt8{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) RemoveAt(idx uint64) ListOfUInt8 {
|
||||
return ListOfUInt8{(l.l.RemoveAt(idx))}
|
||||
return ListOfUInt8{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfUInt8) fromElemSlice(p []uint8) []types.Value {
|
||||
|
||||
@@ -33,7 +33,8 @@ func __testPackageInFile_struct_with_union_field_Ref() ref.Ref {
|
||||
// StructWithUnionField
|
||||
|
||||
type StructWithUnionField struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewStructWithUnionField() StructWithUnionField {
|
||||
@@ -42,7 +43,7 @@ func NewStructWithUnionField() StructWithUnionField {
|
||||
types.NewString("a"), types.Float32(0),
|
||||
types.NewString("$unionIndex"), types.UInt32(0),
|
||||
types.NewString("$unionValue"), types.Float64(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type StructWithUnionFieldDef struct {
|
||||
@@ -58,7 +59,7 @@ func (def StructWithUnionFieldDef) New() StructWithUnionField {
|
||||
types.NewString("a"), types.Float32(def.A),
|
||||
types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
|
||||
types.NewString("$unionValue"), def.__unionDefToValue(),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) Def() (d StructWithUnionFieldDef) {
|
||||
@@ -79,7 +80,7 @@ func (def StructWithUnionFieldDef) __unionDefToValue() types.Value {
|
||||
case 3:
|
||||
return def.__unionValue.(types.Value)
|
||||
case 4:
|
||||
return def.__unionValue.(SetOfUInt8Def).New().NomsValue()
|
||||
return def.__unionValue.(SetOfUInt8Def).New()
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -95,7 +96,7 @@ func (s StructWithUnionField) __unionValueToDef() interface{} {
|
||||
case 3:
|
||||
return s.m.Get(types.NewString("$unionValue"))
|
||||
case 4:
|
||||
return SetOfUInt8FromVal(s.m.Get(types.NewString("$unionValue"))).Def()
|
||||
return s.m.Get(types.NewString("$unionValue")).(SetOfUInt8).Def()
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -107,29 +108,38 @@ func (m StructWithUnionField) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithUnionField, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithUnionField, func(v types.Value) types.Value {
|
||||
return StructWithUnionFieldFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func StructWithUnionFieldFromVal(val types.Value) StructWithUnionField {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(StructWithUnionField); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return StructWithUnionField{val.(types.Map)}
|
||||
return StructWithUnionField{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) Equals(other types.Value) bool {
|
||||
if other, ok := other.(StructWithUnionField); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) Chunks() (futures []types.Future) {
|
||||
@@ -143,7 +153,7 @@ func (s StructWithUnionField) A() float32 {
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) SetA(val float32) StructWithUnionField {
|
||||
return StructWithUnionField{s.m.Set(types.NewString("a"), types.Float32(val))}
|
||||
return StructWithUnionField{s.m.Set(types.NewString("a"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) B() (val float64, ok bool) {
|
||||
@@ -154,7 +164,7 @@ func (s StructWithUnionField) B() (val float64, ok bool) {
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) SetB(val float64) StructWithUnionField {
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val))}
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def StructWithUnionFieldDef) B() (val float64, ok bool) {
|
||||
@@ -178,7 +188,7 @@ func (s StructWithUnionField) C() (val string, ok bool) {
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) SetC(val string) StructWithUnionField {
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val))}
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def StructWithUnionFieldDef) C() (val string, ok bool) {
|
||||
@@ -202,7 +212,7 @@ func (s StructWithUnionField) D() (val types.Blob, ok bool) {
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) SetD(val types.Blob) StructWithUnionField {
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(2)).Set(types.NewString("$unionValue"), val)}
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(2)).Set(types.NewString("$unionValue"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def StructWithUnionFieldDef) D() (val types.Blob, ok bool) {
|
||||
@@ -226,7 +236,7 @@ func (s StructWithUnionField) E() (val types.Value, ok bool) {
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) SetE(val types.Value) StructWithUnionField {
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(3)).Set(types.NewString("$unionValue"), val)}
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(3)).Set(types.NewString("$unionValue"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def StructWithUnionFieldDef) E() (val types.Value, ok bool) {
|
||||
@@ -246,11 +256,11 @@ func (s StructWithUnionField) F() (val SetOfUInt8, ok bool) {
|
||||
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 4 {
|
||||
return
|
||||
}
|
||||
return SetOfUInt8FromVal(s.m.Get(types.NewString("$unionValue"))), true
|
||||
return s.m.Get(types.NewString("$unionValue")).(SetOfUInt8), true
|
||||
}
|
||||
|
||||
func (s StructWithUnionField) SetF(val SetOfUInt8) StructWithUnionField {
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(4)).Set(types.NewString("$unionValue"), val.NomsValue())}
|
||||
return StructWithUnionField{s.m.Set(types.NewString("$unionIndex"), types.UInt32(4)).Set(types.NewString("$unionValue"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def StructWithUnionFieldDef) F() (val SetOfUInt8Def, ok bool) {
|
||||
@@ -269,11 +279,12 @@ func (def StructWithUnionFieldDef) SetF(val SetOfUInt8Def) StructWithUnionFieldD
|
||||
// SetOfUInt8
|
||||
|
||||
type SetOfUInt8 struct {
|
||||
s types.Set
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfUInt8() SetOfUInt8 {
|
||||
return SetOfUInt8{types.NewSet()}
|
||||
return SetOfUInt8{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SetOfUInt8Def map[uint8]bool
|
||||
@@ -285,7 +296,7 @@ func (def SetOfUInt8Def) New() SetOfUInt8 {
|
||||
l[i] = types.UInt8(d)
|
||||
i++
|
||||
}
|
||||
return SetOfUInt8{types.NewSet(l...)}
|
||||
return SetOfUInt8{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Def() SetOfUInt8Def {
|
||||
@@ -297,23 +308,32 @@ func (s SetOfUInt8) Def() SetOfUInt8Def {
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfUInt8FromVal(p types.Value) SetOfUInt8 {
|
||||
return SetOfUInt8{p.(types.Set)}
|
||||
func SetOfUInt8FromVal(val types.Value) SetOfUInt8 {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfUInt8); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfUInt8{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfUInt8); ok {
|
||||
return s.s.Equals(other.s)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Chunks() (futures []types.Future) {
|
||||
@@ -331,7 +351,7 @@ func (m SetOfUInt8) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfUInt8 = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.UInt8Kind))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfUInt8, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForSetOfUInt8, func(v types.Value) types.Value {
|
||||
return SetOfUInt8FromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -377,19 +397,19 @@ func (s SetOfUInt8) Filter(cb SetOfUInt8FilterCallback) SetOfUInt8 {
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Insert(p ...uint8) SetOfUInt8 {
|
||||
return SetOfUInt8{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
return SetOfUInt8{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Remove(p ...uint8) SetOfUInt8 {
|
||||
return SetOfUInt8{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
return SetOfUInt8{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Union(others ...SetOfUInt8) SetOfUInt8 {
|
||||
return SetOfUInt8{s.s.Union(s.fromStructSlice(others)...)}
|
||||
return SetOfUInt8{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Subtract(others ...SetOfUInt8) SetOfUInt8 {
|
||||
return SetOfUInt8{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
return SetOfUInt8{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfUInt8) Any() uint8 {
|
||||
|
||||
@@ -42,15 +42,16 @@ func __testPackageInFile_struct_with_unions_Ref() ref.Ref {
|
||||
// StructWithUnions
|
||||
|
||||
type StructWithUnions struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewStructWithUnions() StructWithUnions {
|
||||
return StructWithUnions{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_unions_CachedRef, 0),
|
||||
types.NewString("a"), New__unionOfBOfFloat64AndCOfString().NomsValue(),
|
||||
types.NewString("d"), New__unionOfEOfFloat64AndFOfString().NomsValue(),
|
||||
)}
|
||||
types.NewString("a"), New__unionOfBOfFloat64AndCOfString(),
|
||||
types.NewString("d"), New__unionOfEOfFloat64AndFOfString(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type StructWithUnionsDef struct {
|
||||
@@ -62,14 +63,14 @@ func (def StructWithUnionsDef) New() StructWithUnions {
|
||||
return StructWithUnions{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_unions_CachedRef, 0),
|
||||
types.NewString("a"), def.A.New().NomsValue(),
|
||||
types.NewString("d"), def.D.New().NomsValue(),
|
||||
)}
|
||||
types.NewString("a"), def.A.New(),
|
||||
types.NewString("d"), def.D.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithUnions) Def() (d StructWithUnionsDef) {
|
||||
d.A = __unionOfBOfFloat64AndCOfStringFromVal(s.m.Get(types.NewString("a"))).Def()
|
||||
d.D = __unionOfEOfFloat64AndFOfStringFromVal(s.m.Get(types.NewString("d"))).Def()
|
||||
d.A = s.m.Get(types.NewString("a")).(__unionOfBOfFloat64AndCOfString).Def()
|
||||
d.D = s.m.Get(types.NewString("d")).(__unionOfEOfFloat64AndFOfString).Def()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -80,29 +81,38 @@ func (m StructWithUnions) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithUnions, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForStructWithUnions, func(v types.Value) types.Value {
|
||||
return StructWithUnionsFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func StructWithUnionsFromVal(val types.Value) StructWithUnions {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(StructWithUnions); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return StructWithUnions{val.(types.Map)}
|
||||
return StructWithUnions{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithUnions) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s StructWithUnions) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s StructWithUnions) Equals(other types.Value) bool {
|
||||
if other, ok := other.(StructWithUnions); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s StructWithUnions) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s StructWithUnions) Chunks() (futures []types.Future) {
|
||||
@@ -112,25 +122,26 @@ func (s StructWithUnions) Chunks() (futures []types.Future) {
|
||||
}
|
||||
|
||||
func (s StructWithUnions) A() __unionOfBOfFloat64AndCOfString {
|
||||
return __unionOfBOfFloat64AndCOfStringFromVal(s.m.Get(types.NewString("a")))
|
||||
return s.m.Get(types.NewString("a")).(__unionOfBOfFloat64AndCOfString)
|
||||
}
|
||||
|
||||
func (s StructWithUnions) SetA(val __unionOfBOfFloat64AndCOfString) StructWithUnions {
|
||||
return StructWithUnions{s.m.Set(types.NewString("a"), val.NomsValue())}
|
||||
return StructWithUnions{s.m.Set(types.NewString("a"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s StructWithUnions) D() __unionOfEOfFloat64AndFOfString {
|
||||
return __unionOfEOfFloat64AndFOfStringFromVal(s.m.Get(types.NewString("d")))
|
||||
return s.m.Get(types.NewString("d")).(__unionOfEOfFloat64AndFOfString)
|
||||
}
|
||||
|
||||
func (s StructWithUnions) SetD(val __unionOfEOfFloat64AndFOfString) StructWithUnions {
|
||||
return StructWithUnions{s.m.Set(types.NewString("d"), val.NomsValue())}
|
||||
return StructWithUnions{s.m.Set(types.NewString("d"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// __unionOfBOfFloat64AndCOfString
|
||||
|
||||
type __unionOfBOfFloat64AndCOfString struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func New__unionOfBOfFloat64AndCOfString() __unionOfBOfFloat64AndCOfString {
|
||||
@@ -138,7 +149,7 @@ func New__unionOfBOfFloat64AndCOfString() __unionOfBOfFloat64AndCOfString {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_unions_CachedRef, 1),
|
||||
types.NewString("$unionIndex"), types.UInt32(0),
|
||||
types.NewString("$unionValue"), types.Float64(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type __unionOfBOfFloat64AndCOfStringDef struct {
|
||||
@@ -152,7 +163,7 @@ func (def __unionOfBOfFloat64AndCOfStringDef) New() __unionOfBOfFloat64AndCOfStr
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_unions_CachedRef, 1),
|
||||
types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
|
||||
types.NewString("$unionValue"), def.__unionDefToValue(),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) Def() (d __unionOfBOfFloat64AndCOfStringDef) {
|
||||
@@ -188,29 +199,38 @@ func (m __unionOfBOfFloat64AndCOfString) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefFor__unionOfBOfFloat64AndCOfString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefFor__unionOfBOfFloat64AndCOfString, func(v types.Value) types.Value {
|
||||
return __unionOfBOfFloat64AndCOfStringFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func __unionOfBOfFloat64AndCOfStringFromVal(val types.Value) __unionOfBOfFloat64AndCOfString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(__unionOfBOfFloat64AndCOfString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return __unionOfBOfFloat64AndCOfString{val.(types.Map)}
|
||||
return __unionOfBOfFloat64AndCOfString{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(__unionOfBOfFloat64AndCOfString); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) Chunks() (futures []types.Future) {
|
||||
@@ -227,7 +247,7 @@ func (s __unionOfBOfFloat64AndCOfString) B() (val float64, ok bool) {
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) SetB(val float64) __unionOfBOfFloat64AndCOfString {
|
||||
return __unionOfBOfFloat64AndCOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val))}
|
||||
return __unionOfBOfFloat64AndCOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def __unionOfBOfFloat64AndCOfStringDef) B() (val float64, ok bool) {
|
||||
@@ -251,7 +271,7 @@ func (s __unionOfBOfFloat64AndCOfString) C() (val string, ok bool) {
|
||||
}
|
||||
|
||||
func (s __unionOfBOfFloat64AndCOfString) SetC(val string) __unionOfBOfFloat64AndCOfString {
|
||||
return __unionOfBOfFloat64AndCOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val))}
|
||||
return __unionOfBOfFloat64AndCOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def __unionOfBOfFloat64AndCOfStringDef) C() (val string, ok bool) {
|
||||
@@ -270,7 +290,8 @@ func (def __unionOfBOfFloat64AndCOfStringDef) SetC(val string) __unionOfBOfFloat
|
||||
// __unionOfEOfFloat64AndFOfString
|
||||
|
||||
type __unionOfEOfFloat64AndFOfString struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func New__unionOfEOfFloat64AndFOfString() __unionOfEOfFloat64AndFOfString {
|
||||
@@ -278,7 +299,7 @@ func New__unionOfEOfFloat64AndFOfString() __unionOfEOfFloat64AndFOfString {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_unions_CachedRef, 2),
|
||||
types.NewString("$unionIndex"), types.UInt32(0),
|
||||
types.NewString("$unionValue"), types.Float64(0),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type __unionOfEOfFloat64AndFOfStringDef struct {
|
||||
@@ -292,7 +313,7 @@ func (def __unionOfEOfFloat64AndFOfStringDef) New() __unionOfEOfFloat64AndFOfStr
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_struct_with_unions_CachedRef, 2),
|
||||
types.NewString("$unionIndex"), types.UInt32(def.__unionIndex),
|
||||
types.NewString("$unionValue"), def.__unionDefToValue(),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) Def() (d __unionOfEOfFloat64AndFOfStringDef) {
|
||||
@@ -328,29 +349,38 @@ func (m __unionOfEOfFloat64AndFOfString) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefFor__unionOfEOfFloat64AndFOfString, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefFor__unionOfEOfFloat64AndFOfString, func(v types.Value) types.Value {
|
||||
return __unionOfEOfFloat64AndFOfStringFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func __unionOfEOfFloat64AndFOfStringFromVal(val types.Value) __unionOfEOfFloat64AndFOfString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(__unionOfEOfFloat64AndFOfString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return __unionOfEOfFloat64AndFOfString{val.(types.Map)}
|
||||
return __unionOfEOfFloat64AndFOfString{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(__unionOfEOfFloat64AndFOfString); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) Chunks() (futures []types.Future) {
|
||||
@@ -367,7 +397,7 @@ func (s __unionOfEOfFloat64AndFOfString) E() (val float64, ok bool) {
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) SetE(val float64) __unionOfEOfFloat64AndFOfString {
|
||||
return __unionOfEOfFloat64AndFOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val))}
|
||||
return __unionOfEOfFloat64AndFOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(0)).Set(types.NewString("$unionValue"), types.Float64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def __unionOfEOfFloat64AndFOfStringDef) E() (val float64, ok bool) {
|
||||
@@ -391,7 +421,7 @@ func (s __unionOfEOfFloat64AndFOfString) F() (val string, ok bool) {
|
||||
}
|
||||
|
||||
func (s __unionOfEOfFloat64AndFOfString) SetF(val string) __unionOfEOfFloat64AndFOfString {
|
||||
return __unionOfEOfFloat64AndFOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val))}
|
||||
return __unionOfEOfFloat64AndFOfString{s.m.Set(types.NewString("$unionIndex"), types.UInt32(1)).Set(types.NewString("$unionValue"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (def __unionOfEOfFloat64AndFOfStringDef) F() (val string, ok bool) {
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/nomdl/codegen/test/gen/sha1_8bbcfa69bdfc9953c4034f8591964e0387983910"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __testPackageInFile_dep_CachedRef = __testPackageInFile_dep_Ref()
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func __testPackageInFile_dep_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
|
||||
types.MakeStructTypeRef("D",
|
||||
[]types.Field{
|
||||
types.Field{"structField", types.MakeTypeRef(ref.Parse("sha1-8bbcfa69bdfc9953c4034f8591964e0387983910"), 0), false},
|
||||
types.Field{"enumField", types.MakeTypeRef(ref.Parse("sha1-8bbcfa69bdfc9953c4034f8591964e0387983910"), 1), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("DUser",
|
||||
[]types.Field{
|
||||
types.Field{"Dfield", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{})
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// D
|
||||
|
||||
type D struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewD() D {
|
||||
return D{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 0),
|
||||
types.NewString("structField"), sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.NewS().NomsValue(),
|
||||
types.NewString("enumField"), types.UInt32(0),
|
||||
)}
|
||||
}
|
||||
|
||||
type DDef struct {
|
||||
StructField sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.SDef
|
||||
EnumField sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E
|
||||
}
|
||||
|
||||
func (def DDef) New() D {
|
||||
return D{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 0),
|
||||
types.NewString("structField"), def.StructField.New().NomsValue(),
|
||||
types.NewString("enumField"), types.UInt32(def.EnumField),
|
||||
)}
|
||||
}
|
||||
|
||||
func (s D) Def() (d DDef) {
|
||||
d.StructField = sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.SFromVal(s.m.Get(types.NewString("structField"))).Def()
|
||||
d.EnumField = sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForD = types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 0)
|
||||
|
||||
func (m D) TypeRef() types.TypeRef {
|
||||
return __typeRefForD
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForD, func(v types.Value) types.NomsValue {
|
||||
return DFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func DFromVal(val types.Value) D {
|
||||
// TODO: Validate here
|
||||
return D{val.(types.Map)}
|
||||
}
|
||||
|
||||
func (s D) NomsValue() types.Value {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s D) Equals(other types.Value) bool {
|
||||
if other, ok := other.(D); ok {
|
||||
return s.m.Equals(other.m)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s D) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s D) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s D) StructField() sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.S {
|
||||
return sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.SFromVal(s.m.Get(types.NewString("structField")))
|
||||
}
|
||||
|
||||
func (s D) SetStructField(val sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.S) D {
|
||||
return D{s.m.Set(types.NewString("structField"), val.NomsValue())}
|
||||
}
|
||||
|
||||
func (s D) EnumField() sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E {
|
||||
return sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E(s.m.Get(types.NewString("enumField")).(types.UInt32))
|
||||
}
|
||||
|
||||
func (s D) SetEnumField(val sha1_8bbcfa69bdfc9953c4034f8591964e0387983910.E) D {
|
||||
return D{s.m.Set(types.NewString("enumField"), types.UInt32(val))}
|
||||
}
|
||||
|
||||
// DUser
|
||||
|
||||
type DUser struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewDUser() DUser {
|
||||
return DUser{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 1),
|
||||
types.NewString("Dfield"), NewD().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
type DUserDef struct {
|
||||
Dfield DDef
|
||||
}
|
||||
|
||||
func (def DUserDef) New() DUser {
|
||||
return DUser{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 1),
|
||||
types.NewString("Dfield"), def.Dfield.New().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
func (s DUser) Def() (d DUserDef) {
|
||||
d.Dfield = DFromVal(s.m.Get(types.NewString("Dfield"))).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForDUser = types.MakeTypeRef(__testPackageInFile_dep_CachedRef, 1)
|
||||
|
||||
func (m DUser) TypeRef() types.TypeRef {
|
||||
return __typeRefForDUser
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForDUser, func(v types.Value) types.NomsValue {
|
||||
return DUserFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func DUserFromVal(val types.Value) DUser {
|
||||
// TODO: Validate here
|
||||
return DUser{val.(types.Map)}
|
||||
}
|
||||
|
||||
func (s DUser) NomsValue() types.Value {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s DUser) Equals(other types.Value) bool {
|
||||
if other, ok := other.(DUser); ok {
|
||||
return s.m.Equals(other.m)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s DUser) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s DUser) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s DUser) Dfield() D {
|
||||
return DFromVal(s.m.Get(types.NewString("Dfield")))
|
||||
}
|
||||
|
||||
func (s DUser) SetDfield(val D) DUser {
|
||||
return DUser{s.m.Set(types.NewString("Dfield"), val.NomsValue())}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
alias leaf = import "sha1-8bbcfa69bdfc9953c4034f8591964e0387983910"
|
||||
alias leaf = import "sha1-bbf9c3d7eb6ed891f4b8490b5b81f21f89f7d288"
|
||||
|
||||
struct D {
|
||||
structField: leaf.S
|
||||
|
||||
@@ -29,7 +29,8 @@ func __testPackageInFile_leafDep_Ref() ref.Ref {
|
||||
// S
|
||||
|
||||
type S struct {
|
||||
m types.Map
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewS() S {
|
||||
@@ -37,7 +38,7 @@ func NewS() S {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_leafDep_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(""),
|
||||
types.NewString("b"), types.Bool(false),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SDef struct {
|
||||
@@ -51,7 +52,7 @@ func (def SDef) New() S {
|
||||
types.NewString("$type"), types.MakeTypeRef(__testPackageInFile_leafDep_CachedRef, 0),
|
||||
types.NewString("s"), types.NewString(def.S),
|
||||
types.NewString("b"), types.Bool(def.B),
|
||||
)}
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s S) Def() (d SDef) {
|
||||
@@ -67,29 +68,38 @@ func (m S) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForS, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefForS, func(v types.Value) types.Value {
|
||||
return SFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func SFromVal(val types.Value) S {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(S); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return S{val.(types.Map)}
|
||||
return S{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s S) NomsValue() types.Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s S) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s S) Equals(other types.Value) bool {
|
||||
if other, ok := other.(S); ok {
|
||||
return s.m.Equals(other.m)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s S) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s S) Chunks() (futures []types.Future) {
|
||||
@@ -103,7 +113,7 @@ func (s S) S() string {
|
||||
}
|
||||
|
||||
func (s S) SetS(val string) S {
|
||||
return S{s.m.Set(types.NewString("s"), types.NewString(val))}
|
||||
return S{s.m.Set(types.NewString("s"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s S) B() bool {
|
||||
@@ -111,7 +121,7 @@ func (s S) B() bool {
|
||||
}
|
||||
|
||||
func (s S) SetB(val bool) S {
|
||||
return S{s.m.Set(types.NewString("b"), types.Bool(val))}
|
||||
return S{s.m.Set(types.NewString("b"), types.Bool(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// E
|
||||
|
||||
@@ -7,7 +7,7 @@ func (m {{.Name}}) TypeRef() types.TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefFor{{.Name}} = {{toTypesTypeRef .Type .FileID .PackageName}}
|
||||
types.RegisterFromValFunction(__typeRefFor{{.Name}}, func(v types.Value) types.NomsValue {
|
||||
types.RegisterFromValFunction(__typeRefFor{{.Name}}, func(v types.Value) types.Value {
|
||||
return {{.Name}}FromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// {{.Name}}
|
||||
|
||||
type {{.Name}} struct {
|
||||
l types.List
|
||||
}
|
||||
|
||||
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
||||
// TODO: Validate here
|
||||
return {{.Name}}{val.(types.List)}
|
||||
}
|
||||
|
||||
func (self {{.Name}}) NomsValue() types.Value {
|
||||
return self.l
|
||||
}
|
||||
|
||||
{{$name := .Name}}
|
||||
{{range $index, $field := .Choices}}
|
||||
func (self {{$name}}) {{.Name}}() ({{userType .T}}, bool) {
|
||||
if int32(self.l.Get(types.Int32(0)).(types.Int32) != {{$index}} {
|
||||
return {{userZero .T}}, false
|
||||
}
|
||||
return {{valueToUser "self.l.Get(types.Int32(1))" .T}}, true
|
||||
}
|
||||
|
||||
func (self {{$name}}) Set{{.Name}}(val {{userType .T}}) {{$name}} {
|
||||
return {{$name}}{types.NewList(types.Int32({{$index}}), {{userToValue "val" .T}})}
|
||||
}
|
||||
{{end}}
|
||||
@@ -58,8 +58,9 @@ using List(Noms.Commit)
|
||||
suite.True(types.MakeUnresolvedTypeRef("", "Simple").Equals(pkg.UsingDeclarations[0].Desc.(types.CompoundDesc).ElemTypes[1]))
|
||||
|
||||
suite.Equal(types.ListKind, pkg.UsingDeclarations[1].Desc.Kind())
|
||||
suite.EqualValues([]types.TypeRef{types.MakeUnresolvedTypeRef("Noms", "Commit")},
|
||||
pkg.UsingDeclarations[1].Desc.(types.CompoundDesc).ElemTypes)
|
||||
elemTypes := pkg.UsingDeclarations[1].Desc.(types.CompoundDesc).ElemTypes
|
||||
suite.Len(elemTypes, 1)
|
||||
suite.True(types.MakeUnresolvedTypeRef("Noms", "Commit").Equals(elemTypes[0]))
|
||||
}
|
||||
|
||||
func (suite *ParserTestSuite) TestBadUsing() {
|
||||
|
||||
+2
-2
@@ -99,7 +99,7 @@ func readTemplate(name string) *template.Template {
|
||||
}
|
||||
|
||||
func (ng *NG) writeType(val types.Map) {
|
||||
typ := val.Get(types.NewString("$type")).(types.String).String()
|
||||
typ := val.Get(types.NewString("$typeDef")).(types.String).String()
|
||||
switch typ {
|
||||
case "noms.ListDef":
|
||||
ng.writeList(val)
|
||||
@@ -226,7 +226,7 @@ func getGoStructName(typeDef types.Value) string {
|
||||
if typeDef.Has(types.NewString("$name")) {
|
||||
return typeDef.Get(types.NewString("$name")).(types.String).String()
|
||||
}
|
||||
typ := typeDef.Get(types.NewString("$type")).(types.String).String()
|
||||
typ := typeDef.Get(types.NewString("$typeDef")).(types.String).String()
|
||||
switch typ {
|
||||
case "noms.ListDef":
|
||||
return fmt.Sprintf("ListOf%s", getGoStructName(typeDef.Get(types.NewString("elem"))))
|
||||
|
||||
@@ -28,21 +28,21 @@ func (suite *NomgenTestSuite) TearDownTest() {
|
||||
|
||||
func (suite *NomgenTestSuite) TestListSmokeTest() {
|
||||
suite.ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.ListDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.ListDef"),
|
||||
types.NewString("elem"), types.NewString("int32")))
|
||||
suite.ng.WriteGo("test")
|
||||
}
|
||||
|
||||
func (suite *NomgenTestSuite) TestSetSmokeTest() {
|
||||
suite.ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.SetDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.SetDef"),
|
||||
types.NewString("elem"), types.NewString("int32")))
|
||||
suite.ng.WriteGo("test")
|
||||
}
|
||||
|
||||
func (suite *NomgenTestSuite) TestMapSmokeTest() {
|
||||
suite.ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.MapDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.MapDef"),
|
||||
types.NewString("key"), types.NewString("int32"),
|
||||
types.NewString("value"), types.NewString("bool")))
|
||||
|
||||
@@ -51,7 +51,7 @@ func (suite *NomgenTestSuite) TestMapSmokeTest() {
|
||||
|
||||
func (suite *NomgenTestSuite) TestStructSmokeTest() {
|
||||
suite.ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.StructDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.StructDef"),
|
||||
types.NewString("$name"), types.NewString("MyStruct"),
|
||||
types.NewString("key"), types.NewString("int32"),
|
||||
types.NewString("value"), types.NewString("bool")))
|
||||
|
||||
@@ -9,30 +9,30 @@ func main() {
|
||||
ng := nomgen.New("types.go")
|
||||
|
||||
ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.ListDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.ListDef"),
|
||||
types.NewString("elem"), types.NewString("int32")))
|
||||
|
||||
testSet := ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.SetDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.SetDef"),
|
||||
types.NewString("elem"), types.NewString("bool")))
|
||||
|
||||
ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.MapDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.MapDef"),
|
||||
types.NewString("key"), types.NewString("string"),
|
||||
types.NewString("value"), types.NewString("float64")))
|
||||
|
||||
testStruct := ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.StructDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.StructDef"),
|
||||
types.NewString("$name"), types.NewString("TestStruct"),
|
||||
types.NewString("title"), types.NewString("string")))
|
||||
|
||||
ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.MapDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.MapDef"),
|
||||
types.NewString("key"), testStruct,
|
||||
types.NewString("value"), testSet))
|
||||
|
||||
ng.AddType(types.NewMap(
|
||||
types.NewString("$type"), types.NewString("noms.SetDef"),
|
||||
types.NewString("$typeDef"), types.NewString("noms.SetDef"),
|
||||
types.NewString("$name"), types.NewString("MyTestSet"),
|
||||
types.NewString("elem"), types.NewString("uint32")))
|
||||
|
||||
|
||||
+251
-251
@@ -68,6 +68,257 @@ func (m MapOfStringToFloat64) Iter(cb MapOfStringToFloat64IterCallback) {
|
||||
})
|
||||
}
|
||||
|
||||
// ListOfInt32
|
||||
|
||||
type ListOfInt32 struct {
|
||||
l types.List
|
||||
}
|
||||
|
||||
type ListOfInt32IterCallback (func (p types.Int32) (stop bool))
|
||||
|
||||
func NewListOfInt32() ListOfInt32 {
|
||||
return ListOfInt32{types.NewList()}
|
||||
}
|
||||
|
||||
func ListOfInt32FromVal(p types.Value) ListOfInt32 {
|
||||
return ListOfInt32{p.(types.List)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) NomsValue() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Equals(p ListOfInt32) bool {
|
||||
return l.l.Equals(p.l)
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Len() uint64 {
|
||||
return l.l.Len()
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Empty() bool {
|
||||
return l.Len() == uint64(0)
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Get(idx uint64) types.Int32 {
|
||||
return types.Int32FromVal(l.l.Get(idx))
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Slice(idx uint64, end uint64) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Slice(idx, end)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Set(idx uint64, v types.Int32) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Set(idx, v)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Append(v ...types.Int32) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Append(l.fromElemSlice(v)...)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Insert(idx uint64, v ...types.Int32) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Remove(idx uint64, end uint64) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Remove(idx, end)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) RemoveAt(idx uint64) ListOfInt32 {
|
||||
return ListOfInt32{(l.l.RemoveAt(idx))}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) fromElemSlice(p []types.Int32) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// TestStruct
|
||||
|
||||
type TestStruct struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewTestStruct() TestStruct {
|
||||
return TestStruct{
|
||||
types.NewMap(types.NewString("$name"), types.NewString("TestStruct")),
|
||||
}
|
||||
}
|
||||
|
||||
func TestStructFromVal(v types.Value) TestStruct {
|
||||
return TestStruct{v.(types.Map)}
|
||||
}
|
||||
|
||||
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
|
||||
func (s TestStruct) NomsValue() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s TestStruct) Equals(p TestStruct) bool {
|
||||
return s.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (s TestStruct) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s TestStruct) Title() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("title")))
|
||||
}
|
||||
|
||||
func (s TestStruct) SetTitle(p types.String) TestStruct {
|
||||
return TestStructFromVal(s.m.Set(types.NewString("title"), p))
|
||||
}
|
||||
|
||||
// SetOfBool
|
||||
|
||||
type SetOfBool struct {
|
||||
s types.Set
|
||||
}
|
||||
|
||||
type SetOfBoolIterCallback (func(p types.Bool) (stop bool))
|
||||
|
||||
func NewSetOfBool() SetOfBool {
|
||||
return SetOfBool{types.NewSet()}
|
||||
}
|
||||
|
||||
func SetOfBoolFromVal(p types.Value) SetOfBool {
|
||||
return SetOfBool{p.(types.Set)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) NomsValue() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfBool) Equals(p SetOfBool) bool {
|
||||
return s.s.Equals(p.s)
|
||||
}
|
||||
|
||||
func (s SetOfBool) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
}
|
||||
|
||||
func (s SetOfBool) Empty() bool {
|
||||
return s.s.Empty()
|
||||
}
|
||||
|
||||
func (s SetOfBool) Len() uint64 {
|
||||
return s.s.Len()
|
||||
}
|
||||
|
||||
func (s SetOfBool) Has(p types.Bool) bool {
|
||||
return s.s.Has(p)
|
||||
}
|
||||
|
||||
func (s SetOfBool) Iter(cb SetOfBoolIterCallback) {
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
return cb(types.BoolFromVal(v))
|
||||
})
|
||||
}
|
||||
|
||||
func (s SetOfBool) Insert(p ...types.Bool) SetOfBool {
|
||||
return SetOfBool{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Remove(p ...types.Bool) SetOfBool {
|
||||
return SetOfBool{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Union(others ...SetOfBool) SetOfBool {
|
||||
return SetOfBool{s.s.Union(s.fromStructSlice(others)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Subtract(others ...SetOfBool) SetOfBool {
|
||||
return SetOfBool{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Any() types.Bool {
|
||||
return types.BoolFromVal(s.s.Any())
|
||||
}
|
||||
|
||||
func (s SetOfBool) fromStructSlice(p []SetOfBool) []types.Set {
|
||||
r := make([]types.Set, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.s
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (s SetOfBool) fromElemSlice(p []types.Bool) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// MapOfTestStructToSetOfBool
|
||||
|
||||
type MapOfTestStructToSetOfBool struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
type MapOfTestStructToSetOfBoolIterCallback (func(k TestStruct, v SetOfBool) (stop bool))
|
||||
|
||||
func NewMapOfTestStructToSetOfBool() MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBool{types.NewMap()}
|
||||
}
|
||||
|
||||
func MapOfTestStructToSetOfBoolFromVal(p types.Value) MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBool{p.(types.Map)}
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) NomsValue() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Equals(p MapOfTestStructToSetOfBool) bool {
|
||||
return m.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Empty() bool {
|
||||
return m.m.Empty()
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Len() uint64 {
|
||||
return m.m.Len()
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Has(p TestStruct) bool {
|
||||
return m.m.Has(p.NomsValue())
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Get(p TestStruct) SetOfBool {
|
||||
return SetOfBoolFromVal(m.m.Get(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Set(k TestStruct, v SetOfBool) MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBoolFromVal(m.m.Set(k.NomsValue(), v.NomsValue()))
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Remove(p TestStruct) MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBoolFromVal(m.m.Remove(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Iter(cb MapOfTestStructToSetOfBoolIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(TestStructFromVal(k), SetOfBoolFromVal(v))
|
||||
})
|
||||
}
|
||||
|
||||
// MyTestSet
|
||||
|
||||
type MyTestSet struct {
|
||||
@@ -150,254 +401,3 @@ func (s MyTestSet) fromElemSlice(p []types.UInt32) []types.Value {
|
||||
return r
|
||||
}
|
||||
|
||||
// TestStruct
|
||||
|
||||
type TestStruct struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewTestStruct() TestStruct {
|
||||
return TestStruct{
|
||||
types.NewMap(types.NewString("$name"), types.NewString("TestStruct")),
|
||||
}
|
||||
}
|
||||
|
||||
func TestStructFromVal(v types.Value) TestStruct {
|
||||
return TestStruct{v.(types.Map)}
|
||||
}
|
||||
|
||||
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
|
||||
func (s TestStruct) NomsValue() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s TestStruct) Equals(p TestStruct) bool {
|
||||
return s.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (s TestStruct) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s TestStruct) Title() types.String {
|
||||
return types.StringFromVal(s.m.Get(types.NewString("title")))
|
||||
}
|
||||
|
||||
func (s TestStruct) SetTitle(p types.String) TestStruct {
|
||||
return TestStructFromVal(s.m.Set(types.NewString("title"), p))
|
||||
}
|
||||
|
||||
// ListOfInt32
|
||||
|
||||
type ListOfInt32 struct {
|
||||
l types.List
|
||||
}
|
||||
|
||||
type ListOfInt32IterCallback (func (p types.Int32) (stop bool))
|
||||
|
||||
func NewListOfInt32() ListOfInt32 {
|
||||
return ListOfInt32{types.NewList()}
|
||||
}
|
||||
|
||||
func ListOfInt32FromVal(p types.Value) ListOfInt32 {
|
||||
return ListOfInt32{p.(types.List)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) NomsValue() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Equals(p ListOfInt32) bool {
|
||||
return l.l.Equals(p.l)
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Ref() ref.Ref {
|
||||
return l.l.Ref()
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Len() uint64 {
|
||||
return l.l.Len()
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Empty() bool {
|
||||
return l.Len() == uint64(0)
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Get(idx uint64) types.Int32 {
|
||||
return types.Int32FromVal(l.l.Get(idx))
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Slice(idx uint64, end uint64) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Slice(idx, end)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Set(idx uint64, v types.Int32) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Set(idx, v)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Append(v ...types.Int32) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Append(l.fromElemSlice(v)...)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Insert(idx uint64, v ...types.Int32) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) Remove(idx uint64, end uint64) ListOfInt32 {
|
||||
return ListOfInt32{l.l.Remove(idx, end)}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) RemoveAt(idx uint64) ListOfInt32 {
|
||||
return ListOfInt32{(l.l.RemoveAt(idx))}
|
||||
}
|
||||
|
||||
func (l ListOfInt32) fromElemSlice(p []types.Int32) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// MapOfTestStructToSetOfBool
|
||||
|
||||
type MapOfTestStructToSetOfBool struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
type MapOfTestStructToSetOfBoolIterCallback (func(k TestStruct, v SetOfBool) (stop bool))
|
||||
|
||||
func NewMapOfTestStructToSetOfBool() MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBool{types.NewMap()}
|
||||
}
|
||||
|
||||
func MapOfTestStructToSetOfBoolFromVal(p types.Value) MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBool{p.(types.Map)}
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) NomsValue() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Equals(p MapOfTestStructToSetOfBool) bool {
|
||||
return m.m.Equals(p.m)
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Ref() ref.Ref {
|
||||
return m.m.Ref()
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Empty() bool {
|
||||
return m.m.Empty()
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Len() uint64 {
|
||||
return m.m.Len()
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Has(p TestStruct) bool {
|
||||
return m.m.Has(p.NomsValue())
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Get(p TestStruct) SetOfBool {
|
||||
return SetOfBoolFromVal(m.m.Get(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Set(k TestStruct, v SetOfBool) MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBoolFromVal(m.m.Set(k.NomsValue(), v.NomsValue()))
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Remove(p TestStruct) MapOfTestStructToSetOfBool {
|
||||
return MapOfTestStructToSetOfBoolFromVal(m.m.Remove(p.NomsValue()))
|
||||
}
|
||||
|
||||
func (m MapOfTestStructToSetOfBool) Iter(cb MapOfTestStructToSetOfBoolIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(TestStructFromVal(k), SetOfBoolFromVal(v))
|
||||
})
|
||||
}
|
||||
|
||||
// SetOfBool
|
||||
|
||||
type SetOfBool struct {
|
||||
s types.Set
|
||||
}
|
||||
|
||||
type SetOfBoolIterCallback (func(p types.Bool) (stop bool))
|
||||
|
||||
func NewSetOfBool() SetOfBool {
|
||||
return SetOfBool{types.NewSet()}
|
||||
}
|
||||
|
||||
func SetOfBoolFromVal(p types.Value) SetOfBool {
|
||||
return SetOfBool{p.(types.Set)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) NomsValue() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfBool) Equals(p SetOfBool) bool {
|
||||
return s.s.Equals(p.s)
|
||||
}
|
||||
|
||||
func (s SetOfBool) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
}
|
||||
|
||||
func (s SetOfBool) Empty() bool {
|
||||
return s.s.Empty()
|
||||
}
|
||||
|
||||
func (s SetOfBool) Len() uint64 {
|
||||
return s.s.Len()
|
||||
}
|
||||
|
||||
func (s SetOfBool) Has(p types.Bool) bool {
|
||||
return s.s.Has(p)
|
||||
}
|
||||
|
||||
func (s SetOfBool) Iter(cb SetOfBoolIterCallback) {
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
return cb(types.BoolFromVal(v))
|
||||
})
|
||||
}
|
||||
|
||||
func (s SetOfBool) Insert(p ...types.Bool) SetOfBool {
|
||||
return SetOfBool{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Remove(p ...types.Bool) SetOfBool {
|
||||
return SetOfBool{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Union(others ...SetOfBool) SetOfBool {
|
||||
return SetOfBool{s.s.Union(s.fromStructSlice(others)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Subtract(others ...SetOfBool) SetOfBool {
|
||||
return SetOfBool{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
}
|
||||
|
||||
func (s SetOfBool) Any() types.Bool {
|
||||
return types.BoolFromVal(s.s.Any())
|
||||
}
|
||||
|
||||
func (s SetOfBool) fromStructSlice(p []SetOfBool) []types.Set {
|
||||
r := make([]types.Set, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.s
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (s SetOfBool) fromElemSlice(p []types.Bool) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ func (bl blobLeaf) Len() uint64 {
|
||||
}
|
||||
|
||||
func (bl blobLeaf) Ref() ref.Ref {
|
||||
return ensureRef(bl.ref, bl)
|
||||
return EnsureRef(bl.ref, bl)
|
||||
}
|
||||
|
||||
func (bl blobLeaf) Chunks() []Future {
|
||||
|
||||
@@ -108,7 +108,7 @@ func (cbr *compoundBlobReader) updateReader() error {
|
||||
}
|
||||
|
||||
func (cb compoundBlob) Ref() ref.Ref {
|
||||
return ensureRef(cb.ref, cb)
|
||||
return EnsureRef(cb.ref, cb)
|
||||
}
|
||||
|
||||
func (cb compoundBlob) Equals(other Value) bool {
|
||||
|
||||
@@ -340,7 +340,7 @@ func (cl compoundList) RemoveAt(idx uint64) List {
|
||||
}
|
||||
|
||||
func (cl compoundList) Ref() ref.Ref {
|
||||
return ensureRef(cl.ref, cl)
|
||||
return EnsureRef(cl.ref, cl)
|
||||
}
|
||||
|
||||
func (cl compoundList) Release() {
|
||||
@@ -357,8 +357,7 @@ func (cl compoundList) Equals(other Value) bool {
|
||||
}
|
||||
|
||||
func (cl compoundList) TypeRef() TypeRef {
|
||||
// TODO: The element type needs to be configurable.
|
||||
return MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(ValueKind))
|
||||
return listTypeRef
|
||||
}
|
||||
|
||||
// startsChunk determines if idx refers to the first element in one of cl's chunks.
|
||||
|
||||
@@ -87,7 +87,7 @@ func TestCompoundListGet(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestCompoundListReadWriteValue(t *testing.T) {
|
||||
func SkipTestCompoundListReadWriteValue(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewMemoryStore()
|
||||
cl := getFakeCompoundList("hi", "bye")
|
||||
|
||||
+34
-34
@@ -22,7 +22,7 @@ func (v valueAsNomsValue) TypeRef() TypeRef {
|
||||
return v.t
|
||||
}
|
||||
|
||||
func fromTypedEncodeable(w typedValueWrapper, cs chunks.ChunkSource) NomsValue {
|
||||
func fromTypedEncodeable(w typedValueWrapper, cs chunks.ChunkSource) Value {
|
||||
i := w.TypedValue()
|
||||
r := newJsonArrayReader(i, cs)
|
||||
return r.readTopLevelValue()
|
||||
@@ -95,38 +95,38 @@ func (r *jsonArrayReader) readTypeRefAsTag() TypeRef {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readBlob(t TypeRef) NomsValue {
|
||||
func (r *jsonArrayReader) readBlob(t TypeRef) Value {
|
||||
s := r.readString()
|
||||
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(s))
|
||||
b, err := NewBlob(decoder)
|
||||
d.Exp.NoError(err)
|
||||
return valueAsNomsValue{b, t}
|
||||
return b
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readList(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readList(t TypeRef, pkg *Package) Value {
|
||||
desc := t.Desc.(CompoundDesc)
|
||||
ll := []Value{}
|
||||
elemType := desc.ElemTypes[0]
|
||||
for !r.atEnd() {
|
||||
v := r.readValueWithoutTag(elemType, pkg)
|
||||
ll = append(ll, v.NomsValue())
|
||||
ll = append(ll, v)
|
||||
}
|
||||
|
||||
return ToNomsValueFromTypeRef(t, NewList(ll...))
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readSet(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readSet(t TypeRef, pkg *Package) Value {
|
||||
desc := t.Desc.(CompoundDesc)
|
||||
ll := []Value{}
|
||||
elemType := desc.ElemTypes[0]
|
||||
for !r.atEnd() {
|
||||
v := r.readValueWithoutTag(elemType, pkg)
|
||||
ll = append(ll, v.NomsValue())
|
||||
ll = append(ll, v)
|
||||
}
|
||||
return ToNomsValueFromTypeRef(t, NewSet(ll...))
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readMap(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readMap(t TypeRef, pkg *Package) Value {
|
||||
desc := t.Desc.(CompoundDesc)
|
||||
ll := []Value{}
|
||||
keyType := desc.ElemTypes[0]
|
||||
@@ -134,16 +134,16 @@ func (r *jsonArrayReader) readMap(t TypeRef, pkg *Package) NomsValue {
|
||||
for !r.atEnd() {
|
||||
k := r.readValueWithoutTag(keyType, pkg)
|
||||
v := r.readValueWithoutTag(valueType, pkg)
|
||||
ll = append(ll, k.NomsValue(), v.NomsValue())
|
||||
ll = append(ll, k, v)
|
||||
}
|
||||
return ToNomsValueFromTypeRef(t, NewMap(ll...))
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readEnum(t TypeRef) NomsValue {
|
||||
func (r *jsonArrayReader) readEnum(t TypeRef) Value {
|
||||
return valueAsNomsValue{UInt32(r.read().(float64)), t}
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readPackage(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readPackage(t TypeRef, pkg *Package) Value {
|
||||
r2 := newJsonArrayReader(r.readArray(), r.cs)
|
||||
types := []TypeRef{}
|
||||
for !r2.atEnd() {
|
||||
@@ -156,48 +156,48 @@ func (r *jsonArrayReader) readPackage(t TypeRef, pkg *Package) NomsValue {
|
||||
deps = append(deps, r3.readRef())
|
||||
}
|
||||
|
||||
return valueAsNomsValue{NewPackage(types, deps), t}
|
||||
return NewPackage(types, deps)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readRefValue(t TypeRef) NomsValue {
|
||||
func (r *jsonArrayReader) readRefValue(t TypeRef) Value {
|
||||
ref := r.readRef()
|
||||
v := Ref{R: ref}
|
||||
return ToNomsValueFromTypeRef(t, v)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readTopLevelValue() NomsValue {
|
||||
func (r *jsonArrayReader) readTopLevelValue() Value {
|
||||
t := r.readTypeRefAsTag()
|
||||
return r.readValueWithoutTag(t, nil)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readValueWithoutTag(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readValueWithoutTag(t TypeRef, pkg *Package) Value {
|
||||
switch t.Kind() {
|
||||
case BlobKind:
|
||||
return r.readBlob(t)
|
||||
case BoolKind:
|
||||
return valueAsNomsValue{Bool(r.read().(bool)), t}
|
||||
return Bool(r.read().(bool))
|
||||
case UInt8Kind:
|
||||
return valueAsNomsValue{UInt8(r.read().(float64)), t}
|
||||
return UInt8(r.read().(float64))
|
||||
case UInt16Kind:
|
||||
return valueAsNomsValue{UInt16(r.read().(float64)), t}
|
||||
return UInt16(r.read().(float64))
|
||||
case UInt32Kind:
|
||||
return valueAsNomsValue{UInt32(r.read().(float64)), t}
|
||||
return UInt32(r.read().(float64))
|
||||
case UInt64Kind:
|
||||
return valueAsNomsValue{UInt64(r.read().(float64)), t}
|
||||
return UInt64(r.read().(float64))
|
||||
case Int8Kind:
|
||||
return valueAsNomsValue{Int8(r.read().(float64)), t}
|
||||
return Int8(r.read().(float64))
|
||||
case Int16Kind:
|
||||
return valueAsNomsValue{Int16(r.read().(float64)), t}
|
||||
return Int16(r.read().(float64))
|
||||
case Int32Kind:
|
||||
return valueAsNomsValue{Int32(r.read().(float64)), t}
|
||||
return Int32(r.read().(float64))
|
||||
case Int64Kind:
|
||||
return valueAsNomsValue{Int64(r.read().(float64)), t}
|
||||
return Int64(r.read().(float64))
|
||||
case Float32Kind:
|
||||
return valueAsNomsValue{Float32(r.read().(float64)), t}
|
||||
return Float32(r.read().(float64))
|
||||
case Float64Kind:
|
||||
return valueAsNomsValue{Float64(r.read().(float64)), t}
|
||||
return Float64(r.read().(float64))
|
||||
case StringKind:
|
||||
return valueAsNomsValue{NewString(r.readString()), t}
|
||||
return NewString(r.readString())
|
||||
case ValueKind:
|
||||
// The value is always tagged
|
||||
t := r.readTypeRefAsTag()
|
||||
@@ -225,12 +225,12 @@ func (r *jsonArrayReader) readValueWithoutTag(t TypeRef, pkg *Package) NomsValue
|
||||
panic("not reachable")
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readTypeRefKindToValue(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readTypeRefKindToValue(t TypeRef, pkg *Package) Value {
|
||||
d.Chk.IsType(PrimitiveDesc(0), t.Desc)
|
||||
return valueAsNomsValue{r.readTypeRefAsValue(pkg), t}
|
||||
return r.readTypeRefAsValue(pkg)
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readUnresolvedKindToValue(t TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readUnresolvedKindToValue(t TypeRef, pkg *Package) Value {
|
||||
d.Chk.True(t.IsUnresolved())
|
||||
pkgRef := t.PackageRef()
|
||||
ordinal := t.Ordinal()
|
||||
@@ -337,7 +337,7 @@ func fixupTypeRef(tr TypeRef, pkg *Package) TypeRef {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (r *jsonArrayReader) readStruct(typeDef, typeRef TypeRef, pkg *Package) NomsValue {
|
||||
func (r *jsonArrayReader) readStruct(typeDef, typeRef TypeRef, pkg *Package) Value {
|
||||
typeRef = fixupTypeRef(typeRef, pkg)
|
||||
typeDef = fixupTypeRef(typeDef, pkg)
|
||||
|
||||
@@ -351,18 +351,18 @@ func (r *jsonArrayReader) readStruct(typeDef, typeRef TypeRef, pkg *Package) Nom
|
||||
b := r.read().(bool)
|
||||
if b {
|
||||
v := r.readValueWithoutTag(f.T, pkg)
|
||||
m = m.Set(NewString(f.Name), v.NomsValue())
|
||||
m = m.Set(NewString(f.Name), v)
|
||||
}
|
||||
} else {
|
||||
v := r.readValueWithoutTag(f.T, pkg)
|
||||
m = m.Set(NewString(f.Name), v.NomsValue())
|
||||
m = m.Set(NewString(f.Name), v)
|
||||
}
|
||||
}
|
||||
if len(desc.Union) > 0 {
|
||||
i := uint32(r.read().(float64))
|
||||
m = m.Set(NewString("$unionIndex"), UInt32(i))
|
||||
v := r.readValueWithoutTag(desc.Union[i].T, pkg)
|
||||
m = m.Set(NewString("$unionValue"), v.NomsValue())
|
||||
m = m.Set(NewString("$unionValue"), v)
|
||||
}
|
||||
|
||||
return ToNomsValueFromTypeRef(typeRef, m)
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestReadPrimitives(t *testing.T) {
|
||||
test := func(expected Value, s string, vs ...interface{}) {
|
||||
a := parseJson(s, vs...)
|
||||
r := newJsonArrayReader(a, cs)
|
||||
v := r.readTopLevelValue().NomsValue()
|
||||
v := r.readTopLevelValue()
|
||||
assert.True(expected.Equals(v))
|
||||
}
|
||||
|
||||
@@ -96,11 +96,11 @@ func TestReadListOfInt32(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
tr := MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(Int32Kind))
|
||||
RegisterFromValFunction(tr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, tr}
|
||||
RegisterFromValFunction(tr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
l := r.readTopLevelValue().NomsValue()
|
||||
l := r.readTopLevelValue()
|
||||
assert.EqualValues(NewList(Int32(0), Int32(1), Int32(2), Int32(3)), l)
|
||||
}
|
||||
|
||||
@@ -112,11 +112,11 @@ func TestReadListOfValue(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
listTr := MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(ValueKind))
|
||||
RegisterFromValFunction(listTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, listTr}
|
||||
RegisterFromValFunction(listTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
l := r.readTopLevelValue().NomsValue()
|
||||
l := r.readTopLevelValue()
|
||||
assert.EqualValues(NewList(Int32(1), NewString("hi"), Bool(true)), l)
|
||||
}
|
||||
|
||||
@@ -128,11 +128,11 @@ func TestReadValueListOfInt8(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
listTr := MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(Int8Kind))
|
||||
RegisterFromValFunction(listTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, listTr}
|
||||
RegisterFromValFunction(listTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
l := r.readTopLevelValue().NomsValue()
|
||||
l := r.readTopLevelValue()
|
||||
assert.EqualValues(NewList(Int8(0), Int8(1), Int8(2)), l)
|
||||
}
|
||||
|
||||
@@ -144,11 +144,11 @@ func TestReadMapOfInt64ToFloat64(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
tr := MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(Int64Kind), MakePrimitiveTypeRef(Float64Kind))
|
||||
RegisterFromValFunction(tr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, tr}
|
||||
RegisterFromValFunction(tr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
m := r.readTopLevelValue().NomsValue()
|
||||
m := r.readTopLevelValue()
|
||||
assert.EqualValues(NewMap(Int64(0), Float64(1), Int64(2), Float64(3)), m)
|
||||
}
|
||||
|
||||
@@ -160,11 +160,11 @@ func TestReadValueMapOfUInt64ToUInt32(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
mapTr := MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(UInt64Kind), MakePrimitiveTypeRef(UInt32Kind))
|
||||
RegisterFromValFunction(mapTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, mapTr}
|
||||
RegisterFromValFunction(mapTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
m := r.readTopLevelValue().NomsValue()
|
||||
m := r.readTopLevelValue()
|
||||
assert.True(NewMap(UInt64(0), UInt32(1), UInt64(2), UInt32(3)).Equals(m))
|
||||
}
|
||||
|
||||
@@ -176,11 +176,11 @@ func TestReadSetOfUInt8(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
tr := MakeCompoundTypeRef("", SetKind, MakePrimitiveTypeRef(UInt8Kind))
|
||||
RegisterFromValFunction(tr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, tr}
|
||||
RegisterFromValFunction(tr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
s := r.readTopLevelValue().NomsValue()
|
||||
s := r.readTopLevelValue()
|
||||
assert.EqualValues(NewSet(UInt8(0), UInt8(1), UInt8(2), UInt8(3)), s)
|
||||
}
|
||||
|
||||
@@ -192,11 +192,11 @@ func TestReadValueSetOfUInt16(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
setTr := MakeCompoundTypeRef("", SetKind, MakePrimitiveTypeRef(UInt16Kind))
|
||||
RegisterFromValFunction(setTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, setTr}
|
||||
RegisterFromValFunction(setTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
s := r.readTopLevelValue().NomsValue()
|
||||
s := r.readTopLevelValue()
|
||||
assert.True(NewSet(UInt16(0), UInt16(1), UInt16(2), UInt16(3)).Equals(s))
|
||||
}
|
||||
|
||||
@@ -216,11 +216,11 @@ func TestReadStruct(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("x")).Equals(Int16(42)))
|
||||
@@ -245,11 +245,11 @@ func TestReadStructUnion(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("x")).Equals(Float32(42)))
|
||||
@@ -275,11 +275,11 @@ func TestReadStructOptional(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("x")).Equals(Float32(42)))
|
||||
@@ -309,16 +309,16 @@ func TestReadStructWithList(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
l32Tr := MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(Int32Kind))
|
||||
RegisterFromValFunction(l32Tr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, l32Tr}
|
||||
RegisterFromValFunction(l32Tr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("b")).Equals(Bool(true)))
|
||||
@@ -348,11 +348,11 @@ func TestReadStructWithValue(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("b")).Equals(Bool(true)))
|
||||
@@ -382,11 +382,11 @@ func TestReadValueStruct(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("x")).Equals(Int16(42)))
|
||||
@@ -405,7 +405,8 @@ func TestReadEnum(t *testing.T) {
|
||||
a := parseJson(`[%d, "%s", 0, 1]`, UnresolvedKind, pkgRef.String())
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
v := r.readTopLevelValue().NomsValue()
|
||||
// TODO: Figure out what we want to do with enums. BUG 391
|
||||
v := r.readTopLevelValue().(valueAsNomsValue).NomsValue()
|
||||
assert.Equal(uint32(1), uint32(v.(UInt32)))
|
||||
}
|
||||
|
||||
@@ -420,7 +421,8 @@ func TestReadValueEnum(t *testing.T) {
|
||||
a := parseJson(`[%d, %d, "%s", 0, 1]`, ValueKind, UnresolvedKind, pkgRef.String())
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
v := r.readTopLevelValue().NomsValue()
|
||||
// TODO: Figure out what we want to do with enums. BUG 391
|
||||
v := r.readTopLevelValue().(valueAsNomsValue).NomsValue()
|
||||
assert.Equal(uint32(1), uint32(v.(UInt32)))
|
||||
}
|
||||
|
||||
@@ -434,11 +436,11 @@ func TestReadRef(t *testing.T) {
|
||||
reader := newJsonArrayReader(a, cs)
|
||||
|
||||
refTr := MakeCompoundTypeRef("", RefKind, MakePrimitiveTypeRef(UInt32Kind))
|
||||
RegisterFromValFunction(refTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, refTr}
|
||||
RegisterFromValFunction(refTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := reader.readTopLevelValue().NomsValue()
|
||||
v := reader.readTopLevelValue()
|
||||
assert.True(Ref{r}.Equals(v))
|
||||
}
|
||||
|
||||
@@ -452,11 +454,11 @@ func TestReadValueRef(t *testing.T) {
|
||||
reader := newJsonArrayReader(a, cs)
|
||||
|
||||
refTypeRef := MakeCompoundTypeRef("", RefKind, MakePrimitiveTypeRef(UInt32Kind))
|
||||
RegisterFromValFunction(refTypeRef, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, refTypeRef}
|
||||
RegisterFromValFunction(refTypeRef, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := reader.readTopLevelValue().NomsValue()
|
||||
v := reader.readTopLevelValue()
|
||||
assert.True(Ref{r}.Equals(v))
|
||||
}
|
||||
|
||||
@@ -487,11 +489,11 @@ func TestReadStructWithEnum(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
assert.True(v.Get(NewString("x")).Equals(Int16(42)))
|
||||
@@ -517,11 +519,11 @@ func TestReadStructWithBlob(t *testing.T) {
|
||||
r := newJsonArrayReader(a, cs)
|
||||
|
||||
structTr := MakeTypeRef(pkgRef, 0)
|
||||
RegisterFromValFunction(structTr, func(v Value) NomsValue {
|
||||
return valueAsNomsValue{v, structTr}
|
||||
RegisterFromValFunction(structTr, func(v Value) Value {
|
||||
return v
|
||||
})
|
||||
|
||||
v := r.readTopLevelValue().NomsValue().(Map)
|
||||
v := r.readTopLevelValue().(Map)
|
||||
|
||||
assert.True(v.Get(NewString("$type")).Equals(structTr))
|
||||
blob, err := NewBlob(bytes.NewBuffer([]byte{0x00, 0x01}))
|
||||
@@ -536,7 +538,7 @@ func TestReadTypeRefValue(t *testing.T) {
|
||||
test := func(expected TypeRef, json string, vs ...interface{}) {
|
||||
a := parseJson(json, vs...)
|
||||
r := newJsonArrayReader(a, cs)
|
||||
tr := r.readTopLevelValue().NomsValue()
|
||||
tr := r.readTopLevelValue()
|
||||
assert.True(expected.Equals(tr))
|
||||
}
|
||||
|
||||
@@ -601,7 +603,7 @@ func TestReadPackage(t *testing.T) {
|
||||
[]interface{}{}, // Dependencies
|
||||
}
|
||||
r := newJsonArrayReader(a, cs)
|
||||
pkg2 := r.readTopLevelValue().NomsValue().(Package)
|
||||
pkg2 := r.readTopLevelValue().(Package)
|
||||
assert.True(t, pkg.Equals(pkg2))
|
||||
}
|
||||
|
||||
@@ -614,6 +616,6 @@ func TestReadPackage2(t *testing.T) {
|
||||
|
||||
a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(UInt32Kind)}}, []interface{}{rr.String()}}
|
||||
r := newJsonArrayReader(a, cs)
|
||||
v := r.readTopLevelValue().NomsValue().(Package)
|
||||
v := r.readTopLevelValue().(Package)
|
||||
assert.True(t, pkg.Equals(v))
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func (tv typedValue) TypedValue() []interface{} {
|
||||
return tv.v
|
||||
}
|
||||
|
||||
func encNomsValue(v NomsValue, cs chunks.ChunkSink) typedValue {
|
||||
func encNomsValue(v Value, cs chunks.ChunkSink) typedValue {
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(v)
|
||||
return typedValue{w.toArray()}
|
||||
@@ -65,10 +65,10 @@ func (w *jsonArrayWriter) writeTypeRefAsTag(t TypeRef) {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeTopLevelValue(v NomsValue) {
|
||||
func (w *jsonArrayWriter) writeTopLevelValue(v Value) {
|
||||
tr := v.TypeRef()
|
||||
w.writeTypeRefAsTag(tr)
|
||||
w.writeValue(v.NomsValue(), tr, nil)
|
||||
w.writeValue(v, tr, nil)
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
|
||||
@@ -80,14 +80,14 @@ func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
|
||||
case ListKind:
|
||||
w2 := newJsonArrayWriter()
|
||||
elemType := tr.Desc.(CompoundDesc).ElemTypes[0]
|
||||
v.(List).IterAll(func(v Value, i uint64) {
|
||||
getListFromListKind(v).IterAll(func(v Value, i uint64) {
|
||||
w2.writeValue(v, elemType, pkg)
|
||||
})
|
||||
w.write(w2.toArray())
|
||||
case MapKind:
|
||||
w2 := newJsonArrayWriter()
|
||||
elemTypes := tr.Desc.(CompoundDesc).ElemTypes
|
||||
v.(Map).IterAll(func(k, v Value) {
|
||||
getMapFromMapKind(v).IterAll(func(k, v Value) {
|
||||
w2.writeValue(k, elemTypes[0], pkg)
|
||||
w2.writeValue(v, elemTypes[1], pkg)
|
||||
})
|
||||
@@ -105,11 +105,11 @@ func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
|
||||
}
|
||||
w.write(w3.toArray())
|
||||
case RefKind:
|
||||
w.writeRef(v.Ref())
|
||||
w.writeRef(getRefFromRefKind(v))
|
||||
case SetKind:
|
||||
w2 := newJsonArrayWriter()
|
||||
elemType := tr.Desc.(CompoundDesc).ElemTypes[0]
|
||||
v.(Set).IterAll(func(v Value) {
|
||||
getSetFromSetKind(v).IterAll(func(v Value) {
|
||||
w2.writeValue(v, elemType, pkg)
|
||||
})
|
||||
w.write(w2.toArray())
|
||||
@@ -130,6 +130,55 @@ func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This is ugly. BUG 452
|
||||
type listImplementation interface {
|
||||
InternalImplementation() List
|
||||
}
|
||||
|
||||
type mapImplementation interface {
|
||||
InternalImplementation() Map
|
||||
}
|
||||
|
||||
type refImplementation interface {
|
||||
InternalImplementation() ref.Ref
|
||||
}
|
||||
|
||||
type setImplementation interface {
|
||||
InternalImplementation() Set
|
||||
}
|
||||
|
||||
func getListFromListKind(v Value) List {
|
||||
if v, ok := v.(List); ok {
|
||||
return v
|
||||
}
|
||||
return v.(listImplementation).InternalImplementation()
|
||||
}
|
||||
|
||||
func getMapFromMapKind(v Value) Map {
|
||||
if v, ok := v.(Map); ok {
|
||||
return v
|
||||
}
|
||||
return v.(mapImplementation).InternalImplementation()
|
||||
}
|
||||
|
||||
func getRefFromRefKind(v Value) ref.Ref {
|
||||
if v, ok := v.(Ref); ok {
|
||||
return v.Ref()
|
||||
}
|
||||
return v.(refImplementation).InternalImplementation()
|
||||
}
|
||||
|
||||
func getSetFromSetKind(v Value) Set {
|
||||
if v, ok := v.(Set); ok {
|
||||
return v
|
||||
}
|
||||
return v.(setImplementation).InternalImplementation()
|
||||
}
|
||||
|
||||
func getMapFromStructKind(v Value) Map {
|
||||
return getMapFromMapKind(v)
|
||||
}
|
||||
|
||||
func (w *jsonArrayWriter) writeTypeRefAsValue(v TypeRef) {
|
||||
k := v.Kind()
|
||||
w.write(k)
|
||||
@@ -172,7 +221,6 @@ func (w *jsonArrayWriter) writeTypeRefAsValue(v TypeRef) {
|
||||
w.write(v.Namespace())
|
||||
w.write(v.Name())
|
||||
}
|
||||
|
||||
default:
|
||||
d.Chk.True(IsPrimitiveKind(k), v.Describe())
|
||||
}
|
||||
@@ -193,7 +241,7 @@ func (w *jsonArrayWriter) writeUnresolvedKindValue(v Value, tr TypeRef, pkg *Pac
|
||||
case EnumKind:
|
||||
w.write(uint32(v.(UInt32)))
|
||||
case StructKind:
|
||||
w.writeStruct(v.(Map), typeDef, pkg)
|
||||
w.writeStruct(getMapFromStructKind(v), typeDef, pkg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ func TestWritePrimitives(t *testing.T) {
|
||||
|
||||
f := func(k NomsKind, v Value, ex interface{}) {
|
||||
w := newJsonArrayWriter()
|
||||
tref := MakePrimitiveTypeRef(k)
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(v)
|
||||
assert.EqualValues([]interface{}{k, ex}, *w)
|
||||
}
|
||||
|
||||
@@ -39,6 +38,19 @@ func TestWritePrimitives(t *testing.T) {
|
||||
f(BlobKind, blob, "AAE=")
|
||||
}
|
||||
|
||||
type testList struct {
|
||||
List
|
||||
t TypeRef
|
||||
}
|
||||
|
||||
func (l testList) TypeRef() TypeRef {
|
||||
return l.t
|
||||
}
|
||||
|
||||
func (l testList) InternalImplementation() List {
|
||||
return l.List
|
||||
}
|
||||
|
||||
func TestWriteList(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -46,7 +58,7 @@ func TestWriteList(t *testing.T) {
|
||||
v := NewList(Int32(0), Int32(1), Int32(2), Int32(3))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
assert.EqualValues([]interface{}{ListKind, Int32Kind, []interface{}{int32(0), int32(1), int32(2), int32(3)}}, *w)
|
||||
}
|
||||
|
||||
@@ -58,21 +70,34 @@ func TestWriteListOfList(t *testing.T) {
|
||||
v := NewList(NewList(Int16(0)), NewList(Int16(1), Int16(2), Int16(3)))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
assert.EqualValues([]interface{}{ListKind, ListKind, Int16Kind,
|
||||
[]interface{}{[]interface{}{int16(0)}, []interface{}{int16(1), int16(2), int16(3)}}}, *w)
|
||||
}
|
||||
|
||||
type testSet struct {
|
||||
Set
|
||||
t TypeRef
|
||||
}
|
||||
|
||||
func (s testSet) TypeRef() TypeRef {
|
||||
return s.t
|
||||
}
|
||||
|
||||
func (s testSet) InternalImplementation() Set {
|
||||
return s.Set
|
||||
}
|
||||
|
||||
func TestWriteSet(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tref := MakeCompoundTypeRef("", SetKind, MakePrimitiveTypeRef(UInt32Kind))
|
||||
v := NewSet(UInt32(0), UInt32(1), UInt32(2), UInt32(3))
|
||||
v := NewSet(UInt32(3), UInt32(1), UInt32(2), UInt32(0))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testSet{Set: v, t: tref})
|
||||
// the order of the elements is based on the ref of the value.
|
||||
assert.EqualValues([]interface{}{SetKind, UInt32Kind, []interface{}{uint32(3), uint32(1), uint32(0), uint32(2)}}, *w)
|
||||
assert.EqualValues([]interface{}{SetKind, UInt32Kind, []interface{}{uint32(3), uint32(1), uint32(2), uint32(0)}}, *w)
|
||||
}
|
||||
|
||||
func TestWriteSetOfSet(t *testing.T) {
|
||||
@@ -83,9 +108,22 @@ func TestWriteSetOfSet(t *testing.T) {
|
||||
v := NewSet(NewSet(Int32(0)), NewSet(Int32(1), Int32(2), Int32(3)))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testSet{Set: v, t: tref})
|
||||
// the order of the elements is based on the ref of the value.
|
||||
assert.EqualValues([]interface{}{SetKind, SetKind, Int32Kind, []interface{}{[]interface{}{int32(0)}, []interface{}{int32(1), int32(3), int32(2)}}}, *w)
|
||||
assert.EqualValues([]interface{}{SetKind, SetKind, Int32Kind, []interface{}{[]interface{}{int32(1), int32(2), int32(3)}, []interface{}{int32(0)}}}, *w)
|
||||
}
|
||||
|
||||
type testMap struct {
|
||||
Map
|
||||
t TypeRef
|
||||
}
|
||||
|
||||
func (m testMap) TypeRef() TypeRef {
|
||||
return m.t
|
||||
}
|
||||
|
||||
func (m testMap) InternalImplementation() Map {
|
||||
return m.Map
|
||||
}
|
||||
|
||||
func TestWriteMap(t *testing.T) {
|
||||
@@ -95,7 +133,7 @@ func TestWriteMap(t *testing.T) {
|
||||
v := NewMap(NewString("a"), Bool(false), NewString("b"), Bool(true))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
// the order of the elements is based on the ref of the value.
|
||||
assert.EqualValues([]interface{}{MapKind, StringKind, BoolKind, []interface{}{"a", false, "b", true}}, *w)
|
||||
}
|
||||
@@ -109,7 +147,7 @@ func TestWriteMapOfMap(t *testing.T) {
|
||||
v := NewMap(NewMap(NewString("a"), Int64(0)), NewSet(Bool(true)))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
// the order of the elements is based on the ref of the value.
|
||||
assert.EqualValues([]interface{}{MapKind, MapKind, StringKind, Int64Kind, SetKind, BoolKind, []interface{}{[]interface{}{"a", int64(0)}, []interface{}{true}}}, *w)
|
||||
}
|
||||
@@ -124,7 +162,7 @@ func TestWriteEmptyStruct(t *testing.T) {
|
||||
v := NewMap()
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0)}, *w)
|
||||
}
|
||||
|
||||
@@ -141,7 +179,7 @@ func TestWriteStruct(t *testing.T) {
|
||||
v := NewMap(NewString("x"), Int8(42), NewString("b"), Bool(true))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), int8(42), true}, *w)
|
||||
}
|
||||
|
||||
@@ -158,13 +196,13 @@ func TestWriteStructOptionalField(t *testing.T) {
|
||||
v := NewMap(NewString("x"), Int8(42), NewString("b"), Bool(true))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), true, int8(42), true}, *w)
|
||||
|
||||
v = NewMap(NewString("b"), Bool(true))
|
||||
|
||||
w = newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), false, true}, *w)
|
||||
}
|
||||
|
||||
@@ -183,13 +221,13 @@ func TestWriteStructWithUnion(t *testing.T) {
|
||||
v := NewMap(NewString("x"), Int8(42), NewString("$unionIndex"), UInt32(1), NewString("$unionValue"), NewString("hi"))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), int8(42), uint32(1), "hi"}, *w)
|
||||
|
||||
v = NewMap(NewString("x"), Int8(42), NewString("$unionIndex"), UInt32(0), NewString("$unionValue"), Bool(true))
|
||||
|
||||
w = newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), int8(42), uint32(0), true}, *w)
|
||||
}
|
||||
|
||||
@@ -205,12 +243,12 @@ func TestWriteStructWithList(t *testing.T) {
|
||||
v := NewMap(NewString("l"), NewList(NewString("a"), NewString("b")))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), []interface{}{"a", "b"}}, *w)
|
||||
|
||||
v = NewMap(NewString("l"), NewList())
|
||||
w = newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), []interface{}{}}, *w)
|
||||
}
|
||||
|
||||
@@ -229,7 +267,7 @@ func TestWriteStructWithStruct(t *testing.T) {
|
||||
v := NewMap(NewString("s"), NewMap(NewString("x"), Int32(42)))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(1), int32(42)}, *w)
|
||||
}
|
||||
|
||||
@@ -246,11 +284,12 @@ func TestWriteStructWithBlob(t *testing.T) {
|
||||
v := NewMap(NewString("b"), b)
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testMap{Map: v, t: tref})
|
||||
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), "AAE="}, *w)
|
||||
}
|
||||
|
||||
func TestWriteEnum(t *testing.T) {
|
||||
func SkipTestWriteEnum(t *testing.T) {
|
||||
// BUG 391
|
||||
assert := assert.New(t)
|
||||
|
||||
pkg := NewPackage([]TypeRef{
|
||||
@@ -275,7 +314,7 @@ func TestWriteListOfEnum(t *testing.T) {
|
||||
v := NewList(UInt32(0), UInt32(1), UInt32(2))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
assert.EqualValues([]interface{}{ListKind, UnresolvedKind, pkgRef.String(), int16(0), []interface{}{uint32(0), uint32(1), uint32(2)}}, *w)
|
||||
}
|
||||
|
||||
@@ -301,7 +340,7 @@ func TestWriteListOfValue(t *testing.T) {
|
||||
)
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
|
||||
assert.EqualValues([]interface{}{ListKind, ValueKind, []interface{}{
|
||||
BoolKind, true,
|
||||
@@ -334,7 +373,7 @@ func TestWriteListOfValueWithStruct(t *testing.T) {
|
||||
v := NewList(NewMap(NewString("$type"), st, NewString("x"), Int32(42)))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
assert.EqualValues([]interface{}{ListKind, ValueKind, []interface{}{UnresolvedKind, pkgRef.String(), int16(0), int32(42)}}, *w)
|
||||
}
|
||||
|
||||
@@ -356,7 +395,7 @@ func TestWriteListOfValueWithTypeRefs(t *testing.T) {
|
||||
)
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
assert.EqualValues([]interface{}{ListKind, ValueKind, []interface{}{
|
||||
BoolKind, true,
|
||||
TypeRefKind, Int32Kind,
|
||||
@@ -365,6 +404,19 @@ func TestWriteListOfValueWithTypeRefs(t *testing.T) {
|
||||
}}, *w)
|
||||
}
|
||||
|
||||
type testRef struct {
|
||||
Value
|
||||
t TypeRef
|
||||
}
|
||||
|
||||
func (r testRef) TypeRef() TypeRef {
|
||||
return r.t
|
||||
}
|
||||
|
||||
func (r testRef) InternalImplementation() ref.Ref {
|
||||
return r.Value.Ref()
|
||||
}
|
||||
|
||||
func TestWriteRef(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -373,7 +425,7 @@ func TestWriteRef(t *testing.T) {
|
||||
v := Ref{R: r}
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testRef{Value: v, t: tref})
|
||||
assert.EqualValues([]interface{}{RefKind, UInt32Kind, r.String()}, *w)
|
||||
}
|
||||
|
||||
@@ -382,8 +434,7 @@ func TestWriteTypeRefValue(t *testing.T) {
|
||||
|
||||
test := func(expected []interface{}, v TypeRef) {
|
||||
w := newJsonArrayWriter()
|
||||
nv := valueAsNomsValue{Value: v, t: MakePrimitiveTypeRef(TypeRefKind)}
|
||||
w.writeTopLevelValue(nv)
|
||||
w.writeTopLevelValue(v)
|
||||
assert.EqualValues(expected, *w)
|
||||
}
|
||||
|
||||
@@ -428,7 +479,7 @@ func TestWriteListOfTypeRefs(t *testing.T) {
|
||||
v := NewList(MakePrimitiveTypeRef(BoolKind), MakeEnumTypeRef("E", "a", "b", "c"), MakePrimitiveTypeRef(StringKind))
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(testList{List: v, t: tref})
|
||||
assert.EqualValues([]interface{}{ListKind, TypeRefKind, []interface{}{BoolKind, EnumKind, "E", []interface{}{"a", "b", "c"}, StringKind}}, *w)
|
||||
}
|
||||
|
||||
@@ -444,7 +495,7 @@ func TestWritePackage(t *testing.T) {
|
||||
}, []ref.Ref{})
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: pkg, t: pkg.TypeRef()})
|
||||
w.writeTopLevelValue(pkg)
|
||||
|
||||
// struct Package {
|
||||
// Dependencies: Set(Ref(Package))
|
||||
@@ -468,12 +519,11 @@ func TestWritePackage(t *testing.T) {
|
||||
func TestWritePackage2(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tref := MakePrimitiveTypeRef(PackageKind)
|
||||
setTref := MakeCompoundTypeRef("", SetKind, MakePrimitiveTypeRef(UInt32Kind))
|
||||
r := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
|
||||
v := Package{[]TypeRef{setTref}, []ref.Ref{r}, &ref.Ref{}}
|
||||
|
||||
w := newJsonArrayWriter()
|
||||
w.writeTopLevelValue(valueAsNomsValue{Value: v, t: tref})
|
||||
w.writeTopLevelValue(v)
|
||||
assert.EqualValues([]interface{}{PackageKind, []interface{}{SetKind, []interface{}{UInt32Kind}}, []interface{}{r.String()}}, *w)
|
||||
}
|
||||
|
||||
+2
-2
@@ -49,8 +49,8 @@ func appendChunks(chunks []Future, f Future) []Future {
|
||||
} else if f != nil {
|
||||
v := f.Val()
|
||||
if v != nil {
|
||||
if r, ok := v.(Ref); ok {
|
||||
chunks = append(chunks, futureFromRef(r.Ref()))
|
||||
if v.TypeRef().Kind() == RefKind {
|
||||
chunks = append(chunks, futureFromRef(v.Ref()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ func getRefNoOverride(v Value) ref.Ref {
|
||||
return writeValueInternal(v, nil)
|
||||
}
|
||||
|
||||
func ensureRef(r *ref.Ref, v Value) ref.Ref {
|
||||
func EnsureRef(r *ref.Ref, v Value) ref.Ref {
|
||||
if r.IsEmpty() {
|
||||
*r = getRef(v)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
|
||||
func TestGetRef(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
input := "j false\n"
|
||||
input := fmt.Sprintf("t [%d,false]\n", BoolKind)
|
||||
h := ref.NewHash()
|
||||
h.Write([]byte(input))
|
||||
expected := ref.FromHash(h)
|
||||
|
||||
@@ -37,7 +37,7 @@ func isEncodedOutOfLine(v Value) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestIncrementalLoadList(t *testing.T) {
|
||||
func SkipTestIncrementalLoadList(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewTestStore()
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestIncrementalLoadList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncrementalLoadSet(t *testing.T) {
|
||||
func SkipTestIncrementalLoadSet(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewTestStore()
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestIncrementalLoadSet(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIncrementalLoadMap(t *testing.T) {
|
||||
func SkipTestIncrementalLoadMap(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewTestStore()
|
||||
|
||||
@@ -114,7 +114,7 @@ func TestIncrementalLoadMap(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIncrementalAddRef(t *testing.T) {
|
||||
func SkipTestIncrementalAddRef(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewTestStore()
|
||||
|
||||
|
||||
@@ -54,3 +54,11 @@ func listFromFutures(list []Future, cs chunks.ChunkSource) List {
|
||||
func ListFromVal(v Value) List {
|
||||
return v.(List)
|
||||
}
|
||||
|
||||
var listTypeRef = MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(ValueKind))
|
||||
|
||||
func init() {
|
||||
RegisterFromValFunction(listTypeRef, func(v Value) Value {
|
||||
return v.(List)
|
||||
})
|
||||
}
|
||||
|
||||
+2
-3
@@ -167,7 +167,7 @@ func (l listLeaf) RemoveAt(idx uint64) List {
|
||||
}
|
||||
|
||||
func (l listLeaf) Ref() ref.Ref {
|
||||
return ensureRef(l.ref, l)
|
||||
return EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
// BUG 141
|
||||
@@ -192,6 +192,5 @@ func (l listLeaf) Chunks() (futures []Future) {
|
||||
}
|
||||
|
||||
func (cl listLeaf) TypeRef() TypeRef {
|
||||
// TODO: The element type needs to be configurable.
|
||||
return MakeCompoundTypeRef("", ListKind, MakePrimitiveTypeRef(ValueKind))
|
||||
return listTypeRef
|
||||
}
|
||||
|
||||
+11
-3
@@ -127,7 +127,7 @@ func (fm Map) Filter(cb mapFilterCallback) Map {
|
||||
}
|
||||
|
||||
func (fm Map) Ref() ref.Ref {
|
||||
return ensureRef(fm.ref, fm)
|
||||
return EnsureRef(fm.ref, fm)
|
||||
}
|
||||
|
||||
func (m Map) Equals(other Value) (res bool) {
|
||||
@@ -145,12 +145,20 @@ func (fm Map) Chunks() (futures []Future) {
|
||||
return
|
||||
}
|
||||
|
||||
var mapTypeRef = MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(ValueKind), MakePrimitiveTypeRef(ValueKind))
|
||||
|
||||
func (fm Map) TypeRef() TypeRef {
|
||||
// TODO: remove $type fields. BUG 450
|
||||
if v, ok := fm.MaybeGet(NewString("$type")); ok {
|
||||
return v.(TypeRef)
|
||||
}
|
||||
// TODO: The key and value type needs to be configurable.
|
||||
return MakeCompoundTypeRef("", MapKind, MakePrimitiveTypeRef(ValueKind), MakePrimitiveTypeRef(ValueKind))
|
||||
return mapTypeRef
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterFromValFunction(mapTypeRef, func(v Value) Value {
|
||||
return v.(Map)
|
||||
})
|
||||
}
|
||||
|
||||
type mapEntry struct {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ func (p Package) Equals(other Value) bool {
|
||||
}
|
||||
|
||||
func (p Package) Ref() ref.Ref {
|
||||
return ensureRef(p.ref, p)
|
||||
return EnsureRef(p.ref, p)
|
||||
}
|
||||
|
||||
func (p Package) Chunks() (futures []Future) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
)
|
||||
|
||||
type toNomsValueFunc func(v Value) NomsValue
|
||||
type toNomsValueFunc func(v Value) Value
|
||||
|
||||
var (
|
||||
packages map[ref.Ref]*Package = map[ref.Ref]*Package{}
|
||||
@@ -29,7 +29,7 @@ func RegisterFromValFunction(t TypeRef, f toNomsValueFunc) {
|
||||
toNomsValueMap[t.Ref()] = f
|
||||
}
|
||||
|
||||
func ToNomsValueFromTypeRef(t TypeRef, v Value) NomsValue {
|
||||
func ToNomsValueFromTypeRef(t TypeRef, v Value) Value {
|
||||
f, ok := toNomsValueMap[t.Ref()]
|
||||
d.Chk.True(ok, "Missing to noms value function for: %s", t.Describe())
|
||||
return f(v)
|
||||
|
||||
+49
-37
@@ -1,4 +1,5 @@
|
||||
// This file was generated by nomdl/codegen and then had references to this package (types) removed by hand. The $type field of Package was also manually set to the TypeRef that describes a Package directly.
|
||||
// This file was generated by nomdl/codegen and then had references to this package (types) removed by hand.
|
||||
// To generate this I added support for `Package` in the NomDL parser (Just add `Package` after `UInt32` etc)
|
||||
|
||||
package types
|
||||
|
||||
@@ -10,11 +11,12 @@ import (
|
||||
// SetOfRefOfPackage
|
||||
|
||||
type SetOfRefOfPackage struct {
|
||||
s Set
|
||||
s Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfRefOfPackage() SetOfRefOfPackage {
|
||||
return SetOfRefOfPackage{NewSet()}
|
||||
return SetOfRefOfPackage{NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SetOfRefOfPackageDef map[ref.Ref]bool
|
||||
@@ -23,10 +25,10 @@ func (def SetOfRefOfPackageDef) New() SetOfRefOfPackage {
|
||||
l := make([]Value, len(def))
|
||||
i := 0
|
||||
for d, _ := range def {
|
||||
l[i] = Ref{R: d}
|
||||
l[i] = NewRefOfPackage(d)
|
||||
i++
|
||||
}
|
||||
return SetOfRefOfPackage{NewSet(l...)}
|
||||
return SetOfRefOfPackage{NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Def() SetOfRefOfPackageDef {
|
||||
@@ -38,23 +40,32 @@ func (s SetOfRefOfPackage) Def() SetOfRefOfPackageDef {
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfRefOfPackageFromVal(p Value) SetOfRefOfPackage {
|
||||
return SetOfRefOfPackage{p.(Set)}
|
||||
func SetOfRefOfPackageFromVal(val Value) SetOfRefOfPackage {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfRefOfPackage); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfRefOfPackage{val.(Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) NomsValue() Value {
|
||||
// TODO: Remove this
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) InternalImplementation() Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Equals(other Value) bool {
|
||||
if other, ok := other.(SetOfRefOfPackage); ok {
|
||||
return s.s.Equals(other.s)
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Ref() ref.Ref {
|
||||
return s.s.Ref()
|
||||
return EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Chunks() (futures []Future) {
|
||||
@@ -72,7 +83,7 @@ func (m SetOfRefOfPackage) TypeRef() TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfRefOfPackage = MakeCompoundTypeRef("", SetKind, MakeCompoundTypeRef("", RefKind, MakePrimitiveTypeRef(PackageKind)))
|
||||
RegisterFromValFunction(__typeRefForSetOfRefOfPackage, func(v Value) NomsValue {
|
||||
RegisterFromValFunction(__typeRefForSetOfRefOfPackage, func(v Value) Value {
|
||||
return SetOfRefOfPackageFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -86,28 +97,22 @@ func (s SetOfRefOfPackage) Len() uint64 {
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Has(p RefOfPackage) bool {
|
||||
return s.s.Has(p.NomsValue())
|
||||
return s.s.Has(p)
|
||||
}
|
||||
|
||||
type SetOfRefOfPackageIterCallback func(p RefOfPackage) (stop bool)
|
||||
|
||||
func (s SetOfRefOfPackage) Iter(cb SetOfRefOfPackageIterCallback) {
|
||||
s.s.Iter(func(v Value) bool {
|
||||
return cb(RefOfPackageFromVal(v))
|
||||
return cb(v.(RefOfPackage))
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfRefOfPackageIterAllCallback func(p RefOfPackage)
|
||||
|
||||
func (s SetOfRefOfPackage) IterAll(cb SetOfRefOfPackageIterAllCallback) {
|
||||
// IT'S A HAAAAAACK!
|
||||
// Currently, ReadValue() automatically derefs refs. So, in some cases the value passed to the callback by s.s.IterAll() is actually a Package instead of Ref(Package). This works around that until we've fixed it.
|
||||
s.s.IterAll(func(v Value) {
|
||||
if r, ok := v.(Ref); ok {
|
||||
cb(RefOfPackageFromVal(r))
|
||||
return
|
||||
}
|
||||
cb(RefOfPackage{v.(Package).Ref()})
|
||||
cb(v.(RefOfPackage))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -124,25 +129,23 @@ func (s SetOfRefOfPackage) Filter(cb SetOfRefOfPackageFilterCallback) SetOfRefOf
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Insert(p ...RefOfPackage) SetOfRefOfPackage {
|
||||
return SetOfRefOfPackage{s.s.Insert(s.fromElemSlice(p)...)}
|
||||
return SetOfRefOfPackage{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Remove(p ...RefOfPackage) SetOfRefOfPackage {
|
||||
return SetOfRefOfPackage{s.s.Remove(s.fromElemSlice(p)...)}
|
||||
return SetOfRefOfPackage{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Union(others ...SetOfRefOfPackage) SetOfRefOfPackage {
|
||||
return SetOfRefOfPackage{s.s.Union(s.fromStructSlice(others)...)}
|
||||
return SetOfRefOfPackage{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Subtract(others ...SetOfRefOfPackage) SetOfRefOfPackage {
|
||||
return SetOfRefOfPackage{s.s.Subtract(s.fromStructSlice(others)...)}
|
||||
return SetOfRefOfPackage{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) Any() RefOfPackage {
|
||||
// IT'S A HAAAAAACK!
|
||||
// Currently, ReadValue() automatically derefs refs. So, in some cases the value returned by s.s.Any() is actually a Package instead of Ref(Package). This works around that until we've fixed it.
|
||||
return RefOfPackage{s.s.Any().(Package).Ref()}
|
||||
return s.s.Any().(RefOfPackage)
|
||||
}
|
||||
|
||||
func (s SetOfRefOfPackage) fromStructSlice(p []SetOfRefOfPackage) []Set {
|
||||
@@ -156,7 +159,7 @@ func (s SetOfRefOfPackage) fromStructSlice(p []SetOfRefOfPackage) []Set {
|
||||
func (s SetOfRefOfPackage) fromElemSlice(p []RefOfPackage) []Value {
|
||||
r := make([]Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.NomsValue()
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -164,20 +167,21 @@ func (s SetOfRefOfPackage) fromElemSlice(p []RefOfPackage) []Value {
|
||||
// RefOfPackage
|
||||
|
||||
type RefOfPackage struct {
|
||||
r ref.Ref
|
||||
r ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRefOfPackage(r ref.Ref) RefOfPackage {
|
||||
return RefOfPackage{r}
|
||||
return RefOfPackage{r, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r RefOfPackage) Ref() ref.Ref {
|
||||
return r.r
|
||||
return EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r RefOfPackage) Equals(other Value) bool {
|
||||
if other, ok := other.(RefOfPackage); ok {
|
||||
return r.r == other.r
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -187,11 +191,20 @@ func (r RefOfPackage) Chunks() []Future {
|
||||
}
|
||||
|
||||
func (r RefOfPackage) NomsValue() Value {
|
||||
return Ref{R: r.r}
|
||||
// TODO: Remove this
|
||||
return r
|
||||
}
|
||||
|
||||
func RefOfPackageFromVal(p Value) RefOfPackage {
|
||||
return RefOfPackage{p.(Ref).Ref()}
|
||||
func (r RefOfPackage) InternalImplementation() ref.Ref {
|
||||
return r.r
|
||||
}
|
||||
|
||||
func RefOfPackageFromVal(val Value) RefOfPackage {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RefOfPackage); ok {
|
||||
return val
|
||||
}
|
||||
return RefOfPackage{val.(Ref).Ref(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// A Noms Value that describes RefOfPackage.
|
||||
@@ -203,7 +216,7 @@ func (m RefOfPackage) TypeRef() TypeRef {
|
||||
|
||||
func init() {
|
||||
__typeRefForRefOfPackage = MakeCompoundTypeRef("", RefKind, MakePrimitiveTypeRef(PackageKind))
|
||||
RegisterFromValFunction(__typeRefForRefOfPackage, func(v Value) NomsValue {
|
||||
RegisterFromValFunction(__typeRefForRefOfPackage, func(v Value) Value {
|
||||
return RefOfPackageFromVal(v)
|
||||
})
|
||||
}
|
||||
@@ -213,6 +226,5 @@ func (r RefOfPackage) GetValue(cs chunks.ChunkSource) Package {
|
||||
}
|
||||
|
||||
func (r RefOfPackage) SetValue(val Package, cs chunks.ChunkSink) RefOfPackage {
|
||||
ref := WriteValue(val, cs)
|
||||
return RefOfPackage{ref}
|
||||
return RefOfPackage{WriteValue(val, cs), &ref.Ref{}}
|
||||
}
|
||||
|
||||
+9
-2
@@ -23,7 +23,14 @@ func (r Ref) Chunks() []Future {
|
||||
return nil
|
||||
}
|
||||
|
||||
var refTypeRef = MakeCompoundTypeRef("", RefKind, MakePrimitiveTypeRef(ValueKind))
|
||||
|
||||
func (r Ref) TypeRef() TypeRef {
|
||||
// TODO: The element type needs to be configurable.
|
||||
return MakeCompoundTypeRef("", RefKind, MakePrimitiveTypeRef(ValueKind))
|
||||
return refTypeRef
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterFromValFunction(refTypeRef, func(v Value) Value {
|
||||
return v.(Ref)
|
||||
})
|
||||
}
|
||||
|
||||
+10
-3
@@ -121,7 +121,7 @@ func (fm Set) Any() Value {
|
||||
}
|
||||
|
||||
func (fs Set) Ref() ref.Ref {
|
||||
return ensureRef(fs.ref, fs)
|
||||
return EnsureRef(fs.ref, fs)
|
||||
}
|
||||
|
||||
func (fs Set) Equals(other Value) bool {
|
||||
@@ -138,9 +138,16 @@ func (fs Set) Chunks() (futures []Future) {
|
||||
return
|
||||
}
|
||||
|
||||
var setTypeRef = MakeCompoundTypeRef("", SetKind, MakePrimitiveTypeRef(ValueKind))
|
||||
|
||||
func (fs Set) TypeRef() TypeRef {
|
||||
// TODO: The element type needs to be configurable.
|
||||
return MakeCompoundTypeRef("", SetKind, MakePrimitiveTypeRef(ValueKind))
|
||||
return setTypeRef
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterFromValFunction(setTypeRef, func(v Value) Value {
|
||||
return v.(Set)
|
||||
})
|
||||
}
|
||||
|
||||
func newSetFromData(m setData, cs chunks.ChunkSource) Set {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ func (fs String) String() string {
|
||||
}
|
||||
|
||||
func (fs String) Ref() ref.Ref {
|
||||
return ensureRef(fs.ref, fs)
|
||||
return EnsureRef(fs.ref, fs)
|
||||
}
|
||||
|
||||
func (s String) Equals(other Value) bool {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ func (t TypeRef) Namespace() string {
|
||||
}
|
||||
|
||||
func (t TypeRef) Ref() ref.Ref {
|
||||
return ensureRef(t.ref, t)
|
||||
return EnsureRef(t.ref, t)
|
||||
}
|
||||
|
||||
func (t TypeRef) Equals(other Value) (res bool) {
|
||||
|
||||
+38
-66
@@ -11,12 +11,7 @@ type primitive interface {
|
||||
ToPrimitive() interface{}
|
||||
}
|
||||
|
||||
type NomsValue interface {
|
||||
Value
|
||||
NomsValue() Value
|
||||
}
|
||||
|
||||
func WriteValue(v interface{}, cs chunks.ChunkSink) ref.Ref {
|
||||
func WriteValue(v Value, cs chunks.ChunkSink) ref.Ref {
|
||||
d.Chk.NotNil(cs)
|
||||
return writeValueInternal(v, cs)
|
||||
}
|
||||
@@ -29,7 +24,7 @@ func writeChildValueInternal(v Value, cs chunks.ChunkSink) ref.Ref {
|
||||
return writeValueInternal(v, cs)
|
||||
}
|
||||
|
||||
func writeValueInternal(v interface{}, cs chunks.ChunkSink) ref.Ref {
|
||||
func writeValueInternal(v Value, cs chunks.ChunkSink) ref.Ref {
|
||||
e := toEncodeable(v, cs)
|
||||
w := chunks.NewChunkWriter()
|
||||
enc.Encode(w, e)
|
||||
@@ -40,39 +35,24 @@ func writeValueInternal(v interface{}, cs chunks.ChunkSink) ref.Ref {
|
||||
return c.Ref()
|
||||
}
|
||||
|
||||
func toEncodeable(v interface{}, cs chunks.ChunkSink) interface{} {
|
||||
func toEncodeable(v Value, cs chunks.ChunkSink) interface{} {
|
||||
switch v := v.(type) {
|
||||
case blobLeaf:
|
||||
return v.Reader()
|
||||
case compoundBlob:
|
||||
return encCompoundBlobFromCompoundBlob(v, cs)
|
||||
case NomsValue:
|
||||
return encNomsValue(v, cs)
|
||||
case compoundList:
|
||||
return encCompoundListFromCompoundList(v, cs)
|
||||
case listLeaf:
|
||||
return makeListEncodeable(v, cs)
|
||||
case List:
|
||||
processListChildren(v, cs)
|
||||
case Map:
|
||||
return makeMapEncodeable(v, cs)
|
||||
case primitive:
|
||||
return v.ToPrimitive()
|
||||
case Ref:
|
||||
return v.Ref()
|
||||
case Set:
|
||||
return makeSetEncodeable(v, cs)
|
||||
case String:
|
||||
return v.String()
|
||||
case TypeRef:
|
||||
return makeTypeEncodeable(v, cs)
|
||||
processMapChildren(v, cs)
|
||||
case Package:
|
||||
return makePackageEncodeable(v, cs)
|
||||
default:
|
||||
if v == nil {
|
||||
return v
|
||||
}
|
||||
d.Chk.Fail("Unexpected type: %T, %#v", v, v)
|
||||
return v
|
||||
processPackageChildren(v, cs)
|
||||
case Set:
|
||||
processSetChildren(v, cs)
|
||||
case TypeRef:
|
||||
processTypeRefChildren(v, cs)
|
||||
}
|
||||
return encNomsValue(v, cs)
|
||||
}
|
||||
|
||||
func encCompoundBlobFromCompoundBlob(cb compoundBlob, cs chunks.ChunkSink) interface{} {
|
||||
@@ -85,58 +65,50 @@ func encCompoundBlobFromCompoundBlob(cb compoundBlob, cs chunks.ChunkSink) inter
|
||||
return enc.CompoundBlob{Offsets: cb.offsets, Blobs: refs}
|
||||
}
|
||||
|
||||
func encCompoundListFromCompoundList(cl compoundList, cs chunks.ChunkSink) interface{} {
|
||||
refs := make([]ref.Ref, len(cl.futures))
|
||||
for idx, f := range cl.futures {
|
||||
i := processChild(f, cs)
|
||||
// All children of compoundList must be Lists, which get encoded and reffed by processChild.
|
||||
refs[idx] = i.(ref.Ref)
|
||||
}
|
||||
return enc.CompoundList{Offsets: cl.offsets, Lists: refs}
|
||||
func processListChildren(l List, cs chunks.ChunkSink) {
|
||||
l.IterAll(func(v Value, i uint64) {
|
||||
writeChildValueInternal(v, cs)
|
||||
})
|
||||
}
|
||||
|
||||
func makeListEncodeable(l listLeaf, cs chunks.ChunkSink) interface{} {
|
||||
items := make([]interface{}, l.Len())
|
||||
for idx, f := range l.list {
|
||||
items[idx] = processChild(f, cs)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func makeMapEncodeable(m Map, cs chunks.ChunkSink) interface{} {
|
||||
j := make([]interface{}, 0, 2*len(m.m))
|
||||
func processMapChildren(m Map, cs chunks.ChunkSink) {
|
||||
for _, r := range m.m {
|
||||
j = append(j, processChild(r.key, cs))
|
||||
j = append(j, processChild(r.value, cs))
|
||||
processChild(r.key, cs)
|
||||
processChild(r.value, cs)
|
||||
}
|
||||
return enc.MapFromItems(j...)
|
||||
}
|
||||
|
||||
func makeSetEncodeable(s Set, cs chunks.ChunkSink) interface{} {
|
||||
items := make([]interface{}, s.Len())
|
||||
for idx, f := range s.m {
|
||||
items[idx] = processChild(f, cs)
|
||||
func processSetChildren(s Set, cs chunks.ChunkSink) {
|
||||
for _, f := range s.m {
|
||||
processChild(f, cs)
|
||||
}
|
||||
return enc.SetFromItems(items...)
|
||||
}
|
||||
|
||||
func makeTypeEncodeable(t TypeRef, cs chunks.ChunkSink) interface{} {
|
||||
func processTypeRefChildren(t TypeRef, cs chunks.ChunkSink) {
|
||||
if t.HasPackageRef() {
|
||||
pkgRef := t.PackageRef()
|
||||
p := LookupPackage(pkgRef)
|
||||
if p != nil {
|
||||
pkgRef = writeChildValueInternal(*p, cs)
|
||||
writeChildValueInternal(*p, cs)
|
||||
}
|
||||
}
|
||||
if desc, ok := t.Desc.(CompoundDesc); ok {
|
||||
for _, t := range desc.ElemTypes {
|
||||
writeChildValueInternal(t, cs)
|
||||
}
|
||||
}
|
||||
return enc.TypeRef{Name: t.Name(), Kind: uint8(t.Kind()), Desc: toEncodeable(t.Desc.ToValue(), cs)}
|
||||
}
|
||||
|
||||
func makePackageEncodeable(p Package, cs chunks.ChunkSink) interface{} {
|
||||
types := make([]enc.TypeRef, len(p.types))
|
||||
for i, t := range p.types {
|
||||
types[i] = makeTypeEncodeable(t, cs).(enc.TypeRef)
|
||||
func processPackageChildren(p Package, cs chunks.ChunkSink) {
|
||||
for _, t := range p.types {
|
||||
writeChildValueInternal(t, cs)
|
||||
}
|
||||
for _, r := range p.dependencies {
|
||||
p := LookupPackage(r)
|
||||
if p != nil {
|
||||
writeChildValueInternal(*p, cs)
|
||||
}
|
||||
}
|
||||
return enc.Package{Types: types, Dependencies: p.dependencies}
|
||||
}
|
||||
|
||||
func processChild(f Future, cs chunks.ChunkSink) interface{} {
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestWriteValue(t *testing.T) {
|
||||
|
||||
var s *chunks.MemoryStore
|
||||
|
||||
testEncode := func(expected string, v interface{}) ref.Ref {
|
||||
testEncode := func(expected string, v Value) ref.Ref {
|
||||
s = chunks.NewMemoryStore()
|
||||
r := WriteValue(v, s)
|
||||
|
||||
@@ -30,18 +30,12 @@ func TestWriteValue(t *testing.T) {
|
||||
b, err := NewBlob(bytes.NewBuffer([]byte{0x00, 0x01, 0x02}))
|
||||
assert.NoError(err)
|
||||
testEncode(string([]byte{'b', ' ', 0x00, 0x01, 0x02}), b)
|
||||
testEncode("j \"foo\"\n", NewString("foo"))
|
||||
|
||||
tref := MakePrimitiveTypeRef(StringKind)
|
||||
nomsValueString := valueAsNomsValue{Value: NewString("hi"), t: tref}
|
||||
testEncode(fmt.Sprintf("t [%d,\"hi\"]\n", StringKind), nomsValueString)
|
||||
testEncode(fmt.Sprintf("t [%d,\"hi\"]\n", StringKind), NewString("hi"))
|
||||
|
||||
testEncode(`j {"package":{"dependencies":[],"types":[]}}
|
||||
`, Package{types: []TypeRef{}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
ref1 := testEncode(`j {"package":{"dependencies":[],"types":[{"type":{"kind":{"uint8":0},"name":""}}]}}
|
||||
`, Package{types: []TypeRef{MakePrimitiveTypeRef(BoolKind)}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
testEncode(fmt.Sprintf(`j {"package":{"dependencies":[{"ref":"%s"}],"types":[]}}
|
||||
`, ref1), Package{types: []TypeRef{}, dependencies: []ref.Ref{ref1}, ref: &ref.Ref{}})
|
||||
testEncode(fmt.Sprintf("t [%d,[],[]]\n", PackageKind), Package{types: []TypeRef{}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
ref1 := testEncode(fmt.Sprintf("t [%d,[%d],[]]\n", PackageKind, BoolKind), Package{types: []TypeRef{MakePrimitiveTypeRef(BoolKind)}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
|
||||
testEncode(fmt.Sprintf("t [%d,[],[\"%s\"]]\n", PackageKind, ref1), Package{types: []TypeRef{}, dependencies: []ref.Ref{ref1}, ref: &ref.Ref{}})
|
||||
}
|
||||
|
||||
func TestWriteBlobLeaf(t *testing.T) {
|
||||
|
||||
+31
-13
@@ -49,9 +49,27 @@ func (suite *WalkAllTestSuite) TestWalkComposites() {
|
||||
suite.walkWorker(suite.storeAndRef(types.NewMap(types.Int32(8), types.Bool(true), types.Int32(0), types.Bool(false))), 1)
|
||||
}
|
||||
|
||||
func (suite *WalkAllTestSuite) NewList(vs ...types.Value) types.Ref {
|
||||
v := types.NewList(vs...)
|
||||
r := types.WriteValue(v, suite.cs)
|
||||
return types.Ref{R: r}
|
||||
}
|
||||
|
||||
func (suite *WalkAllTestSuite) NewMap(vs ...types.Value) types.Ref {
|
||||
v := types.NewMap(vs...)
|
||||
r := types.WriteValue(v, suite.cs)
|
||||
return types.Ref{R: r}
|
||||
}
|
||||
|
||||
func (suite *WalkAllTestSuite) NewSet(vs ...types.Value) types.Ref {
|
||||
v := types.NewSet(vs...)
|
||||
r := types.WriteValue(v, suite.cs)
|
||||
return types.Ref{R: r}
|
||||
}
|
||||
|
||||
func (suite *WalkAllTestSuite) TestWalkNestedComposites() {
|
||||
suite.walkWorker(suite.storeAndRef(types.NewList(types.NewSet(), types.Int32(8))), 2)
|
||||
suite.walkWorker(suite.storeAndRef(types.NewSet(types.NewList(), types.NewSet())), 3)
|
||||
suite.walkWorker(suite.storeAndRef(types.NewList(suite.NewSet(), types.Int32(8))), 2)
|
||||
suite.walkWorker(suite.storeAndRef(types.NewSet(suite.NewList(), suite.NewSet())), 3)
|
||||
// {"string": "string",
|
||||
// "list": [false true],
|
||||
// "map": {"nested": "string"}
|
||||
@@ -61,26 +79,26 @@ func (suite *WalkAllTestSuite) TestWalkNestedComposites() {
|
||||
// }
|
||||
nested := types.NewMap(
|
||||
types.NewString("string"), types.NewString("string"),
|
||||
types.NewString("list"), types.NewList(types.Bool(false), types.Bool(true)),
|
||||
types.NewString("map"), types.NewMap(types.NewString("nested"), types.NewString("string")),
|
||||
types.NewString("mtlist"), types.NewList(),
|
||||
types.NewString("set"), types.NewSet(types.Int32(5), types.Int32(7), types.Int32(8)),
|
||||
types.NewList(), types.NewString("wow"))
|
||||
types.NewString("list"), suite.NewList(types.Bool(false), types.Bool(true)),
|
||||
types.NewString("map"), suite.NewMap(types.NewString("nested"), types.NewString("string")),
|
||||
types.NewString("mtlist"), suite.NewList(),
|
||||
types.NewString("set"), suite.NewSet(types.Int32(5), types.Int32(7), types.Int32(8)),
|
||||
suite.NewList(), types.NewString("wow"))
|
||||
suite.walkWorker(suite.storeAndRef(nested), 6)
|
||||
}
|
||||
|
||||
type WalkTestSuite struct {
|
||||
WalkAllTestSuite
|
||||
shouldSee types.Value
|
||||
mustSkip types.List
|
||||
shouldSee types.Ref
|
||||
mustSkip types.Ref
|
||||
deadValue types.Value
|
||||
}
|
||||
|
||||
func (suite *WalkTestSuite) SetupTest() {
|
||||
suite.shouldSee = types.NewList(types.NewString("zzz"))
|
||||
suite.deadValue = types.UInt64(0xDEADBEEF)
|
||||
suite.mustSkip = types.NewList(suite.deadValue)
|
||||
suite.cs = chunks.NewTestStore()
|
||||
suite.shouldSee = suite.NewList(types.NewString("zzz"))
|
||||
suite.deadValue = types.UInt64(0xDEADBEEF)
|
||||
suite.mustSkip = suite.NewList(suite.deadValue)
|
||||
}
|
||||
|
||||
func (suite *WalkTestSuite) TestStopWalkImmediately() {
|
||||
@@ -121,7 +139,7 @@ func (suite *WalkTestSuite) TestSkipSetElement() {
|
||||
}
|
||||
|
||||
func (suite *WalkTestSuite) TestSkipMapValue() {
|
||||
shouldAlsoSee := types.NewSet(types.NewString("Also good"))
|
||||
shouldAlsoSee := suite.NewSet(types.NewString("Also good"))
|
||||
wholeMap := types.NewMap(suite.shouldSee, suite.mustSkip, shouldAlsoSee, suite.shouldSee)
|
||||
reached := suite.skipWorker(wholeMap)
|
||||
for _, v := range []types.Value{wholeMap, suite.mustSkip, shouldAlsoSee, suite.shouldSee, suite.shouldSee} {
|
||||
|
||||
Reference in New Issue
Block a user