home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Vectronix 2
/
VECTRONIX2.iso
/
FILES_01
/
X_PROLOG.LZH
/
X_PROLOG
/
SOURCES
/
BISYS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-13
|
7KB
|
331 lines
/*
* X PROLOG Vers. 2.0
*
*
* Written by : Andreas Toenne
* CS Dept. , IRB
* University of Dortmund, W-Germany
* <at@unido.uucp>
* <....!seismo!unido!at>
* <at@unido.bitnet>
*
* Copyright : This software is copyrighted by Andreas Toenne.
* Permission is granted hereby to copy the entire
* package including this copyright notice without fee.
*
*/
#include "prolog.h"
#include "error.h"
#include "extern.h"
#ifdef ATARI
#include <osbind.h>
#endif
#ifdef VAX
#include <sys/types.h>
#include <sys/times.h>
#endif
extern term *term_copy(); /* terms */
extern functor *get_functor(); /* functor */
extern term *argument(); /* terms */
extern void bind_2_vars(); /* terms */
extern term *int_copy(); /* terms */
extern term *var_copy(); /* terms */
short bihalt(/* args */)
/* term *args[]; */
{
puts("X Prolog halted.");
exit(0);
}
short bish(/* args */)
/* term *args[]; */
{
if (system("msh") != 0)
return(FALSE);
else
return(TRUE);
}
/* SYSTEM ( term ) */
short bisystem(args)
term *args[];
{
if (! ISATOM(args[0]))
BIERROR(EBAD);
if (system(NAME(args[0])) != 0)
return(FALSE);
else
return(TRUE);
}
/* STATISTICS */
short bistatistics(/* args */)
/* term *args; */
{
term *t;
register char *c;
long i;
printf("\n\t\t\t********* X Prolog Statistics *********\n\n");
printf("Prototype Space:\t%ld bytes free of %ld bytes\n",
(long)protofull-(long)protonext, (long)protofull-(long)protostack);
for (t=(term *)copyfull; t>=(term *)copystack && !t->flags; t--);
printf("Copystack:\t\t%ld bytes free of %ld bytes (min %ld)\n",
(long)copyfull-(long)copynext,(long)copyfull-(long)copystack,
(long)copyfull-(long)t);
printf("Clause Space:\t\t%ld clauses free of %ld\n",
clausefull-(long)(clausenext-clausesp), clausefull);
printf("Functor Space:\t\t%ld bytes free of %ld\n",
(long)functorfull-(long)functornext,
(long)functorfull-(long)functorsp);
for (c=stackfull; c>stacktop && !*c; c--, c--, c--);
printf("Local Stack:\t\t%ld bytes free of %ld (min %ld)\n",
(long)stackfull-(long)stacktop, (long)stackfull-(long)stack,
(long)stackfull-(long)c);
for (i=trailfull-1; i>=0 && !trailstack[i]; i--);
printf("Trail Stack:\t\t%ld trails free of %ld (min %ld)\n",
trailfull-trailtop, trailfull, trailfull-i);
return(TRUE);
}
/* PROMPT ( old, new ) */
short biprompt(args)
term *args[];
{
short res = TRUE;
if (!ISATOM(args[1]) &&
(args[0] != args[1]))
BIERROR(EBAD);
if (ISVAR(args[0]))
{
BIND_VAR(args[0], prompt);
}
else
res = (FUNC(args[0]) == FUNC(prompt));
if (res)
prompt = args[1];
return(res);
}
/* $PROMPT( prompt ) */
/* Neccessary to reset lastc after our last get */
short bidollarprompt(args)
term *args[];
{
if (!ISATOM(args[0]))
BIERROR(EBAD);
lastc = ' ';
if (FUNC(in->atom) != USERFUNCTOR)
return(TRUE);
fprintf(stdout, "%s", NAME(args[0]));
return(TRUE);
}
/* DEBUG */
short bidebug( /* args */ )
/* term *args[]; */
{
dodebug = TRUE;
return(TRUE);
}
/* NODEBUG */
short binodebug( /* args */ )
/* term *args[]; */
{
dodebug = FALSE;
return(TRUE);
}
/* $goalvars ( var ) */
short bidollargoalvars(args)
term *args[];
{
register term *t,*p;
register short i=0;
if (!ISVAR(args[0]))
BIERROR(EBAD);
if (!tide) /* no vars read */
{
BIND_VAR(args[0], NILATOM);
return(TRUE);
}
p = term_copy(DOTFUNCTOR);
t = p;
do
{
ARG(t,1) = term_copy(COMMAFUNCTOR);
ARG(ARG(t,1),1) = term_copy(get_functor(l_table[i].name,0));
ARG(ARG(t,1),2) = l_table[i].t;
i++;
if (i<tide)
{
ARG(t,2) = term_copy(DOTFUNCTOR);
t = ARG(t,2);
}
} while (i < tide);
ARG(t,2) = NILATOM;
BIND_VAR(args[0], p);
return(TRUE);
}
/* $more */
short bidollarmore(args)
term *args[];
{
term *t;
if (!ISVAR(args[0]))
BIERROR(EBAD);
if (Backpoint->frozen_env > Topenv->pre)
t = term_copy(get_functor("yes",0));
else
t = term_copy(get_functor("no",0));
BIND_VAR(args[0], t);
return(TRUE);
}
/* CPUTIME */
/* Primitive for bimath. Returns count of milliseconds since start of */
/* Prolog. */
/* Note! Atari dependent */
#ifdef ATARI
long current_tic() /* return value of $4BA */
{
return(*(long *)0x4ba);
}
void init_cputime() /* for the very first time */
{
s_time = Supexec(current_tic);
}
long cputime()
{
return((Supexec(current_tic)-s_time)*5); /* 200 Hz tic */
}
#endif ATARI
#ifdef VAX
struct tms tb;
void init_cputime()
{
}
long cputime()
{
times(&tb);
return(tb.tms_utime * 16);
}
#endif
/* HIDE ( list of predicates ) */
short bihide(args)
term *args[];
{
register term *t = args[0];
if (!ISSTRUCT(t) || FUNC(t) != DOTFUNCTOR)
BIERROR(EBAD);
while (FUNC(t) == DOTFUNCTOR)
{
if (!ISSTRUCT(argument(t, Topenv, 1)))
return(FALSE);
FUNC(argument(t, Topenv, 1))->flags |= HIDDEN;
t = argument(t, Topenv, 2);
}
return(TRUE);
}
/* PROTECT ( list of predicates ) */
short biprotect(args)
term *args[];
{
register term *t = args[0];
if (!ISSTRUCT(t) || FUNC(t) != DOTFUNCTOR)
BIERROR(EBAD);
while (FUNC(t) == DOTFUNCTOR)
{
if (!ISSTRUCT(argument(t, Topenv, 1)))
return(FALSE);
FUNC(argument(t, Topenv, 1))->flags |= PROTECTED;
t = argument(t, Topenv, 2);
}
return(TRUE);
}
/* REVEAL ( list of predicates ) */
short bireveal(args)
term *args[];
{
register term *t = args[0];
if (!ISSTRUCT(t) || FUNC(t) != DOTFUNCTOR)
BIERROR(EBAD);
while (FUNC(t) == DOTFUNCTOR)
{
if (!ISSTRUCT(argument(t, Topenv, 1)))
return(FALSE);
FUNC(argument(t, Topenv, 1))->flags &= ~HIDDEN;
t = argument(t, Topenv, 2);
}
return(TRUE);
}
/* UNPROTECT ( list of predicates ) */
short biunprotect(args)
term *args[];
{
register term *t = args[0];
if (!ISSTRUCT(t) || FUNC(t) != DOTFUNCTOR)
BIERROR(EBAD);
while (FUNC(t) == DOTFUNCTOR)
{
if (!ISSTRUCT(argument(t, Topenv, 1)))
return(FALSE);
FUNC(argument(t, Topenv, 1))->flags &= ~PROTECTED;
t = argument(t, Topenv, 2);
}
return(TRUE);
}