Skip to content

Commit

Permalink
Merge branch 'no-boost'
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed Dec 23, 2013
2 parents 3c1b32a + bd6028b commit 3203d4a
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 105 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -92,7 +92,7 @@ SET(TORA_SRCS
tora/object/env.cc tora/object/regexp.cc tora/value/code.cc
)

set(libs re2 pthread dl icudata icuuc boost_system)
set(libs re2 pthread dl icudata icuuc)

# libtora.a
ADD_LIBRARY(libtora_a ${TORA_SRCS})
Expand Down
9 changes: 3 additions & 6 deletions tora/compiler.cc
Expand Up @@ -7,9 +7,6 @@
#include "value/regexp.h"
#include "symbol_table.h"
#include "disasm.h"
#include <boost/scope_exit.hpp>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

using namespace tora;
Expand Down Expand Up @@ -953,7 +950,7 @@ void tora::Compiler::compile(const SharedPtr<Node> &node) {
int label2 = ops->size();
jump_if_false->operand.int_value = label2;

BOOST_FOREACH(auto n, last_labels) {
for (auto n: last_labels) {
*n = label2 - 1;
}
last_labels.clear();
Expand Down Expand Up @@ -1208,7 +1205,7 @@ void tora::Compiler::compile(const SharedPtr<Node> &node) {
enter->operand.int_value = this->blocks->back().vars.size();
this->pop_block();

BOOST_FOREACH(auto n, last_labels) {
for (auto n: last_labels) {
*n = label2;
}
last_labels.clear();
Expand Down Expand Up @@ -1282,7 +1279,7 @@ void tora::Compiler::compile(const SharedPtr<Node> &node) {

push_op(new OP(OP_LEAVE));

BOOST_FOREACH(auto n, last_labels) {
for (auto n: last_labels) {
*n = label2;
}
last_labels.clear();
Expand Down
1 change: 1 addition & 0 deletions tora/compiler.h
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <string>
#include <memory>
#include "value/bytes.h"

namespace tora {

Expand Down
2 changes: 1 addition & 1 deletion tora/disasm.cc
Expand Up @@ -36,7 +36,7 @@ void Disasm::disasm(const SharedPtr<OPArray>& ops) {
printf("-- OP DUMP --\n");
for (size_t i=0; i<ops->size(); i++) {
const OP* op = ops->at(i);
printf("[%03d] %s", i, opcode2name[op->op_type]);
printf("[%03zu] %s", i, opcode2name[op->op_type]);
switch (op->op_type) {
case OP_GETDYNAMIC: {
int level = (op->operand.int_value >> 16) & 0x0000FFFF;
Expand Down
4 changes: 0 additions & 4 deletions tora/frame.cc
Expand Up @@ -86,7 +86,3 @@ void LexicalVarsFrame::dump_pad(VM *vm) {
pad_list->dump(vm);
}

#ifdef ENABLE_OBJECT_POOL
boost::object_pool<FunctionFrame> FunctionFrame::pool_;
#endif

13 changes: 0 additions & 13 deletions tora/frame.h
Expand Up @@ -3,12 +3,6 @@

#include <vector>

#ifdef ENABLE_OBJECT_POOL
#include <boost/pool/object_pool.hpp>
#endif

#include <boost/shared_ptr.hpp>

#include "shared_ptr.h"
#include "inspector.h"
#include "value.h"
Expand Down Expand Up @@ -100,13 +94,6 @@ class FunctionFrame : public LexicalVarsFrame {
this->type = FRAME_TYPE_FUNCTION;
}
FunctionFrame(VM *vm, int vars_cnt, size_t top, const SharedPtr<Value>& self_) : LexicalVarsFrame(vm, vars_cnt, top), self(self_) { }
#ifdef ENABLE_OBJECT_POOL
public:
void* operator new(size_t size) { return pool_.malloc(); }
void operator delete(void* doomed, size_t) { pool_.free((FunctionFrame*)doomed); }
private:
static boost::object_pool<FunctionFrame> pool_;
#endif
};

class ForeachFrame : public LexicalVarsFrame {
Expand Down
3 changes: 1 addition & 2 deletions tora/inspector.cc
Expand Up @@ -6,8 +6,7 @@
#include "value/range.h"
#include "value/object.h"
#include "value/regexp.h"

#include <boost/format.hpp>
#include "value/bytes.h"

using namespace tora;

Expand Down
2 changes: 0 additions & 2 deletions tora/lexer.h
Expand Up @@ -10,8 +10,6 @@
#include <fstream>
#include <queue>

#include <boost/shared_ptr.hpp>

#include "node.h"
#include "prim.h"

Expand Down
4 changes: 2 additions & 2 deletions tora/object.h
Expand Up @@ -3,7 +3,7 @@

#include "shared_ptr.h"
#include <vector>
#include <boost/shared_array.hpp>
#include <memory>
#include <re2/re2.h>

namespace tora {
Expand Down Expand Up @@ -40,7 +40,7 @@ void Init_FilePackage(VM *vm);
SharedPtr<Value> Symbol_bless(VM * vm, Value* self, Value *data);
ObjectValue* Dir_new(VM *vm, StrValue *dirname);
SharedPtr<Value> File_open(VM *vm, Value *fname, Value *mode);
SharedPtr<Value> RE2_Regexp_Matched_new(VM *vm, RE2RegexpValue* re, const boost::shared_array<re2::StringPiece> & matches);
SharedPtr<Value> RE2_Regexp_Matched_new(VM *vm, RE2RegexpValue* re, const std::shared_ptr<std::vector<re2::StringPiece>> & matches);

void load_builtin_objects(VM *vm);

Expand Down
18 changes: 9 additions & 9 deletions tora/object/re2_regexp_matched.cc
Expand Up @@ -21,14 +21,14 @@ using namespace tora;
class RE2RegexpMatched {
private:
SharedPtr<RE2RegexpValue> re_;
boost::shared_array<re2::StringPiece> matches_;
std::shared_ptr<std::vector<re2::StringPiece>> matches_;
public:
RE2RegexpMatched(RE2RegexpValue* re, const boost::shared_array<re2::StringPiece> & matches) : re_(re), matches_(matches) {
RE2RegexpMatched(RE2RegexpValue* re, const std::shared_ptr<std::vector<re2::StringPiece>> & matches) : re_(re), matches_(matches) {
}
const SharedPtr<RE2RegexpValue>& re() const {
return re_;
}
boost::shared_array<re2::StringPiece> matches() const {
const std::shared_ptr<std::vector<re2::StringPiece>>& matches() const {
return matches_;
}
};
Expand Down Expand Up @@ -56,8 +56,8 @@ static SharedPtr<Value> RE2_Regexp_Matched_to_array(VM * vm, Value* self) {
SharedPtr<ArrayValue> ary = new ArrayValue();
const SharedPtr<RE2RegexpValue>& re = SELF(self)->re();
for (int i=0; i<re->number_of_capturing_groups(); i++) {
re2::StringPiece* res = &(SELF(self)->matches()[i]);
ary->push_back(new StrValue(std::string(res->data(), res->length())));
const re2::StringPiece& res = SELF(self)->matches()->at(i);
ary->push_back(new StrValue(std::string(res.data(), res.length())));
}
return ary;
}
Expand All @@ -76,9 +76,9 @@ static SharedPtr<Value> RE2_Regexp_Matched_getitem(VM * vm, Value* self, Value *
if (index->to_int() > re->number_of_capturing_groups()) {
return UndefValue::instance();
}
re2::StringPiece* res = &(SELF(self)->matches()[index->to_int()]);
if(res->data()) {
return new StrValue(std::string(res->data(), res->length()));
const re2::StringPiece& res = SELF(self)->matches()->at(index->to_int());
if(res.data()) {
return new StrValue(std::string(res.data(), res.length()));
} else {
return UndefValue::instance();
}
Expand All @@ -95,7 +95,7 @@ static SharedPtr<Value> RE2_Regexp_Matched_DESTROY(VM * vm, Value* self) {
return UndefValue::instance();
}

SharedPtr<Value> tora::RE2_Regexp_Matched_new(VM *vm, RE2RegexpValue* re, const boost::shared_array<re2::StringPiece> & matches) {
SharedPtr<Value> tora::RE2_Regexp_Matched_new(VM *vm, RE2RegexpValue* re, const std::shared_ptr<std::vector<re2::StringPiece>> & matches) {
return new ObjectValue(vm, vm->get_builtin_class(SYMBOL_RE2_REGEXP_MATCHED_CLASS).get(), new PointerValue(new RE2RegexpMatched(re, matches)));
}

Expand Down
1 change: 1 addition & 0 deletions tora/object/str.cc
Expand Up @@ -4,6 +4,7 @@
#include "../shared_ptr.h"
#include "../value/regexp.h"
#include "../value/class.h"
#include "../value/bytes.h"
#include "../symbols.gen.h"
#include <re2/re2.h>
#include <unicode/unistr.h>
Expand Down
1 change: 1 addition & 0 deletions tora/operator.cc
Expand Up @@ -4,6 +4,7 @@
#include "value/object.h"
#include "value/array.h"
#include "ops.gen.h"
#include "value/bytes.h"
#include <math.h>

using namespace tora;
Expand Down
1 change: 1 addition & 0 deletions tora/value.cc
Expand Up @@ -6,6 +6,7 @@
#include "value/double.h"
#include "value/object.h"
#include "value/symbol.h"
#include "value/bytes.h"
#include "symbols.gen.h"
#include "peek.h"
#include <stdarg.h>
Expand Down
11 changes: 3 additions & 8 deletions tora/value.h
@@ -1,5 +1,5 @@
#ifndef VALUE_H_
#define VALUE_H_
#ifndef TORA_VALUE_H_
#define TORA_VALUE_H_

#include <sstream>
#include <cstdlib>
Expand All @@ -13,9 +13,6 @@

#include "tora.h"
#include "shared_ptr.h"
#include "prim.h"
#include "util.h"
#include "op_array.h"
#include "exception.h"

namespace tora {
Expand Down Expand Up @@ -57,7 +54,6 @@ class ClassImpl;
class FilePackageImpl;

class CallbackFunction;
class OPArray;

class RangeImpl {
friend class RangeValue;
Expand Down Expand Up @@ -156,10 +152,9 @@ class Value {

#include "value/undef.h"
#include "value/str.h"
#include "value/bytes.h"
#include "value/bool.h"
#include "value/int.h"
#include "value/double.h"
#include "value/exception.h"

#endif // VALUE_H_
#endif // TORA_VALUE_H_
5 changes: 0 additions & 5 deletions tora/value/bool.cc
Expand Up @@ -2,9 +2,4 @@

using namespace tora;

#ifdef ENABLE_OBJECT_POOL

boost::object_pool<BoolValue> BoolValue::pool_;

#endif

11 changes: 0 additions & 11 deletions tora/value/bool.h
Expand Up @@ -3,10 +3,6 @@

#include "../value.h"

#ifdef ENABLE_OBJECT_POOL
#include <boost/pool/object_pool.hpp>
#endif

namespace tora {

class BoolValue: public Value {
Expand All @@ -24,13 +20,6 @@ class BoolValue: public Value {
return b ? BoolValue::true_instance() : BoolValue::false_instance();
}
bool bool_value() const { return this->bool_value_; }
#ifdef ENABLE_OBJECT_POOL
public:
void* operator new(size_t size) { return pool_.malloc(); }
void operator delete(void* doomed, size_t) { pool_.free((BoolValue*)doomed); }
private:
static boost::object_pool<BoolValue> pool_;
#endif
};

};
Expand Down
4 changes: 2 additions & 2 deletions tora/value/file_package.h
Expand Up @@ -8,14 +8,14 @@ namespace tora {
class FilePackageImpl {
public:
ID name_id_;
boost::shared_ptr<std::map<ID, SharedPtr<tora::Value>>> data_;
std::shared_ptr<std::map<ID, SharedPtr<tora::Value>>> data_;
};

class FilePackageValue : public tora::Value {
public:
typedef std::map<ID, SharedPtr<tora::Value>>::const_iterator const_iterator;

FilePackageValue(ID name_id, const boost::shared_ptr<std::map<ID, SharedPtr<tora::Value>>> & src) : tora::Value(VALUE_TYPE_FILE_PACKAGE) {
FilePackageValue(ID name_id, const std::shared_ptr<std::map<ID, SharedPtr<tora::Value>>> & src) : tora::Value(VALUE_TYPE_FILE_PACKAGE) {
this->file_package_value_ = new FilePackageImpl();
this->file_package_value_->name_id_ = name_id;
this->file_package_value_->data_ = src;
Expand Down
3 changes: 0 additions & 3 deletions tora/value/int.cc
Expand Up @@ -2,6 +2,3 @@

using namespace tora;

#ifdef ENABLE_OBJECT_POOL
boost::object_pool<IntValue> IntValue::pool_;
#endif
11 changes: 0 additions & 11 deletions tora/value/int.h
Expand Up @@ -3,10 +3,6 @@

#include "../value.h"

#ifdef ENABLE_OBJECT_POOL
#include <boost/pool/object_pool.hpp>
#endif

namespace tora {

class IntValue: public Value {
Expand Down Expand Up @@ -39,13 +35,6 @@ class IntValue: public Value {
void int_value(int n) {
VAL() = n;
}
#ifdef ENABLE_OBJECT_POOL
public:
void* operator new(size_t size) { return pool_.malloc(); }
void operator delete(void* doomed, size_t) { pool_.free((IntValue*)doomed); }
private:
static boost::object_pool<IntValue> pool_;
#endif
};

};
Expand Down
14 changes: 6 additions & 8 deletions tora/value/regexp.cc
@@ -1,8 +1,6 @@
#include "regexp.h"
#include "array.h"
#include "../object.h"
#include <boost/shared_array.hpp>
#include <boost/scoped_array.hpp>

using namespace tora;

Expand Down Expand Up @@ -30,10 +28,10 @@ RE2RegexpValue::~RE2RegexpValue() {
}

SharedPtr<Value> RE2RegexpValue::match(VM *vm, const std::string &str) {
boost::shared_array<re2::StringPiece> res(new re2::StringPiece[VAL()->NumberOfCapturingGroups() + 1]);
std::shared_ptr<std::vector<re2::StringPiece>> res(new std::vector<re2::StringPiece>(VAL()->NumberOfCapturingGroups() + 1));

if (VAL()->Match(
str, 0, str.size(), RE2::UNANCHORED, res.get(), VAL()->NumberOfCapturingGroups()+1
str, 0, str.size(), RE2::UNANCHORED, res->data(), VAL()->NumberOfCapturingGroups()+1
)) {
return tora::RE2_Regexp_Matched_new(vm, this, res);
} else {
Expand All @@ -42,10 +40,10 @@ SharedPtr<Value> RE2RegexpValue::match(VM *vm, const std::string &str) {
}

bool RE2RegexpValue::match_bool(VM *vm, const std::string &str) {
boost::shared_array<re2::StringPiece> res(new re2::StringPiece[VAL()->NumberOfCapturingGroups() + 1]);
std::vector<re2::StringPiece> res(VAL()->NumberOfCapturingGroups() + 1);

if (VAL()->Match(
str, 0, str.size(), RE2::UNANCHORED, res.get(), VAL()->NumberOfCapturingGroups()+1
str, 0, str.size(), RE2::UNANCHORED, res.data(), VAL()->NumberOfCapturingGroups()+1
)) {
return true;
} else {
Expand All @@ -54,13 +52,13 @@ bool RE2RegexpValue::match_bool(VM *vm, const std::string &str) {
}

SharedPtr<Value> RE2RegexpValue::scan(VM *vm, const std::string &str) {
boost::scoped_array<re2::StringPiece> buf(new re2::StringPiece[VAL()->NumberOfCapturingGroups() + 1]);
std::vector<re2::StringPiece> buf(VAL()->NumberOfCapturingGroups() + 1);

int start = 0;
int end = str.size();
SharedPtr<ArrayValue> res = new ArrayValue();

while (VAL()->Match(str, start, end, RE2::UNANCHORED, buf.get(), VAL()->NumberOfCapturingGroups()+1)) {
while (VAL()->Match(str, start, end, RE2::UNANCHORED, buf.data(), VAL()->NumberOfCapturingGroups()+1)) {
if (VAL()->NumberOfCapturingGroups() != 0) {
SharedPtr<ArrayValue> av = new ArrayValue();
for (int i=1; i< VAL()->NumberOfCapturingGroups()+1; i++) {
Expand Down

0 comments on commit 3203d4a

Please sign in to comment.