some improvments
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PSObject interface {
|
||||
@@ -17,18 +18,18 @@ type PSInteger struct {
|
||||
Val int
|
||||
}
|
||||
|
||||
func (this *PSInteger) Duplicate() PSObject {
|
||||
func (pI *PSInteger) Duplicate() PSObject {
|
||||
obj := PSInteger{}
|
||||
obj.Val = this.Val
|
||||
obj.Val = pI.Val
|
||||
return &obj
|
||||
}
|
||||
|
||||
func (this *PSInteger) DebugString() string {
|
||||
return fmt.Sprintf("int:%d", this.Val)
|
||||
func (pI *PSInteger) DebugString() string {
|
||||
return fmt.Sprintf("int:%d", pI.Val)
|
||||
}
|
||||
|
||||
func (this *PSInteger) String() string {
|
||||
return fmt.Sprintf("%d", this.Val)
|
||||
func (pI *PSInteger) String() string {
|
||||
return fmt.Sprintf("%d", pI.Val)
|
||||
}
|
||||
|
||||
// Real number.
|
||||
@@ -36,17 +37,17 @@ type PSReal struct {
|
||||
Val float64
|
||||
}
|
||||
|
||||
func (this *PSReal) DebugString() string {
|
||||
return fmt.Sprintf("real:%.5f", this.Val)
|
||||
func (pR *PSReal) DebugString() string {
|
||||
return fmt.Sprintf("real:%.5f", pR.Val)
|
||||
}
|
||||
|
||||
func (this *PSReal) String() string {
|
||||
return fmt.Sprintf("%.5f", this.Val)
|
||||
func (pR *PSReal) String() string {
|
||||
return fmt.Sprintf("%.5f", pR.Val)
|
||||
}
|
||||
|
||||
func (this *PSReal) Duplicate() PSObject {
|
||||
func (pR *PSReal) Duplicate() PSObject {
|
||||
obj := PSReal{}
|
||||
obj.Val = this.Val
|
||||
obj.Val = pR.Val
|
||||
return &obj
|
||||
}
|
||||
|
||||
@@ -55,17 +56,17 @@ type PSBoolean struct {
|
||||
Val bool
|
||||
}
|
||||
|
||||
func (this *PSBoolean) DebugString() string {
|
||||
return fmt.Sprintf("bool:%v", this.Val)
|
||||
func (pB *PSBoolean) DebugString() string {
|
||||
return fmt.Sprintf("bool:%v", pB.Val)
|
||||
}
|
||||
|
||||
func (this *PSBoolean) String() string {
|
||||
return fmt.Sprintf("%v", this.Val)
|
||||
func (pB *PSBoolean) String() string {
|
||||
return fmt.Sprintf("%v", pB.Val)
|
||||
}
|
||||
|
||||
func (this *PSBoolean) Duplicate() PSObject {
|
||||
func (pB *PSBoolean) Duplicate() PSObject {
|
||||
obj := PSBoolean{}
|
||||
obj.Val = this.Val
|
||||
obj.Val = pB.Val
|
||||
return &obj
|
||||
}
|
||||
|
||||
@@ -76,42 +77,44 @@ func NewPSProgram() *PSProgram {
|
||||
return &PSProgram{}
|
||||
}
|
||||
|
||||
func (this *PSProgram) Append(obj PSObject) {
|
||||
*this = append(*this, obj)
|
||||
func (pP *PSProgram) Append(obj PSObject) {
|
||||
*pP = append(*pP, obj)
|
||||
}
|
||||
|
||||
func (this *PSProgram) DebugString() string {
|
||||
s := "{ "
|
||||
for _, obj := range *this {
|
||||
s += obj.DebugString()
|
||||
s += " "
|
||||
func (pP *PSProgram) DebugString() string {
|
||||
var s strings.Builder
|
||||
s.WriteString("{ ")
|
||||
for _, obj := range *pP {
|
||||
s.WriteString(obj.DebugString())
|
||||
s.WriteString(" ")
|
||||
}
|
||||
s += "}"
|
||||
s.WriteString("}")
|
||||
|
||||
return s
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (this *PSProgram) String() string {
|
||||
s := "{ "
|
||||
for _, obj := range *this {
|
||||
s += obj.String()
|
||||
s += " "
|
||||
func (pP *PSProgram) String() string {
|
||||
var s strings.Builder
|
||||
s.WriteString("{ ")
|
||||
for _, obj := range *pP {
|
||||
s.WriteString(obj.String())
|
||||
s.WriteString(" ")
|
||||
}
|
||||
s += "}"
|
||||
s.WriteString("}")
|
||||
|
||||
return s
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (this *PSProgram) Duplicate() PSObject {
|
||||
func (pP *PSProgram) Duplicate() PSObject {
|
||||
prog := &PSProgram{}
|
||||
for _, obj := range *this {
|
||||
for _, obj := range *pP {
|
||||
prog.Append(obj.Duplicate())
|
||||
}
|
||||
return prog
|
||||
}
|
||||
|
||||
func (this *PSProgram) Exec(stack *PSStack) error {
|
||||
for _, obj := range *this {
|
||||
func (pP *PSProgram) Exec(stack *PSStack) error {
|
||||
for _, obj := range *pP {
|
||||
var err error
|
||||
if number, isInt := obj.(*PSInteger); isInt {
|
||||
err = stack.Push(number)
|
||||
@@ -136,118 +139,118 @@ func (this *PSProgram) Exec(stack *PSStack) error {
|
||||
// Operand.
|
||||
type PSOperand string
|
||||
|
||||
func (this *PSOperand) DebugString() string {
|
||||
return fmt.Sprintf("op:'%s'", *this)
|
||||
func (pO *PSOperand) DebugString() string {
|
||||
return fmt.Sprintf("op:'%s'", *pO)
|
||||
}
|
||||
|
||||
func (this *PSOperand) String() string {
|
||||
return fmt.Sprintf("%s", *this)
|
||||
func (pO *PSOperand) String() string {
|
||||
return fmt.Sprintf("%s", *pO)
|
||||
}
|
||||
|
||||
func (this *PSOperand) Duplicate() PSObject {
|
||||
s := *this
|
||||
func (pO *PSOperand) Duplicate() PSObject {
|
||||
s := *pO
|
||||
return &s
|
||||
}
|
||||
|
||||
func (this *PSOperand) Exec(stack *PSStack) error {
|
||||
func (pO *PSOperand) Exec(stack *PSStack) error {
|
||||
err := errors.New("Unsupported operand")
|
||||
switch *this {
|
||||
switch *pO {
|
||||
case "abs":
|
||||
err = this.Abs(stack)
|
||||
err = pO.Abs(stack)
|
||||
case "add":
|
||||
err = this.Add(stack)
|
||||
err = pO.Add(stack)
|
||||
case "and":
|
||||
err = this.And(stack)
|
||||
err = pO.And(stack)
|
||||
case "atan":
|
||||
err = this.Atan(stack)
|
||||
err = pO.Atan(stack)
|
||||
|
||||
case "bitshift":
|
||||
err = this.Bitshift(stack)
|
||||
err = pO.Bitshift(stack)
|
||||
|
||||
case "ceiling":
|
||||
err = this.Ceiling(stack)
|
||||
err = pO.Ceiling(stack)
|
||||
case "copy":
|
||||
err = this.Copy(stack)
|
||||
err = pO.Copy(stack)
|
||||
case "cos":
|
||||
err = this.Cos(stack)
|
||||
err = pO.Cos(stack)
|
||||
case "cvi":
|
||||
err = this.Cvi(stack)
|
||||
err = pO.Cvi(stack)
|
||||
case "cvr":
|
||||
err = this.Cvr(stack)
|
||||
err = pO.Cvr(stack)
|
||||
|
||||
case "div":
|
||||
err = this.Div(stack)
|
||||
err = pO.Div(stack)
|
||||
case "dup":
|
||||
err = this.Dup(stack)
|
||||
err = pO.Dup(stack)
|
||||
|
||||
case "eq":
|
||||
err = this.Eq(stack)
|
||||
err = pO.Eq(stack)
|
||||
case "exch":
|
||||
err = this.Exch(stack)
|
||||
err = pO.Exch(stack)
|
||||
case "exp":
|
||||
err = this.Exp(stack)
|
||||
err = pO.Exp(stack)
|
||||
|
||||
case "floor":
|
||||
err = this.Floor(stack)
|
||||
err = pO.Floor(stack)
|
||||
|
||||
case "ge":
|
||||
err = this.Ge(stack)
|
||||
err = pO.Ge(stack)
|
||||
case "gt":
|
||||
err = this.Gt(stack)
|
||||
err = pO.Gt(stack)
|
||||
|
||||
case "idiv":
|
||||
err = this.IDiv(stack)
|
||||
err = pO.IDiv(stack)
|
||||
case "if":
|
||||
err = this.If(stack)
|
||||
err = pO.If(stack)
|
||||
case "ifelse":
|
||||
err = this.IfElse(stack)
|
||||
err = pO.IfElse(stack)
|
||||
case "index":
|
||||
err = this.Index(stack)
|
||||
err = pO.Index(stack)
|
||||
|
||||
case "le":
|
||||
err = this.Le(stack)
|
||||
err = pO.Le(stack)
|
||||
case "log":
|
||||
err = this.Log(stack)
|
||||
err = pO.Log(stack)
|
||||
case "ln":
|
||||
err = this.Ln(stack)
|
||||
err = pO.Ln(stack)
|
||||
case "lt":
|
||||
err = this.Lt(stack)
|
||||
err = pO.Lt(stack)
|
||||
|
||||
case "mod":
|
||||
err = this.Mod(stack)
|
||||
err = pO.Mod(stack)
|
||||
case "mul":
|
||||
err = this.Mul(stack)
|
||||
err = pO.Mul(stack)
|
||||
|
||||
case "ne":
|
||||
err = this.Ne(stack)
|
||||
err = pO.Ne(stack)
|
||||
case "neg":
|
||||
err = this.Neg(stack)
|
||||
err = pO.Neg(stack)
|
||||
case "not":
|
||||
err = this.Not(stack)
|
||||
err = pO.Not(stack)
|
||||
|
||||
case "or":
|
||||
err = this.Or(stack)
|
||||
err = pO.Or(stack)
|
||||
|
||||
case "pop":
|
||||
err = this.Pop(stack)
|
||||
err = pO.Pop(stack)
|
||||
|
||||
case "round":
|
||||
err = this.Round(stack)
|
||||
err = pO.Round(stack)
|
||||
case "roll":
|
||||
err = this.Roll(stack)
|
||||
err = pO.Roll(stack)
|
||||
|
||||
case "sin":
|
||||
err = this.Sin(stack)
|
||||
err = pO.Sin(stack)
|
||||
case "sqrt":
|
||||
err = this.Sqrt(stack)
|
||||
err = pO.Sqrt(stack)
|
||||
case "sub":
|
||||
err = this.Sub(stack)
|
||||
err = pO.Sub(stack)
|
||||
|
||||
case "truncate":
|
||||
err = this.Truncate(stack)
|
||||
err = pO.Truncate(stack)
|
||||
|
||||
case "xor":
|
||||
err = this.Xor(stack)
|
||||
err = pO.Xor(stack)
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -257,7 +260,7 @@ func (this *PSOperand) Exec(stack *PSStack) error {
|
||||
// Operation implementations
|
||||
|
||||
// Absolute value.
|
||||
func (this *PSOperand) Abs(stack *PSStack) error {
|
||||
func (*PSOperand) Abs(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -285,7 +288,7 @@ func (this *PSOperand) Abs(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// 5 27 add -> 32
|
||||
func (this *PSOperand) Add(stack *PSStack) error {
|
||||
func (*PSOperand) Add(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -338,7 +341,7 @@ func (this *PSOperand) Add(stack *PSStack) error {
|
||||
// bool1 bool2 and -> bool3
|
||||
// if int: returns the bitwise "and" of the inputs
|
||||
// int1 int2 and -> int3
|
||||
func (this *PSOperand) And(stack *PSStack) error {
|
||||
func (*PSOperand) And(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -374,7 +377,7 @@ func (this *PSOperand) And(stack *PSStack) error {
|
||||
|
||||
// den num atan -> atan(num/den) in degrees.
|
||||
// result is a real value.
|
||||
func (this *PSOperand) Atan(stack *PSStack) error {
|
||||
func (*PSOperand) Atan(stack *PSStack) error {
|
||||
// Denominator
|
||||
den, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
@@ -409,7 +412,7 @@ func (this *PSOperand) Atan(stack *PSStack) error {
|
||||
|
||||
// bitshift
|
||||
// int1 shift bitshift -> int2
|
||||
func (this *PSOperand) Bitshift(stack *PSStack) error {
|
||||
func (*PSOperand) Bitshift(stack *PSStack) error {
|
||||
shift, err := stack.PopInteger()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -435,7 +438,7 @@ func (this *PSOperand) Bitshift(stack *PSStack) error {
|
||||
// Ceiling of number.
|
||||
// num1 ceiling -> num2
|
||||
// The type of the result is the same as of the operand.
|
||||
func (this *PSOperand) Ceiling(stack *PSStack) error {
|
||||
func (*PSOperand) Ceiling(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -454,7 +457,7 @@ func (this *PSOperand) Ceiling(stack *PSStack) error {
|
||||
|
||||
// Copy
|
||||
// any1 ... anyn n copy -> any1 ... anyn any1 ... anyn
|
||||
func (this *PSOperand) Copy(stack *PSStack) error {
|
||||
func (*PSOperand) Copy(stack *PSStack) error {
|
||||
n, err := stack.PopInteger()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -475,7 +478,7 @@ func (this *PSOperand) Copy(stack *PSStack) error {
|
||||
// Cosine
|
||||
// angle cos -> real
|
||||
// Angle is in degrees
|
||||
func (this *PSOperand) Cos(stack *PSStack) error {
|
||||
func (*PSOperand) Cos(stack *PSStack) error {
|
||||
angle, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -487,7 +490,7 @@ func (this *PSOperand) Cos(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// Convert to integer
|
||||
func (this *PSOperand) Cvi(stack *PSStack) error {
|
||||
func (*PSOperand) Cvi(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -507,7 +510,7 @@ func (this *PSOperand) Cvi(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// Convert number tor real
|
||||
func (this *PSOperand) Cvr(stack *PSStack) error {
|
||||
func (*PSOperand) Cvr(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -524,7 +527,7 @@ func (this *PSOperand) Cvr(stack *PSStack) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *PSOperand) Div(stack *PSStack) error {
|
||||
func (*PSOperand) Div(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -573,7 +576,7 @@ func (this *PSOperand) Div(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// Duplicates the top object on the stack (dup)
|
||||
func (this *PSOperand) Dup(stack *PSStack) error {
|
||||
func (*PSOperand) Dup(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -591,7 +594,7 @@ func (this *PSOperand) Dup(stack *PSStack) error {
|
||||
|
||||
// Check for equality.
|
||||
// any1 any2 eq bool
|
||||
func (this *PSOperand) Eq(stack *PSStack) error {
|
||||
func (*PSOperand) Eq(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -646,7 +649,7 @@ func (this *PSOperand) Eq(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// Exchange the top two elements of the stack (exch)
|
||||
func (this *PSOperand) Exch(stack *PSStack) error {
|
||||
func (*PSOperand) Exch(stack *PSStack) error {
|
||||
top, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -669,7 +672,7 @@ func (this *PSOperand) Exch(stack *PSStack) error {
|
||||
// base exponent exp -> base^exp
|
||||
// Raises base to exponent power.
|
||||
// The result is a real number.
|
||||
func (this *PSOperand) Exp(stack *PSStack) error {
|
||||
func (*PSOperand) Exp(stack *PSStack) error {
|
||||
exponent, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -691,7 +694,7 @@ func (this *PSOperand) Exp(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// Floor of number.
|
||||
func (this *PSOperand) Floor(stack *PSStack) error {
|
||||
func (*PSOperand) Floor(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -710,7 +713,7 @@ func (this *PSOperand) Floor(stack *PSStack) error {
|
||||
|
||||
// Greater than or equal
|
||||
// num1 num2 ge -> bool; num1 >= num2
|
||||
func (this *PSOperand) Ge(stack *PSStack) error {
|
||||
func (*PSOperand) Ge(stack *PSStack) error {
|
||||
num2, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -736,7 +739,7 @@ func (this *PSOperand) Ge(stack *PSStack) error {
|
||||
|
||||
// Greater than
|
||||
// num1 num2 gt -> bool; num1 > num2
|
||||
func (this *PSOperand) Gt(stack *PSStack) error {
|
||||
func (*PSOperand) Gt(stack *PSStack) error {
|
||||
num2, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -762,7 +765,7 @@ func (this *PSOperand) Gt(stack *PSStack) error {
|
||||
|
||||
// Integral division
|
||||
// 25 3 div -> 8
|
||||
func (this *PSOperand) IDiv(stack *PSStack) error {
|
||||
func (*PSOperand) IDiv(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -794,7 +797,7 @@ func (this *PSOperand) IDiv(stack *PSStack) error {
|
||||
|
||||
// If conditional
|
||||
// bool proc if -> run proc() if bool is true
|
||||
func (this *PSOperand) If(stack *PSStack) error {
|
||||
func (*PSOperand) If(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -825,7 +828,7 @@ func (this *PSOperand) If(stack *PSStack) error {
|
||||
|
||||
// If else conditional
|
||||
// bool proc1 proc2 ifelse -> execute proc1() if bool is true, otherwise proc2()
|
||||
func (this *PSOperand) IfElse(stack *PSStack) error {
|
||||
func (*PSOperand) IfElse(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -866,7 +869,7 @@ func (this *PSOperand) IfElse(stack *PSStack) error {
|
||||
// Add a copy of the nth object in the stack to the top.
|
||||
// any_n ... any_0 n index -> any_n ... any_0 any_n
|
||||
// index from 0
|
||||
func (this *PSOperand) Index(stack *PSStack) error {
|
||||
func (*PSOperand) Index(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -893,7 +896,7 @@ func (this *PSOperand) Index(stack *PSStack) error {
|
||||
|
||||
// Less or equal
|
||||
// num1 num2 le -> bool; num1 <= num2
|
||||
func (this *PSOperand) Le(stack *PSStack) error {
|
||||
func (*PSOperand) Le(stack *PSStack) error {
|
||||
num2, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -918,7 +921,7 @@ func (this *PSOperand) Le(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// num log -> real
|
||||
func (this *PSOperand) Log(stack *PSStack) error {
|
||||
func (*PSOperand) Log(stack *PSStack) error {
|
||||
// Value
|
||||
val, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
@@ -932,7 +935,7 @@ func (this *PSOperand) Log(stack *PSStack) error {
|
||||
|
||||
// num ln -> ln(num)
|
||||
// The result is a real number.
|
||||
func (this *PSOperand) Ln(stack *PSStack) error {
|
||||
func (*PSOperand) Ln(stack *PSStack) error {
|
||||
// Value
|
||||
val, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
@@ -946,7 +949,7 @@ func (this *PSOperand) Ln(stack *PSStack) error {
|
||||
|
||||
// Less than
|
||||
// num1 num2 lt -> bool; num1 < num2
|
||||
func (this *PSOperand) Lt(stack *PSStack) error {
|
||||
func (*PSOperand) Lt(stack *PSStack) error {
|
||||
num2, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -971,7 +974,7 @@ func (this *PSOperand) Lt(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// 12 10 mod -> 2
|
||||
func (this *PSOperand) Mod(stack *PSStack) error {
|
||||
func (*PSOperand) Mod(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1001,7 +1004,7 @@ func (this *PSOperand) Mod(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// 6 8 mul -> 48
|
||||
func (this *PSOperand) Mul(stack *PSStack) error {
|
||||
func (*PSOperand) Mul(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1051,21 +1054,21 @@ func (this *PSOperand) Mul(stack *PSStack) error {
|
||||
|
||||
// Not equal (inverse of eq)
|
||||
// any1 any2 ne -> bool
|
||||
func (this *PSOperand) Ne(stack *PSStack) error {
|
||||
func (pO *PSOperand) Ne(stack *PSStack) error {
|
||||
// Simply call equate and then negate the result.
|
||||
// Implementing directly could be more efficient, but probably not a big deal in most cases.
|
||||
err := this.Eq(stack)
|
||||
err := pO.Eq(stack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = this.Not(stack)
|
||||
err = pO.Not(stack)
|
||||
return err
|
||||
}
|
||||
|
||||
// Negate
|
||||
// 6 neg -> -6
|
||||
func (this *PSOperand) Neg(stack *PSStack) error {
|
||||
func (*PSOperand) Neg(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1086,7 +1089,7 @@ func (this *PSOperand) Neg(stack *PSStack) error {
|
||||
// Logical/bitwise negation
|
||||
// bool1 not -> bool2 (logical)
|
||||
// int1 not -> int2 (bitwise)
|
||||
func (this *PSOperand) Not(stack *PSStack) error {
|
||||
func (*PSOperand) Not(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1106,7 +1109,7 @@ func (this *PSOperand) Not(stack *PSStack) error {
|
||||
// OR logical/bitwise operation.
|
||||
// bool1 bool2 or -> bool3 (logical or)
|
||||
// int1 int2 or -> int3 (bitwise or)
|
||||
func (this *PSOperand) Or(stack *PSStack) error {
|
||||
func (*PSOperand) Or(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1141,7 +1144,7 @@ func (this *PSOperand) Or(stack *PSStack) error {
|
||||
}
|
||||
|
||||
// Remove the top element on the stack (pop)
|
||||
func (this *PSOperand) Pop(stack *PSStack) error {
|
||||
func (*PSOperand) Pop(stack *PSStack) error {
|
||||
_, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1151,7 +1154,7 @@ func (this *PSOperand) Pop(stack *PSStack) error {
|
||||
|
||||
// Round number off.
|
||||
// num1 round -> num2
|
||||
func (this *PSOperand) Round(stack *PSStack) error {
|
||||
func (*PSOperand) Round(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1173,7 +1176,7 @@ func (this *PSOperand) Round(stack *PSStack) error {
|
||||
// 7 8 9 3 1 roll -> 9 7 8
|
||||
// 7 8 9 3 -1 roll -> 8 9 7
|
||||
// n j roll
|
||||
func (this *PSOperand) Roll(stack *PSStack) error {
|
||||
func (*PSOperand) Roll(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1228,7 +1231,7 @@ func (this *PSOperand) Roll(stack *PSStack) error {
|
||||
// Sine.
|
||||
// angle sin -> real
|
||||
// Angle is in degrees
|
||||
func (this *PSOperand) Sin(stack *PSStack) error {
|
||||
func (*PSOperand) Sin(stack *PSStack) error {
|
||||
angle, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1242,7 +1245,7 @@ func (this *PSOperand) Sin(stack *PSStack) error {
|
||||
// Square root.
|
||||
// num sqrt -> real; real=sqrt(num)
|
||||
// The result is a real number.
|
||||
func (this *PSOperand) Sqrt(stack *PSStack) error {
|
||||
func (*PSOperand) Sqrt(stack *PSStack) error {
|
||||
val, err := stack.PopNumberAsFloat64()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1260,7 +1263,7 @@ func (this *PSOperand) Sqrt(stack *PSStack) error {
|
||||
// 8.3 6.6 sub -> 1.7 (real)
|
||||
// 8 6.3 sub -> 1.7 (real)
|
||||
// 8 6 sub -> 2 (int)
|
||||
func (this *PSOperand) Sub(stack *PSStack) error {
|
||||
func (*PSOperand) Sub(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1311,7 +1314,7 @@ func (this *PSOperand) Sub(stack *PSStack) error {
|
||||
// Truncate number.
|
||||
// num1 truncate -> num2
|
||||
// The resulting number is the same type as the input.
|
||||
func (this *PSOperand) Truncate(stack *PSStack) error {
|
||||
func (*PSOperand) Truncate(stack *PSStack) error {
|
||||
obj, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1332,7 +1335,7 @@ func (this *PSOperand) Truncate(stack *PSStack) error {
|
||||
// XOR logical/bitwise operation.
|
||||
// bool1 bool2 xor -> bool3 (logical xor)
|
||||
// int1 int2 xor -> int3 (bitwise xor)
|
||||
func (this *PSOperand) Xor(stack *PSStack) error {
|
||||
func (*PSOperand) Xor(stack *PSStack) error {
|
||||
obj1, err := stack.Pop()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user