summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-10-06 09:04:25 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-10-06 09:04:25 +0000
commit889c0f3df401e98a0d5839654f9d460cde49663e (patch)
tree61d87f903826a7350c0ce0d873a88a2ae27b4614
parent4e00834c68f85fe23abb9877dd3a372f2a215038 (diff)
partial implementation for the FAIL instruction
-rw-r--r--src/runtime/c/pgf/evaluator.c2
-rw-r--r--src/runtime/c/pgf/evaluator.h2
-rw-r--r--src/runtime/c/pgf/jit.c32
3 files changed, 35 insertions, 1 deletions
diff --git a/src/runtime/c/pgf/evaluator.c b/src/runtime/c/pgf/evaluator.c
index e5041adb0..a53279cb3 100644
--- a/src/runtime/c/pgf/evaluator.c
+++ b/src/runtime/c/pgf/evaluator.c
@@ -254,7 +254,7 @@ pgf_value2expr(PgfEvalState* state, int level, PgfClosure* clos, GuPool* pool)
PgfValue* val = (PgfValue*) clos;
expr = val->absfun->ep.expr;
- n_args = gu_seq_length(val->absfun->type->hypos);
+ n_args = val->absfun->arity;
args = val->args;
} else if (clos->code == state->eval_gates->evaluate_value_gen) {
PgfValueGen* val = (PgfValueGen*) clos;
diff --git a/src/runtime/c/pgf/evaluator.h b/src/runtime/c/pgf/evaluator.h
index 0e9236abb..ac314f602 100644
--- a/src/runtime/c/pgf/evaluator.h
+++ b/src/runtime/c/pgf/evaluator.h
@@ -79,6 +79,8 @@ struct PgfEvalGates {
PgfFunction update_closure;
PgfFunction update_pap;
+ PgfFunction mk_const;
+
PgfClosure* (*enter)(PgfEvalState* state, PgfClosure* closure);
GuFinalizer fin;
diff --git a/src/runtime/c/pgf/jit.c b/src/runtime/c/pgf/jit.c
index 056f3d872..3f1bb36dd 100644
--- a/src/runtime/c/pgf/jit.c
+++ b/src/runtime/c/pgf/jit.c
@@ -581,6 +581,36 @@ pgf_jit_gates(PgfReader* rdr)
jit_ldr_p(JIT_R0, JIT_VCLOS);
jit_jmpr(JIT_R0);
+ gates->mk_const = jit_get_ip().ptr;
+ jit_ldxi_p(JIT_R0, JIT_VHEAP, offsetof(PgfAbsFun,arity));
+ jit_muli_i(JIT_R0, JIT_R0, sizeof(PgfClosure*));
+ jit_pushr_i(JIT_R0);
+ jit_pushr_i(JIT_R0);
+ jit_prepare(2);
+ jit_addi_i(JIT_R0, JIT_R0, sizeof(PgfValue));
+ jit_pusharg_ui(JIT_R0);
+ jit_ldxi_p(JIT_R0, JIT_VSTATE, offsetof(PgfEvalState,pool));
+ jit_pusharg_p(JIT_R0);
+ jit_finish(gu_malloc);
+ jit_movi_p(JIT_R1, gates->evaluate_value);
+ jit_str_p(JIT_RET, JIT_R1);
+ jit_stxi_p(offsetof(PgfValue,absfun), JIT_RET, JIT_VHEAP);
+ jit_movr_p(JIT_VHEAP, JIT_RET);
+ jit_popr_i(JIT_R1);
+ next = jit_get_label();
+ ref = jit_blei_i(jit_forward(), JIT_R1, 0);
+ jit_ldxi_p(JIT_R2, JIT_FP, -sizeof(void*));
+ jit_stxi_p(offsetof(PgfValue,args), JIT_RET, JIT_R2);
+ jit_addi_i(JIT_RET, JIT_RET, sizeof(void*));
+ jit_subi_i(JIT_FP, JIT_FP, sizeof(void*));
+ jit_subi_i(JIT_R1, JIT_R1, sizeof(void*));
+ jit_jmpi(next);
+ jit_patch(ref);
+ jit_popr_p(JIT_R1);
+ jit_popr_p(JIT_R0);
+ jit_addr_i(JIT_SP, JIT_SP, JIT_R1);
+ jit_jmpr(JIT_R0);
+
gates->fin.fn = pgf_jit_finalize_defrules;
gates->defrules = NULL;
gu_pool_finally(rdr->opool, &gates->fin);
@@ -1111,6 +1141,8 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr,
#ifdef PGF_JIT_DEBUG
gu_printf(out, err, "FAIL\n");
#endif
+ jit_movi_p(JIT_VHEAP, absfun);
+ jit_jmpi(abstr->eval_gates->mk_const);
break;
default:
gu_impossible();