]> gitweb.factorcode.org Git - factor.git/blob - vm/utilities.cpp
Merge branch 'irc' of git://www.tiodante.com/git/factor
[factor.git] / vm / utilities.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 /* If memory allocation fails, bail out */
7 void *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 vm_char *safe_strdup(const vm_char *str)
15 {
16         vm_char *ptr = STRDUP(str);
17         if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
18         return ptr;
19 }
20
21 /* We don't use printf directly, because format directives are not portable.
22 Instead we define the common cases here. */
23 void nl()
24 {
25         fputs("\n",stdout);
26 }
27
28 void print_string(const char *str)
29 {
30         fputs(str,stdout);
31 }
32
33 void print_cell(cell x)
34 {
35         printf(CELL_FORMAT,x);
36 }
37
38 void print_cell_hex(cell x)
39 {
40         printf(CELL_HEX_FORMAT,x);
41 }
42
43 void print_cell_hex_pad(cell x)
44 {
45         printf(CELL_HEX_PAD_FORMAT,x);
46 }
47
48 void print_fixnum(fixnum x)
49 {
50         printf(FIXNUM_FORMAT,x);
51 }
52
53 cell read_cell_hex()
54 {
55         cell cell;
56         if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
57         return cell;
58 };
59
60 }