main.cxx

Wed, 19 Dec 2012 22:01:42 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 19 Dec 2012 22:01:42 +0200
changeset 69
29a3e669d648
parent 68
588cc27e84bb
permissions
-rw-r--r--

So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.

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
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
41 #define __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
42
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 #include <stdio.h>
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 #include <stdlib.h>
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 #include <string.h>
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 #include "common.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
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 #include "scriptreader.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 #include "objwriter.h"
2
bb2c45522eb6 Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
51 #include "events.h"
6
0005527cad62 Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
52 #include "commands.h"
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
53 #include "stringtable.h"
22
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
54 #include "variables.h"
63
0557babc8675 - Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
55 #include "array.h"
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
56 #include "databuffer.h"
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 #include "bots.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 #include "botcommands.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
63
0557babc8675 - Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
61 // List of keywords
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
62 const char* g_Keywords[] = {
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
63 "bool",
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
64 "break",
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
65 "case",
63
0557babc8675 - Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
66 "continue",
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
67 "const",
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
68 "default",
44
6bbaebc472b5 Added do-while loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
69 "do",
56
384c5605bda9 Added support for else-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
70 "else",
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
71 "event",
43
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
72 "for",
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
73 "goto",
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
74 "if",
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
75 "int",
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
76 "mainloop",
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
77 "onenter",
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
78 "onexit",
43
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
79 "state",
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
80 "switch",
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
81 "str"
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
82 "void",
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
83 "while",
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
84
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
85 // These ones aren't implemented yet but I plan to do so, thus they are
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
86 // reserved. Also serves as a to-do list of sorts for me. >:F
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
87 "enum", // Would enum actually be useful? I think so.
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
88 "func", // Would function support need external support from zandronum?
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
89 "return",
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
90 };
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: 24
diff changeset
91
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
92 // databuffer global variable
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
93 int g_NextMark = 0;
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
94
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 int main (int argc, char** argv) {
21
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
96 // Intepret command-line parameters:
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
97 // -l: list commands
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
98 // I guess there should be a better way to do this.
21
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
99 if (argc == 2 && !strcmp (argv[1], "-l")) {
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
100 ReadCommands ();
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
101 printf ("Begin list of commands:\n");
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
102 printf ("------------------------------------------------------\n");
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
103
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
104 CommandDef* comm;
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
105 ITERATE_COMMANDS (comm)
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
106 printf ("%s\n", GetCommandPrototype (comm).chars());
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
107
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
108 printf ("------------------------------------------------------\n");
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
109 printf ("End of command list\n");
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
110 exit (0);
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
111 }
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
112
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
113 // Print header
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
114 str header;
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
115 str headerline = "-=";
60
8834e4b6aebd only print revision in version header if it's non-zero
Teemu Piippo <crimsondusk64@gmail.com>
parents: 56
diff changeset
116 header.appendformat ("%s version %d.%d", APPNAME, VERSION_MAJOR, VERSION_MINOR);
8834e4b6aebd only print revision in version header if it's non-zero
Teemu Piippo <crimsondusk64@gmail.com>
parents: 56
diff changeset
117
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
118 headerline *= (header.len() / 2) - 1;
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
119 headerline += '-';
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
120 printf ("%s\n%s\n", header.chars(), headerline.chars());
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
121
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: 24
diff changeset
122 if (argc < 2) {
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
123 fprintf (stderr, "usage: %s <infile> [outfile] # compiles botscript\n", argv[0]);
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
124 fprintf (stderr, " %s -l # lists commands\n", argv[0]);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 exit (1);
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 }
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
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
128 // A word should always be exactly 4 bytes. The above list command
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
129 // doesn't need it, but the rest of the program does.
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
130 if (sizeof (word) != 4)
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
131 error ("%s expects a word (uint32_t) to be 4 bytes in size, is %d\n",
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
132 APPNAME, sizeof (word));
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
133
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: 24
diff changeset
134 str outfile;
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: 24
diff changeset
135 if (argc < 3)
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: 24
diff changeset
136 outfile = ObjectFileName (argv[1]);
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: 24
diff changeset
137 else
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: 24
diff changeset
138 outfile = argv[2];
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: 24
diff changeset
139
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: 24
diff changeset
140 // If we'd end up writing into an existing file,
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: 24
diff changeset
141 // ask the user if we want to overwrite it
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: 24
diff changeset
142 if (fexists (outfile)) {
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: 24
diff changeset
143 // Additional warning if the paths are the same
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: 24
diff changeset
144 str warning;
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: 24
diff changeset
145 #ifdef FILE_CASEINSENSITIVE
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: 24
diff changeset
146 if (!outfile.icompare (argv[1]))
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: 24
diff changeset
147 #else
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: 24
diff changeset
148 if (!outfile.compare (argv[1]))
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: 24
diff changeset
149 #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: 24
diff changeset
150 {
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: 24
diff changeset
151 warning = "\nWARNING: Output file is the same as the input file. ";
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: 24
diff changeset
152 warning += "Answering yes here will destroy the source!\n";
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: 24
diff changeset
153 warning += "Continue nevertheless?";
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: 24
diff changeset
154 }
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: 24
diff changeset
155 printf ("output file `%s` already exists! overwrite?%s (y/n) ", outfile.chars(), warning.chars());
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: 24
diff changeset
156
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: 24
diff changeset
157 char ans;
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: 24
diff changeset
158 fgets (&ans, 2, stdin);
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: 24
diff changeset
159 if (ans != 'y') {
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: 24
diff changeset
160 printf ("abort\n");
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: 24
diff changeset
161 exit (1);
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: 24
diff changeset
162 }
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: 24
diff changeset
163 }
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: 24
diff changeset
164
6
0005527cad62 Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
165 // Read definitions
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
166 printf ("Reading definitions...\n");
2
bb2c45522eb6 Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
167 ReadEvents ();
6
0005527cad62 Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
168 ReadCommands ();
2
bb2c45522eb6 Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
169
22
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
170 // Init stuff
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
171 InitStringTable ();
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
172
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
173 // Prepare reader and writer
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
174 ScriptReader* r = new ScriptReader (argv[1]);
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
175 ObjWriter* w = new ObjWriter (outfile);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
177 // We're set, begin parsing :)
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
178 printf ("Parsing script...\n");
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
179 r->ParseBotScript (w);
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
180 printf ("Script parsed successfully.\n");
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181
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: 24
diff changeset
182 // Parse done, print statistics and write to file
67
0a202714eea4 Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
183 unsigned int globalcount = g_GlobalVariables.size();
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
184 unsigned int stringcount = CountStringTable ();
43
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
185 int NumMarks = w->MainBuffer->CountMarks ();
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
186 int NumRefs = w->MainBuffer->CountReferences ();
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
187 printf ("%u / %u strings written\n", stringcount, MAX_LIST_STRINGS);
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
188 printf ("%u / %u global variables\n", globalcount, MAX_SCRIPT_VARIABLES);
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
189 printf ("%d / %d bytecode marks\n", NumMarks, MAX_MARKS);
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
190 printf ("%d / %d bytecode references\n", NumRefs, MAX_MARKS);
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
191 printf ("%d / %d events\n", g_NumEvents, MAX_NUM_EVENTS);
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
192 printf ("%d state%s\n", g_NumStates, PLURAL (g_NumStates));
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
193
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: 24
diff changeset
194 w->WriteToFile ();
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
195
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
196 // Clear out the junk
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 delete r;
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 delete w;
38
e4bbd540663b Added if() support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
199
e4bbd540663b Added if() support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
200 // Done!
e4bbd540663b Added if() support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
201 exit (0);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 }
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203
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
204 // ============================================================================
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
205 // Utility functions
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
206
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
207 // ============================================================================
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
208 // Does the given file exist?
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
209 bool fexists (char* path) {
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
210 if (FILE* test = fopen (path, "r")) {
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
211 fclose (test);
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
212 return true;
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
213 }
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
214 return false;
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
215 }
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
216
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
217 // ============================================================================
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
218 // Generic error
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 void error (const char* text, ...) {
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 PERFORM_FORMAT (text, c);
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 fprintf (stderr, "error: %s", c);
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 exit (1);
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: 24
diff changeset
223 }
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: 24
diff changeset
224
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
225 // ============================================================================
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
226 // Mutates given filename to an object filename
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: 24
diff changeset
227 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: 24
diff changeset
228 // Locate the extension and chop it out
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: 24
diff changeset
229 unsigned int extdot = s.last (".");
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
230 if (extdot >= s.len()-4)
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 63
diff changeset
231 s -= (s.len() - extdot);
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: 24
diff changeset
232
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: 24
diff changeset
233 s += ".o";
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: 24
diff changeset
234 return s.chars();
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
235 }
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
236
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
237 // ============================================================================
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
238 // Is the given argument a reserved keyword?
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
239 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
240 for (unsigned int u = 0; u < NumKeywords (); u++)
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
241 if (!s.icompare (g_Keywords[u]))
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
242 return true;
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
243 return false;
42
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
244 }
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
245
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
246 unsigned int NumKeywords () {
5cd91fd1526c FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
247 return sizeof (g_Keywords) / sizeof (const char*);
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
248 }
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
249
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
250 // ============================================================================
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
251 type_e GetTypeByName (str t) {
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
252 t = t.tolower();
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
253 return (t == "int") ? 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
254 (t == "str") ? 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
255 (t == "void") ? 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
256 (t == "bool") ? 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
257 TYPE_UNKNOWN;
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
258 }
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
259
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
260
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
261 // ============================================================================
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
262 // Inverse operation - type name by value
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
263 str GetTypeName (type_e type) {
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
264 switch (type) {
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
265 case TYPE_INT: return "int"; break;
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
266 case TYPE_STRING: return "str"; break;
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
267 case TYPE_VOID: return "void"; break;
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
268 case TYPE_BOOL: return "bool"; break;
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
269 case TYPE_UNKNOWN: return "???"; break;
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
270 }
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
271
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
272 return "";
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 }

mercurial