From 1bcbd5ce156b6ab257d4bfbe6d6894c1df19c980 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 25 Aug 2016 23:43:54 -0500 Subject: [PATCH 1/2] fix indexing when alloc is on floats. --- C/index.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/C/index.c b/C/index.c index 6074664d5..7722ab2f3 100755 --- a/C/index.c +++ b/C/index.c @@ -3640,6 +3640,7 @@ static yamop **expand_index(struct intermediates *cint) { if (s_reg[-1] != (CELL)FunctorDBREF) { ipc = alt; alt = NULL; + break; } t = AbsAppl(s_reg - 1); sp[-1].extra = t; @@ -3647,9 +3648,10 @@ static yamop **expand_index(struct intermediates *cint) { ipc = NEXTOP(ipc, e); break; case _index_blob: - if (s_reg[-1] != (CELL)FunctorBigInt) { + if (s_reg[-1] != (CELL)FunctorDouble) { ipc = alt; alt = NULL; + break; } t = Yap_DoubleP_key(s_reg); sp[-1].extra = AbsAppl(s_reg - 1); @@ -3660,6 +3662,7 @@ static yamop **expand_index(struct intermediates *cint) { if (s_reg[-1] != (CELL)FunctorLongInt) { ipc = alt; alt = NULL; + break; } t = Yap_IntP_key(s_reg); sp[-1].extra = AbsAppl(s_reg - 1); @@ -6583,14 +6586,16 @@ LogUpdClause *Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], case _index_dbref: if (s_reg[-1] != (CELL)FunctorDBREF) { ipc = FAILCODE; + break; } t = AbsAppl(s_reg - 1); blob_term = FALSE; ipc = NEXTOP(ipc, e); break; case _index_blob: - if (s_reg[-1] != (CELL)FunctorBigInt) { + if (s_reg[-1] != (CELL)FunctorDouble) { ipc = FAILCODE; + break; } t = Yap_DoubleP_key(s_reg); blob_term = TRUE; @@ -6599,6 +6604,7 @@ LogUpdClause *Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], case _index_long: if (s_reg[-1] != (CELL)FunctorLongInt) { ipc = FAILCODE; + break; } t = Yap_IntP_key(s_reg); blob_term = TRUE; From aba60111cff04dc175e71c530ea6617acdf41bd0 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 25 Aug 2016 23:44:36 -0500 Subject: [PATCH 2/2] more python interface. --- packages/python/yap_kernel/yap_kernel.py | 28 +++++--------- packages/python/yutils.py | 47 ------------------------ 2 files changed, 9 insertions(+), 66 deletions(-) delete mode 100644 packages/python/yutils.py diff --git a/packages/python/yap_kernel/yap_kernel.py b/packages/python/yap_kernel/yap_kernel.py index 7a11109f7..ee6fd369a 100644 --- a/packages/python/yap_kernel/yap_kernel.py +++ b/packages/python/yap_kernel/yap_kernel.py @@ -5,18 +5,8 @@ from ipykernel.ipkernel import IPythonKernel import sys import signal import yap - -import logging - -logger = logging.getLogger() -handler = logging.StreamHandler() -formatter = logging.Formatter( - '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') -handler.setFormatter(formatter) -logger.addHandler(handler) -logger.setLevel(logging.DEBUG) - -logger.debug('often makes a very good meal of %s', 'visiting tourists') +#import ipdb +#ipdb,set_trace() kernel_json = { "argv": [sys.executable, @@ -50,12 +40,7 @@ class YAPKernel(IPythonKernel): 'file_extension': '.yap', } - - def __init__(self, **kwargs): - super(YAPKernel, self).__init__( **kwargs) - _start_yap( **kwargs ) - - def _start_yap(self, **kwargs): + def init_yap(self, **kwargs): # Signal handlers are inherited by forked processes, and we can't easily # reset it from the subprocess. Since kernelapp ignores SIGINT except in # message handlers, we need to temporarily reset the SIGINT handler here @@ -71,11 +56,16 @@ class YAPKernel(IPythonKernel): finally: signal.signal(signal.SIGINT, sig) + def __init__(self, **kwargs): + super(YAPKernel, self).__init__( **kwargs) + self.init_yap( **kwargs ) + self.shell.run_cell = self.yap_run_cell + def get_usage(self): return "This is the YAP kernel." - def run_cell(self, s, store_history=False, silent=False, shell_futures=True): + def yap_run_cell(self, s, store_history=False, silent=False, shell_futures=True): if not self.q: self.q = self.engine.query(s) diff --git a/packages/python/yutils.py b/packages/python/yutils.py deleted file mode 100644 index 2eab9aa1e..000000000 --- a/packages/python/yutils.py +++ /dev/null @@ -1,47 +0,0 @@ -# python commands - -import sys -# import collections - -# generated by swig -import yap - -# make sure Python knows about engine -engine = None - -# Mappings between functors and types -# -# they are used to have the same type f1or several occurences -# of the same functor, and to ensure that an object is indeed -# a Prolog compound term. -# -dictF2P = {} - - -class A: - """Represents a non-interned Prolog atom""" - def __init__(self, s): - self.a = s - - def __repr__(self): - return "A(" + self.a + ")" - - def __str__(self): - return self.a - - -class V: - """Wraps a term, or a reference to a logical variables""" - def __init__(self, t): - print(type(t)) - self.v = t - - def __repr__(self): - return "V(" + str(self.v) + ")" - - def __str__(self): - return engine.getTerm(self.v).text() - - def handle(self): - return self.v -