object

package
v0.0.0-...-dd3e944 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package object how the interpretor holds objects during execution

Index

Constants

View Source
const (
	GWBlack     = iota // 0
	GWBlue             // 1
	GWGreen            // 2
	GWCyan             // 3
	GWRed              // 4
	GWMagenta          // 5
	GWBrown            // 6
	GWWhite            // 7
	GWGray             // 8
	GWLtBlue           // 9
	GWLtGreen          // 10
	GWLtCyan           // 11
	GWLtRed            // 12
	GWLtMagenta        // 13
	GWYellow           // 14
	GWBrtWhite         // 15
)

GWBasic color values for screen work,https://hwiegman.home.xs4all.nl/gw-man/SCREENS.html

View Source
const (
	//	XBlack   = iota + 90 // 90
	XRed     = iota + 91 // 91
	XGreen               // 92
	XYellow              // 93
	XBlue                // 94
	XMagenta             // 95
	XCyan                // 96
	XWhite               // 97
	XBlack   = 30
)

XTermjs color directives,https://xtermjs.org/docs/api/vtfeatures/

View Source
const (
	ARRAY_OBJ      = "ARRAY"
	AUTO_OBJ       = "AUTO"
	BSTR_OBJ       = "BSTR"
	BUILTIN_OBJ    = "BUILTIN"
	FILE_OBJ       = "FILE"
	FIXED_OBJ      = "FIXED"
	FLOATSGL_OBJ   = "FLOATSGL"
	FLOATDBL_OBJ   = "FLOATDBL"
	FUNCTION_OBJ   = "FUNCTION"
	ERROR_OBJ      = "ERROR"
	HALT_SIGNAL    = "HALT"
	INTEGER_OBJ    = "INTEGER"
	INTEGER_DBL    = "INTDBL"
	NULL_OBJ       = "NULL"
	RESTART_SIGNAL = "RESTART"
	STRING_OBJ     = "STRING"
	TYPED_OBJ      = "TYPED"
)
View Source
const DefaultDimSize = 10

size of arrays that haven't been DIM'd

Variables

This section is empty.

Functions

func DecodeBytes

func DecodeBytes(bts []byte) string

convert the CP437 values to a strings

Types

type Array

type Array struct {
	Elements []Object
	TypeID   string
}

holds an array of Objects

func (*Array) Inspect

func (ao *Array) Inspect() string

func (*Array) Type

func (ao *Array) Type() ObjectType

type Auto

type Auto struct {
	Next int // the next line number to use
	Step int // the step to add to next each time
}

When auto is on, this holds the current state

func (*Auto) Inspect

func (a *Auto) Inspect() string

func (*Auto) Type

func (a *Auto) Type() ObjectType

type BStr

type BStr struct {
	Value []byte
}

BStr is a byte backed string not COMmonly used parser won't generate one they only occur at run-time

func (*BStr) Inspect

func (bs *BStr) Inspect() string

Inspect returns a displayable string

func (*BStr) Type

func (bs *BStr) Type() ObjectType

Type returns my type BSTR_OBJ

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

type BuiltinFunction func(env *Environment, fn *Builtin, args ...Object) Object

BuiltinFunction is a function defined by gwbasic

type Console

type Console interface {
	// Cls clears the screen contents
	Cls()
	// Print outputs the passed string at the curent cursor position
	Print(string)
	// Println prints the string followed by a CR/LF
	Println(string)

	// Locate moves the cursor to the desired (row, col)
	Locate(int, int)
	// Log string to browser debug console
	Log(string)
	// GetCursor, return cursor location(row, col)
	GetCursor() (int, int)
	// Read, return contents of screen range
	Read(col, row, len int) string
	// ReadKeys reads up to (count) keycode values
	ReadKeys(count int) []byte
	// SoundBell emits facsimile of a console beep
	SoundBell()
	// BreakCheck returns true if a ctrl-c was entere
	BreakCheck() bool
}

Console defines how to collect input and display output

type Environment

type Environment struct {
	ForLoops []ForBlock // any For Loops that are active
	// contains filtered or unexported fields
}

Environment holds my variables and possibly an outer environment

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment allows variables during function calls

func NewTermEnvironment

func NewTermEnvironment(term Console) *Environment

NewTermEnvironment creates an environment with a terminal front-end

func (*Environment) AddCmdStmt

func (e *Environment) AddCmdStmt(stmt ast.Statement)

func (*Environment) AddOpenFile

func (e *Environment) AddOpenFile(num int16, file gwtypes.AnOpenFile)

func (*Environment) AddStatement

func (e *Environment) AddStatement(stmt ast.Statement)

Add a statement to the ast

func (*Environment) ClearCommon

func (e *Environment) ClearCommon()

ClearCommon variables

func (*Environment) ClearVars

func (e *Environment) ClearVars()

ClearVars empties the map of environment objects

func (*Environment) CloseAllFiles

func (e *Environment) CloseAllFiles()

CloseAllFiles closes all open files

func (*Environment) CloseFile

func (e *Environment) CloseFile(f int16) bool

CloseFile closes a file based on its handle

func (*Environment) ClrSetting

func (e *Environment) ClrSetting(name string)

clear a setting

func (*Environment) CmdComplete

func (e *Environment) CmdComplete()

func (*Environment) CmdLineIter

func (e *Environment) CmdLineIter() *ast.Code

func (*Environment) CmdParsed

func (e *Environment) CmdParsed()

Command line has been parsed

func (*Environment) Common

func (e *Environment) Common(name string)

preserve a variable across a chain

func (*Environment) ConstData

func (e *Environment) ConstData() *ast.ConstData

return the programs constant data

func (*Environment) FindOpenFiles

func (e *Environment) FindOpenFiles(file string) []gwtypes.AnOpenFile

find all the currently open instances of files that match the fully qualified file name provided

func (*Environment) Get

func (e *Environment) Get(name string) Object

Get attempts to retrieve an object from the environment, nil if not found

func (*Environment) GetClient

func (e *Environment) GetClient() HttpClient

GetClient returns my http client

func (*Environment) GetSetting

func (e *Environment) GetSetting(name string) ast.Node

Fetch a runtime setting

func (*Environment) GetTrace

func (e *Environment) GetTrace() bool

GetTrace returns true if we are tracing

func (*Environment) NewProgram

func (e *Environment) NewProgram()

NewProgram makes sure the program has been initialized

func (*Environment) Parsed

func (e *Environment) Parsed()

Signals that the program has been parsed

func (*Environment) Pop

func (e *Environment) Pop() *ast.RetPoint

Pop a return address, nil means stack is empty

func (*Environment) ProgramRunning

func (e *Environment) ProgramRunning() bool

Quick test to see if program is currently running

func (*Environment) Push

func (e *Environment) Push(ret ast.RetPoint) int

Push an address, returns stack size

func (*Environment) Random

func (e *Environment) Random(x int) *FloatSgl

Random returns a random number between 0 and 1 if x is greater than zero, a new random number is generated otherwise, the current rndVal is returned

func (*Environment) Randomize

func (e *Environment) Randomize(seed int64)

Randomize takes in a new seed and starts a new random series

func (*Environment) ReadOnly

func (e *Environment) ReadOnly(v string) bool

check if a variable name is defined read only

func (*Environment) SaveSetting

func (e *Environment) SaveSetting(name string, obj ast.Node)

Save a runtime setting

func (*Environment) Set

func (e *Environment) Set(name string, val Object) Object

Set stores an object in the environment

func (*Environment) SetClient

func (e *Environment) SetClient(cl HttpClient)

SetClient setter for the client element mostly used for testing

func (*Environment) SetRun

func (e *Environment) SetRun(run bool)

SetRun controls the "a program is running"

func (*Environment) SetTrace

func (e *Environment) SetTrace(on bool)

SetTrace turns it on or off

func (*Environment) StatementIter

func (e *Environment) StatementIter() *ast.Code

func (*Environment) Terminal

func (e *Environment) Terminal() Console

Terminal allows access to the termianl console

type Error

type Error struct {
	Message string // text error message
	Code    int    // basic internal error code
}

func StdError

func StdError(env *Environment, err int) *Error

StdError returns both the GWBASIC message, and error code for a basic error

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Fixed

type Fixed struct {
	Value decimal.Decimal
}

Fixed decimal point value

func (*Fixed) Inspect

func (f *Fixed) Inspect() string

func (*Fixed) Type

func (f *Fixed) Type() ObjectType

type FloatDbl

type FloatDbl struct {
	Value float64
}

Double precision floats

func (*FloatDbl) Inspect

func (fd *FloatDbl) Inspect() string

func (*FloatDbl) Type

func (fd *FloatDbl) Type() ObjectType

type FloatSgl

type FloatSgl struct {
	Value float32 // value of the float
}

Single precision floats

func (*FloatSgl) Inspect

func (fs *FloatSgl) Inspect() string

func (*FloatSgl) Type

func (fs *FloatSgl) Type() ObjectType

type ForBlock

type ForBlock struct {
	Code ast.RetPoint      // the location in the AST of the FOR statement
	Four *ast.ForStatement // the actual statement
}

type Function

type Function struct {
	Parameters []*ast.Identifier
	Body       *ast.BlockStatement
	Env        *Environment
}

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type HaltSignal

type HaltSignal struct {
	Msg string
}

HaltSignal tells the eval loop to stop executing

func (*HaltSignal) Inspect

func (hs *HaltSignal) Inspect() string

func (*HaltSignal) Type

func (hs *HaltSignal) Type() ObjectType

type HttpClient

type HttpClient interface {
	//Do(req *http.Request) (*http.Response, error)
	Get(url string) (*http.Response, error)
}

HttpClient allows me to mock an http.Client, minimally

type IntDbl

type IntDbl struct {
	Value int32 // 32bit value
}

IntDbl values

func (*IntDbl) Inspect

func (id *IntDbl) Inspect() string

Inspect returns value as a string

func (*IntDbl) Type

func (id *IntDbl) Type() ObjectType

Type returns my type

type Integer

type Integer struct {
	Value int16
}

Integer values

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns value as a string

func (*Integer) Type

func (i *Integer) Type() ObjectType

Type returns my type

type Null

type Null struct{}

func (*Null) Inspect

func (n *Null) Inspect() string

func (*Null) Type

func (n *Null) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string
}

type ObjectType

type ObjectType string

ObjectType can always be displayed as a string

type RestartSignal

type RestartSignal struct{}

RestartSignal restarts the eval loop after a chain

func (*RestartSignal) Inspect

func (rs *RestartSignal) Inspect() string

func (*RestartSignal) Type

func (rs *RestartSignal) Type() ObjectType

type String

type String struct {
	Value string
}

String values

func (*String) Inspect

func (i *String) Inspect() string

Inspect returns value as a string

func (*String) Type

func (i *String) Type() ObjectType

Type returns my type

type TypedVar

type TypedVar struct {
	Value  Object
	TypeID string
}

func (*TypedVar) Inspect

func (tv *TypedVar) Inspect() string

func (*TypedVar) Type

func (tv *TypedVar) Type() ObjectType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL