Parse assignment RTL instead of LTR, fixes multiple assignment (
bug 5420).
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jitcraft_thread_h_
20 #define _include_jitcraft_thread_h_
23 #include "PoolAllocator.h"
29 #include "RootScopes.h"
30 #include "VirtualObjectVisitor.h"
50 Unbarriered<Map> maps_[MapKinds_Total];
51 Unbarriered<ArrayMap> externalGenericArrayMap_;
52 Unbarriered<ArrayMap> externalCharArrayMap_;
56 GlobalRoots *globalRoots_;
57 NativeTable *nativeTable_;
58 PackageCache *packages_;
61 Local<Object> *lastLocalRoot_;
62 RootScopeManager rootScopes_;
63 AutoRooted *specialRoots_;
66 bool hasPendingException_;
67 Ke::IMessageReporter *reporter_;
69 Ke::IPublicFunctionListener *publicFunctionListener_;
72 Zone *thisFromCtor() {
81 PoolAllocator &pool() {
90 Object *allocate(MapKind kind, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
92 Local<Map> map(this, maps_[kind]);
93 return allocate(map, bytes, tenure);
95 Object *allocate(Handle<Map> map, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
96 return heap_.allocate(map, bytes, tenure);
98 Map *getMap(MapKind kind) {
101 Map *allocateMap(MapKind kind, size_t bytes, MapKind parent = MapKind_Meta);
103 ArrayMap *externalGenericArrayMap() {
104 return externalGenericArrayMap_;
106 ArrayMap *externalCharArrayMap() {
107 return externalCharArrayMap_;
110 TypeManager *types() const {
113 AutoRooted **lastSpecialRoot() {
114 return &specialRoots_;
116 Local<Object> **lastLocalRoot() {
117 return &lastLocalRoot_;
119 Object **makeScopedRoot(Object *ptr) {
120 return rootScopes_.make(ptr);
122 RootScopeManager &rootScopes() {
125 StringPool *symbols() {
128 GlobalRoots *globalRoots() {
131 NativeTable *nativeTable() {
134 PackageCache *packages() {
138 String *makeSymbol(const char *string, size_t length);
139 String *makeSymbol(const char *string);
141 void reportOutOfMemory();
142 void reportAllocationOverflow();
143 void reportError(Message message, ...);
144 void reportErrorVA(Message message, va_list ap);
145 bool hasPendingException();
146 void clearPendingException();
147 void installErrorReporter(Ke::IMessageReporter *reporter);
148 Ke::IMessageReporter *errorReporter() {
152 void accept(VirtualObjectVisitor *visitor);
153 void sweepWeakRoots();
155 void setPublicFunctionListener(Ke::IPublicFunctionListener *listener);
156 void registerPublic(Handle<Function> fun);
157 void unregisterPublic(Handle<Function> fun);
159 // Helpers that report OOM.
160 void *malloc(size_t size);
161 void *realloc(void *ptr, size_t size);
164 // In a multi-threaded system, this would be a TLS variable.
165 // In the interest of simplicity, we are single-threaded for now.
166 extern Zone *SingleThreadedZone;
168 // Exposed for the compiler.
169 char *BuildErrorMessage(const char *format, va_list ap);
170 void FreeErrorMessage(const char *message);
172 static inline Zone *ZONE()
174 return SingleThreadedZone;
177 template <typename T>
178 Local<T>::Local(Zone *zone, T *thing)
181 prev_(*zone->lastLocalRoot())
183 *zone->lastLocalRoot() = toRaw();
186 template <typename T>
190 assert(*zone_->lastLocalRoot() == toRaw());
191 *zone_->lastLocalRoot() = prev_;
194 template <typename T>
195 ScopedRoot<T>::ScopedRoot()
196 : thingp_(make(NULL))
200 template <typename T>
201 ScopedRoot<T>::ScopedRoot(T *thing)
202 : thingp_(make(thing))
204 // Type check that T is an Object.
205 (void)static_cast<Object *>(thing);
208 template <typename T> T **
209 ScopedRoot<T>::make(T *other)
211 return reinterpret_cast<T **>(ZONE()->makeScopedRoot(other));
214 RootScope::RootScope(Zone *zone)
215 : Ke::HandleScope(zone, zone->rootScopes().position(), *zone->rootScopes().scope())
221 #endif // _include_jitcraft_thread_h_