comparison truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java @ 22288:47172a9b40ac

Object model refactoring, add Shape#defineProperty
author Andreas Woess <andreas.woess@oracle.com>
date Wed, 07 Oct 2015 19:15:14 +0200
parents 396c1d17a11a
children ca426f243321
comparison
equal deleted inserted replaced
22287:479028cce974 22288:47172a9b40ac
281 } 281 }
282 282
283 @Override 283 @Override
284 @TruffleBoundary 284 @TruffleBoundary
285 public void define(Object id, Object value, int flags) { 285 public void define(Object id, Object value, int flags) {
286 ShapeImpl oldShape = getShape(); 286 define(id, value, flags, ShapeImpl.DEFAULT_LAYOUT_FACTORY);
287 Property existing = oldShape.getProperty(id);
288 if (existing == null) {
289 updateShape();
290 oldShape = getShape();
291 Shape newShape = oldShape.addProperty(Property.create(id, oldShape.allocator().locationForValue(value, true, value != null), flags));
292 updateShape();
293 newShape.getLastProperty().setGeneric(this, value, oldShape, newShape);
294 } else {
295 defineExisting(id, value, flags, existing, oldShape);
296 }
297 }
298
299 private void defineExisting(Object id, Object value, int flags, Property existing, ShapeImpl oldShape) {
300 if (existing.getFlags() == flags) {
301 existing.setGeneric(this, value, null);
302 } else {
303 Property newProperty = Property.create(id, oldShape.getLayout().existingLocationForValue(value, existing.getLocation(), oldShape), flags);
304 Shape newShape = oldShape.replaceProperty(existing, newProperty);
305 this.setShapeAndResize(newShape);
306 newProperty.setInternal(this, value);
307 }
308 } 287 }
309 288
310 @Override 289 @Override
311 @TruffleBoundary 290 @TruffleBoundary
312 public void define(Object id, Object value, int flags, LocationFactory locationFactory) { 291 public void define(Object id, Object value, int flags, LocationFactory locationFactory) {
313 ShapeImpl oldShape = getShape(); 292 ShapeImpl oldShape = getShape();
314 Property existing = oldShape.getProperty(id); 293 ShapeImpl newShape = oldShape.defineProperty(id, value, flags, locationFactory);
315 if (existing == null) { 294 updateShape();
316 updateShape(); 295 Property property = newShape.getProperty(id);
317 oldShape = getShape(); 296
318 Shape newShape = oldShape.addProperty(Property.create(id, locationFactory.createLocation(oldShape, value), flags)); 297 if (oldShape == newShape) {
319 updateShape(); 298 property.setSafe(this, value, oldShape);
320 newShape.getLastProperty().setGeneric(this, value, oldShape, newShape); 299 } else {
321 } else { 300 property.setSafe(this, value, oldShape, newShape);
322 defineExisting(id, value, flags, existing, oldShape);
323 } 301 }
324 } 302 }
325 303
326 @Override 304 @Override
327 @TruffleBoundary 305 @TruffleBoundary