]> gitweb.factorcode.org Git - factor.git/blob - vm/utilities.cpp
removed some global functions from utilities.cpp
[factor.git] / vm / utilities.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 /* If memory allocation fails, bail out */
7 void *factorvm::safe_malloc(size_t size)
8 {
9         void *ptr = malloc(size);
10         if(!ptr) fatal_error("Out of memory in safe_malloc", 0);
11         return ptr;
12 }
13
14 void *safe_malloc(size_t size)
15 {
16         return vm->safe_malloc(size);
17 }
18
19 vm_char *factorvm::safe_strdup(const vm_char *str)
20 {
21         vm_char *ptr = STRDUP(str);
22         if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
23         return ptr;
24 }
25
26 vm_char *safe_strdup(const vm_char *str)
27 {
28         return vm->safe_strdup(str);
29 }
30
31 /* We don't use printf directly, because format directives are not portable.
32 Instead we define the common cases here. */
33 void factorvm::nl()
34 {
35         fputs("\n",stdout);
36 }
37
38 void factorvm::print_string(const char *str)
39 {
40         fputs(str,stdout);
41 }
42
43 void print_string(const char *str)
44 {
45         return vm->print_string(str);
46 }
47
48 void factorvm::print_cell(cell x)
49 {
50         printf(CELL_FORMAT,x);
51 }
52
53 void factorvm::print_cell_hex(cell x)
54 {
55         printf(CELL_HEX_FORMAT,x);
56 }
57
58 void factorvm::print_cell_hex_pad(cell x)
59 {
60         printf(CELL_HEX_PAD_FORMAT,x);
61 }
62
63 void factorvm::print_fixnum(fixnum x)
64 {
65         printf(FIXNUM_FORMAT,x);
66 }
67
68 cell factorvm::read_cell_hex()
69 {
70         cell cell;
71         if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
72         return cell;
73 }
74
75 }