klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

kport.h (1948B)


      1 /*
      2 ** kport.h
      3 ** Kernel Ports
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 #ifndef kport_h
      8 #define kport_h
      9 
     10 #include <stdio.h>
     11 
     12 #include "kobject.h"
     13 #include "kstate.h"
     14 
     15 /* can't be inline because we also use pointers to them,
     16    (at least gcc doesn't bother to create them and the linker fails) */
     17 bool kportp(TValue o);
     18 bool kinput_portp(TValue o);
     19 bool koutput_portp(TValue o);
     20 bool kbinary_portp(TValue o);
     21 bool ktextual_portp(TValue o);
     22 bool kfile_portp(TValue o);
     23 bool kstring_portp(TValue o);
     24 bool kbytevector_portp(TValue o);
     25 bool kport_openp(TValue o);
     26 bool kport_closedp(TValue o);
     27 
     28 /* GC: Assumes filename is rooted */
     29 TValue kmake_fport(klisp_State *K, TValue filename, bool writep, bool binaryp);
     30 
     31 /* this is for creating ports for stdin/stdout/stderr &
     32    helper for the one above */
     33 /* GC: Assumes filename, name & si are rooted */
     34 TValue kmake_std_fport(klisp_State *K, TValue filename, bool writep, 
     35                        bool binaryp, FILE *file);
     36 
     37 /* GC: buffer doesn't need to be rooted, but should probably do it anyways */
     38 TValue kmake_mport(klisp_State *K, TValue buffer, bool writep, bool binaryp);
     39 
     40 /* This closes the underlying FILE * (unless it is a std port or memory port) 
     41    and also set the closed flag to true, this shouldn't throw errors because 
     42    it is also called when deallocating all objs. If errors need to be thrown
     43    fork this function instead of simply modifying */
     44 void kclose_port(klisp_State *K, TValue port);
     45 
     46 #define kport_filename(p_) (tv2port(p_)->filename)
     47 #define kport_line(p_) (tv2port(p_)->row)
     48 #define kport_col(p_) (tv2port(p_)->col)
     49 
     50 #define kfport_file(p_) (tv2fport(p_)->file)
     51 
     52 #define kmport_off(p_) (tv2mport(p_)->off)
     53 #define kmport_buf(p_) (tv2mport(p_)->buf)
     54 
     55 void kport_reset_source_info(TValue port);
     56 void kport_update_source_info(TValue port, int32_t line, int32_t col);
     57 /* GC: port should be rooted */
     58 void kmport_resize_buffer(klisp_State *K, TValue port, size_t min_size);
     59 #endif