From 5a8024ca82ce886eaee151ffda0d6a0e065fabd6 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 18 Oct 2018 20:06:10 +0200 Subject: [PATCH] mes: Move pair? to core. * src/lib.c (pair_p): New function. Gains 8% performance on MesCC. --- mes/module/mes/boot-0.scm.in | 1 - mes/module/mes/boot-01.scm | 1 - mes/module/mes/boot-02.scm | 1 - mes/module/mes/type-0.mes | 3 --- scaffold/boot/37-closure-lambda.scm | 3 --- scaffold/boot/38-simple-format.scm | 2 -- scaffold/boot/4c-quasiquote.scm | 5 ++--- scaffold/boot/60-let-syntax-expanded.scm | 1 - src/lib.c | 6 ++++++ 9 files changed, 8 insertions(+), 15 deletions(-) diff --git a/mes/module/mes/boot-0.scm.in b/mes/module/mes/boot-0.scm.in index 23af0059..d8b61bab 100644 --- a/mes/module/mes/boot-0.scm.in +++ b/mes/module/mes/boot-0.scm.in @@ -42,7 +42,6 @@ ;; end boot-00.scm ;; boot-01.scm -(define (pair? x) (eq? (core:type x) )) (define (not x) (if x #f #t)) (define (display x . rest) diff --git a/mes/module/mes/boot-01.scm b/mes/module/mes/boot-01.scm index 319d02dc..edad5e3c 100644 --- a/mes/module/mes/boot-01.scm +++ b/mes/module/mes/boot-01.scm @@ -32,7 +32,6 @@ ;; end boot-00.scm ;; boot-01.scm -(define (pair? x) (eq? (core:type x) )) (define (not x) (if x #f #t)) (define (display x . rest) diff --git a/mes/module/mes/boot-02.scm b/mes/module/mes/boot-02.scm index d437b09b..e400db43 100644 --- a/mes/module/mes/boot-02.scm +++ b/mes/module/mes/boot-02.scm @@ -42,7 +42,6 @@ ;; end boot-00.scm ;; boot-01.scm -(define (pair? x) (eq? (core:type x) )) (define (not x) (if x #f #t)) (define (display x . rest) diff --git a/mes/module/mes/type-0.mes b/mes/module/mes/type-0.mes index 4db75f9c..0a015994 100644 --- a/mes/module/mes/type-0.mes +++ b/mes/module/mes/type-0.mes @@ -75,9 +75,6 @@ (define (number? x) (eq? (core:type x) )) -(define (pair? x) - (eq? (core:type x) )) - (define (port? x) (eq? (core:type x) )) diff --git a/scaffold/boot/37-closure-lambda.scm b/scaffold/boot/37-closure-lambda.scm index 2ff04c1a..5f0b968c 100644 --- a/scaffold/boot/37-closure-lambda.scm +++ b/scaffold/boot/37-closure-lambda.scm @@ -16,9 +16,6 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Mes. If not, see . -(define (pair? x) - (eq? (core:type x) )) - (define (atom? x) (if (pair? x) #f (if (null? x) #f diff --git a/scaffold/boot/38-simple-format.scm b/scaffold/boot/38-simple-format.scm index 4a1f9a80..cca39ec0 100644 --- a/scaffold/boot/38-simple-format.scm +++ b/scaffold/boot/38-simple-format.scm @@ -16,8 +16,6 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Mes. If not, see . -(define (pair? x) (eq? (core:type x) )) - (define (not x) (if x #f #t)) (define-macro (or . x) diff --git a/scaffold/boot/4c-quasiquote.scm b/scaffold/boot/4c-quasiquote.scm index 5361991a..e5d3374b 100644 --- a/scaffold/boot/4c-quasiquote.scm +++ b/scaffold/boot/4c-quasiquote.scm @@ -16,7 +16,6 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Mes. If not, see . -(define (pair? x) (eq? (core:type x) )) (define (vector? x) (eq? (core:type x) )) @@ -85,7 +84,7 @@ ;; ((lambda (a d) ;; (core:display " a=") (core:display a) (core:display "\n") ;; (core:display " d=") (core:display d) - + ;; (if (pair? d) ;; (if (eq? (car d) 'quote) ;; (if (and (pair? a) (eq? (car a) 'quote)) @@ -133,7 +132,7 @@ (core:display "\n") (core:display "CDR d=") (core:display d) (core:display "\n") - + (if (pair? d) (if (eq? (car d) 'quote) (if (and (pair? a) (eq? (car a) 'quote)) diff --git a/scaffold/boot/60-let-syntax-expanded.scm b/scaffold/boot/60-let-syntax-expanded.scm index 8f84943f..9cec17fd 100644 --- a/scaffold/boot/60-let-syntax-expanded.scm +++ b/scaffold/boot/60-let-syntax-expanded.scm @@ -36,7 +36,6 @@ (define 7) (define 10) -(define (pair? x) (eq? (core:type x) )) (define (not x) (if x #f #t)) (define (display x . rest) diff --git a/src/lib.c b/src/lib.c index 882e5fdb..5730ce38 100644 --- a/src/lib.c +++ b/src/lib.c @@ -348,3 +348,9 @@ last_pair (SCM x) x = CDR (x); return x; } + +SCM +pair_p (SCM x) +{ + return TYPE (x) == TPAIR ? cell_t : cell_f; +}