meta & kernel

This commit is contained in:
Vitor Santos Costa 2018-02-01 01:44:34 +00:00
parent aaadd51309
commit 1cafba0529
11 changed files with 1353 additions and 955 deletions

View File

@ -917,7 +917,8 @@ static int interrupt_dexecute(USES_REGS1) {
static void undef_goal(USES_REGS1) {
PredEntry *pe = PredFromDefCode(P);
CELL *b;
CELL *b0;
BEGD(d0);
/* avoid trouble with undefined dynamic procedures */
/* I assume they were not locked beforehand */
@ -955,14 +956,23 @@ static void undef_goal(USES_REGS1) {
PP = NULL;
#endif
d0 = pe->ArityOfPE;
if (pe->ModuleOfPred == PROLOG_MODULE) {
if (CurrentModule == PROLOG_MODULE)
HR[0] = MkAtomTerm(Yap_LookupAtom("prolog"));
else
HR[0] = CurrentModule;
} else {
HR[0] = Yap_Module_Name(pe);
b = HR;
HR += 2;
}
b = b0 = HR;
HR += 2;
if (d0 == 0) {
b[1] = MkAtomTerm((Atom)(pe->FunctorOfPred));
} else {
b[1] = AbsAppl(HR);
b[1] = AbsAppl(b+2);
*HR++ = (CELL)pe->FunctorOfPred;
b += 3;
HR += d0;
BEGP(pt1);
pt1 = XREGS + 1;
for (; d0 > 0; --d0) {
@ -973,13 +983,13 @@ static void undef_goal(USES_REGS1) {
deref_head(d1, undef_unk);
undef_nonvar:
/* just copy it to the heap */
*HR++ = d1;
*b++ = d1;
continue;
derefa_body(d1, pt0, undef_unk, undef_nonvar);
if (pt0 <= HR) {
/* variable is safe */
*HR++ = (CELL)pt0;
*b++ = (CELL)pt0;
} else {
/* bind it, in case it is a local variable */
d1 = Unsigned(HR);
@ -993,8 +1003,8 @@ static void undef_goal(USES_REGS1) {
ENDP(pt1);
}
ENDD(d0);
ARG2 = Yap_getUnknownModule(Yap_GetModuleEntry(b[0]));
ARG1 = AbsPair(b);
ARG1 = AbsPair(b0);
ARG2 = Yap_getUnknownModule(Yap_GetModuleEntry(b0[0]));
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace)
low_level_trace(enter_pred, UndefCode, XREGS + 1);

View File

@ -269,7 +269,7 @@ static bool CommaCall(Term t, Term mod) {
}
inline static bool do_execute(Term t, Term mod USES_REGS) {
Term t0 = t;
Term t0 = t, mod0 = mod;
t = Yap_YapStripModule(t, &mod);
/* first do predicate expansion, even before you process signals.
This way you don't get to spy goal_expansion(). */
@ -278,7 +278,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
return EnterCreepMode(t, mod PASS_REGS);
}
if (IsVarTerm(t) || IsVarTerm(mod)) {
return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS);
return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS);
}
if (IsApplTerm(t)) {
register Functor f = FunctorOfTerm(t);
@ -290,9 +290,9 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
if (f == FunctorComma && false) {
Term t2 = ArgOfTerm(2, t);
if (IsVarTerm(t2))
return CallMetaCall(t, mod PASS_REGS);
return CallMetaCall(t0, mod0 PASS_REGS);
if (1 || !CommaCall(t2, mod))
return CallMetaCall(t, mod PASS_REGS);
return CallMetaCall(t0, mod0 PASS_REGS);
Term t1 = ArgOfTerm(1, t);
t = t1;
@ -301,11 +301,11 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
return do_execute(t, mod);
}
} else if (IsExtensionFunctor(f)) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS);
}
arity = ArityOfFunctor(f);
if (arity > MaxTemps) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS);
}
pen = RepPredProp(PredPropByFunc(f, mod));
/* You thought we would be over by now */
@ -315,7 +315,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
otherwise I would dereference the argument and
might skip a svar */
if (pen->PredFlags & (MetaPredFlag | UndefPredFlag)) {
return CallMetaCall(t, mod PASS_REGS);
return CallMetaCall(t0, mod0 PASS_REGS);
}
pt = RepAppl(t) + 1;
for (i = 1; i <= arity; i++) {
@ -346,7 +346,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
pe = RepPredProp(PredPropByAtom(a, mod));
return (CallPredicate(pe, B, pe->CodeOfPred PASS_REGS));
}
return CallMetaCall(t, mod PASS_REGS);
return CallMetaCall(t0, mod0 PASS_REGS);
}
static Term copy_execn_to_heap(Functor f, CELL *pt, unsigned int n,
@ -390,17 +390,17 @@ inline static bool do_execute_n(Term t, Term mod, unsigned int n USES_REGS) {
PredEntry *pen;
unsigned int i, arity;
int j = -n;
Term t0 = t;
Term t0 = t, mod0 = mod;
restart_exec:
if (IsVarTerm(t)) {
return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS);
return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS);
} else if (IsAtomTerm(t)) {
arity = n;
Name = AtomOfTerm(t);
pt = NULL;
} else if (IsIntTerm(t)) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
return CallError(TYPE_ERROR_CALLABLE, t, mod0 PASS_REGS);
} else if (IsPairTerm(t)) {
arity = n + 2;
pt = RepPair(t);
@ -415,9 +415,9 @@ restart_exec:
goto restart_exec;
} else {
if (IsVarTerm(tmod)) {
return CallError(INSTANTIATION_ERROR, t0, tmod PASS_REGS);
return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS);
} else {
return CallError(TYPE_ERROR_ATOM, t0, tmod PASS_REGS);
return CallError(TYPE_ERROR_ATOM, t0, mod0 PASS_REGS);
}
}
}
@ -427,7 +427,7 @@ restart_exec:
}
f = Yap_MkFunctor(Name, arity);
if (IsExtensionFunctor(f)) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS);
}
if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled) {
return EnterCreepMode(
@ -435,14 +435,14 @@ restart_exec:
mod PASS_REGS);
}
if (arity > MaxTemps) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
return CallError(TYPE_ERROR_CALLABLE, t0, mod0 PASS_REGS);
}
pen = RepPredProp(PredPropByFunc(f, mod));
/* You thought we would be over by now */
/* but no meta calls require special preprocessing */
if (pen->PredFlags & (MetaPredFlag | UndefPredFlag)) {
Term t = copy_execn_to_heap(f, pt, n, arity, mod PASS_REGS);
return (CallMetaCall(t, mod PASS_REGS));
// Term t = copy_execn_to_heap(f, pt, n, arity, mod PASS_REGS);
return (CallMetaCall(t0, mod0 PASS_REGS));
}
/* now let us do what we wanted to do from the beginning !! */
/* I cannot use the standard macro here because

File diff suppressed because it is too large Load Diff

View File

@ -77,7 +77,6 @@ static Int put_code(USES_REGS1);
static Int put_byte(USES_REGS1);
static Int skip(USES_REGS1);
static Int flush_output(USES_REGS1);
static Int flush_all_streams(USES_REGS1);
/**
* CharOfAtom: convert an atom into a single character.
@ -167,7 +166,6 @@ int Yap_peekWide(int sno) {
Int line = s->linecount;
Int lpos = s->linepos;
int ch = s->stream_wgetc(sno);
fprintf(stderr, "%d=%c\n", fileno(s->file), ch);
if (ch == EOF) {
if (s->file)
clearerr(s->file);
@ -183,7 +181,7 @@ int Yap_peekWide(int sno) {
s->linecount = line;
s->linepos = lpos;
s->stream_wgetc = Yap_popChar;
s->stream_getc = NU;
s->stream_getc = NULL;
s->stream_peek= NULL;
s->stream_wpeek= NULL;
s->stream_getc = Yap_popChar;
@ -214,7 +212,7 @@ int Yap_peekChar(int sno) {
s->linecount = line;
s->linepos = lpos;
s->stream_getc = Yap_popChar;
s->stream_wgetc = NU;
s->stream_wgetc = NULL;
s->stream_peek= NULL;
s->stream_wpeek= NULL;
//Yap_SetCurInpPos(sno, pos);
@ -262,7 +260,10 @@ static Int at_end_of_stream(USES_REGS1) { /* at_end_of_stream */
out = (Yap_peek(sno) < 0);
}
}
UNLOCK(GLOBAL_Stream[sno].streaml
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out;
}
/** @pred at_end_of_stream is iso

View File

@ -350,21 +350,19 @@ void Yap_DefaultStreamOps(StreamDesc *st) {
st->stream_getc = Yap_popChar;
st->stream_wgetc = Yap_popChar;
}
/*
if (st->file) {
if (st->status & Readline_Stream_f) {
if (st->status & Readline_Stream_f) {
st->stream_peek = Yap_ReadlinePeekChar;
st->stream_wpeek = Yap_ReadlinePeekChar;
} else {
}
/* else {
st->stream_peek = Yap_peekWithGetc;
st->stream_wpeek = Yap_peekWideWithGetwc;
}
} else if (st->status & Seekable_Stream_f) {
st->stream_peek = Yap_peekWithSeek;
st->stream_wpeek = Yap_peekWideWithSeek;
} else
*/
{
} */
else {
st->stream_peek = Yap_peekChar;
st->stream_wpeek = Yap_peekWide;
}

View File

@ -337,28 +337,30 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos) {
else {
tm = MkStringTerm("syntax error");
}
if (GLOBAL_Stream[sno].status & Seekable_Stream_f) {
if (errpos && newpos >= 0) {
char o[128 + 1];
diff = errpos - startpos;
if (diff > 128) {
diff = 128;
startpos = errpos - diff;
char o[128 + 1];
diff = errpos - startpos;
if (diff > 128) {
diff = 128;
startpos = errpos - diff;
}
#if HAVE_FTELLO
Int curpos = ftello(GLOBAL_Stream[sno].file);
fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
#else
Int curpos = ftell(GLOBAL_Stream[sno].file);
fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
#endif
fread(o, diff, 1, GLOBAL_Stream[sno].file);
#if HAVE_FTELLO
fseeko(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
#else
fseek(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
#endif
o[diff] = '\0';
tf[3] = MkStringTerm(o);
}
#if HAVE_FTELLO
Int curpos = ftello(GLOBAL_Stream[sno].file);
fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
#else
Int curpos = ftell(GLOBAL_Stream[sno].file);
fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
#endif
fread(o, diff, 1, GLOBAL_Stream[sno].file);
#if HAVE_FTELLO
fseeko(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
#else
fseek(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
#endif
o[diff] = '\0';
tf[3] = MkStringTerm(o);
} else {
while (tok) {

View File

@ -1,42 +1,18 @@
;(function(window_CodeMirror){
"use strict";
define([
"/kernelspecs/yap_kernel/prolog.js"],function(CodeMirror){
// the `require` namespace for codemirror
CM_PATH = "components/codemirror/";
define(
[
"underscore",
"jquery",
CM_PATH + "lib/codemirror",
"base/js/namespace",
// silent upgrades
"./jshint.js",
CM_PATH + "addon/lint/javascript-lint",
CM_PATH + "addon/hint/javascript-hint",
CM_PATH + "addon/lint/lint",
CM_PATH + "addon/hint/show-hint",
"./prolog.js"
],
function(_, $, CodeMirror, Jupyter){
// the main function
cm_tweak_js = function(cell){
var editor = cell.code_mirror,
opts = {},
meta = ensure_ns(cell),
keys = editor.getOption("extraKeys") || {},
mode = editor.getMode();
// only update editors we care about, reset ones we might have messed
if(!editor){
return;
} else {
editor.setOption("mode", "x-text/prolog");
}
}
}
} // the `define` callback
); // the `define`
).call(this, window.CodeMirror);
var onload = function(){
console.log("I am being loaded");
var cell = Jupyter.notebook.get_selected_cell();
var cm = cell.config;
var patch = {
CodeCell:{
cm_config:{mode: "prolog"} // only change here.
}
};
config.update(patch);
return {onload:onload};
}
}
);

View File

@ -524,7 +524,6 @@ class YAPRun:
return self.errors
def jupyter_query(self, s):
import pdb; pdb.set_trace()
#
# construct a self.query from a one-line string
# self.q is opaque to Python
@ -715,7 +714,7 @@ class YAPRun:
mcell = cell.lstrip('%')
txt0 = mcell.split(maxsplit = 2, sep = '\n')
txt = txt0[0].split(maxsplit = 2)
magic = txt[0]
magic = txt[0]
if len(txt) == 2:
line = txt[1]
else:

View File

@ -213,13 +213,12 @@ print_message(L,E) :-
).
:- c_compile('arith.yap').
:- c_compile('builtins.yap').
%:- stop_low_level_trace.
:- '$all_current_modules'(M), yap_flag(M:unknown, error) ; true.
:- '$init_prolog'.
:- '$all_current_modules'(M), yap_flag(M:unknown, error) ; true.
:- compile_expressions.
@ -230,6 +229,7 @@ print_message(L,E) :-
:- c_compile('preddecls.yap').
:- c_compile('preddyns.yap').
:- c_compile('meta.yap').
:- c_compile('builtins.yap').
:- c_compile('newmod.yap').
:- c_compile('atoms.yap').

View File

@ -498,7 +498,6 @@ expand_goal(Input, Output) :-
'$yap_strip_module'(M:GF0, MF, GF).
:- '$install_meta_predicate'((0,0),prolog,(','),2).
:- '$install_meta_predicate'((0),prolog,(','),2).
meta_predicate(P) :-
source_module(SM),

View File

@ -460,7 +460,8 @@ op(Prio,Assoc,Mod:Name),
; prolog_load_context(file, File) ->
recorda('$module','$module'(File,Mod,SourceF,[op(Prio,Assoc,Name)],Line),_)
; recorda('$module','$module'(user_input,Mod,user_input,[op(Prio,Assoc,Name)],1),_)
).export_resource(Resource) :-
).
export_resource(Resource) :-
'$do_error'(type_error(predicate_indicator,Resource),export(Resource)).
export_list(Module, List) :-