1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/jitcraft/Reference.h Sun Jul 01 00:00:27 2012 -0700
1.3 @@ -0,0 +1,63 @@
1.4 +/*
1.5 + * Copyright (C) 2012 David Anderson
1.6 + *
1.7 + * This file is part of JITCraft.
1.8 + *
1.9 + * JITCraft is free software: you can redistribute it and/or modify it under
1.10 + * the terms of the GNU General Public License as published by the Free
1.11 + * Software Foundation, either version 3 of the License, or (at your option)
1.12 + * any later version.
1.13 + *
1.14 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.15 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.17 + *
1.18 + * You should have received a copy of the GNU General Public License along with
1.19 + * JITCraft. If not, see http://www.gnu.org/licenses/.
1.20 + */
1.21 +#ifndef _include_jitcraft_reference_h_
1.22 +#define _include_jitcraft_reference_h_
1.23 +
1.24 +#include "Heap.h"
1.25 +#include "Barriers.h"
1.26 +#include "Stack.h"
1.27 +
1.28 +namespace jc {
1.29 +
1.30 +class Array;
1.31 +
1.32 +// A Reference is a typed pointer to another location in memory.
1.33 +class Reference : public Object
1.34 +{
1.35 + void *location_;
1.36 + LocalSlot slot_;
1.37 + Barriered<Array> base_;
1.38 +
1.39 + public:
1.40 + // :TODO: handles
1.41 + static Reference *NewStack(Zone *zone, void *location, Heap::Tenure tenure = Heap::Tenure_Default);
1.42 + static Reference *NewStack(Zone *zone, const LocalSlot &slot, Heap::Tenure tenure = Heap::Tenure_Default);
1.43 + static Reference *NewArray(Zone *zone, Array *base, size_t index, Heap::Tenure tenure = Heap::Tenure_Default);
1.44 +
1.45 + int getInt() {
1.46 + return *reinterpret_cast<int *>(location_);
1.47 + }
1.48 + void setInt(int i) {
1.49 + *reinterpret_cast<int *>(location_) = i;
1.50 + }
1.51 + float getFloat() {
1.52 + return *reinterpret_cast<float *>(location_);
1.53 + }
1.54 + void setFloat(float f) {
1.55 + *reinterpret_cast<float *>(location_) = f;
1.56 + }
1.57 +
1.58 + static inline Reference *cast(Object *obj) {
1.59 + assert(obj->is(MapKind_Reference));
1.60 + return reinterpret_cast<Reference *>(obj);
1.61 + }
1.62 +};
1.63 +
1.64 +}
1.65 +
1.66 +#endif // _include_jitcraft_reference_h_