From Ivan Skytte Jørgensen: remove duplicate declarations
[nedit.git] / source / interpret.h
blobe3fef1785c7e647d27bf90d1afd667eab53953fe
1 /* $Id: interpret.h,v 1.20 2007/01/12 16:17:42 tringali Exp $ */
2 /*******************************************************************************
3 * *
4 * interpret.h -- Nirvana Editor Interpreter Header File *
5 * *
6 * Copyright 2004 The NEdit Developers *
7 * *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
11 * version. In addition, you may distribute versions of this program linked to *
12 * Motif or Open Motif. See README for details. *
13 * *
14 * This software is distributed in the hope that it will be useful, but WITHOUT *
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
17 * more details. *
18 * *
19 * You should have received a copy of the GNU General Public License along with *
20 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
21 * Place, Suite 330, Boston, MA 02111-1307 USA *
22 * *
23 * Nirvana Text Editor *
24 * July 31, 2001 *
25 * *
26 *******************************************************************************/
28 #ifndef NEDIT_INTERPRET_H_INCLUDED
29 #define NEDIT_INTERPRET_H_INCLUDED
31 #include "nedit.h"
32 #include "rbTree.h"
34 #define MAX_ARGS 9 /* Maximum number of subroutine arguments */
35 #define STACK_SIZE 1024 /* Maximum stack size */
36 #define MAX_SYM_LEN 100 /* Max. symbol name length */
37 #define MACRO_EVENT_MARKER 2 /* Special value for the send_event field of
38 events passed to action routines. Tells
39 them that they were called from a macro */
41 enum symTypes {CONST_SYM, GLOBAL_SYM, LOCAL_SYM, ARG_SYM, PROC_VALUE_SYM,
42 C_FUNCTION_SYM, MACRO_FUNCTION_SYM, ACTION_ROUTINE_SYM};
43 #define N_OPS 43
44 enum operations {OP_RETURN_NO_VAL, OP_RETURN, OP_PUSH_SYM, OP_DUP, OP_ADD,
45 OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_NEGATE, OP_INCR, OP_DECR, OP_GT, OP_LT,
46 OP_GE, OP_LE, OP_EQ, OP_NE, OP_BIT_AND, OP_BIT_OR, OP_AND, OP_OR, OP_NOT,
47 OP_POWER, OP_CONCAT, OP_ASSIGN, OP_SUBR_CALL, OP_FETCH_RET_VAL, OP_BRANCH,
48 OP_BRANCH_TRUE, OP_BRANCH_FALSE, OP_BRANCH_NEVER, OP_ARRAY_REF,
49 OP_ARRAY_ASSIGN, OP_BEGIN_ARRAY_ITER, OP_ARRAY_ITER, OP_IN_ARRAY,
50 OP_ARRAY_DELETE, OP_PUSH_ARRAY_SYM, OP_ARRAY_REF_ASSIGN_SETUP, OP_PUSH_ARG,
51 OP_PUSH_ARG_COUNT, OP_PUSH_ARG_ARRAY};
53 enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG};
55 enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR};
57 #define ARRAY_DIM_SEP "\034"
59 struct DataValueTag;
60 struct ProgramTag;
61 struct SymbolRec;
63 typedef union InstTag {
64 int (*func)(void);
65 int value;
66 struct SymbolRec *sym;
67 } Inst;
69 typedef int (*BuiltInSubr)(WindowInfo *window, struct DataValueTag *argList,
70 int nArgs, struct DataValueTag *result, char **errMsg);
72 typedef struct NStringTag {
73 char *rep;
74 size_t len;
75 } NString;
77 typedef struct DataValueTag {
78 enum typeTags tag;
79 union {
80 int n;
81 struct NStringTag str;
82 BuiltInSubr subr;
83 struct ProgramTag* prog;
84 XtActionProc xtproc;
85 Inst* inst;
86 struct DataValueTag* dataval;
87 struct SparseArrayEntry *arrayPtr;
88 } val;
89 } DataValue;
91 typedef struct {
92 rbTreeNode nodePtrs; /* MUST BE FIRST ENTRY */
93 char *key;
94 DataValue value;
95 } SparseArrayEntry;
97 /* symbol table entry */
98 typedef struct SymbolRec {
99 char *name;
100 enum symTypes type;
101 DataValue value;
102 struct SymbolRec *next; /* to link to another */
103 } Symbol;
105 typedef struct ProgramTag {
106 Symbol *localSymList;
107 Inst *code;
108 } Program;
110 /* Information needed to re-start a preempted macro */
111 typedef struct {
112 DataValue *stack;
113 DataValue *stackP;
114 DataValue *frameP;
115 Inst *pc;
116 WindowInfo *runWindow;
117 WindowInfo *focusWindow;
118 } RestartData;
120 void InitMacroGlobals(void);
122 SparseArrayEntry *arrayIterateFirst(DataValue *theArray);
123 SparseArrayEntry *arrayIterateNext(SparseArrayEntry *iterator);
124 struct SparseArrayEntry *ArrayNew(void);
125 Boolean ArrayInsert(DataValue* theArray, char* keyStr, DataValue* theValue);
126 void ArrayDelete(DataValue *theArray, char *keyStr);
127 void ArrayDeleteAll(DataValue *theArray);
128 unsigned ArraySize(DataValue *theArray);
129 Boolean ArrayGet(DataValue* theArray, char* keyStr, DataValue* theValue);
130 int ArrayCopy(DataValue *dstArray, DataValue *srcArray);
132 /* Routines for creating a program, (accumulated beginning with
133 BeginCreatingProgram and returned via FinishCreatingProgram) */
134 void BeginCreatingProgram(void);
135 int AddOp(int op, char **msg);
136 int AddSym(Symbol *sym, char **msg);
137 int AddImmediate(int value, char **msg);
138 int AddBranchOffset(Inst *to, char **msg);
139 Inst *GetPC(void);
140 Symbol *InstallIteratorSymbol(void);
141 Symbol *LookupStringConstSymbol(const char *value);
142 Symbol *InstallStringConstSymbol(const char *str);
143 Symbol *LookupSymbol(const char *name);
144 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
145 Program *FinishCreatingProgram(void);
146 void SwapCode(Inst *start, Inst *boundary, Inst *end);
147 void StartLoopAddrList(void);
148 int AddBreakAddr(Inst *addr);
149 int AddContinueAddr(Inst *addr);
150 void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr);
152 /* create a permanently allocated static string (only for use with static strings) */
153 #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1)
155 /* Routines for executing programs */
156 int ExecuteMacro(WindowInfo *window, Program *prog, int nArgs, DataValue *args,
157 DataValue *result, RestartData **continuation, char **msg);
158 int ContinueMacro(RestartData *continuation, DataValue *result, char **msg);
159 void RunMacroAsSubrCall(Program *prog);
160 void PreemptMacro(void);
161 char *AllocString(int length);
162 char *AllocStringNCpy(const char *s, int length);
163 char *AllocStringCpy(const char *s);
164 int AllocNString(NString *string, int length);
165 int AllocNStringNCpy(NString *string, const char *s, int length);
166 int AllocNStringCpy(NString *string, const char *s);
167 void GarbageCollectStrings(void);
168 void FreeRestartData(RestartData *context);
169 Symbol *PromoteToGlobal(Symbol *sym);
170 void FreeProgram(Program *prog);
171 void ModifyReturnedValue(RestartData *context, DataValue dv);
172 WindowInfo *MacroRunWindow(void);
173 WindowInfo *MacroFocusWindow(void);
174 void SetMacroFocusWindow(WindowInfo *window);
175 /* function used for implicit conversion from string to number */
176 int StringToNum(const char *string, int *number);
178 #endif /* NEDIT_INTERPRET_H_INCLUDED */