]> gitweb.factorcode.org Git - factor.git/blob - vm/utilities.cpp
moved utilities.cpp functions to vm
[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 nl()
39 {
40         return vm->nl();
41 }
42
43 void factorvm::print_string(const char *str)
44 {
45         fputs(str,stdout);
46 }
47
48 void print_string(const char *str)
49 {
50         return vm->print_string(str);
51 }
52
53 void factorvm::print_cell(cell x)
54 {
55         printf(CELL_FORMAT,x);
56 }
57
58 void print_cell(cell x)
59 {
60         return vm->print_cell(x);
61 }
62
63 void factorvm::print_cell_hex(cell x)
64 {
65         printf(CELL_HEX_FORMAT,x);
66 }
67
68 void print_cell_hex(cell x)
69 {
70         return vm->print_cell_hex(x);
71 }
72
73 void factorvm::print_cell_hex_pad(cell x)
74 {
75         printf(CELL_HEX_PAD_FORMAT,x);
76 }
77
78 void print_cell_hex_pad(cell x)
79 {
80         return vm->print_cell_hex_pad(x);
81 }
82
83 void factorvm::print_fixnum(fixnum x)
84 {
85         printf(FIXNUM_FORMAT,x);
86 }
87
88 void print_fixnum(fixnum x)
89 {
90         return vm->print_fixnum(x);
91 }
92
93 cell factorvm::read_cell_hex()
94 {
95         cell cell;
96         if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
97         return cell;
98 }
99
100 cell read_cell_hex()
101 {
102         return vm->read_cell_hex();
103 };
104
105 }