This commit is contained in:
parent
1173d163f5
commit
7ca821016e
|
@ -246,7 +246,7 @@ func eqBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
l := args.args[0]
|
||||
r := args.args[1]
|
||||
|
||||
return boolObject(objectsEqual(l, r)), nil
|
||||
return BoolObject(objectsEqual(l, r)), nil
|
||||
}
|
||||
|
||||
func neBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
|
@ -257,7 +257,7 @@ func neBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
l := args.args[0]
|
||||
r := args.args[1]
|
||||
|
||||
return boolObject(!objectsEqual(l, r)), nil
|
||||
return BoolObject(!objectsEqual(l, r)), nil
|
||||
}
|
||||
|
||||
func ltBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
|
@ -269,7 +269,7 @@ func ltBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return boolObject(isLess), nil
|
||||
return BoolObject(isLess), nil
|
||||
}
|
||||
|
||||
func leBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
|
@ -281,7 +281,7 @@ func leBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return boolObject(isLess || objectsEqual(args.args[0], args.args[1])), nil
|
||||
return BoolObject(isLess || objectsEqual(args.args[0], args.args[1])), nil
|
||||
}
|
||||
|
||||
func gtBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
|
@ -293,7 +293,7 @@ func gtBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return boolObject(isGreater), nil
|
||||
return BoolObject(isGreater), nil
|
||||
}
|
||||
|
||||
func geBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
|
@ -305,7 +305,7 @@ func geBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return boolObject(isGreater || objectsEqual(args.args[0], args.args[1])), nil
|
||||
return BoolObject(isGreater || objectsEqual(args.args[0], args.args[1])), nil
|
||||
}
|
||||
|
||||
func andBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
|
@ -339,7 +339,7 @@ func notBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return boolObject(!args.args[0].Truthy()), nil
|
||||
return BoolObject(!args.args[0].Truthy()), nil
|
||||
}
|
||||
|
||||
var errObjectsNotEqual = errors.New("objects not equal")
|
||||
|
@ -358,8 +358,8 @@ func objectsEqual(l, r Object) bool {
|
|||
if rv, ok := r.(IntObject); ok {
|
||||
return lv == rv
|
||||
}
|
||||
case boolObject:
|
||||
if rv, ok := r.(boolObject); ok {
|
||||
case BoolObject:
|
||||
if rv, ok := r.(BoolObject); ok {
|
||||
return lv == rv
|
||||
}
|
||||
case Listable:
|
||||
|
@ -446,7 +446,7 @@ func intBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
return nil, errors.New("cannot convert to int")
|
||||
}
|
||||
return IntObject(i), nil
|
||||
case boolObject:
|
||||
case BoolObject:
|
||||
if v {
|
||||
return IntObject(1), nil
|
||||
}
|
||||
|
|
20
ucl/objs.go
20
ucl/objs.go
|
@ -172,26 +172,26 @@ func (i IntObject) Truthy() bool {
|
|||
return i != 0
|
||||
}
|
||||
|
||||
type boolObject bool
|
||||
type BoolObject bool
|
||||
|
||||
func (b boolObject) String() string {
|
||||
func (b BoolObject) String() string {
|
||||
if b {
|
||||
return "true"
|
||||
}
|
||||
return "false"
|
||||
}
|
||||
|
||||
func (b boolObject) Truthy() bool {
|
||||
func (b BoolObject) Truthy() bool {
|
||||
return bool(b)
|
||||
}
|
||||
|
||||
type timeObject time.Time
|
||||
type TimeObject time.Time
|
||||
|
||||
func (t timeObject) String() string {
|
||||
func (t TimeObject) String() string {
|
||||
return time.Time(t).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func (t timeObject) Truthy() bool {
|
||||
func (t TimeObject) Truthy() bool {
|
||||
return !time.Time(t).IsZero()
|
||||
}
|
||||
|
||||
|
@ -205,9 +205,9 @@ func toGoValue(obj Object) (interface{}, bool) {
|
|||
return int(v), true
|
||||
case StringListObject:
|
||||
return []string(v), true
|
||||
case boolObject:
|
||||
case BoolObject:
|
||||
return bool(v), true
|
||||
case timeObject:
|
||||
case TimeObject:
|
||||
return time.Time(v), true
|
||||
case *ListObject:
|
||||
xs := make([]interface{}, 0, len(*v))
|
||||
|
@ -257,9 +257,9 @@ func fromGoValue(v any) (Object, error) {
|
|||
case int:
|
||||
return IntObject(t), nil
|
||||
case bool:
|
||||
return boolObject(t), nil
|
||||
return BoolObject(t), nil
|
||||
case time.Time:
|
||||
return timeObject(t), nil
|
||||
return TimeObject(t), nil
|
||||
}
|
||||
|
||||
return fromGoReflectValue(reflect.ValueOf(v))
|
||||
|
|
Loading…
Reference in a new issue