+ if (obj == 0)
+ {
+ fprintf(out, "()");
+ return;
+ }
+
+ switch (lisp_type(obj))
+ {
+ case LISP_TYPE_EOF :
+ fputs("#<eof>", out);
+ break;
+
+ case LISP_TYPE_PARSE_ERROR :
+ fputs("#<error>", out);
+ break;
+
+ case LISP_TYPE_INTEGER :
+ fprintf(out, "%d", lisp_integer(obj));
+ break;
+
+ case LISP_TYPE_REAL :
+ fprintf(out, "%f", lisp_real(obj));
+ break;
+
+ case LISP_TYPE_SYMBOL :
+ fputs(lisp_symbol(obj), out);
+ break;
+
+ case LISP_TYPE_STRING :
+ {
+ char *p;
+
+ fputc('"', out);
+ for (p = lisp_string(obj); *p != 0; ++p)
+ {
+ if (*p == '"' || *p == '\\')
+ fputc('\\', out);
+ fputc(*p, out);
+ }
+ fputc('"', out);
+ }
+ break;
+
+ case LISP_TYPE_CONS :
+ case LISP_TYPE_PATTERN_CONS :
+ fputs(lisp_type(obj) == LISP_TYPE_CONS ? "(" : "#?(", out);
+ while (obj != 0)
+ {
+ lisp_dump(lisp_car(obj), out);
+ obj = lisp_cdr(obj);
+ if (obj != 0)
+ {
+ if (lisp_type(obj) != LISP_TYPE_CONS
+ && lisp_type(obj) != LISP_TYPE_PATTERN_CONS)
+ {
+ fputs(" . ", out);
+ lisp_dump(obj, out);
+ break;
+ }
+ else
+ fputc(' ', out);
+ }
+ }
+ fputc(')', out);
+ break;
+
+ case LISP_TYPE_BOOLEAN :
+ if (lisp_boolean(obj))
+ fputs("#t", out);
+ else
+ fputs("#f", out);
+ break;
+
+ default :
+ assert(0);
+ }
+}
+
+using namespace std;
+
+LispReader::LispReader (lisp_object_t* l)
+ : lst (l)
+{
+ //std::cout << "LispReader: " << std::flush;
+ //lisp_dump(lst, stdout);
+ //std::cout << std::endl;
+}
+
+lisp_object_t*
+LispReader::search_for(const char* name)
+{
+ //std::cout << "LispReader::search_for(" << name << ")" << std::endl;
+ lisp_object_t* cursor = lst;
+
+ while(!lisp_nil_p(cursor))
+ {
+ lisp_object_t* cur = lisp_car(cursor);
+
+ if (!lisp_cons_p(cur) || !lisp_symbol_p (lisp_car(cur)))
+ {
+ lisp_dump(cur, stdout);
+ //throw ConstruoError (std::string("LispReader: Read error in search_for ") + name);
+ printf("LispReader: Read error in search\n");
+ }
+ else
+ {
+ if (strcmp(lisp_symbol(lisp_car(cur)), name) == 0)
+ {
+ return lisp_cdr(cur);
+ }
+ }
+
+ cursor = lisp_cdr (cursor);
+ }
+ return 0;
+}
+
+bool
+LispReader::read_int (const char* name, int* i)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ if (!lisp_integer_p(lisp_car(obj)))
+ st_abort("LispReader expected type integer at token: ", name);
+ *i = lisp_integer(lisp_car(obj));
+ return true;
+ }
+ return false;
+}
+
+bool
+LispReader::read_lisp(const char* name, lisp_object_t** b)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ *b = obj;
+ return true;
+ }
+ else
+ return false;
+}
+
+bool
+LispReader::read_float (const char* name, float* f)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ if (!lisp_real_p(lisp_car(obj)) && !lisp_integer_p(lisp_car(obj)))
+ st_abort("LispReader expected type real at token: ", name);
+ *f = lisp_real(lisp_car(obj));
+ return true;
+ }
+ return false;
+}
+
+bool
+LispReader::read_string_vector (const char* name, std::vector<std::string>* vec)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ while(!lisp_nil_p(obj))
+ {
+ if (!lisp_string_p(lisp_car(obj)))
+ st_abort("LispReader expected type string at token: ", name);
+ vec->push_back(lisp_string(lisp_car(obj)));
+ obj = lisp_cdr(obj);
+ }
+ return true;
+ }
+ return false;
+}
+
+bool
+LispReader::read_int_vector (const char* name, std::vector<int>* vec)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ while(!lisp_nil_p(obj))
+ {
+ if (!lisp_integer_p(lisp_car(obj)))
+ st_abort("LispReader expected type integer at token: ", name);
+ vec->push_back(lisp_integer(lisp_car(obj)));
+ obj = lisp_cdr(obj);
+ }
+ return true;
+ }
+ return false;
+}
+
+bool
+LispReader::read_char_vector (const char* name, std::vector<char>* vec)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ while(!lisp_nil_p(obj))
+ {
+ vec->push_back(*lisp_string(lisp_car(obj)));
+ obj = lisp_cdr(obj);
+ }
+ return true;
+ }
+ return false;
+}
+
+bool
+LispReader::read_string (const char* name, std::string* str)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)
+ {
+ if (!lisp_string_p(lisp_car(obj)))
+ st_abort("LispReader expected type string at token: ", name);
+ *str = lisp_string(lisp_car(obj));
+ return true;
+ }
+ return false;
+}
+
+bool
+LispReader::read_bool (const char* name, bool* b)
+{
+ lisp_object_t* obj = search_for (name);
+ if (obj)