Skip to content

Commit

Permalink
an experimental left-corner table maker
Browse files Browse the repository at this point in the history
  • Loading branch information
krangelov committed Sep 5, 2024
1 parent d43d2cb commit 5239ce5
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/runtime/c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ libpgf_la_SOURCES = \
pgf/md5.h

libpgf_la_LDFLAGS = -no-undefined -version-info 4:0:0
libpgf_la_CXXFLAGS = -fno-rtti -std=c++11 -DCOMPILING_PGF
libpgf_la_CXXFLAGS = -fno-rtti -std=c++14 -DCOMPILING_PGF

bin_PROGRAMS =

Expand Down
93 changes: 89 additions & 4 deletions src/runtime/c/pgf/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ typedef struct {
PgfProbspace funs_by_cat;
} PgfAbstr;

typedef struct {
size_t factor;
size_t var;
} term;

struct PGF_INTERNAL_DECL PgfLParam {
size_t i0;
size_t n_terms;
struct {
size_t factor;
size_t var;
} terms[];
term terms[];

static void release(ref<PgfLParam> param);
};
Expand Down Expand Up @@ -263,6 +265,89 @@ struct PGF_INTERNAL_DECL PgfConcrPrintname {
static void release(ref<PgfConcrPrintname> printname);
};

#define containerof(T,field,p) (T*) (((char*) p)-offsetof(T,field))

struct PGF_INTERNAL_DECL PgfLCEdge {
struct {
ref<PgfConcrLincat> lincat;
struct {
size_t i0;
term& operator[](int i) {
PgfLCEdge *edge = containerof(PgfLCEdge,from.value,this);
return edge->terms[i];
}
size_t size() {
PgfLCEdge *edge = containerof(PgfLCEdge,from.value,this);
return edge->from.lin_idx.n_offset;
}
} value;
struct {
size_t i0;
size_t n_offset;
term& operator[](int i) {
PgfLCEdge *edge = containerof(PgfLCEdge,from.lin_idx,this);
return edge->terms[n_offset+i];
}
size_t size() {
PgfLCEdge *edge = containerof(PgfLCEdge,from.lin_idx,this);
return edge->to.value.n_offset-n_offset;
}
} lin_idx;
} from;

struct {
ref<PgfConcrLincat> lincat;
struct {
size_t i0;
size_t n_offset;
term& operator[](int i) {
PgfLCEdge *edge = containerof(PgfLCEdge,to.value,this);
return edge->terms[n_offset+i];
}
size_t size() {
PgfLCEdge *edge = containerof(PgfLCEdge,to.value,this);
return edge->to.lin_idx.n_offset-n_offset;
}
} value;
struct {
size_t i0;
size_t n_offset;
term& operator[](int i) {
PgfLCEdge *edge = containerof(PgfLCEdge,to.lin_idx,this);
return edge->terms[n_offset+i];
}
size_t size() {
PgfLCEdge *edge = containerof(PgfLCEdge,to.lin_idx,this);
return edge->n_terms-n_offset;
}
} lin_idx;
} to;

struct {
size_t n_vars;
PgfVariableRange& operator[](int i) {
PgfLCEdge *edge = containerof(PgfLCEdge,vars,this);
return ((PgfVariableRange*)(((term*) (edge+1))+edge->n_terms))[i];
}
size_t size() {
return n_vars;
}
} vars;

size_t n_terms;
term terms[];

static ref<PgfLCEdge> alloc(size_t n_terms1, size_t n_terms2, size_t n_terms3, size_t n_terms4, size_t n_vars) {
auto edge = PgfDB::malloc<PgfLCEdge>((n_terms1+n_terms2+n_terms3+n_terms4)*sizeof(term)+n_vars*sizeof(PgfVariableRange));
edge->from.lin_idx.n_offset = n_terms1;
edge->to.value.n_offset = n_terms1+n_terms2;
edge->to.lin_idx.n_offset = n_terms1+n_terms2+n_terms3;
edge->n_terms = n_terms1+n_terms2+n_terms3+n_terms4;
edge->vars.n_vars = n_vars;
return edge;
}
};

struct PGF_INTERNAL_DECL PgfLRShift {
size_t next_state;
ref<PgfConcrLincat> lincat;
Expand Down
Loading

0 comments on commit 5239ce5

Please sign in to comment.