mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Allow (string->number) to return common type (int and double)
This commit is contained in:
parent
c62e035153
commit
ea8f56a4ee
3 changed files with 15 additions and 14 deletions
2
cgen.scm
2
cgen.scm
|
@ -545,7 +545,7 @@
|
|||
((eq? p 'open-input-file) "port_type")
|
||||
((eq? p 'length) "integer_type")
|
||||
((eq? p 'char->integer) "integer_type")
|
||||
((eq? p 'string->number) "integer_type")
|
||||
((eq? p 'string->number) "common_type")
|
||||
((eq? p 'list->string) "string_type")
|
||||
; ((eq? p 'string->list) "object")
|
||||
((eq? p 'string-append) "string_type")
|
||||
|
|
|
@ -268,5 +268,14 @@ void dispatch(int argc, function_type func, object clo, object cont, object args
|
|||
void dispatch_va(int argc, function_type_va func, object clo, object cont, object args);
|
||||
void do_dispatch(int argc, function_type func, object clo, object *buffer);
|
||||
|
||||
/* All constant-size objects */
|
||||
typedef union {
|
||||
cons_type cons_t;
|
||||
symbol_type symbol_t;
|
||||
primitive_type primitive_t;
|
||||
integer_type integer_t;
|
||||
double_type double_t;
|
||||
string_type string_t;
|
||||
} common_type;
|
||||
|
||||
#endif /* CYCLONE_H */
|
||||
|
|
18
runtime.h
18
runtime.h
|
@ -660,14 +660,16 @@ static void __string2list(const char *str, cons_type *buf, int buflen){
|
|||
}
|
||||
}
|
||||
|
||||
static integer_type Cyc_string2number(object str){
|
||||
static common_type Cyc_string2number(object str){
|
||||
common_type result;
|
||||
make_int(n, 0);
|
||||
if (type_of(str) == string_tag &&
|
||||
((string_type *) str)->str){
|
||||
// TODO: not good enough long-term since it doesn't parse floats
|
||||
n.value = atoi(((string_type *) str)->str);
|
||||
}
|
||||
return n;
|
||||
result.integer_t = n;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void dispatch_string_91append(int argc, object clo, object cont, object str1, ...) {
|
||||
|
@ -975,7 +977,7 @@ static void _char_91_125integer(object cont, object args) {
|
|||
static void _integer_91_125char(object cont, object args) {
|
||||
return_funcall1(cont, Cyc_integer2char(car(args)));}
|
||||
static void _string_91_125number(object cont, object args) {
|
||||
integer_type i = Cyc_string2number(car(args));
|
||||
common_type i = Cyc_string2number(car(args));
|
||||
return_funcall1(cont, &i);}
|
||||
//static void _error(object cont, object args) {
|
||||
// integer_type argc = Cyc_length(args);
|
||||
|
@ -1122,16 +1124,6 @@ defprimitive(write, write, &_write); /* write */
|
|||
defprimitive(display, display, &_display); /* display */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/* All constant-size objects */
|
||||
typedef union {
|
||||
cons_type cons_t;
|
||||
symbol_type symbol_t;
|
||||
primitive_type primitive_t;
|
||||
integer_type integer_t;
|
||||
double_type double_t;
|
||||
string_type string_t;
|
||||
} common_type;
|
||||
|
||||
/*
|
||||
*
|
||||
* @param cont - Continuation for the function to call into
|
||||
|
|
Loading…
Add table
Reference in a new issue