moved math.hpp functions to vm

db4
Phil Dawes 2009-08-17 21:37:11 +01:00
parent 33ecaa5010
commit ae5c0fbfb2
2 changed files with 37 additions and 7 deletions

View File

@ -42,7 +42,7 @@ PRIMITIVE(bignum_bitp);
PRIMITIVE(bignum_log2); PRIMITIVE(bignum_log2);
PRIMITIVE(byte_array_to_bignum); PRIMITIVE(byte_array_to_bignum);
inline static cell allot_integer(fixnum x) inline cell factorvm::allot_integer(fixnum x)
{ {
if(x < fixnum_min || x > fixnum_max) if(x < fixnum_min || x > fixnum_max)
return tag<bignum>(fixnum_to_bignum(x)); return tag<bignum>(fixnum_to_bignum(x));
@ -50,7 +50,12 @@ inline static cell allot_integer(fixnum x)
return tag_fixnum(x); return tag_fixnum(x);
} }
inline static cell allot_cell(cell x) inline cell allot_integer(fixnum x)
{
return vm->allot_integer(x);
}
inline cell factorvm::allot_cell(cell x)
{ {
if(x > (cell)fixnum_max) if(x > (cell)fixnum_max)
return tag<bignum>(cell_to_bignum(x)); return tag<bignum>(cell_to_bignum(x));
@ -58,6 +63,11 @@ inline static cell allot_cell(cell x)
return tag_fixnum(x); return tag_fixnum(x);
} }
inline cell allot_cell(cell x)
{
return vm->allot_cell(x);
}
cell unbox_array_size(); cell unbox_array_size();
inline static double untag_float(cell tagged) inline static double untag_float(cell tagged)
@ -70,33 +80,48 @@ inline static double untag_float_check(cell tagged)
return untag_check<boxed_float>(tagged)->n; return untag_check<boxed_float>(tagged)->n;
} }
inline static cell allot_float(double n) inline cell factorvm::allot_float(double n)
{ {
boxed_float *flo = allot<boxed_float>(sizeof(boxed_float)); boxed_float *flo = allot<boxed_float>(sizeof(boxed_float));
flo->n = n; flo->n = n;
return tag(flo); return tag(flo);
} }
inline cell allot_float(double n)
{
return vm->allot_float(n);
}
inline static fixnum float_to_fixnum(cell tagged) inline static fixnum float_to_fixnum(cell tagged)
{ {
return (fixnum)untag_float(tagged); return (fixnum)untag_float(tagged);
} }
inline static bignum *float_to_bignum(cell tagged) inline bignum *factorvm::float_to_bignum(cell tagged)
{ {
return double_to_bignum(untag_float(tagged)); return double_to_bignum(untag_float(tagged));
} }
inline static double fixnum_to_float(cell tagged) inline bignum *float_to_bignum(cell tagged)
{
return vm->float_to_bignum(tagged);
}
inline double fixnum_to_float(cell tagged)
{ {
return (double)untag_fixnum(tagged); return (double)untag_fixnum(tagged);
} }
inline static double bignum_to_float(cell tagged) inline double factorvm::bignum_to_float(cell tagged)
{ {
return bignum_to_double(untag<bignum>(tagged)); return bignum_to_double(untag<bignum>(tagged));
} }
inline double bignum_to_float(cell tagged)
{
return vm->bignum_to_float(tagged);
}
PRIMITIVE(fixnum_to_float); PRIMITIVE(fixnum_to_float);
PRIMITIVE(bignum_to_float); PRIMITIVE(bignum_to_float);
PRIMITIVE(str_to_float); PRIMITIVE(str_to_float);

View File

@ -246,7 +246,6 @@ struct factorvm {
cell allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_); cell allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_);
inline void vmprim_resize_array(); inline void vmprim_resize_array();
inline void set_array_nth(array *array, cell slot, cell value); inline void set_array_nth(array *array, cell slot, cell value);
// next method here:
//strings //strings
cell string_nth(string* str, cell index); cell string_nth(string* str, cell index);
@ -358,6 +357,12 @@ struct factorvm {
void overflow_fixnum_add(fixnum x, fixnum y); void overflow_fixnum_add(fixnum x, fixnum y);
void overflow_fixnum_subtract(fixnum x, fixnum y); void overflow_fixnum_subtract(fixnum x, fixnum y);
void overflow_fixnum_multiply(fixnum x, fixnum y); void overflow_fixnum_multiply(fixnum x, fixnum y);
inline cell allot_integer(fixnum x);
inline cell allot_cell(cell x);
inline cell allot_float(double n);
inline bignum *float_to_bignum(cell tagged);
inline double bignum_to_float(cell tagged);
// next method here:
//io //io
void init_c_io(); void init_c_io();