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 #define CMPL_NOCLEAR 0x0200 // Do not clear existing objects in the virtual /
46 // machine.
47 #define CMPL_ASM 0x0400 // Convert the bytecode to assembler code.
48
49 //#define CMPL_DEFARG 0x0008 // Define arguments
50
51 /*-----------------------------------------------------------------------------
52 * Id: optiflags D
53 *
54 * Summary: Flags for optimize structure.
55 *
56 -----------------------------------------------------------------------------*/
57
58 #define OPTI_DEFINE 0x0001 // Delete 'define' objects.
59 #define OPTI_NAME 0x0002 // Delete names of objects.
60 #define OPTI_AVOID 0x0004 // Delete not used objects.
61 #define OPTI_MAIN 0x0008 // Leave only one main function with OPTI_AVOID.
62
63 /*-----------------------------------------------------------------------------
64 * Id: toptimize T optimize
65 *
66 * Summary: The structure for the using in $[compileinfo] structure.
67 *
68 -----------------------------------------------------------------------------*/
69
70 typedef struct
71 {
72 uint flag; // Flags of the optimization. $$[optiflags]
73 pubyte nameson; // Don't delete names with the following wildcards /
74 // divided by 0 if OPTI_NAME specified
75 pubyte avoidon; // Don't delete objects with the following wildcards /
76 // divided by 0 if OPTI_AVOID specified
77 } optimize, * poptimize;
78
79 /*-----------------------------------------------------------------------------
80 ** Id: compileinfo T
81 *
82 * Summary: The structure for the using in $[gentee_compile] function.
83 *
84 -----------------------------------------------------------------------------*/
85
86 typedef struct
87 {
88 pubyte input; // The Gentee filename. You can specify the Gentee /
89 // source if the flag CMPL_SRC is defined.
90 uint flag; // Compile flags. $$[compileflags]
91 pubyte libdirs; // Folders for searching files: name1 0 name2 0 ... 00. /
92 // It may be NULL.
93 pubyte include; // Include files: name1 0 name2 0 ... 00. These files /
94 // will be compiled at the beginning of the compilation /
95 // process. It may be NULL.
96 pubyte defargs; // Define arguments: name1 0 name2 0 ... 00. You can /
97 // specify additional macro definitions. For example, /
98 // #b( MYMODE = 10 ). In this case, you can use /
99 // #b( $MYMODE ) in the Gentee program. It may be NULL.
100 pubyte output; // Ouput filename for GE. In default, .ge file is created /
101 // in the same folder as .g main file. You can specify /
102 // any path and name for the output bytecode file. You /
103 // must specify CMPL_GE flag to create the bytecode file.
104 pvoid hthread; // The result handle of the thread if you specified /
105 // CMPL_THREAD | CMPL_NOWAIT.
106 uint result; // Result of the program if it was executed.
107 optimize opti; // Optimize structure. It is used if flag CMPL_OPTIMIZE /
108 // is defined.
109 } compileinfo, * pcompileinfo;
110
111 /*-----------------------------------------------------------------------------
112 *
113 * ID: compilefile 19.10.06 0.0.A.
114 *
115 * Summary: compilefile structure.
116 *
117 -----------------------------------------------------------------------------*/
118
119 typedef struct
120 {
121 pstr filename; // The current compiling filename
122 pstr src; // The current source text
123 uint off; // Parsing offset from the beginning
124 parr lexems; // Array of lexem
125 uint pos; // The current position ( for include )
126 uint idfirst; // The first id ( == count of VM identifier )
127 uint priv; // The private or public mode
128 } compilefile, * pcompilefile;
129
130 /*-----------------------------------------------------------------------------
131 *
132 * ID: compile 26.10.06 0.0.A.
133 *
134 * Summary: compile structure.
135 *
136 -----------------------------------------------------------------------------*/
137
138 typedef struct
139 {
140 uint flag; // Compile flags
141 lex ilex; // Lexical processing structure
142 arrdata libdirs; // Array of folders for searching
143 hash files; // Hash of the compiled filenames
144 hash names; // Hash of the identifier names
145 hash opers; // Hash of operators
146 hash macros; // Hash of macros
147 hash namedef; // Hash of macros without '$'
148 hash resource; // Hash of resource strings
149 arrdata string; // Array of strings
150 arrdata binary; // Array of binary data
151 pcompilefile cur; // The current compiling settings
152 pvoid stkopers; // Stack operations
153 pvoid stkops; // Stack operands
154 pvoid stkpars; // Stack parameters
155 pvoid stkmopers; // Stack operations
156 pvoid stkmops; // Stack operands
157 buf out; // output for bytecode
158 pbuf pout; // The current output buffer
159 poptimize popti; // Pointer to the $[toptimize] structure.
160 pstr curdir; // The current directory before compiling
161 } compile, * pcompile;
162
163 //--------------------------------------------------------------------------
164
165 uint DLL_EXPORT STDCALL gentee_compile( pcompileinfo compinit );
166 uint STDCALL compile_process( pstr filename );
167
168
169 //--------------------------------------------------------------------------
170
171 #ifdef __cplusplus
172 }
173 #endif // __cplusplus
174
175 #endif // _COMPILE_
176
Редактировать