simpler vm
Some checks failed
Test / build (push) Waiting to run
Build / build (push) Successful in 11m8s
Publish Image / publish (push) Has been cancelled

This commit is contained in:
2024-04-01 17:21:55 -04:00
parent f9e6e164b0
commit 803f330e82
6 changed files with 246 additions and 317 deletions

View File

@@ -45,51 +45,61 @@ func (i Integer) Sub(other Object) (Object, error) {
}
func (i Integer) Mul(other Object) (Object, error) {
switch other.Type() {
case IntegerType:
return Integer{i.Value * other.(Integer).Value}, nil
case StringType:
return other.(Mul).Mul(i)
case ArrayType:
return other.(Mul).Mul(i)
switch obj := other.(type) {
case Integer:
return Integer{i.Value * obj.Value}, nil
case String:
return obj.Mul(i)
case *Array:
return obj.Mul(i)
default:
return nil, NewBinaryOpError(i, other, "*")
}
}
func (i Integer) Div(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) Mod(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) BitwiseOr(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) BitwiseXor(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) BitwiseAnd(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) BitwiseNot() Object {
@@ -97,17 +107,21 @@ func (i Integer) BitwiseNot() Object {
}
func (i Integer) LeftShift(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) RightShift(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) LogicalNot() Object {