jitcraft/BytecodeCompiler.cpp
changeset 26 a48382113da6
parent 23 8a31742781c1
child 27 28697d267222
     1.1 --- a/jitcraft/BytecodeCompiler.cpp	Mon Jul 02 01:24:57 2012 -0700
     1.2 +++ b/jitcraft/BytecodeCompiler.cpp	Mon Jul 02 01:52:57 2012 -0700
     1.3 @@ -655,10 +655,12 @@
     1.4  BytecodeCompiler::visit(FunctionStatement *node)
     1.5  {
     1.6      BytecodeCompiler child(tree_, module_);
     1.7 -    Code *code = child.compileFunction(module_, node);
     1.8 +    Function *fun = child.compileFunction(module_, node);
     1.9 +    if (!fun)
    1.10 +        return;
    1.11      
    1.12      assert(!module_->getFunction(node->fun()->slot()));
    1.13 -    module_->setFunction(ZONE(), node->fun()->slot(), code);
    1.14 +    module_->setFunction(ZONE(), node->fun()->slot(), fun);
    1.15  }
    1.16  
    1.17  void
    1.18 @@ -667,7 +669,7 @@
    1.19      // :TODO: eventually, we'll export these.
    1.20  }
    1.21  
    1.22 -Code *
    1.23 +Function *
    1.24  BytecodeCompiler::compileFunction(Module *module, FunctionStatement *node)
    1.25  {
    1.26      // Note: No need to record a life slot here, since it's part of the Frame.
    1.27 @@ -706,8 +708,15 @@
    1.28      for (size_t i = 0; i < __ objects()->size(); i++)
    1.29          objects->set(ZONE(), i, __ objects()->at(i));
    1.30  
    1.31 -    Code *code = Code::New(ZONE(), bytes, locals_, args, objects, __ maxStackDepth(), module_);
    1.32 -    return code;
    1.33 +    Code *code = Code::New(ZONE(), bytes, locals_, objects, __ maxStackDepth(), module_);
    1.34 +    if (!code)
    1.35 +        return NULL;
    1.36 +
    1.37 +    Function *fun = Function::New(ZONE(), module_, code, node->fun()->type(), node->pos());
    1.38 +    if (!fun)
    1.39 +        return NULL;
    1.40 +    
    1.41 +    return fun;
    1.42  }
    1.43  
    1.44  Module *