slime version 0.2
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
namespace Slime {
|
namespace Slime {
|
||||||
#define v_major 0
|
#define v_major 0
|
||||||
#define v_minor 1
|
#define v_minor 2
|
||||||
#define STRINGIZE2(s) #s
|
#define STRINGIZE2(s) #s
|
||||||
#define STRINGIZE(s) STRINGIZE2(s)
|
#define STRINGIZE(s) STRINGIZE2(s)
|
||||||
#define VERSION_STRING "v" STRINGIZE(v_major) "." STRINGIZE(v_minor) " - built on " __DATE__ " " __TIME__
|
#define VERSION_STRING "v" STRINGIZE(v_major) "." STRINGIZE(v_minor) " - built on " __DATE__ " " __TIME__
|
||||||
|
|||||||
@@ -324,6 +324,8 @@ namespace Slime {
|
|||||||
string_builder.dealloc();
|
string_builder.dealloc();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!node) return _strdup("<nullptr>");
|
||||||
|
|
||||||
switch (node->type) {
|
switch (node->type) {
|
||||||
case (Lisp_Object_Type::Nil): return _strdup("()");
|
case (Lisp_Object_Type::Nil): return _strdup("()");
|
||||||
case (Lisp_Object_Type::T): return _strdup("t");
|
case (Lisp_Object_Type::T): return _strdup("t");
|
||||||
|
|||||||
+140
-183
@@ -317,205 +317,169 @@ namespace Slime {
|
|||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc test_built_in_add() -> testresult {
|
proc test_string_copy() -> testresult {
|
||||||
char exp_string[] = "(+ 10 4)";
|
Lisp_Object* str = Memory::create_lisp_object("Hello World");
|
||||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
Lisp_Object* cpy = Memory::copy_lisp_object(str);
|
||||||
Lisp_Object* result;
|
assert_not_equal_int(str, cpy);
|
||||||
try result = eval_expr(expression);
|
assert_not_equal_int(str->value.string.data, cpy->value.string.data);
|
||||||
|
|
||||||
assert_no_error();
|
|
||||||
assert_not_null(result);
|
|
||||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
|
||||||
assert_equal_f64(result->value.number, 14);
|
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc test_built_in_substract() -> testresult {
|
proc test_simple_stuff() -> testresult {
|
||||||
char exp_string[] = "(- 10 4)";
|
{ // built in add
|
||||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
char exp_string[] = "(+ 10 4)";
|
||||||
Lisp_Object* result;
|
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();
|
try result = eval_expr(expression);
|
||||||
assert_not_null(result);
|
|
||||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
|
||||||
assert_equal_f64(result->value.number, 6);
|
|
||||||
|
|
||||||
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 {
|
assert_no_error();
|
||||||
char exp_string[] = "(* 10 4)";
|
assert_not_null(result);
|
||||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||||
Lisp_Object* result;
|
assert_equal_f64(result->value.number, 5);
|
||||||
try result = eval_expr(expression);
|
}
|
||||||
|
{ // 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_no_error();
|
||||||
assert_not_null(result);
|
assert_not_null(result);
|
||||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||||
assert_equal_f64(result->value.number, 40);
|
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 {
|
assert_no_error();
|
||||||
char exp_string[] = "(/ 20 4)";
|
assert_not_null(result);
|
||||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
|
assert_equal_type(result, Lisp_Object_Type::T);
|
||||||
Lisp_Object* result;
|
|
||||||
try result = eval_expr(expression);
|
|
||||||
|
|
||||||
assert_no_error();
|
// a false case
|
||||||
assert_not_null(result);
|
char exp_string2[] = "(and () \"asd\" 4)";
|
||||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
expression = Parser::parse_single_expression(exp_string2);
|
||||||
assert_equal_f64(result->value.number, 5);
|
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 {
|
// a false case
|
||||||
char exp_string1[] = "(if 1 4 5)";
|
char exp_string2[] = "(or () ())";
|
||||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
expression = Parser::parse_single_expression(exp_string2);
|
||||||
Lisp_Object* result;
|
try result = eval_expr(expression);
|
||||||
try result = eval_expr(expression);
|
|
||||||
|
|
||||||
assert_no_error();
|
assert_no_error();
|
||||||
assert_not_null(result);
|
assert_not_null(result);
|
||||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
assert_equal_type(result, Lisp_Object_Type::Nil);
|
||||||
assert_equal_f64(result->value.number, 4);
|
}
|
||||||
|
{ // 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)";
|
// a true case
|
||||||
expression = Parser::parse_single_expression(exp_string2);
|
assert_no_error();
|
||||||
try result = eval_expr(expression);
|
assert_not_null(result);
|
||||||
|
assert_equal_type(result, Lisp_Object_Type::T);
|
||||||
|
|
||||||
assert_no_error();
|
// a false case
|
||||||
assert_not_null(result);
|
char exp_string2[] = "(not \"asd xD\")";
|
||||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
expression = Parser::parse_single_expression(exp_string2);
|
||||||
assert_equal_f64(result->value.number, 5);
|
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 {
|
assert_no_error();
|
||||||
char exp_string1[] = "(and 1 \"asd\" 4)";
|
assert_not_null(result);
|
||||||
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
|
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||||
Lisp_Object* result;
|
assert_equal_string(result->value.symbol, "number");
|
||||||
try result = eval_expr(expression);
|
|
||||||
|
|
||||||
assert_no_error();
|
// setting user type
|
||||||
assert_not_null(result);
|
char exp_string2[] = "(begin (set-type! a :my-type)(type a))";
|
||||||
assert_equal_type(result, Lisp_Object_Type::T);
|
expression = Parser::parse_single_expression(exp_string2);
|
||||||
|
result = eval_expr(expression);
|
||||||
|
|
||||||
// a false case
|
assert_no_error();
|
||||||
char exp_string2[] = "(and () \"asd\" 4)";
|
assert_not_null(result);
|
||||||
expression = Parser::parse_single_expression(exp_string2);
|
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||||
try result = eval_expr(expression);
|
assert_equal_string(result->value.symbol, "my-type");
|
||||||
|
|
||||||
assert_no_error();
|
// deleting user type
|
||||||
assert_not_null(result);
|
char exp_string4[] = "(begin (delete-type! a)(type a))";
|
||||||
assert_equal_type(result, Lisp_Object_Type::Nil);
|
expression = Parser::parse_single_expression(exp_string4);
|
||||||
|
result = eval_expr(expression);
|
||||||
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");
|
|
||||||
|
|
||||||
|
assert_no_error();
|
||||||
|
assert_not_null(result);
|
||||||
|
assert_equal_type(result, Lisp_Object_Type::Keyword);
|
||||||
|
assert_equal_string(result->value.symbol, "number");
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,15 +568,8 @@ namespace Slime {
|
|||||||
invoke_test(test_parse_expression);
|
invoke_test(test_parse_expression);
|
||||||
|
|
||||||
printf("\n-- Built ins --\n");
|
printf("\n-- Built ins --\n");
|
||||||
invoke_test(test_built_in_add);
|
invoke_test(test_simple_stuff);
|
||||||
invoke_test(test_built_in_substract);
|
invoke_test(test_string_copy);
|
||||||
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);
|
|
||||||
|
|
||||||
printf("\n-- Memory management --\n");
|
printf("\n-- Memory management --\n");
|
||||||
invoke_test(test_singular_t_and_nil);
|
invoke_test(test_singular_t_and_nil);
|
||||||
|
|||||||
@@ -20,14 +20,16 @@
|
|||||||
CLOSED: [2020-03-29 So 21:27]
|
CLOSED: [2020-03-29 So 21:27]
|
||||||
* DONE use better type names: u32, ..
|
* DONE use better type names: u32, ..
|
||||||
CLOSED: [2020-03-31 Di 11:36]
|
CLOSED: [2020-03-31 Di 11:36]
|
||||||
* TODO when copying LO<string>, check if string itself is being copied
|
* DONE when copying LO<string>, check if string itself is being copied
|
||||||
|
CLOSED: [2020-03-31 Di 11:58]
|
||||||
|
* DONE update header files
|
||||||
|
CLOSED: [2020-03-31 Di 11:58]
|
||||||
* TODO define-syntax-shorthand
|
* TODO define-syntax-shorthand
|
||||||
(define-syntax-shorthand [ vector ] )
|
(define-syntax-shorthand [ vector ] )
|
||||||
(define-syntax-shorthand { hash-map } )
|
(define-syntax-shorthand { hash-map } )
|
||||||
* TODO doc generation
|
* TODO doc generation
|
||||||
* TODO assert list_length for arguemns of macros
|
* TODO assert list length for arguemns of macros
|
||||||
???
|
???
|
||||||
* TODO update header files
|
|
||||||
* TODO source code locations
|
* TODO source code locations
|
||||||
* TODO function let
|
* TODO function let
|
||||||
(let fac ([n 10])
|
(let fac ([n 10])
|
||||||
|
|||||||
Reference in New Issue
Block a user