Add set index in list, and update lib+examples+tests
This commit is contained in:
parent
8d12c0bdf8
commit
0f905a7fea
12 changed files with 117 additions and 60 deletions
|
|
@ -117,8 +117,12 @@ type Value interface {
|
|||
// Get a member from the value. An error is returned if the member does not exist
|
||||
Get(string) (Value, error)
|
||||
|
||||
// Clone create a clone of the value. The returned value is a pointer to a new value of the same type as the value.
|
||||
Clone() Value
|
||||
// Copy create a copy of the value. A copy is a direct copy for small data (numbers) and a copy of pointer
|
||||
// for bigger data (lists, tuples, dicts)
|
||||
Copy() Value
|
||||
|
||||
// Clone create a clone of the value. A clone is new data for all data.
|
||||
//Clone() Value
|
||||
}
|
||||
|
||||
type NilValue struct{}
|
||||
|
|
@ -143,7 +147,7 @@ func (v *NilValue) Get(_ string) (Value, error) {
|
|||
return nil, errors.New("nil has no properties")
|
||||
}
|
||||
|
||||
func (v *NilValue) Clone() Value {
|
||||
func (v *NilValue) Copy() Value {
|
||||
return &NilValue{}
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +179,7 @@ func (v *BoolValue) Get(_ string) (Value, error) {
|
|||
return nil, errors.New("booleans have no properties")
|
||||
}
|
||||
|
||||
func (v *BoolValue) Clone() Value {
|
||||
func (v *BoolValue) Copy() Value {
|
||||
return &BoolValue{
|
||||
v.Boolean,
|
||||
}
|
||||
|
|
@ -258,11 +262,11 @@ func (v *ObjectValue) Get(key string) (Value, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (v *ObjectValue) Clone() Value {
|
||||
func (v *ObjectValue) Copy() Value {
|
||||
m := make(map[string]Value, len(v.Members))
|
||||
|
||||
for name, mem := range v.Members {
|
||||
m[name] = mem.Clone()
|
||||
m[name] = mem.Copy()
|
||||
}
|
||||
|
||||
return &ObjectValue{
|
||||
|
|
@ -303,7 +307,7 @@ func (v *FloatValue) Get(_ string) (Value, error) {
|
|||
return nil, errors.New("numbers have no properties")
|
||||
}
|
||||
|
||||
func (v *FloatValue) Clone() Value {
|
||||
func (v *FloatValue) Copy() Value {
|
||||
return &FloatValue{
|
||||
v.Number,
|
||||
}
|
||||
|
|
@ -334,7 +338,7 @@ func (v *IntegerValue) Get(_ string) (Value, error) {
|
|||
return nil, errors.New("numbers have no properties")
|
||||
}
|
||||
|
||||
func (v *IntegerValue) Clone() Value {
|
||||
func (v *IntegerValue) Copy() Value {
|
||||
return &IntegerValue{
|
||||
new(big.Int).Set(v.Number),
|
||||
}
|
||||
|
|
@ -427,7 +431,7 @@ func (v *StringValue) Get(key string) (Value, error) {
|
|||
return nil, errors.New(fmt.Sprintf("string has no property \"%s\"", key))
|
||||
}
|
||||
|
||||
func (v *StringValue) Clone() Value {
|
||||
func (v *StringValue) Copy() Value {
|
||||
return &StringValue{
|
||||
v.Text,
|
||||
}
|
||||
|
|
@ -594,15 +598,9 @@ func (v *ListValue) Get(key string) (Value, error) {
|
|||
return nil, errors.New(fmt.Sprintf("list has no property \"%s\"", key))
|
||||
}
|
||||
|
||||
func (v *ListValue) Clone() Value {
|
||||
n := make([]Value, len(v.Items))
|
||||
|
||||
for i, item := range v.Items {
|
||||
n[i] = item.Clone()
|
||||
}
|
||||
|
||||
func (v *ListValue) Copy() Value {
|
||||
return &ListValue{
|
||||
n,
|
||||
v.Items,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -635,13 +633,9 @@ func (v *TupleValue) DebugString() string {
|
|||
return v.String()
|
||||
}
|
||||
|
||||
func (v *TupleValue) Clone() Value {
|
||||
n := make([]Value, len(v.Items))
|
||||
for i, item := range v.Items {
|
||||
n[i] = item.Clone()
|
||||
}
|
||||
func (v *TupleValue) Copy() Value {
|
||||
return &TupleValue{
|
||||
n,
|
||||
v.Items,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -718,7 +712,7 @@ func (v *FunctionValue) Get(_ string) (Value, error) {
|
|||
return nil, errors.New("functions have no properties")
|
||||
}
|
||||
|
||||
func (v *FunctionValue) Clone() Value {
|
||||
func (v *FunctionValue) Copy() Value {
|
||||
return &FunctionValue{
|
||||
v.Name,
|
||||
v.Params,
|
||||
|
|
@ -758,7 +752,7 @@ func (v *BuiltinFunctionValue) Get(_ string) (Value, error) {
|
|||
return nil, errors.New("functions have no properties")
|
||||
}
|
||||
|
||||
func (v *BuiltinFunctionValue) Clone() Value {
|
||||
func (v *BuiltinFunctionValue) Copy() Value {
|
||||
return &BuiltinFunctionValue{
|
||||
v.Name,
|
||||
v.Signature,
|
||||
|
|
@ -807,7 +801,7 @@ func (v *RecordValue) DebugString() string {
|
|||
return v.String()
|
||||
}
|
||||
|
||||
func (v *RecordValue) Clone() Value {
|
||||
func (v *RecordValue) Copy() Value {
|
||||
return &RecordValue{
|
||||
v.Entries,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue