1 /******************************************************************************
2 *
3 * Copyright (C) 2006-08, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 ******************************************************************************/
13
14 #ifndef _COMPILE_
15 #define _COMPILE_
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif // __cplusplus
20
21 #include "../os/user/defines.h"
22 #include "../lex/lex.h"
23 #include "../common/arrdata.h"
24
25 #define STACK_OPERS 0xFFFF
26 #define STACK_OPS 0xFFFF
27 #define STACK_PARS 0xFFFF
28
29 /*-----------------------------------------------------------------------------
30 * Id: compileflags D
31 *
32 * Summary: Flags for gentee_compile function.
33 *
34 -----------------------------------------------------------------------------*/
35
36 #define CMPL_SRC 0x0001 // Specify if compileinfo.input is Gentee source
37 #define CMPL_NORUN 0x0002 // Don't run anything after the compilation.
38 #define CMPL_GE 0x0004 // Create GE file
39 #define CMPL_LINE 0x0010 // Proceed #! at the first string
40 #define CMPL_DEBUG 0x0020 // Compilation with the debug information
41 #define CMPL_THREAD 0x0040 // Compilation in the thread
42 #define CMPL_NOWAIT 0x0080 // Do not wait for the end of the compilation. /
43 // Use with CMPL_THREAD only.
44 #define CMPL_OPTIMIZE 0x0100 // Optimize the output GE file.
45
46 //#define CMPL_DEFARG 0x0008 // Define arguments
47
48 /*-----------------------------------------------------------------------------
49 * Id: optiflags D
50 *
51 * Summary: Flags for optimize structure.
52 *
53 -----------------------------------------------------------------------------*/
54
55 #define OPTI_DEFINE 0x0001 // Delete 'define' objects.
56 #define OPTI_NAME 0x0002 // Delete names of objects.
57 #define OPTI_AVOID 0x0004 // Delete not used objects.
58 #define OPTI_MAIN 0x0008 // Leave only one main function with OPTI_AVOID.
59
60 /*-----------------------------------------------------------------------------
61 * Id: toptimize T optimize
62 *
63 * Summary: The structure for the using in $[compileinfo] structure.
64 *
65 -----------------------------------------------------------------------------*/
66
67 typedef struct
68 {
69 uint flag; // Flags of the optimization. $$[optiflags]
70 pubyte nameson; // Don't delete names with the following wildcards /
71 // divided by 0 if OPTI_NAME specified
72 pubyte avoidon; // Don't delete objects with the following wildcards /
73 // divided by 0 if OPTI_AVOID specified
74 } optimize, * poptimize;
75
76 /*-----------------------------------------------------------------------------
77 ** Id: compileinfo T
78 *
79 * Summary: The structure for the using in $[gentee_compile] function.
80 *
81 -----------------------------------------------------------------------------*/
82
83 typedef struct
84 {
85 pubyte input; // The Gentee filename. You can specify the Gentee /
86 // source if the flag CMPL_SRC is defined.
87 uint flag; // Compile flags. $$[compileflags]
88 pubyte libdirs; // Folders for searching files: name1 0 name2 0 ... 00. /
89 // It may be NULL.
90 pubyte include; // Include files: name1 0 name2 0 ... 00. These files /
91 // will be compiled at the beginning of the compilation /
92 // process. It may be NULL.
93 pubyte defargs; // Define arguments: name1 0 name2 0 ... 00. You can /
94 // specify additional macro definitions. For example, /
95 // #b( MYMODE = 10 ). In this case, you can use /
96 // #b( $MYMODE ) in the Gentee program. It may be NULL.
97 pubyte output; // Ouput filename for GE. In default, .ge file is created /
98 // in the same folder as .g main file. You can specify /
99 // any path and name for the output bytecode file. You /
100 // must specify CMPL_GE flag to create the bytecode file.
101 pvoid hthread; // The result handle of the thread if you specified /
102 // CMPL_THREAD | CMPL_NOWAIT.
103 uint result; // Result of the program if it was executed.
104 optimize opti; // Optimize structure. It is used if flag CMPL_OPTIMIZE /
105 // is defined.
106 } compileinfo, * pcompileinfo;
107
108 /*-----------------------------------------------------------------------------
109 *
110 * ID: compilefile 19.10.06 0.0.A.
111 *
112 * Summary: compilefile structure.
113 *
114 -----------------------------------------------------------------------------*/
115
116 typedef struct
117 {
118 pstr filename; // The current compiling filename
119 pstr src; // The current source text
120 uint off; // Parsing offset from the beginning
121 parr lexems; // Array of lexem
122 uint pos; // The current position ( for include )
123 uint idfirst; // The first id ( == count of VM identifier )
124 uint priv; // The private or public mode
125 } compilefile, * pcompilefile;
126
127 /*-----------------------------------------------------------------------------
128 *
129 * ID: compile 26.10.06 0.0.A.
130 *
131 * Summary: compile structure.
132 *
133 -----------------------------------------------------------------------------*/
134
135 typedef struct
136 {
137 uint flag; // Compile flags
138 lex ilex; // Lexical processing structure
139 arrdata libdirs; // Array of folders for searching
140 hash files; // Hash of the compiled filenames
141 hash names; // Hash of the identifier names
142 hash opers; // Hash of operators
143 hash macros; // Hash of macros
144 hash namedef; // Hash of macros without '$'
145 hash resource; // Hash of resource strings
146 arrdata string; // Array of strings
147 arrdata binary; // Array of binary data
148 pcompilefile cur; // The current compiling settings
149 pvoid stkopers; // Stack operations
150 pvoid stkops; // Stack operands
151 pvoid stkpars; // Stack parameters
152 pvoid stkmopers; // Stack operations
153 pvoid stkmops; // Stack operands
154 buf out; // output for bytecode
155 pbuf pout; // The current output buffer
156 poptimize popti; // Pointer to the $[toptimize] structure.
157 } compile, * pcompile;
158
159 //--------------------------------------------------------------------------
160
161 uint DLL_EXPORT STDCALL gentee_compile( pcompileinfo compinit );
162 uint STDCALL compile_process( pstr filename );
163
164
165 //--------------------------------------------------------------------------
166
167 #ifdef __cplusplus
168 }
169 #endif // __cplusplus
170
171 #endif // _COMPILE_
Edit