Warning: session_start(): open(/var/lib/php/sessions/sess_v05g9lo8eccvkjs4b0ub40hqhq, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// Logic thread
static class LThread {
new L statements;
new SNLMatches m; // current variable assignments
L ops;
int opIdx;
new L output;
L log;
*(Lisp code) {
ops = splitOps(code);
}
boolean done() {
ret opIdx >= l(ops);
}
// returns false if failed
boolean step() {
Lisp code = ops.get(opIdx++);
boolean ok = stepImpl(code);
if (log != null)
log.add((ok ? "[OK] ": "[FAIL] ") + " step " + snlFromTree(code) + " with " + structure(m));
ret ok;
}
boolean stepImpl(Lisp code) {
if (code.isic("if *", "and *")) {
Lisp a = code.get(0);
Lisp b = snlApply(a, m.map);
// try all statements in context
for (Lisp s : statements) {
S x;
if (snlMatch2(b, s, m))
ret true;
}
// try the low-level engine
pcall {
if (yo(b, m)) // todo: rename vars
ret true;
}
// Not matched, fail
ret false;
}
if (code.isic("say *")) {
Lisp b = code.get(0);
//print ("m: " + structure (m) + ", b: " + structure (b));
output.add(snlApply(b, m.map));
ret true;
}
if (code.isic("memorize *")) {
Lisp b = snlApply(code.get(0), m.map);
callOpt(mc(), "memorize", b);
ret true;
}
// unknown code
ret false;
}
// true if succeeded, false if failed
boolean run() {
while (!done())
if (!step()) {
print("fail");
ret false;
}
ret true;
}
// split smth like "if * then *" into "if *" and "then *"
L splitOps(Lisp code) {
S ops = code.head;
L tok = codeTokensOnly(javaTok(ops));
new L out;
for (int i = 0; i < l(tok); i += 2) {
S op = tok.get(i);
assertEquals("*", tok.get(i+1));
out.add(lisp(op + " *", code.get(i/2)));
}
print("splitOps => " + structure(out));
ret out;
}
}