1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-15 08:10:17 +02:00

Added make-nil instruction to VM and use it for Emacs' nil in the compiler.

* doc/ref/vm.texi: Document new instruction.
* libguile/vm-i-system.c: Add it to the VM.
* module/language/assembly.scm: Compile (const %nil) to (make-nil) assembly.
* module/language/glil/decompile-assembly.scm: Handle (make-nil)
* module/language/elisp/compile-tree-il.scm: Use (const %nil) for nil.
This commit is contained in:
Daniel Kraft 2009-06-29 13:16:27 +02:00
parent 46abd569d5
commit 4530432e01
5 changed files with 24 additions and 5 deletions

View file

@ -756,6 +756,10 @@ Push @code{#f} onto the stack.
Push @code{#t} onto the stack.
@end deffn
@deffn Instruction make-nil
Push @code{%nil} onto the stack.
@end deffn
@deffn Instruction make-eol
Push @code{'()} onto the stack.
@end deffn

View file

@ -107,6 +107,12 @@ VM_DEFINE_INSTRUCTION (8, make_false, "make-false", 0, 0, 1)
NEXT;
}
VM_DEFINE_INSTRUCTION (57, make_nil, "make-nil", 0, 0, 1)
{
PUSH (SCM_ELISP_NIL);
NEXT;
}
VM_DEFINE_INSTRUCTION (9, make_eol, "make-eol", 0, 0, 1)
{
PUSH (SCM_EOL);

View file

@ -106,6 +106,7 @@
(define (object->assembly x)
(cond ((eq? x #t) `(make-true))
((eq? x #f) `(make-false))
((eq? x %nil) `(make-nil))
((null? x) `(make-eol))
((and (integer? x) (exact? x))
(cond ((and (<= -128 x) (< x 128))
@ -131,6 +132,7 @@
(pmatch code
((make-true) #t)
((make-false) #f) ;; FIXME: Same as the `else' case!
((make-nil) %nil)
((make-eol) '())
((make-int8 ,n)
(if (< n 128) n (- n 256)))

View file

@ -35,6 +35,11 @@
props))))
; Value to use for Elisp's nil.
(define (nil-value loc) (make-const loc %nil))
; Compile a symbol expression. This is a variable reference or maybe some
; special value like nil.
@ -42,7 +47,7 @@
(case sym
((nil)
(make-const loc #f))
(nil-value loc))
((t)
(make-const loc #t))
@ -63,7 +68,7 @@
((if ,condition ,ifclause)
(make-conditional loc (compile-expr condition)
(compile-expr ifclause)
(make-const loc #f)))
(nil-value loc)))
((if ,condition ,ifclause ,elseclause)
(make-conditional loc (compile-expr condition)
(compile-expr ifclause)
@ -79,14 +84,14 @@
clauses))
(let iterate ((tail clauses))
(if (null? tail)
(make-const loc #f)
(nil-value loc)
(let ((cur (car tail)))
(make-conditional loc
(compile-expr (car cur))
(make-sequence loc (map compile-expr (cdr cur)))
(iterate (cdr tail)))))))
((and) (make-const loc #t))
((and) (nil-value loc))
((and . ,expressions)
(let iterate ((tail expressions))
(if (null? (cdr tail))
@ -94,7 +99,7 @@
(make-conditional loc
(compile-expr (car tail))
(iterate (cdr tail))
(make-const loc #f)))))
(nil-value loc)))))
(('quote ,val)
(make-const loc val))

View file

@ -131,6 +131,8 @@
(lp (cdr in) stack out (1+ pos)))
((make-false)
(lp (cdr in) (cons #f stack) out (1+ pos)))
((make-nil)
(lp (cdr in) (cons %nil stack) out (1+ pos)))
((load-program ,a ,b ,c ,d ,labels ,sublen ,meta . ,body)
(lp (cdr in)
(cons (decompile-load-program a b c d (decompile-meta meta)