mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-21 17:12:50 -06:00
now we can load PGF files as precompiled modules
This commit is contained in:
@@ -107,6 +107,7 @@ public:
|
||||
PGF_INTERNAL_DECL static txn_t get_txn_id();
|
||||
|
||||
PGF_INTERNAL_DECL const char *get_file_path() { return filepath; };
|
||||
PGF_INTERNAL_DECL void set_file_path(const char *filepath) { this->filepath = strdup(filepath); };
|
||||
|
||||
template<class A>
|
||||
static ref<A> malloc(size_t extra_bytes=0) {
|
||||
|
||||
@@ -58,6 +58,7 @@ PgfDB *pgf_read_pgf(const char* fpath, PgfRevision *revision,
|
||||
size_t pgf_size = ftell(in);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
db = new PgfDB(NULL, 0, 0, pgf_size*7);
|
||||
db->set_file_path(fpath);
|
||||
|
||||
{
|
||||
DB_scope scope(db, WRITER_SCOPE);
|
||||
|
||||
@@ -19,6 +19,7 @@ module PGF2 (-- * PGF
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
writePGF_,
|
||||
#endif
|
||||
pgfFilePath,
|
||||
|
||||
-- * Abstract syntax
|
||||
AbsName,abstractName,globalFlag,abstractFlag,
|
||||
@@ -278,6 +279,9 @@ cookie_write cookie buf size = do
|
||||
fmap fromIntegral $ (callback :: Ptr Word8 -> Int -> IO Int) buf (fromIntegral size)
|
||||
#endif
|
||||
|
||||
pgfFilePath :: PGF -> FilePath
|
||||
pgfFilePath p = unsafePerformIO (pgf_file_path (a_db p) >>= peekCString)
|
||||
|
||||
showPGF :: PGF -> String
|
||||
showPGF p =
|
||||
render (text "abstract" <+> ppAbstractName p <+> char '{' $$
|
||||
|
||||
@@ -93,6 +93,8 @@ foreign import ccall pgf_write_pgf_cookie :: Ptr () -> FunPtr (Ptr () -> Ptr Wor
|
||||
foreign import ccall pgf_write_pgf_cookie :: Ptr () -> FunPtr (Ptr () -> Ptr Word8 -> CInt -> IO CInt) -> Ptr PgfDB -> Ptr PGF -> Ptr (Ptr PgfText) -> Ptr PgfExn -> IO ()
|
||||
#endif
|
||||
|
||||
foreign import ccall pgf_file_path :: Ptr PgfDB -> IO CString
|
||||
|
||||
foreign import ccall "pgf_free_revision" pgf_free_revision_ :: Ptr PgfDB -> Ptr PGF -> IO ()
|
||||
|
||||
foreign import ccall "&pgf_free_revision" pgf_free_revision :: FinalizerEnvPtr PgfDB PGF
|
||||
|
||||
@@ -1285,11 +1285,7 @@ PGF_embed(PGFObject* self, PyObject *modname)
|
||||
py_embedding->grammar = self; Py_INCREF(self);
|
||||
|
||||
const char *fpath = pgf_file_path(self->db);
|
||||
if (fpath == NULL) {
|
||||
py_embedding->grammar_path = Py_None; Py_INCREF(Py_None);
|
||||
} else {
|
||||
py_embedding->grammar_path = PyUnicode_FromString(fpath);
|
||||
}
|
||||
py_embedding->grammar_path = PyUnicode_FromString(fpath);
|
||||
|
||||
if (module == NULL) {
|
||||
py_embedding->package_path = PyList_New(0);
|
||||
|
||||
Reference in New Issue
Block a user