}
MNode* MNode::vectorGet (size_t pos) {
- assert (type == MC_VECTOR);
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
return vector->get (pos);
}
size_t MNode::vectorSize () {
- assert (type == MC_VECTOR);
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
return vector->size ();
}
void MNode::vectorPut (size_t pos, MNode* e) {
- assert (type == MC_VECTOR);
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
vector->put (pos, e);
}
void MNode::vectorPush (MNode* e) {
- assert (type == MC_VECTOR);
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
vector->push (e);
}
MNode* MNode::vectorPop () {
- assert (type == MC_VECTOR);
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
return vector->pop ();
}
void MNode::vectorResize (size_t pos) {
- assert (type == MC_VECTOR);
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
vector->resize (pos);
}
MNode* MNode::tableGet (const ustring& name) {
- assert (type == MC_TABLE);
+ if (type != MC_TABLE)
+ throw (uErrorWrongType );
return table->getVar (name);
}
void MNode::tablePut (const ustring& name, MNode* e) {
- assert (type == MC_TABLE);
+ if (type != MC_TABLE)
+ throw (uErrorWrongType );
table->setVar (name, e);
}
ustring MNode::vector_to_string () {
ustring ans;
- assert (type == MC_VECTOR);
+
+ if (type != MC_VECTOR)
+ throw (uErrorWrongType );
+
ans.append (CharConst ("["));
for (MotorVector::size_type i = 0; i < vector->size (); ++ i) {
if (i > 0)
ustring MNode::table_to_string () {
ustring ans;
- assert (type == MC_TABLE);
+
+ if (type != MC_TABLE)
+ throw (uErrorWrongType );
+
ans.append (CharConst ("{"));
MotorVar::iterator b, e;
size_t c = 0;
return (a == NULL || a->isNil ());
}
+inline bool isCons (MNode* a) {
+ return (a != NULL && a->isCons ());
+}
+
+inline bool isStr (MNode* a) {
+ return (a != NULL && a->isStr ());
+}
+
+inline bool isSym (MNode* a) {
+ return (a != NULL && a->isSym ());
+}
+
+inline bool isReal (MNode* a) {
+ return (a != NULL && a->isReal ());
+}
+
+inline bool isVector (MNode* a) {
+ return (a != NULL && a->isVector ());
+}
+
+inline bool isTable (MNode* a) {
+ return (a != NULL && a->isTable ());
+}
+
extern bool eq (MNode* a, MNode* b);
extern bool equal (MNode* a, MNode* b);
if (arg)
throw (uErrorWrongNumber);
- if (! vec () || ! vec ()->isVector ()) {
+ if (isNil (vec ()))
+ return NULL;
+ if (! vec ()->isVector ()) {
throw (uErrorWrongType);
}
return vec ()->vectorGet (n);
if (arg)
throw (uErrorWrongNumber);
- if (! vec () || ! vec ()->isVector ()) {
+ if (isNil (vec ()))
+ newMNode_num (0);
+ if (! vec ()->isVector ()) {
throw (uErrorWrongType);
}
return newMNode_num (vec ()->vectorSize ());
nextNode (arg);
if (arg)
throw (uErrorWrongNumber);
-
- if (! vec () || ! vec ()->isVector ()) {
+ if (! isVector (vec ()))
throw (uErrorWrongType);
- }
+
vec ()->vectorPut (n, e ());
return e.release ();
}
nextNode (arg);
if (arg)
throw (uErrorWrongNumber);
-
- if (! vec () || ! vec ()->isVector ()) {
+ if (! isVector (vec ()))
throw (uErrorWrongType);
- }
+
vec ()->vectorPush (e ());
return e.release ();
}
nextNode (arg);
if (arg)
throw (uErrorWrongNumber);
-
- if (! vec () || ! vec ()->isVector ()) {
+ if (! isVector (vec ()))
throw (uErrorWrongType);
- }
+
return vec ()->vectorPop ();
}
nextNode (arg);
if (arg)
throw (uErrorWrongNumber);
-
- if (! vec () || ! vec ()->isVector ()) {
+ if (! isVector (vec ()))
throw (uErrorWrongType);
- }
+
vec ()->vectorResize (n);
return vec.release ();
}
if (arg)
throw (uErrorWrongNumber);
- if (! e ()->isVector ()) {
+ if (isNil (e ()))
+ return NULL;
+ if (! isVector (e ()))
throw (uErrorWrongType);
- }
+
MotorVector::iterator b = e ()->vector->begin ();
MotorVector::iterator t = e ()->vector->end ();
for (; b < t; ++ b) {
setParams (arg, 2, ¶ms, kwlist, &keywords, &rest);
vlist = eval (params[0], mlenv);
- if (vlist () && vlist ()->isSym ()) {
+ if (isSym (vlist ())) {
lv.push_back (vlist ()->to_string ());
- } else if (vlist () && vlist ()->isCons ()) {
+ } else if (isCons (vlist ())) {
a = vlist ();
- while (a && a->isCons ()) {
+ while (isCons (a)) {
lv.push_back (to_string (a->car ()));
nextNode (a);
}
for (i = 0; i < iu; i ++) {
if (a) {
MNode* e = a->car ();
- if (e && e->isVector ()) {
+ if (isVector (e)) {
llv.push_back (e);
} else {
throw (uErrorWrongType);
while (arg) {
v = eval (arg->car (), mlenv);
nextNode (arg);
- if (v () && v ()->isCons ()) {
+ if (isCons (v ())) {
ans ()->tablePut (to_string (v ()->car ()), v ()->cdr ());
} else {
throw (uErrorWrongType);
if (arg)
throw (uErrorWrongNumber);
- if (! tbl () && ! tbl ()->isTable ()) {
+ if (isNil (tbl ()))
+ return NULL;
+ if (! tbl ()->isTable ())
throw (uErrorWrongType);
- }
+
return tbl ()->tableGet (name);
}
if (arg)
throw (uErrorWrongNumber);
- if (! tbl () && ! tbl ()->isTable ()) {
+ if (! isTable (tbl ()))
throw (uErrorWrongType);
- }
tbl ()->tablePut (name, e ());
+
return e.release ();
}
if (arg)
throw (uErrorWrongNumber);
- if (! e ()->isTable ()) {
+ if (isNil (e ()))
+ return NULL;
+ if (! e ()->isTable ())
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 ();
}
if (vkey.size () == 0 || vval.size () == 0) {
throw (uErrorBadArg);
}
- if (! tbl () || ! tbl ()->isTable () ) {
+ if (! isTable (tbl ()))
throw (uErrorWrongType);
- }
{
AutoLocalVariable autoLocal (mlenv);
vars.push_back (to_string (a1->car ()));
nextNode (a1);
}
- while (a2 && a2->isCons ()) {
- MNode* a3 = a2->car ();
- n ++;
- for (v = vars.begin (); v < vars.end (); v ++) {
- if (a3 && a3->isCons ()) {
- mlenv->setAry (*v, n, a3->car ());
- } else {
- mlenv->setAry (*v, n, NULL);
+ if (isVector (a2)) {
+ size_t i;
+ size_t m = a2->vectorSize ();
+ for (i = 0; i < m; ++ i) {
+ MNode* a3 = a2->vectorGet (i);
+ ++ n;
+ size_t j = 0;
+ for (v = vars.begin (); v < vars.end (); ++ v) {
+ mlenv->setAry (*v, n, a3->vectorGet (j));
+ ++ j;
}
- nextNode (a3);
}
- nextNode (a2);
+ } else {
+ while (a2 && a2->isCons ()) {
+ MNode* a3 = a2->car ();
+ ++ n;
+ for (v = vars.begin (); v < vars.end (); ++ v) {
+ if (a3 && a3->isCons ()) {
+ mlenv->setAry (*v, n, a3->car ());
+ } else {
+ mlenv->setAry (*v, n, NULL);
+ }
+ nextNode (a3);
+ }
+ nextNode (a2);
+ }
}
- for (v = vars.begin (); v < vars.end (); v ++) {
+ for (v = vars.begin (); v < vars.end (); ++ v) {
mlenv->setArySize (*v, n);
}
} else {