示例#1
0
 void Fiber::Info::mark(Object* obj, memory::ObjectMark& mark) {
   auto_mark(obj, mark);
   Fiber* fib = force_as<Fiber>(obj);
   FiberData* data = fib->data();
   if(!data || data->dead_p()) return;
   data->set_mark();
 }
示例#2
0
  void VariableScope::Info::mark(Object* obj, ObjectMark& mark) {
    auto_mark(obj, mark);

    VariableScope* vs = as<VariableScope>(obj);

    vs->fixup();

    if(!vs->isolated()) {
      Object** ary = vs->stack_locals();

      if(Fiber* fib = try_as<Fiber>(vs->fiber())) {
        FiberData* data = fib->data();

        AddressDisplacement dis(data->data_offset(),
                                data->data_lower_bound(),
                                data->data_upper_bound());

        ary = dis.displace(ary);
      }

      size_t locals = vs->number_of_locals();

      for(size_t i = 0; i < locals; i++) {
        Object* tmp = mark.call(ary[i]);
        if(tmp) { ary[i] = tmp; }
      }
    }
  }
示例#3
0
  void VariableScope::Info::visit(Object* obj, ObjectVisitor& visit) {
    auto_visit(obj, visit);

    VariableScope* vs = as<VariableScope>(obj);

    if(!vs->isolated()) {
      Object** ary = vs->stack_locals();

      if(Fiber* fib = try_as<Fiber>(vs->fiber())) {
        FiberData* data = fib->data();

        AddressDisplacement dis(data->data_offset(),
                                data->data_lower_bound(),
                                data->data_upper_bound());

        ary = dis.displace(ary);
      }

      size_t locals = vs->number_of_locals();

      for(size_t i = 0; i < locals; i++) {
        visit.call(ary[i]);
      }
    }
  }
FiberData* FiberReader::readTrkFile(const std::string& fileName) {
    cgtAssert(sizeof(trk_header) == 1000, "invalid trk header size!");
    trk_header header;
    FiberData* toReturn = nullptr;

    std::ifstream file(fileName, std::ios::in |std::ios::binary);
    if (!file) {
        LERROR("Failed to open file: " << fileName);
        return nullptr;
    }
    if (!file.read((char*)&header, sizeof(header))) {
        LERROR("Failed to read header! File: " << fileName);
        return nullptr;
    }

    toReturn = new FiberData();
    int32_t numPoints;

    //LINFO("n_scalars: " << header.n_scalars);
    //LINFO("n_properties: " << header.n_properties);
    float* scalars = new float[header.n_scalars];
    float* properties = new float[header.n_properties];

    while (file.read(reinterpret_cast<char*>(&numPoints), 4)) {
        std::vector<cgt::vec3> vertices;
        vertices.resize(numPoints, cgt::vec3(0.f));


        for (int32_t i=0; i<numPoints; ++i) {
            file.read(reinterpret_cast<char*>(vertices[i].elem), sizeof(cgt::vec3));

            vertices[i] *= p_scaling.getValue();
            vertices[i] += p_offset.getValue();

            file.read((char*)scalars, sizeof(float) * header.n_scalars);
            //if(header.n_scalars > 0)
            //    fibers_.uncertainties_.push_back(scalars[0]);
            //else
            //    fibers_.uncertainties_.push_back(0.0f);
        }

        toReturn->addFiber(vertices);
        file.read((char*) properties, sizeof(float) * header.n_properties);
    }

    delete[] scalars;
    delete[] properties;
    file.close();

    return toReturn;
}
示例#5
0
  Object* VariableScope::get_local(int pos) {
    Object** ary = locals_;
    if(Fiber* fib = try_as<Fiber>(fiber_)) {
      FiberData* data = fib->data();
      if(data) {
        AddressDisplacement dis(data->data_offset(),
                                data->data_lower_bound(),
                                data->data_upper_bound());

        ary = dis.displace(ary);
      }
    }
    return ary[pos];
  }
示例#6
0
  void FiberStacks::gc_scan(GarbageCollector* gc, bool marked_only) {
    for(Datas::iterator i = datas_.begin(); i != datas_.end(); ++i) {
      FiberData* data = *i;
      if(data->dead_p()) continue;
      if(marked_only && !data->marked_p()) {
        data->status_ = FiberData::eDead;
        continue;
      }

      AddressDisplacement dis(data->data_offset(),
                              data->data_lower_bound(),
                              data->data_upper_bound());

      if(CallFrame* cf = data->call_frame()) {
        gc->walk_call_frame(cf, &dis);
      }

      gc->scan(data->variable_root_buffers(), false, &dis);
    }
  }