fibers

parent b227dfa2
......@@ -59,6 +59,7 @@ PSSOURCES = \
logic/guile-log/hash-dynamic.scm \
logic/guile-log/dynamic-features.scm \
logic/guile-log/iinterleave.scm \
logic/guile-log/fiber.scm \
logic/guile-log/weak-vhash.scm \
logic/guile-log/prolog/varstat.scm \
logic/guile-log/prolog/pre.scm \
......@@ -115,6 +116,7 @@ PSSOURCES = \
logic/guile-log/guile-prolog/project.scm \
logic/guile-log/guile-prolog/interpreter.scm \
logic/guile-log/guile-prolog/engine.scm \
logic/guile-log/guile-prolog/fiber.scm \
logic/guile-log/guile-prolog/state.scm \
logic/guile-log/guile-prolog/postpone.scm \
logic/guile-log/guile-prolog/gc-call.scm \
......
......@@ -68,6 +68,9 @@ Version 0.6, TODO
* interpretter stores variables at stall DONE
* Improved iterator frmework for prolog DONE
* Types and type matching DONE
* prolog engines like in swi prolog DONE
* paralell and PARTIAL
* fibers DONE
* GC of the (almost) unreachable tail of a stream (all)
* Multi threading capabilities (all)
* Sandboxing (prolog)
......
......@@ -31,7 +31,16 @@ A 64 bit system
This is a draft for guile-2.0.6 and later and works for linux.
You need to have guile-syntax-parse installed into the system
http://gitorious.org/guile-syntax-parse/guile-syntax-parse
http://gitorious.org/guile-syntax-parse/guile-syntax-parse
For fibers you need to have wingo's fibers library
https://github.com/wingo/fibers/wiki/Manual
For correct garbage collection , engines and fibers you need
https://gitlab.com/bdw-gc-logical-mod/bdw-gc-logical-mod
If you want to hack the prolog VM (it is written in compiled scheme) you need
https://gitlab.com/clambda/clambda
You need autotools, texinfo, gcc, make, guile >= 2.0
Either do a system install:
......@@ -67,10 +76,14 @@ info guile-log at a system install.
For an Interactive prolog shell use
,L prolog
Else in doc/guile-log the documentation in html is available
Have fun!
Else in doc/guile-log the documentation in html is available or at
http://c-lambda.se/guile-log/
Also check out the blocg at
http://c-lambda.se/
There are a lot of material not included in the docs there
To enable proper gc and engine support se the installatoin instructions in the manual. That is difficult though, you need to compile the repository refferenced above and make sure that guile is using it. I ended up replacing the original so library with the new one (saving the old one in case there is bugs) Use this only if you know what you are doing.
Have fun!
......@@ -14,6 +14,7 @@
add-vhash-dynamics
add-dynamic-function-dynamics
add-dynamic-barrier
add-parameter-dynamics
mk-combine-dynamics
;; this can combine many dynamics into one dynamic
......@@ -176,7 +177,7 @@ used it is then a safe journey.
make-fluid
#:fail fail))
(define* (add-parameter-dynamics s p cc h const #:optional
(define* (add-parameter-dynamics s p cc h #:optional
(fail (mkf 'parameter)))
(add-dynamic-object-features s p cc h
procedure?
......
(define-module (logic guile-log fiber)
#:use-module (fibers)
#:use-module (fibers internal)
#:use-module (fibers channels)
#:use-module (logic guile-log dynamic-features)
#:use-module (logic guile-log)
#:export (scheduler <with-fibers> <spawn-fiber> <sleep>
<make-channel> <put-message> <get-message>))
(define scheduler
(let ((scheduler #f))
(case-lambda
(() (serialize-scheduler scheduler))
((state)
(if ((@@ (fibers internal) scheduler?) state)
(set! scheduler state)
(try-update-scheduler scheduler state))))))
(<wrap> add-parameter-dynamics scheduler)
(<define> (<with-fibers> thunk ret)
(<=> ret
,(run-fibers
(lambda ()
(scheduler (current-scheduler))
(thunk S (lambda () #f) (lambda x #t))))))
(define (mk-fiber f)
(case-lambda
(() (serialize-fiber f))
((s)
(if s
(update-fiber f s)
f))))
(<define> (<spawn-fiber> fiber <thunk>)
(let* ((f (spawn-fiber (lambda () (<thunk> S (lambda () #f) (lambda x #t)))))
(ff (mk-fiber f)))
(add-parameter-dynamics ff)
(<=> fiber ff)))
(<define> (<sleep> n) (<code> (sleep (<lookup> n))))
(define <make-channel>
(<case-lambda>
((ch) (<=> ch ,(make-channel)))
((ch n) (<=> ch ,(make-channel #:queue-size (<lookup> n))))))
(<define> (<put-message> ch message)
(<var> (out)
(<=> out ,(<cp> message))
(<code> (put-message (<lookup> ch) out))))
(<define> (<get-message> ch message)
(<=> message ,(get-message (<lookup> ch))))
......@@ -148,22 +148,40 @@
(set! path (gp-set-engine pth))
(gp-restore-engine-guards g))))))
(ret
(lambda (kind s . term)
(match kind
(#:run (start-f s))
(#:post (apply variable-set! postbox term))
(#:finish
(set! engine #f))
(#:set-state
(set! state s))
(#:set-engine
(set! engine (cadr state)))
(#:exist
(and engine
(match state
((#:throw . _) #f)
(#:exit #f)
(_ #t))))))))
(case-lambda
(()
(let* ((pth (gp-set-engine path))
(s (<state-ref>)))
(gp-set-engine pth)
(list s state path guards engine (variable-ref postbox))))
((l)
(match l
((s state_ path_ guards_ engine_ post_)
(set! state s)
(set! path path_)
(set! guards guards_)
(set! engine engine_)
(variable-set! postbox post_)
(<state-set> s))))
((kind s . term)
(match kind
(#:run (start-f s))
(#:post (apply variable-set! postbox term))
(#:finish
(set! engine #f))
(#:set-state
(set! state s))
(#:set-engine
(set! engine (cadr state)))
(#:exist
(and engine
(match state
((#:throw . _) #f)
(#:exit #f)
(_ #t)))))))))
(set-procedure-property! ret 'engine #t)
(set-procedure-property!
ret 'name (string->symbol (format #f "e<~a>" (name-it name))))
......
(define-module (logic guile-log guile-prolog fiber)
#:use-module (logic guile-log guile-prolog engine)
#:use-module (logic guile-log prolog goal-functors)
#:use-module (logic guile-log fiber)
#:use-module (logic guile-log)
#:export (with_fibers
spawn_fiber
sleep
make_channel
get_message
put_message))
(define with_fibers
(<case-lambda>
((goal ret)
(<with-fibers> (<lambda> () (goal-eval goal)) ret))
((goal)
(<var> (v) (with_fibers goal v)))))
(define spawn_fiber
(<case-lambda>
((goal fiber)
(<spawn-fiber> fiber
(<lambda> ()
(<var> (t engine v)
(engine_create t goal engine)
(engine_next engine v)
<fail>))))
((goal)
(<var> (v)
(spawn_fiber goal v)))))
(<define> (sleep x) (<sleep> x))
(<define> (make_channel . l) (<apply> <make-channel> l))
(<define> (put_message ch x) (<put-message> ch x))
(<define> (get_message ch x) (<get-message> ch x))
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# Makefile.in generated by automake 1.15 from Makefile.am.
# logic/guile-log/src/Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
# Copyright (C) 1994-2014 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
......@@ -16,7 +16,17 @@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
false; \
elif test -n '$(MAKE_HOST)'; then \
true; \
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
true; \
else \
false; \
fi; \
}
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
......@@ -80,8 +90,6 @@ POST_UNINSTALL = :
build_triplet = x86_64-unknown-linux-gnu
host_triplet = x86_64-unknown-linux-gnu
subdir = logic/guile-log/src
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/build-aux/depcomp $(noinst_HEADERS)
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
......@@ -89,6 +97,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \
$(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
......@@ -194,17 +204,19 @@ am__define_uniq_tagged_files = \
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
am__DIST_COMMON = $(srcdir)/Makefile.in \
$(top_srcdir)/build-aux/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /home/stis/src/guile-log/build-aux/missing aclocal-1.14
ACLOCAL = ${SHELL} /home/stis/src/guile-log/build-aux/missing aclocal-1.15
AMTAR = $${TAR-tar}
AM_DEFAULT_VERBOSITY = 0
AR = ar
AUTOCONF = ${SHELL} /home/stis/src/guile-log/build-aux/missing autoconf
AUTOHEADER = ${SHELL} /home/stis/src/guile-log/build-aux/missing autoheader
AUTOMAKE = ${SHELL} /home/stis/src/guile-log/build-aux/missing automake-1.14
AUTOMAKE = ${SHELL} /home/stis/src/guile-log/build-aux/missing automake-1.15
AWK = gawk
CC = gcc
CCDEPMODE = depmode=gcc3
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
CPP = gcc -E
CPPFLAGS =
......@@ -310,6 +322,7 @@ pdfdir = ${docdir}
prefix = /usr/local
program_transform_name = s,x,x,
psdir = ${docdir}
runstatedir = ${localstatedir}/run
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
srcdir = .
......@@ -318,11 +331,12 @@ target_alias =
top_build_prefix = ../../../
top_builddir = ../../..
top_srcdir = ../../..
extlibdir = $(libdir)/guile/2.2/extensions
extlibdir = /usr/local/lib/guile/2.2/extensions
extlib_LTLIBRARIES = libguile-log.la
GUILE_CFLAGS = -I/usr/local/include/guile/2.2 -lguile-2.2 -L/usr/local/lib/
AM_CFLAGS = -I$(srcdir) $(WARN_CFLAGS) $(DEBUG_CFLAGS)
libguile_log_la_SOURCES = unify.c
libguile_log_la_CFLAGS = -I/usr/local/include/guile/2.2 $(AM_CFLAGS) $(GUILE_CFLAGS)
libguile_log_la_CFLAGS = $(AM_CFLAGS) $(GUILE_CFLAGS)
libguile_log_la_LIBADD = $(GUILE_LIBS)
libguile_log_la_LDFLAGS = -export-dynamic -module -avoid-version
noinst_HEADERS = unify.h
......@@ -349,7 +363,6 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign logic/guile-log/src/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign logic/guile-log/src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
......@@ -659,6 +672,8 @@ uninstall-am: uninstall-extlibLTLIBRARIES
mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
uninstall-am uninstall-extlibLTLIBRARIES
.PRECIOUS: Makefile
.c.x:
guile-snarf $(GUILE_SNARF_CFLAGS) $< > $@ \
......
## The library
extlibdir = $(libdir)/guile/2.0/extensions
extlibdir = /usr/local/lib/guile/2.2/extensions
extlib_LTLIBRARIES = libguile-log.la
GUILE_CFLAGS = -I/usr/local/include/guile/2.2 -lguile-2.2 -L/usr/local/lib/
AM_CFLAGS = -I$(srcdir) $(WARN_CFLAGS) $(DEBUG_CFLAGS)
libguile_log_la_SOURCES = unify.c
......@@ -27,4 +30,4 @@ DOT_X_FILES = $(C_FILES:.c=.x)
BUILT_SOURCES = $(DOT_X_FILES)
CLEANFILES = $(DOT_X_FILES)
\ No newline at end of file
CLEANFILES = $(DOT_X_FILES)
......@@ -5,6 +5,7 @@
#:use-module (logic guile-log iso-prolog)
#:use-module (logic guile-log prolog swi)
#:use-module (logic guile-log guile-prolog engine)
#:use-module (logic guile-log guile-prolog fiber)
#:use-module (logic guile-log guile-prolog ops)
#:use-module (logic guile-log guile-prolog set)
#:use-module (logic guile-log guile-prolog attribute)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment