# HG changeset patch # User David Anderson # Date 1341301008 25200 # Node ID 95baf120f7d41b505e0abe5897272e967f9dc1b2 # Parent af1ed58252ac56af5812168afac44c4188d86fa4 Handle-ize BytecodeEmitter. diff -r af1ed58252ac -r 95baf120f7d4 jitcraft/BytecodeCompiler.cpp --- a/jitcraft/BytecodeCompiler.cpp Tue Jul 03 00:32:19 2012 -0700 +++ b/jitcraft/BytecodeCompiler.cpp Tue Jul 03 00:36:48 2012 -0700 @@ -702,7 +702,7 @@ return NULL; for (size_t i = 0; i < __ objects()->size(); i++) - objects->set(zone_, i, __ objects()->at(i)); + objects->set(zone_, i, *(__ objects()->at(i))); Local code(zone_, Code::New(zone_, bytes, locals_, objects, __ maxStackDepth(), module_)); if (!code) diff -r af1ed58252ac -r 95baf120f7d4 jitcraft/BytecodeEmitter.h --- a/jitcraft/BytecodeEmitter.h Tue Jul 03 00:32:19 2012 -0700 +++ b/jitcraft/BytecodeEmitter.h Tue Jul 03 00:36:48 2012 -0700 @@ -1,4 +1,5 @@ -/* +/* vim: set ts=4 sw=4 tw=99 et: + * * Copyright (C) 2012 David Anderson * * This file is part of JITCraft. @@ -23,12 +24,15 @@ #include #include "Opcodes.h" #include "NameBinding.h" +#include "Handles.h" namespace jc { class Type; class Map; +typedef std::vector *> ObjectList; + class BytecodeEmitter { bytecode *buffer_; @@ -38,7 +42,7 @@ bool oom_; unsigned maxStackDepth_; unsigned stackDepth_; - std::vector objects_; + ObjectList objects_; private: static const size_t MAX_LENGTH = INT_MAX / 2; @@ -80,7 +84,10 @@ } void writeObject(Object *obj) { writeUint32(objects_.size()); - objects_.push_back(obj); + ScopedRoot *root = new ScopedRoot(obj); + if (!root) + oom_ = true; + objects_.push_back(root); } int position() const { @@ -106,7 +113,7 @@ unsigned maxStackDepth() const { return maxStackDepth_; } - const std::vector *objects() const { + const ObjectList *objects() const { return &objects_; } @@ -310,7 +317,7 @@ void cvt_i2f() { singleByteOp(OP_CVT_I2F); } - void newarray_lifo(Map *map) { + void newarray_lifo(Handle map) { ensure(OP_NEWARRAY_LIFO_LENGTH); writeOp(OP_NEWARRAY_LIFO); writeObject(map); @@ -375,7 +382,7 @@ singleByteOp(OP_SETREF_F); } } - void object(Object *obj) { + void object(Handle obj) { ensure(OP_OBJECT_LENGTH); writeOp(OP_OBJECT); writeObject(obj);