|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#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 |
| #define CHUNK 32 |
| #define PUSH | ( | s, | |
| x ) |
| void _ConvToPostFix | ( | void | ) |
| void _evaluate | ( | void | ) |
|
static |
finit: nothing (RTS).
|
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.
| void _PFErrorText | ( | void | ) |
| void _PFErrorType | ( | void | ) |
| void _PFIndirectAddr | ( | void | ) |
| void _registers | ( | void | ) |
|
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).
|
static |
|
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.
|
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).
| result | d0: the caller's d0 |
|
static |
|
static |
|
static |
|
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).
| str | d0: the postfix string |
|
static |
|
static |
PFIndirectAddr: the address of the last {...} indirection.
|
static |
|
static |
|
static |
|
static |
PFRegisters *registerblock: the register block of PFEvaluate.
Longs d0-d7, a0-a7, pc (index * 4); 0 = none (register operands fail with error 2).
| block | d0: the address of the block |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |