Ports
[Functional objects]

Collaboration diagram for Ports:


Data Structures

struct  fileport_t
struct  fileport_type_t
struct  ez_result_t
struct  white_space_t
struct  muse_port_type_t
 Defines the Ports protocol. More...
struct  muse_port_buffer_t
 Every port is buffered for input as well as output. More...
struct  _muse_port_base_t
 The base port type. More...

Pretty print support.

enum  { MAX_INDENT_COLS = 128 }
static void pretty_printer_reset (muse_port_t p)
static void pretty_printer_indent ()
static void pretty_printer_unindent ()
static void pretty_printer_line_break (muse_port_t f)
static void pretty_printer_move (int numc)
static int g_align_cols [MAX_INDENT_COLS]
static int g_align_level = 0
static muse_boolean g_pretty_printer_enabled = MUSE_TRUE
static int g_tab_size = 4

Ports implementation API

void port_init (muse_port_base_t *p)
 Intended to be called inside a particular port's init function at port creation time.
void port_destroy (muse_port_base_t *p)
 Intended to be called inside a particular ports destroy function at port destruction time.
int port_getc (muse_port_base_t *p)
 Same protocol as the system getc function, but works with the given port.
int port_ungetc (int c, muse_port_base_t *p)
 Same protocol as the system ungetc function.
int port_putc (int c, muse_port_base_t *p)
 Same protocol as the system putc function.
int port_eof (muse_port_base_t *port)
 Returns EOF if the port has reached end of stream.
void port_close (muse_port_base_t *p)
 Flushes the port and call's the port's close function to release system resources.
size_t port_read (void *buffer, size_t nbytes, muse_port_base_t *port)
 Wraps the port specific read function.
size_t port_write (void *buffer, size_t nbytes, muse_port_base_t *port)
 Wraps the port specific write function.
int port_flush (muse_port_base_t *port)
 Writes any data pending in the port's output buffer and then calls the port-specific flush function.

ezscheme structures

int ez_update_col (int ch, int col)
static ez_result_t ez_result (muse_cell expr, int col_start, int col_end)
ez_result_t ez_parse (muse_port_t p, int col, muse_boolean is_head)
 Indentation dependent parsing of expressions - ezscheme.
muse_cell ez_parse_expr (muse_port_t p)

Defines

#define portfn(p, fn)   ((muse_port_type_t*)((muse_functional_object_t*)p)->type_info)->fn

Typedefs

typedef _muse_port_base_t muse_port_base_t
 The base port type.

Enumerations

enum  {
  PORT_BUFFER_SIZE = 4096,
  PORT_BUFFER_MASK = PORT_BUFFER_SIZE - 1,
  PORT_BUFFER_UNGET_SIZE = 16
}
enum  {
  PARSE_EOF = -1000,
  PARSE_ERROR = -1001,
  PARSE_ERROR_BUFFER_OVERFLOW = -1002,
  PARSE_ERROR_EXPECTED_STRING = -1003,
  PARSE_ERROR_EXPECTED_LIST = -1004,
  PARSE_ERROR_BAD_CONS_SYNTAX = -1005,
  PARSE_ERROR_EXPECTED_SYMBOL = -1006,
  PARSE_EMPTY_GROUP = -10000,
  PARSE_END_OF_GROUP = -10001,
  PARSE_END_OF_LIST = -10002,
  PARSE_LIST_ITEM_SEPARATOR = -10003
}

Functions

static void write_utf8_header (fileport_t *p)
static void discard_utf8_header (fileport_t *p)
static void check_for_ezscheme_file (fileport_t *p)
static void fileport_init (void *ptr, muse_cell args)
static void fileport_destroy (void *ptr)
static void fileport_close (void *ptr)
static size_t fileport_read (void *buffer, size_t nbytes, void *port)
static size_t fileport_write (void *buffer, size_t nbytes, void *port)
static int fileport_flush (void *port)
muse_port_t muse_stdport (muse_stdport_t descriptor)
static muse_cell fn_open_file (muse_env *env, void *context, muse_cell args)
 (open-file "filename.txt" ['for-reading 'for-writing]).
static muse_cell fn_destroy_stdports (muse_env *env, void *context, muse_cell args)
 The destructor that will be called at environment destruction time to free up the standard ports.
void muse_define_builtin_fileport ()
 Adds all file port definitions such as "open-file".
muse_port_t muse_assign_port (FILE *f, int mode)
 Creates a port definition that you can use to read/write stuff from a given file pointer.
void muse_unassign_port (muse_port_t p)
 Unassigns a file port which was earlier assigned using muse_assign_port.
static void port_init_buffer (muse_port_buffer_t *buffer)
static void port_destroy_buffer (muse_port_buffer_t *buffer)
static int peekc (muse_port_t f)
white_space_t ez_skip_whitespace (muse_port_t f, int line, int col)
 Skips all white space and comments following the current stream position in the given stream Returns the column position at which the next non-white space character starts.
static int _token_begin_list (int c)
static int _token_end_list (int c)
static ez_result_t _read_number (muse_port_t f, int col)
 Reads a decimal number starting from the current stream position.
static int hex (int c)
static ez_result_t _read_hex (muse_port_t f, int col)
 Reads a hexadecimal number starting from the current stream position.
static ez_result_t _read_string (muse_port_t f, int col)
 Reads and returns the next string delimited by double quote characters.
static muse_boolean is_symbol_char (int c)
static ez_result_t _read_symbol (muse_port_t f, int col)
 Reads a symbol from the current stream position.
static ez_result_t _read_atom (muse_port_t f, int col)
 An atom is a number, symbol or a string.
static muse_cell _read_list (muse_port_t f)
 Reads a list delimited by parentheses.
static muse_boolean is_macro_sexpr (muse_cell sexpr)
 Returns MUSE_TRUE if the given sexpr is a macro expression.
muse_cell muse_pread (muse_port_t f)
 Reads the next symbolic expression at the current stream position, ignoring white space and comment lines.
static void muse_print_q (muse_port_t f, muse_cell sexpr, muse_boolean quote)
 Prints the given s-expr to the given stream.
static void muse_print_int (muse_port_t f, muse_cell i)
static void muse_print_float (muse_port_t s, muse_cell f)
static size_t muse_print_text (muse_port_t f, muse_cell t, muse_boolean quote)
static void muse_print_list (muse_port_t f, muse_cell l, muse_boolean quote)
static void muse_print_sym (muse_port_t f, muse_cell s)
static void muse_print_lambda (muse_port_t f, muse_cell l, muse_boolean quote)
static void muse_print_nativefn (muse_port_t f, muse_cell l)
void muse_pprint (muse_port_t port, muse_cell sexpr)
void muse_pwrite (muse_port_t f, muse_cell sexpr)
 Writes the given s-expression to the given stream.
muse_port_t muse_port (muse_cell p)
 Takes a muSE port represented as a cell and returns the internal port object that it uses.

Variables

static fileport_type_t g_fileport_type
static fileport_type_t g_port_type_stdin
static fileport_type_t g_port_type_stdout
static fileport_t g_muse_stdports [3]

Define Documentation

#define portfn ( p,
fn   )     ((muse_port_type_t*)((muse_functional_object_t*)p)->type_info)->fn


Typedef Documentation

typedef struct _muse_port_base_t muse_port_base_t

The base port type.


Enumeration Type Documentation

anonymous enum

Enumerator:
PORT_BUFFER_SIZE 
PORT_BUFFER_MASK 
PORT_BUFFER_UNGET_SIZE 

anonymous enum

Enumerator:
PARSE_EOF 
PARSE_ERROR 
PARSE_ERROR_BUFFER_OVERFLOW 
PARSE_ERROR_EXPECTED_STRING 
PARSE_ERROR_EXPECTED_LIST 
PARSE_ERROR_BAD_CONS_SYNTAX 
PARSE_ERROR_EXPECTED_SYMBOL 
PARSE_EMPTY_GROUP 
PARSE_END_OF_GROUP 
PARSE_END_OF_LIST 
PARSE_LIST_ITEM_SEPARATOR 

anonymous enum

Enumerator:
MAX_INDENT_COLS 


Function Documentation

static void write_utf8_header ( fileport_t p  )  [static]

static void discard_utf8_header ( fileport_t p  )  [static]

static void check_for_ezscheme_file ( fileport_t p  )  [static]

static void fileport_init ( void *  ptr,
muse_cell  args 
) [static]

static void fileport_destroy ( void *  ptr  )  [static]

static void fileport_close ( void *  ptr  )  [static]

static size_t fileport_read ( void *  buffer,
size_t  nbytes,
void *  port 
) [static]

static size_t fileport_write ( void *  buffer,
size_t  nbytes,
void *  port 
) [static]

static int fileport_flush ( void *  port  )  [static]

muse_port_t muse_stdport ( muse_stdport_t  descriptor  ) 

static muse_cell fn_open_file ( muse_env env,
void *  context,
muse_cell  args 
) [static]

(open-file "filename.txt" ['for-reading 'for-writing]).

Returns a new file port for reading or writing to it. Use read and write with the returned port and when you're done with it, call close.

For example -

 (let ((f (open-file "output.txt" 'for-writing)))
     (write f '(hello world))
     (close f))

static muse_cell fn_destroy_stdports ( muse_env env,
void *  context,
muse_cell  args 
) [static]

The destructor that will be called at environment destruction time to free up the standard ports.

void muse_define_builtin_fileport (  ) 

Adds all file port definitions such as "open-file".

muse_port_t muse_assign_port ( FILE *  f,
int  mode 
)

Creates a port definition that you can use to read/write stuff from a given file pointer.

The returned port is only for use by the API when it has a file pointer and must use the port calls such as muse_pread() several times on the same port.

Ports assigned using muse_assign_port must be released using muse_unassign_port.

Parameters:
f The file that the new port should read from.
mode A combination of muse_port_mode_bits_t indicating properties of the file port.

void muse_unassign_port ( muse_port_t  p  ) 

Unassigns a file port which was earlier assigned using muse_assign_port.

Should not be used with other ports.

static void port_init_buffer ( muse_port_buffer_t buffer  )  [static]

static void port_destroy_buffer ( muse_port_buffer_t buffer  )  [static]

void port_init ( muse_port_base_t p  ) 

Intended to be called inside a particular port's init function at port creation time.

Sets up the port's buffers.

void port_destroy ( muse_port_base_t p  ) 

Intended to be called inside a particular ports destroy function at port destruction time.

Destroys the port's buffers.

int port_getc ( muse_port_base_t p  ) 

Same protocol as the system getc function, but works with the given port.

int port_ungetc ( int  c,
muse_port_base_t p 
)

Same protocol as the system ungetc function.

The only difference from the system version is that infinite ungetting is not supported. Only a maximum of 16 characters may be "ungot".

int port_putc ( int  c,
muse_port_base_t p 
)

Same protocol as the system putc function.

Flushes the port whenever a '
' character is put.

int port_eof ( muse_port_base_t port  ) 

Returns EOF if the port has reached end of stream.

similar to feof.

void port_close ( muse_port_base_t p  ) 

Flushes the port and call's the port's close function to release system resources.

size_t port_read ( void *  buffer,
size_t  nbytes,
muse_port_base_t port 
)

Wraps the port specific read function.

Any data pending in the input buffer is copied first before requesting the port for more data.

size_t port_write ( void *  buffer,
size_t  nbytes,
muse_port_base_t port 
)

Wraps the port specific write function.

Writes any data in the output buffer before calling the port-specific write function. If the buffer can hold all the given data as well, then the port's write function is not called and the given bytes are simply copied to the port buffer.

int port_flush ( muse_port_base_t port  ) 

Writes any data pending in the port's output buffer and then calls the port-specific flush function.

static void pretty_printer_reset ( muse_port_t  p  )  [static]

static void pretty_printer_indent (  )  [static]

static void pretty_printer_unindent (  )  [static]

static void pretty_printer_line_break ( muse_port_t  f  )  [static]

static void pretty_printer_move ( int  numc  )  [static]

int ez_update_col ( int  ch,
int  col 
)

static ez_result_t ez_result ( muse_cell  expr,
int  col_start,
int  col_end 
) [static]

ez_result_t ez_parse ( muse_port_t  p,
int  col,
muse_boolean  is_head 
)

Indentation dependent parsing of expressions - ezscheme.

muse_cell ez_parse_expr ( muse_port_t  p  ) 

static int peekc ( muse_port_t  f  )  [static]

white_space_t ez_skip_whitespace ( muse_port_t  f,
int  line,
int  col 
)

Skips all white space and comments following the current stream position in the given stream Returns the column position at which the next non-white space character starts.

static int _token_begin_list ( int  c  )  [inline, static]

static int _token_end_list ( int  c  )  [inline, static]

static ez_result_t _read_number ( muse_port_t  f,
int  col 
) [static]

Reads a decimal number starting from the current stream position.

static int hex ( int  c  )  [static]

static ez_result_t _read_hex ( muse_port_t  f,
int  col 
) [static]

Reads a hexadecimal number starting from the current stream position.

This does not include the "0x" prefix.

static ez_result_t _read_string ( muse_port_t  f,
int  col 
) [static]

Reads and returns the next string delimited by double quote characters.

static muse_boolean is_symbol_char ( int  c  )  [static]

static ez_result_t _read_symbol ( muse_port_t  f,
int  col 
) [static]

Reads a symbol from the current stream position.

Only named symbols are possible to be read by this. Anonymous symbols are never created by read.

static ez_result_t _read_atom ( muse_port_t  f,
int  col 
) [static]

An atom is a number, symbol or a string.

static muse_cell _read_list ( muse_port_t  f  )  [static]

Reads a list delimited by parentheses.

The list items are all separated by white space. The last pair of the list can be specified using the special dot notation - ex:

 (a b c . d) 

static muse_boolean is_macro_sexpr ( muse_cell  sexpr  )  [static]

Returns MUSE_TRUE if the given sexpr is a macro expression.

A macro expression is a list expression which has a symbol at its head that is defined to be a macro.

muse_cell muse_pread ( muse_port_t  f  ) 

Reads the next symbolic expression at the current stream position, ignoring white space and comment lines.

Parameters:
f The port from which the expression is to be read.

< Some error happened.

static void muse_print_q ( muse_port_t  f,
muse_cell  sexpr,
muse_boolean  quote 
) [static]

Prints the given s-expr to the given stream.

The quote parameter detemines whether strings should be printed with double-quote delimiters or just as strings.

static void muse_print_int ( muse_port_t  f,
muse_cell  i 
) [static]

static void muse_print_float ( muse_port_t  s,
muse_cell  f 
) [static]

static size_t muse_print_text ( muse_port_t  f,
muse_cell  t,
muse_boolean  quote 
) [static]

static void muse_print_list ( muse_port_t  f,
muse_cell  l,
muse_boolean  quote 
) [static]

static void muse_print_sym ( muse_port_t  f,
muse_cell  s 
) [static]

static void muse_print_lambda ( muse_port_t  f,
muse_cell  l,
muse_boolean  quote 
) [static]

static void muse_print_nativefn ( muse_port_t  f,
muse_cell  l 
) [static]

void muse_pprint ( muse_port_t  port,
muse_cell  sexpr 
)

void muse_pwrite ( muse_port_t  f,
muse_cell  sexpr 
)

Writes the given s-expression to the given stream.

If the expression contains only basic objects such as numbers, lists and symbols, then output of write is suitable to read back by muse_pread(). Otherwise, the only difference between write and print is that write encloses strings in quotes and print doesn't.

muse_port_t muse_port ( muse_cell  p  ) 

Takes a muSE port represented as a cell and returns the internal port object that it uses.

If the given thing is not a port, then it returns NULL.


Variable Documentation

fileport_type_t g_fileport_type [static]

Initial value:

{
    {
        {
            'muSE',
            'port',
            sizeof(fileport_t),
            NULL,
            NULL,
            fileport_init,
            NULL,
            fileport_destroy,
            NULL
        },

        fileport_close,
        fileport_read,
        fileport_write,
        fileport_flush
    },

    MUSE_NIL,
    MUSE_NIL
}

fileport_type_t g_port_type_stdin [static]

Initial value:

{
    {
        {
            'muSE',
            'port',
            sizeof(fileport_t),
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
        },

        NULL,
        fileport_read,
        NULL,
        NULL
    },

    MUSE_NIL,
    MUSE_NIL
}

fileport_type_t g_port_type_stdout [static]

Initial value:

{
    {
        {
            'muSE',
            'port',
            sizeof(fileport_t),
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
        },

        NULL,
        NULL,
        fileport_write,
        fileport_flush
    },

    MUSE_NIL,
    MUSE_NIL
}

fileport_t g_muse_stdports[3] [static]

Initial value:

int g_align_cols[MAX_INDENT_COLS] [static]

int g_align_level = 0 [static]

muse_boolean g_pretty_printer_enabled = MUSE_TRUE [static]

int g_tab_size = 4 [static]


Generated on Mon Sep 25 23:12:50 2006 for muSE by  doxygen 1.4.7