further improvements
Some checks failed
Build / build (push) Successful in 10m40s
Publish Image / publish (push) Failing after 34s
Test / build (push) Has been cancelled

This commit is contained in:
2024-04-01 17:02:44 -04:00
parent aebbe43999
commit f9e6e164b0
26 changed files with 168 additions and 138 deletions

View File

@@ -4,10 +4,22 @@ import (
"fmt"
)
var (
TRUE = Boolean{Value: true}
FALSE = Boolean{Value: false}
)
type Boolean struct {
Value bool
}
func NewBoolean(value bool) Boolean {
if value {
return TRUE
}
return FALSE
}
func (b Boolean) Bool() bool {
return b.Value
}

View File

@@ -7,18 +7,18 @@ type Builtin struct {
Fn BuiltinFunction
}
func (b *Builtin) Bool() bool {
func (b Builtin) Bool() bool {
return true
}
func (b *Builtin) Type() Type {
func (b Builtin) Type() Type {
return BuiltinType
}
func (b *Builtin) Inspect() string {
func (b Builtin) Inspect() string {
return fmt.Sprintf("<built-in function %s>", b.Name)
}
func (b *Builtin) String() string {
func (b Builtin) String() string {
return b.Inspect()
}

View File

@@ -27,17 +27,21 @@ func (i Integer) String() string {
}
func (i Integer) Add(other Object) (Object, error) {
if !AssertTypes(other, IntegerType) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value + obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "+")
}
return Integer{i.Value + other.(Integer).Value}, nil
}
func (i Integer) Sub(other Object) (Object, error) {
if !AssertTypes(other, IntegerType) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value - obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "-")
}
return Integer{i.Value - other.(Integer).Value}, nil
}
func (i Integer) Mul(other Object) (Object, error) {
@@ -115,15 +119,16 @@ func (i Integer) Negate() Object {
}
func (i Integer) Compare(other Object) int {
if obj, ok := other.(Integer); ok {
switch {
case i.Value < obj.Value:
switch obj := other.(type) {
case Integer:
if i.Value < obj.Value {
return -1
case i.Value > obj.Value:
return 1
default:
return 0
}
if i.Value > obj.Value {
return 1
}
return 0
default:
return -1
}
return -1
}

View File

@@ -1,5 +1,7 @@
package object
var NULL = Null{}
type Null struct{}
func (n Null) Bool() bool {