mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-21 22:59:16 +02:00
Modified code to account for numeric tower, fixed up number->string
This commit is contained in:
parent
cac2144f76
commit
010d3e6a18
2 changed files with 15 additions and 18 deletions
14
cgen.scm
14
cgen.scm
|
@ -351,13 +351,6 @@
|
||||||
(c-code "nil"))
|
(c-code "nil"))
|
||||||
((pair? exp)
|
((pair? exp)
|
||||||
(c-compile-scalars exp))
|
(c-compile-scalars exp))
|
||||||
((real? exp)
|
|
||||||
(let ((cvar-name (mangle (gensym 'c))))
|
|
||||||
(c-code/vars
|
|
||||||
(string-append "&" cvar-name) ; Code is just the variable name
|
|
||||||
(list ; Allocate on the C stack
|
|
||||||
(string-append
|
|
||||||
"make_double(" cvar-name ", " (number->string exp) ");")))))
|
|
||||||
((integer? exp)
|
((integer? exp)
|
||||||
(let ((cvar-name (mangle (gensym 'c))))
|
(let ((cvar-name (mangle (gensym 'c))))
|
||||||
(c-code/vars
|
(c-code/vars
|
||||||
|
@ -365,6 +358,13 @@
|
||||||
(list ; Allocate integer on the C stack
|
(list ; Allocate integer on the C stack
|
||||||
(string-append
|
(string-append
|
||||||
"make_int(" cvar-name ", " (number->string exp) ");")))))
|
"make_int(" cvar-name ", " (number->string exp) ");")))))
|
||||||
|
((real? exp)
|
||||||
|
(let ((cvar-name (mangle (gensym 'c))))
|
||||||
|
(c-code/vars
|
||||||
|
(string-append "&" cvar-name) ; Code is just the variable name
|
||||||
|
(list ; Allocate on the C stack
|
||||||
|
(string-append
|
||||||
|
"make_double(" cvar-name ", " (number->string exp) ");")))))
|
||||||
((boolean? exp)
|
((boolean? exp)
|
||||||
(c-code (string-append
|
(c-code (string-append
|
||||||
(if exp "boolean_t" "boolean_f"))))
|
(if exp "boolean_t" "boolean_f"))))
|
||||||
|
|
17
runtime.h
17
runtime.h
|
@ -531,9 +531,7 @@ static object Cyc_is_number(object o){
|
||||||
return boolean_f;}
|
return boolean_f;}
|
||||||
|
|
||||||
static object Cyc_is_real(object o){
|
static object Cyc_is_real(object o){
|
||||||
if (!nullp(o) && !is_value_type(o) && type_of(o) == double_tag)
|
return Cyc_is_number(o);}
|
||||||
return boolean_t;
|
|
||||||
return boolean_f;}
|
|
||||||
|
|
||||||
static object Cyc_is_integer(object o){
|
static object Cyc_is_integer(object o){
|
||||||
if (!nullp(o) && !is_value_type(o) && type_of(o) == integer_tag)
|
if (!nullp(o) && !is_value_type(o) && type_of(o) == integer_tag)
|
||||||
|
@ -615,14 +613,13 @@ static integer_type Cyc_length(object l){
|
||||||
|
|
||||||
static string_type Cyc_number2string(object n) {
|
static string_type Cyc_number2string(object n) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
if (type_of(n) == integer_tag) {
|
||||||
snprintf(buffer, 1024, "%d", ((integer_type *)n)->value);
|
snprintf(buffer, 1024, "%d", ((integer_type *)n)->value);
|
||||||
//TODO: if (type_of(n) == integer_tag) {
|
} else if (type_of(n) == double_tag) {
|
||||||
//TODO: snprintf(buffer, 1024, "%d", ((integer_type *)n)->value);
|
snprintf(buffer, 1024, "%lf", ((double_type *)n)->value);
|
||||||
//TODO: } else if (type_of(n) == double_tag) {
|
} else {
|
||||||
//TODO: snprintf(buffer, 1024, "%lf", ((double_type *)n)->value);
|
buffer[0] = '\0'; // TODO: throw error instead
|
||||||
//TODO: } else {
|
}
|
||||||
//TODO: buffer[0] = '\0'; // TODO: throw error instead
|
|
||||||
//TODO: }
|
|
||||||
make_string(str, buffer);
|
make_string(str, buffer);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue