本文整理汇总了C++中gc类的典型用法代码示例。如果您正苦于以下问题:C++ gc类的具体用法?C++ gc怎么用?C++ gc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了gc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compiler
void Compiler::compileModule(VM& vm, ErrorReporter& reporter,
gc<ModuleAst> ast, Module* module)
{
Compiler compiler(vm, reporter);
for (int i = 0; i < ast->body()->expressions().count(); i++)
{
compiler.declareTopLevel(ast->body()->expressions()[i], module);
}
gc<Chunk> code = ExprCompiler(compiler).compileBody(module, ast->body());
module->setBody(code);
}
示例2: dir
gc<String> dir(gc<String> path)
{
// Find the last directory separator.
int lastSeparator;
for (lastSeparator = path->length() - 1; lastSeparator >= 0;
lastSeparator--)
{
if ((*path)[lastSeparator] == separator()) break;
}
// If there are no directory separators, just return the original path.
if (lastSeparator == -1) return path;
return path->substring(0, lastSeparator);
}
示例3: compileParamField
void ExprCompiler::compileParamField(PatternCompiler& compiler,
gc<Pattern> param, int slot)
{
VariablePattern* variable = param->asVariablePattern();
if (variable != NULL)
{
// It's a variable, so compile its inner pattern. We don't worry about
// the variable itself because the calling convention ensures its value
// is already in the right slot.
compiler.compile(variable->pattern(), slot);
// If we closed over the parameter, then we don't want in a local slot,
// we want it in the upvar, so create it and copy the value up.
if (*variable->name() != "_" &&
variable->resolved()->scope() == NAME_CLOSURE)
{
write(variable->pos(),
OP_SET_UPVAR, variable->resolved()->index(), slot, 1);
}
}
else
{
// Not a variable, so just compile it normally.
compiler.compile(param, slot);
}
}
示例4: sizeof
gc<FunctionObject> FunctionObject::create(gc<Chunk> chunk)
{
// Allocate enough memory for the object and its upvars.
void* mem = Memory::allocate(sizeof(FunctionObject) +
sizeof(gc<Upvar>) * (chunk->numUpvars() - 1));
// Construct it by calling global placement new.
return ::new(mem) FunctionObject(chunk);
}
示例5: ASSERT
gc<DynamicObject> DynamicObject::create(gc<ClassObject> classObj)
{
ASSERT(classObj->numFields() == 0, "Class cannot have fields.");
// Allocate enough memory for the object.
void* mem = Memory::allocate(sizeof(DynamicObject));
// Construct it by calling global placement new.
return ::new(mem) DynamicObject(classObj);
}
示例6: destructureParam
void Resolver::destructureParam(gc<Pattern> pattern)
{
// No parameter so do nothing.
if (pattern.isNull()) return;
RecordPattern* record = pattern->asRecordPattern();
if (record != NULL)
{
// Resolve each field.
for (int i = 0; i < record->fields().count(); i++)
{
resolveParam(record->fields()[i].value);
}
}
else
{
// If we got here, the pattern isn't a record, so its a single slot.
resolveParam(pattern);
}
}
示例7: allocateSlotsForParam
void Resolver::allocateSlotsForParam(gc<Pattern> pattern)
{
// No parameter so do nothing.
if (pattern.isNull()) return;
RecordPattern* record = pattern->asRecordPattern();
if (record != NULL)
{
// Allocate each field.
for (int i = 0; i < record->fields().count(); i++)
{
makeParamSlot(record->fields()[i].value);
}
}
else
{
// If we got here, the pattern isn't a record, so it's a single slot.
makeParamSlot(pattern);
}
}
示例8: makeParamSlot
void Resolver::makeParamSlot(gc<Pattern> param)
{
VariablePattern* variable = param->asVariablePattern();
if (variable != NULL && *variable->name() != "_")
{
// It's a variable, so create a named local for it and resolve the
// variable.
variable->setResolved(makeLocal(param->pos(), variable->name()));
// Note that we do *not* resolve the variable's inner pattern here. We
// do that after all param slots are resolved so that we can ensure the
// param slots are contiguous.
}
else
{
// We don't have a variable for this parameter, but the argument
// will still be on the stack, so make an unnamed slot for it.
makeLocal(param->pos(), String::format("(%d)", unnamedSlotId_++));
}
}
示例9: open
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);
}
示例10: compileParam
void ExprCompiler::compileParam(PatternCompiler& compiler,
gc<Pattern> param, int& slot)
{
// No parameter so do nothing.
if (param.isNull()) return;
RecordPattern* record = param->asRecordPattern();
if (record != NULL)
{
// Compile each field.
for (int i = 0; i < record->fields().count(); i++)
{
compileParamField(compiler, record->fields()[i].value, slot++);
}
}
else
{
// If we got here, the pattern isn't a record, so it's a single slot.
compileParamField(compiler, param, slot++);
}
}
示例11: compileArg
int ExprCompiler::compileArg(gc<Expr> arg)
{
// No arg so do nothing.
if (arg.isNull()) return 0;
RecordExpr* record = arg->asRecordExpr();
if (record != NULL)
{
// Compile each field.
for (int i = 0; i < record->fields().count(); i++)
{
compile(record->fields()[i].value, makeTemp());
}
return record->fields().count();
}
// If we got here, the arg isn't a record, so its a single value.
compile(arg, makeTemp());
return 1;
}
示例12: send
void ChannelObject::send(gc<Fiber> sender, gc<Object> value)
{
// TODO(bob): What if the channel is closed?
// If we have a receiver, give it the value.
if (receivers_.count() > 0)
{
gc<Fiber> receiver = receivers_.removeAt(0);
receiver->storeReturn(value);
receiver->ready();
// Add the sender back to the scheduler too since it isn't blocked.
sender->ready();
return;
}
// Otherwise, stuff the value and suspend.
sender->waitToSend(value);
senders_.add(sender);
return;
}
示例13: declareTopLevel
void Compiler::declareTopLevel(gc<Expr> expr, Module* module)
{
DefExpr* def = expr->asDefExpr();
if (def != NULL)
{
declareMultimethod(SignatureBuilder::build(*def));
return;
}
DefClassExpr* defClass = expr->asDefClassExpr();
if (defClass != NULL)
{
declareClass(*defClass, module);
return;
}
VariableExpr* var = expr->asVariableExpr();
if (var != NULL)
{
declareVariables(var->pattern(), module);
return;
}
}
示例14: declareVariable
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>());
}
示例15: declareVariables
void Compiler::declareVariables(gc<Pattern> pattern, Module* module)
{
RecordPattern* record = pattern->asRecordPattern();
if (record != NULL)
{
for (int i = 0; i < record->fields().count(); i++)
{
declareVariables(record->fields()[i].value, module);
}
return;
}
VariablePattern* variable = pattern->asVariablePattern();
if (variable != NULL)
{
declareVariable(variable->pos(), variable->name(), module);
if (!variable->pattern().isNull())
{
declareVariables(variable->pattern(), module);
}
}
}