BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
rievallib.c File Reference
#include "blitzlib.h"

Data Structures

struct  op
struct  chunk
struct  state

Macros

#define CHUNK   32
#define PUSH(s, x)

Functions

void _ConvToPostFix (void)
void _evaluate (void)
void _registers (void)
void _PFErrorType (void)
void _PFErrorText (void)
void _PFIndirectAddr (void)
static void _libinit (void)
 init: no register block, no error and no indirect address yet.
static void _libfinit (void)
 finit: nothing (RTS).
static void st_init (struct state *s, struct chunk *k)
static int st_empty (const struct state *s)
static int st_push (struct state *s, ULONG x)
static ULONG * st_top (struct state *s)
static ULONG st_pop (struct state *s)
static ULONG grow (struct state *s, ULONG x)
static int is_operator (UBYTE c)
static ULONG ctp_loop (struct state *s)
static void convtopostfix_c (UBYTE *str, UBYTE *buf)
 ConvToPostFix string,buffer: converts an infix expression to postfix.
static ULONG lmult (ULONG lhs, ULONG *rhs)
static ULONG ldivide (ULONG dividend, ULONG *divisor)
static ULONG ev_error (const char *text, UWORD type)
static int ev_indirect (struct state *s)
static ULONG ev_loop (struct state *s)
static ULONG evaluate_c (UBYTE *str)
 PFEvaluate(string): evaluates a postfix expression of ConvToPostFix.
static void registers_c (ULONG block)
 PFRegisters *registerblock: the register block of PFEvaluate.
static ULONG errortype_c (ULONG result)
 PFErrorType: the number of the last PFEvaluate error, 0 for none.
static ULONG errortext_c (void)
 PFErrorText: the text of the last PFEvaluate error.
static ULONG indirectaddr_c (void)
 PFIndirectAddr: the address of the last {...} indirection.

Variables

static const struct op operators []
static const char err_arg [] = "Need 2 arguments for expression!"
static const char err_reg [] = "Register structure not found!"
static const char err_noresult [] = "No result value!"
static const char err_divide0 [] = "Divide by 0 error!"
static const char err_close [] = "No close bracket on indirect!"
static const char err_size [] = "Invalid size for indirection!"
static ULONG lastaddr
static UBYTE negative
static UBYTE indirect
static ULONG argc
static ULONG regs
static UWORD errortype
static const char * errortext

Macro Definition Documentation

◆ CHUNK

#define CHUNK   32

◆ PUSH

#define PUSH ( s,
x )
Value:
do { if (!st_push((s), (x))) return grow((s), (x)); } while (0)
ULONG x
Definition 2dlib.c:2491
static ULONG grow(struct state *s, ULONG x)
Definition rievallib.c:260
static int st_push(struct state *s, ULONG x)
Definition rievallib.c:226

Function Documentation

◆ _ConvToPostFix()

void _ConvToPostFix ( void )

◆ _evaluate()

void _evaluate ( void )

◆ _libfinit()

void _libfinit ( void )
static

finit: nothing (RTS).

◆ _libinit()

void _libinit ( void )
static

init: no register block, no error and no indirect address yet.

Fixed (#1087): the original's init is RTS, so a second run of the program with the library still loaded (from the editor) started with the first run's block (freed at its end), its last error number and the address of its last indirection.

◆ _PFErrorText()

void _PFErrorText ( void )

◆ _PFErrorType()

void _PFErrorType ( void )

◆ _PFIndirectAddr()

void _PFIndirectAddr ( void )

◆ _registers()

void _registers ( void )

◆ convtopostfix_c()

void convtopostfix_c ( UBYTE * str,
UBYTE * buf )
static

ConvToPostFix string,buffer: converts an infix expression to postfix.

Lower-cases the string in place, then writes the operands and operators separated by spaces to the buffer (0 terminated), with an operator stack; "(" ... ")" group. A - is a sign at the start or after an operator or (, spaces between skipped (fixed, #633). A . copies the character behind it, not the string's 0 (fixed, #631). Every other character of an operand is kept, for PFEvaluate to reject (fixed, #632). a3 is left at the string (a statement: nothing uses it after it).

Parameters
strd0: the expression (changed: lower case)
bufd1: the output buffer

◆ ctp_loop()

ULONG ctp_loop ( struct state * s)
static

◆ errortext_c()

ULONG errortext_c ( void )
static

PFErrorText: the text of the last PFEvaluate error.

The text at a3 (a3 ends at its 0), d0 = its length. With no error nothing is written and the length is 0. Fixed (#640): the original set only d0.w (MOVE.w errortype,d0), the upper word of the length was the caller's.

Returns
d0: the length of the text, 0 without an error

◆ errortype_c()

ULONG errortype_c ( ULONG result)
static

PFErrorType: the number of the last PFEvaluate error, 0 for none.

MOVE.w errortype,d0: the caller's upper word of d0 stays (a word result, no defect).

Parameters
resultd0: the caller's d0
Returns
d0.w: the error number (1-6) or 0

◆ ev_error()

ULONG ev_error ( const char * text,
UWORD type )
static

◆ ev_indirect()

int ev_indirect ( struct state * s)
static

◆ ev_loop()

ULONG ev_loop ( struct state * s)
static

◆ evaluate_c()

ULONG evaluate_c ( UBYTE * str)
static

PFEvaluate(string): evaluates a postfix expression of ConvToPostFix.

Operands: decimal, $ hex, % binary numbers, - signs, registers d0-d7, a0-a7, pc of the PFRegisters block, {...} an indirection (a long, .b/.w/.l behind it; PFIndirectAddr keeps the address). Operators: = & | < > + - * / ^ (comparisons give -1/0; < and > signed, < fixed, #638). Errors set PFErrorType/PFErrorText and return 0: 1 "Need 2 arguments", 2 "Register structure not found", 3 "Divide by 0", 4 "No result value", 5 "No close bracket on indirect", 6 "Invalid size for indirection". An empty string returns 0, error 0; a string of spaces only 0, error 4 (fixed, #644). * gives the low 32 bits of the product (fixed, #639); the } of a register in {...} is checked at the string (fixed, #637); the indirection reads the bytes of its size one by one (fixed, #636). A character that is no digit of the number's base is error 4 (fixed, #634); so is a register other than a0-a7, d0-d7, pc, or one not followed by a space, the end or its } (fixed, #642). More than one value left at the end is error 4 (fixed, #635). ^ is the integer power, a negative exponent the truncated value, 0^-n error 3 (fixed, #641).

Parameters
strd0: the postfix string
Returns
d0: the value, 0 on an error

◆ grow()

ULONG grow ( struct state * s,
ULONG x )
static

◆ indirectaddr_c()

ULONG indirectaddr_c ( void )
static

PFIndirectAddr: the address of the last {...} indirection.

Returns
d0: the address

◆ is_operator()

int is_operator ( UBYTE c)
static

◆ ldivide()

ULONG ldivide ( ULONG dividend,
ULONG * divisor )
static

◆ lmult()

ULONG lmult ( ULONG lhs,
ULONG * rhs )
static

◆ registers_c()

void registers_c ( ULONG block)
static

PFRegisters *registerblock: the register block of PFEvaluate.

Longs d0-d7, a0-a7, pc (index * 4); 0 = none (register operands fail with error 2).

Parameters
blockd0: the address of the block

◆ st_empty()

int st_empty ( const struct state * s)
static

◆ st_init()

void st_init ( struct state * s,
struct chunk * k )
static

◆ st_pop()

ULONG st_pop ( struct state * s)
static

◆ st_push()

int st_push ( struct state * s,
ULONG x )
static

◆ st_top()

ULONG * st_top ( struct state * s)
static

Variable Documentation

◆ argc

ULONG argc
static

◆ err_arg

const char err_arg[] = "Need 2 arguments for expression!"
static

◆ err_close

const char err_close[] = "No close bracket on indirect!"
static

◆ err_divide0

const char err_divide0[] = "Divide by 0 error!"
static

◆ err_noresult

const char err_noresult[] = "No result value!"
static

◆ err_reg

const char err_reg[] = "Register structure not found!"
static

◆ err_size

const char err_size[] = "Invalid size for indirection!"
static

◆ errortext

const char* errortext
static

◆ errortype

UWORD errortype
static

◆ indirect

UBYTE indirect
static

◆ lastaddr

ULONG lastaddr
static

◆ negative

UBYTE negative
static

◆ operators

const struct op operators[]
static
Initial value:
= {
{ '(', 0 }, { '=', 1 }, { '&', 1 }, { '|', 1 }, { '<', 2 }, { '>', 2 },
{ '+', 3 }, { '-', 3 }, { '*', 4 }, { '/', 4 }, { '^', 5 }, { 0, 0 },
}

◆ regs

ULONG regs
static