#include "util_string.h"
#include "config.h"
#include "motorconst.h"
+#include "motorvar.h"
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/unordered_map.hpp>
setLocalAry (pool, name, n, list->car ());
nextNode (list);
}
+ } else if (list->isVector ()) {
+ MotorVector::iterator b = list->vector->begin ();
+ MotorVector::iterator e = list->vector->end ();
+ for (; b < e; ++ b) {
+ ++ n;
+ setLocalAry (pool, name, n, (*b) ());
+ }
} else {
throw (ustring (CharConst ("setting a scalar value to an array.")));
}
setGlobalAry (name, n, list->car ());
nextNode (list);
}
+ } else if (list->isVector ()) {
+ MotorVector::iterator b = list->vector->begin ();
+ MotorVector::iterator e = list->vector->end ();
+ for (; b < e; ++ b) {
+ ++ n;
+ setGlobalAry (name, n, (*b) ());
+ }
} else {
throw (ustring (CharConst ("setting a scalar value to an array.")));
}
}
/*DOC:
+===list-to-vector===
+ (list-to-vector LIST) -> VECTOR
+
+*/
+//#AFUNC list-to-vector ml_list_to_vector
+//#WIKIFUNC list-to-vector
+MNode* ml_list_to_vector (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ MNodePtr e;
+ MNodePtr ans;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+ e = eval (arg->car (), mlenv);
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ ans = newMNode_vector ();
+ if (isNil (e ())) {
+ } else if (! e ()->isCons ()) {
+ throw (uErrorWrongType);
+ }
+ MNode* a = e ();
+ while (a) {
+ ans ()->vectorPush (a->car ());
+ nextNode (a);
+ }
+ return ans.release ();
+}
+
+/*DOC:
+===vector-to-list===
+ (vector-to-list VECTOR) -> LIST
+
+*/
+//#AFUNC vector-to-list ml_vector_to_list
+//#WIKIFUNC vector-to-list
+MNode* ml_vector_to_list (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ MNodePtr e;
+ MNodeList ans;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+ e = eval (arg->car (), mlenv);
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ if (! e ()->isVector ()) {
+ throw (uErrorWrongType);
+ }
+ MotorVector::iterator b = e ()->vector->begin ();
+ MotorVector::iterator t = e ()->vector->end ();
+ for (; b < t; ++ b) {
+ ans.append ((*b) ());
+ }
+ return mlenv->retval = ans.release ();
+}
+
+/*DOC:
===table===
(table CONS ...) -> TABLE
return e.release ();
}
+/*DOC:
+===table-to-list===
+ (table-to-list CONS ...) -> TABLE
+
+*/
+//#AFUNC table-to-list ml_table_to_list
+//#WIKIFUNC table-to-list
+MNode* ml_table_to_list (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ MNodePtr e;
+ MNodeList ans;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+ e = eval (arg->car (), mlenv);
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ if (! e ()->isVector ()) {
+ throw (uErrorWrongType);
+ }
+ MotorVar::iterator b = e ()->table->begin ();
+ MotorVar::iterator t = e ()->table->end ();
+ for (; b != t; ++ b) {
+ ans.append (newMNode_cons (newMNode_sym (new ustring ((*b).first)), (*b).second ()));
+ }
+ return ans.release ();
+}
MNode* ml_vector_push (MNode* cell, MlEnv* mlenv);
MNode* ml_vector_pop (MNode* cell, MlEnv* mlenv);
MNode* ml_vector_resize (MNode* cell, MlEnv* mlenv);
+MNode* ml_list_to_vector (MNode* cell, MlEnv* mlenv);
+MNode* ml_vector_to_list (MNode* cell, MlEnv* mlenv);
MNode* ml_table (MNode* cell, MlEnv* mlenv);
MNode* ml_table_get (MNode* cell, MlEnv* mlenv);
MNode* ml_table_put (MNode* cell, MlEnv* mlenv);
+MNode* ml_table_to_list (MNode* cell, MlEnv* mlenv);
#endif /* ML_TEXP_H */