lota things

This commit is contained in:
Felix Brendel
2019-06-27 11:11:18 +02:00
parent 6f5ecc87b0
commit efded2f9b8
13 changed files with 3211 additions and 199 deletions
+3 -1
View File
@@ -272,7 +272,9 @@ struct {
#define assert_type(_node, _type) \
do { \
if (Memory::get_type(_node) != _type) { \
create_type_missmatch_error("symbol", Lisp_Object_Type_to_string(Memory::get_type(_node))); \
create_type_missmatch_error( \
Lisp_Object_Type_to_string(_type), \
Lisp_Object_Type_to_string(Memory::get_type(_node))); \
} \
} while(0)
+1 -1
View File
@@ -37,7 +37,7 @@ proc generate_docs(Environment* env, String* path) -> void {
if (!we_already_printed) {
append_to_array_list(visited, env);
for (int i = 0; i < env->next_index; ++i) {
fprintf(f, "\n* =%s%s= \n"
fprintf(f, "\\hrule\n* =%s%s= \n"
// " :PROPERTIES:\n"
// " :UNNUMBERED: t\n"
// " :END:"
+40 -6
View File
@@ -32,6 +32,38 @@ proc get_nibble(char c) -> char {
return (c - '0');
}
proc escape_string(char* in) -> char* {
// TODO(Felix): add more escape sequences
int i = 0, count = 0;
while (in[i] != '\0') {
switch (in[i]) {
case '\\':
case '\n':
case '\t':
++count;
default: break;
}
++i;
}
char* ret = (char*)malloc((i+count+1)*sizeof(char));
// copy in
i = 0;
int j = 0;
while (in[i] != '\0') {
switch (in[i]) {
case '\\': ret[j++] = '\\'; ret[j++] = '\\'; break;
case '\n': ret[j++] = '\\'; ret[j++] = 'n'; break;
case '\t': ret[j++] = '\\'; ret[j++] = 't'; break;
default: ret[j++] = in[i];
}
++i;
}
ret[j++] = '\0';
return ret;
}
proc unescape_string(char* in) -> bool {
if (!in)
return true;
@@ -236,7 +268,7 @@ proc panic(char* message) -> void {
exit(1);
}
proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) -> void {
proc print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout) -> void {
switch (Memory::get_type(node)) {
case (Lisp_Object_Type::Nil): fputs("()", file); break;
@@ -251,10 +283,12 @@ proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) ->
case (Lisp_Object_Type::Symbol): fprintf(file, "%s", Memory::get_c_str(node->value.symbol.identifier)); break;
case (Lisp_Object_Type::CFunction): fputs("[C-function]", file); break;
case (Lisp_Object_Type::String): {
if (print_quotes) {
if (print_repr) {
putc('\"', file);
fputs(Memory::get_c_str(node->value.string), file);
char* escaped = escape_string(Memory::get_c_str(node->value.string));
fputs(escaped, file);
putc('\"', file);
free(escaped);
}
else
fputs(Memory::get_c_str(node->value.string), file);
@@ -293,13 +327,13 @@ proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) ->
assert_type(head->value.pair.rest, Lisp_Object_Type::Pair);
assert(head->value.pair.rest->value.pair.rest == Memory::nil);
print(head->value.pair.rest->value.pair.first, print_quotes, file);
print(head->value.pair.rest->value.pair.first, print_repr, file);
break;
}
else if (string_equal(identifier, "quasiquote")) {
putc('`', file);
assert_type(head->value.pair.rest, Lisp_Object_Type::Pair);
print(head->value.pair.rest->value.pair.first, print_quotes, file);
print(head->value.pair.rest->value.pair.first, print_repr, file);
break;
}
}
@@ -310,7 +344,7 @@ proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) ->
// we want to print a broken list (for logging the error) we
// should do mo checks.
while (head) {
print(head->value.pair.first, print_quotes, file);
print(head->value.pair.first, print_repr, file);
head = head->value.pair.rest;
if (!head)
return;
+1 -2
View File
@@ -1,11 +1,10 @@
#include "slime.h"
int main(int argc, char* argv[]) {
if (argc > 1) {
if (Slime::string_equal(argv[1], "--run-tests")) {
return Slime::run_all_tests() ? 0 : 1;
}
}
Slime::interprete_file(argv[1]);
if (Slime::Globals::error) {
+1
View File
@@ -629,6 +629,7 @@ proc run_all_tests() -> bool {
printf("\n-- Test Files --\n");
invoke_test_script("alists");
invoke_test_script("evaluation_of_default_args");
invoke_test_script("lexical_scope");
invoke_test_script("class_macro");