Added missing shell/macroMenuValid initializations.
[nedit.git] / source / interpret.h
blob1a3b911a47a5eeae0c9e64c9654b0d8d4bc9fc93
1 /* $Id: interpret.h,v 1.14 2003/12/19 23:23:30 slobasso Exp $ */
3 #ifndef NEDIT_INTERPRET_H_INCLUDED
4 #define NEDIT_INTERPRET_H_INCLUDED
6 #include "nedit.h"
7 #include "rbTree.h"
9 #define MAX_ARGS 9 /* Maximum number of subroutine arguments */
10 #define STACK_SIZE 1024 /* Maximum stack size */
11 #define MAX_SYM_LEN 100 /* Max. symbol name length */
12 #define MACRO_EVENT_MARKER 2 /* Special value for the send_event field of
13 events passed to action routines. Tells
14 them that they were called from a macro */
16 enum symTypes {CONST_SYM, GLOBAL_SYM, LOCAL_SYM, ARG_SYM, PROC_VALUE_SYM,
17 C_FUNCTION_SYM, MACRO_FUNCTION_SYM, ACTION_ROUTINE_SYM};
18 #define N_OPS 43
19 enum operations {OP_RETURN_NO_VAL, OP_RETURN, OP_PUSH_SYM, OP_DUP, OP_ADD,
20 OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_NEGATE, OP_INCR, OP_DECR, OP_GT, OP_LT,
21 OP_GE, OP_LE, OP_EQ, OP_NE, OP_BIT_AND, OP_BIT_OR, OP_AND, OP_OR, OP_NOT,
22 OP_POWER, OP_CONCAT, OP_ASSIGN, OP_SUBR_CALL, OP_FETCH_RET_VAL, OP_BRANCH,
23 OP_BRANCH_TRUE, OP_BRANCH_FALSE, OP_BRANCH_NEVER, OP_ARRAY_REF,
24 OP_ARRAY_ASSIGN, OP_BEGIN_ARRAY_ITER, OP_ARRAY_ITER, OP_IN_ARRAY,
25 OP_ARRAY_DELETE, OP_PUSH_ARRAY_SYM, OP_ARRAY_REF_ASSIGN_SETUP, OP_PUSH_ARG,
26 OP_PUSH_ARG_COUNT, OP_PUSH_ARG_ARRAY};
28 enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG};
30 enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR};
32 #define ARRAY_DIM_SEP "\034"
34 struct DataValueTag;
35 struct ProgramTag;
37 typedef int (*Inst)(void);
39 typedef int (*BuiltInSubr)(WindowInfo *window, struct DataValueTag *argList,
40 int nArgs, struct DataValueTag *result, char **errMsg);
42 typedef struct DataValueTag {
43 enum typeTags tag;
44 union {
45 int n;
46 char *str;
47 BuiltInSubr subr;
48 struct ProgramTag* prog;
49 XtActionProc xtproc;
50 Inst* inst;
51 struct DataValueTag* dataval;
52 struct SparseArrayEntry *arrayPtr;
53 } val;
54 } DataValue;
56 typedef struct {
57 rbTreeNode nodePtrs; /* MUST BE FIRST ENTRY */
58 char *key;
59 DataValue value;
60 } SparseArrayEntry;
62 /* symbol table entry */
63 typedef struct SymbolRec {
64 char *name;
65 enum symTypes type;
66 DataValue value;
67 struct SymbolRec *next; /* to link to another */
68 } Symbol;
70 typedef struct ProgramTag {
71 Symbol *localSymList;
72 Inst *code;
73 } Program;
75 /* Information needed to re-start a preempted macro */
76 typedef struct {
77 DataValue *stack;
78 DataValue *stackP;
79 DataValue *frameP;
80 Inst *pc;
81 WindowInfo *runWindow;
82 WindowInfo *focusWindow;
83 } RestartData;
85 void InitMacroGlobals(void);
87 SparseArrayEntry *arrayIterateFirst(DataValue *theArray);
88 SparseArrayEntry *arrayIterateNext(SparseArrayEntry *iterator);
89 struct SparseArrayEntry *ArrayNew(void);
90 int ArrayInsert(DataValue *theArray, char *keyStr, DataValue *theValue);
91 void ArrayDelete(DataValue *theArray, char *keyStr);
92 void ArrayDeleteAll(DataValue *theArray);
93 int ArraySize(DataValue *theArray);
94 int ArrayGet(DataValue *theArray, char *keyStr, DataValue *theValue);
95 int ArrayCopy(DataValue *dstArray, DataValue *srcArray);
97 /* Routines for creating a program, (accumulated beginning with
98 BeginCreatingProgram and returned via FinishCreatingProgram) */
99 void BeginCreatingProgram(void);
100 int AddOp(int op, char **msg);
101 int AddSym(Symbol *sym, char **msg);
102 int AddImmediate(void *value, char **msg);
103 int AddBranchOffset(Inst *to, char **msg);
104 Inst *GetPC(void);
105 Symbol *InstallIteratorSymbol();
106 Symbol *LookupStringConstSymbol(const char *value);
107 Symbol *InstallStringConstSymbol(const char *str);
108 Symbol *LookupSymbol(const char *name);
109 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
110 Program *FinishCreatingProgram(void);
111 void SwapCode(Inst *start, Inst *boundary, Inst *end);
112 void StartLoopAddrList(void);
113 int AddBreakAddr(Inst *addr);
114 int AddContinueAddr(Inst *addr);
115 void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr);
117 /* create a permanently allocated static string (only for use with static strings) */
118 #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1)
120 /* Routines for executing programs */
121 int ExecuteMacro(WindowInfo *window, Program *prog, int nArgs, DataValue *args,
122 DataValue *result, RestartData **continuation, char **msg);
123 int ContinueMacro(RestartData *continuation, DataValue *result, char **msg);
124 void RunMacroAsSubrCall(Program *prog);
125 void PreemptMacro(void);
126 char *AllocString(int length);
127 char *AllocStringNCpy(const char *s, int length);
128 char *AllocStringCpy(const char *s);
129 void GarbageCollectStrings(void);
130 void FreeRestartData(RestartData *context);
131 Symbol *PromoteToGlobal(Symbol *sym);
132 void FreeProgram(Program *prog);
133 void ModifyReturnedValue(RestartData *context, DataValue dv);
134 WindowInfo *MacroRunWindow(void);
135 WindowInfo *MacroFocusWindow(void);
136 void SetMacroFocusWindow(WindowInfo *window);
137 /* function used for implicit conversion from string to number */
138 int StringToNum(const char *string, int *number);
140 #endif /* NEDIT_INTERPRET_H_INCLUDED */