mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-10 14:27:36 +02:00
Return immediate integers
This commit is contained in:
parent
8845991c71
commit
3a79a0f181
2 changed files with 15 additions and 14 deletions
|
@ -98,16 +98,16 @@ object Cyc_global_set(void *thd, object *glo, object value);
|
||||||
return_closcall1(data, cont, &d)
|
return_closcall1(data, cont, &d)
|
||||||
|
|
||||||
#define return_exact_double_op(data, cont, OP, z) \
|
#define return_exact_double_op(data, cont, OP, z) \
|
||||||
make_int(i, 0); \
|
int i = 0; \
|
||||||
Cyc_check_num(data, z); \
|
Cyc_check_num(data, z); \
|
||||||
if (obj_is_int(z)) { \
|
if (obj_is_int(z)) { \
|
||||||
i.value = obj_obj2int(z); \
|
i = obj_obj2int(z); \
|
||||||
} else if (type_of(z) == integer_tag) { \
|
} else if (type_of(z) == integer_tag) { \
|
||||||
i.value = (int)OP(((integer_type *)z)->value); \
|
i = (int)OP(((integer_type *)z)->value); \
|
||||||
} else { \
|
} else { \
|
||||||
i.value = (int)OP(((double_type *)z)->value); \
|
i = (int)OP(((double_type *)z)->value); \
|
||||||
} \
|
} \
|
||||||
return_closcall1(data, cont, &i)
|
return_closcall1(data, cont, obj_int2obj(i))
|
||||||
|
|
||||||
#define unbox_number(n) \
|
#define unbox_number(n) \
|
||||||
((obj_is_int(n) ? obj_obj2int(n) : \
|
((obj_is_int(n) ? obj_obj2int(n) : \
|
||||||
|
|
19
runtime.c
19
runtime.c
|
@ -1108,7 +1108,7 @@ object Cyc_list2string(void *data, object cont, object lst){
|
||||||
object Cyc_string2number2_(void *data, object cont, int argc, object str, ...)
|
object Cyc_string2number2_(void *data, object cont, int argc, object str, ...)
|
||||||
{
|
{
|
||||||
object base = nil;
|
object base = nil;
|
||||||
int base_num;
|
int base_num, result;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, str);
|
va_start(ap, str);
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
@ -1120,20 +1120,21 @@ object Cyc_string2number2_(void *data, object cont, int argc, object str, ...)
|
||||||
base_num = obj_is_int(base) ? obj_obj2int(base) : integer_value(base);
|
base_num = obj_is_int(base) ? obj_obj2int(base) : integer_value(base);
|
||||||
Cyc_check_str(data, str);
|
Cyc_check_str(data, str);
|
||||||
if (base_num == 2) {
|
if (base_num == 2) {
|
||||||
make_int(result, binstr2int(string_str(str)));
|
result = binstr2int(string_str(str));
|
||||||
return_closcall1(data, cont, &result);
|
return_closcall1(data, cont, obj_int2obj(result));
|
||||||
}else if (base_num == 8) {
|
}else if (base_num == 8) {
|
||||||
make_int(result, octstr2int(string_str(str)));
|
result = octstr2int(string_str(str));
|
||||||
return_closcall1(data, cont, &result);
|
return_closcall1(data, cont, obj_int2obj(result));
|
||||||
}else if (base_num == 16) {
|
}else if (base_num == 16) {
|
||||||
make_int(result, hexstr2int(string_str(str)));
|
result = hexstr2int(string_str(str));
|
||||||
return_closcall1(data, cont, &result);
|
return_closcall1(data, cont, obj_int2obj(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Cyc_string2number_(data, cont, str);
|
Cyc_string2number_(data, cont, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
object Cyc_string2number_(void *data, object cont, object str){
|
object Cyc_string2number_(void *data, object cont, object str){
|
||||||
|
int result;
|
||||||
double n;
|
double n;
|
||||||
Cyc_check_obj(data, string_tag, str);
|
Cyc_check_obj(data, string_tag, str);
|
||||||
Cyc_check_str(data, str);
|
Cyc_check_str(data, str);
|
||||||
|
@ -1142,8 +1143,8 @@ object Cyc_string2number_(void *data, object cont, object str){
|
||||||
n = atof(((string_type *) str)->str);
|
n = atof(((string_type *) str)->str);
|
||||||
|
|
||||||
if (ceilf(n) == n) {
|
if (ceilf(n) == n) {
|
||||||
make_int(result, (int)n);
|
result = (int)n;
|
||||||
return_closcall1(data, cont, &result);
|
return_closcall1(data, cont, obj_int2obj(result));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
make_double(result, n);
|
make_double(result, n);
|
||||||
|
|
Loading…
Add table
Reference in a new issue