diff -r 0998a43cc155 -r ca99a81745fe src/API.cpp --- a/src/API.cpp Sat Dec 29 00:55:38 2012 -0800 +++ b/src/API.cpp Tue Jan 01 15:34:07 2013 -0800 @@ -28,6 +28,7 @@ #include "Interpreter.h" #include "Stack.h" #include "Strings.h" +#include "Packages.h" #include "NativeTable.h" #include "Spaces-inl.h" #include "Heap-inl.h" @@ -76,32 +77,35 @@ template static inline To * Open(Ke::Handle from) { + if (!from) + return NULL; return *reinterpret_cast(*from); } template static inline To * Open(From *from) { + if (!from) + return NULL; return *reinterpret_cast(from); } template static inline Ke::Local ToLocal(From *from) { + if (!from) + return Ke::Local(); return Ke::Local(reinterpret_cast(Ke::HandleScope::CreateHandle(from))); } bool -InternalCompile(const char *path) +InternalCompile(ke::Handle package, const char *name) { PoolScope poolScope(ZONE()->pool()); RootScope roots(ZONE()); - CompileContext cc(ZONE(), path); + CompileContext cc(ZONE(), name); - TranslationUnit *unit = new TranslationUnit(); - unit->path_ = path; - - if (!cc.addTranslationUnit(unit)) + if (!cc.initialize(package, name)) return false; if (!cc.compile()) @@ -113,9 +117,10 @@ // This is split out from InternalCompile so the RootScope doesn't conflict // with making a return handle. bool -Ke::Compile(const char *path) +Ke::Keima::Compile(Handle argPackage, const char *name) { - return InternalCompile(path); + ke::Local package(ke::ZONE(), Open(argPackage)); + return InternalCompile(package, name); } void @@ -186,12 +191,14 @@ ZONE()->globalRoots()->destroy(FromAPI(root)); } +#if 0 bool -Ke::Keima::IsInCallStack(Handle argModule) +Ke::Keima::IsInCallStack(Handle package) { ke::Local module(ke::ZONE(), Open(argModule)); return ZONE()->stack().isInCallStack(module); } +#endif void Ke::Keima::CollectGarbage() @@ -206,10 +213,10 @@ } void -Ke::Module::setNativeIdentity(void *identity) +Ke::Package::setNativeIdentity(void *identity) { - ke::Local module(ke::ZONE(), Open(this)); - module->setNativeIdentity(identity); + ke::Local package(ke::ZONE(), Open(this)); + package->setNativeIdentity(identity); } unsigned @@ -233,6 +240,18 @@ return ToLocal(fun->name()); } +Ke::Local +Ke::Package::New(Handle argParent, + Handle argName, + const char *path, + unsigned flags) +{ + ke::Local parent(ke::ZONE(), Open(argParent)); + ke::Local name(ke::ZONE(), Open(argName)); + ke::Local package(ke::ZONE(), ke::Package::New(ke::ZONE(), parent, path, name, flags)); + return ToLocal(package); +} + static inline const char * GetInvokeTypeName(Ke::Parameter::Type type) {