Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions
scheme.h File Reference
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  num
union  num.value

Defines

#define STANDALONE   1
#define USE_STRCASECMP   1
#define USE_STRLWR   1
#define SCHEME_EXPORT
#define USE_SCHEME_STACK
#define USE_MATH   1
#define USE_CHAR_CLASSIFIERS   1
#define USE_ASCII_NAMES   1
#define USE_STRING_PORTS   1
#define USE_TRACING   1
#define USE_PLIST   0
#define USE_ERROR_HOOK   1
#define USE_COLON_HOOK   1
#define STDIO_ADDS_CR   0
#define INLINE
#define USE_INTERFACE   0
#define SHOW_ERROR_LINE   1

Typedefs

typedef struct scheme
typedef struct cellcell_ptr
typedef void *(* func_alloc )(size_t)
typedef void(* func_dealloc )(void *)
typedef struct num num
typedef cell_ptr(* foreign_func )(scheme *, cell_ptr)

Functions

SCHEME_EXPORT schemescheme_init_new ()
SCHEME_EXPORT schemescheme_init_new_custom_alloc (func_alloc malloc, func_dealloc free)
SCHEME_EXPORT int scheme_init (scheme *sc)
SCHEME_EXPORT int scheme_init_custom_alloc (scheme *sc, func_alloc, func_dealloc)
SCHEME_EXPORT void scheme_deinit (scheme *sc)
void scheme_set_input_port_file (scheme *sc, FILE *fin)
void scheme_set_input_port_string (scheme *sc, char *start, char *past_the_end)
SCHEME_EXPORT void scheme_set_output_port_file (scheme *sc, FILE *fin)
void scheme_set_output_port_string (scheme *sc, char *start, char *past_the_end)
SCHEME_EXPORT void scheme_load_file (scheme *sc, FILE *fin)
SCHEME_EXPORT void scheme_load_named_file (scheme *sc, FILE *fin, const char *filename)
SCHEME_EXPORT void scheme_load_string (scheme *sc, const char *cmd)
SCHEME_EXPORT cell_ptr scheme_apply0 (scheme *sc, const char *procname)
SCHEME_EXPORT cell_ptr scheme_call (scheme *sc, cell_ptr func, cell_ptr args)
SCHEME_EXPORT cell_ptr scheme_eval (scheme *sc, cell_ptr obj)
void scheme_set_external_data (scheme *sc, void *p)
SCHEME_EXPORT void scheme_define (scheme *sc, cell_ptr env, cell_ptr symbol, cell_ptr value)
cell_ptr _cons (scheme *sc, cell_ptr a, cell_ptr b, int immutable)
cell_ptr mk_integer (scheme *sc, long num)
cell_ptr mk_real (scheme *sc, double num)
cell_ptr mk_symbol (scheme *sc, const char *name)
cell_ptr gensym (scheme *sc)
cell_ptr mk_string (scheme *sc, const char *str)
cell_ptr mk_counted_string (scheme *sc, const char *str, int len)
cell_ptr mk_empty_string (scheme *sc, int len, char fill)
cell_ptr mk_character (scheme *sc, int c)
cell_ptr mk_foreign_func (scheme *sc, foreign_func f)
cell_ptr mk_blackbox (scheme *sc, void *b)
void putstr (scheme *sc, const char *s)
int list_length (scheme *sc, cell_ptr a)
int eqv (cell_ptr a, cell_ptr b)
void finalize_blackbox (void *p)

Class Documentation

struct num

Definition at line 122 of file scheme.h.

Class Members
char is_fixnum
union num value
union num.value

Definition at line 124 of file scheme.h.

Class Members
long ivalue
double rvalue

Define Documentation

#define INLINE

Definition at line 104 of file scheme.h.

#define SCHEME_EXPORT

Definition at line 24 of file scheme.h.

#define SHOW_ERROR_LINE   1

Definition at line 112 of file scheme.h.

#define STANDALONE   1

Definition at line 16 of file scheme.h.

#define STDIO_ADDS_CR   0

Definition at line 100 of file scheme.h.

#define USE_ASCII_NAMES   1

Definition at line 67 of file scheme.h.

#define USE_CHAR_CLASSIFIERS   1

Definition at line 63 of file scheme.h.

#define USE_COLON_HOOK   1

Definition at line 88 of file scheme.h.

#define USE_ERROR_HOOK   1

Definition at line 84 of file scheme.h.

#define USE_INTERFACE   0

Definition at line 108 of file scheme.h.

#define USE_MATH   1

Definition at line 59 of file scheme.h.

#define USE_PLIST   0

Definition at line 79 of file scheme.h.

Definition at line 51 of file scheme.h.

#define USE_STRCASECMP   1

Definition at line 20 of file scheme.h.

#define USE_STRING_PORTS   1

Definition at line 71 of file scheme.h.

#define USE_STRLWR   1

Definition at line 22 of file scheme.h.

#define USE_TRACING   1

Definition at line 75 of file scheme.h.


Typedef Documentation

typedef struct cell* cell_ptr

Definition at line 116 of file scheme.h.

Definition at line 148 of file scheme.h.

typedef void*(* func_alloc)(size_t)

Definition at line 118 of file scheme.h.

typedef void(* func_dealloc)(void *)

Definition at line 119 of file scheme.h.

typedef struct num num
typedef struct scheme

Definition at line 115 of file scheme.h.


Function Documentation

cell_ptr _cons ( scheme sc,
cell_ptr  a,
cell_ptr  b,
int  immutable 
)

Definition at line 813 of file scheme.c.

                                                                  {
  cell_ptr x = get_cell(sc,a, b);

  typeflag(x) = T_PAIR;
  if(immutable) {
    setimmutable(x);
  }
  car(x) = a;
  cdr(x) = b;
  return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int eqv ( cell_ptr  a,
cell_ptr  b 
)

Definition at line 2099 of file scheme.c.

                                {
     if (is_string(a)) {
          if (is_string(b))
               return (strvalue(a) == strvalue(b));
          else
               return (0);
     } else if (is_number(a)) {
          if (is_number(b)) {
               if (num_is_integer(a) == num_is_integer(b))
                    return num_eq(nvalue(a),nvalue(b));
          }
          return (0);
     } else if (is_character(a)) {
          if (is_character(b))
               return charvalue(a)==charvalue(b);
          else
               return (0);
     } else if (is_port(a)) {
          if (is_port(b))
               return a==b;
          else
               return (0);
     } else if (is_proc(a)) {
          if (is_proc(b))
               return procnum(a)==procnum(b);
          else
               return (0);
     } else {
          return (a == b);
     }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void finalize_blackbox ( void *  p)

Definition at line 25 of file tinyscheme_tm.cpp.

                                {
       tm_delete((blackbox*)p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr gensym ( scheme sc)

Definition at line 1067 of file scheme.c.

                                      {
     cell_ptr x;
     char name[40];

     for(; sc->gensym_cnt<LONG_MAX; sc->gensym_cnt++) {
          snprintf(name,40,"gensym-%ld",sc->gensym_cnt);

          /* first check oblist */
          x = oblist_find_by_name(sc, name);

          if (x != sc->NIL) {
               continue;
          } else {
               x = oblist_add_by_name(sc, name);
               return (x);
          }
     }

     return sc->NIL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int list_length ( scheme sc,
cell_ptr  a 
)

Definition at line 3522 of file scheme.c.

                                        {
    int i=0;
    cell_ptr slow, fast;

    slow = fast = a;
    while (1)
    {
        if (fast == sc->NIL)
                return i;
        if (!is_pair(fast))
                return -2 - i;
        fast = cdr(fast);
        ++i;
        if (fast == sc->NIL)
                return i;
        if (!is_pair(fast))
                return -2 - i;
        ++i;
        fast = cdr(fast);

        /* Safe because we would have already returned if `fast'
           encountered a non-pair. */
        slow = cdr(slow);
        if (fast == slow)
        {
            /* the fast pointer has looped back around and caught up
               with the slow pointer, hence the structure is circular,
               not of finite length, and therefore not a list */
            return -1;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_blackbox ( scheme sc,
void *  b 
)

Definition at line 1014 of file scheme.c.

                                                           {
       cell_ptr x = get_cell(sc, sc->NIL, sc->NIL);
       typeflag(x) = (T_BLACKBOX | T_ATOM);
       car(x) = blackbox;
       return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_character ( scheme sc,
int  c 
)

Definition at line 939 of file scheme.c.

                                                   {
  cell_ptr x = get_cell(sc,sc->NIL, sc->NIL);

  typeflag(x) = (T_CHARACTER | T_ATOM);
  ivalue_unchecked(x)= c;
  set_num_integer(x);
  return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_counted_string ( scheme sc,
const char *  str,
int  len 
)

Definition at line 998 of file scheme.c.

                                                                           {
     cell_ptr x = get_cell(sc, sc->NIL, sc->NIL);
     typeflag(x) = (T_STRING | T_ATOM);
     strvalue(x) = store_string(sc,len,str,0);
     strlength(x) = len;
     return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_empty_string ( scheme sc,
int  len,
char  fill 
)

Definition at line 1006 of file scheme.c.

                                                                   {
     cell_ptr x = get_cell(sc, sc->NIL, sc->NIL);
     typeflag(x) = (T_STRING | T_ATOM);
     strvalue(x) = store_string(sc,len,0,fill);
     strlength(x) = len;
     return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 931 of file scheme.c.

                                                     {
  cell_ptr x = get_cell(sc, sc->NIL, sc->NIL);

  typeflag(x) = (T_FOREIGN | T_ATOM);
  x->_object._ff=f;
  return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_integer ( scheme sc,
long  num 
)

Definition at line 949 of file scheme.c.

                                                    {
  cell_ptr x = get_cell(sc,sc->NIL, sc->NIL);

  typeflag(x) = (T_NUMBER | T_ATOM);
  ivalue_unchecked(x)= num;
  set_num_integer(x);
  return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_real ( scheme sc,
double  num 
)

Definition at line 958 of file scheme.c.

                                                 {
  cell_ptr x = get_cell(sc,sc->NIL, sc->NIL);

  typeflag(x) = (T_NUMBER | T_ATOM);
  rvalue_unchecked(x)= n;
  set_num_real(x);
  return (x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_string ( scheme sc,
const char *  str 
)

Definition at line 994 of file scheme.c.

                                                          {
     return mk_counted_string(sc,str,strlen(str));
}

Here is the call graph for this function:

Here is the caller graph for this function:

cell_ptr mk_symbol ( scheme sc,
const char *  name 
)

Definition at line 1054 of file scheme.c.

                                                           {
     cell_ptr x;

     /* first check oblist */
     x = oblist_find_by_name(sc, name);
     if (x != sc->NIL) {
          return (x);
     } else {
          x = oblist_add_by_name(sc, name);
          return (x);
     }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void putstr ( scheme sc,
const char *  s 
)

Definition at line 1585 of file scheme.c.

                                                 {
  port *pt=sc->outport->_object._port;
  if(pt->kind&port_file) {
    fputs(s,pt->rep.stdio.file);
  } else {
    for(;*s;s++) {
      if(pt->rep.string.curr!=pt->rep.string.past_the_end) {
      *pt->rep.string.curr++=*s;
      } else if(pt->kind&port_srfi6&&realloc_port_string(sc,pt)) {
      *pt->rep.string.curr++=*s;
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

SCHEME_EXPORT cell_ptr scheme_apply0 ( scheme sc,
const char *  procname 
)
SCHEME_EXPORT cell_ptr scheme_call ( scheme sc,
cell_ptr  func,
cell_ptr  args 
)

Here is the caller graph for this function:

SCHEME_EXPORT void scheme_define ( scheme sc,
cell_ptr  env,
cell_ptr  symbol,
cell_ptr  value 
)

Definition at line 4771 of file scheme.c.

                                                                                {
     cell_ptr x;

     x=find_slot_in_env(sc,envir,symbol,0);
     if (x != sc->NIL) {
          set_slot_in_env(sc, x, value);
     } else {
          new_slot_spec_in_env(sc, envir, symbol, value);
     }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4678 of file scheme.c.

                               {
  int i;

#if SHOW_ERROR_LINE
  char *fname;
#endif

  sc->oblist=sc->NIL;
  sc->global_env=sc->NIL;
  dump_stack_free(sc);
  sc->envir=sc->NIL;
  sc->code=sc->NIL;
  sc->args=sc->NIL;
  sc->value=sc->NIL;
  if(is_port(sc->inport)) {
    typeflag(sc->inport) = T_ATOM;
  }
  sc->inport=sc->NIL;
  sc->outport=sc->NIL;
  if(is_port(sc->save_inport)) {
    typeflag(sc->save_inport) = T_ATOM;
  }
  sc->save_inport=sc->NIL;
  if(is_port(sc->loadport)) {
    typeflag(sc->loadport) = T_ATOM;
  }
  sc->loadport=sc->NIL;
  sc->gc_verbose=0;
  gc(sc,sc->NIL,sc->NIL);

  for(i=0; i<=sc->last_cell_seg; i++) {
    sc->free(sc->alloc_seg[i]);
  }

#if SHOW_ERROR_LINE
  fname = sc->load_stack[i].rep.stdio.filename;

  for(i=0; i<sc->file_i; i++) {
    if(fname)
      sc->free(fname);
  }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Here is the caller graph for this function:

Definition at line 4553 of file scheme.c.

                            {
 return scheme_init_custom_alloc(sc,malloc,free);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4557 of file scheme.c.

                                                                               {
  int i, n=sizeof(dispatch_table)/sizeof(dispatch_table[0]);
  cell_ptr x;

  num_zero.is_fixnum=1;
  num_zero.value.ivalue=0;
  num_one.is_fixnum=1;
  num_one.value.ivalue=1;

#if USE_INTERFACE
  sc->vptr=&vtbl;
#endif
  sc->gensym_cnt=0;
  sc->malloc=malloc;
  sc->free=free;
  sc->last_cell_seg = -1;
  sc->sink = &sc->_sink;
  sc->NIL = &sc->_NIL;
  sc->T = &sc->_HASHT;
  sc->F = &sc->_HASHF;
  sc->EOF_OBJ=&sc->_EOF_OBJ;
  sc->free_cell = &sc->_NIL;
  sc->fcells = 0;
  sc->no_memory=0;
  sc->inport=sc->NIL;
  sc->outport=sc->NIL;
  sc->save_inport=sc->NIL;
  sc->loadport=sc->NIL;
  sc->nesting=0;
  sc->interactive_repl=0;

  if (alloc_cellseg(sc,FIRST_CELLSEGS) != FIRST_CELLSEGS) {
    sc->no_memory=1;
    return 0;
  }
  sc->gc_verbose = 0;
  dump_stack_initialize(sc);
  sc->code = sc->NIL;
  sc->tracing=0;

  /* init sc->NIL */
  typeflag(sc->NIL) = (T_ATOM | MARK);
  car(sc->NIL) = cdr(sc->NIL) = sc->NIL;
  /* init T */
  typeflag(sc->T) = (T_ATOM | MARK);
  car(sc->T) = cdr(sc->T) = sc->T;
  /* init F */
  typeflag(sc->F) = (T_ATOM | MARK);
  car(sc->F) = cdr(sc->F) = sc->F;
  /* init sink */
  typeflag(sc->sink) = (T_PAIR | MARK);
  car(sc->sink) = sc->NIL;
  /* init c_nest */
  sc->c_nest = sc->NIL;

  sc->oblist = oblist_initial_value(sc);
  /* init global_env */
  new_frame_in_env(sc, sc->NIL);
  sc->global_env = sc->envir;
  /* init else */
  x = mk_symbol(sc,"else");
  new_slot_in_env(sc, x, sc->T);

  assign_syntax(sc, "lambda");
  assign_syntax(sc, "quote");
  assign_syntax(sc, "define");
  assign_syntax(sc, "if");
  assign_syntax(sc, "begin");
  assign_syntax(sc, "set!");
  assign_syntax(sc, "let");
  assign_syntax(sc, "let*");
  assign_syntax(sc, "letrec");
  assign_syntax(sc, "cond");
  assign_syntax(sc, "delay");
  assign_syntax(sc, "and");
  assign_syntax(sc, "or");
  assign_syntax(sc, "cons-stream");
  assign_syntax(sc, "macro");
  assign_syntax(sc, "case");

  for(i=0; i<n; i++) {
    if(dispatch_table[i].name!=0) {
      assign_proc(sc, (enum scheme_opcodes)i, dispatch_table[i].name);
    }
  }

  /* initialization of global pointers to special symbols */
  sc->LAMBDA = mk_symbol(sc, "lambda");
  sc->QUOTE = mk_symbol(sc, "quote");
  sc->QQUOTE = mk_symbol(sc, "quasiquote");
  sc->UNQUOTE = mk_symbol(sc, "unquote");
  sc->UNQUOTESP = mk_symbol(sc, "unquote-splicing");
  sc->FEED_TO = mk_symbol(sc, "=>");
  sc->COLON_HOOK = mk_symbol(sc,"*colon-hook*");
  sc->ERROR_HOOK = mk_symbol(sc, "*error-hook*");
  sc->SHARP_HOOK = mk_symbol(sc, "*sharp-hook*");
  sc->COMPILE_HOOK = mk_symbol(sc, "*compile-hook*");

  return !sc->no_memory;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4532 of file scheme.c.

                          {
  scheme *sc=(scheme*)malloc(sizeof(scheme));
  if(!scheme_init(sc)) {
    free(sc);
    return 0;
  } else {
    return sc;
  }
}

Here is the call graph for this function:

Definition at line 4542 of file scheme.c.

                                                                           {
  scheme *sc=(scheme*)malloc(sizeof(scheme));
  if(!scheme_init_custom_alloc(sc,malloc,free)) {
    free(sc);
    return 0;
  } else {
    return sc;
  }
}

Here is the call graph for this function:

SCHEME_EXPORT void scheme_load_file ( scheme sc,
FILE *  fin 
)

Definition at line 4722 of file scheme.c.

{ scheme_load_named_file(sc,fin,0); }

Here is the call graph for this function:

Here is the caller graph for this function:

SCHEME_EXPORT void scheme_load_named_file ( scheme sc,
FILE *  fin,
const char *  filename 
)

Definition at line 4724 of file scheme.c.

                                                                         {
  dump_stack_reset(sc);
  sc->envir = sc->global_env;
  sc->file_i=0;
  sc->load_stack[0].kind=port_input|port_file;
  sc->load_stack[0].rep.stdio.file=fin;
  sc->loadport=mk_port(sc,sc->load_stack);
  sc->retcode=0;
  if(fin==stdin) {
    sc->interactive_repl=1;
  }

#if SHOW_ERROR_LINE
  sc->load_stack[0].rep.stdio.curr_line = 0;
  if(fin!=stdin && filename)
    sc->load_stack[0].rep.stdio.filename = store_string(sc, strlen(filename), filename, 0);
#endif

  sc->inport=sc->loadport;
  sc->args = mk_integer(sc,sc->file_i);
  Eval_Cycle(sc, OP_T0LVL);
  typeflag(sc->loadport)=T_ATOM;
  if(sc->retcode==0) {
    sc->retcode=sc->nesting!=0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

SCHEME_EXPORT void scheme_load_string ( scheme sc,
const char *  cmd 
)

Definition at line 4751 of file scheme.c.

                                                     {
  dump_stack_reset(sc);
  sc->envir = sc->global_env;
  sc->file_i=0;
  sc->load_stack[0].kind=port_input|port_string;
  sc->load_stack[0].rep.string.start=(char*)cmd; /* This func respects const */
  sc->load_stack[0].rep.string.past_the_end=(char*)cmd+strlen(cmd);
  sc->load_stack[0].rep.string.curr=(char*)cmd;
  sc->loadport=mk_port(sc,sc->load_stack);
  sc->retcode=0;
  sc->interactive_repl=0;
  sc->inport=sc->loadport;
  sc->args = mk_integer(sc,sc->file_i);
  Eval_Cycle(sc, OP_T0LVL);
  typeflag(sc->loadport)=T_ATOM;
  if(sc->retcode==0) {
    sc->retcode=sc->nesting!=0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scheme_set_external_data ( scheme sc,
void *  p 
)

Definition at line 4674 of file scheme.c.

                                                   {
 sc->ext_data=p;
}
void scheme_set_input_port_file ( scheme sc,
FILE *  fin 
)

Definition at line 4658 of file scheme.c.

                                                       {
  sc->inport=port_from_file(sc,fin,port_input);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scheme_set_input_port_string ( scheme sc,
char *  start,
char *  past_the_end 
)

Definition at line 4662 of file scheme.c.

                                                                               {
  sc->inport=port_from_string(sc,start,past_the_end,port_input);
}

Here is the call graph for this function:

SCHEME_EXPORT void scheme_set_output_port_file ( scheme sc,
FILE *  fin 
)

Definition at line 4666 of file scheme.c.

                                                         {
  sc->outport=port_from_file(sc,fout,port_output);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scheme_set_output_port_string ( scheme sc,
char *  start,
char *  past_the_end 
)

Definition at line 4670 of file scheme.c.

                                                                                {
  sc->outport=port_from_string(sc,start,past_the_end,port_output);
}

Here is the call graph for this function: