]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/io.cpp
io.streams.256color: faster by caching styles
[factor.git] / vm / io.cpp
index 6f768b034c9ef0e66b5cc22ed01ff325a048ab9f..e299e9888607e392d5da89f5dd55a3c3134c48a3 100644 (file)
--- a/vm/io.cpp
+++ b/vm/io.cpp
@@ -41,13 +41,6 @@ int raw_fclose(FILE* stream) {
   return 0;
 }
 
-
-void factor_vm::init_c_io() {
-  special_objects[OBJ_STDIN] = allot_alien(false_object, (cell)stdin);
-  special_objects[OBJ_STDOUT] = allot_alien(false_object, (cell)stdout);
-  special_objects[OBJ_STDERR] = allot_alien(false_object, (cell)stderr);
-}
-
 // Allocates memory
 void factor_vm::io_error_if_not_EINTR() {
   if (errno == EINTR)
@@ -116,7 +109,7 @@ size_t factor_vm::safe_fwrite(void* ptr, size_t size, size_t nitems,
   return items_written;
 }
 
-int factor_vm::safe_ftell(FILE* stream) {
+off_t factor_vm::safe_ftell(FILE* stream) {
   off_t offset;
   for (;;) {
     if ((offset = FTELL(stream)) == -1)
@@ -139,7 +132,7 @@ void factor_vm::safe_fseek(FILE* stream, off_t offset, int whence) {
       whence = SEEK_END;
       break;
     default:
-      critical_error("Bad value for whence", whence);
+      general_error(ERROR_IO, tag_fixnum(EINVAL), false_object);
   }
 
   for (;;) {
@@ -160,20 +153,20 @@ void factor_vm::safe_fflush(FILE* stream) {
 }
 
 void factor_vm::primitive_fopen() {
-  data_root<byte_array> mode(ctx->pop(), this);
-  data_root<byte_array> path(ctx->pop(), this);
-  check_tagged(mode);
-  check_tagged(path);
+  byte_array *mode = untag_check<byte_array>(ctx->pop());
+  byte_array *path = untag_check<byte_array>(ctx->pop());
 
-  FILE* file;
-  file = safe_fopen((char*)(path.untagged() + 1),
-                    (char*)(mode.untagged() + 1));
+  FILE* file = safe_fopen((char*)(path + 1), (char*)(mode + 1));
   ctx->push(allot_alien((cell)file));
 }
 
-FILE* factor_vm::pop_file_handle() { return (FILE*)alien_offset(ctx->pop()); }
+FILE* factor_vm::pop_file_handle() {
+  return (FILE*)alien_offset(ctx->pop());
+}
 
-FILE* factor_vm::peek_file_handle() { return (FILE*)alien_offset(ctx->peek()); }
+FILE* factor_vm::peek_file_handle() {
+  return (FILE*)alien_offset(ctx->peek());
+}
 
 void factor_vm::primitive_fgetc() {
   FILE* file = peek_file_handle();