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