OSDN Git Service

save point.
authorvisor <visor@users.sourceforge.jp>
Mon, 18 Aug 2014 15:31:11 +0000 (00:31 +0900)
committervisor <visor@users.sourceforge.jp>
Mon, 18 Aug 2014 15:31:11 +0000 (00:31 +0900)
lib/mlenv.cc
modules/ml-texp.cc
modules/ml-texp.h

index c4990eb..befa8a1 100644 (file)
@@ -5,6 +5,7 @@
 #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>
 
@@ -279,6 +280,13 @@ void  MlEnv::setAry (const ustring& name, MNode* list) {
                    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.")));
            }
@@ -291,6 +299,13 @@ void  MlEnv::setAry (const ustring& name, MNode* list) {
                    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.")));
            }
index 201bf5c..065297e 100644 (file)
@@ -195,6 +195,68 @@ MNode*  ml_vector_resize (MNode* cell, MlEnv* mlenv) {
 }
 
 /*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
 
@@ -278,3 +340,32 @@ MNode*  ml_table_put (MNode* cell, MlEnv* mlenv) {
     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 ();
+}
index 8259a0f..4b31234 100644 (file)
@@ -11,8 +11,11 @@ MNode*  ml_vector_put (MNode* cell, MlEnv* mlenv);
 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 */