From b2cc35e1417103706b758928a7ed4d056e9a1ba7 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 9 Apr 2015 17:54:35 -0400 Subject: [PATCH] Added `real?` and `integer?` --- cgen.scm | 2 ++ eval.scm | 2 ++ runtime.h | 18 ++++++++++++++++++ test.scm | 1 + tests/unit-tests.scm | 2 +- trans.scm | 3 +++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cgen.scm b/cgen.scm index fdde1054..0f133304 100644 --- a/cgen.scm +++ b/cgen.scm @@ -468,6 +468,8 @@ ((eq? p 'char?) "Cyc_is_char") ((eq? p 'null?) "Cyc_is_null") ((eq? p 'number?) "Cyc_is_number") + ((eq? p 'real?) "Cyc_is_real") + ((eq? p 'integer?) "Cyc_is_integer") ((eq? p 'pair?) "Cyc_is_cons") ((eq? p 'procedure?) "Cyc_is_procedure") ((eq? p 'string?) "Cyc_is_string") diff --git a/eval.scm b/eval.scm index 8a96514d..8db5c50f 100644 --- a/eval.scm +++ b/eval.scm @@ -263,6 +263,8 @@ (list 'eof-object? eof-object?) (list 'null? null?) (list 'number? number?) + (list 'real? real?) + (list 'integer? integer?) (list 'pair? pair?) (list 'procedure? procedure?) (list 'string? string?) diff --git a/runtime.h b/runtime.h index 493ea779..52790013 100644 --- a/runtime.h +++ b/runtime.h @@ -86,6 +86,8 @@ static object Cyc_is_boolean(object o); static object Cyc_is_cons(object o); static object Cyc_is_null(object o); static object Cyc_is_number(object o); +static object Cyc_is_real(object o); +static object Cyc_is_integer(object o); static object Cyc_is_symbol(object o); static object Cyc_is_string(object o); static object Cyc_is_char(object o); @@ -528,6 +530,16 @@ static object Cyc_is_number(object o){ return boolean_t; return boolean_f;} +static object Cyc_is_real(object o){ + if (!nullp(o) && !is_value_type(o) && type_of(o) == double_tag) + return boolean_t; + return boolean_f;} + +static object Cyc_is_integer(object o){ + if (!nullp(o) && !is_value_type(o) && type_of(o) == integer_tag) + return boolean_t; + return boolean_f;} + static object Cyc_is_symbol(object o){ if (!nullp(o) && !is_value_type(o) && ((list)o)->tag == symbol_tag) return boolean_t; @@ -927,6 +939,10 @@ static void _eof_91object_127(object cont, object args) { return_funcall1(cont, Cyc_is_eof_object(car(args))); } static void _number_127(object cont, object args) { return_funcall1(cont, Cyc_is_number(car(args))); } +static void _real_127(object cont, object args) { + return_funcall1(cont, Cyc_is_real(car(args))); } +static void _integer_127(object cont, object args) { + return_funcall1(cont, Cyc_is_integer(car(args))); } static void _pair_127(object cont, object args) { return_funcall1(cont, Cyc_is_cons(car(args))); } static void _procedure_127(object cont, object args) { @@ -1122,6 +1138,8 @@ defprimitive(char_127, char?, &_char_127); /* char? */ defprimitive(eof_91object_127, eof-object?, &_eof_91object_127); /* eof-object? */ defprimitive(null_127, null?, &_null_127); /* null? */ defprimitive(number_127, number?, &_number_127); /* number? */ +defprimitive(real_127, real?, &_real_127); /* real? */ +defprimitive(integer_127, integer?, &_integer_127); /* integer? */ defprimitive(pair_127, pair?, &_pair_127); /* pair? */ defprimitive(procedure_127, procedure?, &_procedure_127); /* procedure? */ defprimitive(string_127, string?, &_string_127); /* string? */ diff --git a/test.scm b/test.scm index bc4cb3fe..7e16791f 100644 --- a/test.scm +++ b/test.scm @@ -1,3 +1,4 @@ +1.1 ;((lambda (x) ; ((lambda () ; ((lambda (z) diff --git a/tests/unit-tests.scm b/tests/unit-tests.scm index 4e045c34..ee64f7d8 100644 --- a/tests/unit-tests.scm +++ b/tests/unit-tests.scm @@ -158,7 +158,7 @@ (assert:equal "" (string->number "0") 0) (assert:equal "" (string->number "42") 42) ;(assert:equal "" (string->number "343243243232") ;; Note no bignum support -(assert:equal "" (string->number "3.14159") 3) ;; Currently no float support +(assert:equal "" (string->number "3.14159") 3.14159) (assert:equal "" (list->string (list #\A #\B #\C)) "ABC") (assert:equal "" (list->string (list #\A)) "A") (assert:equal "" (list->string (list)) "") diff --git a/trans.scm b/trans.scm index e841a380..2b58b17d 100644 --- a/trans.scm +++ b/trans.scm @@ -511,6 +511,7 @@ ; const? : exp -> boolean (define (const? exp) (or (integer? exp) + (real? exp) (string? exp) (char? exp) (boolean? exp))) @@ -735,6 +736,8 @@ eof-object? null? number? + real? + integer? pair? procedure? string?