Compare commits

..

9 Commits

Author SHA1 Message Date
Vaclav Tvrdik
17bdfdcbcb a bit od examples in doc 2022-12-29 14:13:56 +01:00
Vaclav Tvrdik
d9898aa64d fix erroneous paren 2022-09-12 16:05:08 +02:00
Vaclav Tvrdik
e7b62ab770 added comment for creating installation dirs 2022-09-12 16:04:48 +02:00
Vaclav Tvrdik
c9baa8a227 monterey homebrew directory change 2022-09-12 15:45:35 +02:00
vaclavt
a87ceb2f19 load_std_lib moved to anothep place in file 2022-06-16 17:08:58 +02:00
vaclavt
e6cf7aa636 doc::??? updates 2022-06-16 17:08:36 +02:00
vaclavt
7acab5d229 double is alias of float 2022-06-02 14:14:06 +02:00
vaclavt
25efdaac37 clear warning 2022-06-02 14:13:38 +02:00
vaclavt
8e6dff278d index scan is default on 2022-06-02 14:13:15 +02:00
12 changed files with 1175 additions and 28 deletions

View File

@@ -15,9 +15,9 @@ set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
# set(CMAKE_CXX_FLAGS "-Wall -Wextra") # set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
include_directories(/usr/local/opt/openssl/include ${CMAKE_SOURCE_DIR}/clib ${CMAKE_SOURCE_DIR}) include_directories(/opt/homebrew/opt/openssl@1.1/include ${CMAKE_SOURCE_DIR}/clib ${CMAKE_SOURCE_DIR})
link_directories(/usr/local/lib /usr/local/opt/openssl/lib) link_directories(/opt/homebrew/opt/openssl@1.1/lib)
project(ml) project(ml)

View File

@@ -69,6 +69,7 @@ utils/local_install.sh
### TODO ### TODO
- order of arguments in functions like member and filter - filter swap lambda and list - order of arguments in functions like member and filter - filter swap lambda and list
- add possibility to specify filename for input2 history file
- better output of !e in repl (resp !e !ee) - better output of !e in repl (resp !e !ee)
- unify -f and -run options - unify -f and -run options
- add debug support, at least call stack - add debug support, at least call stack

1082
doc/Doc.html Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -40,14 +40,14 @@
|`(set! x)`|`set!` ...|....|Language| |`(set! x)`|`set!` ...|....|Language|
## Macros ## Macros
|Signature|Description|Return values|Section| |Signature|Description|Example|Section|
|:-|-|-|-| |:-|-|-|-|
|`(unles cond body)`|`unless` only evaluates its `cond` argument. If `cond` is not truthy, then `body` is evaluated.|`>>> (unless #t (print "it is #f")) => nil`|Language| |`(unles cond body)`|`unless` only evaluates its `cond` argument. If `cond` is not truthy, then `body` is evaluated.|`>>> (unless #t (print "it is #f")) => nil`|Language|
|`(dotimes v n body)`|Iterates over `v` from 0 below `n` and evaluated `body`. Returns the last value of v|`>>> (dotimes i 5 i) => 4`|Language| |`(dotimes v n body)`|Iterates over `v` from 0 below `n` and evaluated `body`. Returns the last value of v|`>>> (dotimes i 5 i) => 4`|Language|
|`(until cond body)`|Evaluated `body` as long as `cond` is not truthy|`>>> (def i 0)(until (> i 3) (set! i (inc i))) => 4`|Language| |`(until cond body)`|Evaluated `body` as long as `cond` is not truthy|`>>> (def i 0)(until (> i 3) (set! i (inc i))) => 4`|Language|
## Library ## Library
|Signature|Description|Return values|Section| |Signature|Description|Example|Section|
|:-|-|-|-| |:-|-|-|-|
|`(= a b)`|Test whether two values are equal|`1` when equal otherwise `nil`|Language| |`(= a b)`|Test whether two values are equal|`1` when equal otherwise `nil`|Language|
|`(!= a b)`|Test whether two values are not equal|`1` when not equal otherwise `nil`|Language| |`(!= a b)`|Test whether two values are not equal|`1` when not equal otherwise `nil`|Language|
@@ -63,10 +63,10 @@
|`(list ..)`|Create a list of values||List manipulation| |`(list ..)`|Create a list of values||List manipulation|
|`(insert list index element)`|Insert an element into a list. Indexed from 0|new list with value inserted|List manipulation| |`(insert list index element)`|Insert an element into a list. Indexed from 0|new list with value inserted|List manipulation|
|`(index list index)`|Return element at index in list. First element is at index 0|Element at index|List manipulation| |`(index list index)`|Return element at index in list. First element is at index 0|Element at index|List manipulation|
|`(remove list index)`|Remove a value at an index from a list|List with element removed|List manipulation| |`(remove list index)`|Remove a value at an index from a list|`>>> (remove '(1 2 3 4) 1) => (1 3 4)`|List manipulation|
|`(len list)`|Get the length of a list|list length|List manipulation| |`(len list)`|Get the length of a list|`>>> (len '(1 2 3 4)) => 4`|List manipulation|
|`(push list element)`|Add an item to the end of a list|new list with element added|List manipulation| |`(push list element)`|Add an item to the end of a list|`>>> (push '(1 2 3 4) 5) => (1 2 3 4 5)`|List manipulation|
|`(pop list)`|Returns last element of list|Last element|List manipulation| |`(pop list)`|Returns last element of list|`>>> (pop '(1 2 3 4)) => 4`|List manipulation|
|`(head list)`|Returns first element of a list|`>>> (head '(1 2 3)) => 1`|List manipulation| |`(head list)`|Returns first element of a list|`>>> (head '(1 2 3)) => 1`|List manipulation|
|`(tail list)`|Return all elements of list except first one|`>>> (tail '(1 2 3)) => (2 3)`|List manipulation| |`(tail list)`|Return all elements of list except first one|`>>> (tail '(1 2 3)) => (2 3)`|List manipulation|
|`(first list)`|Returns first element of a list|`>>> (first '(1 2 3)) => 1`|List manipulation| |`(first list)`|Returns first element of a list|`>>> (first '(1 2 3)) => 1`|List manipulation|
@@ -192,4 +192,4 @@
|`(thread-sleep milisecons)`|Sleeps thread for given amount of miliseconds|`>>> (thread-sleep 100) => 100`|Threading| |`(thread-sleep milisecons)`|Sleeps thread for given amount of miliseconds|`>>> (thread-sleep 100) => 100`|Threading|
|`(threads-join)`|Wait for all running threads to finish||Threading| |`(threads-join)`|Wait for all running threads to finish||Threading|
|`(try block catch_block [finally_block])`|Evaluates block and if an exception is thrown, evaluates catch_block.Eventually in both cases evals finally_block. Return evaluated last expression from block if no exception or last expression from catch_block, if exception is thrown from block. Variable ml-exception in catch block is available with astring describing exception||Exceptions| |`(try block catch_block [finally_block])`|Evaluates block and if an exception is thrown, evaluates catch_block.Eventually in both cases evals finally_block. Return evaluated last expression from block if no exception or last expression from catch_block, if exception is thrown from block. Variable ml-exception in catch block is available with astring describing exception||Exceptions|
|`(throw exp_desc)`|Throws an exception with exp_desc describing what happened. exp_desc will be evaluated a returned as string|`>>> (throw (+ 1 2))\n3`|Exceptions| |`(throw exp_desc)`|Throws an exception with exp_desc describing what happened. exp_desc will be evaluated a returned as string|`>>> (throw (+ 1 2))\n3`|Exceptions|

22
doc/readme.txt Normal file
View File

@@ -0,0 +1,22 @@
to convert Doc.md to Doc.html use https://markdowntohtml.com/ with custom ccs style
body {
color: black;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid;
}
th {
text-align: left;
}
td {
height: 50px;
vertical-align: top;
}
code{
background: #0003;
color: #a31515;
}

9
ml.cpp
View File

@@ -2196,9 +2196,6 @@ MlValue usql(std::vector<MlValue> args, MlEnvironment &env) {
} // namespace builtin } // namespace builtin
void load_std_lib(MlEnvironment &env) {
run(STDLIB_LOADER, env);
}
// Does this environment, or its parent environment, have a variable? // Does this environment, or its parent environment, have a variable?
bool MlEnvironment::has(const std::string &name) const { bool MlEnvironment::has(const std::string &name) const {
@@ -2440,6 +2437,12 @@ std::vector<std::string> getCmdOption(char *argv[], int argc, const std::string
return tokens; return tokens;
} }
void load_std_lib(MlEnvironment &env) {
run(STDLIB_LOADER, env);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
MlEnvironment env; MlEnvironment env;
std::vector<MlValue> args; std::vector<MlValue> args;

View File

@@ -79,7 +79,7 @@ void MlPerfMon::restore_callstack_position(size_t to_position) {
} }
void MlPerfMon::clear_callstack() { void MlPerfMon::clear_callstack() {
call_stack.empty(); auto r = call_stack.empty();
} }
void MlPerfMon::print_results() const { void MlPerfMon::print_results() const {

View File

@@ -43,6 +43,12 @@
nil nil
)) ))
(defn doc::print-entry (entry)
(do (def call (doc::strip-backticks (second entry)))
(def desc (doc::strip-backticks (third entry)))
(print (term-red (first entry)) "-" (term-green (doc::strip-backticks (second entry))) "-" (third entry))
))
(defn doc::man (what) (defn doc::man (what)
(do (def man (filter (lambda (x) (= (first x) what)) doc::doc_entries)) (do (def man (filter (lambda (x) (= (first x) what)) doc::doc_entries))
(if man (if man
@@ -75,29 +81,54 @@
(def sorted (quick-sort-by scores (lambda (a b) (< (first a) (first b))))) (def sorted (quick-sort-by scores (lambda (a b) (< (first a) (first b)))))
(for e (take sorted 10) (for e (take sorted 10)
(def entry (second e)) (doc::print-entry (second e)))
(def call (doc::strip-backticks (second entry)))
(def desc (doc::strip-backticks (third entry)))
(print (term-red (first entry)) "-" (term-green (doc::strip-backticks (second entry))) "-" (third entry))
)
(if (> (len sorted) 10) (print "...")) (if (> (len sorted) 10) (print "..."))
)) ))
(defn doc::section (what)
(do
(def entries '())
(for entry doc::doc_entries
; ("throw-exception" "`(throw-exception exp_desc)`" "Throws an exception with exp_desc describing what happened " "" "Exceptions"
; section matches
(if (= (string-downcase (fifth entry)) (string-downcase what))
(set! entries (push entries entry)))
)
(for e (quick-sort-by entries (lambda (a b) (> (string-cmp (first a) (first b)) 0)))
(doc::print-entry e))
))
(defn doc::all ()
(for e (quick-sort-by doc::doc_entries (lambda (a b) (> (string-cmp (first a) (first b)) 0)))
(doc::print-entry e))
)
(defn doc::appropos (which) (defn doc::appropos (which)
(doc::look which)) (doc::look which))
(defn doc::lookup (which) (defn doc::lookup (which)
(doc::look which)) (doc::look which))
;(defn doc::section (which) (defn doc::doc ()
; (print (term-red "implement me!"))) (do
(print "Usage:")
(print "\t(doc::doc) - shows this help")
(print "\t(doc::man func) - func must be a string, ie (doc::man \"for\")")
(print "\t(doc::look str) - str must be a string, ie (doc::look \"length\")")
(print "\t(doc::lookup) - alias for doc::look")
(print "\t(doc::appropos) - alias for doc::look")
(print "\t(doc::all) - show short info about all functions")
(print "\t(doc::section sec) - show help for section, sec is string one of:")
(print "\t\t\t\t\"List manipulation\" \"Language\" \"System\"")
(print "\t\t\t\t\"String manipulation\" \"Date and time\" \"IO\" \"Regex\"")
(print "\t\t\t\t\"Type casting\" \"Threading\" \"Exceptions\"")
))
(def doc::doc_entries '()) ; must be here (def doc::doc_entries '()) ; must be here
; read doc into memory ; read doc into memory
(doc::read-doc-file "/usr/local/var/mlisp/Doc.md") (doc::read-doc-file "/usr/local/var/mlisp/Doc.md")
;;example
; (doc::man "first")
; (doc::look "string pad")
; (doc::look "list flat")

View File

@@ -162,7 +162,7 @@ TokenType Lexer::type(const std::string &token) {
if (token == "not") return TokenType::keyword_not; if (token == "not") return TokenType::keyword_not;
if (token == "null") return TokenType::keyword_null; if (token == "null") return TokenType::keyword_null;
if (token == "integer") return TokenType::keyword_integer; if (token == "integer") return TokenType::keyword_integer;
if (token == "float") return TokenType::keyword_float; if (token == "float" || token == "double") return TokenType::keyword_float;
if (token == "varchar") return TokenType::keyword_varchar; if (token == "varchar") return TokenType::keyword_varchar;
if (token == "date") return TokenType::keyword_date; if (token == "date") return TokenType::keyword_date;
if (token == "boolean") return TokenType::keyword_bool; if (token == "boolean") return TokenType::keyword_bool;

View File

@@ -12,7 +12,7 @@ std::vector<std::pair<std::string, std::string>> Settings::m_settings =
std::make_pair("BOOL_TRUE_LITERAL", "Y"), std::make_pair("BOOL_TRUE_LITERAL", "Y"),
std::make_pair("BOOL_FALSE_LITERAL", "N"), std::make_pair("BOOL_FALSE_LITERAL", "N"),
std::make_pair("DOUBLE_FORMAT", "%.2f"), std::make_pair("DOUBLE_FORMAT", "%.2f"),
std::make_pair("USE_INDEXSCAN", "N"), std::make_pair("USE_INDEXSCAN", "Y"),
std::make_pair("MAX_PARALLELISM", "1") }; // values "AUTO" or number of workers; when number negative means std::thread::hardware_concurrency() - number std::make_pair("MAX_PARALLELISM", "1") }; // values "AUTO" or number of workers; when number negative means std::thread::hardware_concurrency() - number

View File

@@ -35,7 +35,7 @@ std::pair<bool, std::vector<rowid_t>> USql::look_for_usable_index(const Node *wh
if (used_index != nullptr) { if (used_index != nullptr) {
std::vector<rowid_t> rowids = used_index->search((ValueNode *)ron->right.get()); std::vector<rowid_t> rowids = used_index->search((ValueNode *)ron->right.get());
#ifndef NDEBUG #ifndef NDEBUG
std::cout << "using index " << table->m_name << "(" << used_index->get_column_name() << "), " << rowids.size() << "/" << table->rows_count() << std::endl; std::cerr << "using index " << table->m_name << "(" << used_index->get_column_name() << "), " << rowids.size() << "/" << table->rows_count() << std::endl;
#endif #endif
return std::make_pair(true, rowids); return std::make_pair(true, rowids);
} }

View File

@@ -8,11 +8,19 @@ echo "building ml"
cmake --build ./ --target all -j 4 -- cmake --build ./ --target all -j 4 --
echo "" echo ""
# echo "create dirs"
# sudo mkdir -p /usr/local/var/mlisp/
# sudo mkdir -p /usr/local/bin/
# sudo chown -R vaclavt:admin /usr/local/bin/
# sudo chown -R vaclavt:admin /usr/local/var/mlisp/
echo "copying lsp files" echo "copying lsp files"
mkdir -p /usr/local/var/mlisp/
cp stdlib/*.lsp /usr/local/var/mlisp/ cp stdlib/*.lsp /usr/local/var/mlisp/
echo "copying doc files" echo "copying doc files"
cp doc/*.md /usr/local/var/mlisp/ cp doc/*.md /usr/local/var/mlisp/
echo "copying ml file" echo "copying ml file"
mv ./ml /usr/local/bin/ml mv ./ml /usr/local/bin/ml