1 // Copyright 2014 Wouter van Oortmerssen. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #ifdef _WIN32
18     #define _CRT_SECURE_NO_WARNINGS
19     #define _SCL_SECURE_NO_WARNINGS
20     #define _CRTDBG_MAP_ALLOC
21     #include <stdlib.h>
22     #include <crtdbg.h>
23     #ifndef NDEBUG
24         #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
25         #define new DEBUG_NEW
26     #endif
27     #include "StackWalker\StackWalkerHelpers.h"
28     #include <intrin.h>
29 #endif
30 
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <assert.h>
34 #include <math.h>
35 #include <string.h>
36 #include <stdint.h>
37 #include <float.h>
38 #include <limits.h>
39 
40 #include <string>
41 #include <map>
42 #include <unordered_map>
43 #include <vector>
44 #include <list>
45 #include <set>
46 #include <algorithm>
47 #include <iterator>
48 #include <functional>
49 #include <array>
50 #include <type_traits>
51 #include <memory>
52 #include <optional>
53 
54 #if defined(__has_include) && __has_include(<string_view>)
55     #include <string_view>
56 #else
57     #include <experimental/string_view>
58 #endif
59 
60 #include <thread>
61 #include <future>
62 
63 #include <sstream>
64 #include <iostream>
65 #include <iomanip>
66 
67 using namespace std;
68 
69 #include "gsl/gsl-lite.hpp"
70 
71 using namespace gsl;
72 
73 #include "flatbuffers/flatbuffers.h"
74 
75 typedef unsigned char uchar;
76 typedef unsigned short ushort;
77 typedef unsigned int uint;
78 
79 #ifdef nullptr
80 #undef nullptr
81 #endif
82 #define nullptr nullptr
83 
84 // Our universally used headers.
85 #include "wentropy.h"
86 #include "tools.h"
87 #include "platform.h"
88 #include "slaballoc.h"
89 #include "geom.h"
90 
91 using namespace geom;
92 
93 #ifdef BUILD_CONTEXT_compiled_lobster
94     // This code is being build as part of lobster code compiled to C++, modify VM behavior
95     // accordingly.
96     #define VM_COMPILED_CODE_MODE
97 #endif
98 
99 #ifndef LOBSTER_ENGINE
100     // By default, build Lobster assuming it comes with the default engine.
101     // Build systems can override this for a console-only build.
102     #define LOBSTER_ENGINE 1
103 #endif
104