factor/vm/utilities.cpp

106 lines
1.5 KiB
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 */
2009-08-17 16:37:09 -04:00
void *factorvm::safe_malloc(size_t size)
2009-05-02 05:04:19 -04:00
{
void *ptr = malloc(size);
if(!ptr) fatal_error("Out of memory in safe_malloc", 0);
return ptr;
}
2009-08-17 16:37:09 -04:00
void *safe_malloc(size_t size)
{
return vm->safe_malloc(size);
}
vm_char *factorvm::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;
}
2009-08-17 16:37:09 -04:00
vm_char *safe_strdup(const vm_char *str)
{
return vm->safe_strdup(str);
}
2009-05-02 05:04:19 -04:00
/* We don't use printf directly, because format directives are not portable.
Instead we define the common cases here. */
2009-08-17 16:37:09 -04:00
void factorvm::nl()
2009-05-02 05:04:19 -04:00
{
fputs("\n",stdout);
}
2009-08-17 16:37:09 -04:00
void nl()
{
return vm->nl();
}
void factorvm::print_string(const char *str)
2009-05-02 05:04:19 -04:00
{
fputs(str,stdout);
}
2009-08-17 16:37:09 -04:00
void print_string(const char *str)
{
return vm->print_string(str);
}
void factorvm::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
}
2009-08-17 16:37:09 -04:00
void print_cell(cell x)
{
return vm->print_cell(x);
}
void factorvm::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
}
2009-08-17 16:37:09 -04:00
void print_cell_hex(cell x)
{
return vm->print_cell_hex(x);
}
void factorvm::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
}
2009-08-17 16:37:09 -04:00
void print_cell_hex_pad(cell x)
{
return vm->print_cell_hex_pad(x);
}
void factorvm::print_fixnum(fixnum x)
2009-05-02 05:04:19 -04:00
{
printf(FIXNUM_FORMAT,x);
}
2009-08-17 16:37:09 -04:00
void print_fixnum(fixnum x)
{
return vm->print_fixnum(x);
}
cell factorvm::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
}
cell read_cell_hex()
{
return vm->read_cell_hex();
2009-05-02 05:04:19 -04:00
};
2009-05-04 02:46:13 -04:00
}