3 MIDletPascal-compiler 3.5.IDE (mp3CC.exe)
4 http://sourceforge.net/projects/midletpascal
10 Artem (ironwoodcutter@bk.ru)
14 smart string concatenation,
15 new max array size (up to 32767),
16 inclusion of {$R+/-} to enable/disable real numbers support,
17 and {$V+/-} to enable/disable internal bytecode preverification
20 Javier Santo Domingo (j-a-s-d@users.sourceforge.net)
21 ported to GNUCC (with coditional defines),
22 pascal-like errors messages and warnings,
23 new command-line parsing (C way),
24 disabled $R and $V directives (confusing overlapped functionality with the IDE),
25 and several other adjustments (wow64 WM_COPYDATA workaround, etc)
26 and bugfixes (real numbers parsing, shl & shr swapped operators, etc)
29 Javier Santo Domingo (j-a-s-d@users.sourceforge.net)
30 infinite-loop support (repeat/forever),
31 and bugfixes (complex-type bidimensional array initialization index out-of-bound, etc)
34 Javier Santo Domingo (j-a-s-d@users.sourceforge.net)
36 C-style multiline comments support
39 Javier Santo Domingo (j-a-s-d@users.sourceforge.net)
40 result keyword support,
41 C-style shift operators support (<< and >>),
42 and bugfixes (const assignment crash, etc)
45 Javier Santo Domingo (j-a-s-d@users.sourceforge.net)
46 Project Library Directory support via -p switch,
47 imported the "ASM BLOCK" from the Artem's MPC.3.0.011.SIMPLE parser.c,
48 bytecode keyword support,
49 and ushr/>>> shift operator support
52 Javier Santo Domingo (j-a-s-d@users.sourceforge.net)
53 C-like double quoted strings support,
54 negative integer constants support,
55 and bugfixes (consecutive same variable name declaration collision, etc)
59 // j-a-s-d: workaround for Wow64 using WM_COPYDATA
61 #define WOW64_WORKAROUND
64 #include "../util/strings.h"
65 #include "../util/error.h"
66 #include "../structures/type_list.h"
67 #include "../structures/string_list.h"
68 #include "../structures/type.h"
69 #include "../structures/identifier.h"
70 #include "../structures/name_table.h"
71 #include "../classgen/bytecode.h"
72 #include "../structures/block.h"
73 #include "../parser/parser.h"
74 #include "../util/memory.h"
80 #ifdef WOW64_WORKAROUND
83 int ParentNotifyHandle
= INVALID_HANDLE_VALUE
;
84 COPYDATASTRUCT COMPILERMESSAGE
;
91 int detect_units_only
;
95 extern string
*string_constant
;
97 char *source_file_name
;
98 char *global_library_directory
;
99 char *project_library_directory
;
100 char *user_libraries
= NULL
;
103 extern short int error_count
;
104 extern short int warning_count
;
106 extern int usesForms
;
107 extern int usesSupport
;
108 extern int usesFloat
;
109 extern int usesRecordStore
;
111 extern int usesPlayer
;
114 extern int constant_pool_size
;
115 extern long int last_error_linenum
;
116 extern int inside_loop
;
119 extern string
*string_constant
;
121 extern int next_record_ID
;
125 #ifdef WOW64_WORKAROUND
126 if (ParentNotifyHandle
!= INVALID_HANDLE_VALUE
) {
127 COMPILERMESSAGE
.dwData
= 1;
128 COMPILERMESSAGE
.cbData
= sizeof( msgstr
);
129 COMPILERMESSAGE
.lpData
= &msgstr
;
130 SendMessage(ParentNotifyHandle
, WM_COPYDATA
,
131 (WPARAM
) 0, (LPARAM
)(LPVOID
) &COMPILERMESSAGE
);
139 void requires(int reqkind
, char* req
)
144 sprintf(msgstr
,"^0%s\n", req
);
147 sprintf(msgstr
,"^1%s\n", req
);
150 sprintf(msgstr
,"^2%s\n", req
);
153 sprintf(msgstr
,"^3%s\n", req
);
161 void compile_progress(int x
)
163 if (x
!= last_progress
)
166 sprintf(msgstr
,"@%d\n", last_progress
);
171 void compile_terminate(){
179 void initialize_compiler()
181 constant_pool_size
= 0;
182 string_constant
= NULL
;
185 last_error_linenum
= -1;
196 user_libraries
= NULL
;
202 "-------------------------------------------------------------------------\n"
203 "MIDletPascal 3.5 Compiler\n"
204 "Version: MPC.3.5.IDE\n"
205 "Authors: Niksa Orlic (1.x-2.0), Artem (3.0), Javier Santo Domingo (3.x)\n"
206 "-------------------------------------------------------------------------\n"
208 "\t-s\"<source_filename>\"\n"
209 "\t-o\"<output_path>\"\n"
210 "\t-l\"<global_library_path>\"\n"
211 "\t-p\"<project_library_path>\"\n"
213 "\t-c<canvas_type>\n"
214 "\t-r<next_record_ID>\n"
215 "\t[-d] // detect units only\n"
216 #ifdef WOW64_WORKAROUND
217 "\t[-n]<parent_notify_handle> // outputs using WMCOPYDATA\n"
225 void PrintFinalMessage ()
228 requires(2,"FS.class");
231 requires(2,"S.class");
233 if (usesFloat
== 1) {
235 requires(2,"Real.class");
236 requires(2,"Real$NumberFormat.class");
238 requires(2,"F.class");
241 if (usesRecordStore
== 1) {
242 requires(2,"RS.class");
245 requires(2,"H.class");
247 if (usesPlayer
== 1) {
248 requires(2,"P.class");
251 requires(2,"SM.class");
253 sprintf(msgstr
,"Done - %d error(s), %d warning(s)\n", error_count
, warning_count
);
256 int main(int argc
, char **argv
)
259 char *source_file
= NULL
;
260 char *output_directory
= NULL
;
266 // -- parse command line arguments
267 detect_units_only
= 0;
272 while ((c
= getopt(argc
, argv
, "?:s:o:l:p:m:n:c:r:d")) != -1) {
275 source_file
= optarg
;
278 output_directory
= optarg
;
281 global_library_directory
= optarg
;
284 project_library_directory
= optarg
;
287 if (strcmp("2", optarg
) == 0) {
288 mathType
= 2; // REAL
292 #ifdef WOW64_WORKAROUND
293 ParentNotifyHandle
= atoi(optarg
);
297 next_record_ID
= atoi(optarg
);
300 if (strcmp("2", optarg
) == 0) {
301 canvasType
= FULL_NOKIA
; // FULL_NOKIA
302 } else if (strcmp("1", optarg
) == 0) {
303 canvasType
= FULL_MIDP20
; // FULL_MIDP20
315 if (project_library_directory
== NULL
) {
316 sprintf(msgstr
,"mp3cc: no project library directory\n");
320 if (global_library_directory
== NULL
) {
321 sprintf(msgstr
,"mp3cc: no global library directory\n");
325 if (output_directory
== NULL
) {
326 sprintf(msgstr
,"mp3cc: no output directory\n");
330 if (source_file
== NULL
) {
331 sprintf(msgstr
,"mp3cc: no source file\n");
339 initialize_compiler();
343 pos
=strlen(source_file
)-1;
344 while ((source_file
[pos
] == '\r') || (source_file
[pos
] == '\n')) pos
--;
345 source_file
[pos
+ 1] = '\0';
346 source_file_name
= (char*) mem_alloc(pos
+ 1);
347 if (source_file_name
== NULL
) die(1);
350 while ((pos
>= 0) && (source_file
[pos
] != '/')) pos
--;
353 while ((pos
>= 0) && (source_file
[pos
] != '\\')) pos
--;
354 if (source_file
[pos
] != '\\') die(21);
357 strcpy(source_file_name
, source_file
+ pos
+ 1);
359 pos
= strlen(output_directory
) - 1;
360 while ((output_directory
[pos
] == '\r')|| (output_directory
[pos
] == '\n')) pos
--;
361 output_directory
[pos
+ 1] = '\0';
362 //len = strlen(output_directory); output_path = (char*) mem_alloc(len + 1);
363 output_path
= output_directory
;
364 //library_directory=output_directory;
365 yyrestart(source_file
);
366 if ((yyin
!= NULL
) && (output_path
!= NULL
))
368 if (detect_units_only
) {
369 sprintf(msgstr
,"Detecting units of \'%s\'...\n", source_file_name
);
371 sprintf(msgstr
,"Compiling \'%s\'...\n", source_file_name
);
374 strcpy(output_path
, output_directory
);
378 mem_free(output_path
);
379 mem_free(source_file_name
);
383 if (string_constant
!= NULL
)
384 string_destroy(string_constant
);
386 if (!detect_units_only
)