mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
a type annotated version of marshaller/unmarshaller
This commit is contained in:
@@ -37,7 +37,7 @@ struct PGF_INTERNAL_DECL PgfFlag {
|
||||
|
||||
// PgfPatt
|
||||
|
||||
typedef variant PgfPatt;
|
||||
typedef object PgfPatt;
|
||||
|
||||
struct PGF_INTERNAL_DECL PgfPattApp {
|
||||
static const uint8_t tag = 0;
|
||||
@@ -87,7 +87,7 @@ typedef struct {
|
||||
} PgfEquation;
|
||||
|
||||
struct PGF_INTERNAL_DECL PgfAbsFun {
|
||||
ref<PgfType> type;
|
||||
ref<PgfDTyp> type;
|
||||
int arity;
|
||||
ref<PgfVector<ref<PgfEquation>>> defns;
|
||||
PgfExprProb ep;
|
||||
|
||||
@@ -21,12 +21,12 @@ struct mchunk {
|
||||
size_t mchunk_prev_size; /* Size of previous chunk (if free). */
|
||||
size_t mchunk_size; /* Size in bytes, including overhead. */
|
||||
|
||||
moffset fd; /* double links -- used only if free. */
|
||||
moffset bk;
|
||||
object fd; /* double links -- used only if free. */
|
||||
object bk;
|
||||
|
||||
/* Only used for large blocks: pointer to next larger size. */
|
||||
moffset fd_nextsize; /* double links -- used only if free. */
|
||||
moffset bk_nextsize;
|
||||
object fd_nextsize; /* double links -- used only if free. */
|
||||
object bk_nextsize;
|
||||
};
|
||||
|
||||
#define POOL_ALIGNMENT (2 * sizeof(size_t) < __alignof__ (long double) \
|
||||
@@ -256,17 +256,17 @@ struct malloc_state
|
||||
/* Set if the fastbin chunks contain recently inserted free blocks. */
|
||||
bool have_fastchunks;
|
||||
/* Fastbins */
|
||||
moffset fastbins[NFASTBINS];
|
||||
object fastbins[NFASTBINS];
|
||||
/* Base of the topmost chunk -- not otherwise kept in a bin */
|
||||
moffset top;
|
||||
object top;
|
||||
/* The remainder from the most recent split of a small request */
|
||||
moffset last_remainder;
|
||||
object last_remainder;
|
||||
/* Normal bins packed as described above */
|
||||
moffset bins[NBINS * 2 - 2];
|
||||
object bins[NBINS * 2 - 2];
|
||||
/* Bitmap of bins */
|
||||
unsigned int binmap[BINMAPSIZE];
|
||||
/* Reference to the root object */
|
||||
moffset root_offset;
|
||||
object root_offset;
|
||||
};
|
||||
|
||||
DB::DB(const char* pathname, int flags, int mode) {
|
||||
@@ -338,11 +338,11 @@ void DB::sync()
|
||||
throw std::system_error(errno, std::generic_category());
|
||||
}
|
||||
|
||||
moffset DB::get_root_internal() {
|
||||
object DB::get_root_internal() {
|
||||
return ms->root_offset;
|
||||
}
|
||||
|
||||
void DB::set_root_internal(moffset root_offset) {
|
||||
void DB::set_root_internal(object root_offset) {
|
||||
ms->root_offset = root_offset;
|
||||
}
|
||||
|
||||
@@ -410,8 +410,8 @@ unlink_chunk (malloc_state* ms, mchunk* p)
|
||||
*/
|
||||
static void malloc_consolidate(malloc_state *ms)
|
||||
{
|
||||
moffset* fb; /* current fastbin being consolidated */
|
||||
moffset* maxfb; /* last fastbin (for loop control) */
|
||||
object* fb; /* current fastbin being consolidated */
|
||||
object* maxfb; /* last fastbin (for loop control) */
|
||||
mchunk* p; /* current chunk being consolidated */
|
||||
mchunk* nextp; /* next chunk to consolidate */
|
||||
mchunk* unsorted_bin; /* bin header */
|
||||
@@ -478,7 +478,7 @@ static void malloc_consolidate(malloc_state *ms)
|
||||
} while (fb++ != maxfb);
|
||||
}
|
||||
|
||||
moffset
|
||||
object
|
||||
DB::malloc_internal(size_t bytes)
|
||||
{
|
||||
unsigned int idx; /* associated bin index */
|
||||
@@ -520,7 +520,7 @@ DB::malloc_internal(size_t bytes)
|
||||
bin = bin_at (ms, idx);
|
||||
if ((victim = ptr(ms,last(bin))) != bin)
|
||||
{
|
||||
moffset bck = victim->bk;
|
||||
object bck = victim->bk;
|
||||
set_inuse_bit_at_offset (victim, nb);
|
||||
bin->bk = bck;
|
||||
ptr(ms,bck)->fd = ofs(ms,bin);
|
||||
@@ -852,10 +852,10 @@ DB::malloc_internal(size_t bytes)
|
||||
}
|
||||
|
||||
void
|
||||
DB::free_internal(moffset o)
|
||||
DB::free_internal(object o)
|
||||
{
|
||||
size_t size; /* its size */
|
||||
moffset *fb; /* associated fastbin */
|
||||
object *fb; /* associated fastbin */
|
||||
mchunk *nextchunk; /* next contiguous chunk */
|
||||
size_t nextsize; /* its size */
|
||||
int nextinuse; /* true if nextchunk is used */
|
||||
|
||||
@@ -8,28 +8,24 @@ class DB;
|
||||
extern PGF_INTERNAL_DECL __thread unsigned char* current_base __attribute__((tls_model("initial-exec")));
|
||||
extern PGF_INTERNAL_DECL __thread DB* current_db __attribute__((tls_model("initial-exec")));
|
||||
|
||||
typedef size_t moffset;
|
||||
|
||||
typedef moffset variant;
|
||||
|
||||
struct malloc_state;
|
||||
|
||||
template<class A> class PGF_INTERNAL_DECL ref {
|
||||
private:
|
||||
moffset offset;
|
||||
object offset;
|
||||
|
||||
friend class DB;
|
||||
|
||||
public:
|
||||
ref<A>() { }
|
||||
ref<A>(moffset o) { offset = o; }
|
||||
ref<A>(object o) { offset = o; }
|
||||
|
||||
A* operator->() const { return (A*) (current_base+offset); }
|
||||
operator A*() const { return (A*) (current_base+offset); }
|
||||
bool operator ==(ref<A>& other) const { return offset==other->offset; }
|
||||
bool operator !=(ref<A>& other) const { return offset!=other->offset; }
|
||||
bool operator ==(moffset other_offset) const { return offset==other_offset; }
|
||||
bool operator !=(moffset other_offset) const { return offset!=other_offset; }
|
||||
bool operator ==(object other_offset) const { return offset==other_offset; }
|
||||
bool operator !=(object other_offset) const { return offset!=other_offset; }
|
||||
|
||||
ref<A>& operator= (const ref<A>& r) {
|
||||
offset = r.offset;
|
||||
@@ -39,19 +35,21 @@ public:
|
||||
static
|
||||
ref<A> from_ptr(A *ptr) { return (((uint8_t*) ptr) - current_base); }
|
||||
|
||||
object as_object() { return offset; }
|
||||
|
||||
static
|
||||
variant tagged(ref<A> ref) {
|
||||
object tagged(ref<A> ref) {
|
||||
assert(A::tag < MALLOC_ALIGN_MASK + 1);
|
||||
return (ref.offset | A::tag);
|
||||
}
|
||||
|
||||
static
|
||||
ref<A> untagged(variant v) {
|
||||
ref<A> untagged(object v) {
|
||||
return (v & ~MALLOC_ALIGN_MASK);
|
||||
}
|
||||
|
||||
static
|
||||
uint8_t get_tag(variant v) {
|
||||
uint8_t get_tag(object v) {
|
||||
return (v & MALLOC_ALIGN_MASK);
|
||||
}
|
||||
};
|
||||
@@ -94,11 +92,11 @@ public:
|
||||
private:
|
||||
void init_state(size_t size);
|
||||
|
||||
moffset malloc_internal(size_t bytes);
|
||||
void free_internal(moffset o);
|
||||
object malloc_internal(size_t bytes);
|
||||
void free_internal(object o);
|
||||
|
||||
moffset get_root_internal();
|
||||
void set_root_internal(moffset root_offset);
|
||||
object get_root_internal();
|
||||
void set_root_internal(object root_offset);
|
||||
|
||||
unsigned char* relocate(unsigned char* ptr);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
PGF_INTERNAL
|
||||
PgfDBMarshaller db_marshaller;
|
||||
|
||||
uintptr_t PgfDBMarshaller::match_lit(PgfUnmarshaller *u, uintptr_t l)
|
||||
PgfLiteral PgfDBMarshaller::match_lit(PgfUnmarshaller *u, PgfLiteral l)
|
||||
{
|
||||
switch (ref<PgfLiteral>::get_tag(l)) {
|
||||
case PgfLiteralInt::tag: {
|
||||
@@ -20,29 +20,29 @@ uintptr_t PgfDBMarshaller::match_lit(PgfUnmarshaller *u, uintptr_t l)
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t PgfDBMarshaller::match_expr(PgfUnmarshaller *u, uintptr_t e)
|
||||
PgfExpr PgfDBMarshaller::match_expr(PgfUnmarshaller *u, PgfExpr e)
|
||||
{
|
||||
switch (ref<PgfExpr>::get_tag(e)) {
|
||||
case PgfExprAbs::tag: {
|
||||
auto eabs = ref<PgfExprAbs>::untagged(e);
|
||||
uintptr_t body = match_expr(u,eabs->body);
|
||||
uintptr_t res = u->eabs(eabs->bind_type,&eabs->name,body);
|
||||
PgfExpr body = match_expr(u,eabs->body);
|
||||
PgfExpr res = u->eabs(eabs->bind_type,&eabs->name,body);
|
||||
u->free_ref(body);
|
||||
return res;
|
||||
}
|
||||
case PgfExprApp::tag: {
|
||||
auto eapp = ref<PgfExprApp>::untagged(e);
|
||||
uintptr_t fun = match_expr(u,eapp->fun);
|
||||
uintptr_t arg = match_expr(u,eapp->arg);
|
||||
uintptr_t res = u->eapp(fun,arg);
|
||||
PgfExpr fun = match_expr(u,eapp->fun);
|
||||
PgfExpr arg = match_expr(u,eapp->arg);
|
||||
PgfExpr res = u->eapp(fun,arg);
|
||||
u->free_ref(arg);
|
||||
u->free_ref(fun);
|
||||
return res;
|
||||
}
|
||||
case PgfExprLit::tag: {
|
||||
auto elit = ref<PgfExprLit>::untagged(e);
|
||||
uintptr_t lit = match_lit(u,elit->lit);
|
||||
uintptr_t res = u->elit(lit);
|
||||
PgfLiteral lit = match_lit(u,elit->lit);
|
||||
PgfExpr res = u->elit(lit);
|
||||
u->free_ref(lit);
|
||||
return res;
|
||||
}
|
||||
@@ -57,17 +57,17 @@ uintptr_t PgfDBMarshaller::match_expr(PgfUnmarshaller *u, uintptr_t e)
|
||||
}
|
||||
case PgfExprTyped::tag: {
|
||||
auto etyped = ref<PgfExprTyped>::untagged(e);
|
||||
uintptr_t expr = match_expr(u,etyped->expr);
|
||||
uintptr_t type = match_type(u,(uintptr_t) &(*etyped->type));
|
||||
uintptr_t res = u->etyped(expr,type);
|
||||
PgfExpr expr = match_expr(u,etyped->expr);
|
||||
PgfType type = match_type(u,etyped->type.as_object());
|
||||
PgfExpr res = u->etyped(expr,type);
|
||||
u->free_ref(type);
|
||||
u->free_ref(expr);
|
||||
return res;
|
||||
}
|
||||
case PgfExprImplArg::tag: {
|
||||
auto eimpl = ref<PgfExprImplArg>::untagged(e);
|
||||
uintptr_t expr = match_expr(u,eimpl->expr);
|
||||
uintptr_t res = u->eimplarg(expr);
|
||||
PgfExpr expr = match_expr(u,eimpl->expr);
|
||||
PgfExpr res = u->eimplarg(expr);
|
||||
u->free_ref(expr);
|
||||
return res;
|
||||
}
|
||||
@@ -77,27 +77,27 @@ uintptr_t PgfDBMarshaller::match_expr(PgfUnmarshaller *u, uintptr_t e)
|
||||
}
|
||||
|
||||
PGF_INTERNAL
|
||||
uintptr_t PgfDBMarshaller::match_type(PgfUnmarshaller *u, uintptr_t ty)
|
||||
PgfType PgfDBMarshaller::match_type(PgfUnmarshaller *u, PgfType ty)
|
||||
{
|
||||
PgfType *tp = (PgfType *) ty;
|
||||
ref<PgfDTyp> tp = ty;
|
||||
|
||||
PgfTypeHypo *hypos = (PgfTypeHypo *)
|
||||
alloca(tp->hypos->len * sizeof(PgfTypeHypo));
|
||||
for (size_t i = 0; i < tp->hypos->len; i++) {
|
||||
hypos[i].bind_type = tp->hypos->data[i].bind_type;
|
||||
hypos[i].cid = &(*tp->hypos->data[i].cid);
|
||||
hypos[i].type = match_type(u, (uintptr_t) &(*tp->hypos->data[i].type));
|
||||
hypos[i].type = match_type(u, tp->hypos->data[i].type.as_object());
|
||||
}
|
||||
|
||||
uintptr_t *exprs = (uintptr_t *)
|
||||
alloca(tp->exprs->len * sizeof(uintptr_t));
|
||||
PgfExpr *exprs = (PgfExpr *)
|
||||
alloca(tp->exprs->len * sizeof(PgfExpr));
|
||||
for (size_t i = 0; i < tp->exprs->len; i++) {
|
||||
exprs[i] = match_expr(u, tp->exprs->data[i]);
|
||||
}
|
||||
|
||||
uintptr_t res = u->dtyp(tp->hypos->len, hypos,
|
||||
&tp->name,
|
||||
tp->exprs->len, exprs);
|
||||
PgfType res = u->dtyp(tp->hypos->len, hypos,
|
||||
&tp->name,
|
||||
tp->exprs->len, exprs);
|
||||
|
||||
for (size_t i = 0; i < tp->hypos->len; i++) {
|
||||
u->free_ref(hypos[i].type);
|
||||
@@ -361,12 +361,12 @@ bool PgfExprParser::lookahead(int ch)
|
||||
return (this->ch == ch);
|
||||
}
|
||||
|
||||
uintptr_t PgfExprParser::parse_term()
|
||||
PgfExpr PgfExprParser::parse_term()
|
||||
{
|
||||
switch (token_tag) {
|
||||
case PGF_TOKEN_LPAR: {
|
||||
token();
|
||||
uintptr_t expr = parse_expr();
|
||||
PgfExpr expr = parse_expr();
|
||||
if (token_tag == PGF_TOKEN_RPAR) {
|
||||
token();
|
||||
return expr;
|
||||
@@ -378,7 +378,7 @@ uintptr_t PgfExprParser::parse_term()
|
||||
}
|
||||
case PGF_TOKEN_LTRIANGLE: {
|
||||
token();
|
||||
uintptr_t expr = parse_expr();
|
||||
PgfExpr expr = parse_expr();
|
||||
if (expr == 0)
|
||||
return 0;
|
||||
|
||||
@@ -388,7 +388,7 @@ uintptr_t PgfExprParser::parse_term()
|
||||
}
|
||||
token();
|
||||
|
||||
uintptr_t type = parse_type();
|
||||
PgfType type = parse_type();
|
||||
if (type == 0) {
|
||||
u->free_ref(expr);
|
||||
return 0;
|
||||
@@ -401,7 +401,7 @@ uintptr_t PgfExprParser::parse_term()
|
||||
}
|
||||
token();
|
||||
|
||||
uintptr_t e = u->etyped(expr,type);
|
||||
PgfExpr e = u->etyped(expr,type);
|
||||
u->free_ref(expr);
|
||||
u->free_ref(type);
|
||||
return e;
|
||||
@@ -417,29 +417,29 @@ uintptr_t PgfExprParser::parse_term()
|
||||
return u->emeta(id);
|
||||
}
|
||||
case PGF_TOKEN_IDENT: {
|
||||
uintptr_t e = u->efun(token_value);
|
||||
PgfExpr e = u->efun(token_value);
|
||||
token();
|
||||
return e;
|
||||
}
|
||||
case PGF_TOKEN_INT: {
|
||||
int n = atoi((const char*) &token_value->text);
|
||||
uint32_t lit = u->lint(n);
|
||||
uint32_t e = u->elit(lit);
|
||||
PgfLiteral lit = u->lint(n);
|
||||
PgfExpr e = u->elit(lit);
|
||||
u->free_ref(lit);
|
||||
token();
|
||||
return e;
|
||||
}
|
||||
case PGF_TOKEN_STR: {
|
||||
uint32_t lit = u->lstr(token_value);
|
||||
uint32_t e = u->elit(lit);
|
||||
PgfLiteral lit = u->lstr(token_value);
|
||||
PgfExpr e = u->elit(lit);
|
||||
u->free_ref(lit);
|
||||
token();
|
||||
return e;
|
||||
}
|
||||
case PGF_TOKEN_FLT: {
|
||||
double d = atof((const char*) &token_value->text);
|
||||
uint32_t lit = u->lflt(d);
|
||||
uint32_t e = u->elit(lit);
|
||||
PgfLiteral lit = u->lflt(d);
|
||||
PgfExpr e = u->elit(lit);
|
||||
u->free_ref(lit);
|
||||
token();
|
||||
return e;
|
||||
@@ -449,9 +449,9 @@ uintptr_t PgfExprParser::parse_term()
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t PgfExprParser::parse_arg()
|
||||
PgfExpr PgfExprParser::parse_arg()
|
||||
{
|
||||
uintptr_t arg;
|
||||
PgfExpr arg;
|
||||
|
||||
if (token_tag == PGF_TOKEN_LCURLY) {
|
||||
token();
|
||||
@@ -466,7 +466,7 @@ uintptr_t PgfExprParser::parse_arg()
|
||||
}
|
||||
token();
|
||||
|
||||
uintptr_t e = u->eimplarg(arg);
|
||||
PgfExpr e = u->eimplarg(arg);
|
||||
u->free_ref(arg);
|
||||
arg = e;
|
||||
} else {
|
||||
@@ -556,9 +556,9 @@ PgfBind *PgfExprParser::parse_binds(PgfBind *next)
|
||||
return next;
|
||||
}
|
||||
|
||||
uintptr_t PgfExprParser::parse_expr()
|
||||
PgfExpr PgfExprParser::parse_expr()
|
||||
{
|
||||
uintptr_t expr;
|
||||
PgfExpr expr;
|
||||
|
||||
if (token_tag == PGF_TOKEN_LAMBDA) {
|
||||
token();
|
||||
@@ -577,7 +577,7 @@ uintptr_t PgfExprParser::parse_expr()
|
||||
goto error;
|
||||
|
||||
while (bs != NULL) {
|
||||
uintptr_t abs_expr = u->eabs(bs->bind_type, &bs->var, expr);
|
||||
PgfExpr abs_expr = u->eabs(bs->bind_type, &bs->var, expr);
|
||||
u->free_ref(expr);
|
||||
expr = abs_expr;
|
||||
|
||||
@@ -609,7 +609,7 @@ error:
|
||||
token_tag != PGF_TOKEN_COMMA &&
|
||||
token_tag != PGF_TOKEN_SEMI &&
|
||||
token_tag != PGF_TOKEN_UNKNOWN) {
|
||||
uintptr_t arg = parse_arg();
|
||||
PgfExpr arg = parse_arg();
|
||||
if (arg == 0)
|
||||
return expr;
|
||||
|
||||
@@ -669,9 +669,9 @@ bool PgfExprParser::parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos)
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t PgfExprParser::parse_type()
|
||||
PgfType PgfExprParser::parse_type()
|
||||
{
|
||||
uintptr_t type = 0;
|
||||
PgfType type = 0;
|
||||
|
||||
size_t n_hypos = 0;
|
||||
PgfTypeHypo *hypos = NULL;
|
||||
@@ -679,7 +679,7 @@ uintptr_t PgfExprParser::parse_type()
|
||||
PgfText *cat = NULL;
|
||||
|
||||
size_t n_args = 0;
|
||||
uintptr_t *args = NULL;
|
||||
PgfType *args = NULL;
|
||||
|
||||
for (;;) {
|
||||
if (token_tag == PGF_TOKEN_LPAR) {
|
||||
@@ -711,7 +711,7 @@ uintptr_t PgfExprParser::parse_type()
|
||||
|
||||
size_t n_end = n_hypos;
|
||||
|
||||
uintptr_t type = parse_type();
|
||||
PgfType type = parse_type();
|
||||
if (type == 0)
|
||||
goto exit;
|
||||
|
||||
@@ -737,11 +737,11 @@ uintptr_t PgfExprParser::parse_type()
|
||||
token_tag != PGF_TOKEN_RPAR &&
|
||||
token_tag != PGF_TOKEN_RTRIANGLE &&
|
||||
token_tag != PGF_TOKEN_RARROW) {
|
||||
uintptr_t arg = parse_arg();
|
||||
PgfExpr arg = parse_arg();
|
||||
if (arg == 0)
|
||||
break;
|
||||
|
||||
args = (uintptr_t*) realloc(args, sizeof(uintptr_t)*(n_args+1));
|
||||
args = (PgfExpr*) realloc(args, sizeof(PgfExpr)*(n_args+1));
|
||||
args[n_args++] = arg;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
#ifndef EXPR_H_
|
||||
#define EXPR_H_
|
||||
|
||||
/// An abstract syntax tree
|
||||
typedef variant PgfExpr;
|
||||
|
||||
struct PgfHypo;
|
||||
struct PgfType;
|
||||
|
||||
/// A literal for an abstract syntax tree
|
||||
typedef variant PgfLiteral;
|
||||
struct PgfDTyp;
|
||||
|
||||
struct PGF_INTERNAL_DECL PgfLiteralStr {
|
||||
static const uint8_t tag = 0;
|
||||
@@ -31,10 +25,10 @@ struct PGF_INTERNAL_DECL PgfLiteralFlt {
|
||||
struct PGF_INTERNAL_DECL PgfHypo {
|
||||
PgfBindType bind_type;
|
||||
ref<PgfText> cid;
|
||||
ref<PgfType> type;
|
||||
ref<PgfDTyp> type;
|
||||
};
|
||||
|
||||
struct PGF_INTERNAL_DECL PgfType {
|
||||
struct PGF_INTERNAL_DECL PgfDTyp {
|
||||
ref<PgfVector<PgfHypo>> hypos;
|
||||
ref<PgfVector<PgfExpr>> exprs;
|
||||
PgfText name;
|
||||
@@ -83,7 +77,7 @@ struct PGF_INTERNAL_DECL PgfExprTyped {
|
||||
static const uint8_t tag = 6;
|
||||
|
||||
PgfExpr expr;
|
||||
ref<PgfType> type;
|
||||
ref<PgfDTyp> type;
|
||||
};
|
||||
|
||||
struct PGF_INTERNAL_DECL PgfExprImplArg {
|
||||
@@ -100,9 +94,9 @@ typedef struct {
|
||||
} PgfExprProb;
|
||||
|
||||
struct PgfDBMarshaller : public PgfMarshaller {
|
||||
virtual uintptr_t match_lit(PgfUnmarshaller *u, uintptr_t l);
|
||||
virtual uintptr_t match_expr(PgfUnmarshaller *u, uintptr_t e);
|
||||
virtual uintptr_t match_type(PgfUnmarshaller *u, uintptr_t tp);
|
||||
virtual object match_lit(PgfUnmarshaller *u, PgfLiteral l);
|
||||
virtual object match_expr(PgfUnmarshaller *u, PgfExpr e);
|
||||
virtual object match_type(PgfUnmarshaller *u, PgfType ty);
|
||||
};
|
||||
|
||||
extern PGF_INTERNAL_DECL PgfDBMarshaller db_marshaller;
|
||||
@@ -158,12 +152,12 @@ public:
|
||||
PgfBind *parse_binds(PgfBind *next);
|
||||
|
||||
|
||||
uintptr_t parse_arg();
|
||||
uintptr_t parse_term();
|
||||
uintptr_t parse_expr();
|
||||
PgfExpr parse_arg();
|
||||
PgfExpr parse_term();
|
||||
PgfExpr parse_expr();
|
||||
|
||||
bool parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos);
|
||||
uintptr_t parse_type();
|
||||
PgfType parse_type();
|
||||
|
||||
bool eof();
|
||||
};
|
||||
|
||||
@@ -167,7 +167,7 @@ void pgf_iter_categories(PgfPGF *pgf, PgfItor *itor)
|
||||
}
|
||||
|
||||
PGF_API
|
||||
uintptr_t pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u)
|
||||
PgfType pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u)
|
||||
{
|
||||
DB_scope scope(pgf, READER_SCOPE);
|
||||
|
||||
@@ -184,7 +184,7 @@ uintptr_t pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u)
|
||||
case PgfLiteralStr::tag: {
|
||||
auto lstr = ref<PgfLiteralStr>::untagged(flag->value);
|
||||
|
||||
uintptr_t type = pgf_read_type(&lstr->val, u);
|
||||
PgfType type = pgf_read_type(&lstr->val, u);
|
||||
if (type == 0)
|
||||
break;
|
||||
return type;
|
||||
@@ -217,7 +217,7 @@ PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos
|
||||
for (size_t i = 0; i < abscat->context->len; i++) {
|
||||
hypos[i].bind_type = abscat->context->data[i].bind_type;
|
||||
hypos[i].cid = textdup(abscat->context->data[i].cid);
|
||||
hypos[i].type = db_marshaller.match_type(u, (uintptr_t) &(*abscat->context->data[i].type));
|
||||
hypos[i].type = db_marshaller.match_type(u, abscat->context->data[i].type.as_object());
|
||||
}
|
||||
|
||||
*n_hypos = abscat->context->len;
|
||||
@@ -274,7 +274,7 @@ void pgf_iter_functions_by_cat(PgfPGF *pgf, PgfText *cat, PgfItor *itor)
|
||||
}
|
||||
|
||||
PGF_API
|
||||
uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u)
|
||||
PgfType pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u)
|
||||
{
|
||||
DB_scope scope(pgf, READER_SCOPE);
|
||||
|
||||
@@ -283,7 +283,7 @@ uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u)
|
||||
if (absfun == 0)
|
||||
return 0;
|
||||
|
||||
return db_marshaller.match_type(u, (uintptr_t) &(*absfun->type));
|
||||
return db_marshaller.match_type(u, absfun->type.as_object());
|
||||
}
|
||||
|
||||
PGF_API
|
||||
@@ -313,7 +313,7 @@ prob_t pgf_function_prob(PgfPGF *pgf, PgfText *funname)
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfText *pgf_print_expr(uintptr_t e,
|
||||
PgfText *pgf_print_expr(PgfExpr e,
|
||||
PgfPrintContext *ctxt, int prio,
|
||||
PgfMarshaller *m)
|
||||
{
|
||||
@@ -322,11 +322,11 @@ PgfText *pgf_print_expr(uintptr_t e,
|
||||
return printer.get_text();
|
||||
}
|
||||
|
||||
PGF_API uintptr_t
|
||||
PGF_API PgfExpr
|
||||
pgf_read_expr(PgfText *input, PgfUnmarshaller *u)
|
||||
{
|
||||
PgfExprParser parser(input, u);
|
||||
uintptr_t res = parser.parse_expr();
|
||||
PgfExpr res = parser.parse_expr();
|
||||
if (!parser.eof()) {
|
||||
u->free_ref(res);
|
||||
return 0;
|
||||
@@ -335,7 +335,7 @@ pgf_read_expr(PgfText *input, PgfUnmarshaller *u)
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfText *pgf_print_type(uintptr_t ty,
|
||||
PgfText *pgf_print_type(PgfType ty,
|
||||
PgfPrintContext *ctxt, int prio,
|
||||
PgfMarshaller *m)
|
||||
{
|
||||
@@ -344,11 +344,11 @@ PgfText *pgf_print_type(uintptr_t ty,
|
||||
return printer.get_text();
|
||||
}
|
||||
|
||||
PGF_API uintptr_t
|
||||
pgf_read_type(PgfText *input, PgfUnmarshaller *u)
|
||||
PGF_API
|
||||
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u)
|
||||
{
|
||||
PgfExprParser parser(input, u);
|
||||
uintptr_t res = parser.parse_type();
|
||||
PgfType res = parser.parse_type();
|
||||
if (!parser.eof()) {
|
||||
u->free_ref(res);
|
||||
return 0;
|
||||
|
||||
@@ -53,6 +53,15 @@ struct PgfItor {
|
||||
void (*fn)(PgfItor* self, PgfText* key, void *value);
|
||||
};
|
||||
|
||||
typedef uintptr_t object;
|
||||
|
||||
/// An abstract syntax tree
|
||||
typedef object PgfExpr;
|
||||
|
||||
/// A literal for an abstract syntax tree
|
||||
typedef object PgfLiteral;
|
||||
typedef object PgfType;
|
||||
|
||||
typedef enum {
|
||||
PGF_BIND_TYPE_EXPLICIT,
|
||||
PGF_BIND_TYPE_IMPLICIT
|
||||
@@ -63,7 +72,7 @@ typedef int PgfMetaId;
|
||||
typedef struct {
|
||||
PgfBindType bind_type;
|
||||
PgfText *cid;
|
||||
uintptr_t type;
|
||||
PgfType type;
|
||||
} PgfTypeHypo;
|
||||
|
||||
/* This structure tells the runtime how to create abstract syntax
|
||||
@@ -78,48 +87,48 @@ typedef struct {
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
struct PgfUnmarshaller {
|
||||
virtual uintptr_t eabs(PgfBindType btype, PgfText *name, uintptr_t body)=0;
|
||||
virtual uintptr_t eapp(uintptr_t fun, uintptr_t arg)=0;
|
||||
virtual uintptr_t elit(uintptr_t lit)=0;
|
||||
virtual uintptr_t emeta(PgfMetaId meta)=0;
|
||||
virtual uintptr_t efun(PgfText *name)=0;
|
||||
virtual uintptr_t evar(int index)=0;
|
||||
virtual uintptr_t etyped(uintptr_t expr, uintptr_t typ)=0;
|
||||
virtual uintptr_t eimplarg(uintptr_t expr)=0;
|
||||
virtual uintptr_t lint(int v)=0;
|
||||
virtual uintptr_t lflt(double v)=0;
|
||||
virtual uintptr_t lstr(PgfText *v)=0;
|
||||
virtual uintptr_t dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs)=0;
|
||||
virtual void free_ref(uintptr_t x)=0;
|
||||
virtual PgfExpr eabs(PgfBindType btype, PgfText *name, PgfExpr body)=0;
|
||||
virtual PgfExpr eapp(PgfExpr fun, PgfExpr arg)=0;
|
||||
virtual PgfExpr elit(PgfLiteral lit)=0;
|
||||
virtual PgfExpr emeta(PgfMetaId meta)=0;
|
||||
virtual PgfExpr efun(PgfText *name)=0;
|
||||
virtual PgfExpr evar(int index)=0;
|
||||
virtual PgfExpr etyped(PgfExpr expr, PgfType typ)=0;
|
||||
virtual PgfExpr eimplarg(PgfExpr expr)=0;
|
||||
virtual PgfLiteral lint(int v)=0;
|
||||
virtual PgfLiteral lflt(double v)=0;
|
||||
virtual PgfLiteral lstr(PgfText *v)=0;
|
||||
virtual PgfType dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, PgfExpr *exprs)=0;
|
||||
virtual void free_ref(object x)=0;
|
||||
};
|
||||
|
||||
struct PgfMarshaller {
|
||||
virtual uintptr_t match_lit(PgfUnmarshaller *u, uintptr_t lit)=0;
|
||||
virtual uintptr_t match_expr(PgfUnmarshaller *u, uintptr_t expr)=0;
|
||||
virtual uintptr_t match_type(PgfUnmarshaller *u, uintptr_t ty)=0;
|
||||
virtual object match_lit(PgfUnmarshaller *u, PgfLiteral lit)=0;
|
||||
virtual object match_expr(PgfUnmarshaller *u, PgfExpr expr)=0;
|
||||
virtual object match_type(PgfUnmarshaller *u, PgfType ty)=0;
|
||||
};
|
||||
#else
|
||||
typedef struct PgfUnmarshaller PgfUnmarshaller;
|
||||
typedef struct PgfUnmarshallerVtbl PgfUnmarshallerVtbl;
|
||||
struct PgfUnmarshallerVtbl {
|
||||
uintptr_t (*eabs)(PgfUnmarshaller *this, PgfBindType btype, PgfText *name, uintptr_t body);
|
||||
uintptr_t (*eapp)(PgfUnmarshaller *this, uintptr_t fun, uintptr_t arg);
|
||||
uintptr_t (*elit)(PgfUnmarshaller *this, uintptr_t lit);
|
||||
uintptr_t (*emeta)(PgfUnmarshaller *this, PgfMetaId meta);
|
||||
uintptr_t (*efun)(PgfUnmarshaller *this, PgfText *name);
|
||||
uintptr_t (*evar)(PgfUnmarshaller *this, int index);
|
||||
uintptr_t (*etyped)(PgfUnmarshaller *this, uintptr_t expr, uintptr_t typ);
|
||||
uintptr_t (*eimplarg)(PgfUnmarshaller *this, uintptr_t expr);
|
||||
uintptr_t (*lint)(PgfUnmarshaller *this, int v);
|
||||
uintptr_t (*lflt)(PgfUnmarshaller *this, double v);
|
||||
uintptr_t (*lstr)(PgfUnmarshaller *this, PgfText *v);
|
||||
uintptr_t (*dtyp)(PgfUnmarshaller *this,
|
||||
int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs);
|
||||
void (*free_ref)(PgfUnmarshaller *this, uintptr_t x);
|
||||
PgfExpr (*eabs)(PgfUnmarshaller *this, PgfBindType btype, PgfText *name, PgfExpr body);
|
||||
PgfExpr (*eapp)(PgfUnmarshaller *this, PgfExpr fun, PgfExpr arg);
|
||||
PgfExpr (*elit)(PgfUnmarshaller *this, PgfLiteral lit);
|
||||
PgfExpr (*emeta)(PgfUnmarshaller *this, PgfMetaId meta);
|
||||
PgfExpr (*efun)(PgfUnmarshaller *this, PgfText *name);
|
||||
PgfExpr (*evar)(PgfUnmarshaller *this, int index);
|
||||
PgfExpr (*etyped)(PgfUnmarshaller *this, PgfExpr expr, PgfType typ);
|
||||
PgfExpr (*eimplarg)(PgfUnmarshaller *this, PgfExpr expr);
|
||||
PgfLiteral (*lint)(PgfUnmarshaller *this, int v);
|
||||
PgfLiteral (*lflt)(PgfUnmarshaller *this, double v);
|
||||
PgfLiteral (*lstr)(PgfUnmarshaller *this, PgfText *v);
|
||||
PgfType (*dtyp)(PgfUnmarshaller *this,
|
||||
int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, PgfExpr *exprs);
|
||||
void (*free_ref)(PgfUnmarshaller *this, object x);
|
||||
};
|
||||
struct PgfUnmarshaller {
|
||||
PgfUnmarshallerVtbl *vtbl;
|
||||
@@ -128,9 +137,9 @@ struct PgfUnmarshaller {
|
||||
typedef struct PgfMarshaller PgfMarshaller;
|
||||
typedef struct PgfMarshallerVtbl PgfMarshallerVtbl;
|
||||
struct PgfMarshallerVtbl {
|
||||
uintptr_t (*match_lit)(PgfUnmarshaller *u, uintptr_t lit);
|
||||
uintptr_t (*match_expr)(PgfUnmarshaller *u, uintptr_t expr);
|
||||
uintptr_t (*match_type)(PgfUnmarshaller *u, uintptr_t ty);
|
||||
object (*match_lit)(PgfUnmarshaller *u, PgfLiteral lit);
|
||||
object (*match_expr)(PgfUnmarshaller *u, PgfExpr expr);
|
||||
object (*match_type)(PgfUnmarshaller *u, PgfType ty);
|
||||
};
|
||||
struct PgfMarshaller {
|
||||
PgfMarshallerVtbl *vtbl;
|
||||
@@ -201,7 +210,7 @@ PGF_API_DECL
|
||||
void pgf_iter_categories(PgfPGF *pgf, PgfItor *itor);
|
||||
|
||||
PGF_API_DECL
|
||||
uintptr_t pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u);
|
||||
PgfType pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API_DECL
|
||||
PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u);
|
||||
@@ -216,7 +225,7 @@ PGF_API_DECL
|
||||
void pgf_iter_functions_by_cat(PgfPGF *pgf, PgfText *cat, PgfItor *itor);
|
||||
|
||||
PGF_API_DECL
|
||||
uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u);
|
||||
PgfType pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API_DECL
|
||||
int pgf_function_is_constructor(PgfPGF *pgf, PgfText *funname);
|
||||
@@ -232,19 +241,19 @@ struct PgfPrintContext {
|
||||
};
|
||||
|
||||
PGF_API_DECL
|
||||
PgfText *pgf_print_expr(uintptr_t e,
|
||||
PgfText *pgf_print_expr(PgfExpr e,
|
||||
PgfPrintContext *ctxt, int prio,
|
||||
PgfMarshaller *m);
|
||||
|
||||
PGF_API_DECL
|
||||
uintptr_t pgf_read_expr(PgfText *input, PgfUnmarshaller *u);
|
||||
PgfExpr pgf_read_expr(PgfText *input, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API_DECL
|
||||
PgfText *pgf_print_type(uintptr_t ty,
|
||||
PgfText *pgf_print_type(PgfType ty,
|
||||
PgfPrintContext *ctxt, int prio,
|
||||
PgfMarshaller *m);
|
||||
|
||||
PGF_API_DECL
|
||||
uintptr_t pgf_read_type(PgfText *input, PgfUnmarshaller *u);
|
||||
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u);
|
||||
|
||||
#endif // PGF_H_
|
||||
|
||||
@@ -121,7 +121,7 @@ void PgfPrinter::pop_variable()
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::eabs(PgfBindType btype, PgfText *name, uintptr_t body)
|
||||
PgfExpr PgfPrinter::eabs(PgfBindType btype, PgfText *name, PgfExpr body)
|
||||
{
|
||||
bool p = (prio > 1);
|
||||
if (p) puts("(");
|
||||
@@ -159,7 +159,7 @@ uintptr_t PgfPrinter::eabs(PgfBindType btype, PgfText *name, uintptr_t body)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::eapp(uintptr_t fun, uintptr_t arg)
|
||||
PgfExpr PgfPrinter::eapp(PgfExpr fun, PgfExpr arg)
|
||||
{
|
||||
flush_lambdas();
|
||||
|
||||
@@ -179,13 +179,13 @@ uintptr_t PgfPrinter::eapp(uintptr_t fun, uintptr_t arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::elit(uintptr_t lit)
|
||||
PgfExpr PgfPrinter::elit(PgfLiteral lit)
|
||||
{
|
||||
flush_lambdas();
|
||||
return m->match_lit(this, lit);
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::emeta(PgfMetaId meta)
|
||||
PgfExpr PgfPrinter::emeta(PgfMetaId meta)
|
||||
{
|
||||
flush_lambdas();
|
||||
|
||||
@@ -198,7 +198,7 @@ uintptr_t PgfPrinter::emeta(PgfMetaId meta)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::efun(PgfText *name)
|
||||
PgfExpr PgfPrinter::efun(PgfText *name)
|
||||
{
|
||||
flush_lambdas();
|
||||
|
||||
@@ -206,7 +206,7 @@ uintptr_t PgfPrinter::efun(PgfText *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::evar(int index)
|
||||
PgfExpr PgfPrinter::evar(int index)
|
||||
{
|
||||
flush_lambdas();
|
||||
|
||||
@@ -224,7 +224,7 @@ uintptr_t PgfPrinter::evar(int index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::etyped(uintptr_t expr, uintptr_t ty)
|
||||
PgfExpr PgfPrinter::etyped(PgfExpr expr, PgfType ty)
|
||||
{
|
||||
flush_lambdas();
|
||||
|
||||
@@ -238,7 +238,7 @@ uintptr_t PgfPrinter::etyped(uintptr_t expr, uintptr_t ty)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::eimplarg(uintptr_t expr)
|
||||
PgfExpr PgfPrinter::eimplarg(PgfExpr expr)
|
||||
{
|
||||
flush_lambdas();
|
||||
|
||||
@@ -249,19 +249,19 @@ uintptr_t PgfPrinter::eimplarg(uintptr_t expr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::lint(int v)
|
||||
PgfLiteral PgfPrinter::lint(int v)
|
||||
{
|
||||
nprintf(16, "%d", v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::lflt(double v)
|
||||
PgfLiteral PgfPrinter::lflt(double v)
|
||||
{
|
||||
nprintf(16,"%lg",v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::lstr(PgfText *v)
|
||||
PgfLiteral PgfPrinter::lstr(PgfText *v)
|
||||
{
|
||||
PgfText *charbuf = (PgfText *) alloca(sizeof(PgfText)+7);
|
||||
|
||||
@@ -305,9 +305,9 @@ uintptr_t PgfPrinter::lstr(PgfText *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uintptr_t PgfPrinter::dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs)
|
||||
PgfType PgfPrinter::dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, PgfExpr *exprs)
|
||||
{
|
||||
bool p = (prio > 0 && n_hypos > 0) ||
|
||||
(prio > 3 && n_exprs > 0);
|
||||
@@ -353,6 +353,6 @@ uintptr_t PgfPrinter::dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PgfPrinter::free_ref(uintptr_t x)
|
||||
void PgfPrinter::free_ref(object x)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -45,21 +45,21 @@ public:
|
||||
|
||||
PgfText *get_text();
|
||||
|
||||
virtual uintptr_t eabs(PgfBindType btype, PgfText *name, uintptr_t body);
|
||||
virtual uintptr_t eapp(uintptr_t fun, uintptr_t arg);
|
||||
virtual uintptr_t elit(uintptr_t lit);
|
||||
virtual uintptr_t emeta(PgfMetaId meta);
|
||||
virtual uintptr_t efun(PgfText *name);
|
||||
virtual uintptr_t evar(int index);
|
||||
virtual uintptr_t etyped(uintptr_t expr, uintptr_t typ);
|
||||
virtual uintptr_t eimplarg(uintptr_t expr);
|
||||
virtual uintptr_t lint(int v);
|
||||
virtual uintptr_t lflt(double v);
|
||||
virtual uintptr_t lstr(PgfText *v);
|
||||
virtual uintptr_t dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs);
|
||||
virtual void free_ref(uintptr_t x);
|
||||
virtual PgfExpr eabs(PgfBindType btype, PgfText *name, PgfExpr body);
|
||||
virtual PgfExpr eapp(PgfExpr fun, PgfExpr arg);
|
||||
virtual PgfExpr elit(PgfLiteral lit);
|
||||
virtual PgfExpr emeta(PgfMetaId meta);
|
||||
virtual PgfExpr efun(PgfText *name);
|
||||
virtual PgfExpr evar(int index);
|
||||
virtual PgfExpr etyped(PgfExpr expr, PgfType typ);
|
||||
virtual PgfExpr eimplarg(PgfExpr expr);
|
||||
virtual PgfLiteral lint(int v);
|
||||
virtual PgfLiteral lflt(double v);
|
||||
virtual PgfLiteral lstr(PgfText *v);
|
||||
virtual PgfType dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
PgfText *cat,
|
||||
int n_exprs, PgfExpr *exprs);
|
||||
virtual void free_ref(object x);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -82,10 +82,10 @@ uint64_t PgfReader::read_uint()
|
||||
return u;
|
||||
}
|
||||
|
||||
moffset PgfReader::read_name_internal(size_t struct_size)
|
||||
object PgfReader::read_name_internal(size_t struct_size)
|
||||
{
|
||||
size_t size = read_len();
|
||||
moffset offs = current_db->malloc_internal(struct_size+sizeof(PgfText)+size+1);
|
||||
object offs = current_db->malloc_internal(struct_size+sizeof(PgfText)+size+1);
|
||||
PgfText* ptext = (PgfText*) (current_base+offs+struct_size);
|
||||
ptext->size = size;
|
||||
|
||||
@@ -102,7 +102,7 @@ moffset PgfReader::read_name_internal(size_t struct_size)
|
||||
return offs;
|
||||
}
|
||||
|
||||
moffset PgfReader::read_text_internal(size_t struct_size)
|
||||
object PgfReader::read_text_internal(size_t struct_size)
|
||||
{
|
||||
size_t len = read_len();
|
||||
|
||||
@@ -139,7 +139,7 @@ moffset PgfReader::read_text_internal(size_t struct_size)
|
||||
size_t size = p-buf;
|
||||
*p++ = 0;
|
||||
|
||||
moffset offs = current_db->malloc_internal(struct_size+sizeof(PgfText)+size+1);
|
||||
object offs = current_db->malloc_internal(struct_size+sizeof(PgfText)+size+1);
|
||||
PgfText* ptext = (PgfText*) (current_base+offs+struct_size);
|
||||
ptext->size = size;
|
||||
memcpy(ptext->text, buf, size+1);
|
||||
@@ -291,11 +291,11 @@ void PgfReader::read_hypo(ref<PgfHypo> hypo)
|
||||
hypo->type = read_type();
|
||||
}
|
||||
|
||||
ref<PgfType> PgfReader::read_type()
|
||||
ref<PgfDTyp> PgfReader::read_type()
|
||||
{
|
||||
ref<PgfVector<PgfHypo>> hypos =
|
||||
read_vector<PgfHypo>(&PgfReader::read_hypo);
|
||||
ref<PgfType> tp = read_name<PgfType>(&PgfType::name);
|
||||
ref<PgfDTyp> tp = read_name<PgfDTyp>(&PgfDTyp::name);
|
||||
tp->hypos = hypos;
|
||||
tp->exprs =
|
||||
read_vector<PgfExpr>(&PgfReader::read_expr);
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
void read_expr(ref<PgfExpr> r) { *r = read_expr(); };
|
||||
|
||||
void read_hypo(ref<PgfHypo> hypo);
|
||||
ref<PgfType> read_type();
|
||||
ref<PgfDTyp> read_type();
|
||||
|
||||
ref<PgfFlag> read_flag();
|
||||
|
||||
@@ -72,8 +72,8 @@ public:
|
||||
private:
|
||||
std::istream *in;
|
||||
|
||||
moffset read_name_internal(size_t struct_size);
|
||||
moffset read_text_internal(size_t struct_size);
|
||||
object read_name_internal(size_t struct_size);
|
||||
object read_text_internal(size_t struct_size);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user