asherkin@263: /* asherkin@263: * Copyright (C) 2012 David Anderson asherkin@263: * asherkin@263: * This file is part of SourcePawn. asherkin@263: * asherkin@263: * SourcePawn is free software: you can redistribute it and/or modify it under asherkin@263: * the terms of the GNU General Public License as published by the Free asherkin@263: * Software Foundation, either version 3 of the License, or (at your option) asherkin@263: * any later version. asherkin@263: * asherkin@263: * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY asherkin@263: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS asherkin@263: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. asherkin@263: * asherkin@263: * You should have received a copy of the GNU General Public License along with asherkin@263: * SourcePawn. If not, see http://www.gnu.org/licenses/. asherkin@263: */ asherkin@263: #ifndef _include_jitcraft_reference_h_ asherkin@263: #define _include_jitcraft_reference_h_ asherkin@263: asherkin@263: #include "Heap.h" asherkin@263: #include "Barriers.h" asherkin@263: #include "Stack.h" asherkin@263: asherkin@263: namespace ke { asherkin@263: asherkin@263: class Array; asherkin@263: class Struct; asherkin@263: asherkin@263: // A Reference is a typed pointer to another location in memory. asherkin@263: class Reference : public Object asherkin@263: { asherkin@263: void *location_; asherkin@263: Barriered base_; asherkin@263: asherkin@263: // We do not compute references to objects, so this does not need to be asherkin@263: // traced. asherkin@263: LocalSlot slot_; asherkin@263: asherkin@263: public: asherkin@263: static Reference *NewStack(Zone *zone, void *location, Heap::Tenure tenure = Heap::Tenure_Default); asherkin@263: static Reference *NewStack(Zone *zone, const LocalSlot &slot, Heap::Tenure tenure = Heap::Tenure_Default); asherkin@263: asherkin@263: int getInt() { asherkin@263: return *reinterpret_cast(location_); asherkin@263: } asherkin@263: void setInt(int i) { asherkin@263: *reinterpret_cast(location_) = i; asherkin@263: } asherkin@263: float getFloat() { asherkin@263: return *reinterpret_cast(location_); asherkin@263: } asherkin@263: void setFloat(float f) { asherkin@263: *reinterpret_cast(location_) = f; asherkin@263: } asherkin@263: asherkin@263: // WARNING! This should only be for Native calls. asherkin@263: void *location() { asherkin@263: return location_; asherkin@263: } asherkin@263: asherkin@263: // Begin GC Descriptor. asherkin@263: static inline size_t offsetOfBase() { asherkin@263: return offsetof(Reference, base_); asherkin@263: } asherkin@263: // End GC Descriptor. asherkin@263: asherkin@263: static inline Reference *cast(Object *obj) { asherkin@263: assert(!obj || obj->is(MapKind_Reference)); asherkin@263: return reinterpret_cast(obj); asherkin@263: } asherkin@263: }; asherkin@263: asherkin@263: } asherkin@263: asherkin@263: #endif // _include_jitcraft_reference_h_