mirror of
https://github.com/uffejakobsen/acme.git
synced 2025-01-12 05:31:19 +00:00
Changed comments and struct names; no change in functionality
git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@42 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
parent
0e66c1fcb2
commit
653ce7549c
@ -162,8 +162,8 @@ enum alu_state {
|
||||
};
|
||||
static enum alu_state alu_state; // deterministic finite automaton
|
||||
// predefined stuff
|
||||
static struct node_t *operator_tree = NULL; // tree to hold operators
|
||||
static struct node_t operator_list[] = {
|
||||
static struct ronode *operator_tree = NULL; // tree to hold operators
|
||||
static struct ronode operator_list[] = {
|
||||
PREDEFNODE(s_asr, &ops_asr),
|
||||
PREDEFNODE(s_lsr, &ops_lsr),
|
||||
PREDEFNODE(s_asl, &ops_sl),
|
||||
@ -176,8 +176,8 @@ static struct node_t operator_list[] = {
|
||||
PREDEFLAST(s_xor, &ops_xor),
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
static struct node_t *function_tree = NULL; // tree to hold functions
|
||||
static struct node_t function_list[] = {
|
||||
static struct ronode *function_tree = NULL; // tree to hold functions
|
||||
static struct ronode function_list[] = {
|
||||
PREDEFNODE("addr", &ops_addr),
|
||||
PREDEFNODE("int", &ops_int),
|
||||
PREDEFNODE("float", &ops_float),
|
||||
|
@ -240,7 +240,7 @@ static enum eos PO_serious(void)
|
||||
|
||||
|
||||
// pseudo ocpode table
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE(s_08, PO_08),
|
||||
PREDEFNODE(s_8, PO_08),
|
||||
PREDEFNODE("by", PO_08),
|
||||
|
@ -60,8 +60,8 @@ static struct cpu_type cpu_type_65816 = {
|
||||
// variables
|
||||
|
||||
// predefined stuff
|
||||
static struct node_t *CPU_tree = NULL; // tree to hold CPU types
|
||||
static struct node_t CPUs[] = {
|
||||
static struct ronode *CPU_tree = NULL; // tree to hold CPU types
|
||||
static struct ronode CPUs[] = {
|
||||
// PREDEFNODE("z80", &cpu_type_Z80),
|
||||
PREDEFNODE("6502", &cpu_type_6502),
|
||||
PREDEFNODE("6510", &cpu_type_6510),
|
||||
@ -230,7 +230,7 @@ static enum eos PO_rs(void)
|
||||
|
||||
// pseudo opcode table
|
||||
// FIXME - move to basics.c
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE("align", PO_align),
|
||||
PREDEFNODE("cpu", PO_cpu),
|
||||
PREDEFNODE("pseudopc", PO_pseudopc),
|
||||
|
@ -29,7 +29,7 @@ static const char s_scr[] = "scr";
|
||||
static char outermost_table[256]; // space for encoding table...
|
||||
static char *loaded_table = outermost_table; // ...loaded from file
|
||||
// predefined stuff
|
||||
static struct node_t *encoder_tree = NULL; // tree to hold encoders
|
||||
static struct ronode *encoder_tree = NULL; // tree to hold encoders
|
||||
|
||||
|
||||
// Functions
|
||||
@ -216,7 +216,7 @@ static enum eos PO_convtab(void)
|
||||
}
|
||||
|
||||
// pseudo opcode table
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE(s_cbm, PO_cbm),
|
||||
PREDEFNODE("ct", PO_convtab),
|
||||
PREDEFNODE("convtab", PO_convtab),
|
||||
@ -230,7 +230,7 @@ static struct node_t pseudo_opcodes[] = {
|
||||
};
|
||||
|
||||
// keywords for "!convtab" pseudo opcode
|
||||
static struct node_t encoders[] = {
|
||||
static struct ronode encoders[] = {
|
||||
PREDEFNODE(s_pet, encoder_pet),
|
||||
PREDEFNODE(s_raw, encoder_raw),
|
||||
PREDEFLAST(s_scr, encoder_scr),
|
||||
|
14
src/flow.c
14
src/flow.c
@ -36,8 +36,8 @@ struct loop_condition {
|
||||
// variables
|
||||
|
||||
// predefined stuff
|
||||
static struct node_t *condkey_tree = NULL; // tree to hold UNTIL and WHILE
|
||||
static struct node_t condkeys[] = {
|
||||
static struct ronode *condkey_tree = NULL; // tree to hold UNTIL and WHILE
|
||||
static struct ronode condkeys[] = {
|
||||
PREDEFNODE("until", TRUE), // UNTIL inverts the condition
|
||||
PREDEFLAST("while", FALSE), // WHILE does not change the condition
|
||||
// ^^^^ this marks the last element
|
||||
@ -336,10 +336,10 @@ static enum eos PO_if(void) // Now GotByte = illegal char
|
||||
// conditional assembly ("!ifdef" and "!ifndef"). Has to be re-entrant.
|
||||
static enum eos ifdef_ifndef(int invert) // Now GotByte = illegal char
|
||||
{
|
||||
struct node_ra_t *node;
|
||||
struct symbol *symbol;
|
||||
zone_t zone;
|
||||
int defined = FALSE;
|
||||
struct rwnode *node;
|
||||
struct symbol *symbol;
|
||||
zone_t zone;
|
||||
int defined = FALSE;
|
||||
|
||||
if (Input_read_zone_and_keyword(&zone) == 0) // skips spaces before
|
||||
return SKIP_REMAINDER;
|
||||
@ -453,7 +453,7 @@ static enum eos PO_source(void) // Now GotByte = illegal char
|
||||
|
||||
|
||||
// pseudo opcode table
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE("do", PO_do),
|
||||
PREDEFNODE("for", PO_for),
|
||||
PREDEFNODE("if", PO_if),
|
||||
|
@ -98,7 +98,7 @@ const char Byte_flags[256] = {
|
||||
|
||||
|
||||
// variables
|
||||
struct node_t *pseudo_opcode_tree = NULL; // tree to hold pseudo opcodes
|
||||
struct ronode *pseudo_opcode_tree = NULL; // tree to hold pseudo opcodes (FIXME - move when grouping all POs)
|
||||
int pass_count; // number of current pass (starts 0)
|
||||
char GotByte; // Last byte read (processed)
|
||||
int Process_verbosity = 0; // Level of additional output
|
||||
|
@ -56,7 +56,7 @@ extern const char Byte_flags[];
|
||||
|
||||
// Variables
|
||||
|
||||
extern struct node_t *pseudo_opcode_tree; // tree to hold pseudo opcodes
|
||||
extern struct ronode *pseudo_opcode_tree; // tree to hold pseudo opcodes (FIXME - move when grouping all POs)
|
||||
// structures
|
||||
// different ways to handle end-of-statement:
|
||||
enum eos {
|
||||
|
@ -51,7 +51,7 @@ static enum eos PO_eof(void)
|
||||
}
|
||||
|
||||
// predefined stuff
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE("eof", PO_eof),
|
||||
PREDEFLAST("endoffile", PO_eof),
|
||||
// ^^^^ this marks the last element
|
||||
|
32
src/macro.c
32
src/macro.c
@ -50,7 +50,7 @@ union macro_arg_t {
|
||||
// Variables
|
||||
static struct dynabuf *user_macro_name; // original macro title
|
||||
static struct dynabuf *internal_name; // plus param type chars
|
||||
static struct node_ra_t *macro_forest[256]; // trees (because of 8b hash)
|
||||
static struct rwnode *macro_forest[256]; // trees (because of 8b hash)
|
||||
// Dynamic argument table
|
||||
static union macro_arg_t *arg_table = NULL;
|
||||
static int argtable_size = HALF_INITIAL_ARG_TABLE_SIZE;
|
||||
@ -125,7 +125,7 @@ static char *get_string_copy(const char *original)
|
||||
// Terminate macro name and copy from internal_name to GlobalDynaBuf
|
||||
// (because that's where Tree_hard_scan() looks for the search string).
|
||||
// Then try to find macro and return whether it was created.
|
||||
static int search_for_macro(struct node_ra_t **result, zone_t zone, int create)
|
||||
static int search_for_macro(struct rwnode **result, zone_t zone, int create)
|
||||
{
|
||||
DynaBuf_append(internal_name, '\0'); // terminate macro name
|
||||
// now internal_name = macro_title SPC argument_specifiers NUL
|
||||
@ -139,7 +139,7 @@ static int search_for_macro(struct node_ra_t **result, zone_t zone, int create)
|
||||
// It first outputs a warning and then a serious error, stopping assembly.
|
||||
// Showing the first message as a warning guarantees that ACME does not reach
|
||||
// the maximum error limit inbetween.
|
||||
static void report_redefinition(struct node_ra_t *macro_node)
|
||||
static void report_redefinition(struct rwnode *macro_node)
|
||||
{
|
||||
struct macro *original_macro = macro_node->body;
|
||||
|
||||
@ -160,10 +160,10 @@ static void report_redefinition(struct node_ra_t *macro_node)
|
||||
// Return with GotByte = '}'
|
||||
void Macro_parse_definition(void) // Now GotByte = illegal char after "!macro"
|
||||
{
|
||||
char *formal_parameters;
|
||||
struct node_ra_t *macro_node;
|
||||
struct macro *new_macro;
|
||||
zone_t macro_zone = get_zone_and_title();
|
||||
char *formal_parameters;
|
||||
struct rwnode *macro_node;
|
||||
struct macro *new_macro;
|
||||
zone_t macro_zone = get_zone_and_title();
|
||||
|
||||
// now GotByte = first non-space after title
|
||||
DYNABUF_CLEAR(GlobalDynaBuf); // prepare to hold formal parameters
|
||||
@ -224,15 +224,15 @@ void Macro_parse_definition(void) // Now GotByte = illegal char after "!macro"
|
||||
// Parse macro call ("+MACROTITLE"). Has to be re-entrant.
|
||||
void Macro_parse_call(void) // Now GotByte = dot or first char of macro name
|
||||
{
|
||||
char local_gotbyte;
|
||||
struct symbol *symbol;
|
||||
struct section new_section,
|
||||
*outer_section;
|
||||
struct input new_input,
|
||||
*outer_input;
|
||||
struct macro *actual_macro;
|
||||
struct node_ra_t *macro_node,
|
||||
*symbol_node;
|
||||
char local_gotbyte;
|
||||
struct symbol *symbol;
|
||||
struct section new_section,
|
||||
*outer_section;
|
||||
struct input new_input,
|
||||
*outer_input;
|
||||
struct macro *actual_macro;
|
||||
struct rwnode *macro_node,
|
||||
*symbol_node;
|
||||
zone_t macro_zone,
|
||||
symbol_zone;
|
||||
int arg_count = 0;
|
||||
|
30
src/mnemo.c
30
src/mnemo.c
@ -144,13 +144,13 @@ static const char exception_highbyte_zero[] = "Using oversized addressing mode."
|
||||
|
||||
static struct dynabuf *mnemo_dyna_buf; // dynamic buffer for mnemonics
|
||||
// predefined stuff
|
||||
static struct node_t *mnemo_6502_tree = NULL; // holds 6502 mnemonics
|
||||
static struct node_t *mnemo_6510_tree = NULL; // holds 6510 extensions
|
||||
static struct node_t *mnemo_c64dtv2_tree = NULL; // holds C64DTV2 extensions
|
||||
static struct node_t *mnemo_65c02_tree = NULL; // holds 65c02 extensions
|
||||
//static struct node_t *mnemo_Rockwell65c02_tree = NULL; // Rockwell
|
||||
static struct node_t *mnemo_WDC65c02_tree = NULL; // WDC's "stp"/"wai"
|
||||
static struct node_t *mnemo_65816_tree = NULL; // holds 65816 extensions
|
||||
static struct ronode *mnemo_6502_tree = NULL; // holds 6502 mnemonics
|
||||
static struct ronode *mnemo_6510_tree = NULL; // holds 6510 extensions
|
||||
static struct ronode *mnemo_c64dtv2_tree = NULL; // holds C64DTV2 extensions
|
||||
static struct ronode *mnemo_65c02_tree = NULL; // holds 65c02 extensions
|
||||
//static struct ronode *mnemo_Rockwell65c02_tree = NULL; // Rockwell
|
||||
static struct ronode *mnemo_WDC65c02_tree = NULL; // WDC's "stp"/"wai"
|
||||
static struct ronode *mnemo_65816_tree = NULL; // holds 65816 extensions
|
||||
|
||||
// Command's code and group values are stored together in a single integer.
|
||||
// To extract the code, use "& CODEMASK".
|
||||
@ -162,7 +162,7 @@ static struct node_t *mnemo_65816_tree = NULL; // holds 65816 extensions
|
||||
#define GROUPSHIFT 10 // shift right by this to extract group
|
||||
#define MERGE(g, v) ((g << GROUPSHIFT) | v)
|
||||
|
||||
static struct node_t mnemos_6502[] = {
|
||||
static struct ronode mnemos_6502[] = {
|
||||
PREDEFNODE("ora", MERGE(GROUP_ACCU, IDX_ORA | IMM_ACCU)),
|
||||
PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDX_AND | IMM_ACCU)),
|
||||
PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDX_EOR | IMM_ACCU)),
|
||||
@ -222,7 +222,7 @@ static struct node_t mnemos_6502[] = {
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
|
||||
static struct node_t mnemos_6510[] = {
|
||||
static struct ronode mnemos_6510[] = {
|
||||
PREDEFNODE("slo", MERGE(GROUP_ACCU, IDX_SLO)), // ASL + ORA (aka ASO)
|
||||
PREDEFNODE("rla", MERGE(GROUP_ACCU, IDX_RLA)), // ROL + AND
|
||||
PREDEFNODE("sre", MERGE(GROUP_ACCU, IDX_SRE)), // LSR + EOR (aka LSE)
|
||||
@ -242,14 +242,14 @@ static struct node_t mnemos_6510[] = {
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
|
||||
static struct node_t mnemos_c64dtv2[] = {
|
||||
static struct ronode mnemos_c64dtv2[] = {
|
||||
PREDEFNODE(s_bra, MERGE(GROUP_RELATIVE8, 0x12)), // branch always
|
||||
PREDEFNODE("sac", MERGE(GROUP_MISC, IDX_SAC)), // set accumulator mapping
|
||||
PREDEFLAST("sir", MERGE(GROUP_MISC, IDX_SIR)), // set index register mapping
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
|
||||
static struct node_t mnemos_65c02[] = {
|
||||
static struct ronode mnemos_65c02[] = {
|
||||
PREDEFNODE("ora", MERGE(GROUP_ACCU, IDXcORA | IMM_ACCU)),
|
||||
PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDXcAND | IMM_ACCU)),
|
||||
PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDXcEOR | IMM_ACCU)),
|
||||
@ -273,7 +273,7 @@ static struct node_t mnemos_65c02[] = {
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
|
||||
//static struct node_t mnemos_Rockwell65c02[] = {
|
||||
//static struct ronode mnemos_Rockwell65c02[] = {
|
||||
// PREDEFNODE("rmb0", MERGE(G_ , 0x07)),
|
||||
// PREDEFNODE("rmb1", MERGE(G_ , 0x17)),
|
||||
// PREDEFNODE("rmb2", MERGE(G_ , 0x27)),
|
||||
@ -309,13 +309,13 @@ static struct node_t mnemos_65c02[] = {
|
||||
// // ^^^^ this marks the last element
|
||||
//};
|
||||
|
||||
static struct node_t mnemos_WDC65c02[] = {
|
||||
static struct ronode mnemos_WDC65c02[] = {
|
||||
PREDEFNODE("stp", MERGE(GROUP_IMPLIEDONLY, 219)),
|
||||
PREDEFLAST("wai", MERGE(GROUP_IMPLIEDONLY, 203)),
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
|
||||
static struct node_t mnemos_65816[] = {
|
||||
static struct ronode mnemos_65816[] = {
|
||||
PREDEFNODE("ora", MERGE(GROUP_ACCU, IDX816ORA | IMM_ACCU)),
|
||||
PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDX816AND | IMM_ACCU)),
|
||||
PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDX816EOR | IMM_ACCU)),
|
||||
@ -838,7 +838,7 @@ static void group_jump(int index)
|
||||
}
|
||||
|
||||
// Work function
|
||||
static int check_mnemo_tree(struct node_t *tree, struct dynabuf *dyna_buf)
|
||||
static int check_mnemo_tree(struct ronode *tree, struct dynabuf *dyna_buf)
|
||||
{
|
||||
void *node_body;
|
||||
int code,
|
||||
|
10
src/output.c
10
src/output.c
@ -59,7 +59,7 @@ struct vcpu CPU_state; // current CPU state
|
||||
|
||||
// FIXME - move file format stuff to some other .c file!
|
||||
// predefined stuff
|
||||
static struct node_t *file_format_tree = NULL; // tree to hold output formats
|
||||
static struct ronode *file_format_tree = NULL; // tree to hold output formats
|
||||
// possible file formats
|
||||
enum output_format {
|
||||
OUTPUT_FORMAT_UNSPECIFIED, // default (uses "plain" actually)
|
||||
@ -67,7 +67,7 @@ enum output_format {
|
||||
OUTPUT_FORMAT_CBM, // load address, code (default for "!to" pseudo opcode)
|
||||
OUTPUT_FORMAT_PLAIN // code only
|
||||
};
|
||||
static struct node_t file_formats[] = {
|
||||
static struct ronode file_formats[] = {
|
||||
PREDEFNODE("apple", OUTPUT_FORMAT_APPLE),
|
||||
PREDEFNODE(s_cbm, OUTPUT_FORMAT_CBM),
|
||||
// PREDEFNODE("o65", OUTPUT_FORMAT_O65),
|
||||
@ -79,11 +79,11 @@ static enum output_format output_format = OUTPUT_FORMAT_UNSPECIFIED;
|
||||
|
||||
|
||||
// predefined stuff
|
||||
static struct node_t *segment_modifier_tree = NULL; // tree to hold segment modifiers
|
||||
static struct ronode *segment_modifier_tree = NULL; // tree to hold segment modifiers
|
||||
// segment modifiers
|
||||
#define SEGMENT_FLAG_OVERLAY (1u << 0)
|
||||
#define SEGMENT_FLAG_INVISIBLE (1u << 1)
|
||||
static struct node_t segment_modifiers[] = {
|
||||
static struct ronode segment_modifiers[] = {
|
||||
PREDEFNODE("overlay", SEGMENT_FLAG_OVERLAY),
|
||||
PREDEFLAST("invisible", SEGMENT_FLAG_INVISIBLE),
|
||||
// ^^^^ this marks the last element
|
||||
@ -350,7 +350,7 @@ static enum eos PO_to(void)
|
||||
|
||||
// pseudo ocpode table
|
||||
// FIXME - move to basics.c
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE("initmem", PO_initmem),
|
||||
PREDEFLAST("to", PO_to),
|
||||
// ^^^^ this marks the last element
|
||||
|
@ -97,7 +97,7 @@ static enum eos PO_subzone(void)
|
||||
}
|
||||
|
||||
// predefined stuff
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE(s_zone, PO_zone),
|
||||
PREDEFNODE("zn", PO_zone),
|
||||
PREDEFNODE(s_subzone, PO_subzone),
|
||||
|
24
src/symbol.c
24
src/symbol.c
@ -26,11 +26,11 @@
|
||||
|
||||
|
||||
// variables
|
||||
struct node_ra_t *symbols_forest[256]; // ... (because of 8-bit hash)
|
||||
struct rwnode *symbols_forest[256]; // ... (because of 8-bit hash)
|
||||
|
||||
|
||||
// Dump symbol value and flags to dump file
|
||||
static void dump_one_symbol(struct node_ra_t *node, FILE *fd)
|
||||
static void dump_one_symbol(struct rwnode *node, FILE *fd)
|
||||
{
|
||||
struct symbol *symbol = node->body;
|
||||
|
||||
@ -68,7 +68,7 @@ static void dump_one_symbol(struct node_ra_t *node, FILE *fd)
|
||||
|
||||
|
||||
// output symbols in VICE format (example: "al C:09ae .nmi1")
|
||||
static void dump_vice_address(struct node_ra_t *node, FILE *fd)
|
||||
static void dump_vice_address(struct rwnode *node, FILE *fd)
|
||||
{
|
||||
struct symbol *symbol = node->body;
|
||||
|
||||
@ -78,7 +78,7 @@ static void dump_vice_address(struct node_ra_t *node, FILE *fd)
|
||||
&& (symbol->result.addr_refs == 1))
|
||||
fprintf(fd, "al C:%04x .%s\n", (unsigned) symbol->result.val.intval, node->id_string);
|
||||
}
|
||||
static void dump_vice_usednonaddress(struct node_ra_t *node, FILE *fd)
|
||||
static void dump_vice_usednonaddress(struct rwnode *node, FILE *fd)
|
||||
{
|
||||
struct symbol *symbol = node->body;
|
||||
|
||||
@ -89,7 +89,7 @@ static void dump_vice_usednonaddress(struct node_ra_t *node, FILE *fd)
|
||||
&& (symbol->result.addr_refs != 1))
|
||||
fprintf(fd, "al C:%04x .%s\n", (unsigned) symbol->result.val.intval, node->id_string);
|
||||
}
|
||||
static void dump_vice_unusednonaddress(struct node_ra_t *node, FILE *fd)
|
||||
static void dump_vice_unusednonaddress(struct rwnode *node, FILE *fd)
|
||||
{
|
||||
struct symbol *symbol = node->body;
|
||||
|
||||
@ -106,10 +106,10 @@ static void dump_vice_unusednonaddress(struct node_ra_t *node, FILE *fd)
|
||||
// the symbol name must be held in GlobalDynaBuf.
|
||||
struct symbol *symbol_find(zone_t zone, int flags)
|
||||
{
|
||||
struct node_ra_t *node;
|
||||
struct symbol *symbol;
|
||||
int node_created,
|
||||
force_bits = flags & MVALUE_FORCEBITS;
|
||||
struct rwnode *node;
|
||||
struct symbol *symbol;
|
||||
int node_created,
|
||||
force_bits = flags & MVALUE_FORCEBITS;
|
||||
|
||||
node_created = Tree_hard_scan(&node, symbols_forest, zone, TRUE);
|
||||
// if node has just been created, create symbol as well
|
||||
@ -234,7 +234,7 @@ static enum eos PO_sl(void)
|
||||
|
||||
|
||||
// predefined stuff
|
||||
static struct node_t pseudo_opcodes[] = {
|
||||
static struct ronode pseudo_opcodes[] = {
|
||||
PREDEFNODE("set", PO_set),
|
||||
PREDEFNODE("symbollist", PO_sl),
|
||||
PREDEFLAST(s_sl, PO_sl),
|
||||
@ -325,8 +325,8 @@ void symbols_vicelabels(FILE *fd)
|
||||
// clear symbols forest (is done early)
|
||||
void symbols_clear_init(void)
|
||||
{
|
||||
struct node_ra_t **ptr;
|
||||
int ii;
|
||||
struct rwnode **ptr;
|
||||
int ii;
|
||||
|
||||
// cut down all the trees (clear pointer table)
|
||||
ptr = symbols_forest;
|
||||
|
@ -19,7 +19,7 @@ struct symbol {
|
||||
|
||||
|
||||
// variables
|
||||
extern struct node_ra_t *symbols_forest[]; // trees (because of 8-bit hash)
|
||||
extern struct rwnode *symbols_forest[]; // trees (because of 8-bit hash)
|
||||
|
||||
|
||||
// clear symbol forest (is done early)
|
||||
|
28
src/tree.c
28
src/tree.c
@ -15,7 +15,7 @@
|
||||
// Compute hash value by exclusive ORing the node's ID string and write
|
||||
// output to struct.
|
||||
// This function is not allowed to change GlobalDynaBuf!
|
||||
hash_t make_hash(struct node_t *node) {
|
||||
hash_t make_hash(struct ronode *node) {
|
||||
register char byte;
|
||||
register const char *read;
|
||||
register hash_t tmp = 0;
|
||||
@ -28,7 +28,7 @@ hash_t make_hash(struct node_t *node) {
|
||||
}
|
||||
|
||||
// Link a predefined data set to a tree
|
||||
void add_node_to_tree(struct node_t **tree, struct node_t *node_to_add)
|
||||
void add_node_to_tree(struct ronode **tree, struct ronode *node_to_add)
|
||||
{
|
||||
hash_t hash;
|
||||
|
||||
@ -50,7 +50,7 @@ void add_node_to_tree(struct node_t **tree, struct node_t *node_to_add)
|
||||
|
||||
// Add predefined tree items to given tree. The PREDEF* macros set HashValue
|
||||
// to 1 in all entries but the last. The last entry contains 0.
|
||||
void Tree_add_table(struct node_t **tree, struct node_t *table_to_add)
|
||||
void Tree_add_table(struct ronode **tree, struct ronode *table_to_add)
|
||||
{
|
||||
// Caution when trying to optimise this. :)
|
||||
while (table_to_add->hash_value)
|
||||
@ -61,11 +61,11 @@ void Tree_add_table(struct node_t **tree, struct node_t *table_to_add)
|
||||
// Search for a given ID string in a given tree.
|
||||
// Compute the hash of the given string and then use that to try to find a
|
||||
// tree item that matches the given data (HashValue and DynaBuf-String).
|
||||
// Store "Body" component in NodeBody and return TRUE.
|
||||
// Store "body" component in node_body and return TRUE.
|
||||
// Return FALSE if no matching item found.
|
||||
int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf *dyna_buf)
|
||||
int Tree_easy_scan(struct ronode *tree, void **node_body, struct dynabuf *dyna_buf)
|
||||
{
|
||||
struct node_t wanted; // temporary storage
|
||||
struct ronode wanted; // temporary storage
|
||||
const char *p1,
|
||||
*p2;
|
||||
char b1,
|
||||
@ -106,15 +106,15 @@ int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf *dyna_b
|
||||
// and then use that to try to find a tree item that matches the given data
|
||||
// (HashValue, ID_Number, GlobalDynaBuf-String). Save pointer to found tree
|
||||
// item in given location.
|
||||
// If no matching item is found, check the "Create" flag. If it is set, create
|
||||
// If no matching item is found, check the "create" flag. If it is set, create
|
||||
// a new tree item, link to tree, fill with data and store its pointer. If the
|
||||
// "Create" flag is clear, store NULL as result.
|
||||
// "create" flag is zero, store NULL as result.
|
||||
// Returns whether item was created.
|
||||
int Tree_hard_scan(struct node_ra_t **result, struct node_ra_t **forest, int id_number, int create)
|
||||
int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, int create)
|
||||
{
|
||||
struct node_t wanted; // temporary storage
|
||||
struct node_ra_t **current_node;
|
||||
struct node_ra_t *new_leaf_node;
|
||||
struct ronode wanted; // temporary storage
|
||||
struct rwnode **current_node;
|
||||
struct rwnode *new_leaf_node;
|
||||
const char *p1,
|
||||
*p2;
|
||||
char b1,
|
||||
@ -178,7 +178,7 @@ int Tree_hard_scan(struct node_ra_t **result, struct node_ra_t **forest, int id_
|
||||
|
||||
// Call given function for each object of matching type in the given tree.
|
||||
// Calls itself recursively.
|
||||
void dump_tree(struct node_ra_t *node, int id_number, void (*fn)(struct node_ra_t *, FILE *), FILE *env)
|
||||
void dump_tree(struct rwnode *node, int id_number, void (*fn)(struct rwnode *, FILE *), FILE *env)
|
||||
{
|
||||
|
||||
if (node->id_number == id_number)
|
||||
@ -190,7 +190,7 @@ void dump_tree(struct node_ra_t *node, int id_number, void (*fn)(struct node_ra_
|
||||
}
|
||||
|
||||
// Calls Tree_dump_tree for each non-zero entry of the given tree table.
|
||||
void Tree_dump_forest(struct node_ra_t **forest, int id_number, void (*fn)(struct node_ra_t *, FILE *), FILE *env)
|
||||
void Tree_dump_forest(struct rwnode **forest, int id_number, void (*fn)(struct rwnode *, FILE *), FILE *env)
|
||||
{
|
||||
int ii;
|
||||
|
||||
|
40
src/tree.h
40
src/tree.h
@ -21,40 +21,40 @@
|
||||
typedef unsigned int hash_t;
|
||||
// Must be unsigned, otherwise the hash algorithm won't be very useful!
|
||||
|
||||
// tree node structure type definition (for easy lookups)
|
||||
struct node_t {
|
||||
struct node_t *greater_than; // pointer to sub-tree
|
||||
struct node_t *less_than_or_equal; // pointer to sub-tree
|
||||
// tree node structure type definition for lookups in "read-only" (i.e. keyword) trees
|
||||
struct ronode {
|
||||
struct ronode *greater_than; // pointer to sub-tree
|
||||
struct ronode *less_than_or_equal; // pointer to sub-tree
|
||||
hash_t hash_value;
|
||||
const char *id_string; // name, zero-terminated
|
||||
void *body; // bytes, handles or handler function
|
||||
};
|
||||
|
||||
// tree node structure type definition (for macros/labels)
|
||||
struct node_ra_t {
|
||||
struct node_ra_t *greater_than; // pointer to sub-tree
|
||||
struct node_ra_t *less_than_or_equal; // pointer to sub-tree
|
||||
hash_t hash_value;
|
||||
char *id_string; // name, zero-terminated
|
||||
void *body; // macro/label body
|
||||
unsigned int id_number; // zone number
|
||||
// tree node structure type definition for "read/write" items, i.e. macros/labels
|
||||
struct rwnode {
|
||||
struct rwnode *greater_than; // pointer to sub-tree
|
||||
struct rwnode *less_than_or_equal; // pointer to sub-tree
|
||||
hash_t hash_value;
|
||||
char *id_string; // name, zero-terminated
|
||||
void *body; // macro/label body
|
||||
unsigned int id_number; // zone number
|
||||
};
|
||||
|
||||
|
||||
// Prototypes
|
||||
|
||||
// Add predefined tree items to given tree.
|
||||
extern void Tree_add_table(struct node_t **tree, struct node_t *table_to_add);
|
||||
// Search for a given ID string in a given tree. Store "Body" component in
|
||||
// NodeBody and return TRUE. Return FALSE if no matching item found.
|
||||
extern int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf *dyna_buf);
|
||||
extern void Tree_add_table(struct ronode **tree, struct ronode *table_to_add);
|
||||
// Search for a given ID string in a given tree. Store "body" component in
|
||||
// node_body and return TRUE. Return FALSE if no matching item found.
|
||||
extern int Tree_easy_scan(struct ronode *tree, void **node_body, struct dynabuf *dyna_buf);
|
||||
// Search for a "RAM tree" item. Save pointer to found tree item in given
|
||||
// location. If no matching item is found, check the "Create" flag: If set,
|
||||
// location. If no matching item is found, check the "create" flag: If set,
|
||||
// create new tree item, link to tree, fill with data and store its pointer.
|
||||
// If "Create" is clear, store NULL. Returns whether item was created.
|
||||
extern int Tree_hard_scan(struct node_ra_t **, struct node_ra_t **, int, int);
|
||||
// If "create" is zero, store NULL. Returns whether item was created.
|
||||
extern int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, int create);
|
||||
// Calls given function for each node of each tree of given forest.
|
||||
extern void Tree_dump_forest(struct node_ra_t **, int, void (*)(struct node_ra_t *, FILE *), FILE *);
|
||||
extern void Tree_dump_forest(struct rwnode **, int, void (*)(struct rwnode *, FILE *), FILE *);
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user