Documentation
¶
Overview ¶
Package object contains code to store values passed to/from BASIC.
Go allows a rich number of types, but when interpreting BASIC programs we only support numbers & strings, as well as two-dimensional arrays containing those values.
Note that numbers are stored as `float64`, to allow holding both integers and floating-point numbers.
Index ¶
Constants ¶
const ( ERROR = "ERROR" NUMBER = "NUMBER" STRING = "STRING" ARRAY = "ARRAY" )
These are our object-types.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayObject ¶
type ArrayObject struct { // We store objects in our array Contents []Object // X is the X-size of the array, fixed at creation-time X int // Y is the Y-size of the array, fixed at creation-time. Y int }
ArrayObject holds an array.
We allow only two-dimensional arrays, and the size is set at the time the array is constructed.
func Array ¶
func Array(x int, y int) *ArrayObject
Array creates a new array of the given dimensions
func (*ArrayObject) Get ¶
func (a *ArrayObject) Get(x int, y int) Object
Get the value at the given X,Y coordinate
func (*ArrayObject) Set ¶
func (a *ArrayObject) Set(x int, y int, obj Object) Object
Set the value at the given X,Y coordinate
func (*ArrayObject) String ¶
func (a *ArrayObject) String() string
String returns the string-contents of the string
type ErrorObject ¶
type ErrorObject struct { // Value is the message our object wraps. Value string }
ErrorObject holds a string, which describes an error
func Error ¶
func Error(format string, args ...interface{}) *ErrorObject
Error is a helper for creating a new error-object with the given message.
func (*ErrorObject) String ¶
func (eo *ErrorObject) String() string
String returns a string representation of this object.
type NumberObject ¶
type NumberObject struct { // Value is the value our object wraps. Value float64 }
NumberObject holds a number.
func Number ¶
func Number(val float64) *NumberObject
Number is a helper for creating a new number-object with the given value.
func (*NumberObject) String ¶
func (no *NumberObject) String() string
String returns a string representation of this object.
func (*NumberObject) Type ¶
func (no *NumberObject) Type() Type
Type returns the type of this object.
type Object ¶
type Object interface { // Type returns the type of the object. Type() Type // String converts the object to a printable version for debugging. String() string }
Object is the interface that our types must implement.
type StringObject ¶
type StringObject struct { // Value is the value our object wraps. Value string }
StringObject holds a string.
func String ¶
func String(val string) *StringObject
String is a helper for creating a new string-object with the given value.
func (*StringObject) String ¶
func (s *StringObject) String() string
String returns a string representation of this object.
func (*StringObject) Type ¶
func (s *StringObject) Type() Type
Type returns the type of this object.