makefile_bertw: always compile with -g
[nedit-bw.git] / nested-subroutines.patch
blob66dba480304c84f05d56f44815abca34f6478591
1 ---
3 source/built-ins.h | 1 +
4 source/highlightData.c | 2 +-
5 source/interpret.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
6 source/interpret.h | 4 +++-
7 source/macro.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
8 5 files changed, 98 insertions(+), 7 deletions(-)
10 diff --quilt old/source/interpret.c new/source/interpret.c
11 --- old/source/interpret.c
12 +++ new/source/interpret.c
13 @@ -294,6 +294,7 @@ Program *FinishCreatingProgram(Accumulat
14 progLen = ProgP - Prog;
15 newProg->code = (Inst *)XtCalloc(progLen, sizeof(Inst));
16 memcpy(newProg->code, Prog, progLen * sizeof(Inst));
17 + newProg->nested = False;
18 newProg->refcount = 1;
20 DISASM(newProg->name, newProg->code, ProgP - Prog);
21 @@ -587,6 +588,29 @@ static int setupFrame(RestartData *conte
22 return STAT_OK;
25 +/*
26 +** setup a nested frame:
27 +**
28 +** - use arguments from current frame
29 +** - use local symbol list from current frame
30 +*/
31 +static int setupNestedFrame(RestartData *context, Program *prog)
33 + int ret;
34 + int nArgs = FP_GET_ARG_COUNT(context->frameP);
35 + DataValue *args = &FP_GET_ARG_N(context->frameP, 0);
36 + DataValue argArray = FP_GET_ARG_ARRAY(context->frameP);
37 + Symbol *symList = FP_GET_SYM_TAB(context->frameP);
39 + ret = setupFrame(context, prog, nArgs, args, argArray, prog->name);
41 + if (ret == STAT_OK) {
42 + FP_GET_SYM_TAB(context->frameP) = symList;
43 + }
45 + return STAT_OK;
48 static void rewindFrame(RestartData *context)
50 /* get stored return information */
51 @@ -595,8 +619,7 @@ static void rewindFrame(RestartData *con
52 Inst *newPC = FP_GET_RET_PC(context->frameP);
53 Program *prog = FP_GET_PROG(context->frameP);
54 Symbol *symList = FP_GET_SYM_TAB(context->frameP);
56 - freeSymbolList(symList);
57 + int isNestedFrame = prog->nested;
59 /* pop past local variables */
60 context->stackP = context->frameP;
61 @@ -608,6 +631,14 @@ static void rewindFrame(RestartData *con
62 FreeProgram(prog);
64 context->pc = newPC;
66 + if (!isNestedFrame) {
67 + freeSymbolList(symList);
68 + }
69 + else {
70 + /* copy the local symlist back to this frame */
71 + FP_GET_SYM_TAB(context->frameP) = symList;
72 + }
75 static void rewindStack(RestartData *context)
76 @@ -2680,8 +2711,14 @@ static int callSubroutineFromSymbol(Symb
77 if (sym->value.tag == MACRO_SUBR_TAG) {
78 prog = sym->value.val.prog;
79 prog->refcount++;
80 - /* -nArgs means 'arguments are on stack' */
81 - return setupFrame(Interpreter, prog, -nArgs, NULL, argArray, sym->name);
82 + if (prog->nested) {
83 + return setupNestedFrame(Interpreter, prog);
84 + }
85 + else {
86 + /* -nArgs means 'arguments are on stack' */
87 + return setupFrame(Interpreter, prog, -nArgs, NULL, argArray,
88 + sym->name);
89 + }
93 @@ -4850,7 +4887,8 @@ static void stackdumpframe(DataValue *ar
94 else
95 if (dv == prFP) {
96 Program *prog = dv->val.prog;
97 - printd(" <%s:%u %p>",
98 + printd(" <%s%s:%u %p>",
99 + prog->nested ? "nested " : "",
100 prog->name, prog->refcount,
101 prog);
103 @@ -4917,3 +4955,4 @@ static void stackdump(RestartData *conte
106 #endif /* ifdef DEBUG_STACK */
108 diff --quilt old/source/interpret.h new/source/interpret.h
109 --- old/source/interpret.h
110 +++ new/source/interpret.h
111 @@ -123,7 +123,8 @@ typedef struct SymbolRec {
112 typedef struct ProgramTag {
113 const char *name;
114 Inst *code;
115 - unsigned refcount;
116 + unsigned nested:1;
117 + unsigned refcount:31;
118 } Program;
120 /* Information needed to re-start a preempted macro */
121 @@ -213,3 +214,4 @@ const char *longAsStr(long val);
122 int lenLongAsStr(long val);
124 #endif /* NEDIT_INTERPRET_H_INCLUDED */
126 diff --quilt old/source/macro.c new/source/macro.c
127 --- old/source/macro.c
128 +++ new/source/macro.c
129 @@ -3845,6 +3845,55 @@ static int escapeLiteralMS(WindowInfo *w
130 return True;
135 + */
136 +static int evalMS(WindowInfo *window, DataValue *argList, int nArgs,
137 + DataValue *result, char **errMsg)
139 + char stringStorage[TYPE_INT_STR_SIZE(int)];
140 + char *macro = NULL;
141 + char *macronl = NULL;
142 + char *stoppedAt = NULL;
143 + Program *prog;
144 + int ret;
146 + if (nArgs != 1) {
147 + return wrongNArgsErr(errMsg);
149 + if (!readStringArg(argList[0], &macro, stringStorage, errMsg)) {
150 + return False;
153 + /* add a terminating newline */
154 + macronl = XtMalloc(strlen(macro) + 2);
155 + if (!macronl) {
156 + *errMsg = "Internal error";
157 + return False;
159 + strcpy(macronl, macro);
160 + strcat(macronl, "\n");
162 + /* Parse the macro and report errors if it fails */
163 + prog = ParseMacro(macronl, errMsg, &stoppedAt, False, "eval");
164 + if (!prog) {
165 + ParseError(window->macroCmdData ? window->shell : NULL,
166 + macronl, stoppedAt, "eval", *errMsg);
167 + XtFree(macronl);
168 + return False;
170 + XtFree(macronl);
172 + prog->nested = True;
173 + prog->refcount = 0;
175 + ret = OverlayRoutineFromProg(prog, nArgs, nArgs);
176 + if (!ret) {
177 + FreeProgram(prog);
179 + return ret;
182 /* T Balinski */
183 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
184 DataValue *result, char **errMsg)
185 diff --quilt old/source/highlightData.c new/source/highlightData.c
186 --- old/source/highlightData.c
187 +++ new/source/highlightData.c
188 @@ -554,7 +554,7 @@ static char *DefaultPatternSets[] = {
189 Built-in Misc Vars:\"(?<!\\Y)\\$(?:active_pane|calltip_ID|column|cursor|display_width|empty_array|file_name|file_path|language_mode|line|locked|max_font_width|min_font_width|modified|n_display_lines|n_panes|rangeset_list|read_only|selection_(?:start|end|left|right)|server_name|text_length|top_line|transient|VERSION|NEDIT_HOME)>\":::Identifier::\n\
190 Built-in Pref Vars:\"(?<!\\Y)\\$(?:auto_indent|em_tab_dist|file_format|font_name|font_name_bold|font_name_bold_italic|font_name_italic|highlight_syntax|incremental_backup|incremental_search_line|make_backup_copy|match_syntax_based|overtype_mode|show_line_numbers|show_matching|statistics_line|tab_dist|use_tabs|wrap_margin|wrap_text)>\":::Identifier2::\n\
191 Built-in Special Vars:\"(?<!\\Y)\\$(?:args|[1-9]|list_dialog_button|n_args|read_status|search_end|shell_cmd_status|string_dialog_button|sub_sep)>\":::String1::\n\
192 - Built-in Subrs:\"<(?:args|append_file|beep|call|calltip|clipboard_to_string|define|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|escape_literal|focus_window|get_character|get_matching|get_pattern_(by_name|at_pos)|get_range|get_selection|get_style_(by_name|at_pos)|getenv|highlight_calltip_line|kill_calltip|length|list_dialog|max|min|n_args|rangeset_(?:add|create|destroy|get_by_name|includes|info|invert|range|set_color|set_mode|set_name|subtract)|read_file|replace_in_string|replace_range|replace_selection|replace_substring|search|search_string|select|select_rectangle|set_cursor_pos|set_transient|set_window_title|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|timer_(?:add|remove)|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
193 + Built-in Subrs:\"<(?:args|append_file|beep|call|calltip|clipboard_to_string|define|dialog|eval|filename_dialog|dict_(?:insert|complete|save|append|is_element)|escape_literal|focus_window|get_character|get_matching|get_pattern_(by_name|at_pos)|get_range|get_selection|get_style_(by_name|at_pos)|getenv|highlight_calltip_line|kill_calltip|length|list_dialog|max|min|n_args|rangeset_(?:add|create|destroy|get_by_name|includes|info|invert|range|set_color|set_mode|set_name|subtract)|read_file|replace_in_string|replace_range|replace_selection|replace_substring|search|search_string|select|select_rectangle|set_cursor_pos|set_transient|set_window_title|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|timer_(?:add|remove)|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
194 Menu Actions:\"<(?:new(?:_tab|_opposite)?|open|open-dialog|open_dialog|open-selected|open_selected|close|save|save-as|save_as|save-as-dialog|save_as_dialog|revert-to-saved|revert_to_saved|revert_to_saved_dialog|include-file|include_file|include-file-dialog|include_file_dialog|load-macro-file|load_macro_file|load-macro-file-dialog|load_macro_file_dialog|load-tags-file|load_tags_file|load-tags-file-dialog|load_tags_file_dialog|unload_tags_file|load_tips_file|load_tips_file_dialog|unload_tips_file|print|print-selection|print_selection|exit|undo|redo|delete|select-all|select_all|shift-left|shift_left|shift-left-by-tab|shift_left_by_tab|shift-right|shift_right|shift-right-by-tab|shift_right_by_tab|find|find-dialog|find_dialog|find-again|find_again|find-selection|find_selection|find_incremental|start_incremental_find|replace|replace-dialog|replace_dialog|replace-all|replace_all|replace-in-selection|replace_in_selection|replace-again|replace_again|replace_find|replace_find_same|replace_find_again|goto-line-number|goto_line_number|goto-line-number-dialog|goto_line_number_dialog|goto-selected|goto_selected|mark|mark-dialog|mark_dialog|goto-mark|goto_mark|goto-mark-dialog|goto_mark_dialog|match|select_to_matching|goto_matching|find-definition|find_definition|show_tip|split-pane|split_pane|close-pane|close_pane|detach_document(?:_dialog)?|move_document_dialog|(?:next|previous|last)_document|uppercase|lowercase|fill-paragraph|fill_paragraph|control-code-dialog|control_code_dialog|filter-selection-dialog|filter_selection_dialog|filter-selection|filter_selection|execute-command|execute_command|execute-command-dialog|execute_command_dialog|execute-command-line|execute_command_line|shell-menu-command|shell_menu_command|macro-menu-command|macro_menu_command|bg_menu_command|post_window_bg_menu|post_tab_context_menu|beginning-of-selection|beginning_of_selection|end-of-selection|end_of_selection|repeat_macro|repeat_dialog|raise_window|focus_pane|set_statistics_line|set_incremental_search_line|set_show_line_numbers|set_auto_indent|set_wrap_text|set_wrap_margin|set_highlight_syntax|set_make_backup_copy|set_incremental_backup|set_show_matching|set_match_syntax_based|set_overtype_mode|set_locked|set_tab_dist|set_em_tab_dist|set_use_tabs|set_fonts|set_language_mode)(?=\\s*\\()\":::Subroutine::\n\
195 Text Actions:\"<(?:self-insert|self_insert|grab-focus|grab_focus|extend-adjust|extend_adjust|extend-start|extend_start|extend-end|extend_end|secondary-adjust|secondary_adjust|secondary-or-drag-adjust|secondary_or_drag_adjust|secondary-start|secondary_start|secondary-or-drag-start|secondary_or_drag_start|process-bdrag|process_bdrag|move-destination|move_destination|move-to|move_to|move-to-or-end-drag|move_to_or_end_drag|end_drag|copy-to|copy_to|copy-to-or-end-drag|copy_to_or_end_drag|exchange|process-cancel|process_cancel|paste-clipboard|paste_clipboard|copy-clipboard|copy_clipboard|cut-clipboard|cut_clipboard|copy-primary|copy_primary|cut-primary|cut_primary|newline|newline-and-indent|newline_and_indent|newline-no-indent|newline_no_indent|delete-selection|delete_selection|delete-previous-character|delete_previous_character|delete-next-character|delete_next_character|delete-previous-word|delete_previous_word|delete-next-word|delete_next_word|delete-to-start-of-line|delete_to_start_of_line|delete-to-end-of-line|delete_to_end_of_line|forward-character|forward_character|backward-character|backward_character|key-select|key_select|process-up|process_up|process-down|process_down|process-shift-up|process_shift_up|process-shift-down|process_shift_down|process-home|process_home|forward-word|forward_word|backward-word|backward_word|forward-paragraph|forward_paragraph|backward-paragraph|backward_paragraph|beginning-of-line|beginning_of_line|end-of-line|end_of_line|beginning-of-file|beginning_of_file|end-of-file|end_of_file|next-page|next_page|previous-page|previous_page|page-left|page_left|page-right|page_right|toggle-overstrike|toggle_overstrike|scroll-up|scroll_up|scroll-down|scroll_down|scroll_left|scroll_right|scroll-to-line|scroll_to_line|select-all|select_all|select_word|deselect-all|deselect_all|focusIn|focusOut|process-return|process_return|process-tab|process_tab|insert-string|insert_string|mouse_pan)(?=\\s*\\()\":::Subroutine::\n\
196 Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus|language_mode)_hook(?=\\s*\\()\":::Subroutine1::\n\
197 diff --quilt old/source/built-ins.h new/source/built-ins.h
198 --- old/source/built-ins.h
199 +++ new/source/built-ins.h
200 @@ -79,6 +79,7 @@ MS(timer_remove, timerRemove)
201 MS(escape_literal, escapeLiteral)
202 MS(full_file_name, fullFileName)
203 MS(join, join)
204 +MS(eval, eval)
206 MV(cursor, cursor)
207 MV(line, line)