src/API.cpp
changeset 251 ca99a81745fe
parent 250 0998a43cc155
child 262 c4b1341297e5
     1.1 --- a/src/API.cpp	Sat Dec 29 00:55:38 2012 -0800
     1.2 +++ b/src/API.cpp	Tue Jan 01 15:34:07 2013 -0800
     1.3 @@ -28,6 +28,7 @@
     1.4  #include "Interpreter.h"
     1.5  #include "Stack.h"
     1.6  #include "Strings.h"
     1.7 +#include "Packages.h"
     1.8  #include "NativeTable.h"
     1.9  #include "Spaces-inl.h"
    1.10  #include "Heap-inl.h"
    1.11 @@ -76,32 +77,35 @@
    1.12  template <typename From, typename To> static inline To *
    1.13  Open(Ke::Handle<From> from)
    1.14  {
    1.15 +    if (!from)
    1.16 +        return NULL;
    1.17      return *reinterpret_cast<To **>(*from);
    1.18  }
    1.19  
    1.20  template <typename From, typename To> static inline To *
    1.21  Open(From *from)
    1.22  {
    1.23 +    if (!from)
    1.24 +        return NULL;
    1.25      return *reinterpret_cast<To **>(from);
    1.26  }
    1.27  
    1.28  template <typename From, typename To> static inline Ke::Local<To>
    1.29  ToLocal(From *from)
    1.30  {
    1.31 +    if (!from)
    1.32 +        return Ke::Local<To>();
    1.33      return Ke::Local<To>(reinterpret_cast<To *>(Ke::HandleScope::CreateHandle(from)));
    1.34  }
    1.35  
    1.36  bool
    1.37 -InternalCompile(const char *path)
    1.38 +InternalCompile(ke::Handle<ke::Package> package, const char *name)
    1.39  {
    1.40      PoolScope poolScope(ZONE()->pool());
    1.41      RootScope roots(ZONE());
    1.42 -    CompileContext cc(ZONE(), path);
    1.43 +    CompileContext cc(ZONE(), name);
    1.44  
    1.45 -    TranslationUnit *unit = new TranslationUnit();
    1.46 -    unit->path_ = path;
    1.47 -
    1.48 -    if (!cc.addTranslationUnit(unit))
    1.49 +    if (!cc.initialize(package, name))
    1.50          return false;
    1.51  
    1.52      if (!cc.compile())
    1.53 @@ -113,9 +117,10 @@
    1.54  // This is split out from InternalCompile so the RootScope doesn't conflict
    1.55  // with making a return handle.
    1.56  bool
    1.57 -Ke::Compile(const char *path)
    1.58 +Ke::Keima::Compile(Handle<Package> argPackage, const char *name)
    1.59  {
    1.60 -    return InternalCompile(path);
    1.61 +    ke::Local<ke::Package> package(ke::ZONE(), Open<Ke::Package, ke::Package>(argPackage));
    1.62 +    return InternalCompile(package, name);
    1.63  }
    1.64  
    1.65  void
    1.66 @@ -186,12 +191,14 @@
    1.67      ZONE()->globalRoots()->destroy(FromAPI(root));
    1.68  }
    1.69  
    1.70 +#if 0
    1.71  bool
    1.72 -Ke::Keima::IsInCallStack(Handle<Module> argModule)
    1.73 +Ke::Keima::IsInCallStack(Handle<Package> package)
    1.74  {
    1.75      ke::Local<ke::Module> module(ke::ZONE(), Open<Ke::Module, ke::Module>(argModule));
    1.76      return ZONE()->stack().isInCallStack(module);
    1.77  }
    1.78 +#endif
    1.79  
    1.80  void
    1.81  Ke::Keima::CollectGarbage()
    1.82 @@ -206,10 +213,10 @@
    1.83  }
    1.84  
    1.85  void
    1.86 -Ke::Module::setNativeIdentity(void *identity)
    1.87 +Ke::Package::setNativeIdentity(void *identity)
    1.88  {
    1.89 -    ke::Local<ke::Module> module(ke::ZONE(), Open<Ke::Module, ke::Module>(this));
    1.90 -    module->setNativeIdentity(identity);
    1.91 +    ke::Local<ke::Package> package(ke::ZONE(), Open<Ke::Package, ke::Package>(this));
    1.92 +    package->setNativeIdentity(identity);
    1.93  }
    1.94  
    1.95  unsigned
    1.96 @@ -233,6 +240,18 @@
    1.97      return ToLocal<ke::String, Ke::String>(fun->name());
    1.98  }
    1.99  
   1.100 +Ke::Local<Ke::Package>
   1.101 +Ke::Package::New(Handle<Package> argParent,
   1.102 +                 Handle<String> argName,
   1.103 +                 const char *path,
   1.104 +                 unsigned flags)
   1.105 +{
   1.106 +    ke::Local<ke::Package> parent(ke::ZONE(), Open<Ke::Package, ke::Package>(argParent));
   1.107 +    ke::Local<ke::String> name(ke::ZONE(), Open<Ke::String, ke::String>(argName));
   1.108 +    ke::Local<ke::Package> package(ke::ZONE(), ke::Package::New(ke::ZONE(), parent, path, name, flags));
   1.109 +    return ToLocal<ke::Package, Ke::Package>(package);
   1.110 +}
   1.111 +
   1.112  static inline const char *
   1.113  GetInvokeTypeName(Ke::Parameter::Type type)
   1.114  {