mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-16 00:30:21 +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:
parent
46abd569d5
commit
4530432e01
5 changed files with 24 additions and 5 deletions
|
@ -756,6 +756,10 @@ Push @code{#f} onto the stack.
|
||||||
Push @code{#t} onto the stack.
|
Push @code{#t} onto the stack.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn Instruction make-nil
|
||||||
|
Push @code{%nil} onto the stack.
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn Instruction make-eol
|
@deffn Instruction make-eol
|
||||||
Push @code{'()} onto the stack.
|
Push @code{'()} onto the stack.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
|
@ -107,6 +107,12 @@ VM_DEFINE_INSTRUCTION (8, make_false, "make-false", 0, 0, 1)
|
||||||
NEXT;
|
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)
|
VM_DEFINE_INSTRUCTION (9, make_eol, "make-eol", 0, 0, 1)
|
||||||
{
|
{
|
||||||
PUSH (SCM_EOL);
|
PUSH (SCM_EOL);
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
(define (object->assembly x)
|
(define (object->assembly x)
|
||||||
(cond ((eq? x #t) `(make-true))
|
(cond ((eq? x #t) `(make-true))
|
||||||
((eq? x #f) `(make-false))
|
((eq? x #f) `(make-false))
|
||||||
|
((eq? x %nil) `(make-nil))
|
||||||
((null? x) `(make-eol))
|
((null? x) `(make-eol))
|
||||||
((and (integer? x) (exact? x))
|
((and (integer? x) (exact? x))
|
||||||
(cond ((and (<= -128 x) (< x 128))
|
(cond ((and (<= -128 x) (< x 128))
|
||||||
|
@ -131,6 +132,7 @@
|
||||||
(pmatch code
|
(pmatch code
|
||||||
((make-true) #t)
|
((make-true) #t)
|
||||||
((make-false) #f) ;; FIXME: Same as the `else' case!
|
((make-false) #f) ;; FIXME: Same as the `else' case!
|
||||||
|
((make-nil) %nil)
|
||||||
((make-eol) '())
|
((make-eol) '())
|
||||||
((make-int8 ,n)
|
((make-int8 ,n)
|
||||||
(if (< n 128) n (- n 256)))
|
(if (< n 128) n (- n 256)))
|
||||||
|
|
|
@ -35,6 +35,11 @@
|
||||||
props))))
|
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
|
; Compile a symbol expression. This is a variable reference or maybe some
|
||||||
; special value like nil.
|
; special value like nil.
|
||||||
|
|
||||||
|
@ -42,7 +47,7 @@
|
||||||
(case sym
|
(case sym
|
||||||
|
|
||||||
((nil)
|
((nil)
|
||||||
(make-const loc #f))
|
(nil-value loc))
|
||||||
|
|
||||||
((t)
|
((t)
|
||||||
(make-const loc #t))
|
(make-const loc #t))
|
||||||
|
@ -63,7 +68,7 @@
|
||||||
((if ,condition ,ifclause)
|
((if ,condition ,ifclause)
|
||||||
(make-conditional loc (compile-expr condition)
|
(make-conditional loc (compile-expr condition)
|
||||||
(compile-expr ifclause)
|
(compile-expr ifclause)
|
||||||
(make-const loc #f)))
|
(nil-value loc)))
|
||||||
((if ,condition ,ifclause ,elseclause)
|
((if ,condition ,ifclause ,elseclause)
|
||||||
(make-conditional loc (compile-expr condition)
|
(make-conditional loc (compile-expr condition)
|
||||||
(compile-expr ifclause)
|
(compile-expr ifclause)
|
||||||
|
@ -79,14 +84,14 @@
|
||||||
clauses))
|
clauses))
|
||||||
(let iterate ((tail clauses))
|
(let iterate ((tail clauses))
|
||||||
(if (null? tail)
|
(if (null? tail)
|
||||||
(make-const loc #f)
|
(nil-value loc)
|
||||||
(let ((cur (car tail)))
|
(let ((cur (car tail)))
|
||||||
(make-conditional loc
|
(make-conditional loc
|
||||||
(compile-expr (car cur))
|
(compile-expr (car cur))
|
||||||
(make-sequence loc (map compile-expr (cdr cur)))
|
(make-sequence loc (map compile-expr (cdr cur)))
|
||||||
(iterate (cdr tail)))))))
|
(iterate (cdr tail)))))))
|
||||||
|
|
||||||
((and) (make-const loc #t))
|
((and) (nil-value loc))
|
||||||
((and . ,expressions)
|
((and . ,expressions)
|
||||||
(let iterate ((tail expressions))
|
(let iterate ((tail expressions))
|
||||||
(if (null? (cdr tail))
|
(if (null? (cdr tail))
|
||||||
|
@ -94,7 +99,7 @@
|
||||||
(make-conditional loc
|
(make-conditional loc
|
||||||
(compile-expr (car tail))
|
(compile-expr (car tail))
|
||||||
(iterate (cdr tail))
|
(iterate (cdr tail))
|
||||||
(make-const loc #f)))))
|
(nil-value loc)))))
|
||||||
|
|
||||||
(('quote ,val)
|
(('quote ,val)
|
||||||
(make-const loc val))
|
(make-const loc val))
|
||||||
|
|
|
@ -131,6 +131,8 @@
|
||||||
(lp (cdr in) stack out (1+ pos)))
|
(lp (cdr in) stack out (1+ pos)))
|
||||||
((make-false)
|
((make-false)
|
||||||
(lp (cdr in) (cons #f stack) out (1+ pos)))
|
(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)
|
((load-program ,a ,b ,c ,d ,labels ,sublen ,meta . ,body)
|
||||||
(lp (cdr in)
|
(lp (cdr in)
|
||||||
(cons (decompile-load-program a b c d (decompile-meta meta)
|
(cons (decompile-load-program a b c d (decompile-meta meta)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue