Object represents an object in the VM.
| 25 | |
| 26 | // Object represents an object in the VM. |
| 27 | type Object interface { |
| 28 | // TypeName should return the name of the type. |
| 29 | TypeName() string |
| 30 | |
| 31 | // String should return a string representation of the type's value. |
| 32 | String() string |
| 33 | |
| 34 | // BinaryOp should return another object that is the result of a given |
| 35 | // binary operator and a right-hand side object. If BinaryOp returns an |
| 36 | // error, the VM will treat it as a run-time error. |
| 37 | BinaryOp(op token.Token, rhs Object) (Object, error) |
| 38 | |
| 39 | // IsFalsy should return true if the value of the type should be considered |
| 40 | // as falsy. |
| 41 | IsFalsy() bool |
| 42 | |
| 43 | // Equals should return true if the value of the type should be considered |
| 44 | // as equal to the value of another object. |
| 45 | Equals(another Object) bool |
| 46 | |
| 47 | // Copy should return a copy of the type (and its value). Copy function |
| 48 | // will be used for copy() builtin function which is expected to deep-copy |
| 49 | // the values generally. |
| 50 | Copy() Object |
| 51 | |
| 52 | // IndexGet should take an index Object and return a result Object or an |
| 53 | // error for indexable objects. Indexable is an object that can take an |
| 54 | // index and return an object. If error is returned, the runtime will treat |
| 55 | // it as a run-time error and ignore returned value. If Object is not |
| 56 | // indexable, ErrNotIndexable should be returned as error. If nil is |
| 57 | // returned as value, it will be converted to UndefinedToken value by the |
| 58 | // runtime. |
| 59 | IndexGet(index Object) (value Object, err error) |
| 60 | |
| 61 | // IndexSet should take an index Object and a value Object for index |
| 62 | // assignable objects. Index assignable is an object that can take an index |
| 63 | // and a value on the left-hand side of the assignment statement. If Object |
| 64 | // is not index assignable, ErrNotIndexAssignable should be returned as |
| 65 | // error. If an error is returned, it will be treated as a run-time error. |
| 66 | IndexSet(index, value Object) error |
| 67 | |
| 68 | // Iterate should return an Iterator for the type. |
| 69 | Iterate() Iterator |
| 70 | |
| 71 | // CanIterate should return whether the Object can be Iterated. |
| 72 | CanIterate() bool |
| 73 | |
| 74 | // Call should take an arbitrary number of arguments and returns a return |
| 75 | // value and/or an error, which the VM will consider as a run-time error. |
| 76 | Call(args ...Object) (ret Object, err error) |
| 77 | |
| 78 | // CanCall should return whether the Object can be Called. |
| 79 | CanCall() bool |
| 80 | } |
| 81 | |
| 82 | // ObjectImpl represents a default Object Implementation. To defined a new |
| 83 | // value type, one can embed ObjectImpl in their type declarations to avoid |
no outgoing calls
no test coverage detected
searching dependent graphs…