factor/vm/utilities.cpp

54 lines
792 B
C++
Raw Normal View History

2009-05-02 05:04:19 -04:00
#include "master.hpp"
2009-05-04 02:46:13 -04:00
namespace factor
{
2009-05-02 05:04:19 -04:00
/* If memory allocation fails, bail out */
vm_char *safe_strdup(const vm_char *str)
2009-05-02 05:04:19 -04:00
{
2009-05-04 05:50:24 -04:00
vm_char *ptr = STRDUP(str);
2009-05-02 05:04:19 -04:00
if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
return ptr;
}
/* We don't use printf directly, because format directives are not portable.
Instead we define the common cases here. */
void nl()
2009-05-02 05:04:19 -04:00
{
fputs("\n",stdout);
}
void print_string(const char *str)
2009-05-02 05:04:19 -04:00
{
fputs(str,stdout);
}
void print_cell(cell x)
2009-05-02 05:04:19 -04:00
{
2009-05-13 02:08:16 -04:00
printf(CELL_FORMAT,x);
2009-05-02 05:04:19 -04:00
}
void print_cell_hex(cell x)
2009-05-02 05:04:19 -04:00
{
2009-05-13 02:08:16 -04:00
printf(CELL_HEX_FORMAT,x);
2009-05-02 05:04:19 -04:00
}
void print_cell_hex_pad(cell x)
2009-05-02 05:04:19 -04:00
{
2009-05-13 02:08:16 -04:00
printf(CELL_HEX_PAD_FORMAT,x);
2009-05-02 05:04:19 -04:00
}
void print_fixnum(fixnum x)
2009-05-02 05:04:19 -04:00
{
printf(FIXNUM_FORMAT,x);
}
cell read_cell_hex()
2009-05-02 05:04:19 -04:00
{
2009-05-04 05:50:24 -04:00
cell cell;
2009-05-13 02:08:16 -04:00
if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
2009-05-02 05:04:19 -04:00
return cell;
2009-08-17 16:37:09 -04:00
}
2009-05-04 02:46:13 -04:00
}