83aa45e3ec13 — Leonard Ritter tip 17 hours ago
* compiler.File: File.create, File can be printed to
* src: more refactoring
2 files changed, 16 insertions(+), 11 deletions(-)

M lib/scopes/compiler/File.sc
M src/globals.cpp
M lib/scopes/compiler/File.sc +11 -6
@@ 3,12 3,8 @@ 
     This file is distributed under the MIT License.
     See LICENSE.md for details.
 
-using import struct
-using import enum
-using import C.errno
-using import C.stdio
-using import C.string
-using import C.stat
+using import struct enum print
+using import C.errno C.stdio C.string C.stat
 #typedef FILE
 
 let

          
@@ 42,12 38,17 @@ struct File
                 deref self._handle
 
     inline open (filename mode)
+        mode := static-if (none? mode) "rb"
+        else mode
         let handle = (fopen filename mode)
         if (handle == null)
             raise (errno)
         super-type.__typecall this-type
             _handle = handle
 
+    inline create (filename)
+        open filename "wb"
+
     fn file? (self)
         fd := fileno self._handle
         local ss : stat

          
@@ 92,6 93,10 @@ struct File
         fclose self._handle
         super-type.__drop self
 
+    inline __call (self ...)
+        write := StyledFilePrinter self
+        write ...
+
 do
     let File
     locals;
  No newline at end of file

          
M src/globals.cpp +5 -5
@@ 3079,23 3079,23 @@ int sc_typed_value_index(sc_value_t valu
 
 int sc_block_instruction_count(sc_value_t block) {
     using namespace scopes;
-    return block.cast<Block>()->body.size();
+    return cast<Block>(block)->body.size();
 }
 
 sc_value_t sc_block_get_instruction(sc_value_t block, int index) {
     using namespace scopes;
-    return block.cast<Block>()->body[index];
+    return cast<Block>(block)->body[index];
 }
 
 sc_value_t sc_block_terminator(sc_value_t block) {
     using namespace scopes;
-    assert(block.cast<Block>()->terminator);
-    return block.cast<Block>()->terminator;
+    assert(cast<Block>(block)->terminator);
+    return *cast<Block>(block)->terminator;
 }
 
 bool sc_block_is_terminated(sc_value_t block) {
     using namespace scopes;
-    return (bool)block.cast<Block>()->terminator;
+    return (bool)cast<Block>(block)->terminator;
 }
 
 } // extern "C"