Documentation ¶
Overview ¶
Package builtin contains the implementation for the core functions implemented for BASIC, such as SIN, COS, RND, PRINT, etc.
The builtin package also provides an interface which with you can extent the interpreter to supply new primitives, for example you might implement RANDOM, PEEK, POKE, or something entirely different.
Examples of extending the interpreter exist within the `goserver/` and `embed/` packages within the distribution.
Index ¶
- func ABS(env Environment, args []object.Object) object.Object
- func ACS(env Environment, args []object.Object) object.Object
- func ASN(env Environment, args []object.Object) object.Object
- func ATN(env Environment, args []object.Object) object.Object
- func BIN(env Environment, args []object.Object) object.Object
- func CHR(env Environment, args []object.Object) object.Object
- func CODE(env Environment, args []object.Object) object.Object
- func COS(env Environment, args []object.Object) object.Object
- func DUMP(env Environment, args []object.Object) object.Object
- func EXP(env Environment, args []object.Object) object.Object
- func INT(env Environment, args []object.Object) object.Object
- func LEFT(env Environment, args []object.Object) object.Object
- func LEN(env Environment, args []object.Object) object.Object
- func LN(env Environment, args []object.Object) object.Object
- func MID(env Environment, args []object.Object) object.Object
- func PI(env Environment, args []object.Object) object.Object
- func PRINT(env Environment, args []object.Object) object.Object
- func RIGHT(env Environment, args []object.Object) object.Object
- func RND(env Environment, args []object.Object) object.Object
- func SGN(env Environment, args []object.Object) object.Object
- func SIN(env Environment, args []object.Object) object.Object
- func SPC(env Environment, args []object.Object) object.Object
- func SQR(env Environment, args []object.Object) object.Object
- func STR(env Environment, args []object.Object) object.Object
- func TAN(env Environment, args []object.Object) object.Object
- func TL(env Environment, args []object.Object) object.Object
- func VAL(env Environment, args []object.Object) object.Object
- type Builtins
- type Environment
- type Signature
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BIN ¶
func BIN(env Environment, args []object.Object) object.Object
BIN converts a number from binary.
func CHR ¶
func CHR(env Environment, args []object.Object) object.Object
CHR returns the character specified by the given ASCII code.
func CODE ¶
func CODE(env Environment, args []object.Object) object.Object
CODE returns the integer value of the specified character.
func COS ¶
func COS(env Environment, args []object.Object) object.Object
COS implements the COS function..
func DUMP ¶
func DUMP(env Environment, args []object.Object) object.Object
DUMP just displays the only argument it received.
func LEFT ¶
func LEFT(env Environment, args []object.Object) object.Object
LEFT returns the N left-most characters of the string.
func LEN ¶
func LEN(env Environment, args []object.Object) object.Object
LEN returns the length of the given string
func LN ¶
func LN(env Environment, args []object.Object) object.Object
LN calculates logarithms to the base e - LN
func MID ¶
func MID(env Environment, args []object.Object) object.Object
MID returns the N characters from the given offset
func PRINT ¶
func PRINT(env Environment, args []object.Object) object.Object
PRINT handles displaying strings, integers, and errors.
func RIGHT ¶
func RIGHT(env Environment, args []object.Object) object.Object
RIGHT returns the N right-most characters of the string.
func SGN ¶
func SGN(env Environment, args []object.Object) object.Object
SGN is the sign function (sometimes called signum).
func SIN ¶
func SIN(env Environment, args []object.Object) object.Object
SIN operats the sin function.
func SPC ¶
func SPC(env Environment, args []object.Object) object.Object
SPC returns a string containing the given number of spaces
func SQR ¶
func SQR(env Environment, args []object.Object) object.Object
SQR implements square root.
func STR ¶
func STR(env Environment, args []object.Object) object.Object
STR converts a number to a string
func TAN ¶
func TAN(env Environment, args []object.Object) object.Object
TAN implements the tan function.
Types ¶
type Builtins ¶
type Builtins struct {
// contains filtered or unexported fields
}
Builtins holds our state.
func (*Builtins) Register ¶
Register records a built-in function. The three arguments are:
NAME - The thing that the BASIC program will call nARGS - The number of arguments the built-in requires. NOTE: Arguments are comma-separated in the BASIC program, but commas are stripped out. FT - The function which provides the implementation.
type Environment ¶
type Environment interface { // StdInput is a handle to a reader-object, allowing input to // be processed by the built-ins. StdInput() *bufio.Reader // StdOutput is a handle to a writer-object, allowing output to // be generated by the built-ins. StdOutput() *bufio.Writer // StdError is a handle to a writer-object, allowing user errors to // be communicated by the built-ins. StdError() *bufio.Writer // LineEnding specifies any additional characters that should be // appended to PRINT commands - for example '\n' LineEnding() string // Data allows the builtins to get a reference to the intepreter. Data() interface{} }
Environment is an interface which is passed to all built-in functions.
type Signature ¶
type Signature func(env Environment, args []object.Object) object.Object
Signature is the signature of a builtin-function.
Each built-in will receive an array of objects, and will return a single object back to the caller.
In the case of an error then the object will be an error-object.