slime version 0.2
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Slime {
|
||||
#define v_major 0
|
||||
#define v_minor 1
|
||||
#define v_minor 2
|
||||
#define STRINGIZE2(s) #s
|
||||
#define STRINGIZE(s) STRINGIZE2(s)
|
||||
#define VERSION_STRING "v" STRINGIZE(v_major) "." STRINGIZE(v_minor) " - built on " __DATE__ " " __TIME__
|
||||
|
||||
@@ -324,6 +324,8 @@ namespace Slime {
|
||||
string_builder.dealloc();
|
||||
};
|
||||
|
||||
if (!node) return _strdup("<nullptr>");
|
||||
|
||||
switch (node->type) {
|
||||
case (Lisp_Object_Type::Nil): return _strdup("()");
|
||||
case (Lisp_Object_Type::T): return _strdup("t");
|
||||
|
||||
+140
-183
@@ -317,205 +317,169 @@ namespace Slime {
|
||||
return pass;
|
||||
}
|
||||
|
||||
proc test_built_in_add() -> testresult {
|
||||
char exp_string[] = "(+ 10 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 14);
|
||||
|
||||
proc test_string_copy() -> testresult {
|
||||
Lisp_Object* str = Memory::create_lisp_object("Hello World");
|
||||
Lisp_Object* cpy = Memory::copy_lisp_object(str);
|
||||
assert_not_equal_int(str, cpy);
|
||||
assert_not_equal_int(str->value.string.data, cpy->value.string.data);
|
||||
return pass;
|
||||
}
|
||||
|
||||
proc test_built_in_substract() -> testresult {
|
||||
char exp_string[] = "(- 10 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
proc test_simple_stuff() -> testresult {
|
||||
{ // built in add
|
||||
char exp_string[] = "(+ 10 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
try result = eval_expr(expression);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 14);
|
||||
}
|
||||
{ // built in subtract
|
||||
char exp_string[] = "(- 10 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 6);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
return pass;
|
||||
}
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 6);
|
||||
}
|
||||
{ // built in multiply
|
||||
char exp_string[] = "(* 10 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 40);
|
||||
}
|
||||
{ // built in divide
|
||||
char exp_string[] = "(/ 20 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
proc test_built_in_multiply() -> testresult {
|
||||
char exp_string[] = "(* 10 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 5);
|
||||
}
|
||||
{ // built in if
|
||||
char exp_string1[] = "(if 1 4 5)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 40);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 4);
|
||||
|
||||
return pass;
|
||||
}
|
||||
char exp_string2[] = "(if () 4 5)";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 5);
|
||||
}
|
||||
{ // built in and
|
||||
char exp_string1[] = "(and 1 \"asd\" 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
proc test_built_in_divide() -> testresult {
|
||||
char exp_string[] = "(/ 20 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::T);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 5);
|
||||
// a false case
|
||||
char exp_string2[] = "(and () \"asd\" 4)";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
return pass;
|
||||
}
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||
}
|
||||
{ // built in or
|
||||
char exp_string1[] = "(or \"asd\" nil)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::T);
|
||||
|
||||
proc test_built_in_if() -> testresult {
|
||||
char exp_string1[] = "(if 1 4 5)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
// a false case
|
||||
char exp_string2[] = "(or () ())";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 4);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||
}
|
||||
{ // buit in not
|
||||
char exp_string1[] = "(not ())";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
char exp_string2[] = "(if () 4 5)";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
// a true case
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::T);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_f64(result->value.number, 5);
|
||||
// a false case
|
||||
char exp_string2[] = "(not \"asd xD\")";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
return pass;
|
||||
}
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||
}
|
||||
{ // built in type
|
||||
// normal type testing
|
||||
char exp_string1[] = "(begin (define a 10)(type a))";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result = eval_expr(expression);
|
||||
|
||||
proc test_built_in_and() -> testresult {
|
||||
char exp_string1[] = "(and 1 \"asd\" 4)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||
assert_equal_string(result->value.symbol, "number");
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::T);
|
||||
// setting user type
|
||||
char exp_string2[] = "(begin (set-type! a :my-type)(type a))";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
result = eval_expr(expression);
|
||||
|
||||
// a false case
|
||||
char exp_string2[] = "(and () \"asd\" 4)";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||
assert_equal_string(result->value.symbol, "my-type");
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
proc test_built_in_or() -> testresult {
|
||||
char exp_string1[] = "(or \"asd\" nil)";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::T);
|
||||
|
||||
// a false case
|
||||
char exp_string2[] = "(or () ())";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
|
||||
proc test_built_in_not() -> testresult {
|
||||
char exp_string1[] = "(not ())";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result;
|
||||
try result = eval_expr(expression);
|
||||
|
||||
// a true case
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::T);
|
||||
|
||||
// a false case
|
||||
char exp_string2[] = "(not \"asd xD\")";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
try result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
proc test_built_in_type() -> testresult {
|
||||
// Environment* env;
|
||||
// try env = get_root_environment();
|
||||
|
||||
// normal type testing
|
||||
char exp_string1[] = "(begin (define a 10)(type a))";
|
||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
||||
Lisp_Object* result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||
assert_equal_string(result->value.symbol, "number");
|
||||
|
||||
// setting user type
|
||||
char exp_string2[] = "(begin (set-type! a :my-type)(type a))";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||
assert_equal_string(result->value.symbol, "my-type");
|
||||
|
||||
// // trying to set invalid user type
|
||||
// char exp_string3[] = "(begin (set-type! a \"wrong tpye\")(type a))";
|
||||
// expression = Parser::parse_single_expression(exp_string3);
|
||||
// assert_no_error();
|
||||
|
||||
// ignore_logging {
|
||||
// dont_break_on_errors {
|
||||
// result = eval_expr(expression);
|
||||
// }
|
||||
// }
|
||||
|
||||
// assert_error();
|
||||
// delete_error();
|
||||
|
||||
// deleting user type
|
||||
char exp_string4[] = "(begin (delete-type! a)(type a))";
|
||||
expression = Parser::parse_single_expression(exp_string4);
|
||||
result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||
assert_equal_string(result->value.symbol, "number");
|
||||
// deleting user type
|
||||
char exp_string4[] = "(begin (delete-type! a)(type a))";
|
||||
expression = Parser::parse_single_expression(exp_string4);
|
||||
result = eval_expr(expression);
|
||||
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||
assert_equal_string(result->value.symbol, "number");
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
|
||||
@@ -604,15 +568,8 @@ namespace Slime {
|
||||
invoke_test(test_parse_expression);
|
||||
|
||||
printf("\n-- Built ins --\n");
|
||||
invoke_test(test_built_in_add);
|
||||
invoke_test(test_built_in_substract);
|
||||
invoke_test(test_built_in_multiply);
|
||||
invoke_test(test_built_in_divide);
|
||||
invoke_test(test_built_in_if);
|
||||
invoke_test(test_built_in_and);
|
||||
invoke_test(test_built_in_or);
|
||||
invoke_test(test_built_in_not);
|
||||
// invoke_test(test_built_in_type);
|
||||
invoke_test(test_simple_stuff);
|
||||
invoke_test(test_string_copy);
|
||||
|
||||
printf("\n-- Memory management --\n");
|
||||
invoke_test(test_singular_t_and_nil);
|
||||
|
||||
Reference in New Issue
Block a user