new functinal database code compiles and old functionality is working

parent 9b0e90ea
......@@ -77,7 +77,7 @@
vhashv->assoc
block-growth-factor init-block-size
get-index-set get-index-test
get-index-set get-index-test get-index-tags
prolog-closure?
......
This diff is collapsed.
(define-module (logic guile-log indexer)
#:use-module (logic guile-log code-load)
#:re-export (get-index-set get-index-test))
\ No newline at end of file
#:re-export (get-index-set get-index-test get-index-tags))
......@@ -277,6 +277,15 @@ inline int MIN(int i, int j)
return i;
}
SCM and_tag_p = SCM_BOOL_F;
SCM or_tag_p = SCM_BOOL_F;
SCM not_tag_p = SCM_BOOL_F;
SCM predicate_tag_p = SCM_BOOL_F;
typedef int (*predicate_t)(SCM,SCM);
predicate_t predicates[1000];
//#define DB(X) X
// Fast but horribly hard really, this need to be in C
void get_index_set_0(SCM s, SCM e, SCM db_, int *n, ulong *data)
......@@ -316,6 +325,9 @@ void get_index_set_0(SCM s, SCM e, SCM db_, int *n, ulong *data)
if(SCM_CONSP(e))
{
SCM x = SCM_CAR(e);
if(scm_is_eq(x, and_tag_p)) goto and_tag;
if(scm_is_eq(x, not_tag_p)) goto not_tag;
if(scm_is_eq(x, predicate_tag_p)) goto predicate_tag;
SCM l = SCM_CDR(e);
SCM v = get_vars(db);
int i;
......@@ -454,7 +466,7 @@ void get_index_set_0(SCM s, SCM e, SCM db_, int *n, ulong *data)
//printf("na = %p, data[0]= %p\n", na, data[0]);
}
else
{
{
mpz_t *mpa = &(SCM_I_BIG_MPZ(a));
int n4 = (*mpa)->_mp_size;
ulong *data4 = (*mpa)->_mp_d;
......@@ -491,6 +503,140 @@ void get_index_set_0(SCM s, SCM e, SCM db_, int *n, ulong *data)
// printf("ret n=%d,data[0]=%p, data[1]=%p",*n,data[0],data[1]);
return;
}
and_tag:
{
SCM a = SCM_CADR(e);
SCM b = SCM_CADDR(e);
SCM c = SCM_CADDDR(e);
ulong data2[100];
int i;
int n2 = *n;
for(i = 0; i < *n; i++)
data2[i] = data[i];
get_index_set_0(s, e, a, &n2, data2);
get_index_set_0(s, e, b, n, data);
get_index_set_0(s, e, c, n, data);
if(*n < n2)
{
for(i = 0; i < *n ; i++)
data[i] = data[i] | data2[i];
for(;i<n2; i++)
data[i] = data2[i];
*n = n2;
}
else
{
for(i = 0; i < n2 ; i++)
data[i] = data[i] | data2[i];
}
return;
}
not_tag:
{
SCM a = SCM_CADR(e);
SCM b = SCM_CADDR(e);
ulong data2[100];
ulong data3[100];
int i;
int n2 = 0;
int n3 = *n;
for(i = 0; i < *n; i++)
data3[i] = data[i];
get_index_set_0(s, e, b, &n2, data2);
get_index_set_0(s, e, a, n, data);
if(n3 < n2)
{
for(i = 0; i < n3; i++)
data3[i] = data3[i] & ~data2[i];
}
else
{
for(i=0; i < n2; i++)
data3[i] = data3[i] & ~data2[i];
}
if(n3 < *n)
{
int i;
for(i = 0; i < n2 ; i++)
{
data[i] = data[i] | data3[i];
}
}
else
{
int i;
for(i = 0; i < *n; i++)
{
data[i] = data[i] | data3[i];
}
for(; i < n3; i++)
{
data[i] = data3[i];
*n = n3;
}
}
}
return;
predicate_tag:
{
SCM a = SCM_CADR(e);
SCM l = SCM_CDDR(e);
get_index_set_0(s, e, a, &n2, data);
while(SCM_CONSP(l))
{
scm_t_bits tag = SCM_UNPACK(SCM_CAAR(l));
SCM p = SCM_CDAR(l);
if(predicates[tag](e,s))
{
ulong *data4;
int n4;
if(SCM_I_INUMP (p))
{
ulong data4_ = my_scm_to_ulong(p);
data4 = & data4_;
n4 = 1;
}
else
{
mpz_t *mpa = &(SCM_I_BIG_MPZ(p));
n4 = (*mpa)->_mp_size;
data4 = (*mpa)->_mp_d;
}
if(n4 < *n)
{
int i;
for(i = 0; i < n4; i++)
data[i] = data[i] | data4[i];
}
else
{
int i;
for(i = 0; i < *n; i++)
data[i] = data[i] | data4[i];
for(;i<n4;i++)
data[i] = data4[i];
}
}
l = SCM_CDR(l);
}
}
}
//#define DB(X)
SCM get_index_set(SCM s, SCM e, SCM db)
......@@ -528,6 +674,7 @@ SCM get_index_set(SCM s, SCM e, SCM db)
//return scm_from_int(10);
}
SCM_DEFINE(scm_get_index_set, "get-index-set", 3, 0, 0,
(SCM s, SCM e, SCM db), "")
#define FUNC_NAME s_scm_get_index_set
......@@ -548,3 +695,56 @@ SCM_DEFINE(scm_get_index_test, "get-index-test", 4, 0, 0,
}
#undef FUNC_NAME
#define MKSIMPLE(gp_,gp_gp) \
int gp_(SCM x, SCM s) \
{ \
return scm_is_true(gp_gp(x)); \
}
#define MKSIMPLE2(gp_,gp_gp) \
int gp_(SCM x, SCM s) \
{ \
return scm_is_true(gp_gp(x,s)); \
}
MKSIMPLE(gp_ ,gp_gp)
MKSIMPLE(integer__,scm_integer_p)
MKSIMPLE(string_ ,scm_string_p)
MKSIMPLE(id_ ,scm_procedure_p)
MKSIMPLE(number_ ,scm_number_p)
MKSIMPLE(float_ ,scm_inexact_p)
MKSIMPLE2(var_ , gp_attvar);
MKSIMPLE2(attvar_ , gp_att_rawvar);
MKSIMPLE2(varvar_ , gp_varp);
int integer_(SCM x, SCM s)
{
return scm_is_true(scm_integer_p(x));
}
SCM_DEFINE(scm_get_index_tags, "get-index-tags", 0, 0, 0, (), "")
#define FUNC_NAME s_scm_get_tags
{
return scm_list_3(and_tag_p, not_tag_p, predicate_tag_p);
}
#undef FUNC_NAME
void init_indexer()
{
and_tag_p = scm_cons(SCM_BOOL_F, SCM_BOOL_F);
or_tag_p = scm_cons(SCM_BOOL_F, SCM_BOOL_F);
not_tag_p = scm_cons(SCM_BOOL_F, SCM_BOOL_F);
predicate_tag_p = scm_cons(SCM_BOOL_F, SCM_BOOL_F);
predicates[0] = &gp_;
predicates[1] = &integer__;
predicates[2] = &string_;
predicates[3] = &id_;
predicates[4] = &number_;
predicates[5] = &float_;
predicates[6] = &var_;
predicates[7] = &attvar_;
predicates[8] = &varvar_;
}
SCM_API SCM scm_get_index_set(SCM s, SCM e, SCM db);
SCM_API SCM scm_get_index_test(SCM s, SCM e, SCM db, SCM n_);
SCM_API SCM scm_get_index_tags();
......@@ -3536,6 +3536,8 @@ void gp_init()
init_gpgc();
init_variables();
init_indexer();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment