1 /* |
1 /* |
2 Copyright (c) 2013-2014, Santeri Piippo |
2 Copyright (c) 2012-2014, Santeri Piippo |
3 All rights reserved. |
3 All rights reserved. |
4 |
4 |
5 Redistribution and use in source and binary forms, with or without |
5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are met: |
6 modification, are permitted provided that the following conditions are met: |
7 |
7 |
37 |
37 |
38 #include <cstdio> |
38 #include <cstdio> |
39 #include <cstdarg> |
39 #include <cstdarg> |
40 #include <cstdint> |
40 #include <cstdint> |
41 #include "types.h" |
41 #include "types.h" |
42 #include "bots.h" |
42 #include "containers.h" |
43 #include "str.h" |
43 #include "str.h" |
44 #include "containers.h" |
|
45 #include "format.h" |
44 #include "format.h" |
|
45 #include "botstuff.h" |
46 #include "tokens.h" |
46 #include "tokens.h" |
47 |
47 |
48 // Application name and version |
48 // Application name and version |
49 #define APPNAME "botc" |
49 #define APPNAME "botc" |
50 #define VERSION_MAJOR 0 |
50 #define VERSION_MAJOR 0 |
51 #define VERSION_MINOR 999 |
51 #define VERSION_MINOR 999 |
52 |
52 |
53 // On Windows, files are case-insensitive |
53 // On Windows, files are case-insensitive |
54 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) |
54 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) |
55 #define FILE_CASEINSENSITIVE |
55 #define FILE_CASEINSENSITIVE |
56 #endif |
56 #endif |
57 |
57 |
58 // Parser mode: where is the parser at? |
58 // Parser mode: where is the parser at? |
59 enum parsermode_e { |
59 enum parsermode_e |
|
60 { |
60 MODE_TOPLEVEL, // at top level |
61 MODE_TOPLEVEL, // at top level |
61 MODE_EVENT, // inside event definition |
62 MODE_EVENT, // inside event definition |
62 MODE_MAINLOOP, // inside mainloop |
63 MODE_MAINLOOP, // inside mainloop |
63 MODE_ONENTER, // inside onenter |
64 MODE_ONENTER, // inside onenter |
64 MODE_ONEXIT, // inside onexit |
65 MODE_ONEXIT, // inside onexit |
65 }; |
66 }; |
66 |
67 |
67 enum type_e { |
68 enum type_e |
|
69 { |
68 TYPE_UNKNOWN = 0, |
70 TYPE_UNKNOWN = 0, |
69 TYPE_VOID, |
71 TYPE_VOID, |
70 TYPE_INT, |
72 TYPE_INT, |
71 TYPE_STRING, |
73 TYPE_STRING, |
72 TYPE_BOOL, |
74 TYPE_BOOL, |
97 extern int g_NumStates; |
99 extern int g_NumStates; |
98 extern int g_NumEvents; |
100 extern int g_NumEvents; |
99 extern parsermode_e g_CurMode; |
101 extern parsermode_e g_CurMode; |
100 extern string g_CurState; |
102 extern string g_CurState; |
101 |
103 |
102 #define neurosphere if (g_Neurosphere) |
|
103 #define twice for (int repeat_token = 0; repeat_token < 2; repeat_token++) |
|
104 |
|
105 #ifndef __GNUC__ |
104 #ifndef __GNUC__ |
106 #define __attribute__(X) |
105 #define __attribute__(X) |
107 #endif |
106 #endif |
108 #define deprecated __attribute__ ((deprecated)) |
107 #define deprecated __attribute__ ((deprecated)) |
109 |
|
110 // Power function |
|
111 template<class T> T pow (T a, int b) { |
|
112 if (!b) |
|
113 return 1; |
|
114 |
|
115 T r = a; |
|
116 while (b > 1) { |
|
117 b--; |
|
118 r = r * a; |
|
119 } |
|
120 |
|
121 return r; |
|
122 } |
|
123 |
108 |
124 // Byte datatype |
109 // Byte datatype |
125 typedef int32_t word; |
110 typedef int32_t word; |
126 typedef unsigned char byte; |
111 typedef unsigned char byte; |
127 |
112 |
128 // Keywords |
113 // Keywords |
129 extern const char** g_Keywords; |
114 extern const string_list g_Keywords; |
130 |
115 |
131 bool IsKeyword (string s); |
116 bool IsKeyword (string s); |
132 int NumKeywords (); |
117 int NumKeywords (); |
133 |
118 |
134 // Script mark and reference |
119 // Script mark and reference |
135 struct ScriptMark { |
120 struct ScriptMark |
|
121 { |
136 string name; |
122 string name; |
137 size_t pos; |
123 size_t pos; |
138 }; |
124 }; |
139 |
125 |
140 struct ScriptMarkReference { |
126 struct ScriptMarkReference |
|
127 { |
141 int num; |
128 int num; |
142 size_t pos; |
129 size_t pos; |
143 }; |
130 }; |
144 |
131 |
145 // ==================================================================== |
132 // ==================================================================== |
146 // Generic union |
133 // Generic union |
147 template <class T> union generic_union { |
134 template <class T> union generic_union |
|
135 { |
148 T as_t; |
136 T as_t; |
149 byte as_bytes[sizeof (T)]; |
137 byte as_bytes[sizeof (T)]; |
150 char as_chars[sizeof (T)]; |
138 char as_chars[sizeof (T)]; |
151 double as_double; |
139 double as_double; |
152 float as_float; |
140 float as_float; |
154 word as_word; |
142 word as_word; |
155 }; |
143 }; |
156 |
144 |
157 // ==================================================================== |
145 // ==================================================================== |
158 // Finds a byte in the given value. |
146 // Finds a byte in the given value. |
159 template <class T> inline unsigned char GetByteIndex (T a, int b) { |
147 template <class T> inline unsigned char GetByteIndex (T a, int b) |
160 union_t<T> uni; |
148 { |
161 uni.val = a; |
149 generic_union<T> uni; |
162 return uni.b[b]; |
150 uni.as_t = a; |
|
151 return uni.as_bytes[b]; |
163 } |
152 } |
164 |
153 |
165 #endif // BOTC_COMMON_H |
154 #endif // BOTC_COMMON_H |