better boolean handling..
still T symbol should be implemented
This commit is contained in:
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(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::quote(const MlValue "ed) {
|
||||
@@ -1240,22 +1242,20 @@ namespace builtin {
|
||||
MlValue is_file(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
eval_args(args, env);
|
||||
|
||||
// TODO add support for more params and list params
|
||||
if (args.size() != 1)
|
||||
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
|
||||
MlValue is_dir(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
eval_args(args, env);
|
||||
|
||||
// TODO add support for more params and list params
|
||||
if (args.size() != 1)
|
||||
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
|
||||
@@ -1349,7 +1349,7 @@ namespace builtin {
|
||||
|
||||
if (args.size() != 2)
|
||||
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?
|
||||
@@ -1358,7 +1358,7 @@ namespace builtin {
|
||||
|
||||
if (args.size() != 2)
|
||||
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?
|
||||
@@ -1367,7 +1367,7 @@ namespace builtin {
|
||||
|
||||
if (args.size() != 2)
|
||||
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?
|
||||
@@ -1376,7 +1376,7 @@ namespace builtin {
|
||||
|
||||
if (args.size() != 2)
|
||||
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?
|
||||
@@ -1385,7 +1385,7 @@ namespace builtin {
|
||||
|
||||
if (args.size() != 2)
|
||||
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?
|
||||
@@ -1394,7 +1394,7 @@ namespace builtin {
|
||||
|
||||
if (args.size() != 2)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user