Ejemplo n.º 1
0
extern void make_fake_action(void)
{   int i;
    char action_sub[MAX_IDENTIFIER_LENGTH+4];

    get_next_token();
    if (token_type != SYMBOL_TT)
    {   ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    sprintf(action_sub, "%s__A", token_text);
    i = symbol_index(action_sub, -1);

    if (!(sflags[i] & UNKNOWN_SFLAG))
    {   ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    assign_symbol(i, ((grammar_version_number==1)?256:4096)+no_fake_actions++,
        FAKE_ACTION_T);

    new_action(token_text, i);
    if (debugfile_switch)
    {   write_debug_byte(FAKE_ACTION_DBR);
        write_debug_byte(svals[i]/256);
        write_debug_byte(svals[i]%256);
        write_debug_string(token_text);
    }
    return;
}
Ejemplo n.º 2
0
extern assembly_operand action_of_name(char *name)
{
    /*  Returns the action number of the given name, creating it as a new
        action name if it isn't already known as such.                       */

    char action_sub[MAX_IDENTIFIER_LENGTH+4];
    int j;
    assembly_operand AO;

    sprintf(action_sub, "%s__A", name);
    j = symbol_index(action_sub, -1);

    if (stypes[j] == FAKE_ACTION_T)
    {   AO.value = svals[j];
        AO.marker = 0;
        if (!glulx_mode)
          AO.type = LONG_CONSTANT_OT;
        else
          set_constant_ot(&AO);
        sflags[j] |= USED_SFLAG;
        return AO;
    }

    if (sflags[j] & UNKNOWN_SFLAG)
    {
        if (no_actions>=MAX_ACTIONS) memoryerror("MAX_ACTIONS",MAX_ACTIONS);
        new_action(name, no_actions);
        action_symbol[no_actions] = j;
        assign_symbol(j, no_actions++, CONSTANT_T);
        sflags[j] |= ACTION_SFLAG;
    }
    sflags[j] |= USED_SFLAG;

    AO.value = svals[j];
    AO.marker = ACTION_MV;
    if (!glulx_mode) {
      AO.type = (module_switch)?LONG_CONSTANT_OT:SHORT_CONSTANT_OT;
      if (svals[j] >= 256) AO.type = LONG_CONSTANT_OT;
    }
    else {
      AO.type = CONSTANT_OT;
    }
    return AO;
}
Ejemplo n.º 3
0
extern void make_fake_action(void)
{   int i;
    char action_sub[MAX_IDENTIFIER_LENGTH+4];
    debug_location_beginning beginning_debug_location =
        get_token_location_beginning();

    get_next_token();
    if (token_type != SYMBOL_TT)
    {   discard_token_location(beginning_debug_location);
        ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    sprintf(action_sub, "%s__A", token_text);
    i = symbol_index(action_sub, -1);

    if (!(sflags[i] & UNKNOWN_SFLAG))
    {   discard_token_location(beginning_debug_location);
        ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    assign_symbol(i, ((grammar_version_number==1)?256:4096)+no_fake_actions++,
        FAKE_ACTION_T);

    new_action(token_text, i);

    if (debugfile_switch)
    {   debug_file_printf("<fake-action>");
        debug_file_printf("<identifier>##%s</identifier>", token_text);
        debug_file_printf("<value>%d</value>", svals[i]);
        get_next_token();
        write_debug_locations
            (get_token_location_end(beginning_debug_location));
        put_token_back();
        debug_file_printf("</fake-action>");
    }

    return;
}
Ejemplo n.º 4
0
extern int parse_directive(int internal_flag)
{
    /*  Internal_flag is FALSE if the directive is encountered normally,
        TRUE if encountered with a # prefix inside a routine or object
        definition.

        Returns: TRUE if program continues, FALSE if end of file reached.    */

    int routine_symbol, rep_symbol;
    int is_renamed;

    begin_syntax_line(FALSE);
    get_next_token();

    if (token_type == EOF_TT) return(FALSE);

    if ((token_type == SEP_TT) && (token_value == HASH_SEP))
        get_next_token();

    if ((token_type == SEP_TT) && (token_value == OPEN_SQUARE_SEP))
    {   if (internal_flag)
        {   error("It is illegal to nest routines using '#['");
            return(TRUE);
        }

        directives.enabled = FALSE;
        directive_keywords.enabled = FALSE;
        segment_markers.enabled = FALSE;

        /* The upcoming symbol is a definition; don't count it as a
           top-level reference *to* the function. */
        df_dont_note_global_symbols = TRUE;
        get_next_token();
        df_dont_note_global_symbols = FALSE;
        if ((token_type != SYMBOL_TT)
                || ((!(sflags[token_value] & UNKNOWN_SFLAG))
                    && (!(sflags[token_value] & REPLACE_SFLAG))))
        {   ebf_error("routine name", token_text);
            return(FALSE);
        }

        routine_symbol = token_value;

        rep_symbol = routine_symbol;
        is_renamed = find_symbol_replacement(&rep_symbol);

        if ((sflags[routine_symbol] & REPLACE_SFLAG)
                && !is_renamed && (is_systemfile()))
        {   /* The function is definitely being replaced (system_file
               always loses priority in a replacement) but is not
               being renamed to something else. Skip its definition
               entirely. */
            dont_enter_into_symbol_table = TRUE;
            do
            {   get_next_token();
            } while (!((token_type == EOF_TT)
                       || ((token_type==SEP_TT)
                           && (token_value==CLOSE_SQUARE_SEP))));
            dont_enter_into_symbol_table = FALSE;
            if (token_type == EOF_TT) return FALSE;
        }
        else
        {   /* Parse the function definition and assign its symbol. */
            assign_symbol(routine_symbol,
                          parse_routine(lexical_source, FALSE,
                                        (char *) symbs[routine_symbol], FALSE, routine_symbol),
                          ROUTINE_T);
            slines[routine_symbol] = routine_starts_line;
        }

        if (is_renamed) {
            /* This function was subject to a "Replace X Y" directive.
               The first time we see a definition for symbol X, we
               copy it to Y -- that's the "original" form of the
               function. */
            if (svals[rep_symbol] == 0) {
                assign_symbol(rep_symbol, svals[routine_symbol], ROUTINE_T);
            }
        }

        get_next_token();
        if ((token_type != SEP_TT) || (token_value != SEMICOLON_SEP))
        {   ebf_error("';' after ']'", token_text);
            put_token_back();
        }
        return TRUE;
    }

    if ((token_type == SYMBOL_TT) && (stypes[token_value] == CLASS_T))
    {   if (internal_flag)
        {   error("It is illegal to nest an object in a routine using '#classname'");
            return(TRUE);
        }
        sflags[token_value] |= USED_SFLAG;
        make_object(FALSE, NULL, -1, -1, svals[token_value]);
        return TRUE;
    }

    if (token_type != DIRECTIVE_TT)
    {   /* If we're internal, we expect only a directive here. If
           we're top-level, the possibilities are broader. */
        if (internal_flag)
            ebf_error("directive", token_text);
        else
            ebf_error("directive, '[' or class name", token_text);
        panic_mode_error_recovery();
        return TRUE;
    }

    return !(parse_given_directive(internal_flag));
}