src/types.h

changeset 88
5def6ff8b466
parent 87
8f65914e7046
child 89
029a330a9bef
equal deleted inserted replaced
87:8f65914e7046 88:5def6ff8b466
1 /*
2 Copyright 2012-2014 Santeri Piippo
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 3. The name of the author may not be used to endorse or promote products
15 derived from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef BOTC_TYPES_H
30 #define BOTC_TYPES_H
31
32 #include <cstdlib>
33 #include <stdexcept>
34 #include "str.h"
35
36 static const std::nullptr_t null = nullptr;
37
38 // Byte datatype
39 typedef int32_t word;
40 typedef unsigned char byte;
41
42 // Parser mode: where is the parser at?
43 enum parsermode_e
44 {
45 e_top_level_mode, // at top level
46 e_event_mode, // inside event definition
47 e_main_loop_mode, // inside mainloop
48 e_onenter_mode, // inside onenter
49 e_onexit_mode, // inside onexit
50 };
51
52 enum type_e
53 {
54 e_unknown_type = 0,
55 e_void_type,
56 e_int_type,
57 e_string_type,
58 e_bool_type,
59 };
60
61 // Script mark and reference
62 struct byte_mark
63 {
64 string name;
65 int pos;
66 };
67
68 struct mark_reference
69 {
70 byte_mark* target;
71 int pos;
72 };
73
74 class script_error : public std::exception
75 {
76 public:
77 script_error (const string& msg) : m_msg (msg) {}
78
79 inline const char* what() const throw()
80 {
81 return m_msg.c_str();
82 }
83
84 private:
85 string m_msg;
86 };
87
88 // ====================================================================
89 // Generic union
90 template <class T> union generic_union
91 {
92 T as_t;
93 byte as_bytes[sizeof (T)];
94 char as_chars[sizeof (T)];
95 double as_double;
96 float as_float;
97 int as_int;
98 word as_word;
99 };
100
101 template<class T> inline T abs (T a)
102 {
103 return (a >= 0) ? a : -a;
104 }
105
106 #ifdef IN_IDE_PARSER
107 using FILE = void;
108 #endif
109
110 #endif // BOTC_TYPES_H

mercurial