Retro Rocket Kernel BASIC-Powered Operating System

Data Fields
ubasic_ctx Struct Reference

BASIC program context. Every instance of a BASIC program has one of these,* also certain structures such as functions will clone the context and run on the clone until the function completes. Cloned contexts share variables and you should never call ubasic_destroy() on them! More...

`#include <ubasic.h>`

Collaboration diagram for ubasic_ctx:
[legend]

## Data Fields
char const * | ptr
| Pointer to the start of the next token Always between program_ptr and program_ptr + strlen(program_ptr) More...
char const * | nextptr
| Pointer to the character after the next token. Always between program_ptr and program_ptr + strlen(program_ptr) More...
int | current_token
| Numeric form of the token between ptr and nextptr. Should always be a value within the enum token_t. More...
int64_t | current_linenum
| Current line number. More...
bool | errored
| True if the program has thrown an error and should end. This may not actually cause termination of the program if we are inside an EVAL at the time. More...
bool | ended
| True if the program has ended, e.g. it reached an explicit END statement, or fell off the end of the program to the terminating null char. More...
char * | program_ptr
| The whole program text, untokenized. May have been "cleaned" by an initial preprocessing phase which removes unneccesary spacing etc. More...
char | string [1024]
| A context-local string buffer used for parsing function/procedure parameter lists. More...
struct ub_var_int * | local_int_variables [255]
| Local integer variable stack for variables declared within a function or procedure scope. More...
struct ub_var_string * | local_string_variables [255]
| Local string variable stack for variables declared within a function or procedure scope. More...
struct ub_var_double * | local_double_variables [255]
| Local real (double) variable stack for variables declared within a function or procedure scope. More...
uint64_t | call_stack [255]
| Call stack, holds the return line numbers for each level of calls to a procedure, function or GOSUB. More...
uint64_t | call_stack_ptr
| How far up the call stack we are. The call stack pointer starts at 0, and can go as high as MAX_CALL_STACK_DEPTH - 1. More...
uint64_t | repeat_stack [255]
| Repeat stack, holds the return line numbers for each level of REPEAT...UNTIL loop. More...
uint64_t | repeat_stack_ptr
| How far up the REPEAT...UNTIL stack we are. The repeat stack pointer starts at 0, and can go as high as MAX_LOOP_STACK_DEPTH - 1. More...
size_t | oldlen
| Previous program length, before an EVAL statement. An EVAL statement appends additional lines to the program beyond its original end, storing the previous size in this value. If this value is non-zero an EVAL is in progress, otherwise no EVAL is executing. More...
int64_t | eval_linenum
| The return line number for an EVAL statement. More...
struct for_state | for_stack [255]
| FOR stack, holds the return line numbers for each level of FOR...NEXT loop. More...
uint64_t | for_stack_ptr
| How far up the FOR...NEXT stack we are. The FOR stack pointer starts at 0, and can go as high as MAX_LOOP_STACK_DEPTH - 1. More...
struct ub_proc_fn_def * | defs
| Definitions for procedures and functions in the program. More...
struct ub_var_int * | int_variables
| Global integer variable list. More...
struct ub_var_string * | str_variables
| Global string variable list. More...
struct ub_var_double * | double_variables
| Global double variable list. More...
struct ub_var_int_array * | int_array_variables
| Global integer array variable list. More...
struct ub_var_string_array * | string_array_variables
| Global string array variable list. More...
struct ub_var_double_array * | double_array_variables
| Global double array variable list. More...
struct console * | cons
| I/O Console. More...
ub_return_type | fn_type
| Function return type expected. This is only relavent when executing a function atomically. More...
void * | fn_return
| Function return value pointer. This is only relavent when executing a function atomically. More...
int | bracket_depth
| Bracket depth when parsing function or procedure parameter lists. More...
char const * | item_begin
| Item start pointer when parsing function or procedure parameter lists. More...
struct ub_param * | param
| Linked list of function parameters when parsing function or procedure parameter lists. More...
int32_t | graphics_colour
| Current graphics colour (GCOL) for graphics drawing commands. More...
struct hashmap * | lines
| Hashmap of lines for O(1) lookup of line numbers. More...
uint64_t | if_nest_level
| Block IF...THEN...ELSE depth. More...

## Detailed Description

BASIC program context. Every instance of a BASIC program has one of these,* also certain structures such as functions will clone the context and run on the clone until the function completes. Cloned contexts share variables and you should never call ubasic_destroy() on them!

## Field Documentation

## ◆ bracket_depth

int ubasic_ctx::bracket_depth

Bracket depth when parsing function or procedure parameter lists.

## ◆ call_stack

uint64_t ubasic_ctx::call_stack[255]

Call stack, holds the return line numbers for each level of calls to a procedure, function or GOSUB.

## ◆ call_stack_ptr

uint64_t ubasic_ctx::call_stack_ptr

How far up the call stack we are. The call stack pointer starts at 0, and can go as high as MAX_CALL_STACK_DEPTH - 1.

## ◆ cons

struct console* ubasic_ctx::cons

I/O Console.

## ◆ current_linenum

int64_t ubasic_ctx::current_linenum

Current line number.

## ◆ current_token

int ubasic_ctx::current_token

Numeric form of the token between ptr and nextptr. Should always be a value within the enum token_t.

## ◆ defs

struct ub_proc_fn_def* ubasic_ctx::defs

Definitions for procedures and functions in the program.

## ◆ double_array_variables

struct ub_var_double_array* ubasic_ctx::double_array_variables

Global double array variable list.

## ◆ double_variables

struct ub_var_double* ubasic_ctx::double_variables

Global double variable list.

## ◆ ended

bool ubasic_ctx::ended

True if the program has ended, e.g. it reached an explicit END statement, or fell off the end of the program to the terminating null char.

## ◆ errored

bool ubasic_ctx::errored

True if the program has thrown an error and should end. This may not actually cause termination of the program if we are inside an EVAL at the time.

## ◆ eval_linenum

int64_t ubasic_ctx::eval_linenum

The return line number for an EVAL statement.

## ◆ fn_return

void* ubasic_ctx::fn_return

Function return value pointer. This is only relavent when executing a function atomically.

## ◆ fn_type

ub_return_type ubasic_ctx::fn_type

Function return type expected. This is only relavent when executing a function atomically.

## ◆ for_stack

struct for_state ubasic_ctx::for_stack[255]

FOR stack, holds the return line numbers for each level of FOR...NEXT loop.

## ◆ for_stack_ptr

uint64_t ubasic_ctx::for_stack_ptr

How far up the FOR...NEXT stack we are. The FOR stack pointer starts at 0, and can go as high as MAX_LOOP_STACK_DEPTH - 1.

## ◆ graphics_colour

int32_t ubasic_ctx::graphics_colour

Current graphics colour (GCOL) for graphics drawing commands.

## ◆ if_nest_level

uint64_t ubasic_ctx::if_nest_level

Block IF...THEN...ELSE depth.

## ◆ int_array_variables

struct ub_var_int_array* ubasic_ctx::int_array_variables

Global integer array variable list.

## ◆ int_variables

struct ub_var_int* ubasic_ctx::int_variables

Global integer variable list.

## ◆ item_begin

char const* ubasic_ctx::item_begin

Item start pointer when parsing function or procedure parameter lists.

## ◆ lines

struct hashmap* ubasic_ctx::lines

Hashmap of lines for O(1) lookup of line numbers.

## ◆ local_double_variables

struct ub_var_double* ubasic_ctx::local_double_variables[255]

Local real (double) variable stack for variables declared within a function or procedure scope.

## ◆ local_int_variables

struct ub_var_int* ubasic_ctx::local_int_variables[255]

Local integer variable stack for variables declared within a function or procedure scope.

## ◆ local_string_variables

struct ub_var_string* ubasic_ctx::local_string_variables[255]

Local string variable stack for variables declared within a function or procedure scope.

## ◆ nextptr

char const* ubasic_ctx::nextptr

Pointer to the character after the next token. Always between program_ptr and program_ptr + strlen(program_ptr)

## ◆ oldlen

size_t ubasic_ctx::oldlen

Previous program length, before an EVAL statement. An EVAL statement appends additional lines to the program beyond its original end, storing the previous size in this value. If this value is non-zero an EVAL is in progress, otherwise no EVAL is executing.

## ◆ param

struct ub_param* ubasic_ctx::param

Linked list of function parameters when parsing function or procedure parameter lists.

## ◆ program_ptr

char* ubasic_ctx::program_ptr

The whole program text, untokenized. May have been "cleaned" by an initial preprocessing phase which removes unneccesary spacing etc.

## ◆ ptr

char const* ubasic_ctx::ptr

Pointer to the start of the next token Always between program_ptr and program_ptr + strlen(program_ptr)

## ◆ repeat_stack

uint64_t ubasic_ctx::repeat_stack[255]

Repeat stack, holds the return line numbers for each level of REPEAT...UNTIL loop.

## ◆ repeat_stack_ptr

uint64_t ubasic_ctx::repeat_stack_ptr

How far up the REPEAT...UNTIL stack we are. The repeat stack pointer starts at 0, and can go as high as MAX_LOOP_STACK_DEPTH - 1.

## ◆ str_variables

struct ub_var_string* ubasic_ctx::str_variables

Global string variable list.

## ◆ string

char ubasic_ctx::string[1024]

A context-local string buffer used for parsing function/procedure parameter lists.

## ◆ string_array_variables

struct ub_var_string_array* ubasic_ctx::string_array_variables

Global string array variable list.