microlisp 0.1.0
A small Scheme-subset interpreter in modern C.
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
microlisp_internal.h File Reference
#include "microlisp/microlisp.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for microlisp_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mobj
 
struct  mpair
 
struct  mstring
 
struct  mclosure
 
struct  mprim
 
struct  menv
 
struct  ml_symtab_entry
 
struct  ml_symtab
 
struct  ml_error
 
struct  microlisp_state
 
struct  ml_reader
 

Macros

#define M_TAG_MASK   ((mvalue)0x7U)
 
#define M_TAG_OBJ   ((mvalue)0x0U)
 
#define M_TAG_FIX   ((mvalue)0x1U)
 
#define M_TAG_IMM   ((mvalue)0x2U)
 
#define M_TAG_SYM   ((mvalue)0x3U)
 
#define M_TAG_OF(v)   ((v) & M_TAG_MASK)
 
#define M_PAYLOAD(v)   ((v) >> 3)
 
#define M_IMM_ID_NIL   0U
 
#define M_IMM_ID_TRUE   1U
 
#define M_IMM_ID_FALSE   2U
 
#define M_IMM_ID_EOF   3U
 
#define M_IMM_ID_UNDEF   4U /* "no result" / unbound sentinel inside eval */
 
#define M_MAKE_IMM(id)   ((mvalue)(((mvalue)(id) << 3) | M_TAG_IMM))
 
#define MV_NIL   M_MAKE_IMM(M_IMM_ID_NIL)
 
#define MV_TRUE   M_MAKE_IMM(M_IMM_ID_TRUE)
 
#define MV_FALSE   M_MAKE_IMM(M_IMM_ID_FALSE)
 
#define MV_EOF   M_MAKE_IMM(M_IMM_ID_EOF)
 
#define MV_UNDEF   M_MAKE_IMM(M_IMM_ID_UNDEF)
 
#define M_FIX_MIN   ((int64_t) - ((int64_t)1 << 59))
 
#define M_FIX_MAX   ((int64_t)(((int64_t)1 << 59) - 1))
 

Typedefs

typedef uintptr_t mvalue
 
typedef enum mobj_type mobj_type
 
typedef struct mobj mobj
 
typedef struct mpair mpair
 
typedef struct mstring mstring
 
typedef struct mclosure mclosure
 
typedef microlisp_status(* ml_prim_fn) (struct microlisp_state *state, size_t argc, const mvalue *argv, mvalue *out)
 
typedef struct mprim mprim
 
typedef struct menv menv
 
typedef struct ml_symtab_entry ml_symtab_entry
 
typedef struct ml_symtab ml_symtab
 
typedef struct ml_error ml_error
 
typedef struct microlisp_state ml_state
 
typedef struct ml_reader ml_reader
 
typedef microlisp_status(* ml_out_fn) (const void *bytes, size_t len, void *user)
 

Enumerations

enum  mobj_type {
  OBJ_PAIR = 1 , OBJ_STRING = 2 , OBJ_CLOSURE = 3 , OBJ_PRIMITIVE = 4 ,
  OBJ_ENV = 5
}
 

Functions

static mvalue ml_make_fix (int64_t x)
 
static int64_t ml_fix_int (mvalue v)
 
static int ml_is_obj (mvalue v)
 
static int ml_is_fix (mvalue v)
 
static int ml_is_imm (mvalue v)
 
static int ml_is_sym (mvalue v)
 
static int ml_is_nil (mvalue v)
 
static int ml_is_bool (mvalue v)
 
static int ml_truthy (mvalue v)
 
static mvalue ml_make_bool (int b)
 
static mvalue ml_make_sym (uint32_t idx)
 
static uint32_t ml_sym_index (mvalue v)
 
static mobjml_as_obj (mvalue v)
 
static mpairml_as_pair (mvalue v)
 
static mstringml_as_string (mvalue v)
 
static mclosureml_as_closure (mvalue v)
 
static mprimml_as_prim (mvalue v)
 
static menvml_as_env (mvalue v)
 
static int ml_is_obj_type (mvalue v, mobj_type t)
 
static int ml_is_pair (mvalue v)
 
static int ml_is_string (mvalue v)
 
static int ml_is_closure (mvalue v)
 
static int ml_is_prim (mvalue v)
 
static int ml_is_env (mvalue v)
 
static int ml_is_procedure (mvalue v)
 
void * ml_raw_alloc (ml_state *s, size_t size)
 
void ml_raw_free (ml_state *s, void *p)
 
microlisp_status ml_gc_alloc_pair (ml_state *s, mvalue car, mvalue cdr, mvalue *out)
 
microlisp_status ml_gc_alloc_string (ml_state *s, const uint8_t *bytes, size_t len, mvalue *out)
 
microlisp_status ml_gc_alloc_closure (ml_state *s, mvalue env, mvalue params, mvalue body, mvalue *out)
 
microlisp_status ml_gc_alloc_primitive (ml_state *s, const char *name, ml_prim_fn fn, uint32_t arity_min, uint32_t arity_max, mvalue *out)
 
microlisp_status ml_gc_alloc_env (ml_state *s, mvalue parent, mvalue *out)
 
microlisp_status ml_gc_protect (ml_state *s, mvalue v)
 
void ml_gc_unprotect (ml_state *s, size_t n)
 
static size_t ml_gc_savepoint (const ml_state *s)
 
void ml_gc_restore (ml_state *s, size_t saved)
 
void ml_gc_collect (ml_state *s)
 
void ml_gc_free_all (ml_state *s)
 
microlisp_status ml_sym_intern (ml_state *s, const char *name, size_t len, mvalue *out)
 
const char * ml_sym_name (const ml_state *s, mvalue sym, size_t *out_len)
 
microlisp_status ml_env_define (ml_state *s, mvalue env, mvalue name, mvalue value)
 
microlisp_status ml_env_set (ml_state *s, mvalue env, mvalue name, mvalue value)
 
microlisp_status ml_env_lookup (const ml_state *s, mvalue env, mvalue name, mvalue *out)
 
microlisp_status ml_read (ml_state *s, ml_reader *r, mvalue *out)
 
microlisp_status ml_print (ml_state *s, mvalue v, int write_style, ml_out_fn out, void *user)
 
microlisp_status ml_print_to_alloc (ml_state *s, mvalue v, int write_style, char **out_bytes, size_t *out_len)
 
microlisp_status ml_eval (ml_state *s, mvalue form, mvalue env, mvalue *out)
 
microlisp_status ml_primitives_install (ml_state *s, mvalue env)
 
int ml_value_eq (mvalue a, mvalue b)
 
int ml_value_eqv (mvalue a, mvalue b)
 
microlisp_status ml_value_equal (ml_state *s, mvalue a, mvalue b, int *out_equal)
 
void ml_set_error (ml_state *s, size_t line, size_t column, const char *fmt,...) MICROLISP_PRINTF(4
 
void void ml_clear_error (ml_state *s)
 

Macro Definition Documentation

◆ M_FIX_MAX

#define M_FIX_MAX   ((int64_t)(((int64_t)1 << 59) - 1))

◆ M_FIX_MIN

#define M_FIX_MIN   ((int64_t) - ((int64_t)1 << 59))

◆ M_IMM_ID_EOF

#define M_IMM_ID_EOF   3U

◆ M_IMM_ID_FALSE

#define M_IMM_ID_FALSE   2U

◆ M_IMM_ID_NIL

#define M_IMM_ID_NIL   0U

◆ M_IMM_ID_TRUE

#define M_IMM_ID_TRUE   1U

◆ M_IMM_ID_UNDEF

#define M_IMM_ID_UNDEF   4U /* "no result" / unbound sentinel inside eval */

◆ M_MAKE_IMM

#define M_MAKE_IMM (   id)    ((mvalue)(((mvalue)(id) << 3) | M_TAG_IMM))

◆ M_PAYLOAD

#define M_PAYLOAD (   v)    ((v) >> 3)

◆ M_TAG_FIX

#define M_TAG_FIX   ((mvalue)0x1U)

◆ M_TAG_IMM

#define M_TAG_IMM   ((mvalue)0x2U)

◆ M_TAG_MASK

#define M_TAG_MASK   ((mvalue)0x7U)

◆ M_TAG_OBJ

#define M_TAG_OBJ   ((mvalue)0x0U)

◆ M_TAG_OF

#define M_TAG_OF (   v)    ((v) & M_TAG_MASK)

◆ M_TAG_SYM

#define M_TAG_SYM   ((mvalue)0x3U)

◆ MV_EOF

#define MV_EOF   M_MAKE_IMM(M_IMM_ID_EOF)

◆ MV_FALSE

#define MV_FALSE   M_MAKE_IMM(M_IMM_ID_FALSE)

◆ MV_NIL

#define MV_NIL   M_MAKE_IMM(M_IMM_ID_NIL)

◆ MV_TRUE

#define MV_TRUE   M_MAKE_IMM(M_IMM_ID_TRUE)

◆ MV_UNDEF

#define MV_UNDEF   M_MAKE_IMM(M_IMM_ID_UNDEF)

Typedef Documentation

◆ mclosure

typedef struct mclosure mclosure

◆ menv

typedef struct menv menv

◆ ml_error

typedef struct ml_error ml_error

◆ ml_out_fn

typedef microlisp_status(* ml_out_fn) (const void *bytes, size_t len, void *user)

◆ ml_prim_fn

typedef microlisp_status(* ml_prim_fn) (struct microlisp_state *state, size_t argc, const mvalue *argv, mvalue *out)

◆ ml_reader

typedef struct ml_reader ml_reader

◆ ml_state

typedef struct microlisp_state ml_state

◆ ml_symtab

typedef struct ml_symtab ml_symtab

◆ ml_symtab_entry

◆ mobj

typedef struct mobj mobj

◆ mobj_type

typedef enum mobj_type mobj_type

◆ mpair

typedef struct mpair mpair

◆ mprim

typedef struct mprim mprim

◆ mstring

typedef struct mstring mstring

◆ mvalue

typedef uintptr_t mvalue

Enumeration Type Documentation

◆ mobj_type

enum mobj_type
Enumerator
OBJ_PAIR 
OBJ_STRING 
OBJ_CLOSURE 
OBJ_PRIMITIVE 
OBJ_ENV 

Function Documentation

◆ ml_as_closure()

static mclosure * ml_as_closure ( mvalue  v)
inlinestatic

◆ ml_as_env()

static menv * ml_as_env ( mvalue  v)
inlinestatic

◆ ml_as_obj()

static mobj * ml_as_obj ( mvalue  v)
inlinestatic

◆ ml_as_pair()

static mpair * ml_as_pair ( mvalue  v)
inlinestatic

◆ ml_as_prim()

static mprim * ml_as_prim ( mvalue  v)
inlinestatic

◆ ml_as_string()

static mstring * ml_as_string ( mvalue  v)
inlinestatic

◆ ml_clear_error()

void void ml_clear_error ( ml_state s)

◆ ml_env_define()

microlisp_status ml_env_define ( ml_state s,
mvalue  env,
mvalue  name,
mvalue  value 
)

◆ ml_env_lookup()

microlisp_status ml_env_lookup ( const ml_state s,
mvalue  env,
mvalue  name,
mvalue out 
)

◆ ml_env_set()

microlisp_status ml_env_set ( ml_state s,
mvalue  env,
mvalue  name,
mvalue  value 
)

◆ ml_eval()

microlisp_status ml_eval ( ml_state s,
mvalue  form,
mvalue  env,
mvalue out 
)

◆ ml_fix_int()

static int64_t ml_fix_int ( mvalue  v)
inlinestatic

◆ ml_gc_alloc_closure()

microlisp_status ml_gc_alloc_closure ( ml_state s,
mvalue  env,
mvalue  params,
mvalue  body,
mvalue out 
)

◆ ml_gc_alloc_env()

microlisp_status ml_gc_alloc_env ( ml_state s,
mvalue  parent,
mvalue out 
)

◆ ml_gc_alloc_pair()

microlisp_status ml_gc_alloc_pair ( ml_state s,
mvalue  car,
mvalue  cdr,
mvalue out 
)

◆ ml_gc_alloc_primitive()

microlisp_status ml_gc_alloc_primitive ( ml_state s,
const char *  name,
ml_prim_fn  fn,
uint32_t  arity_min,
uint32_t  arity_max,
mvalue out 
)

◆ ml_gc_alloc_string()

microlisp_status ml_gc_alloc_string ( ml_state s,
const uint8_t *  bytes,
size_t  len,
mvalue out 
)

◆ ml_gc_collect()

void ml_gc_collect ( ml_state s)

◆ ml_gc_free_all()

void ml_gc_free_all ( ml_state s)

◆ ml_gc_protect()

microlisp_status ml_gc_protect ( ml_state s,
mvalue  v 
)

◆ ml_gc_restore()

void ml_gc_restore ( ml_state s,
size_t  saved 
)

◆ ml_gc_savepoint()

static size_t ml_gc_savepoint ( const ml_state s)
inlinestatic

◆ ml_gc_unprotect()

void ml_gc_unprotect ( ml_state s,
size_t  n 
)

◆ ml_is_bool()

static int ml_is_bool ( mvalue  v)
inlinestatic

◆ ml_is_closure()

static int ml_is_closure ( mvalue  v)
inlinestatic

◆ ml_is_env()

static int ml_is_env ( mvalue  v)
inlinestatic

◆ ml_is_fix()

static int ml_is_fix ( mvalue  v)
inlinestatic

◆ ml_is_imm()

static int ml_is_imm ( mvalue  v)
inlinestatic

◆ ml_is_nil()

static int ml_is_nil ( mvalue  v)
inlinestatic

◆ ml_is_obj()

static int ml_is_obj ( mvalue  v)
inlinestatic

◆ ml_is_obj_type()

static int ml_is_obj_type ( mvalue  v,
mobj_type  t 
)
inlinestatic

◆ ml_is_pair()

static int ml_is_pair ( mvalue  v)
inlinestatic

◆ ml_is_prim()

static int ml_is_prim ( mvalue  v)
inlinestatic

◆ ml_is_procedure()

static int ml_is_procedure ( mvalue  v)
inlinestatic

◆ ml_is_string()

static int ml_is_string ( mvalue  v)
inlinestatic

◆ ml_is_sym()

static int ml_is_sym ( mvalue  v)
inlinestatic

◆ ml_make_bool()

static mvalue ml_make_bool ( int  b)
inlinestatic

◆ ml_make_fix()

static mvalue ml_make_fix ( int64_t  x)
inlinestatic

◆ ml_make_sym()

static mvalue ml_make_sym ( uint32_t  idx)
inlinestatic

◆ ml_primitives_install()

microlisp_status ml_primitives_install ( ml_state s,
mvalue  env 
)

◆ ml_print()

microlisp_status ml_print ( ml_state s,
mvalue  v,
int  write_style,
ml_out_fn  out,
void *  user 
)

◆ ml_print_to_alloc()

microlisp_status ml_print_to_alloc ( ml_state s,
mvalue  v,
int  write_style,
char **  out_bytes,
size_t *  out_len 
)

◆ ml_raw_alloc()

void * ml_raw_alloc ( ml_state s,
size_t  size 
)

◆ ml_raw_free()

void ml_raw_free ( ml_state s,
void *  p 
)

◆ ml_read()

microlisp_status ml_read ( ml_state s,
ml_reader r,
mvalue out 
)

◆ ml_set_error()

void ml_set_error ( ml_state s,
size_t  line,
size_t  column,
const char *  fmt,
  ... 
)

◆ ml_sym_index()

static uint32_t ml_sym_index ( mvalue  v)
inlinestatic

◆ ml_sym_intern()

microlisp_status ml_sym_intern ( ml_state s,
const char *  name,
size_t  len,
mvalue out 
)

◆ ml_sym_name()

const char * ml_sym_name ( const ml_state s,
mvalue  sym,
size_t *  out_len 
)

◆ ml_truthy()

static int ml_truthy ( mvalue  v)
inlinestatic

◆ ml_value_eq()

int ml_value_eq ( mvalue  a,
mvalue  b 
)

◆ ml_value_equal()

microlisp_status ml_value_equal ( ml_state s,
mvalue  a,
mvalue  b,
int *  out_equal 
)

◆ ml_value_eqv()

int ml_value_eqv ( mvalue  a,
mvalue  b 
)