diff --git a/doc/ref/vm.texi b/doc/ref/vm.texi index fe5c1eeb4..b64c2a675 100644 --- a/doc/ref/vm.texi +++ b/doc/ref/vm.texi @@ -1,6 +1,6 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. -@c Copyright (C) 2008,2009 +@c Copyright (C) 2008,2009,2010 @c Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @@ -678,14 +678,12 @@ and arguments off the stack, and push the result of calling @code{scm_apply}. @end deffn -@deffn Instruction goto/args nargs +@deffn Instruction tail-call nargs Like @code{call}, but reusing the current continuation. This instruction implements tail calls as required by RnRS. -For compiled procedures, that means that @code{goto/args} simply +For compiled procedures, that means that @code{tail-call} simply shuffles down the procedure and arguments to the current stack frame. -The @code{goto/*} instruction family is named as it is because tail -calls are equivalent to @code{goto}, along with relabeled variables. For non-VM procedures, the result is the same, but the current VM invocation remains on the C stack. True tail calls are not currently @@ -693,16 +691,16 @@ possible between compiled and non-compiled procedures. @end deffn @deffn Instruction apply nargs -@deffnx Instruction goto/apply nargs -Like @code{call} and @code{goto/args}, except that the top item on the +@deffnx Instruction tail-apply nargs +Like @code{call} and @code{tail-call}, except that the top item on the stack must be a list. The elements of that list are then pushed on the stack and treated as additional arguments, replacing the list itself, then the procedure is invoked as usual. @end deffn @deffn Instruction call/nargs -@deffnx Instruction goto/nargs -These are like @code{call} and @code{goto/args}, except they take the +@deffnx Instruction tail-call/nargs +These are like @code{call} and @code{tail-call}, except they take the number of arguments from the stack instead of the instruction stream. These instructions are used in the implementation of multiple value returns, where the actual number of values is pushed on the stack. @@ -767,7 +765,7 @@ Signals an error if there is an insufficient number of values. @end deffn @deffn Instruction call/cc -@deffnx Instruction goto/cc +@deffnx Instruction tail-call/cc Capture the current continuation, and then call (or tail-call) the procedure on the top of the stack, with the continuation as the argument. diff --git a/libguile/vm-i-system.c b/libguile/vm-i-system.c index a12f46570..99c638192 100644 --- a/libguile/vm-i-system.c +++ b/libguile/vm-i-system.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001,2008,2009 Free Software Foundation, Inc. +/* Copyright (C) 2001,2008,2009,2010 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -808,11 +808,11 @@ VM_DEFINE_INSTRUCTION (54, call, "call", 1, -1, 1) goto vm_error_wrong_type_apply; } -VM_DEFINE_INSTRUCTION (55, goto_args, "goto/args", 1, -1, 1) +VM_DEFINE_INSTRUCTION (55, tail_call, "tail-call", 1, -1, 1) { register SCM x; nargs = FETCH (); - vm_goto_args: + vm_tail_call: x = sp[-nargs]; VM_HANDLE_INTERRUPTS; @@ -850,7 +850,7 @@ VM_DEFINE_INSTRUCTION (55, goto_args, "goto/args", 1, -1, 1) if (SCM_STRUCTP (x) && SCM_STRUCT_APPLICABLE_P (x)) { sp[-nargs] = SCM_STRUCT_PROCEDURE (x); - goto vm_goto_args; + goto vm_tail_call; } /* * Other interpreted or compiled call @@ -886,13 +886,13 @@ VM_DEFINE_INSTRUCTION (55, goto_args, "goto/args", 1, -1, 1) goto vm_error_wrong_type_apply; } -VM_DEFINE_INSTRUCTION (56, goto_nargs, "goto/nargs", 0, 0, 1) +VM_DEFINE_INSTRUCTION (56, tail_call_nargs, "tail-call/nargs", 0, 0, 1) { SCM x; POP (x); nargs = scm_to_int (x); /* FIXME: should truncate values? */ - goto vm_goto_args; + goto vm_tail_call; } VM_DEFINE_INSTRUCTION (57, call_nargs, "call/nargs", 0, 0, 1) @@ -995,7 +995,7 @@ VM_DEFINE_INSTRUCTION (59, apply, "apply", 1, -1, 1) goto vm_call; } -VM_DEFINE_INSTRUCTION (60, goto_apply, "goto/apply", 1, -1, 1) +VM_DEFINE_INSTRUCTION (60, tail_apply, "tail-apply", 1, -1, 1) { int len; SCM ls; @@ -1011,7 +1011,7 @@ VM_DEFINE_INSTRUCTION (60, goto_apply, "goto/apply", 1, -1, 1) PUSH_LIST (ls, SCM_NULL_OR_NIL_P); nargs += len - 2; - goto vm_goto_args; + goto vm_tail_call; } VM_DEFINE_INSTRUCTION (61, call_cc, "call/cc", 0, 1, 1) @@ -1051,7 +1051,7 @@ VM_DEFINE_INSTRUCTION (61, call_cc, "call/cc", 0, 1, 1) } } -VM_DEFINE_INSTRUCTION (62, goto_cc, "goto/cc", 0, 1, 1) +VM_DEFINE_INSTRUCTION (62, tail_call_cc, "tail-call/cc", 0, 1, 1) { int first; SCM proc, cont; @@ -1065,7 +1065,7 @@ VM_DEFINE_INSTRUCTION (62, goto_cc, "goto/cc", 0, 1, 1) PUSH (proc); PUSH (cont); nargs = 1; - goto vm_goto_args; + goto vm_tail_call; } else if (SCM_VALUESP (cont)) { diff --git a/module/language/glil/decompile-assembly.scm b/module/language/glil/decompile-assembly.scm index 916353818..9e3a00b58 100644 --- a/module/language/glil/decompile-assembly.scm +++ b/module/language/glil/decompile-assembly.scm @@ -1,6 +1,6 @@ ;;; Guile VM code converters -;; Copyright (C) 2001, 2009 Free Software Foundation, Inc. +;; Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc. ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -183,9 +183,9 @@ (cons (make-glil-call 'mul 2) (emit-constants (list-head stack 2) out)) (+ pos 1))) - ((goto/args ,n) + ((tail-call ,n) (lp (cdr in) (list-tail stack (1+ n)) - (cons (make-glil-call 'goto/args n) + (cons (make-glil-call 'tail-call n) (emit-constants (list-head stack (1+ n)) out)) (+ pos 2))) (else (error "unsupported decompilation" (car in))))))))) diff --git a/module/language/tree-il/compile-glil.scm b/module/language/tree-il/compile-glil.scm index a79be410c..32c5b03f6 100644 --- a/module/language/tree-il/compile-glil.scm +++ b/module/language/tree-il/compile-glil.scm @@ -1,6 +1,6 @@ ;;; TREE-IL -> GLIL compiler -;; Copyright (C) 2001,2008,2009 Free Software Foundation, Inc. +;; Copyright (C) 2001,2008,2009,2010 Free Software Foundation, Inc. ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -277,7 +277,7 @@ ((tail) (comp-push proc) (for-each comp-push args) - (emit-code src (make-glil-call 'goto/apply (1+ (length args))))) + (emit-code src (make-glil-call 'tail-apply (1+ (length args))))) ((push) (emit-code src (make-glil-call 'new-frame 0)) (comp-push proc) @@ -344,12 +344,12 @@ (comp-push producer) (emit-code src (make-glil-mv-call 0 MV)) (case context - ((tail) (emit-code src (make-glil-call 'goto/args 1))) + ((tail) (emit-code src (make-glil-call 'tail-call 1))) (else (emit-code src (make-glil-call 'call 1)) (emit-branch #f 'br POST))) (emit-label MV) (case context - ((tail) (emit-code src (make-glil-call 'goto/nargs 0))) + ((tail) (emit-code src (make-glil-call 'tail-call/nargs 0))) (else (emit-code src (make-glil-call 'call/nargs 0)) (emit-label POST) (if (eq? context 'drop) @@ -362,7 +362,7 @@ (case context ((tail) (comp-push (car args)) - (emit-code src (make-glil-call 'goto/cc 1))) + (emit-code src (make-glil-call 'tail-call/cc 1))) ((vals) (comp-vals (make-application @@ -482,7 +482,7 @@ (for-each comp-push args) (let ((len (length args))) (case context - ((tail) (emit-code src (make-glil-call 'goto/args len))) + ((tail) (emit-code src (make-glil-call 'tail-call len))) ((push) (emit-code src (make-glil-call 'call len)) (maybe-emit-return)) ((vals) (emit-code src (make-glil-mv-call len MVRA)) diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test index 3fe68652a..f7cc75be0 100644 --- a/test-suite/tests/tree-il.test +++ b/test-suite/tests/tree-il.test @@ -1,7 +1,7 @@ ;;;; tree-il.test --- test suite for compiling tree-il -*- scheme -*- ;;;; Andy Wingo --- May 2009 ;;;; -;;;; Copyright (C) 2009 Free Software Foundation, Inc. +;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -69,7 +69,7 @@ (with-test-prefix "application" (assert-tree-il->glil (apply (toplevel foo) (const 1)) - (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (const 1) (call goto/args 1))) + (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (const 1) (call tail-call 1))) (assert-tree-il->glil (begin (apply (toplevel foo) (const 1)) (void)) (program () (std-prelude 0 0 #f) (label _) (call new-frame 0) (toplevel ref foo) (const 1) (mv-call 1 ,l1) @@ -81,7 +81,7 @@ (assert-tree-il->glil (apply (toplevel foo) (apply (toplevel bar))) (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (call new-frame 0) (toplevel ref bar) (call call 0) - (call goto/args 1)))) + (call tail-call 1)))) (with-test-prefix "conditional" (assert-tree-il->glil @@ -457,7 +457,7 @@ (with-test-prefix "apply" (assert-tree-il->glil (apply (primitive @apply) (toplevel foo) (toplevel bar)) - (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (toplevel ref bar) (call goto/apply 2))) + (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (toplevel ref bar) (call tail-apply 2))) (assert-tree-il->glil (begin (apply (primitive @apply) (toplevel foo) (toplevel bar)) (void)) (program () (std-prelude 0 0 #f) (label _) @@ -471,12 +471,12 @@ (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (call new-frame 0) (toplevel ref bar) (toplevel ref baz) (call apply 2) - (call goto/args 1)))) + (call tail-call 1)))) (with-test-prefix "call/cc" (assert-tree-il->glil (apply (primitive @call-with-current-continuation) (toplevel foo)) - (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (call goto/cc 1))) + (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (call tail-call/cc 1))) (assert-tree-il->glil (begin (apply (primitive @call-with-current-continuation) (toplevel foo)) (void)) (program () (std-prelude 0 0 #f) (label _) @@ -491,7 +491,7 @@ (program () (std-prelude 0 0 #f) (label _) (toplevel ref foo) (toplevel ref bar) (call call/cc 1) - (call goto/args 1)))) + (call tail-call 1)))) (with-test-prefix "tree-il-fold"