better boolean handling..
still T symbol should be implemented
This commit is contained in:
parent
ea76cdf0be
commit
783aa6976b
20
ml.cpp
20
ml.cpp
|
|
@ -72,6 +72,8 @@ MlValue::MlValue(long i) : type(INT) { stack_data.i = i; }
|
||||||
|
|
||||||
MlValue::MlValue(double f) : type(FLOAT) { stack_data.f = f; }
|
MlValue::MlValue(double f) : type(FLOAT) { stack_data.f = f; }
|
||||||
|
|
||||||
|
MlValue::MlValue(bool b) { if (b) {type = INT; stack_data.i = 1;} else {type = NIL;} }
|
||||||
|
|
||||||
MlValue::MlValue(const std::vector<MlValue> &list) : type(LIST), list(list) {}
|
MlValue::MlValue(const std::vector<MlValue> &list) : type(LIST), list(list) {}
|
||||||
|
|
||||||
MlValue MlValue::quote(const MlValue "ed) {
|
MlValue MlValue::quote(const MlValue "ed) {
|
||||||
|
|
@ -1240,22 +1242,20 @@ namespace builtin {
|
||||||
MlValue is_file(std::vector<MlValue> args, MlEnvironment &env) {
|
MlValue is_file(std::vector<MlValue> args, MlEnvironment &env) {
|
||||||
eval_args(args, env);
|
eval_args(args, env);
|
||||||
|
|
||||||
// TODO add support for more params and list params
|
|
||||||
if (args.size() != 1)
|
if (args.size() != 1)
|
||||||
throw MlError(MlValue("is-file?", is_file), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue("is-file?", is_file), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
|
|
||||||
return MlValue((long)is_path_file(args[0].as_string()));
|
return MlValue(is_path_file(args[0].as_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_path directory
|
// is_path directory
|
||||||
MlValue is_dir(std::vector<MlValue> args, MlEnvironment &env) {
|
MlValue is_dir(std::vector<MlValue> args, MlEnvironment &env) {
|
||||||
eval_args(args, env);
|
eval_args(args, env);
|
||||||
|
|
||||||
// TODO add support for more params and list params
|
|
||||||
if (args.size() != 1)
|
if (args.size() != 1)
|
||||||
throw MlError(MlValue("is-dir?", is_dir), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue("is-dir?", is_dir), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
|
|
||||||
return MlValue((long)is_path_dir(args[0].as_string()));
|
return MlValue(is_path_dir(args[0].as_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a file and execute its code
|
// Read a file and execute its code
|
||||||
|
|
@ -1349,7 +1349,7 @@ namespace builtin {
|
||||||
|
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
throw MlError(MlValue("=", eq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue("=", eq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
return MlValue(long(args[0] == args[1]));
|
return MlValue(args[0] == args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are two values not equal?
|
// Are two values not equal?
|
||||||
|
|
@ -1358,7 +1358,7 @@ namespace builtin {
|
||||||
|
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
throw MlError(MlValue("!=", neq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue("!=", neq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
return MlValue(long(args[0] != args[1]));
|
return MlValue(args[0] != args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is one number greater than another?
|
// Is one number greater than another?
|
||||||
|
|
@ -1367,7 +1367,7 @@ namespace builtin {
|
||||||
|
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
throw MlError(MlValue(">", greater), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue(">", greater), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
return MlValue(long(args[0] > args[1]));
|
return MlValue(args[0] > args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is one number less than another?
|
// Is one number less than another?
|
||||||
|
|
@ -1376,7 +1376,7 @@ namespace builtin {
|
||||||
|
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
throw MlError(MlValue("<", less), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue("<", less), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
return MlValue(long(args[0] < args[1]));
|
return MlValue(args[0] < args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is one number greater than or equal to another?
|
// Is one number greater than or equal to another?
|
||||||
|
|
@ -1385,7 +1385,7 @@ namespace builtin {
|
||||||
|
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
throw MlError(MlValue(">=", greater_eq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue(">=", greater_eq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
return MlValue(long(args[0] >= args[1]));
|
return MlValue(args[0] >= args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is one number less than or equal to another?
|
// Is one number less than or equal to another?
|
||||||
|
|
@ -1394,7 +1394,7 @@ namespace builtin {
|
||||||
|
|
||||||
if (args.size() != 2)
|
if (args.size() != 2)
|
||||||
throw MlError(MlValue("<=", less_eq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
throw MlError(MlValue("<=", less_eq), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||||
return MlValue(long(args[0] <= args[1]));
|
return MlValue(args[0] <= args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the type name of a value
|
// Get the type name of a value
|
||||||
|
|
|
||||||
3
ml.h
3
ml.h
|
|
@ -110,6 +110,9 @@ public:
|
||||||
// Constructs a floating point value
|
// Constructs a floating point value
|
||||||
MlValue(double f);
|
MlValue(double f);
|
||||||
|
|
||||||
|
// Constructs a bool value
|
||||||
|
MlValue(bool b);
|
||||||
|
|
||||||
// Constructs a list
|
// Constructs a list
|
||||||
MlValue(const std::vector<MlValue> &list);
|
MlValue(const std::vector<MlValue> &list);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
; it is expected to be called from parent directory ie: ml -f tests/test.lisp
|
|
||||||
|
|
||||||
(include "/usr/local/var/mlisp/ut.lsp")
|
(include "/usr/local/var/mlisp/ut.lsp")
|
||||||
|
|
||||||
;; prepare some code to be used in tests
|
;; prepare some code to be used in tests
|
||||||
|
|
@ -55,7 +53,7 @@
|
||||||
|
|
||||||
(ut::define-test "result of (string-split \"split me by space\" \"\\s+\")" '(ut::assert-equal '("split" "me" "by" "space") (string-split "split me by space" "\\s+")))
|
(ut::define-test "result of (string-split \"split me by space\" \"\\s+\")" '(ut::assert-equal '("split" "me" "by" "space") (string-split "split me by space" "\\s+")))
|
||||||
(ut::define-test "result of (string-upcase \"abcABCD\")" '(ut::assert-equal "ABCABCD" (string-upcase "abcABCD")))
|
(ut::define-test "result of (string-upcase \"abcABCD\")" '(ut::assert-equal "ABCABCD" (string-upcase "abcABCD")))
|
||||||
(ut::define-test "result of (string-downcase \"abcABCD\")" '(ut::assert-equal "!abcabcd" (string-downcase "abcABCD")))
|
(ut::define-test "result of (string-downcase \"abcABCD\")" '(ut::assert-equal "abcabcd" (string-downcase "abcABCD")))
|
||||||
|
|
||||||
(ut::define-test "result of (write-file \"/tmp/file\" \"write-file test\")" '(ut::assert-equal 1 (write-file "/tmp/file" "write-file test\n")))
|
(ut::define-test "result of (write-file \"/tmp/file\" \"write-file test\")" '(ut::assert-equal 1 (write-file "/tmp/file" "write-file test\n")))
|
||||||
(ut::define-test "result of (is-file? \"/tmp/file\")" '(ut::assert-true (is-file? "/tmp/file")))
|
(ut::define-test "result of (is-file? \"/tmp/file\")" '(ut::assert-true (is-file? "/tmp/file")))
|
||||||
|
|
@ -75,6 +73,8 @@
|
||||||
|
|
||||||
(ut::define-test "result of (get-env \"HOME\")" '(ut::assert-equal "/Users/vaclavt" (get-env "HOME")))
|
(ut::define-test "result of (get-env \"HOME\")" '(ut::assert-equal "/Users/vaclavt" (get-env "HOME")))
|
||||||
|
|
||||||
|
(ut::define-test "result of (!= nil nil)" '(ut::assert-false (!= nil nil)))
|
||||||
|
|
||||||
;(ut::define-test "result of " '(ut::assert-true )
|
;(ut::define-test "result of " '(ut::assert-true )
|
||||||
(ut::run-tests)
|
(ut::run-tests)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue