change library(random) to use O'Keefe code.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@80 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2001-06-11 20:20:36 +00:00
parent 96ae69e8d6
commit 90c92979c6
9 changed files with 2718 additions and 6046 deletions

View File

@@ -0,0 +1,88 @@
#
# default base directory for YAP installation
#
ROOTDIR = @prefix@
#
# where the binary should be
#
BINDIR = $(ROOTDIR)/bin
#
# where YAP should look for libraries
#
LIBDIR=$(ROOTDIR)/lib/Yap
#
#
CC=@CC@
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include
#
#
# You shouldn't need to change what follows.
#
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
SHELL=/bin/sh
RANLIB=@RANLIB@
srcdir=@srcdir@
SHLIB_CFLAGS=@SHLIB_CFLAGS@
SHLIB_SUFFIX=@SHLIB_SUFFIX@
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
CWD=$(PWD)
#
OBJS=random.o
SOBJS=random@SHLIB_SUFFIX@
#in some systems we just create a single object, in others we need to
# create a libray
all: @NEWSHOBJ@
sobjs: $(SOBJS)
dll: random@SHLIB_SUFFIX@
random.o: $(srcdir)/random.c
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/random.c -o random.o
%.so: %.o
@SHLIB_LD@ -o $@ $<
random.so: random.o
@SHLIB_LD@ -o random.so random.o
#
# create a new DLL library on cygwin environments
#
# DLLNAME: name of the new dll
# OBJS: list of object files I want to put in
# LIBS: list of libraries to link with
# DEFFILE is the name of the definitions file.
# BASEFILE temporary
# EXPFILE temporary
# ENTRY is the entry point int WINAPI startup (HINSTANCE, DWORD, LPVOID)
#
DLLTOOL=dlltool
DLLNAME=random.dll
DLL_LIBS=-L /usr/lib/mingw -lmoldname -lcrtdll -lkernel32 -L../.. -lWYap
BASE_FILE=random.base
EXP_FILE=random.exp
DEF_FILE=$(srcdir)/random.def
ENTRY_FUNCTION=_win_random@12
#
random.dll: $(OBJS)
$(LD) -s --base-file $(BASE_FILE) --dll -o $(DLLNAME) $(OBJS) $(DLL_LIBS) -e $(ENTRY_FUNCTION)
$(DLLTOOL) --as=$(AS) --dllname $(DLLNAME) --def $(DEF_FILE) --base-file $(BASE_FILE) --output-exp $(EXP_FILE)
$(LD) -s --base-file $(BASE_FILE) $(EXP_FILE) -dll -o $(DLLNAME) $(OBJS) $(DLL_LIBS) -e $(ENTRY_FUNCTION)
$(DLLTOOL) --as=$(AS) --dllname $(DLLNAME) --def $(DEF_FILE) --base-file $(BASE_FILE) --output-exp $(EXP_FILE)
$(LD) $(EXP_FILE) --dll -o $(DLLNAME) $(OBJS) $(DLL_LIBS) -e $(ENTRY_FUNCTION)
install: all
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(LIBDIR)
install_mingw32: dll
$(INSTALL_PROGRAM) -m 755 random.dll $(LIBDIR)/random.dll
clean:
rm -f *.o *.so *~ $(OBJS) *.BAK

88
library/random/random.c Normal file
View File

@@ -0,0 +1,88 @@
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: regexp.c *
* Last rev: *
* mods: *
* comments: regular expression interpreter *
* *
*************************************************************************/
#include "config.h"
#include "c_interface.h"
#include <math.h>
void PROTO(init_random, (void));
static short a1 = 27314, b1 = 9213, c1 = 17773;
static int
p_random(void)
{
flt fli;
Int t1, t2, t3;
t1 = (a1 * 171) % 30269;
t2 = (b1 * 172) % 30307;
t3 = (c1 * 170) % 30323;
fli = (t1/30269.0) + (t2/30307.0) + (t3/30323.0);
a1 = t1;
b1 = t2;
c1 = t3;
return(unify(ARG1, MkFloatTerm(fli-(int)(fli))));
}
static int
p_setrand(void)
{
a1 = IntOfTerm(ARG1);
b1 = IntOfTerm(ARG2);
c1 = IntOfTerm(ARG3);
return(TRUE);
}
static int
p_getrand(void)
{
return(unify(ARG1,MkIntTerm(a1)) &&
unify(ARG2,MkIntTerm(b1)) &&
unify(ARG3,MkIntTerm(c1)));
}
void
init_random(void)
{
UserCPredicate("random", p_random, 1);
UserCPredicate("setrand", p_setrand, 3);
UserCPredicate("getrand", p_getrand, 3);
}
#ifdef _WIN32
#include <windows.h>
int WINAPI PROTO(win_random, (HANDLE, DWORD, LPVOID));
int WINAPI win_random(HANDLE hinst, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return 1;
}
#endif

View File

@@ -0,0 +1,2 @@
EXPORTS
init_random