common.h

Wed, 19 Dec 2012 13:44:18 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 19 Dec 2012 13:44:18 +0200
changeset 68
588cc27e84bb
parent 67
0a202714eea4
child 69
29a3e669d648
permissions
-rw-r--r--

Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.

0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * botc source code
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Santeri `Dusk` Piippo
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 * All rights reserved.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright notice,
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * this list of conditions and the following disclaimer.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * this list of conditions and the following disclaimer in the documentation
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * and/or other materials provided with the distribution.
3
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
14 * 3. Neither the name of the developer nor the names of its contributors may
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
15 * be used to endorse or promote products derived from this software without
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
16 * specific prior written permission.
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 * 4. Redistributions in any form must be accompanied by information on how to
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 * obtain complete source code for the software and any accompanying
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 * software that uses the software. The source code must either be included
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 * in the distribution or be available for no more than the cost of
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 * distribution plus a nominal fee, and must be freely redistributable
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 * under reasonable conditions. For an executable file, complete source
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 * code means the source code for all modules it contains. It does not
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 * include source code for modules or files that typically accompany the
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 * major components of the operating system on which the executable file
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 * runs.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 * POSSIBILITY OF SUCH DAMAGE.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 */
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 #ifndef __COMMON_H__
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 #define __COMMON_H__
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
26
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
44 #include <stdio.h>
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 #include <stdarg.h>
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
46 #include <stdint.h>
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 #include "bots.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 #include "str.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
50 // Application name and version
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
51 #define APPNAME "botc"
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
52 #define VERSION_MAJOR 0
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
53 #define VERSION_MINOR 0
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
54 #define VERSION_REVISION 999
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
32
d11a034aabfd - The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
56 // On Windows, files are case-insensitive
d11a034aabfd - The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
57 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
58 #define FILE_CASEINSENSITIVE
32
d11a034aabfd - The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
59 #endif
d11a034aabfd - The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
60
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
61 // Parser mode: where is the parser at?
67
0a202714eea4 Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
62 enum parsermode_e {
26
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
63 MODE_TOPLEVEL, // at top level
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
64 MODE_EVENT, // inside event definition
26
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
65 MODE_MAINLOOP, // inside mainloop
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
66 MODE_ONENTER, // inside onenter
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
67 MODE_ONEXIT, // inside onexit
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
68 };
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
69
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
70 enum type_e {
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
71 TYPE_UNKNOWN = 0,
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
72 TYPE_VOID,
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
73 TYPE_INT,
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
74 TYPE_STRING,
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
75 TYPE_FLOAT,
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
76 TYPE_BOOL,
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
77
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
78 };
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
79
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
80 #define CHECK_FILE(pointer,path,action) \
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
81 if (!pointer) { \
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
82 error ("couldn't open %s for %s!\n", (char*)path, action); \
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
83 exit (1); \
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
86 // Shortcut for formatting
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
87 #define PERFORM_FORMAT(in, out) \
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
88 va_list v; \
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 va_start (v, in); \
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 char* out = vdynformat (in, v, 256); \
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 va_end (v);
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
93 // Plural expression
22
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
94 #define PLURAL(n) (n != 1) ? "s" : ""
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
95
59
891b9e6ee139 Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
96 // Shortcut for zeroing something
891b9e6ee139 Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
97 #define ZERO(obj) memset (&obj, 0, sizeof (obj));
891b9e6ee139 Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
98
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 void error (const char* text, ...);
32
d11a034aabfd - The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
100 char* ObjectFileName (str s);
d11a034aabfd - The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
101 bool fexists (char* path);
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
102 type_e GetTypeByName (str token);
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 67
diff changeset
103 str GetTypeName (type_e type);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
105 // Make the parser's variables globally available
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
106 extern int g_NumStates;
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
107 extern int g_NumEvents;
67
0a202714eea4 Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
108 extern parsermode_e g_CurMode;
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
109 extern str g_CurState;
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
110
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
111 #define neurosphere if (g_Neurosphere)
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
112 #define twice for (int repeat_token = 0; repeat_token < 2; repeat_token++)
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
113
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
114 #ifndef __GNUC__
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
115 #define __attribute__(X)
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
116 #endif
67
0a202714eea4 Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
117 #define deprecated __attribute__ ((deprecated))
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
118
26
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
119 // Power function
63
0557babc8675 - Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
120 template<class T> T pow (T a, unsigned int b) {
26
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
121 if (!b)
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
122 return 1;
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
123
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
124 T r = a;
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
125 while (b > 1) {
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
126 b--;
63
0557babc8675 - Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
127 r = r * a;
26
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
128 }
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
129
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
130 return r;
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
131 }
54eaea6dc27c Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
132
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
133 // Whitespace check
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
134 inline bool IsCharWhitespace (char c) {
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
135 return (c <= 32 || c == 127 || c == 255);
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
136 }
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
137
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
138 // Byte datatype
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
139 typedef int32_t word;
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
140 typedef unsigned char byte;
36
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
141
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
142 // Keywords
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
143 #ifndef __MAIN_CXX__
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
144 extern const char** g_Keywords;
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
145 #endif
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
146
36
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
147 bool IsKeyword (str s);
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
148 unsigned int NumKeywords ();
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
149
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
150 // Script mark and reference
37
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
151 struct ScriptMark {
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
152 str name;
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
153 size_t pos;
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
154 };
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
155
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
156 struct ScriptMarkReference {
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
157 unsigned int num;
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
158 size_t pos;
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
159 };
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
160
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
161 // ====================================================================
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
162 // Generic union
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
163 template <class T> union union_t {
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
164 T val;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
165 byte b[sizeof (T)];
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
166 char c[sizeof (T)];
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
167 double d;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
168 float f;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
169 int i;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
170 word w;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
171 };
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
172
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
173 // ====================================================================
37
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
174 // Finds a byte in the given value.
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
175 template <class T> inline unsigned char GetByteIndex (T a, unsigned int b) {
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
176 union_t<T> uni;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
177 uni.val = a;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
178 return uni.b[b];
37
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
179 }
c349dca807f9 Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
180
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 #endif // __COMMON_H__

mercurial