diff options
Diffstat (limited to 'builtins.c')
-rw-r--r-- | builtins.c | 93 |
1 files changed, 33 insertions, 60 deletions
@@ -5,7 +5,7 @@ #include "dat.h" #include "fns.h" -#define BuiltinProto(name) int name(Term *, Term *, Goal **, Choicepoint **, Binding **) +#define BuiltinProto(name) int name(Term *, Term *, Goal **, Binding **) #define Match(X, Y) (runestrcmp(name, X) == 0 && arity == Y) #define Throw(What) do{\ Goal *g = malloc(sizeof(Goal)); \ @@ -128,21 +128,19 @@ findbuiltin(Term *goal) } int -builtinfail(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinfail(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goal); USED(goals); - USED(choicestack); USED(bindings); return 0; } int -builtincall(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincall(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); - USED(choicestack); USED(bindings); Goal *g = malloc(sizeof(Goal)); @@ -155,106 +153,98 @@ builtincall(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, } int -builtincut(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincut(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); USED(bindings); - Choicepoint *cp = *choicestack; + Choicepoint *cp = choicestack; /* Cut all choicepoints with an id larger or equal to the goal clause number, since they must have been introduced after this goal's parent. */ while(cp != nil && cp->id >= goal->clausenr) cp = cp->next; - *choicestack = cp; + choicestack = cp; return 1; } int -builtinvar(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinvar(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == VariableTerm); } int -builtinatom(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinatom(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == AtomTerm); } int -builtininteger(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtininteger(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == NumberTerm && arg->numbertype == NumberInt); } int -builtinfloat(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinfloat(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == NumberTerm && arg->numbertype == NumberFloat); } int -builtinatomic(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinatomic(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == AtomTerm || arg->tag == NumberTerm); } int -builtincompound(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincompound(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == CompoundTerm); } int -builtinnonvar(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinnonvar(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag != VariableTerm); } int -builtinnumber(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinnumber(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *arg = goal->children; return (arg->tag == NumberTerm); @@ -316,11 +306,10 @@ compareterms(Term *t1, Term *t2) } int -builtincompare(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincompare(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); Term *order = goal->children; Term *t1 = order->next; Term *t2 = t1->next; @@ -339,11 +328,10 @@ builtincompare(Term *database, Term *goal, Goal **goals, Choicepoint **choicesta } int -builtinfunctor(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinfunctor(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); Term *term = goal->children; Term *name = term->next; @@ -378,11 +366,10 @@ builtinfunctor(Term *database, Term *goal, Goal **goals, Choicepoint **choicesta } int -builtinarg(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinarg(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); Term *n = goal->children; Term *term = n->next; @@ -416,11 +403,10 @@ listlength(Term *term) } int -builtinuniv(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinuniv(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); Term *term = goal->children; Term *list = term->next; @@ -491,11 +477,10 @@ aritheval(Term *expr) } int -builtinis(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinis(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); Term *result = goal->children; Term *expr = result->next; @@ -508,10 +493,9 @@ builtinis(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, B } int -builtincatch(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincatch(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); - USED(choicestack); USED(bindings); Term *catchgoal = goal->children; @@ -534,10 +518,9 @@ builtincatch(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack } int -builtinthrow(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinthrow(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); - USED(choicestack); USED(bindings); USED(goals); @@ -564,10 +547,10 @@ builtinthrow(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack *goals = newgoal; applybinding(newgoal->goal, *bindings); - Choicepoint *cp = *choicestack; + Choicepoint *cp = choicestack; while(cp != nil && cp->id >= goal->clausenr) cp = cp->next; - *choicestack = cp; + choicestack = cp; return 1; } } @@ -576,21 +559,19 @@ builtinthrow(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack } int -builtincurrentprologflag(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincurrentprologflag(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goal); USED(goals); - USED(choicestack); USED(bindings); return 0; } int -builtinsetprologflag(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinsetprologflag(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); - USED(choicestack); USED(bindings); Term *key = goal->children; Term *value = key->next; @@ -608,11 +589,10 @@ builtinsetprologflag(Term *database, Term *goal, Goal **goals, Choicepoint **cho } int -builtinopen(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinopen(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *sourcesink = goal->children; @@ -646,11 +626,10 @@ builtinopen(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, } int -builtinclose(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinclose(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; @@ -674,11 +653,10 @@ builtinclose(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack } int -builtincurrentinput(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincurrentinput(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; @@ -690,11 +668,10 @@ builtincurrentinput(Term *database, Term *goal, Goal **goals, Choicepoint **choi } int -builtincurrentoutput(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtincurrentoutput(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; @@ -706,11 +683,10 @@ builtincurrentoutput(Term *database, Term *goal, Goal **goals, Choicepoint **cho } int -builtinsetinput(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinsetinput(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; @@ -731,11 +707,10 @@ builtinsetinput(Term *database, Term *goal, Goal **goals, Choicepoint **choicest } int -builtinsetoutput(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinsetoutput(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; @@ -756,11 +731,10 @@ builtinsetoutput(Term *database, Term *goal, Goal **goals, Choicepoint **choices } int -builtinreadterm(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinreadterm(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; @@ -789,11 +763,10 @@ builtinreadterm(Term *database, Term *goal, Goal **goals, Choicepoint **choicest } int -builtinwriteterm(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) +builtinwriteterm(Term *database, Term *goal, Goal **goals, Binding **bindings) { USED(database); USED(goals); - USED(choicestack); USED(bindings); Term *stream = goal->children; |