OSDN Git Service

add lisp object reader/writer function.
authorvisor <visor@users.sourceforge.jp>
Sat, 16 Jan 2010 09:09:18 +0000 (18:09 +0900)
committervisor <visor@users.sourceforge.jp>
Sat, 16 Jan 2010 09:09:18 +0000 (18:09 +0900)
lib/ml.cc
lib/ml.h
modules/ml-string.cc
modules/ml-string.h

index 89c9842..80bb8e5 100644 (file)
--- a/lib/ml.cc
+++ b/lib/ml.cc
@@ -474,7 +474,8 @@ bool  MotorSexp::scanSexp (int& linenum, uiterator& b, uiterator& e, MNode*& cel
        if (qcdr)
            newMNodeCdr (cell);
        x = new MNode;
-       mlenv->push_linenum (x, linenum);
+       if (mlenv)
+           mlenv->push_linenum (x, linenum);
        if (! scanCar (linenum, b, e, x)) {
            status = S_MISSING_PAREN;
        }
@@ -497,7 +498,8 @@ bool  MotorSexp::scanSexp (int& linenum, uiterator& b, uiterator& e, MNode*& cel
            status = S_MISSING_PAREN;
        Ep1:
            if (l.isCons ()) {
-               mlenv->push_linenum (l.cdr (), n);
+               if (mlenv)
+                   mlenv->push_linenum (l.cdr (), n);
                cell->set_car (l.cdr ());
            }
        }
@@ -508,7 +510,8 @@ bool  MotorSexp::scanSexp (int& linenum, uiterator& b, uiterator& e, MNode*& cel
            newMNodeCdr (cell);
        x = new MNode;
        cell->set_car (x);
-       mlenv->push_linenum (x, linenum);
+       if (mlenv)
+           mlenv->push_linenum (x, linenum);
        scanQuote (linenum, b, e, x);
        break;
     case YYREN:
index ed749ce..b7de3dd 100644 (file)
--- a/lib/ml.h
+++ b/lib/ml.h
@@ -37,8 +37,7 @@ class  MNode {
        cons.cdr = NULL;
        refcount = 0;
     };
-    MNode (bool v) {
-    };
+    MNode (bool v) {};
     ~MNode () {
        fdelete ();
     };
index 24437af..40cf830 100644 (file)
@@ -602,3 +602,48 @@ MNode*  ml_random_key (MNode* cell, MlEnv* mlenv) {
 
     return newMNode_str (new ustring (randomKey ()));
 }
+
+/*DOC:
+===to-string===
+ (to-string OBJECT) -> STRING
+
+*/
+//#AFUNC       to-string       ml_to_string
+//#WIKIFUNC    to-string
+MNode*  ml_to_string (MNode* cell, MlEnv* mlenv) {
+    MNode*  arg = cell->cdr ();
+    ustring  text;
+
+    if (! arg)
+       throw (uErrorWrongNumber);
+    text = eval_str (arg->car (), mlenv);
+    nextNode (arg);
+    if (arg)
+       throw (uErrorWrongNumber);
+
+    return newMNode_str (new ustring (text));
+}
+
+/*DOC:
+===to-lisp===
+ (to-lisp STRING) -> OBJECT
+
+*/
+//#AFUNC       to-lisp ml_to_lisp
+//#WIKIFUNC    to-lisp
+MNode*  ml_to_lisp (MNode* cell, MlEnv* mlenv) {
+    MNode*  arg = cell->cdr ();
+    ustring  text;
+    MotorSexp ml (NULL);
+
+    if (! arg)
+       throw (uErrorWrongNumber);
+    text = eval_str (arg->car (), mlenv);
+    nextNode (arg);
+    if (arg)
+       throw (uErrorWrongNumber);
+
+    ml.scan (text);
+
+    return mlenv->retval = ml.top.cdr ();
+}
index 2ed1101..d07ed96 100644 (file)
@@ -22,5 +22,7 @@ MNode*  ml_pad0 (MNode* cell, MlEnv* mlenv);
 MNode*  ml_ellipsis (MNode* cell, MlEnv* mlenv);
 MNode*  ml_string_format (MNode* cell, MlEnv* mlenv);
 MNode*  ml_random_key (MNode* cell, MlEnv* mlenv);
+MNode*  ml_to_string (MNode* cell, MlEnv* mlenv);
+MNode*  ml_to_lisp (MNode* cell, MlEnv* mlenv);
 
 #endif /* ML_STRING_H */