00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #include "lisp_writer.hxx"
00021 
00022 LispWriter::LispWriter (const char* name)
00023 {
00024   lisp_objs.push_back(lisp_make_symbol (name));
00025 }
00026 
00027 void
00028 LispWriter::append (lisp_object_t* obj)
00029 {
00030   lisp_objs.push_back(obj);
00031 }
00032 
00033 lisp_object_t*
00034 LispWriter::make_list3 (lisp_object_t* a, lisp_object_t* b, lisp_object_t* c)
00035 {
00036   return lisp_make_cons (a, lisp_make_cons(b, lisp_make_cons(c, lisp_nil())));
00037 }
00038 
00039 lisp_object_t*
00040 LispWriter::make_list2 (lisp_object_t* a, lisp_object_t* b)
00041 {
00042   return lisp_make_cons (a, lisp_make_cons(b, lisp_nil()));
00043 }
00044 
00045 void
00046 LispWriter::write_vector (const char* name, const Vector2d& pos)
00047 {
00048   append(lisp_make_cons (lisp_make_symbol (name),
00049                          make_list2(lisp_make_real(pos.x),
00050                                     lisp_make_real(pos.y))));
00051 }
00052 
00053 void
00054 LispWriter::write_float (const char* name, float f)
00055 {
00056   append(make_list2 (lisp_make_symbol (name),
00057                      lisp_make_real(f)));
00058 }
00059 
00060 void 
00061 LispWriter::write_int (const char* name, int i)
00062 {
00063   append(make_list2 (lisp_make_symbol (name),
00064                      lisp_make_integer(i)));
00065 }
00066 
00067 void
00068 LispWriter::write_string (const char* name, const char* str)
00069 {
00070   append(make_list2 (lisp_make_symbol (name),
00071                      lisp_make_string(str)));
00072 }
00073 
00074 void
00075 LispWriter::write_symbol (const char* name, const char* symname)
00076 {
00077   append(make_list2 (lisp_make_symbol (name),
00078                      lisp_make_symbol(symname)));
00079 }
00080 
00081 void
00082 LispWriter::write_lisp_obj(const char* name, lisp_object_t* lst)
00083 {
00084   append(make_list2 (lisp_make_symbol (name),
00085                      lst));
00086 }
00087 
00088 void
00089 LispWriter::write_boolean (const char* name, bool b)
00090 {
00091   append(make_list2 (lisp_make_symbol (name),
00092                      lisp_make_boolean(b)));
00093 }
00094 
00095 lisp_object_t*
00096 LispWriter::create_lisp ()
00097 {
00098   lisp_object_t* lisp_obj = lisp_nil();
00099   
00100   for(std::vector<lisp_object_t*>::reverse_iterator i = lisp_objs.rbegin (); 
00101       i != lisp_objs.rend (); ++i)
00102     {
00103       lisp_obj = lisp_make_cons (*i, lisp_obj);
00104     }
00105   lisp_objs.clear();
00106   
00107   return lisp_obj;
00108 }
00109 
00110