Exemple #1
0
  void FileObject::open(gc<Fiber> fiber, gc<String> path)
  {
    FSTask* task = new FSTask(fiber);

    // TODO(bob): Make this configurable.
    int flags = O_RDONLY;
    // TODO(bob): Make this configurable when creating a file.
    int mode = 0;
    uv_fs_open(task->loop(), task->request(), path->cString(), flags, mode,
               openFileCallback);
  }
Exemple #2
0
  void Compiler::declareVariable(gc<SourcePos> pos, gc<String> name,
                                 Module* module)
  {
    // Make sure there isn't already a top-level variable with that name.
    int existing = module->findVariable(name);
    if (existing != -1)
    {
      reporter_.error(pos,
          "There is already a variable '%s' defined in this module.",
          name->cString());
    }

    module->addVariable(name, gc<Object>());
  }
Exemple #3
0
  gc<ResolvedName> Resolver::makeLocal(gc<SourcePos> pos, gc<String> name)
  {
    // Make sure there isn't already a local variable with this name in the
    // current scope.
    for (int i = scope_->startSlot(); i < locals_.count(); i++)
    {
      if (locals_[i].name() == name)
      {
        compiler_.reporter().error(pos,
            "There is already a variable '%s' defined in this scope.",
            name->cString());
      }
    }

    gc<ResolvedName> resolved = new ResolvedName(locals_.count());
    locals_.add(Local(name, resolved));
    if (locals_.count() > maxLocals_) {
      maxLocals_ = locals_.count();
    }
            
    return resolved;
  }
Exemple #4
0
  // Reads a file from the given path into a String.
  gc<String> readFile(gc<String> path)
  {
    // TODO(bob): Use platform-native API for this?
    using namespace std;

    ifstream stream(path->cString());

    if (stream.fail()) return gc<String>();

    // From: http://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring.
    string str;

    // Allocate a std::string big enough for the file.
    stream.seekg(0, ios::end);
    str.reserve(stream.tellg());
    stream.seekg(0, ios::beg);

    // Read it in.
    str.assign((istreambuf_iterator<char>(stream)),
               istreambuf_iterator<char>());

    return String::create(str.c_str());
  }
Exemple #5
0
 void SignatureBuilder::add(gc<String> text)
 {
   add(text->cString());
 }
Exemple #6
0
 gc<String> join(gc<String> a, gc<String> b)
 {
   // TODO(bob): Handle lots of edge cases better here.
   return String::format("%s%c%s", a->cString(), separator(), b->cString());
 }
Exemple #7
0
 bool fileExists(gc<String> path)
 {
   // If we can stat it, it exists.
   struct stat dummy;
   return stat(path->cString(), &dummy) == 0;
 }
Exemple #8
0
 gc<String> real(gc<String> path)
 {
   char absolute[PATH_MAX];
   realpath(path->cString(), absolute);
   return String::create(absolute);
 }