Ejemplo n.º 1
0
Archivo: lisp.c Proyecto: jbulow/tort
tort_v _tort_m_initializer__lisp(tort_tp tort_v init)
{
  tort_v _mt_cons = tort_mtable_create_class("cons", tort_mt(pair)); // FIXME: tort_mtable_create_class().
  tort_mtable_create_class("list", 0); // FIXME: tort_mtable_create_class().

  /* Dependency. */
  tort_send(tort_s(load), tort_mt(dynlib), tort_string_new_cstr("libtortext"));

  /* Reused methods. */
  tort_add_method(tort__mt(fixnum), "lisp_write", _tort_m_fixnum___inspect);
  tort_add_method(tort__mt(string), "lisp_write", _tort_m_string___inspect);
  tort_add_method(tort__mt(method), "lisp_write", _tort_m_method___inspect);
  tort_add_method(tort__mt(message), "lisp_write", _tort_m_message___inspect);
  tort_add_method(tort__mt(nil),    "lisp_write", _tort_m_nil___inspect);

  tort_add_method(_mt_cons, "value", _tort_m_cons__car);

  tort_add_method(_mt_cons, "lisp_write", _tort_m_list__lisp_write);
  tort_add_method(_mt_cons, "_inspect", _tort_m_list__lisp_write);
  tort_add_method(tort__mt(nil),  "lisp_write", _tort_m_list__lisp_write);
  tort_add_method(_mt_cons, "size", _tort_m_list__size);
  tort_add_method(tort__mt(nil),  "size", _tort_m_list__size);
  tort_add_method(_mt_cons, "list->vector", _tort_m_list__list_TO_vector);
  tort_add_method(tort__mt(nil),  "list->vector", _tort_m_list__list_TO_vector);

  tort_send(tort_s(set), tort_(_printf_dispatch), tort_c('O'), tort_s(printf_lisp_write));

  return _mt_cons;
}
Ejemplo n.º 2
0
Archivo: init.c Proyecto: jbulow/tort
tort_v tort_runtime_create_ (int *argcp, char ***argvp, char ***envp)
{
  tort_mtable *obj_mt, *cls_mt;
  tort_v init_backlog[10]; int init_backlog_n = 0;

  {
    char *s;
    if ( (s = getenv("TORT_INIT_DEBUG")) && *s )
      _tort_init_debug = atoi(s);
  }

  assert(sizeof(tort_header) % sizeof(tort_v) == 0);
  INIT(malloc);

  /* Create runtime object. */
#if TORT_MULTIPLICITY
  _tort = tort_ref(tort_runtime, tort_allocate(0, sizeof(tort_runtime)));
#endif

  tort_(_initialized) = 0;

  INIT(error);

  /* Setup environment from main. */
  tort_(_argc) = *argcp;
  tort_(_argv) = *argvp;
  tort_(_env)  = *envp;
  tort_(stack_bottom) = envp;
  
  /* Allocate and initialize mtables */
  INIT(mtable);

  tort_h(_tort)->mtable = tort__mt(runtime);
  tort_h(_tort)->applyf = _tort_m_object___cannot_apply;

#if ! TORT_NIL_IS_ZERO
  /* Create the nil object. */
  tort_nil = tort_allocate(tort__mt(nil), sizeof(tort_object));
#endif

  /* Create the boolean objects. */
  tort_true = tort_allocate(tort__mt(boolean), sizeof(tort_object));
#if ! TORT_FALSE_IS_NIL
  tort_false = tort_allocate(tort__mt(boolean), sizeof(tort_object));
#endif

  /* Backpatch object delegate as nil. */
  tort_ref(tort_mtable, tort__mt(object))->delegate = tort_nil;

  /* Initialize the message reference. */
  _tort_message = tort_nil;
  tort_(message) = tort_nil;

  /* Initialize lookup(). */
  INIT(lookup);
  
  /*******************************************************/
  /* Messaging Boot strap. */

  /* Create the symbol table. */
  tort_(symbols) = tort_map_new();
  
  obj_mt = tort__mt(mtable);
  cls_mt = tort_h_mtable(obj_mt);
  
  tort__s(lookup) = tort_symbol_new("lookup");
  tort_add_method(cls_mt, "lookup", _tort_m_mtable__lookup);

  tort__s(add_method) = tort_symbol_new("add_method");
  tort_add_method(cls_mt, "add_method", _tort_m_mtable__add_method);

  tort__s(allocate) = tort_symbol_new("allocate");
  tort_send(tort__s(add_method), cls_mt, tort__s(allocate), tort_method_new(_tort_M_object__allocate, 0));

  /******************************************************/

  /* Create the core symbols. */
  INIT(symbol);

  /* Create the mtable map. */
  tort_(m_mtable) = tort_map_new();
#define tort_d_mt(X) \
  if ( tort__mt(X) )  _tort_m_map__set(tort_ta tort_(m_mtable), tort_symbol_new(#X), tort__mt(X));
#include "tort/d_mt.h"

  /* Install core methods. */
  INIT(method);

  /* Start initializer. */
  tort_(initializer) = tort_send(tort__s(new), tort__mt(initializer));
  while ( init_backlog_n > 0 )
    tort_send(tort__s(set), tort_(initializer), init_backlog[-- init_backlog_n], tort__s(initialized));

  INIT(eq);
  INIT(cmp);

  /* Add core slots. */
  INIT(slot);

  /* Create the root table. */
  tort_(root) = tort_map_new();

  /* Symbol Encoder. */
  INIT(symbol_encoder);

  /* Uncloneable objects. */
  tort_add_method(tort__mt(symbol),  "clone", _tort_m_object__identity);  
  tort_add_method(tort__mt(nil),     "clone", _tort_m_object__identity);
  tort_add_method(tort__mt(ptr),     "clone", _tort_m_object__identity);
  tort_add_method(tort__mt(tagged),  "clone", _tort_m_object__identity);
  tort_add_method(tort__mt(boolean), "clone", _tort_m_object__identity);

  /* Initialize system method table. */
  tort_h(_tort)->mtable = tort_mtable_new_class(tort__mt(object));

  /* Subsystem initialization. */
  INIT(gc);

  /* unknown caller_info */
  tort_(unknown_caller_info) = tort_send(tort__s(_allocate), tort__mt(caller_info), tort_i(sizeof(tort_caller_info)));
  tort_(unknown_caller_info)->file = "<unknown>";

  /* Setup the root namespace. */
#define ROOT(N,V) tort_send(tort__s(set), tort_(root), tort_symbol_new(#N), (V))
  ROOT(runtime, tort_ref_box(_tort));
  ROOT(initializer, tort_(initializer));
  ROOT(nil, tort_nil);
  ROOT(true, tort_true);
  ROOT(false, tort_false);
  ROOT(symbols, tort_(symbols));
  ROOT(mtable, tort_(m_mtable));
  ROOT(unknown_caller_info, tort_(unknown_caller_info));
  ROOT(tag_bits, tort_i(TORT_TAG_BITS));
  ROOT(word_size, tort_i(sizeof(tort_v)));
  ROOT(object_header_size, tort_i(sizeof(tort_header)));

  INIT(io);
  INIT(printf);
  INIT(debug);
  INIT(dynlib);

  {
    int i; tort_v m = tort_map_new();
    for ( i = 0; i < 1 << TORT_TAG_BITS; ++ i ) {
      tort_v k = tort_i(i), v = tort_(tagged_header)[i].mtable;
      if ( ! v ) v = tort_nil;
      tort_send(tort__s(set), m, k, v);
      tort_send(tort__s(set), m, v, k);
    }
    ROOT(tagged_mtables, m);
  }

  {
    int i; tort_v v = tort_vector_new(0, 0);
    for ( i = 0; i < tort_(_argc) && tort_(_argv)[i]; ++ i ) {
      tort_send(tort__s(add), v, tort_string_new_cstr(tort_(_argv)[i]));
    }
    ROOT(argv, v);
  }

  INIT(gc_ready);

  tort_(_initialized) = tort_true;

  // fprintf(stderr, "\ntort: initialized\n");
#undef ROOT
#undef INIT

  return tort_ref_box(_tort);
}
Ejemplo n.º 3
0
tort_v tort_add_class_method(tort_v mtable, const char *name, void *applyf)
{
  return tort_add_method(tort_h_ref(mtable)->mtable, name, applyf);
}
Ejemplo n.º 4
0
Archivo: gc.c Proyecto: jbulow/tort
tort_v _tort_m_initializer__gc(tort_tp tort_v init)
{
  tort_add_method(tort__mt(object), "__finalize",  _tort_m_object__identity);
  return init;
}