fixes
This commit is contained in:
parent
6e2eb11bf9
commit
e1465ae786
32
Readme.md
32
Readme.md
|
|
@ -1,21 +1,28 @@
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
|
- construct list for parse-csv in csvparse.cpp instead of ml.cpp
|
||||||
- support for strings with " included
|
- support for strings with " included
|
||||||
- update openssl libs
|
|
||||||
- documentation
|
- documentation
|
||||||
- add url of source/inspiration to clib/*.cpp
|
- add url of source/inspiration to clib/*.cpp
|
||||||
|
- load std lib when starting
|
||||||
|
- add more command line args
|
||||||
|
- split into more files
|
||||||
|
- prejmenovat ivaluize
|
||||||
|
- add some debug support??
|
||||||
|
- add instrumentation (time, nr of evals, debug info, debug environment etc)
|
||||||
|
|
||||||
#### Functionality
|
#### Functionality
|
||||||
- readline
|
- readline
|
||||||
- cvs read
|
- execute system command
|
||||||
- url read
|
|
||||||
- json
|
|
||||||
- printf
|
- printf
|
||||||
- env
|
- env
|
||||||
- support for including lib
|
- support for including lib
|
||||||
- date support
|
- date support
|
||||||
- file functions
|
- file functions
|
||||||
|
- name it here
|
||||||
- string funtions
|
- string funtions
|
||||||
|
- name it here
|
||||||
|
- add hash datatype
|
||||||
|
|
||||||
|
|
||||||
#### Performance
|
#### Performance
|
||||||
|
|
@ -28,3 +35,20 @@
|
||||||
time ./build/ml -c '(include "../example.lisp") (print (fact 1000))'
|
time ./build/ml -c '(include "../example.lisp") (print (fact 1000))'
|
||||||
./build/ml -f debug.lisp
|
./build/ml -f debug.lisp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Links
|
||||||
|
https://www.tutorialspoint.com/lisp/index.htm
|
||||||
|
https://github.com/adam-mcdaniel/wisp
|
||||||
|
|
||||||
|
https://github.com/dropbox/json11
|
||||||
|
|
||||||
|
#### std::vector
|
||||||
|
https://stackoverflow.com/questions/12271017/initial-capacity-of-vector-in-c
|
||||||
|
https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html
|
||||||
|
|
||||||
|
#### parse http headers in c++
|
||||||
|
```
|
||||||
|
^(?:((?:https?|s?ftp):)\/\/)([^:\/\s]+)(?::(\d*))?(?:\/([^\s?#]+)?([?][^?#]*)?(#.*)?)?
|
||||||
|
```
|
||||||
|
|
||||||
|
https://stackoverflow.com/questions/25896916/parse-http-headers-in-c
|
||||||
|
|
|
||||||
54
ml.cpp
54
ml.cpp
|
|
@ -117,20 +117,6 @@ bool is_symbol(char ch) {
|
||||||
return (isalpha(ch) || ispunct(ch)) && ch != '(' && ch != ')' && ch != '"' && ch != '\'';
|
return (isalpha(ch) || ispunct(ch)) && ch != '(' && ch != ')' && ch != '"' && ch != '\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::regex int_underscored_regex("[0-9][0-9_]+[0-9]");
|
|
||||||
std::regex int_regex("[0-9]+");
|
|
||||||
std::regex double_regex("[0-9]+\\.[0-9]+");
|
|
||||||
|
|
||||||
// Is string representing int value
|
|
||||||
bool is_string_int(const std::string &str) {
|
|
||||||
return std::regex_match(str, int_regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is string representing float value
|
|
||||||
bool is_string_float(const std::string &str) {
|
|
||||||
return std::regex_match(str, double_regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// LISP CONSTRUCTS ////////////////////////////////////////////////////////////
|
/// LISP CONSTRUCTS ////////////////////////////////////////////////////////////
|
||||||
|
|
@ -1148,30 +1134,7 @@ namespace builtin {
|
||||||
std::vector<std::vector<std::string> > parsed_data; // TODO some default size here
|
std::vector<std::vector<std::string> > parsed_data; // TODO some default size here
|
||||||
csv.parseCSV(args[0].as_string(), parsed_data);
|
csv.parseCSV(args[0].as_string(), parsed_data);
|
||||||
|
|
||||||
int rows = parsed_data.size();
|
return csv.ivalualize(parsed_data);
|
||||||
int cols = rows > 0 ? parsed_data[0].size() : 0;
|
|
||||||
|
|
||||||
std::vector<MlValue> result;
|
|
||||||
|
|
||||||
if (rows > 0 && cols > 0) {
|
|
||||||
for (int r = 0; r < rows; r++) {
|
|
||||||
std::vector<MlValue> row;
|
|
||||||
for (int c = 0; c < cols; c++) {
|
|
||||||
std::string value = parsed_data[r][c];
|
|
||||||
if (is_string_int(value)) {
|
|
||||||
row.push_back(MlValue(stoi(value)));
|
|
||||||
}
|
|
||||||
if (is_string_float(value)) {
|
|
||||||
row.push_back(MlValue(std::stod(value)));
|
|
||||||
} else {
|
|
||||||
row.push_back(MlValue::string(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.push_back(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MlValue(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the contents of a file
|
// Get the contents of a file
|
||||||
|
|
@ -1208,21 +1171,22 @@ namespace builtin {
|
||||||
eval_args(args, env);
|
eval_args(args, env);
|
||||||
|
|
||||||
// PERF optimize it for memory usage and performance
|
// PERF optimize it for memory usage and performance
|
||||||
// TODO handle second parameter (headers)
|
if (args.size() < 1 || args.size() > 2)
|
||||||
if (args.size() != 1)
|
throw MlError(MlValue("read_url", read_url), env, args.size() < 1 ? TOO_FEW_ARGS : TOO_MANY_ARGS);
|
||||||
throw MlError(MlValue("read_url", read_url), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> headers = {};
|
std::unordered_map<std::string, std::string> headers = {};
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
|
|
||||||
if (args.size() == 2) {
|
if (args.size() == 2) {
|
||||||
// do magick here
|
for(const auto& pair_list: args[1].as_list()[0].as_list()) {
|
||||||
// for (auto i = map.begin(); i != map.end(); ++i) {
|
// TODO check its 2 string elements list
|
||||||
// headers[i->first] = i->second.getString();
|
const auto& pair = pair_list.as_list();
|
||||||
// }
|
headers[pair[0].as_string()] = pair[1].as_string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, std::string> result = client.doGetRequest(args[0].as_string(), headers);
|
std::pair<int, std::string> result = client.doGetRequest(args[0].as_string(), headers);
|
||||||
|
// TODO add helper function for this
|
||||||
std::vector<MlValue> lst;
|
std::vector<MlValue> lst;
|
||||||
lst.push_back(MlValue(result.first));
|
lst.push_back(MlValue(result.first));
|
||||||
lst.push_back(MlValue::string(result.second));
|
lst.push_back(MlValue::string(result.second));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue