Example #1
0
File: io.c Project: jaz303/lispy
void pretty_print(env_t *env, VALUE v, int i) {
    if (VALUE_IS_ERROR(v)) {
        printf("<error>\n");
    } else if (IS_LIST(v)) {
        printf("(\n");
		int j;
		for (j = 0; j < list_len(v); j++) {
            indent(i + 1); pretty_print(env, list_get(v, j), i + 1);
		}
		indent(i); printf(")\n");
    } else {
        if (VALUE_IS_INT(v)) {
    		printf("%lld\n", INTVAL(v));
    	} else if (VALUE_IS_BOOL(v)) {
    		printf("#%c\n", BOOLVAL(v) ? 't' : 'f');
        } else if (VALUE_IS_NIL(v)) {
            printf("#nil\n");
        } else if (VALUE_IS_IDENT(v)) {
            printf("%s\n", intern_table_get_str(&env->intern, IDENT(v)));
        } else if (VALUE_IS_ATOM(v)) {
            printf(":%s\n", intern_table_get_str(&env->intern, ATOM(v)));
        } else if (IS_STRING(v)) {
    		printf("\"%s\"\n", string_chars(v));
		} else {
            printf("<unknown %p>\n", v);
    	}
    }
}
Example #2
0
void reset_cl_flags(void)
{
    int indx;
    long int moving_bit = 1;

    for ( indx = 0 ; indx < (number_of_cl_flags - 1) ; indx++ )
    {
	*(cl_flags_list[indx].flag_var) =
	    BOOLVAL( cl_flags_bit_map & moving_bit) ;
	moving_bit <<= 1;
    }
}
Example #3
0
char *in_what_node(device_node_t *the_node)
{
    bool top_node    = BOOLVAL( the_node == &top_level_dev_node);
    bool curr_node   = BOOLVAL( the_node == current_device_node);
    bool known_node  = BOOLVAL( top_node || curr_node );
    bool no_line     = BOOLVAL( the_node->line_no == 0);

    show_where   = INVERSE( no_line  );
    show_which   = known_node;
    in_what_line = the_node->line_no;
    in_what_file = the_node->ifile_name;

    sprintf( in_what_buffr, "in the%s device-node%s",
	INVERSE( known_node )  ? ""
	        :  top_node    ?    " top-level"   :  " current" ,
	
	no_line                ?  ".\n"
	        :  known_node  ?  ", which began"  :   ""         );

    
    return( in_what_buffr);
}
Example #4
0
static void conditional_word_in_line( bool alr_ign,
                                          bool exist_test,
                                              bool (*exist_funct)() )
{
    if ( get_word_in_line( statbuf) )
    {
    	bool cond = FALSE;
	if ( INVERSE( alr_ign) )
	{
	    bool exists = exist_funct( statbuf);
	    cond = BOOLVAL( exists == exist_test);
	}
	conditionally_tokenize( cond, alr_ign );
    }
}
Example #5
0
void finish_device_vocab( void )
{
    bool at_top_level;

    dev_vocab_control_struct_check();

    /*   We never remove the top-level device-node vocabulary,
     *       so we need to test whether we're about to.
     */

    at_top_level = BOOLVAL( current_device_node == &top_level_dev_node );
    if ( at_top_level )
    {
        tokenization_error( TKERROR,
	    "Encountered %s without corresponding NEW-DEVICE.  "
	    "Resetting definitions since start of tokenization.\n",
		statbuf );
    }else{    
	tokenization_error(INFO,
	    "Encountered %s.  Resetting definitions of device node",
		statbuf );
	started_at( current_device_node->ifile_name,
	     current_device_node->line_no );
    }

    /*  Now to business...   */
    delete_device_vocab();

    /*   Did we just get to the top-level device-node vocabulary
     *       when we weren't before?
     */
    if ( INVERSE(at_top_level) )
    {
	if ( current_device_node == &top_level_dev_node )
	{
	    tokenization_error(INFO,
		"Resuming definitions since start of tokenization.\n" );
	}else{
	    tokenization_error(INFO,
		"Resuming definitions of parent device-node" );
	    started_at( current_device_node->ifile_name,
		 current_device_node->line_no );
	}
    }
}
Example #6
0
static void conditionally_tokenize( bool cond, bool alr_ign )
{
    
    signed long wlen;

    /*  Note:  The following variables *must* remain within
     *      the scope of this routine; a distinct instance
     *      is needed each time this routine is re-entered
     *     (aka "a nested call").
     */
    bool ignoring;
    bool first_else = TRUE;  /*  The "else" we see is the first.  */
    bool not_done = TRUE;
    unsigned int cond_strt_lineno = lineno;
    char *cond_strt_ifile_nam = strdup( iname);

    ignoring = BOOLVAL( ( cond == FALSE ) || ( alr_ign != FALSE ) );

    if ( trace_conditionals )
    {
        char *cond_val = cond ? "True" : "False" ;
	char *cond_junct = alr_ign ? ", but Already " : "; ";
	char *processg = ignoring ? "Ignoring" : "Processing" ;
	tokenization_error( INFO,
	    "Tokenization-Condition is %s%s%s.\n",
		cond_val, cond_junct, processg);
    }

    while ( not_done )
    {
        wlen = get_word();
	if ( wlen == 0 )
	{
	    continue;
	}

	if ( wlen < 0 )
	{
	    tokenization_error( TKERROR,
	        "Conditional without conclusion; started");
	    just_where_started( cond_strt_ifile_nam, cond_strt_lineno);
	    not_done = FALSE ;
	    continue;
	}

	if ( is_a_then ( statbuf ) )
	{
	    if ( trace_conditionals )
	    {
		tokenization_error( INFO,
		    "Concluding Conditional");
		just_started_at( cond_strt_ifile_nam, cond_strt_lineno);
	    }
	    not_done = FALSE ;
	    continue;
	}

	if ( is_an_else( statbuf ) )
	{
	    if ( ! alr_ign )
	    {
		if ( first_else )
		{
		    ignoring = INVERSE( ignoring);
		}
	    }

	    if ( ! first_else )
	    {
		int severity = ignoring ? WARNING : TKERROR ;
		char *the_scop = ignoring ? "(ignored)" : "the" ;
		tokenization_error( severity, "Multiple %s directives "
		    "within %s scope of the Conditional",
			 strupr(statbuf), the_scop);
		just_started_at( cond_strt_ifile_nam, cond_strt_lineno);
	    }else{
		first_else = FALSE;
		if ( trace_conditionals )
		{
		    char *when_enc = alr_ign ? "While already" : "Now" ;
		    char *processg = alr_ign ? "ignoring" :
				    ignoring ? "Ignoring" : "Processing" ;
		    char *enc       = alr_ign ? ", e" : ".  E" ;

		    tokenization_error( INFO,
			"%s %s%sncountered %s belonging to Conditional",
			    when_enc, processg, enc, strupr(statbuf) );
		    just_started_at( cond_strt_ifile_nam, cond_strt_lineno);
		}
	    }

	    continue;
	}

	/*  If we are ignoring source input, for whatever reason, we still
	 *      need to be sensitive to the nesting of Conditional Operators
	 *      and some other commands and directives, as indicated...
	 */
	if ( ignoring )
	{
	    ignore_one_word( statbuf );
	}else{
	    /*  And if we're not ignoring source input, process it! */
	    tokenize_one_word ( wlen );
	}
    }
}