klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit a0b5ed0952269bd5f9573a199f4f7c6aa961de03
parent d1e8c3c67be5428edf456c3b8014b07574fc9edf
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri, 22 Jun 2012 19:43:02 -0300

Added 3 tests for eval/continuation-capturing/mutation interaction (2 of them fail).

Diffstat:
ACHANGES | 6++++++
MTODO | 2++
Msrc/tests/environments.k | 46++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/CHANGES b/CHANGES @@ -0,0 +1,5 @@ +v0.4 + +- Added eq-hashtables (Oto Havle) +- Fixed semantics of eval in the presence of continuation capturing + and mutation of the argument or result list +\ No newline at end of file diff --git a/TODO b/TODO @@ -25,6 +25,8 @@ *** add static qualifiers (especially in all kg*.c files) *** add const qualifiers where sensible ** fix: +- fix semantics of map, for-each, etc in the presence of continuation + capture and mutation of the underlying lists. - fix char-ready? and u8-ready? (r7rs) - Probably need a thread per port ** reader/writer diff --git a/src/tests/environments.k b/src/tests/environments.k @@ -60,6 +60,52 @@ ($let ((env ($bindings->environment (+ *)))) ($check equal? (eval ($quote (+ 1 1)) env) 1)) +; eval semantics in the presence of continuation capturing and +; mutation + +; This check will try to mutate the list argument to eval +; during the evaluation of the list to see if eval makes a +; copy of the list previous to start evaluating (this test +; contemplates the two more usual cases of left-to-right and +; right-to-left list evaluation) +($check equal? + ($let* ((ls (list list 1 #ignore 3)) + (mut-ls! ($lambda () + (set-car! (cdr ls) -1) + (set-car! (cdddr ls) -3) + 2))) + (set-car! (cddr ls) (list mut-ls!)) + (eval ls (get-current-environment))) + (list 1 2 3)) + +; This check will capture the continuation in the middle of list +; evaluation to see whether restarting the continuation later +; works as expected +($check equal? + ($let* ((cc ($lambda () ($let/cc cont cont))) + (ls (list list 1 (list cc) 3)) + (res (eval ls (get-current-environment))) + (cont (cddr res))) + (set-car! res -1) + (set-car! (cddr res) -3) + (apply-continuation cont 2)) + (list 1 2 3)) + +; This check is a combination of the last two. +; It will capture the continuation in the middle of list +; evaluation and later mutate the result list to see whether restarting +; the continuation later works as expected +($check equal? + ($let* ((cc ($lambda () ($let/cc cont cont))) + (ls (list list 1 (list cc) 3)) + (cont (cadr (eval ls (get-current-environment))))) + (apply-continuation cont 2)) + (list 1 2 3)) + +;; TODO add checks to also test what happens when cyclic lists are +;; mixed with continuation capturing and mutation + + ;; 4.8.4 make-environment ($check-predicate (applicative? make-environment))