Commits

Taegyoon Kim committed 50406c0

version 1.4.6: removed builtin_map

Comments (0)

Files changed (3)

 ## Reference ##
 ```
 Predefined Symbols:
- E PI false true
-Functions:
  ! != % && * + ++ - -- /
- < <= == > >= ^ apply begin ceil char-at
- chr dec double eval exit filter floor fn fold for
- if inc int length list ln log10 map nth pr
- prn quote rand range read-string set sqrt strcat string strlen
- system type when while ||
+ < <= == > >= E PI ^ apply begin
+ ceil char-at chr dec double eval exit false filter floor
+ fn fold for if inc int length list ln log10
+ map nth pr prn quote rand range read-string set sqrt
+ strcat string strlen system true type when while ||
 Etc.:
  (list) "string" ; end-of-line comment
 ```
                 if (n2.type != node::T_NIL)
                     return n2;
                 else {
-                    auto found = builtin_map.find(n.v_string);
-                    if (found != builtin_map.end()) {
-                        n = builtin(found->second); // elementary just-in-time compilation
-                        return n;
-                    }
-                    else {
-                        cerr << "Unknown variable: " << n.v_string << endl;
-                        return nil;
-                    }
+                    cerr << "Unknown variable: " << n.v_string << endl;
+                    return nil;
                 }
                 
             }
         puts("");
     }
     
-    void paren::print_functions() {
-        int i = 0;
-        map<string, int> ordered(builtin_map.begin(), builtin_map.end());
-        for (auto iter = ordered.begin(); iter != ordered.end(); iter++) {
-            printf(" %s", iter->first.c_str());
-            i++;
-            if (i % 10 == 0) puts("");
-        }
-        puts("");
-    }
-    
     void paren::print_logo() {
         printf("Paren %s (C) 2013 Kim, Taegyoon\n", PAREN_VERSION);        
         puts("Predefined Symbols:");
         print_symbols();
-        puts("Functions:");
-        print_functions();
         puts("Etc.:");
         puts(" (list) \"string\" ; end-of-line comment");
     } 
         global_env.env["false"] = node(false);
         global_env.env["E"] = node(2.71828182845904523536);
         global_env.env["PI"] = node(3.14159265358979323846);
-
-        builtin_map["+"] = node::PLUS;
-        builtin_map["-"] = node::MINUS;
-        builtin_map["*"] = node::MUL;
-        builtin_map["/"] = node::DIV;
-        builtin_map["^"] = node::CARET;
-        builtin_map["%"] = node::PERCENT;
-        builtin_map["sqrt"] = node::SQRT;
-        builtin_map["inc"] = node::INC;
-        builtin_map["dec"] = node::DEC;
-        builtin_map["++"] = node::PLUSPLUS;
-        builtin_map["--"] = node::MINUSMINUS;
-        builtin_map["floor"] = node::FLOOR;
-        builtin_map["ceil"] = node::CEIL;
-        builtin_map["ln"] = node::LN;
-        builtin_map["log10"] = node::LOG10;
-        builtin_map["rand"] = node::RAND;
-        builtin_map["=="] = node::EQEQ;
-        builtin_map["!="] = node::NOTEQ;
-        builtin_map["<"] = node::LT;
-        builtin_map[">"] = node::GT;
-        builtin_map["<="] = node::LTE;
-        builtin_map[">="] = node::GTE;
-        builtin_map["&&"] = node::ANDAND;
-        builtin_map["||"] = node::OROR;
-        builtin_map["!"] = node::NOT;
-        builtin_map["if"] = node::IF;
-        builtin_map["when"] = node::WHEN;
-        builtin_map["for"] = node::FOR;
-        builtin_map["while"] = node::WHILE;
-        builtin_map["strlen"] = node::STRLEN;
-        builtin_map["strcat"] = node::STRCAT;
-        builtin_map["char-at"] = node::CHAR_AT;
-        builtin_map["chr"] = node::CHR;
-        builtin_map["int"] = node::INT;
-        builtin_map["double"] = node::DOUBLE;
-        builtin_map["string"] = node::STRING;
-        builtin_map["read-string"] = node::READ_STRING;
-        builtin_map["type"] = node::TYPE;
-        builtin_map["eval"] = node::EVAL;
-        builtin_map["quote"] = node::QUOTE;
-        builtin_map["fn"] = node::FN;
-        builtin_map["list"] = node::LIST;
-        builtin_map["apply"] = node::APPLY;
-        builtin_map["fold"] = node::FOLD;
-        builtin_map["map"] = node::MAP;
-        builtin_map["filter"] = node::FILTER;
-        builtin_map["range"] = node::RANGE;
-        builtin_map["nth"] = node::NTH;
-        builtin_map["length"] = node::LENGTH;
-        builtin_map["begin"] = node::BEGIN;
-        builtin_map["set"] = node::SET;
-        builtin_map["pr"] = node::PR;
-        builtin_map["prn"] = node::PRN;
-        builtin_map["exit"] = node::EXIT;
-        builtin_map["system"] = node::SYSTEM;
+                
+        global_env.env["+"] = builtin(node::PLUS);
+        global_env.env["-"] = builtin(node::MINUS);
+        global_env.env["*"] = builtin(node::MUL);
+        global_env.env["/"] = builtin(node::DIV);
+        global_env.env["^"] = builtin(node::CARET);
+        global_env.env["%"] = builtin(node::PERCENT);
+        global_env.env["sqrt"] = builtin(node::SQRT);
+        global_env.env["inc"] = builtin(node::INC);
+        global_env.env["dec"] = builtin(node::DEC);
+        global_env.env["++"] = builtin(node::PLUSPLUS);
+        global_env.env["--"] = builtin(node::MINUSMINUS);
+        global_env.env["floor"] = builtin(node::FLOOR);
+        global_env.env["ceil"] = builtin(node::CEIL);
+        global_env.env["ln"] = builtin(node::LN);
+        global_env.env["log10"] = builtin(node::LOG10);
+        global_env.env["rand"] = builtin(node::RAND);
+        global_env.env["=="] = builtin(node::EQEQ);
+        global_env.env["!="] = builtin(node::NOTEQ);
+        global_env.env["<"] = builtin(node::LT);
+        global_env.env[">"] = builtin(node::GT);
+        global_env.env["<="] = builtin(node::LTE);
+        global_env.env[">="] = builtin(node::GTE);
+        global_env.env["&&"] = builtin(node::ANDAND);
+        global_env.env["||"] = builtin(node::OROR);
+        global_env.env["!"] = builtin(node::NOT);
+        global_env.env["if"] = builtin(node::IF);
+        global_env.env["when"] = builtin(node::WHEN);
+        global_env.env["for"] = builtin(node::FOR);
+        global_env.env["while"] = builtin(node::WHILE);
+        global_env.env["strlen"] = builtin(node::STRLEN);
+        global_env.env["strcat"] = builtin(node::STRCAT);
+        global_env.env["char-at"] = builtin(node::CHAR_AT);
+        global_env.env["chr"] = builtin(node::CHR);
+        global_env.env["int"] = builtin(node::INT);
+        global_env.env["double"] = builtin(node::DOUBLE);
+        global_env.env["string"] = builtin(node::STRING);
+        global_env.env["read-string"] = builtin(node::READ_STRING);
+        global_env.env["type"] = builtin(node::TYPE);
+        global_env.env["eval"] = builtin(node::EVAL);
+        global_env.env["quote"] = builtin(node::QUOTE);
+        global_env.env["fn"] = builtin(node::FN);
+        global_env.env["list"] = builtin(node::LIST);
+        global_env.env["apply"] = builtin(node::APPLY);
+        global_env.env["fold"] = builtin(node::FOLD);
+        global_env.env["map"] = builtin(node::MAP);
+        global_env.env["filter"] = builtin(node::FILTER);
+        global_env.env["range"] = builtin(node::RANGE);
+        global_env.env["nth"] = builtin(node::NTH);
+        global_env.env["length"] = builtin(node::LENGTH);
+        global_env.env["begin"] = builtin(node::BEGIN);
+        global_env.env["set"] = builtin(node::SET);
+        global_env.env["pr"] = builtin(node::PR);
+        global_env.env["prn"] = builtin(node::PRN);
+        global_env.env["exit"] = builtin(node::EXIT);
+        global_env.env["system"] = builtin(node::SYSTEM);
     }
 
     node paren::eval_string(string &s) {
 #include <ctime>
 #include <memory>
 
-#define PAREN_VERSION "1.4.5"
+#define PAREN_VERSION "1.4.6"
 
 namespace libparen {
     using namespace std;
         vector<string> tokenize(const string &s);
         vector<node> parse(const string &s);
 
-        unordered_map<string, int> builtin_map;
         environment global_env; // variables
                 
         node eval(node &n, environment &env);
         node eval_all(vector<node> &lst);
-        void print_symbols();
-        void print_functions();
+        void print_symbols();        
         void print_logo();
         void prompt();
         void prompt2();