-
Notifications
You must be signed in to change notification settings - Fork 0
/
ground.h
39 lines (32 loc) · 877 Bytes
/
ground.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef GROUND_H_
#define GROUND_H_
#include "pred.h"
namespace {
// clears offset (it doesnt' matter, because result contains no vars)
inline Term ground(Term t) {
switch(t.type()) {
case Term::VAR: return Term(Fun::Builder(Fun::EXTRA_CONST,0).build());
case Term::FUN: {
Fun tf(t);
size_t ac = tf.arg_count();
Fun::Builder b(tf.fun(),ac);
for(size_t i=0; i<ac; ++i) b.set_arg(i,ground(tf.arg(i)));
return Term(b.build());
}
default: DEBUG error("unhandled t.type() = %",t.type());
}
}
// clears offset
inline Atom ground(Atom a) {
size_t ac = a.arg_count();
Atom::Builder b(a.sign(),a.pred(),ac,0);
for(size_t i=ac; i--;) b.set_arg(i,ground(a.arg(i)));
return b.build();
}
// clears offset
inline OrClause ground(OrClause cla) {
for(auto &a : cla.atoms) a = ground(a);
return cla;
}
}
#endif // GROUND_H_