Author: stepan Date: 2006-10-30 10:48:28 +0100 (Mon, 30 Oct 2006) New Revision: 100
Modified: fcode-utils/toke/Makefile fcode-utils/toke/clflags.c fcode-utils/toke/clflags.h fcode-utils/toke/devnode.c fcode-utils/toke/dictionary.c fcode-utils/toke/emit.c fcode-utils/toke/emit.h fcode-utils/toke/errhandler.c fcode-utils/toke/errhandler.h fcode-utils/toke/flowcontrol.c fcode-utils/toke/macros.c fcode-utils/toke/nextfcode.c fcode-utils/toke/parselocals.c fcode-utils/toke/scanner.c fcode-utils/toke/scanner.h fcode-utils/toke/stream.c fcode-utils/toke/stream.h fcode-utils/toke/ticvocab.c fcode-utils/toke/ticvocab.h fcode-utils/toke/toke.c fcode-utils/toke/tokzesc.c fcode-utils/toke/tracesyms.c fcode-utils/toke/tracesyms.h fcode-utils/toke/vocabfuncts.h Log: tokenizer v 1.0.2, contribution by David Paktor dlpaktor@netscape.net
Modified: fcode-utils/toke/Makefile =================================================================== --- fcode-utils/toke/Makefile 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/Makefile 2006-10-30 09:48:28 UTC (rev 100) @@ -29,7 +29,7 @@ INCLUDES = -I../shared
# Normal flags -CFLAGS = -O2 -Wall -Wno-pointer-sign -fno-strict-aliasing -DSYS_IS_GNU_Linux +CFLAGS = -O2 -Wall -Wno-pointer-sign -fno-strict-aliasing LDFLAGS =
# Coverage:
Modified: fcode-utils/toke/clflags.c =================================================================== --- fcode-utils/toke/clflags.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/clflags.c 2006-10-30 09:48:28 UTC (rev 100) @@ -104,6 +104,7 @@ bool obso_fcode_warning = TRUE ; bool trace_conditionals = FALSE ; bool big_end_pci_image_rev = FALSE ; +bool allow_ret_stk_interp = TRUE ;
/* And one to trigger a "help" message */ bool clflag_help = FALSE; @@ -242,7 +243,12 @@ "Save the Vendor's Rev Level field of the PCI Header" " in Big-Endian format" } ,
+ { "Ret-Stk-Interp", + &allow_ret_stk_interp, + "\t\t", + "Allow Return-Stack Operations during Interpretation" } ,
+ /* Keep the "help" pseudo-flag last in the list */ { "help", &clflag_help,
Modified: fcode-utils/toke/clflags.h =================================================================== --- fcode-utils/toke/clflags.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/clflags.h 2006-10-30 09:48:28 UTC (rev 100) @@ -124,6 +124,7 @@
extern bool force_tokens_case; extern bool force_lower_case_tokens; +extern bool allow_ret_stk_interp;
extern bool clflag_help;
Modified: fcode-utils/toke/devnode.c =================================================================== --- fcode-utils/toke/devnode.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/devnode.c 2006-10-30 09:48:28 UTC (rev 100) @@ -580,7 +580,7 @@ } if ( grandpa != NULL ) { - char as_what_buf[32] = ""; + char as_what_buf[AS_WHAT_BUF_SIZE] = ""; if ( as_a_what( found->fword_defr, as_what_buf) ) { strcat( as_what_buf, " ");
Modified: fcode-utils/toke/dictionary.c =================================================================== --- fcode-utils/toke/dictionary.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/dictionary.c 2006-10-30 09:48:28 UTC (rev 100) @@ -50,6 +50,7 @@ #include "errhandler.h" #include "tokzesc.h" #include "conditl.h" +#include "tracesyms.h"
/* ************************************************************************** * @@ -87,10 +88,48 @@ * Begin development of implementation of a way to define both (all?) * types of definitions in a single tic_hdr_t type vocabulary. * + * Wed, 04 Oct 2006 by David L. Paktor + * Issue a message when a name on the trace list is invoked (as well + * as when it is created), but keep a limit on the speed penalty. + * (I.e., don't scan the trace-list for every symbol invoked.) + * We will scan the trace-list for every pre-defined symbol during + * initialization of the built-in vocabularies' lists, but that + * occurs only once... + * **************************************************************************** */
+/* ************************************************************************** + * + * Global Variables Exported + * + * scope_is_global Indication that "global" scope is in effect + * + * define_token Normally TRUE, but if the definition in progress + * occurs inside a control-structure, (which is an Error), we + * make this FALSE. We will allow the definition to proceed + * (in order to avoid "cascade" errors and so that other errors + * can be recognized normally) but we will use this to suppress + * adding the new definition's token to the vocab. We also use + * this to suppress the actions of "hide_..." and "reveal..." + * because if the token wasn't added to the vocabulary, there's + * nothing to find that needed to be "hidden"... + * + **************************************************************************** */
+bool scope_is_global = FALSE; +bool define_token = TRUE; /* TRUE = Normal definition process; + * FALSE when definition is an Error. + * We enter definition state anyway, + * but must still suppress: + * (1) adding an entry for the token + * to the vocab, + * (2) "hiding" it at first, and + * (3) "revealing" it later. + * + * Makes for more "normal" error- detection... + */ + /* ************************************************************************** * * We will be creating several different lists of initial built-in @@ -170,6 +209,8 @@
/* ************************************************************************** * + * Internal Static Variables + * * We'll be initializing the lists later, but will be referencing * the pointers sooner, so we need to declare the pointers here. * @@ -278,20 +319,20 @@ #define FC_TOKEN_FUNC emit_fc_token
#define BUILTIN_FCODE( tok, nam) \ - VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , UNSPECIFIED ) + VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , UNSPECIFIED, TRUE )
/* Built-in FCodes with known definers: */ #define BI_FCODE_VALUE( tok, nam) \ - VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , VALUE ) + VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , VALUE, TRUE )
#define BI_FCODE_VRBLE( tok, nam) \ - VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , VARIABLE ) + VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , VARIABLE, TRUE )
#define BI_FCODE_DEFER( tok, nam) \ - VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , DEFER ) + VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , DEFER, TRUE )
#define BI_FCODE_CONST( tok, nam) \ - VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , CONST ) + VALPARAM_TIC(nam, FC_TOKEN_FUNC, tok , CONST, TRUE )
/* ************************************************************************** * @@ -322,10 +363,10 @@ #define OBSO_FC_FUNC obsolete_fc_token
#define OBSOLETE_FCODE( tok, nam) \ - VALPARAM_TIC(nam, OBSO_FC_FUNC, tok , UNSPECIFIED ) + VALPARAM_TIC(nam, OBSO_FC_FUNC, tok , UNSPECIFIED, TRUE )
#define OBSOLETE_VALUE( tok, nam) \ - VALPARAM_TIC(nam, OBSO_FC_FUNC, tok , VALUE ) + VALPARAM_TIC(nam, OBSO_FC_FUNC, tok , VALUE, TRUE )
/* ************************************************************************** @@ -457,10 +498,7 @@ **************************************************************************** */
static tic_hdr_t **save_device_definitions; -/* Export the indication that "global" scope is in effect */ -bool scope_is_global = FALSE;
- void enter_global_scope( void ) { if ( scope_is_global ) @@ -626,20 +664,24 @@ * name The name of the new entry * fc_token The new entry's assigned FCode-number * fw_definer The new entry's definer - * define_token If FALSE, suppress adding the entry, - * but preserve the side-effect of - * setting save_current * Global Variables: * current_definitions Pointer to pointer to "tail" of the * Vocabulary currently in effect; * either Device-node or Global. + * define_token TRUE = Normal definition process; + * FALSE if def'n is an Error. + * Suppress adding entry to vocab; + * Display "failure" Trace-note + * and Duplicate-Name Warning. * * Outputs: * Returned Value: NONE * Global Variables: * *current_definitions Updated with the new entry * Local Static Variables: - * save_current Pointer to previous entry + * save_current Saved state of current_definitions + * before the new entry is added, + * to permit "hide" and "reveal". * Memory Allocated * For the new entry's copy of the name. * When Freed? @@ -653,34 +695,38 @@ * All user-defined words have the same action, i.e., emitting * the assigned FCode-number. The new entry's "parameter * field" size is, of course, zero; the "ignore-function" - * is NULL. + * is NULL, and the entry has a single-token FCode number. * * Extraneous Remarks: - * The define_token parameter is a late addition, necessitated - * by the decision to continue processing after an erroneous + * The define_token input is a late addition, necessitated by + * the decision to continue processing after an erroneous * attempt to create a definition inside a control-structure, * in order to catch other errors. * - * **************************************************************************** */
void add_to_current( char *name, TIC_P_DEFLT_TYPE fc_token, - fwtoken definer, - bool define_token) + fwtoken definer) { - save_current = *current_definitions; if ( define_token ) { char *nu_name = strdup( name); + + save_current = *current_definitions; add_tic_entry( nu_name, FC_TOKEN_FUNC, fc_token, - definer, 0 , NULL, current_definitions ); + definer, 0 , TRUE , NULL, current_definitions ); + }else{ + trace_create_failure( name, NULL, fc_token); + warn_if_duplicate( name); } }
void hide_last_colon ( void ) { + if ( define_token ) + { tic_hdr_t *temp_vocab;
/* The add_to_current() function will have been called before this @@ -692,16 +738,20 @@ temp_vocab = save_current ; save_current = *current_definitions; *current_definitions = temp_vocab; + }
}
void reveal_last_colon ( void ) { + if ( define_token ) + { /* We call this function either when the colon-definition is * completed, or when "recursive"-ness is intentional. */ *current_definitions = save_current ; } +}
/* ************************************************************************** @@ -724,6 +774,15 @@ * current_definitions Device-node vocabulary currently * in effect. * scope_is_global TRUE if "global" scope is in effect + * split_alias_message Message-type for announcement that + * the "new" name was created in + * a different vocabulary than where + * the "old" name was found, if so + * be. (See "Rule 3", below). An + * Advisory, normally, but if either + * of the names is being Traced, the + * create_split_alias() routine will + * change it to a Trace-Note. * Local Static Variables: * global_voc_dict_ptr "Tail" of Global Vocabulary * @@ -766,35 +825,52 @@ * * And one other thing: * We will always make the alias's pfld_size zero. See the - * prolog for create_tic_alias() in ticvocab.c for details... + * prolog for create_split_alias() in ticvocab.c for details... * * Extraneous Remarks: - * I will stretch the rules of well-structured code here, too. + * I tried stretching the rules of well-structured code, but + * I'm finding that there is a _good_reason_ for them... * **************************************************************************** */
bool create_current_alias( char *new_name, char *old_name ) { bool retval = FALSE; + bool split_alias = FALSE;
+ /* Rules 1 & 2 are implemented in the same code. */ if ( create_tic_alias( new_name, old_name, current_definitions) ) { - return ( TRUE ); - } - + retval = TRUE; + }else{ if ( INVERSE(scope_is_global) ) { - tic_hdr_t *found = lookup_core_word( old_name ); - if ( found != NULL ) - { - add_tic_entry( new_name, found->funct, - found->pfield.deflt_elem, - found->fword_defr, - 0, found->ign_func, + /* Rule 3. + * Because the vocab into which the new definition will go is + * not the same as the one in which the old name was found, + * we cannot call create_tic_alias but must replicate it. + */ + /* Hmmmmmm..... + * We could get around that by refactoring: add a parameter, + * make the vocab to search separate from the one in which to + * create. Also, by making it a separate routine, we won't + * have to disturb the other callers of create_tic_alias() + * Yes! Excellent! Make it so! + */ + split_alias = TRUE; + split_alias_message = INFO; + retval = create_split_alias( + new_name, old_name, + &global_voc_dict_ptr, current_definitions ); - retval = TRUE; + } + } + + if ( retval ) { - tokenization_error( INFO, + if ( split_alias ) + { + tokenization_error( split_alias_message, "%s is a Global definition, but its alias, %s, " "will only be defined %s", strupr( old_name), new_name, @@ -802,7 +878,6 @@ show_node_start(); } } - }
return ( retval ); } @@ -1347,19 +1422,30 @@ * * Process Explanation: * We cannot rely on the "definer" field to indicate whether - * it is a single-token entry; instead, we will look at - * the associated function. - * Keep this routine here to avoid needing to export the names - * of the permitted functions or their synonymous macros. - * If we ever need to change it, we can do so at a single - * point of maintenance. - * Because the entry might have been found in the initial list - * of entries to the "FCode-Tokens" list, we need to check - * whether the associated function is either the general - * single-token emitting function, FC_TOKEN_FUNC , or the - * function OBSO_FC_FUNC , which presents a message before - * emitting, but is still a valid single-token function. + * it is a single-token entry, and there too many possible + * associated functions to be practical; instead we will + * look at the is_token flag of the data structure. * + * Revision History: + * Updated Mon, 25 Sep 2006 by David L. Paktor + * Previously operated by examining the function associated + * with the entry, accepting the general single-token + * emitting function, FC_TOKEN_FUNC , and later adding + * the function OBSO_FC_FUNC , which presents a message + * before emitting. Now the functions that present a + * message before emitting might be about to proliferate, + * rendering this implementation strategy impractical (i.e., + * ugly to code and too attention-demanding to maintain) + * Instead, I will introduce a flag into the TIC-entry + * data-structure and rely on it. + * Updated Wed, 11 Oct 2006 by David L. Paktor + * Discarded plan to have functions that present a "Trace-Note" + * message prior to performing their other duties (just too + * unwieldly all around) in favor of adding a "tracing" flag + * to the TIC_HDR data-structure. Could have gone back to + * doing this the other way, but this is so much neater a + * solution that I'm keeping it. + * **************************************************************************** */
bool entry_is_token( tic_hdr_t *test_entry ) @@ -1367,11 +1453,7 @@ bool retval = FALSE; if ( test_entry != NULL ) { - if ( ( test_entry->funct == FC_TOKEN_FUNC ) || - ( test_entry->funct == OBSO_FC_FUNC ) ) - { - retval = TRUE; - } + retval = test_entry->is_token; } return ( retval ); } @@ -1836,9 +1918,10 @@ * Inputs: * Parameters: NONE * Global Variables: + * current_device_node Vocab struct of current dev-node + * Local Static Variables: * global_voc_reset_ptr Position to which to reset * the "Global" Vocabulary - * current_device_node Vocab struct of current dev-node * * Outputs: * Returned Value: NONE
Modified: fcode-utils/toke/emit.c =================================================================== --- fcode-utils/toke/emit.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/emit.c 2006-10-30 09:48:28 UTC (rev 100) @@ -30,6 +30,19 @@ * Modifications Author: David L. Paktor dlpaktor@us.ibm.com **************************************************************************** */
+/* ************************************************************************** + * + * Still to be done: + * Re-arrange routine and variable locations to clarify the + * functions of this file and its companion, stream.c + * This file should be concerned primarily with management + * of the Outputs; stream.c should be primarily concerned + * with management of the Inputs. + * Hard to justify, pragmatically, but will make for easier + * maintainability down the proverbial road... + * + **************************************************************************** */ + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -58,6 +71,20 @@
/* ************************************************************************** * + * Global Variables Exported: + * opc Output Buffer Position Counter + * pci_hdr_end_ob_off Offsets into Output Buffer of end + * of last PCI Header Block structure + * (To help match up the offset printed in Tokenization_error() + * with the offsets shown by the DeTokenizer) + * + **************************************************************************** */ + +unsigned int opc = 0; +unsigned int pci_hdr_end_ob_off = 0; /* 0 means "Not initialized" */ + +/* ************************************************************************** + * * Macro to zero-fill a field of the size of the given structure * into the Output Buffer using the emit_byte() routine. * @@ -113,8 +140,8 @@ /* ************************************************************************** * * Function name: init_emit - * Synopsis: Initialize Local Static Variables before starting - * Output. + * Synopsis: Initialize Output-related Local Static and Global + * Variables before starting Output. * Exposure as Limited as possible. * **************************************************************************** */ @@ -126,6 +153,8 @@ fcode_body_ob_off = -1; pci_hdr_ob_off = -1; pci_data_blk_ob_off = -1; + opc = 0; + pci_hdr_end_ob_off = 0; fcode_written = FALSE; haveend = FALSE; /* Get this one too... */ } @@ -462,13 +491,19 @@ * Inputs: * Parameters: NONE * Global Variables: + * opc Output Buffer Position Counter * fcode_start_ob_off Initted if FCode output has begun * noerrors The "Ignore Errors" flag * * Outputs: * Returned Value: NONE * Global Variables: - * FCode Output buffer: + * pci_hdr_end_ob_off Set to the Output Buffer Position + * Counter after the PCI Header + * FCode Output buffer + * :The beginning of the PCI Header will be entered, waiting for + * the fields that could not be determined until the end + * to be filled in. * * Error Detection: * An attempt to write a PCI Header after FCode output -- either an @@ -496,6 +531,8 @@ emit_pci_rom_hdr();
emit_pci_data_block(); + + pci_hdr_end_ob_off = opc; }
/* ************************************************************************** @@ -561,8 +598,18 @@ pci_hdr_ob_off = -1; pci_data_blk_ob_off = -1; + pci_hdr_end_ob_off = 0; }
+ +/* ************************************************************************** + * + * Function name: finish_headers + * Synopsis: Fill-in the fields of the FCode- and PCI- Headers + * that could not be determined until the end. + * + *************************************************************************** */ + void finish_headers(void) { if (fcode_hdr_ob_off != -1) finish_fcodehdr();
Modified: fcode-utils/toke/emit.h =================================================================== --- fcode-utils/toke/emit.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/emit.h 2006-10-30 09:48:28 UTC (rev 100) @@ -96,6 +96,15 @@
/* ************************************************************************** * * + * Global Variables Exported + * + **************************************************************************** */ + +extern unsigned int opc; +extern unsigned int pci_hdr_end_ob_off; + +/* ************************************************************************** * + * * Function Prototypes / Functions Exported: * **************************************************************************** */
Modified: fcode-utils/toke/errhandler.c =================================================================== --- fcode-utils/toke/errhandler.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/errhandler.c 2006-10-30 09:48:28 UTC (rev 100) @@ -59,7 +59,15 @@ * **************************************************************************** */
+/* ************************************************************************** + * + * Revision History: + * Updated Fri, 13 Oct 2006 by David L. Paktor + * Added "(Output Position ..." to standard message format. + * + **************************************************************************** */
+ /* ************************************************************************** * * We will define a set of bit-valued error-types and a @@ -89,13 +97,18 @@ * It's a deprecated feature, or one * that might be incompatible with * other standard tokenizers. + * + * Other types of Messages fall into these broad categories: * INFO Nothing is changed in processing, but - * an advisory is still in order. + * an advisory is still in order. Omitted + * if "verbose" is not specified. * MESSAGE Message generated by the user. (Complete; * new-line will be added by display routine.) * P_MESSAGE Partial Message -- Instigated by user, but * pre-formatted and not complete. New-line * will be added by follow-up routine. + * TRACER Message related to the trace-symbols option; + * either a creation or an invocation message. * **************************************************************************** */
@@ -108,6 +121,7 @@ #include "types.h" #include "toke.h" #include "stream.h" +#include "emit.h" #include "errhandler.h" #include "scanner.h"
@@ -118,6 +132,9 @@ * lineno Current line-number being processed * noerrors "Ignore Errors" flag, set by "-i" switch * opc FCode Output Buffer Position Counter + * pci_hdr_end_ob_off + * Position in FCode Output Buffer of + * end of last PCI Header Block structure * verbose If true, enable Advisory Messages * **************************************************************************** */ @@ -139,6 +156,7 @@ * warn_count Count of Warning Messages * info_count Count of "Advisory" Messages * user_msg_count Count of User-generated Messages + * trace_msg_count Count of Trace-Note Messages * fatal_err_exit Exit code to be used for "Fatal" error. * This is a special accommodation * for the safe_malloc routine. @@ -147,12 +165,13 @@
static bool print_msg ; static int errs_to_print = ( FATAL | TKERROR | WARNING | - MESSAGE | P_MESSAGE | FORCE_MSG ) ; + MESSAGE | P_MESSAGE | TRACER | FORCE_MSG ) ; static int err_types_found = 0 ; static int err_count = 0 ; static int warn_count = 0 ; static int info_count = 0 ; static int user_msg_count = 0 ; +static int trace_msg_count = 0 ; static int fatal_err_exit = -1 ; static FILE *message_dest; /* Would like to init to ERRMSG_DESTINATION * here, but the compiler complains... @@ -186,15 +205,14 @@ { WARNING, "Warning" , "", "s", &warn_count , FALSE }, { INFO, "Advisor" , "y", "ies", &info_count , FALSE }, { MESSAGE , "Message" , "", "s", &user_msg_count , TRUE }, - { P_MESSAGE , "Message" , "", "s", &user_msg_count , FALSE } + { P_MESSAGE , "Message" , "", "s", &user_msg_count , FALSE }, + { TRACER , "Trace-Note" , "", "s", &trace_msg_count , FALSE } };
static const int num_categories = ( sizeof(error_categories) / sizeof(err_category) );
-#ifdef NEEDS_STRUPR - /* ************************************************************************** * * Function name: toup @@ -328,8 +346,6 @@ }
-#endif /* NEEDS_STRUPR */ - /* ************************************************************************** * * Function name: init_error_handler @@ -359,6 +375,7 @@ * warn_count Count of Warning Messages * info_count Count of "Advisory" Messages * user_msg_count Count of User-generated Messages + * trace_msg_count Count of Trace-Note Messages * Other Exotic Effects: * Flush stdout if Error message destination is not stdout, to * avoid collisions with stderr once Error Messaging begins. @@ -371,13 +388,18 @@
void init_error_handler( void) { + int indx ; + message_dest = ERRMSG_DESTINATION; if ( verbose ) errs_to_print |= INFO ; err_types_found = 0 ; - err_count = 0 ; - warn_count = 0 ; - info_count = 0 ; - user_msg_count = 0 ; + + /* Start at indx = 1 to skip resetting FATALs */ + for ( indx = 1; indx < num_categories ; indx ++ ) + { + *(error_categories[indx].counter) = 0 ; + } + FFLUSH_STDOUT }
@@ -397,6 +419,11 @@ * iname Name of file currently being processed * lineno Current line-number being processed * fatal_err_exit Exit code for "Fatal" error, if applicable. + * opc FCode Output Buffer Position Counter + * pci_hdr_end_ob_off + * Position in FCode Output Buffer of end + * of last PCI Header Block structure + * Macro: * ERRMSG_DESTINATION Error message destination; * (Development-time switch) @@ -444,6 +471,11 @@ * Error-Category string also identifies the applicable * Category Counter; increment it. * Of course, there's no return from a FATAL error; it exits. + * The Message will show: + * The Error-Category (always) + * The Input File-name and Line Number (if input file was opened) + * The Output Buffer Position (if output has begun) + * The PCI-Block Position (if different from Output Buffer Pos'n) * **************************************************************************** */
@@ -490,15 +522,25 @@ { va_list argp;
+ fprintf(ERRMSG_DESTINATION, "%s%s: ", + catgy_name, catgy_suffx); if ( iname != NULL ) { - fprintf(ERRMSG_DESTINATION, "%s%s: File %s, Line %d. ", - catgy_name, catgy_suffx, iname, lineno); - }else{ /* Don't print iname or lineno if no file opened. */ - fprintf(ERRMSG_DESTINATION, "%s%s: ", - catgy_name, catgy_suffx); + fprintf(ERRMSG_DESTINATION, "File %s, Line %d. ", + iname, lineno); } + if ( opc > 0 ) + { + /* Don't print Output Position if no output started. */ + fprintf(ERRMSG_DESTINATION, "(Output Position = %d). ", opc); + } + if ( pci_hdr_end_ob_off > 0 ) + { + /* Don't print PCI-Block Position if no PCI-Block in effect. */ + fprintf(ERRMSG_DESTINATION, "(PCI-Block Position = %d). ", + opc - pci_hdr_end_ob_off ); + }
va_start(argp, msg); vfprintf(ERRMSG_DESTINATION, msg, argp); @@ -618,7 +660,7 @@
if ( may_show_incolon ) { - in_last_colon(); + in_last_colon( TRUE ); }else{ fprintf(message_dest, "\n"); } @@ -765,7 +807,10 @@ * Can be used to finish the line in either case. * * Inputs: - * Parameters: NONE + * Parameters: + * say_in If TRUE, lead phrase with " in ". + * If FALSE, print even if not + * inside a Colon-def'n. * Global Variables: * incolon TRUE if Colon-definition is in progress * last_colon_defname Name of last colon-definition @@ -787,17 +832,17 @@ * Because this routine does some of its own printing, it needs * to check the residual state of print_msg first. * The calling routine does not need to test incolon ; it can - * call this to end the line in either case. + * call this (with TRUE) to end the line in either case. * **************************************************************************** */
-void in_last_colon( void ) +void in_last_colon( bool say_in ) { if ( print_msg ) { - if ( incolon ) + if ( incolon || ( ! say_in ) ) { - fprintf( message_dest, " in definition of %s ", + fprintf( message_dest, "%s definition of %s ", say_in ? " in" : "", strupr( last_colon_defname) ); print_where_started( TRUE, FALSE, last_colon_filename, last_colon_lineno, FALSE);
Modified: fcode-utils/toke/errhandler.h =================================================================== --- fcode-utils/toke/errhandler.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/errhandler.h 2006-10-30 09:48:28 UTC (rev 100) @@ -44,6 +44,7 @@ #define TKERROR 0x04000000 #define WARNING 0x00200000 #define INFO 0x00010000 +#define TRACER 0x00008000 #define MESSAGE 0x00000800 #define P_MESSAGE 0x00000040 #define FORCE_MSG 0x00000001 @@ -55,7 +56,7 @@ void just_started_at( char * saved_ifile, unsigned int saved_lineno); void where_started( char * saved_ifile, unsigned int saved_lineno); void just_where_started( char * saved_ifile, unsigned int saved_lineno); -void in_last_colon( void ); +void in_last_colon( bool say_in ); _PTR safe_malloc( size_t size, char *phrase); bool error_summary( void ); /* Return TRUE if OK to produce output. */
@@ -88,17 +89,7 @@ #define FFLUSH_STDOUT /* Don't need to do anything here */ #endif /* Switchable error-message destination */
-/* Some systems don't seem to have strupr */ -#ifdef SYS_IS_GNU_Linux -#define NEEDS_STRUPR -#endif /* SYS_IS_GNU_Linux */ -#ifdef SYS_IS_AIX -#define NEEDS_STRUPR -#endif /* SYS_IS_AIX */ -/* ??? Should this instead be tuned to Proc'r is PPC ??? Why? */
-#ifdef NEEDS_STRUPR - /* ************************************************************************** * * A necessary hack for systems that don't seem @@ -114,6 +105,4 @@ #define strlwr strlower
-#endif /* NEEDS_STRUPR */ - #endif /* _TOKE_ERRHANDLER_H */
Modified: fcode-utils/toke/flowcontrol.c =================================================================== --- fcode-utils/toke/flowcontrol.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/flowcontrol.c 2006-10-30 09:48:28 UTC (rev 100) @@ -479,7 +479,7 @@ retval = FALSE; tokenization_error ( TKERROR, "Control-Stack underflow at %s", strupr(statbuf) ); - in_last_colon(); + in_last_colon( TRUE);
not_cs_underflow = FALSE; /* See expl'n early on in this file */ }
Modified: fcode-utils/toke/macros.c =================================================================== --- fcode-utils/toke/macros.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/macros.c 2006-10-30 09:48:28 UTC (rev 100) @@ -57,13 +57,13 @@ #include <string.h> #include <errno.h>
+#include "macros.h" #include "errhandler.h" #include "ticvocab.h" #include "stream.h" #include "scanner.h" #include "dictionary.h" #include "devnode.h" -#include "macros.h"
/* ************************************************************************** * @@ -297,7 +297,15 @@ BUILTIN_MACRO( "blank", "bl fill") , BUILTIN_MACRO( "carret", "h# d") , BUILTIN_MACRO( ".d", "base @ swap h# a base ! . base !") , - BUILTIN_MACRO( "decode-bytes", ">r over r@ + swap r@ - rot r>") , + + /* Note: The Standard gives: ">r over r@ + swap r@ - rot r>" + * as its example of the macro for decode-bytes + * But here's one that does the same thing without + * using return-stack operations. And it's one step + * shorter, into the bargain! + */ + BUILTIN_MACRO( "decode-bytes", "tuck - -rot 2dup + swap 2swap rot") , + BUILTIN_MACRO( "3drop", "drop 2drop") , BUILTIN_MACRO( "3dup", "2 pick 2 pick 2 pick") , BUILTIN_MACRO( "erase", "0 fill") , @@ -473,9 +481,6 @@ tic_hdr_t **target_vocab = current_definitions; if ( in_tokz_esc ) target_vocab = &tokz_esc_vocab ;
- warn_if_duplicate( macroname); - trace_creation( MACRO_DEF, macroname); - /* Tack on a new-line, so that a remark will appear * to be properly terminated. This might trigger * an undeserved multi-line warning if the Macro @@ -489,7 +494,7 @@
add_tic_entry( macroname, EVAL_MAC_FUNC, (TIC_P_DEFLT_TYPE)macrobody, - MACRO_DEF, mac_body_len, + MACRO_DEF, mac_body_len, FALSE, EVAL_MAC_FUNC, target_vocab ); failure = FALSE; }
Modified: fcode-utils/toke/nextfcode.c =================================================================== --- fcode-utils/toke/nextfcode.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/nextfcode.c 2006-10-30 09:48:28 UTC (rev 100) @@ -556,8 +556,6 @@ * Inputs: * Parameters: * test_fcode FCode to be tested - * Global Variables: - * * Local Static Variables: * ranges_exist If not TRUE, no need to test * first_fc_range Start of Ranges to test @@ -610,7 +608,7 @@ * Parameters: * * Global Variables: - * nextfcode + * nextfcode The FCode-number to be assigned * Local Static Variables: * ranges_exist TRUE if FCode Ranges have been created * first_fc_range First entry in linked list of Ranges. @@ -618,7 +616,6 @@ * * Outputs: * Returned Value: NONE - * Global Variables: * Local Static Variables: * changes_listed Reset to FALSE * One of these two will be set to nextfcode
Modified: fcode-utils/toke/parselocals.c =================================================================== --- fcode-utils/toke/parselocals.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/parselocals.c 2006-10-30 09:48:28 UTC (rev 100) @@ -78,15 +78,18 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> + +#include "parselocals.h" #include "ticvocab.h" #include "dictionary.h" #include "scanner.h" -#include "parselocals.h" #include "errhandler.h" #include "clflags.h" #include "stream.h" +#include "emit.h" #include "devnode.h" #include "flowcontrol.h" +#include "tracesyms.h"
/* ************************************************************************** * @@ -335,8 +338,8 @@
lnamecopy = strdup( lname); add_tic_entry( lnamecopy, invoke_local, lnum, - LOCAL_VAL, 0, NULL, &local_names ); - trace_creation( LOCAL_VAL, lname); + LOCAL_VAL, 0, FALSE, NULL, + &local_names ); }
@@ -423,7 +426,7 @@ tokenization_error ( TKERROR, "Excess separator -- %s -- found " "in Local-Values declaration", statbuf); - in_last_colon(); + in_last_colon( TRUE); continue; } } @@ -570,7 +573,7 @@ if ( last_local_colon == lastcolon ) { tokenization_error ( TKERROR, "Excess Locals Declaration"); - in_last_colon(); + in_last_colon( TRUE); retval = TRUE; }else{ last_local_colon = lastcolon;
Modified: fcode-utils/toke/scanner.c =================================================================== --- fcode-utils/toke/scanner.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/scanner.c 2006-10-30 09:48:28 UTC (rev 100) @@ -82,6 +82,9 @@ bool haveend = FALSE; /* TRUE if the "end" code was read. */ int do_loop_depth = 0; /* How deep we are inside DO ... LOOP variants */
+/* State of headered-ness for name-creation */ +headeredness hdr_flag = FLAG_HEADERLESS ; /* Init'l default state */ + /* Used for error-checking of IBM-style Locals */ int lastcolon; /* Location in output stream of latest colon-definition. */
@@ -92,6 +95,10 @@ bool report_multiline = TRUE; /* False to suspend multiline warning */ unsigned int last_colon_abs_token_no;
+ /* Shared phrases */ +char *in_tkz_esc_mode = "in Tokenizer-Escape mode.\n"; +char *wh_defined = ", which is defined as a "; + /* ************************************************************************** * Local variables **************************************************************************** */ @@ -103,13 +110,6 @@
static unsigned int last_colon_do_depth = 0;
-/* State of headered-ness for name-creation */ -typedef enum headeredness_t { - FLAG_HEADERLESS , - FLAG_EXTERNAL , - FLAG_HEADERS } headeredness ; -static headeredness hdr_flag = FLAG_HEADERLESS ; /* Init'l default state */ - /* Local variables having to do with: */ /* ... the state of the tokenization */ static bool is_instance = FALSE; /* Is "instance" is in effect? */ @@ -133,10 +133,7 @@ /* Has a gap developed between "instance" and its application? */ static bool instance_definer_gap = FALSE;
- /* Shared phrases */ -static char *in_tkz_esc_mode = "in Tokenizer-Escape mode.\n";
- /* ************************************************************************** * * Function name: skip_ws @@ -821,7 +818,7 @@ unterm_is_colon = FALSE; }else{ tokenization_error( severity, "Unterminated %s", something); - in_last_colon(); + in_last_colon( TRUE); } lineno = tmp; } @@ -1349,7 +1346,8 @@ * -delimiting whitespace character. Regard any sub- * sequent whitespace characters as part of the string */ - if (*pc++=='\n') lineno++; + if ( *pc == '\n' ) lineno++; + pc++;
got_until_eof = TRUE ;
@@ -1564,7 +1562,8 @@ { if ( *pc != '\n') pc++; }else{ - if (*pc++=='\n') lineno++; + if ( *pc == '\n' ) lineno++; + pc++; multiline_start = lineno; check_multiline = TRUE; } @@ -1914,7 +1913,7 @@ * * Outputs: * Returned Value: None - * Local Static Variables: + * Global Variables: * hdr_flag Adjusted to new setting * * Process Explanation: @@ -2161,7 +2160,7 @@
tokenization_error( TKERROR, "%s outside of %s structure", strupr(statbuf), deep_do); - in_last_colon(); + in_last_colon( TRUE); }
} @@ -2288,7 +2287,7 @@
tokenization_error( WARNING, "Possible Return-Stack %s before %s", what_flow, what_phr); - in_last_colon(); + in_last_colon( TRUE);
if ( clear_it ) { @@ -2335,7 +2334,7 @@ "Possible Return-Stack access attempt by %s " "without value having been placed there", strupr(statbuf) ); - in_last_colon(); + in_last_colon( TRUE); } }
@@ -2462,7 +2461,7 @@ * **************************************************************************** */
-static bool definer_name(fwtoken definer, char **reslt_ptr) +bool definer_name(fwtoken definer, char **reslt_ptr) { bool retval = TRUE; switch (definer) @@ -2533,6 +2532,11 @@ * are needed, they, too, are the responsibility of the * calling routine. The return value gives a helpful clue. * + * Extraneous Remarks: + * We define a Macro -- kept in scanner.h --that will give the + * recommended length for the buffer passed to this routine. + * It will be called AS_WHAT_BUF_SIZE + * **************************************************************************** */
bool as_a_what( fwtoken definer, char *as_what) @@ -2639,7 +2643,7 @@ * **************************************************************************** */
-static char lookup_where_pt1_buf[32]; +static char lookup_where_pt1_buf[AS_WHAT_BUF_SIZE];
tic_hdr_t *lookup_word( char *stat_name, char **where_pt1, char **where_pt2 ) { @@ -2883,7 +2887,10 @@ * * Outputs: * Returned Value: NONE - * Printout: Error message. Possible Advisory about + * Printout: + * Error message. + * Possible Advisory about where the word might be found. + * Trace-Note, if the word was on the Trace-List * * Error Detection: * Error was detected by the calling routine... @@ -2911,6 +2918,8 @@ bool sav_in_tokz_esc = in_tokz_esc; in_tokz_esc = INVERSE(sav_in_tokz_esc);
+ traced_name_error( stat_name); + found_somewhere = word_exists( stat_name, &where_pt1, &where_pt2); if ( found_somewhere ) { @@ -3073,88 +3082,6 @@
/* ************************************************************************** * - * Function name: trace_creation - * Synopsis: If the word being created is on the Trace List, - * display the appropriate message - * - * Inputs: - * Parameters: - * definer Internal token for the defining-word - * nu_name The word being created - * Global Variables: - * verbose No point in doing all this if we're - * not showing the message anyway... - * in_tokz_esc TRUE if we are in Tokenizer-Escape mode - * scope_is_global TRUE if "global" scope is in effect - * current_device_node Current dev-node data-struct - * - * Outputs: - * Returned Value: NONE - * Printout: - * Advisory Message, if the word is on the Trace List. - * - * Process Explanation: - * The order of scope-checking is important: - * A Local has no scope beyond the definition in which it occurs. - * Tokenizer-Escape mode supercedes "Normal" mode, and renders - * moot the differences between Global and Device scope. - * Global scope is mutually exclusive with Device scope. - * Device scope needs to identify where the Current device-node - * began. - * - **************************************************************************** */ - -void trace_creation( fwtoken definer, char *nu_name) -{ - if ( verbose ) - { - if ( is_on_trace_list( nu_name) ) - { - char as_what[96] = ""; - bool show_last_colon = BOOLVAL( definer == LOCAL_VAL); - - as_a_what( definer, as_what); /* No need to check return value. */ - - /* Scope-checking starts here, unless show_last_colon is TRUE. - * Come out of this with as_what[] filled up and - * terminated with a new-line, if appropriate, - */ - while ( ! show_last_colon ) - { - strcat( as_what, " "); - - if ( in_tokz_esc ) - { - strcat( as_what, in_tkz_esc_mode); - break; - } - - if ( scope_is_global ) - { - strcat( as_what, "with Global scope.\n"); - }else{ - /* In Device scope. Show the Current node. */ - strcat( as_what, in_what_node( current_device_node)); - } - break; - - } /* Destination of BREAKs ... */ - - tokenization_error(INFO, "Creating %s %s", nu_name, as_what); - - if ( show_last_colon ) - { - in_last_colon(); - }else{ - show_node_start(); - } - - } - } -} - -/* ************************************************************************** - * * Function name: create_word * Synopsis: * @@ -3180,6 +3107,15 @@ * nextfcode Incremented (by bump_fcode() ) * statbuf Advanced to next symbol; must be re-read * pc Advanced, then restored to previous value + * define_token Normally TRUE. Made FALSE if the definition + * occurs inside a control-structure, (which + * is an Error); we allow the definition to + * proceed (so as to avoid "cascade" errors + * and catch other errors normally) but we + * suppress adding its token to the vocab, + * "hiding" it and "revealing" it (because + * there's nothing to hide). + * NOTE: Make this a Global. Use it in the routines it controls... * Memory Allocated * Copy of the name being defined, by support routine. * Copy of input-source file name, for error-reporting @@ -3249,8 +3185,9 @@ { char defn_type_buffr[32] = ""; unsigned int old_lineno = lineno; /* For error message */ - bool define_token = TRUE;
+ define_token = TRUE; + { /* Set up definition-type text for error-message */
/* No need to check the return value */ @@ -3280,20 +3217,17 @@ }else{ bool emit_token_name = TRUE;
- /* Handle Tracing of new definitions */ - trace_creation( definer, statbuf); - /* Other Error or Warnings as applicable */ validate_instance( definer); - warn_if_duplicate( statbuf); - check_name_length( wlen);
/* Bump FCode; error-check as applicable */ assigning_fcode();
/* Define the new token, unless disallowed */ - add_to_current( statbuf, nextfcode, definer, define_token); + add_to_current( statbuf, nextfcode, definer);
+ check_name_length( wlen); + /* Emit appropriate FCodes: Type of def'n, */ switch ( hdr_flag ) { @@ -3375,7 +3309,7 @@ static void cannot_apply( char *func_nam, char *targ_nam, fwtoken defr) { char *defr_name = "" ; - const char *defr_phrase = ", which is defined as a " ; + char *defr_phrase = wh_defined ;
if ( ! definer_name(defr, &defr_name) ) { @@ -3797,24 +3731,29 @@ * Outputs: * Returned Value: TRUE if successful (i.e., no error) * Supplied Pointers: - * *tok_entry The token entry, if no error + * *tok_entry The token entry, if no error. + * Unchanged if error. * Global Variables: * statbuf The next word in the input stream * pc Restored to previous value if error + * Other Effects: + * Display Invocation Message if entry found and is being Traced * * Error Detection: * The next word in the input stream is expected to be on the * same line as the directive. The get_word_in_line() * routine will check for that. - * If the next word in the input stream is not a symbol - * for which a single-token FCode number is assigned, - * report an ERROR and restore PC to its previous value. + * If the next word in the input stream is a known symbol, but + * not one for which a single-token FCode number is assigned, + * report an ERROR and restore PC to its previous value. The + * supplied pointer tok_entry will remain unaltered. * **************************************************************************** */
static bool get_token(tic_hdr_t **tok_entry) { bool retval = FALSE; + tic_hdr_t *found; u8 *save_pc;
/* Copy of command being processed, for error message */ @@ -3837,8 +3776,8 @@ * need to search again, specifically within the list * of FCode Tokens. */ - *tok_entry = lookup_with_definer( statbuf, &defr); - if ( *tok_entry != NULL ) + found = lookup_with_definer( statbuf, &defr); + if ( found != NULL ) { /* Built-in FWords can be uniquely identified by their * definer, BI_FWRD_DEFN . The definer for "shared" @@ -3848,15 +3787,19 @@ */ if ( defr == BI_FWRD_DEFN ) { - *tok_entry = lookup_token( statbuf); - retval = BOOLVAL( *tok_entry != NULL ); + found = lookup_token( statbuf); + retval = BOOLVAL( found != NULL ); }else{ - retval = entry_is_token( *tok_entry); + retval = entry_is_token( found); } }
- if ( INVERSE( retval) ) + handle_invocation( found); + + if ( retval) { + *tok_entry = found; + }else{ cannot_apply( cmnd_cpy, strupr(statbuf), defr ); pc = save_pc; } @@ -4180,9 +4123,7 @@ * Two words will be read. * * Outputs: - * Returned Value: TRUE if succeeded. - * Global Variables: - * statbuf New name will be copied back into here. + * Returned Value: NONE * Memory Allocated * The two words will be copied into freshly-allocated memory * that will be passed to the create_..._alias() routine. @@ -4195,16 +4136,15 @@ * If the ALIAS command was given during colon-definition, that * can be handled by this tokenizer, but it is not supported * by IEEE 1275-1994. Issue a WARNING. - * If the new name is a copy of an existing word-name, issue a warning. * If the word to which an alias is to be created does not exist * in the appropriate mode -- relative to "Tokenizer-Escape" -- * that is an ERROR. * If "instance" is in effect, the ALIAS command is an ERROR. + * Duplicate-name Warning is handled by support-routine. * * Process Explanation: * Get two words -- the new name and the "old" word -- from the * same line of input as the ALIAS command. - * Copy the new name back into statbuf for use in trace_creation. * Determine whether or not we are in "Tokenizer-Escape" mode. * Subsequent searches will take place in that same mode. * If the "new" name already exists, issue a warning. @@ -4234,10 +4174,15 @@ * Revision History: * Updated Tue, 10 Jan 2006 by David L. Paktor * Convert to tic_hdr_t type vocabularies. + * Updated Fri, 22 Sep 2006 by David L. Paktor + * Move the warn_if_duplicate() call to the calling routine. + * Updated Wed, 11 Oct 2006 by David L. Paktor + * Move the Tracing and Duplicate-Warning message functions + * into support routine. * **************************************************************************** */
-static bool create_alias( void ) +static void create_alias( void ) { char *new_alias ;
@@ -4257,30 +4202,6 @@ { char *old_name = strdup((char *)statbuf) ;
- /* Copy the "new" alias name back into statbuf. - * This is a HACK ^H^H^H^H awkward way to retrofit - * support for the trace_creation() function. - */ - strcpy( statbuf, new_alias); - - /* We don't call trace_creation() here because we don't - * know if the creation succeeded. However, we want - * to issue a "Duplicate" warning based on the attempt, - * even if it doesn't succeed. - * We would prefer to have the "Trace" message precede the - * "Duplicate" warning, but we don't think it's worth - * the effort. When it becomes worthwhile, the way to - * do it would be to factor out the block that handles - * normal-tokenization versus "Tokenizer-Escape" mode; - * condition the "Trace" message on its success-return, - * show the "Duplicate" warning in any case, then show - * the error-message and do the cleanup conditioned on - * a failure-return. - * That will also obviate the need for a return value from - * this routine and for the copy-back into statbuf. - */ - warn_if_duplicate(new_alias); - /* * Here is where we begin trying the create_..._alias() * routines for the vocabularies. @@ -4293,7 +4214,7 @@ if ( in_tokz_esc ) { if ( create_tokz_esc_alias( new_alias, old_name) ) - return(TRUE); + return; /* * Handle the classes of operatives that are common between @@ -4306,7 +4227,7 @@ if ( found != NULL ) { if ( create_core_alias( new_alias, old_name) ) - return(TRUE); + return; } } }else{ @@ -4314,7 +4235,7 @@ /* Can create aliases for "Locals", why not? */ if ( create_local_alias( new_alias, old_name) ) - return(TRUE); + return;
/* * All other classes of operatives -- non-fcode forth @@ -4325,19 +4246,19 @@ */
if ( create_current_alias( new_alias, old_name) ) - return(TRUE); + return; } /* End of separate handling for normal-tokenization mode * versus "Tokenizer-Escape" mode */
/* It's not a word, a macro or any of that other stuff. */ + trace_create_failure( new_alias, old_name, 0); tokenized_word_error(old_name); free(old_name); } free (new_alias); } - return(FALSE); }
@@ -4443,6 +4364,9 @@ unsigned int sav_lineno = lineno; /* For error message */
bool handy_toggle = TRUE ; /* Various uses... */ + bool handy_toggle_too = TRUE ; /* Various other uses... */ + char *handy_string = ""; + int handy_int = 0; #ifdef DEBUG_SCANNER printf("%s:%d: debug: tokenizing control word '%s'\n", @@ -4594,10 +4518,7 @@ break;
case ALIAS: - if ( create_alias() ) - { - trace_creation( ALIAS, statbuf); - } + create_alias(); break;
case CONTROL: @@ -4916,19 +4837,21 @@ break;
case FUNC_NAME: - if ( test_in_colon( statbuf, TRUE, TKERROR, NULL) ) - { if ( in_tokz_esc ) { + if ( incolon ) + { tokenization_error( P_MESSAGE, "Currently" ); - in_last_colon(); }else{ + tokenization_error( P_MESSAGE, "After" ); + } + in_last_colon( incolon); + }else{ emit_token("b(")"); emit_string( last_colon_defname, strlen( last_colon_defname) ); /* if ( hdr_flag == FLAG_HEADERLESS ) { WARNING } */ } - } break;
case IFILE_NAME: @@ -5066,19 +4989,56 @@ break;
case RET_STK_FETCH: - ret_stk_access_rpt(); - emit_token( "r@"); - break; - + /* handy_toggle controls reloading other "handy_"s + * handy_toggle_too controls calling ret_stk_access_rpt() + * handy_int, if non-zero, passed to bump_ret_stk_depth() + */ + /* First in series doesn't need to check handy_toggle */ + handy_string = "r@"; + /* Will call ret_stk_access_rpt() */ + /* handy_toggle_too is already TRUE */ + /* Will not call bump_ret_stk_depth() */ + /* handy_int is already zero */ + handy_toggle = FALSE; case RET_STK_FROM: - ret_stk_access_rpt(); - bump_ret_stk_depth( -1); - emit_token( "r>"); - break; - + if ( handy_toggle ) + { + handy_string = "r>"; + /* Will call ret_stk_access_rpt() */ + /* handy_toggle_too is already TRUE */ + /* Will call bump_ret_stk_depth( -1) */ + handy_int = -1; + handy_toggle = FALSE; + } case RET_STK_TO: - bump_ret_stk_depth( 1); - emit_token( ">r"); + if ( handy_toggle ) + { + handy_string = ">r"; + /* Will not call ret_stk_access_rpt() */ + handy_toggle_too = FALSE; + /* Will call bump_ret_stk_depth( 1) */ + handy_int = 1; + /* Last in series doesn't need to reset handy_toggle */ + } + + /* handy_toggle is now free for other use */ + handy_toggle = allow_ret_stk_interp; + if ( ! handy_toggle ) + { + handy_toggle = test_in_colon(statbuf, TRUE, TKERROR, NULL ); + } + if ( handy_toggle || noerrors ) + { + if ( handy_toggle_too ) + { + ret_stk_access_rpt(); + } + if ( handy_int != 0 ) + { + bump_ret_stk_depth( handy_int); + } + emit_token( handy_string); + } break;
case PCIHDR: @@ -5490,6 +5450,10 @@ if ( found != NULL ) { tic_found = found; + if ( found->tracing) + { + invoking_traced_name( found); + } found->funct( found->pfield); return ; }
Modified: fcode-utils/toke/scanner.h =================================================================== --- fcode-utils/toke/scanner.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/scanner.h 2006-10-30 09:48:28 UTC (rev 100) @@ -61,6 +61,13 @@ extern bool haveend; /* TRUE if the "end" code was read. */ extern int do_loop_depth; /* How deep we are inside DO ... LOOP variants */
+/* State of headered-ness for name-creation */ +typedef enum headeredness_t { + FLAG_HEADERLESS , + FLAG_EXTERNAL , + FLAG_HEADERS } headeredness ; +extern headeredness hdr_flag; + /* For special-case error detection or reporting */ extern int lastcolon; /* Loc'n in output stream of latest colon-def'n. */ /* Used for error-checking of IBM-style Locals */ @@ -70,6 +77,10 @@ extern bool report_multiline; /* False to suspend multiline warning */ extern unsigned int last_colon_abs_token_no;
+ /* Shared phrases */ +extern char *in_tkz_esc_mode; +extern char *wh_defined; + /* ************************************************************************** * * * Function Prototypes / Functions Exported: @@ -101,23 +112,27 @@ tic_hdr_t *lookup_word( char *stat_name, char **where_pt1, char **where_pt2 ); bool word_exists( char *stat_name, char **where_pt1, char **where_pt2 ); void warn_if_duplicate ( char *stat_name); -void trace_creation( fwtoken definer, char *nu_name); void tokenize_one_word( signed long wlen ); void check_name_length( signed long wlen ); +bool definer_name(fwtoken definer, char **reslt_ptr);
void tokenize( void );
/* ************************************************************************** * - * Macro Name: FUNC_CPY_BUF_SIZE - * Size of a temporary buffer to retain a copy of - * a function name taken from statbuf, when statbuf - * will be used to return a value, but the function - * name might still be needed for an error message. + * Macros: + * FUNC_CPY_BUF_SIZE Recommended size of a temporary buffer to retain + * a copy of a function name taken from statbuf, + * when statbuf will be used to return a value, + * but the function name might still be needed for + * an error message. + * AS_WHAT_BUF_SIZE Recommended size of the buffer passed to the + * as_a_what() routine. * **************************************************************************** */
#define FUNC_CPY_BUF_SIZE 40
+#define AS_WHAT_BUF_SIZE 32
#endif /* _TOKE_SCANNER_H */
Modified: fcode-utils/toke/stream.c =================================================================== --- fcode-utils/toke/stream.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/stream.c 2006-10-30 09:48:28 UTC (rev 100) @@ -55,8 +55,23 @@ * **************************************************************************** */
+ /* ************************************************************************** * + * Still to be done: + * Re-arrange routine and variable locations to clarify the + * functions of this file and its companion, emit.c + * This file should be concerned primarily with management + * of the Inputs; emit.c should be primarily concerned + * with management of the Outputs. + * Hard to justify, pragmatically, but will make for easier + * maintainability down the proverbial road... + * + **************************************************************************** */ + + +/* ************************************************************************** + * * Global Variables Exported * start Start of input-source buffer * end End of input-source buffer @@ -64,7 +79,6 @@ * iname Current Input File name * lineno Current Line Number in Input File * ostart Start of Output Buffer - * opc FCode Output Buffer Position Counter * oname Output File name * **************************************************************************** */ @@ -86,8 +100,8 @@ /* output pointers */ u8 *ostart; char *oname = NULL; -unsigned int opc; /* Output Position Counter */
+ /* We want to limit exposure of this v'ble, so don't put it in .h file */ unsigned int olen; /* Length of Output Buffer */ /* We want to limit exposure of this Imported Function, likewise. */ @@ -1373,7 +1387,6 @@ olen = OUTPUT_SIZE; ostart=safe_malloc(olen, "initting output buffer");
- opc = 0; init_emit(); /* Init'l'zns needed by our companion file, emit.c */
printf("Binary output to %s ", oname); @@ -1494,7 +1507,10 @@ unsigned int rea_len; olen = olen * 2; rea_len = olen; - if ( rea_len == 0 ) rea_len = (unsigned int)-1; + if ( rea_len == 0 ) + { + rea_len = (unsigned int)-1; + } tokenization_error( INFO, "Output Buffer overflow. " "Relocating and increasing to %d bytes.\n", rea_len);
Modified: fcode-utils/toke/stream.h =================================================================== --- fcode-utils/toke/stream.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/stream.h 2006-10-30 09:48:28 UTC (rev 100) @@ -52,7 +52,6 @@ /* output pointers */ extern char *oname; /* output file name */
-extern unsigned int opc; /* output buffer position counter */
/* ************************************************************************** *
Modified: fcode-utils/toke/ticvocab.c =================================================================== --- fcode-utils/toke/ticvocab.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/ticvocab.c 2006-10-30 09:48:28 UTC (rev 100) @@ -102,8 +102,13 @@
#include <stdlib.h> #include <string.h> + #include "ticvocab.h" #include "errhandler.h" +#include "tracesyms.h" +#include "scanner.h" +#include "devnode.h" +#include "vocabfuncts.h"
tic_hdr_t *tic_found;
@@ -133,8 +138,10 @@ * precede this one in the voacbulary) gets entered into * the link-pointer field of the first element of the array. * For this reason, it is important that all TIC_HDR vocabulary - * pointers that will be pased to this routine have their + * pointers that will be passed to this routine have their * initial values explicitly declared NULL. + * If the user has asked to Trace any built-in name, the support + * routine will set its tracing field and dispay a message. * **************************************************************************** */
@@ -147,14 +154,16 @@ { tic_vocab_tbl[indx].next = *tic_vocab_ptr; *tic_vocab_ptr = &tic_vocab_tbl[indx]; + trace_builtin( &tic_vocab_tbl[indx]); } }
/* ************************************************************************** * - * Function name: add_tic_entry - * Synopsis: Add an entry to the given TIC_HDR -type vocabulary + * Function name: make_tic_entry + * Synopsis: Construct a new entry to a TIC_HDR -type vocab-list + * but do not add it to a vocabulary * * Inputs: * Parameters: @@ -163,13 +172,15 @@ * tparam The "parameter field" value (may be a pointer) * fw_defr FWord Token of the entry's Definer * pfldsiz Size of "param field" (if a pointer to alloc'd mem) + * is_single TRUE if entry is a single-token FCode * ign_fnc Pointer to "ignoring" routine for new entry - * tic_vocab Pointer to ptr to "tail" of T.I.C.-type vocab-list + * trace_this TRUE if new entry is to be "Traced" + * tic_vocab Address of the variable that holds the latest + * pointer to the "tail" of the T.I.C.-type + * vocab-list to which we are adding. * * Outputs: - * Returned Value: NONE - * Supplied Pointers: - * *tic_vocab Will point to new entry + * Returned Value: Pointer to the new entry * Memory Allocated: * For the new entry. * When Freed? @@ -183,18 +194,27 @@ * newly-allocated memory-space. If the parameter field is * actually a pointer, it, too, is presumed to already have * been allocated. - * Memory will be allocated for the entry itself; its pointers - * will be entered and the given pointer-to-the-tail-of-the- - * -vocabulary will be updated to point to the new entry. + * Memory will be allocated for the entry itself and the given + * data will be placed into its fields. * + * Extraneous Remarks: + * This is a retro-fit; it's a factor of the add_tic_entry() + * routine, whose functionality has been expanded to include + * issuing the Trace-Note and Duplication Warning messages. + * Having it separate allows it to be called (internally) by + * create_split_alias(), which has special requirements for + * its call to trace_creation() + * **************************************************************************** */
-void add_tic_entry( char *tname, +static tic_hdr_t *make_tic_entry( char *tname, void (*tfunct)(), TIC_P_DEFLT_TYPE tparam, fwtoken fw_defr, int pfldsiz, + bool is_single, void (*ign_fnc)(), + bool trace_this, tic_hdr_t **tic_vocab ) { tic_hdr_t *new_entry; @@ -205,9 +225,89 @@ new_entry->funct = tfunct; new_entry->pfield.deflt_elem = tparam; new_entry->fword_defr = fw_defr; + new_entry->is_token = is_single; new_entry->ign_func = ign_fnc; new_entry->pfld_size = pfldsiz; + new_entry->tracing = trace_this;
+ return( new_entry); +} + + +/* ************************************************************************** + * + * Function name: add_tic_entry + * Synopsis: Add an entry to the given TIC_HDR -type vocabulary; + * issue the Creation Tracing and Duplicate-Name + * messages as applicable. + * + * Inputs: + * Parameters: + * tname Pointer to space containing entry's new name + * tfunct Pointer to the routine the new entry will call + * tparam The "parameter field" value (may be a pointer) + * fw_defr FWord Token of the entry's Definer + * pfldsiz Size of "param field" (if a ptr to alloc'd mem) + * is_single TRUE if entry is a single-token FCode + * ign_fnc Pointer to "ignoring" routine for new entry + * NOTE: No trace_this param here; it's only in make_tic_entry() + * tic_vocab Address of the variable that holds the latest + * pointer to the "tail" of the T.I.C.-type + * vocab-list to which we are adding. + * Global Variables: + * scope_is_global TRUE if "global" scope is in effect + * (passed to "Trace-Creation" message) + * + * Outputs: + * Returned Value: NONE + * Supplied Pointers: + * *tic_vocab Will point to new entry + * Printout: + * "Trace-Creation" message + * + * Error Detection: + * Warning on duplicate name (subject to command-line control) + * + * Process Explanation: + * The entry itself will be created by the make_tic_entry() routine. + * This routine will test whether the new name is to be Traced, + * and will pass that datum to the make_tic_entry() routine. + * If the new name is to be Traced, issue a Creation Tracing message. + * (We want it to appear first). Use the new entry. + * Because this routine will not be called for creating aliases, the + * second param to trace_creation() is NULL. + * Do the duplicate-name check _before_ linking the new entry in to + * the given vocabulary. We don't want the duplicate-name test + * to find the name in the new entry, only in pre-existing ones... + * Now we're ready to update the given pointer-to-the-tail-of-the- + * -vocabulary to point to the new entry. + * + **************************************************************************** */ + +void add_tic_entry( char *tname, + void (*tfunct)(), + TIC_P_DEFLT_TYPE tparam, + fwtoken fw_defr, + int pfldsiz, + bool is_single, + void (*ign_fnc)(), + tic_hdr_t **tic_vocab ) +{ + bool trace_this = is_on_trace_list( tname); + tic_hdr_t *new_entry = make_tic_entry( tname, + tfunct, + tparam, + fw_defr, pfldsiz, + is_single, + ign_fnc, + trace_this, + tic_vocab ); + + if ( trace_this ) + { + trace_creation( new_entry, NULL, scope_is_global); + } + warn_if_duplicate( tname); *tic_vocab = new_entry;
} @@ -221,6 +321,7 @@ * Parameters: * tname The "target" name for which to look * tic_vocab Pointer to the T. I. C. -type vocabulary + * in which to search * * Outputs: * Returned Value: Pointer to the relevant entry, or @@ -229,8 +330,8 @@ * Extraneous Remarks: * We don't set the global tic_found here because this routine * is not always called when the found function is going to - * be executed; sometimes it is called for error-detection, - * for instance... + * be executed; sometimes it is called for error-detection; + * for instance, duplicate-name checking... * **************************************************************************** */
@@ -282,9 +383,11 @@
/* ************************************************************************** * - * Function name: create_tic_alias - * Synopsis: Create an Alias in a TIC_HDR -type vocabulary + * Function name: create_split_alias + * Synopsis: Create an Alias in one TIC_HDR -type vocabulary + * for a word in (optionally) another vocabulary. * Return a "success" flag. + * This is the work-horse for create_tic_alias() * * Associated FORTH word: ALIAS * @@ -292,18 +395,25 @@ * Parameters: * old_name Name of existing entry * new_name New name for which to create an entry - * *tic_vocab Pointer to the "tail" of the - * T. I. C. -type vocab-list + * *src_vocab Pointer to the "tail" of the "Source" + * TIC_HDR -type vocab-list + * *dest_vocab Pointer to the "tail" of the "Destination" + * TIC_HDR -type vocab-list * * Outputs: - * Returned Value: TRUE if old_name found in given vocab + * Returned Value: TRUE if old_name found in "Source" vocab * Supplied Pointers: - * *tic_vocab Will be updated to point to the new entry + * *dest_vocab Will be updated to point to the new entry * Memory Allocated: * For the new entry, by the support routine. * When Freed? - * When reset_tic_vocab() is applied to the same vocab-list. + * When reset_tic_vocab() is applied to "Destination" vocab-list. + * Printout: + * "Trace-Creation" message * + * Error Detection: + * Warning on duplicate name (subject to command-line control) + * * Process Explanation: * Both the "old" and "new" names are presumed to already point to * stable, freshly allocated memory-spaces. @@ -314,28 +424,92 @@ * the reference to the old space will work, and the old * entry's param-field memory space will not be freed with * the alias-entry but only with the "old" entry. + * We will do both the "Creation-Tracing" announcement and the + * Duplicate Name Warning here. "Tracing" happens either if + * the entry for the old name has its tracing flag set, or + * if the new name is on the trace-list. The "source" vocab + * and the "dest" vocab can only be different when the "old" + * name has defined Global scope. We will pass that along + * to the trace_creation() routine. + * We're doing the "Tracing" and Duplicate-Name functions because + * we're applying the "Tracing" message to the "old" name's + * entry. Because of this, we must call make_tic_entry() to + * bypass add_tic_entry(), which now does its own "Tracing" + * and Duplicate-Name functions on the new entry. * **************************************************************************** */
-bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ) +bool create_split_alias( char *new_name, char *old_name, + tic_hdr_t **src_vocab, tic_hdr_t **dest_vocab ) { tic_hdr_t *found ; bool retval = FALSE;
- found = lookup_tic_entry( old_name, *tic_vocab ); + found = lookup_tic_entry( old_name, *src_vocab ); if ( found != NULL ) { - add_tic_entry( new_name, found->funct, + bool trace_it = found->tracing; + if ( ! trace_it ) + { + trace_it = is_on_trace_list( new_name); + } + if ( trace_it ) + { + bool old_is_global = BOOLVAL( src_vocab != dest_vocab ); + trace_creation( found, new_name, old_is_global); + } + warn_if_duplicate( new_name); + + *dest_vocab = make_tic_entry( new_name, + found->funct, found->pfield.deflt_elem, - found->fword_defr, - 0, found->ign_func, tic_vocab ); + found->fword_defr, 0, + found->is_token, + found->ign_func, + trace_it, + dest_vocab ); retval = TRUE; }
return ( retval ); }
+/* ************************************************************************** + * + * Function name: create_tic_alias + * Synopsis: Create an Alias in a TIC_HDR -type vocabulary + * Return a "success" flag. + * + * Associated FORTH word: ALIAS + * + * Inputs: + * Parameters: + * old_name Name of existing entry + * new_name New name for which to create an entry + * *tic_vocab Pointer to the "tail" of the + * T. I. C. -type vocab-list + * + * Outputs: + * Returned Value: TRUE if old_name found in given vocab + * Supplied Pointers: + * *tic_vocab Will be updated to point to the new entry + * Memory Allocated: + * For the new entry, by the support routine. + * When Freed? + * When reset_tic_vocab() is applied to the same vocab-list. + * + * Process Explanation: + * The given vocabulary is both the "Source" and the "Destination". + * Pass them both to create_split_alias.
+ **************************************************************************** */ + +bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ) +{ + return ( create_split_alias( new_name, old_name, tic_vocab, tic_vocab ) ); +} + + /* ************************************************************************** * * Function name: handle_tic_vocab
Modified: fcode-utils/toke/ticvocab.h =================================================================== --- fcode-utils/toke/ticvocab.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/ticvocab.h 2006-10-30 09:48:28 UTC (rev 100) @@ -52,18 +52,24 @@ * The function may re-cast it as needed. * (5) The "Definer" of the entry; a member of the subset of FWord- * -tokens that may be Definers. - * (6) A Pointer to a routine to be run when the word is encountered + * (6) A flag indicating whether the item is one for which a + * single-token FCode number is assigned. + * (7) A Pointer to a routine to be run when the word is encountered * in a Conditional Compilation section that is being ignored. * Certain functions still need to be recognized in that state, * and will require special behaviors; those that can be simply * ignored will have a NULL pointer in this field. The function * in this field, also, takes the "parameter field" item as its * argument and has no return-value. - * (7) The size of the data pointed to by the "parameter field" item, + * (8) The size of the data pointed to by the "parameter field" item, * if it is a pointer to allocated data; used to allocate space * for a copy of the p.f. when making an alias, and to indicate * whether the space needs to be freed. Automatic procedures * are too often fooled, so we don't leave things to chance... + * (9) A flag, set TRUE if the word is on the Trace List, to indicate + * that an Invocation Message should be displayed when the word + * is invoked. + * * To accommodate C's insistence on strong-typing, we might need * to define different "parameter field" structure-types; see * description of "Parameter Field as a union", below. @@ -176,8 +182,10 @@ void (*funct)(); /* Function for active processing */ tic_param_t pfield; fwtoken fword_defr; /* FWord Token of entry's Definer */ + bool is_token; /* Is entry a single-token FCode? */ void (*ign_func)(); /* Function in "Ignored" segment */ int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ } tic_hdr_t ;
/* ************************************************************************** @@ -203,8 +211,10 @@ void (*funct)(); /* Function for active processing */ tic_fwt_param_t pfield; fwtoken fword_defr; /* FWord Token of entry's Definer */ + bool is_token; /* Is entry a single-token FCode? */ void (*ign_func)(); /* Function in "Ignored" segment */ int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ } tic_fwt_hdr_t ;
@@ -237,8 +247,10 @@ void (*funct)(); tic_mac_param_t pfield; fwtoken fword_defr; + bool is_token; /* Is entry a single-token FCode? */ void (*ign_func)(); int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ } tic_mac_hdr_t ;
/* ************************************************************************** @@ -265,8 +277,10 @@ void (*funct)(); tic_bool_param_t pfield; fwtoken fword_defr; + bool is_token; /* Is entry a single-token FCode? */ void (*ign_func)(); int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ } tic_bool_hdr_t ;
@@ -292,10 +306,12 @@ * Arguments: * nam (string) Name of the entry as seen in the source * func (routine-name) Name of internal function to call + * The item is not one for which single-token FCode number is assigned. * **************************************************************************** */ #define NO_PARAM_TIC(nam, func ) \ - { nam , (tic_hdr_t *)NULL , func , { 0 }, UNSPECIFIED , NULL , 0 } + { nam , (tic_hdr_t *)NULL , func , \ + { 0 }, UNSPECIFIED , FALSE , NULL , 0 , FALSE }
/* ************************************************************************** @@ -307,11 +323,12 @@ * Arguments: * nam (string) Name of the entry as seen in the source * func (routine-name) Name of internal function to call for both + * The item is not one for which single-token FCode number is assigned. * - * **************************************************************************** */ #define NO_PARAM_IGN(nam, func ) \ - { nam , (tic_hdr_t *)NULL , func , { 0 }, UNSPECIFIED , func , 0 } + { nam , (tic_hdr_t *)NULL , func , \ + { 0 }, UNSPECIFIED , FALSE , func , 0 , FALSE }
/* ************************************************************************** @@ -331,14 +348,15 @@ * func (routine-name) Name of internal function to call * pval (integer) The "param field" item * definr (fword_token) "Definer" of the entry + * is_tok (bool) Is the "param" item a single-token FCode? * * The "param field" item will be recast to the required default type. * **************************************************************************** */
-#define VALPARAM_TIC(nam, func, pval, definr ) \ +#define VALPARAM_TIC(nam, func, pval, definr, is_tok ) \ { nam , (tic_hdr_t *)NULL , func , \ - { (TIC_P_DEFLT_TYPE)(pval) }, definr , NULL , 0 } + { (TIC_P_DEFLT_TYPE)(pval) }, definr , is_tok , NULL , 0 , FALSE }
/* ************************************************************************** @@ -357,16 +375,17 @@ * definr (fword_token) "Definer" of the entry * * The "param field" item will be recast to the required default type. + * The item is not one for which single-token FCode number is assigned. * **************************************************************************** */ #define DUALFUNC_TIC(nam, afunc, pval, ifunc, definr ) \ { nam , (tic_hdr_t *)NULL , afunc , \ - { (TIC_P_DEFLT_TYPE)(pval) }, definr , ifunc , 0 } + { (TIC_P_DEFLT_TYPE)(pval) }, definr , FALSE , ifunc , 0 , FALSE }
/* Similar but a tic_fwt_hdr_t type structure */ #define DUFNC_FWT_PARM(nam, afunc, pval, ifunc, definr ) \ { nam , (tic_fwt_hdr_t *)NULL , afunc , \ - { (TIC_FWT_P_DEFLT_TYPE)(pval) }, definr , ifunc , 0 } + { (TIC_FWT_P_DEFLT_TYPE)(pval) }, definr , FALSE , ifunc , 0 , FALSE }
/* ************************************************************************** @@ -381,11 +400,13 @@ * definr (fword_token) "Definer" of the entry * * The "param field" item should not need be recast. + * The item is not one for which single-token FCode number is assigned. * **************************************************************************** */
#define FWORD_TKN_TIC(nam, func, fw_tokval, definr ) \ - { nam , (tic_fwt_hdr_t *)NULL , func , { fw_tokval }, definr , NULL , 0 } + { nam , (tic_fwt_hdr_t *)NULL , func , { fw_tokval }, \ + definr , FALSE , NULL , 0 , FALSE }
/* ************************************************************************** * Macro Name: DUALFUNC_FWT_TIC @@ -401,10 +422,12 @@ * definr (fword_token) "Definer" of the entry * * The "param field" item should not need be recast. + * The item is not one for which single-token FCode number is assigned. * **************************************************************************** */ #define DUALFUNC_FWT_TIC(nam, afunc, fw_tokval, ifunc, definr ) \ - { nam , (tic_fwt_hdr_t *)NULL , afunc , { fw_tokval }, definr , ifunc , 0 } + { nam , (tic_fwt_hdr_t *)NULL , afunc , { fw_tokval }, \ + definr , FALSE , ifunc , 0 , FALSE }
/* ************************************************************************** * Macro Name: BUILTIN_MAC_TIC @@ -420,11 +443,13 @@ * The "definer" will be MACRO_DEF * Builtin Macros do not need to be expanded while Ignoring, so * the ign_func will be NULL + * The item is not one for which single-token FCode number is assigned. * **************************************************************************** */
#define BUILTIN_MAC_TIC(nam, func, alias ) \ - { nam , (tic_mac_hdr_t *)NULL , func , { alias }, MACRO_DEF , NULL , 0 } + { nam , (tic_mac_hdr_t *)NULL , func , { alias }, \ + MACRO_DEF , FALSE , NULL , 0 , FALSE }
/* ************************************************************************** @@ -441,12 +466,13 @@ * For all of the Condtionals, the "Ignoring" function is the same * as the "Active" function. * The "definer" will be COMMON_FWORD + * The item is not one for which single-token FCode number is assigned. * **************************************************************************** */
#define BUILTIN_BOOL_TIC(nam, func, bool_vbl ) \ { nam , (tic_bool_hdr_t *)NULL , func , { &bool_vbl }, \ - COMMON_FWORD , func , 0 } + COMMON_FWORD , FALSE , func , 0 , FALSE }
/* ************************************************************************** @@ -465,14 +491,15 @@ TIC_P_DEFLT_TYPE tparam, fwtoken fw_defr, int pfldsiz, + bool is_single, void (*ign_fnc)(), tic_hdr_t **tic_vocab ); tic_hdr_t *lookup_tic_entry( char *tname, tic_hdr_t *tic_vocab ); bool exists_in_tic_vocab( char *tname, tic_hdr_t *tic_vocab ); bool handle_tic_vocab( char *tname, tic_hdr_t *tic_vocab ); -bool create_tic_alias( char *new_name, - char *old_name, - tic_hdr_t **tic_vocab ); +bool create_split_alias( char *new_name, char *old_name, + tic_hdr_t **src_vocab, tic_hdr_t **dest_vocab ); +bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ); void reset_tic_vocab( tic_hdr_t **tic_vocab, tic_hdr_t *reset_position );
#endif /* _TOKE_TICVOCAB_H */
Modified: fcode-utils/toke/toke.c =================================================================== --- fcode-utils/toke/toke.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/toke.c 2006-10-30 09:48:28 UTC (rev 100) @@ -46,7 +46,8 @@ #include "stack.h" #include "emit.h"
-#define TOKE_VERSION "1.0.1" +#define TOKE_VERSION "1.0.2" +#define TOKE_COPYRIGHT_DATE "2001-2006"
#include "vocabfuncts.h" #include "scanner.h" @@ -102,8 +103,8 @@ printf( "Welcome to toke - OpenBIOS tokenizer v" TOKE_VERSION "\n" CORE_COPYR "\n" IBM_COPYR "\n" "This program is free software; you may redistribute it " - "under the terms of\nthe GNU General Public License v2. This " - "program has absolutely no warranty.\n\n"); + "under the terms of\nthe GNU General Public License v2. " + "This program has absolutely no warranty.\n\n"); #ifdef DEVEL /* Temporary hack during development... */ printf( "\tTokenizer Compiled " DATE_STAMP "\n" ); @@ -352,6 +353,7 @@ list_cl_flag_settings(); display_include_list(); } + show_trace_list(); save_cl_flags(); }
@@ -378,6 +380,8 @@ print_copyright(); get_args( argc, argv );
+ init_error_handler(); + init_stack(); init_dictionary();
Modified: fcode-utils/toke/tokzesc.c =================================================================== --- fcode-utils/toke/tokzesc.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/tokzesc.c 2006-10-30 09:48:28 UTC (rev 100) @@ -45,8 +45,9 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> + +#include "tokzesc.h" #include "ticvocab.h" -#include "tokzesc.h" #include "stack.h" #include "emit.h" #include "stream.h" @@ -54,6 +55,7 @@ #include "errhandler.h" #include "strsubvocab.h" #include "nextfcode.h" +#include "tracesyms.h"
#undef TOKZTEST /* Define for testing only; else undef */ #ifdef TOKZTEST /* For testing only */ @@ -215,7 +217,8 @@ * Inputs: * Parameters: * the_num Pointer to where to put the number - * the_action Phrase to be used in ERROR message + * setting_fc TRUE if number is to be set as next fcode, + * FALSE if the number is to be emitted * Data-Stack Items: * Top: Value to be retrieved * @@ -224,21 +227,44 @@ * Supplied Pointers: * *the_num Value retrieved from the data-stack * + * Process Explanation: + * From the value of setting_fc we will deduce both the legal + * minimum and the phrase to be used in the ERROR message. + * If the number is to be emitted, it can be any legal FCode + * token number down to 0x10 but if it is to be set, the + * legal minimum is 0x0800. + * In either case, 0x0fff is the legal maximum. + * * Error Detection: * If the number on the stack is larger than 16 bits, truncate * it, with a WARNING message. - * If the (possibly truncated) number from the stack is larger - * than the legal maximum for an FCode (0x0fff), or - * less than the legal minimum (0x0800), issue an ERROR, + * If the (possibly truncated) number taken from the stack is + * larger than the legal maximum for an FCode, or if it is + * less than the legal minimum, issue an ERROR message, * leave the_num unchanged and return FALSE. * + * Extraneous Remarks: + * If this function is ever used in more than the two ways allowed + * by the setting_fc parameter, then the Right Thing would + * be to define a local ENUM type for the possible uses, and + * use a SWITCH statement to set the internal variables. (But + * I really don't see any way that could become necessary...) + * **************************************************************************** */
-static bool get_fcode_from_stack( u16 *the_num, char *the_action) +static bool get_fcode_from_stack( u16 *the_num, bool setting_fc) { bool retval = FALSE; + char *the_action = "emit FCode value of"; + u16 legal_minimum = 0x10; long num_on_stk = dpop(); u16 test_fcode = (u16)num_on_stk; + + if ( setting_fc ) + { + the_action = "set next fcode to"; + legal_minimum = 0x800; + } if ( test_fcode != num_on_stk ) { tokenization_error( WARNING, @@ -246,7 +272,7 @@ "Truncating to 0x%03x.\n", strupr(statbuf), num_on_stk, test_fcode); } - if ( ( test_fcode >= 0x800 ) && ( test_fcode <= 0xfff ) ) + if ( ( test_fcode >= legal_minimum ) && ( test_fcode <= 0xfff ) ) { retval = TRUE; *the_num = test_fcode; @@ -279,7 +305,7 @@ { u16 test_fcode;
- if ( get_fcode_from_stack( &test_fcode, "set next fcode to") ) + if ( get_fcode_from_stack( &test_fcode, TRUE) ) { if ( test_fcode == nextfcode ) { @@ -318,7 +344,7 @@ { u16 test_fcode;
- if ( get_fcode_from_stack( &test_fcode, "Emit FCode value of") ) + if ( get_fcode_from_stack( &test_fcode, FALSE) ) { tokenization_error( INFO, "Emitting FCode value of 0x%x\n", test_fcode); @@ -462,8 +488,8 @@ * Error Detection: * Failure to allocate memory is a Fatal Error. * Warning on excessively long name - * Warning on duplicate name * Name to be defined not in same file, ERROR + * Warning on duplicate name handled by support routine * * Process Explanation: * Get the next word, STRDUP it (which implicitly allocates memory). @@ -493,11 +519,6 @@ * the lines from here to the end of the * routine should be re-factored... */ - trace_creation( CONST, statbuf); - - warn_if_duplicate( statbuf ); - check_name_length( wlen ); - c_name_space = strdup( statbuf );
add_tic_entry( @@ -505,9 +526,11 @@ do_constant, (TIC_P_DEFLT_TYPE)valu, CONST , - 0 , NULL, + 0 , FALSE , NULL, &tokz_esc_vocab );
+ check_name_length( wlen ); + }
/* ************************************************************************** @@ -538,7 +561,7 @@ **************************************************************************** */
#define TKZESC_CONST(nam, pval) \ - VALPARAM_TIC(nam, do_constant, pval, CONST ) + VALPARAM_TIC(nam, do_constant, pval, CONST, FALSE ) #define TKZ_ESC_FUNC(nam, afunc, pval, ifunc) \ DUALFUNC_TIC(nam, afunc, pval, ifunc, UNSPECIFIED)
@@ -586,6 +609,11 @@ * Synopsis: Initialize the "Tokenizer Escape" Vocabulary * link-pointers dynamically. * + * Process Explanation: + * While this is going on, set in_tokz_esc to TRUE; clear it + * when done. This will be used by the trace_builtin + * routine... + * **************************************************************************** */
void init_tokz_esc_vocab ( void ) @@ -593,10 +621,12 @@ static const int tokz_esc_vocab_max_indx = sizeof(tokz_esc_vocab_tbl)/sizeof(tic_hdr_t) ;
+ in_tokz_esc = TRUE; tokz_esc_vocab = NULL ; /* Belt-and-suspenders... */ init_tic_vocab(tokz_esc_vocab_tbl, tokz_esc_vocab_max_indx, &tokz_esc_vocab ); + in_tokz_esc = FALSE; }
/* **************************************************************************
Modified: fcode-utils/toke/tracesyms.c =================================================================== --- fcode-utils/toke/tracesyms.c 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/tracesyms.c 2006-10-30 09:48:28 UTC (rev 100) @@ -33,31 +33,96 @@
/* ************************************************************************** * + * Revision History: + * Wed, 04 Oct 2006 by David L. Paktor + * Issue a message when a name on the trace list is invoked (as well + * as when it is created), but keep a limit on the speed penalty. + * (I.e., don't scan the trace-list for every symbol invoked.) + * Instead, we are going to install a function that prints the + * message; this requires scanning only once at creation time, + * which is already a necessity. There are too many permutations + * of "action" functions to define a separate set that combine + * with the invocation-message, so we will have a separate field + * for the invocation-message function, which will be NULL if + * the entry is not being traced. (If, however, it is faster + * to execute a null function than to first test for a NULL, + * then we can define a null function and put _that_ into the + * invocation-message-function field... + * Wed, 11 Oct 2006 by David L. Paktor + * We have reduced the Invocation Message Function to a single common + * routine; we will add a field that is a simple flag indicating + * if the entry is being traced. At the common point where the + * entry's function is called, we will test the flag to decide + * whether call the Invocation Message routine. + * + **************************************************************************** */ + +/* ************************************************************************** + * * Functions Exported: * add_to_trace_list Add the given name to the Trace List - * show_initial_traces Show pre-defined names the user - * asked to Trace (if any) * is_on_trace_list Indicate whether the given name is * on the Trace List + * tracing_fcode Show a token's assigned FCode-token + * in a consistent format. + * trace_creation Display a Trace-Note when a word known + * to be on the Trace List is created. + * trace_create_failure Display a Trace-Note indicating a failed + * attempt to create a word, if it is + * on the Trace List. + * traced_name_error Display a Trace-Note indicating a failed + * attempt to invoke an undefined word, + * if it is on the Trace List. + * invoking_traced_name Display a Trace-Note when a word known + * to be on the Trace List is invoked. + * handle_invocation Test whether a word is on the Trace List; + * if so, display a Trace-Note. + * show_trace_list Display the trace-list (if any) at + * the start of the run + * trace_builtin Test whether a pre-defined name is on + * the Trace List; issue a Trace-Note + * and set the entry's tracing flag. * **************************************************************************** */
+/* ************************************************************************** + * + * Global Variables Exported + * split_alias_message Back-channel way to permit a certain + * message about an alias to a Global + * definition only having local scope + * to become a Trace-Note instead of + * an Advisory when one of the names + * is being Traced. + * + **************************************************************************** */ + + #include <string.h> +#include <stdio.h> +#include <stdlib.h>
#include "tracesyms.h" #include "errhandler.h" +#include "scanner.h" +#include "vocabfuncts.h" +#include "devnode.h" +#include "toke.h"
+int split_alias_message = INFO;
/* ************************************************************************** * * Internal Static Variables - * trace_list Pointer to last entry in the Trace List linked-list - * data structure - * - * + * trace_list Pointer to the first entry in the Trace List + * linked-list data structure + * trace_list_last Pointer to the last entry in the Trace List; + * the list will be forward-linked + * tracing_symbols TRUE if "Trace-Symbols" is in effect. * **************************************************************************** */
+ /* ************************************************************************** * * Internal (Static) Structures: @@ -65,35 +130,38 @@ * * Fields: * tracee Name of the symbol to be traced - * prev Pointer to previous entry in the linked-list + * next Pointer to next entry in the forward-linked-list * **************************************************************************** */
typedef struct trace_entry { char *tracee; - struct trace_entry *prev; + struct trace_entry *next; } trace_entry_t;
static trace_entry_t *trace_list = NULL; +static trace_entry_t *trace_list_last = NULL;
+static bool tracing_symbols = FALSE;
- /* ************************************************************************** * * Function name: add_to_trace_list * Synopsis: Add the given name to the Trace List * - * * Inputs: * Parameters: * trace_symb Name of the symbol to be added * Local Static Variables: * trace_list Pointer to the Trace List + * trace_list_last Pointer to last entry in the Trace List * * Outputs: * Returned Value: NONE * Local Static Variables: - * trace_list Points to new entry in Trace List + * trace_list Points to first entry in Trace List + * trace_list_last Pointer to new entry in the Trace List + * tracing_symbols Set to TRUE * Memory Allocated * For Trace List entry * For copy of Symbol Name @@ -101,6 +169,12 @@ * Never. Well, only on termination of the program. Trace-list * endures for the entire batch of tokenizations. * + * Process Explanation: + * The list will be forward-linked so that the display of the list + * can be in the same order as specified by the User. It will + * take a little extra effort, but having it come out that way + * satisfies the "Rule of Least Astonishment"... + * * Error Detection: * Memory allocation failure is a FATAL error. * @@ -111,9 +185,16 @@ trace_entry_t *new_t_l_entry = safe_malloc( sizeof( trace_entry_t), "adding to trace-list"); new_t_l_entry->tracee = strdup( trace_symb); - new_t_l_entry->prev = trace_list; + new_t_l_entry->next = NULL;
+ if ( trace_list != NULL ) + { + trace_list_last->next = new_t_l_entry; + }else{ trace_list = new_t_l_entry; + tracing_symbols = TRUE; + } + trace_list_last = new_t_l_entry; }
@@ -126,6 +207,7 @@ * Parameters: * symb_name Symbol-name to test * Local Static Variables: + * tracing_symbols Skip the search if FALSE * trace_list Pointer to the Trace List * * Outputs: @@ -136,6 +218,8 @@ bool is_on_trace_list( char *symb_name) { bool retval = FALSE; + if ( tracing_symbols ) + { trace_entry_t *test_entry = trace_list; while ( test_entry != NULL ) { @@ -144,7 +228,8 @@ retval = TRUE; break; } - test_entry = test_entry->prev; + test_entry = test_entry->next; + } } return ( retval ); } @@ -152,21 +237,504 @@
/* ************************************************************************** * - * Still to be done: - * Implement a function -- name it show_initial_traces -- - * that will show any pre-defined names the user asked - * to Trace. That is, if any of the names the user asked - * to Trace belongs to a pre-defined function, macro or - * directive, then, at the beginning of the output, issue - * Advisory Messages identifying the scope of those names. + * Function name: tracing_fcode + * Synopsis: Fill the given buffer with the string showing the + * assigned FCode-token given. Produce a consistent + * format for all messages that include this phrase. + * + * Inputs: + * Parameters: + * fc_phrase_buff Pointer to buffer for the phrase + * fc_token_num Assigned FCode-token number. + * + * Outputs: + * Returned Value: NONE + * Supplied Pointers: + * fc_phrase_buff Filled with the phrase. + * + * Process Explanation: + * It is the responsibility of the calling routine to make sure + * that the buffer passed as the fc_phrase_buff parameter + * is sufficiently large for the phrase. + * This routine will test fc_token_num and leave the buffer + * unchanged if it is not greater than zero, relieving the + * calling routine of that chore. + * + * Extraneous Remarks: + * We will export, in tracesyms.h , a Macro that will give the + * recommended length for the buffer passed to this routine. + * It will be called TRACING_FCODE_LENGTH + * + **************************************************************************** */ + +void tracing_fcode( char *fc_phrase_buff, u16 fc_token_num) +{ + if ( fc_token_num > 0 ) + { + sprintf( fc_phrase_buff, + " (FCode token = 0x%03x)", fc_token_num); + } +} + +/* ************************************************************************** + * + * Function name: trace_creation + * Synopsis: Display the appropriate message when a word, known + * to be on the Trace List, is created. + * + * Inputs: + * Parameters: + * trace_entry The TIC entry of the name + * nu_name If creating an Alias, the "new" name, + * otherwise NULL. + * is_global TRUE if trace_entry has Global scope. + * Global Variables: + * in_tokz_esc TRUE if we are in Tokenizer-Escape mode + * current_device_node Where the new definition's scope is, + * if it's not Global or Tokzr-Escape. + * hdr_flag State of name-creation headered-ness + * in_tkz_esc_mode String for announcing Tokz-Esc mode + * wh_defined String, = ", which is defined as a " + * + * Outputs: + * Returned Value: NONE + * Global Variables: + * split_alias_message Set to TRACER if creating an Alias. + * Printout: + * Trace-Note Message. + * If not an ALIAS, takes the form: + * Creating <name> <(if is_single:FCode Token = xxx)> + * as a{n External,Headered,Headerless} <Type> + * <with scope> + * If it is an ALIAS, takes the form: + * Creating <new-name> as a{n External,Headered,Headerless} + * ALIAS to <old-name> <(if is_single:FCode Token = xxx)>, + * which is defined [ as a <Type>] <with scope> + * Headered-ness, of course, only applies to words with a + * single-token FCode. + * The <with scope> phrase is: + * If we are in Tokz-Esc mode, "in Tokenizer-Escape mode". + * If the TIC entry is a Local, the current colon-definition. + * If the TIC entry is Global in scope, "with Global scope" + * Otherwise, the identification of the current device-node. + * + * Process Explanation: + * The calling routine will already have verified that the + * name is on the trace-list. + * The name will already have been entered into a TIC_HDR vocab; + * + * The order of scope-checking is important: + * A Local has no scope beyond the definition in which it occurs. + * Tokenizer-Escape mode supercedes "Normal" mode, and renders + * moot the differences between Global and Device scope. + * Global scope is mutually exclusive with Device scope. + * Device scope needs to identify where the Current device-node + * began. + * + **************************************************************************** */ + +void trace_creation( tic_hdr_t *trace_entry, + char *nu_name, + bool is_global) +{ + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *head_ness = ""; + char *defr_name = "" ; + char *defr_phrase = "" ; + char *with_scope = "" ; + bool def_is_local = BOOLVAL( trace_entry->fword_defr == LOCAL_VAL); + bool creating_alias = BOOLVAL( nu_name != NULL ); + + if ( creating_alias ) + { + head_ness = "n"; + split_alias_message = TRACER; + } + + if ( in_tokz_esc ) + { + with_scope = in_tkz_esc_mode; + }else{ + if ( ! def_is_local ) + { + if ( is_global ) + { + with_scope = "with Global scope.\n"; + }else{ + with_scope = in_what_node( current_device_node); + } + } + + if ( trace_entry->is_token ) + { + tracing_fcode( fc_token_display, + (u16)trace_entry->pfield.deflt_elem ); + /* Headered-ness only applies to FCode definitions */ + /* But not to aliases to FCode definitions */ + if ( ! creating_alias ) + { + switch ( hdr_flag ) + { + case FLAG_HEADERS: + head_ness = " Headered"; + break; + + case FLAG_EXTERNAL: + head_ness = "n External"; + break; + + default: /* FLAG_HEADERLESS */ + head_ness = " Headerless"; + } + } + } + + } + + + if ( definer_name(trace_entry->fword_defr, &defr_name) ) + { + defr_phrase = wh_defined; + }else{ + /* Even if we don't have a Type for the "old" word + * we still have its scope. If the "new" word's + * scope is different, the "split-alias message" + * will take care of it. + */ + if ( creating_alias ) + { + defr_phrase = ", which is defined" ; + } + } + + if ( creating_alias ) + { + /* + * Creating <new-name> as a{n External,Headered,Headerless} + * ALIAS to <old-name> <(if is_single:FCode Token = xxx)>, + * [which is defined as a <Type> <with scope>] + */ + tokenization_error(TRACER, + "Creating %s" /* nu_name */ + " as a%s ALIAS to %s" /* head_ness trace_entry->name */ + "%s" /* fc_token_display */ + "%s%s " /* defr_phrase defr_name */ + "%s", /* with_scope */ + nu_name, head_ness, trace_entry->name, + fc_token_display, defr_phrase, defr_name, with_scope ); + }else{ + /* + * Creating <name> <(if is_single:FCode Token = xxx)> + * as a{n External,Headered,Headerless} <Type> + * [ <with scope> ] + */ + tokenization_error(TRACER, + "Creating %s" /* trace_entry->name */ + "%s" /* fc_token_display */ + " as a%s %s " /* head_ness defr_name */ + "%s", /* with_scope */ + trace_entry->name, + fc_token_display, head_ness, defr_name, with_scope ); + } + /* + * The <with scope> phrase is: + * If we are in Tokz-Esc mode, "in Tokenizer-Escape mode". + * (Already handled. No more to do here) + * If the TIC entry is a Local, the current colon-definition. + * If the TIC entry is Global in scope, "with Global scope" + * (identified by NULL in_vocab). + * Otherwise, the identification of the current device-node. + */ + + + if ( ! in_tokz_esc ) + { + if ( def_is_local ) + { + in_last_colon( TRUE); + }else{ + show_node_start(); + } + } + +} + + +/* ************************************************************************** + * + * Function name: trace_create_failure + * Synopsis: Display a Trace-Note indicating a failed attempt + * to create a word, if it is on the Trace List. * - * E.g, if the user had -T 3DUP -T SWAP the function would - * issue Messages like: - * 3DUP is pre-defined as a Macro with Global scope - * SWAP is pre-defined with Global scope - * SWAP is pre-defined in Tokenizer-Escape mode - * - * The names would, of course, remain on the Trace List and - * any re-definitions of them would be reported. + * Inputs: + * Parameters: + * new_name The name of the word you failed to create + * old_name If attempted to create an Alias, the + * "old" name, otherwise NULL. + * fc_tokn FCode-Token that might have been assigned + * to the "new" name. Zero if none. * + * Outputs: + * Returned Value: NONE + * Printout: + * Failed to create <new_name> [FCode Token = <xxx>] + * [ as an ALIAS to <old_name>]\n" + * **************************************************************************** */ + +void trace_create_failure( char *new_name, char *old_name, u16 fc_tokn) +{ + bool not_alias = BOOLVAL( old_name == NULL ); + bool do_it = is_on_trace_list( new_name); + + if ( ( ! do_it ) && ( ! not_alias ) ) + { + do_it = is_on_trace_list( old_name); + } + + if ( do_it ) + { + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *as_alias = not_alias ? "" : " as an ALIAS to "; + char *alias_name = not_alias ? "" : old_name; + + if ( fc_tokn > 0 ) + { + tracing_fcode( fc_token_display, fc_tokn); + } + tokenization_error(TRACER, + "Failed to create %s" /* new_name */ + "%s" /* fc_token_display */ + "%s" /* as_alias */ + "%s\n", /* alias_name */ + new_name, fc_token_display, + as_alias, alias_name); + } +} + + +/* ************************************************************************** + * + * Function name: traced_name_error + * Synopsis: Display a Trace-Note indicating a failed attempt + * to invoke an undefined word, if it is on the + * Trace List. + * + * Inputs: + * Parameters: + * trace_name The name being invoked + * + * Outputs: + * Returned Value: NONE + * Printout: + * A Trace-Note message indicating a attempt to "invoke" the name + * + * Error Detection: + * Error was detected by calling routine + * + * Process Explanation: + * Test if the name is on the trace-list, first. + * + **************************************************************************** */ + +void traced_name_error( char *trace_name) +{ + if ( is_on_trace_list( trace_name ) ) + { + tokenization_error(TRACER, "Attempt to invoke (undefined) %s.\n", + trace_name); + } +} + +/* ************************************************************************** + * + * Function name: invoking_traced_name + * Synopsis: Print a message indicating that the given name, + * (which is on the trace-list) is being invoked. + * If available, show the name's assigned FCode- + * -token, definition-type, and scope. + * + * Inputs: + * Parameters: + * trace_entry The TIC entry of the name + * + * Outputs: + * Returned Value: NONE + * Printout: + * A Trace-Note message: + * Invoking <name> [FCode Token = <xxx>] [defined as a <Type>] + * + * Process Explanation: + * Although we could test the entry here to see whether it is + * being traced, we do not want to incur the speed penalty + * of the overhead of unconditionally calling a routine that, + * in most cases, will not do anything, every time a token + * is processed. We believe it is faster for the calling + * routine to conduct that test. + * Therefore, this routine will pre-suppose that the "tracing" + * field of the entry is TRUE. + * + **************************************************************************** */ + +void invoking_traced_name( tic_hdr_t *trace_entry) +{ + + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *defr_name = "" ; + char *defr_phrase = "" ; + char *defr_space = "" ; + + if ( trace_entry->is_token ) + { + tracing_fcode( fc_token_display, + (u16)trace_entry->pfield.deflt_elem ); + } + + if ( definer_name(trace_entry->fword_defr, &defr_name) ) + { + defr_phrase = " defined as a"; + defr_space = " " ; + + } + + tokenization_error(TRACER, + "Invoking %s" /* <name> */ + "%s" /* fc_token_display */ + "%s%s" /* defr_phrase defr_space */ + "%s.\n", /* defr_name */ + trace_entry->name, + fc_token_display, + defr_phrase, defr_space, + defr_name); + +} + +/* ************************************************************************** + * + * Function name: handle_invocation + * Synopsis: Test whether the entry is being traced; + * if so, print the Trace-Note message. + * + * Inputs: + * Parameters: + * trace_entry The TIC entry to be tested. + * No harm if NULL + * + * Outputs: + * Returned Value: NONE + * Printout: + * A Trace-Note message, by invoking_traced_name() if + * the entry's tracing field is set. + * + * Extraneous Remarks: + * In cases that do not occur every time a token is processed, + * we can trade-off a small price in speed for convenience + * of coding. Call this routine judiciously... + * + **************************************************************************** */ + +void handle_invocation( tic_hdr_t *trace_entry) +{ + if ( trace_entry != NULL ) + { + if ( trace_entry->tracing) + { + invoking_traced_name( trace_entry); + } + } +} + + +/* ************************************************************************** + * + * Function name: show_trace_list + * Synopsis: Display the trace-list (if any) at the start of the run + * + * Inputs: + * Parameters: NONE + * Local Static Variables: + * tracing_symbols Skip the display if FALSE + * trace_list Pointer to the Trace List + * + * Outputs: + * Returned Value: NONE + * Printout: + * List of symbols being traced; nothing if not tracing. + * + * Error Detection: + * Memory allocation failure is a FATAL error. + * + **************************************************************************** */ + +void show_trace_list( void) +{ + if ( tracing_symbols ) + { + trace_entry_t *test_entry; + printf("\nTracing these symbols:"); + for ( test_entry = trace_list; + test_entry != NULL; + test_entry = test_entry->next ) + { + printf(" %s", test_entry->tracee); + + } + printf("\n"); + } + +} + +/* ************************************************************************** + * + * Function name: trace_builtin + * Synopsis: If the given built-in token, function, macro or + * directive is one the user asked to have Traced, + * issue a Trace-Note describing it, and set the + * TIC_HDR entry's tracing field to TRUE. + * Called while initializing vocab-lists. + * + * Inputs: + * Parameters: + * trace_entry The TIC entry of the built-in name + * Global Variables: + * in_tokz_esc TRUE if initializing the vocab-list + * for Tokenizer-Escape mode. + * in_tkz_esc_mode String for announcing Tokz-Esc mode + * Local Static Variables: + * + * Outputs: + * Returned Value: NONE + * Supplied Pointers: + * trace_entry->tracing Set TRUE, if the entry's name is on + * the Trace List. + * Printout: + * Trace-Note: <name> <(if is_single:FCode Token = xxx)> + * is a built-in {word|<Type>} [in Tokz-Esc mode] + * + **************************************************************************** */ + +void trace_builtin( tic_hdr_t *trace_entry) +{ + if (is_on_trace_list( trace_entry->name ) ) + { + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *defr_name = "word"; + char *ws_space = in_tokz_esc ? " " : ""; + char *with_scope = in_tokz_esc ? in_tkz_esc_mode : ".\n"; + if ( trace_entry->is_token ) + { + tracing_fcode( fc_token_display, + (u16)trace_entry->pfield.deflt_elem ); + } + definer_name(trace_entry->fword_defr, &defr_name); + trace_entry->tracing = TRUE; + tokenization_error(TRACER, + "%s" /* <name> */ + "%s " /* fc_token_display */ + "is a built-in %s" /* defr_name */ + "%s%s", /* ws_space with_scope */ + trace_entry->name, + fc_token_display, defr_name, ws_space, with_scope ); + } +} +
Modified: fcode-utils/toke/tracesyms.h =================================================================== --- fcode-utils/toke/tracesyms.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/tracesyms.h 2006-10-30 09:48:28 UTC (rev 100) @@ -35,14 +35,44 @@ **************************************************************************** */
#include "types.h" +#include "ticvocab.h" +#include "devnode.h"
/* ************************************************************************** * * + * Global Variables Exported + * + **************************************************************************** */ + +extern int split_alias_message; + +/* ************************************************************************** * + * * Function Prototypes / Functions Exported: * **************************************************************************** */
void add_to_trace_list( char *trace_symb); bool is_on_trace_list( char *symb_name); +void tracing_fcode( char *fc_phrase_buff, u16 fc_token_num); +void trace_creation( tic_hdr_t *trace_entry, + char *nu_name, + bool is_global); +void trace_create_failure( char *new_name, char *old_name, u16 fc_tokn); +void traced_name_error( char *trace_name); +void invoking_traced_name( tic_hdr_t *trace_entry); +void handle_invocation( tic_hdr_t *trace_entry); +void show_trace_list( void); +void trace_builtin( tic_hdr_t *trace_entry);
+/* ************************************************************************** * + * + * Macro: + * TRACING_FCODE_LENGTH + * Adequate length for the buffer passed to tracing_fcode() + * + **************************************************************************** */ + +#define TRACING_FCODE_LENGTH 32 + #endif /* _TOKE_TRACESYMS_H */
Modified: fcode-utils/toke/vocabfuncts.h =================================================================== --- fcode-utils/toke/vocabfuncts.h 2006-10-15 20:09:08 UTC (rev 99) +++ fcode-utils/toke/vocabfuncts.h 2006-10-30 09:48:28 UTC (rev 100) @@ -47,7 +47,9 @@ **************************************************************************** */
extern bool scope_is_global; +extern bool define_token;
+ /* ************************************************************************** * * * Function Prototypes / Functions Exported: @@ -66,8 +68,7 @@ tic_hdr_t *lookup_in_dev_node( char *tname); void add_to_current( char *name, TIC_P_DEFLT_TYPE fc_token, - fwtoken definer, - bool define_token); + fwtoken definer); void hide_last_colon ( void ); void reveal_last_colon ( void ); bool create_current_alias( char *new_name, char *old_name );