Renamed jitcraft/ to src/, fixed some /Wp64 warnings.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #include "Environments.h"
20 #include "Structures.h"
21 #include "FixedArray.h"
23 #include "NameBinding.h"
27 EnvironmentSlotDescriptorArray *
28 EnvironmentSlotDescriptorArray::New(Zone *zone, unsigned nslots)
30 size_t bytesNeeded = sizeof(EnvironmentSlotDescriptorArray) +
31 sizeof(EnvironmentSlotDescriptor) * nslots;
33 Local<EnvironmentSlotDescriptorArray> array(zone);
34 Local<Map> map(zone, zone->getMap(MapKind_EnvironmentSlotDescriptorArray));
36 array = EnvironmentSlotDescriptorArray::cast(zone->allocate(map, bytesNeeded, Heap::Tenure_Old));
40 // We zero the array for safety, since we could GC or fail before initialization.
41 array->length_ = nslots;
42 memset(array->slots(), 0, sizeof(EnvironmentSlotDescriptor) * nslots);
47 Environment::New(Zone *zone, Handle<EnvironmentMap> map, Heap::Tenure tenure)
49 size_t bytesNeeded = sizeof(Environment) + map->structureSize();
50 Local<Environment> env(zone, Environment::cast(zone->allocate(map, bytesNeeded, tenure)));
54 // Initialize when called from C++, to make sure object slots are NULL.
55 memset((Object *)env + 1, 0, map->structureSize());
60 EnvironmentMap::New(Zone *zone, unsigned nvars, Variable **vars)
62 StructureBufferBuilder structure;
64 Local<EnvironmentSlotDescriptorArray> slots(zone);
65 slots = EnvironmentSlotDescriptorArray::New(zone, nvars);
69 // Build the descriptor table, mapping each slot to an offset and type.
70 Local<Type> type(zone);
71 for (unsigned i = 0; i < nvars; i++) {
72 assert(vars[i]->slot() == i);
73 type = vars[i]->type();
75 EnvironmentSlotDescriptor &desc = slots->slots()[i];
76 if (!structure.add(type, &desc.offset))
82 // Allocate the actual map now.
83 size_t bytesNeeded = sizeof(EnvironmentMap) + structure.traceableOffsetCount() * sizeof(unsigned);
84 Local<EnvironmentMap> map(zone);
86 map = EnvironmentMap::cast(zone->allocateMap(MapKind_Environment, bytesNeeded, MapKind_MetaEnvironment));
90 // Fill in the map fields, and copy the traceable offsets structure.
91 map->structureSize_ = structure.structureSize();
92 map->traceOffsetCount_ = structure.traceableOffsetCount();
94 memcpy(const_cast<unsigned *>(map->traceOffsets()), structure.offsets(), sizeof(unsigned) * structure.traceableOffsetCount());