Esempio n. 1
0
File: lisp.c Progetto: 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;
}
Esempio n. 2
0
int main(int argc, char **argv, char **environ)
{
  tort_v io;
  tort_v st;
  tort_v v;

  tort_runtime_create();

  io = tort_stdout;

  st = tort_send(tort_s(load), tort_mt(dynlib), tort_string_new_cstr("libtortlisp"));
  (void) st;

  // tort_send(tort_s(_inspect), st, io);
  tort_send(tort_s(lisp_write), tort_nil, io);
  tort_printf(io, "\n");

  tort_send(tort_s(lisp_write), tort_true, io);
  tort_printf(io, "\n");

  tort_send(tort_s(lisp_write), tort_false, io);
  tort_printf(io, "\n");

  v = tort_send(tort_s(new), tort_mt(cons), tort_true, tort_false);
  tort_send(tort_s(lisp_write), v, io);
  tort_printf(io, "\n");

  tort_printf(io, "\nDONE\n");

  return 0;
}
Esempio n. 3
0
File: lisp.c Progetto: jbulow/tort
tort_v _tort_m_list__lisp_write(tort_tp tort_v rcvr, tort_v io) /**/
{
  tort_v x;
  if ( tort_pairQ(rcvr) &&
       tort_car(rcvr) == tort_s(quote) &&
       tort_pairQ(x = tort_cdr(rcvr)) &&
       tort_cdr(x) == tort_nil
       ) {
    tort_printf(io, "'");
    return_tort_send(tort_s(lisp_write), tort_car(x), io);
  }
  tort_printf(io, "(");
  while ( rcvr != tort_nil ) {
    if ( tort_h_mtable(rcvr) == tort_mt(cons) ) {
      tort_send(tort_s(lisp_write), tort_ref(tort_cons, rcvr)->car, io);
      rcvr = tort_ref(tort_cons, rcvr)->cdr;
      if ( rcvr == tort_nil ) break;
    } else {
      tort_printf(io, ". ");
      tort_send(tort_s(lisp_write), rcvr, io);
      break;
    }
    tort_printf(io, " "); 
  } 
  tort_printf(io, ")");
  return tort_nil;
}
Esempio n. 4
0
File: lisp.c Progetto: jbulow/tort
tort_v _tort_m_list__size(tort_tp tort_cons *rcvr) /**/
{
  size_t i = 0;
  while ( rcvr != tort_nil )  {
    ++ i;
    if ( tort_h_mtable(rcvr) == tort_mt(cons) ) {
      rcvr = rcvr->cdr;
    } else {
      break;
    }
  }
  return tort_i(i);
}
Esempio n. 5
0
File: lisp.c Progetto: jbulow/tort
tort_v _tort_m_list__list_TO_vector(tort_tp tort_v rcvr, tort_v io) /**/
{
  tort_v size = tort_send(tort__s(size), rcvr);
  tort_v vec = tort_vector_new(0, tort_I(size));
  size_t i = 0;
  while ( rcvr != tort_nil ) {
    if ( tort_h_mtable(rcvr) == tort_mt(cons) ) {
      tort_vector_data(vec)[i ++] = tort_ref(tort_cons, rcvr)->car;
      rcvr = tort_ref(tort_cons, rcvr)->cdr;
    } else {
      tort_vector_data(vec)[i ++] = rcvr;
      break;
    }
  } 
  return vec;
}
Esempio n. 6
0
File: lisp.c Progetto: jbulow/tort
static int tort_pairQ(tort_v o)
{
  return tort_h_mtable(o) == tort_mt(cons);
}