1 /* $Id: interpret.h,v 1.22 2008/10/03 14:34:55 lebert Exp $ */
2 /*******************************************************************************
4 * interpret.h -- Nirvana Editor Interpreter Header File *
6 * Copyright 2004 The NEdit Developers *
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. *
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 *
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 *
23 * Nirvana Text Editor *
26 *******************************************************************************/
28 #ifndef NEDIT_INTERPRET_H_INCLUDED
29 #define NEDIT_INTERPRET_H_INCLUDED
34 #define STACK_SIZE 1024 /* Maximum stack size */
35 #define MAX_SYM_LEN 100 /* Max. symbol name length */
36 #define MACRO_EVENT_MARKER 2 /* Special value for the send_event field of
37 events passed to action routines. Tells
38 them that they were called from a macro */
40 enum symTypes
{CONST_SYM
, GLOBAL_SYM
, LOCAL_SYM
, ARG_SYM
, PROC_VALUE_SYM
,
41 C_FUNCTION_SYM
, MACRO_FUNCTION_SYM
, ACTION_ROUTINE_SYM
};
43 enum operations
{OP_RETURN_NO_VAL
, OP_RETURN
, OP_PUSH_SYM
, OP_DUP
, OP_ADD
,
44 OP_SUB
, OP_MUL
, OP_DIV
, OP_MOD
, OP_NEGATE
, OP_INCR
, OP_DECR
, OP_GT
, OP_LT
,
45 OP_GE
, OP_LE
, OP_EQ
, OP_NE
, OP_BIT_AND
, OP_BIT_OR
, OP_AND
, OP_OR
, OP_NOT
,
46 OP_POWER
, OP_CONCAT
, OP_ASSIGN
, OP_SUBR_CALL
, OP_FETCH_RET_VAL
, OP_BRANCH
,
47 OP_BRANCH_TRUE
, OP_BRANCH_FALSE
, OP_BRANCH_NEVER
, OP_ARRAY_REF
,
48 OP_ARRAY_ASSIGN
, OP_BEGIN_ARRAY_ITER
, OP_ARRAY_ITER
, OP_IN_ARRAY
,
49 OP_ARRAY_DELETE
, OP_PUSH_ARRAY_SYM
, OP_ARRAY_REF_ASSIGN_SETUP
, OP_PUSH_ARG
,
50 OP_PUSH_ARG_COUNT
, OP_PUSH_ARG_ARRAY
};
52 enum typeTags
{NO_TAG
, INT_TAG
, STRING_TAG
, ARRAY_TAG
};
54 enum execReturnCodes
{MACRO_TIME_LIMIT
, MACRO_PREEMPT
, MACRO_DONE
, MACRO_ERROR
};
56 #define ARRAY_DIM_SEP "\034"
59 struct SparseArrayEntryTag
;
63 typedef union InstTag
{
66 struct SymbolRec
*sym
;
69 typedef int (*BuiltInSubr
)(WindowInfo
*window
, struct DataValueTag
*argList
,
70 int nArgs
, struct DataValueTag
*result
, char **errMsg
);
72 typedef struct NStringTag
{
77 typedef struct DataValueTag
{
81 struct NStringTag str
;
83 struct ProgramTag
* prog
;
86 struct DataValueTag
* dataval
;
87 struct SparseArrayEntryTag
*arrayPtr
;
91 typedef struct SparseArrayEntryTag
{
92 rbTreeNode nodePtrs
; /* MUST BE FIRST ENTRY */
97 /* symbol table entry */
98 typedef struct SymbolRec
{
102 struct SymbolRec
*next
; /* to link to another */
105 typedef struct ProgramTag
{
106 Symbol
*localSymList
;
110 /* Information needed to re-start a preempted macro */
116 WindowInfo
*runWindow
;
117 WindowInfo
*focusWindow
;
120 void InitMacroGlobals(void);
122 SparseArrayEntry
*arrayIterateFirst(DataValue
*theArray
);
123 SparseArrayEntry
*arrayIterateNext(SparseArrayEntry
*iterator
);
124 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
);
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 */