]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/utilities.cpp
alien.syntax: clarify that we can dispatch off ENUM: members
[factor.git] / vm / utilities.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 94f010d..60d524a
@@ -1,62 +1,41 @@
 #include "master.hpp"
 
-namespace factor
-{
+namespace factor {
 
-/* If memory allocation fails, bail out */
-void *safe_malloc(size_t size)
-{
-       void *ptr = malloc(size);
-       if(!ptr) fatal_error("Out of memory in safe_malloc", 0);
-       return ptr;
+// Fill in a PPC function descriptor
+void* fill_function_descriptor(void* ptr, void* code) {
+  void** descriptor = (void**)ptr;
+  descriptor[0] = code;
+  descriptor[1] = NULL;
+  descriptor[2] = NULL;
+  return descriptor;
 }
 
-vm_char *safe_strdup(const vm_char *str)
-{
-       vm_char *ptr = STRDUP(str);
-       if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
-       return ptr;
+// Get a field from a PPC function descriptor
+void* function_descriptor_field(void* ptr, size_t idx) {
+  return ptr ? ((void**)ptr)[idx] : ptr;
 }
 
-
-/* We don't use printf directly, because format directives are not portable.
-Instead we define the common cases here. */
-void nl()
-{
-       fputs("\n",stdout);
-}
-
-void print_string(const char *str)
-{
-       fputs(str,stdout);
-}
-
-
-void print_cell(cell x)
-{
-       printf(CELL_FORMAT,x);
-}
-
-void print_cell_hex(cell x)
-{
-       printf(CELL_HEX_FORMAT,x);
-}
-
-void print_cell_hex_pad(cell x)
-{
-       printf(CELL_HEX_PAD_FORMAT,x);
+// If memory allocation fails, bail out
+vm_char* safe_strdup(const vm_char* str) {
+  vm_char* ptr = STRDUP(str);
+  if (!ptr)
+    fatal_error("Out of memory in safe_strdup", 0);
+  return ptr;
 }
 
-void print_fixnum(fixnum x)
-{
-       printf(FIXNUM_FORMAT,x);
+cell read_cell_hex() {
+  cell cell;
+  std::cin >> std::hex >> cell >> std::dec;
+  if (!std::cin.good())
+    exit(1);
+  return cell;
 }
 
-cell read_cell_hex()
-{
-       cell cell;
-       if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
-       return cell;
+// On Windows, memcpy() is in a different DLL and the non-optimizing
+// compiler can't find it
+VM_C_API void* factor_memcpy(void* dst, void* src, size_t len) {
+  return memcpy(dst, src, len);
 }
 
 }