fixed import bug

This commit is contained in:
fumfar hiwi
2019-12-04 14:51:06 +01:00
parent 667989e373
commit efbdfeed2e
19 changed files with 3698 additions and 3680 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
(define a 10)
(define a 1111)
(define (get-a-1) a)
+8 -15
View File
@@ -1,27 +1,20 @@
(import "tests/import1.slime")
(print)
(print ">" a)
(assert (= a 10))
(print ">" (get-a-1))
(assert (= (get-a-1) 10))
(assert (= a 1111))
(assert (= (get-a-1) 1111))
(import "tests/import2.slime")
(print ">" a)
(assert (= a 10))
(print ">" (get-a-1))
(assert (= (get-a-1) 10))
(print ">" (get-a-2))
(assert (= (get-a-2) 10))
(assert (= a 1111))
(assert (= (get-a-1) 1111))
(assert (= (get-a-2) 1111))
(set-a-2 11)
(print "> should be 11 from now on")
(print ">" a)
(assert (= a 11))
(print ">" (get-a-1))
(assert (= (get-a-1) 11))
(print ">" (get-a-2))
(assert (= (get-a-2) 11))
+3 -1
View File
@@ -1,4 +1,5 @@
proc generate_docs(String* path) -> void {
namespace Slime {
proc generate_docs(String* path) -> void {
FILE *f = fopen(Memory::get_c_str(path), "w");
if (!f) {
create_generic_error("The file for writing the documentation (%s) "
@@ -141,4 +142,5 @@ proc generate_docs(String* path) -> void {
};
print_this_env(print_this_env, get_current_environment(), (char*)"");
}
}
+5 -5
View File
@@ -97,11 +97,11 @@ namespace Slime {
}
};
// if(env == get_root_environment()) {
// print_indent(indent);
// printf("[built-ins]-Environment (%lld)\n", (long long)env);
// return;
// }
if(env == get_root_environment()) {
print_indent(indent);
printf("[built-ins]-Environment (%lld)\n", (long long)env);
return;
}
for_hash_map (env->hm) {
print_indent(indent);
+8 -5
View File
@@ -1,11 +1,13 @@
proc delete_error() -> void {
namespace Slime {
proc delete_error() -> void {
using Globals::error;
free(error);
error = nullptr;
}
}
proc create_error(const char* c_func_name,const char* c_file_name, int c_file_line, Lisp_Object* type, String* message) -> void {
proc create_error(const char* c_func_name,const char* c_file_name, int c_file_line, Lisp_Object* type, String* message) -> void {
delete_error();
if (Globals::breaking_on_errors) {
debug_break();
@@ -29,9 +31,9 @@ proc create_error(const char* c_func_name,const char* c_file_name, int c_file_li
}
// visualize_lisp_machine();
}
}
proc create_error(const char* c_func_name, const char* c_file_name, int c_file_line, Lisp_Object* type, const char* format, ...) -> void {
proc create_error(const char* c_func_name, const char* c_file_name, int c_file_line, Lisp_Object* type, const char* format, ...) -> void {
using Globals::error;
int length = 200;
@@ -51,4 +53,5 @@ proc create_error(const char* c_func_name, const char* c_file_name, int c_file_l
strcpy(&formatted_string->data, out_msg);
free(out_msg);
create_error(c_func_name, c_file_name, c_file_line, type, formatted_string);
}
}
+22 -20
View File
@@ -1,8 +1,9 @@
proc create_extended_environment_for_function_application(
namespace Slime {
proc create_extended_environment_for_function_application(
Lisp_Object* unevaluated_arguments,
Lisp_Object* function,
bool should_evaluate) -> Environment*
{
{
profile_this();
bool is_c_function = Memory::get_type(function) == Lisp_Object_Type::CFunction;
Environment* new_env;
@@ -221,9 +222,9 @@ proc create_extended_environment_for_function_application(
try read_rest_arg();
return new_env;
}
}
proc apply_arguments_to_function(Lisp_Object* arguments, Lisp_Object* function, bool should_evaluate_args) -> Lisp_Object* {
proc apply_arguments_to_function(Lisp_Object* arguments, Lisp_Object* function, bool should_evaluate_args) -> Lisp_Object* {
profile_this();
Environment* new_env;
Lisp_Object* result;
@@ -243,7 +244,7 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Lisp_Object* function,
try result = eval_expr(function->value.function->body);
return result;
}
}
/**
This parses the argument specification of funcitons into their
@@ -251,7 +252,7 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Lisp_Object* function,
positional_arguments, keyword_arguments and rest_argument and
filling it in
*/
proc create_arguments_from_lambda_list_and_inject(Lisp_Object* arguments, Lisp_Object* function) -> void {
proc create_arguments_from_lambda_list_and_inject(Lisp_Object* arguments, Lisp_Object* function) -> void {
Arguments* result;
if (Memory::get_type(function) == Lisp_Object_Type::CFunction) {
result = &function->value.cFunction->args;
@@ -329,10 +330,10 @@ proc create_arguments_from_lambda_list_and_inject(Lisp_Object* arguments, Lisp_O
else
create_parsing_error("The rest argument must be a symbol.");
}
}
}
proc list_length(Lisp_Object* node) -> int {
proc list_length(Lisp_Object* node) -> int {
if (node == Memory::nil)
return 0;
@@ -349,14 +350,14 @@ proc list_length(Lisp_Object* node) -> int {
create_parsing_error("Can't calculate length of ill formed list.");
return 0;
}
}
proc copy_scl(Source_Code_Location*) -> Source_Code_Location* {
proc copy_scl(Source_Code_Location*) -> Source_Code_Location* {
// TODO(Felix):
return nullptr;
}
}
proc eval_arguments(Lisp_Object* arguments) -> Lisp_Object* {
proc eval_arguments(Lisp_Object* arguments) -> Lisp_Object* {
profile_this();
// int my_out_arguments_length = 0;
if (arguments == Memory::nil) {
@@ -390,9 +391,9 @@ proc eval_arguments(Lisp_Object* arguments) -> Lisp_Object* {
}
// *(out_arguments_length) = my_out_arguments_length;
return evaluated_arguments;
}
}
proc eval_expr(Lisp_Object* node) -> Lisp_Object* {
proc eval_expr(Lisp_Object* node) -> Lisp_Object* {
profile_this();
using namespace Globals::Current_Execution;
@@ -476,16 +477,16 @@ proc eval_expr(Lisp_Object* node) -> Lisp_Object* {
}
}
}
}
proc is_truthy(Lisp_Object* expression) -> bool {
proc is_truthy(Lisp_Object* expression) -> bool {
Lisp_Object* result;
try result = eval_expr(expression);
return result != Memory::nil;
}
}
proc interprete_file (char* file_name) -> Lisp_Object* {
proc interprete_file (char* file_name) -> Lisp_Object* {
try Memory::init(4096 * 256);
Lisp_Object* result;
@@ -493,9 +494,9 @@ proc interprete_file (char* file_name) -> Lisp_Object* {
try result = built_in_load(Memory::create_string(file_name));
return result;
}
}
proc interprete_stdin() -> void {
proc interprete_stdin() -> void {
try_void Memory::init(4096 * 256* 100);
printf("Welcome to the lispy interpreter.\n");
@@ -519,4 +520,5 @@ proc interprete_stdin() -> void {
}
}();
}
}
}
+34 -32
View File
@@ -1,37 +1,38 @@
void add_to_load_path(const char*);
bool lisp_object_equal(Lisp_Object*,Lisp_Object*);
Lisp_Object* built_in_load(String*);
Lisp_Object* built_in_import(String*);
void delete_error();
void create_error(const char* c_func_name, const char* c_file_name, int c_file_line, Lisp_Object* type, const char* format, ...);
void create_error(const char* c_func_name, const char* c_file_name, int c_file_line, Lisp_Object* type, String* message);
void create_error(Lisp_Object* type, const char* message, const char* c_file_name, int c_file_line);
Lisp_Object* eval_arguments(Lisp_Object*);
Lisp_Object* eval_expr(Lisp_Object*);
bool is_truthy (Lisp_Object*);
int list_length(Lisp_Object*);
void* load_built_ins_into_environment();
void create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function);
namespace Slime {
void add_to_load_path(const char*);
bool lisp_object_equal(Lisp_Object*,Lisp_Object*);
Lisp_Object* built_in_load(String*);
Lisp_Object* built_in_import(String*);
void delete_error();
void create_error(const char* c_func_name, const char* c_file_name, int c_file_line, Lisp_Object* type, const char* format, ...);
void create_error(const char* c_func_name, const char* c_file_name, int c_file_line, Lisp_Object* type, String* message);
void create_error(Lisp_Object* type, const char* message, const char* c_file_name, int c_file_line);
Lisp_Object* eval_arguments(Lisp_Object*);
Lisp_Object* eval_expr(Lisp_Object*);
bool is_truthy (Lisp_Object*);
int list_length(Lisp_Object*);
void* load_built_ins_into_environment();
void create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function);
Lisp_Object* lookup_symbol(Lisp_Object* symbol, Environment*);
void define_symbol(Lisp_Object* symbol, Lisp_Object* value);
void print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout);
void print_environment(Environment*);
Lisp_Object* lookup_symbol(Lisp_Object* symbol, Environment*);
void define_symbol(Lisp_Object* symbol, Lisp_Object* value);
void print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout);
void print_environment(Environment*);
bool run_all_tests();
bool run_all_tests();
inline Environment* get_root_environment();
inline Environment* get_current_environment();
inline void push_environment(Environment*);
inline void pop_environment();
inline Environment* get_root_environment();
inline Environment* get_current_environment();
inline void push_environment(Environment*);
inline void pop_environment();
const char* Lisp_Object_Type_to_string(Lisp_Object_Type type);
const char* Lisp_Object_Type_to_string(Lisp_Object_Type type);
void visualize_lisp_machine();
void generate_docs(String* path);
void log_error();
void visualize_lisp_machine();
void generate_docs(String* path);
void log_error();
namespace Memory {
namespace Memory {
Environment* create_built_ins_environment();
Lisp_Object* create_lisp_object_cfunction(bool is_special);
inline Lisp_Object_Type get_type(Lisp_Object* node);
@@ -55,9 +56,9 @@ namespace Memory {
inline Lisp_Object* create_list(Lisp_Object*,Lisp_Object*,Lisp_Object*,Lisp_Object*);
inline Lisp_Object* create_list(Lisp_Object*,Lisp_Object*,Lisp_Object*,Lisp_Object*,Lisp_Object*);
inline Lisp_Object* create_list(Lisp_Object*,Lisp_Object*,Lisp_Object*,Lisp_Object*,Lisp_Object*,Lisp_Object*);
}
}
namespace Parser {
namespace Parser {
// extern Environment* environment_for_macros;
extern String* standard_in;
@@ -68,9 +69,9 @@ namespace Parser {
Lisp_Object* parse_expression(char* text, int* index_in_text);
Lisp_Object* parse_single_expression(char* text);
Lisp_Object* parse_single_expression(wchar_t* text);
}
}
namespace Globals {
namespace Globals {
extern char* bin_path;
extern Log_Level log_level;
extern Array_List<void*> load_path;
@@ -80,4 +81,5 @@ namespace Globals {
}
extern Error* error;
extern bool breaking_on_errors;
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
namespace GC {
namespace Slime::GC {
proc maybe_mark(Environment* env) -> void;
int current_mark;
+1 -1
View File
@@ -1,4 +1,4 @@
namespace Globals {
namespace Slime::Globals {
char* bin_path = nullptr;
Log_Level log_level = Log_Level::Debug;
+35 -33
View File
@@ -1,4 +1,5 @@
proc string_equal(const char input[], const char check[]) -> bool {
namespace Slime {
proc string_equal(const char input[], const char check[]) -> bool {
if (input == check) return true;
for(int i = 0; input[i] == check[i]; i++) {
@@ -7,32 +8,32 @@ proc string_equal(const char input[], const char check[]) -> bool {
}
return false;
}
}
proc string_equal(String* str, const char check[]) -> bool {
proc string_equal(String* str, const char check[]) -> bool {
return string_equal(Memory::get_c_str(str), check);
}
}
proc string_equal(const char check[], String* str) -> bool {
proc string_equal(const char check[], String* str) -> bool {
return string_equal(Memory::get_c_str(str), check);
}
}
proc string_equal(String* str1, String* str2) -> bool {
proc string_equal(String* str1, String* str2) -> bool {
if (str1 == str2)
return true;
return string_equal(Memory::get_c_str(str1), Memory::get_c_str(str2));
}
}
proc get_nibble(char c) -> char {
proc get_nibble(char c) -> char {
if (c >= 'A' && c <= 'F')
return (c - 'A') + 10;
else if (c >= 'a' && c <= 'f')
return (c - 'a') + 10;
return (c - '0');
}
}
proc escape_string(char* in) -> char* {
proc escape_string(char* in) -> char* {
// TODO(Felix): add more escape sequences
int i = 0, count = 0;
while (in[i] != '\0') {
@@ -62,9 +63,9 @@ proc escape_string(char* in) -> char* {
}
ret[j++] = '\0';
return ret;
}
}
proc unescape_string(char* in) -> int {
proc unescape_string(char* in) -> int {
if (!in) return 0;
char *out = in, *p = in;
@@ -117,9 +118,9 @@ proc unescape_string(char* in) -> int {
/* Set the end of string. */
*out = '\0';
return (int)(out - in);
}
}
proc read_entire_file(char* filename) -> char* {
proc read_entire_file(char* filename) -> char* {
profile_with_comment(filename);
char *fileContent = nullptr;
FILE *fp = fopen(filename, "r");
@@ -156,9 +157,9 @@ proc read_entire_file(char* filename) -> char* {
return fileContent;
/* Don't forget to call free() later! */
}
}
proc read_expression() -> char* {
proc read_expression() -> char* {
char* line = (char*)malloc(100);
if(line == nullptr)
@@ -201,9 +202,9 @@ proc read_expression() -> char* {
*line = '\0';
return linep;
}
}
proc read_line() -> char* {
proc read_line() -> char* {
char* line = (char*)malloc(100), * linep = line;
size_t lenmax = 100, len = lenmax;
int c;
@@ -244,9 +245,9 @@ proc read_line() -> char* {
*line = '\0';
return linep;
}
}
proc log_message(Log_Level type, const char* message) -> void {
proc log_message(Log_Level type, const char* message) -> void {
if (type > Globals::log_level)
return;
@@ -259,9 +260,9 @@ proc log_message(Log_Level type, const char* message) -> void {
default: return;
}
printf("%s: %s\n",prefix, message);
}
}
char* wchar_to_char(const wchar_t* pwchar) {
char* wchar_to_char(const wchar_t* pwchar) {
// get the number of characters in the string.
int currentCharIndex = 0;
char currentChar = (char)pwchar[currentCharIndex];
@@ -292,16 +293,16 @@ char* wchar_to_char(const wchar_t* pwchar) {
filePathC -= (sizeof(char) * charCount);
return filePathC;
}
}
const wchar_t* char_to_wchar(const char* c) {
const wchar_t* char_to_wchar(const char* c) {
const size_t cSize = strlen(c)+1;
wchar_t* wc = new wchar_t[cSize];
mbstowcs (wc, c, cSize);
return wc;
}
proc print(Lisp_Object* node, bool print_repr, FILE* file) -> void {
}
proc print(Lisp_Object* node, bool print_repr, FILE* file) -> void {
switch (Memory::get_type(node)) {
case (Lisp_Object_Type::Nil): fputs("()", file); break;
case (Lisp_Object_Type::T): fputs("t", file); break;
@@ -420,9 +421,9 @@ proc print(Lisp_Object* node, bool print_repr, FILE* file) -> void {
putc(')', file);
} break;
}
}
}
proc print_single_call(Lisp_Object* obj) -> void {
proc print_single_call(Lisp_Object* obj) -> void {
printf(console_cyan);
print(obj, true);
printf(console_normal);
@@ -436,9 +437,9 @@ proc print_single_call(Lisp_Object* obj) -> void {
} else {
fputs("no source code location avaliable", stdout);
}
}
}
proc print_call_stack() -> void {
proc print_call_stack() -> void {
using Globals::Current_Execution::call_stack;
printf("callstack [%d] (most recent call last):\n", call_stack.next_index);
@@ -447,9 +448,9 @@ proc print_call_stack() -> void {
print_single_call(call_stack.data[i]);
printf("\n");
}
}
}
proc log_error() -> void {
proc log_error() -> void {
fputs(console_red, stdout);
fputs(Memory::get_c_str(Globals::error->message), stdout);
puts(console_normal);
@@ -457,4 +458,5 @@ proc log_error() -> void {
fputs(" in: ", stdout);
print_call_stack();
puts(console_normal);
}
}
+3 -4
View File
@@ -39,14 +39,14 @@ unsigned int hm_hash(void* ptr);
unsigned int hm_hash(Slime::Lisp_Object* obj);
#include "ftb/hashmap.hpp"
namespace Slime {
# include "defines.cpp"
# include "assert.hpp"
# include "define_macros.hpp"
# include "platform.cpp"
# include "structs.cpp"
# include "forward_decls.cpp"
}
bool hm_objects_match(char* a, char* b) {
return strcmp(a, b) == 0;
@@ -107,7 +107,6 @@ unsigned int hm_hash(Slime::Lisp_Object* obj) {
}
}
namespace Slime {
# include "globals.cpp"
# include "memory.cpp"
# include "gc.cpp"
@@ -122,4 +121,4 @@ namespace Slime {
# include "built_ins.cpp"
# include "testing.cpp"
// # include "undefines.cpp"
}
+7 -5
View File
@@ -1,4 +1,5 @@
proc create_source_code_location(String* file, int line, int col) -> Source_Code_Location* {
namespace Slime {
proc create_source_code_location(String* file, int line, int col) -> Source_Code_Location* {
if (!file)
return nullptr;
@@ -7,9 +8,9 @@ proc create_source_code_location(String* file, int line, int col) -> Source_Code
ret->line = line;
ret->column = col;
return ret;
}
}
proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char* {
proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char* {
switch (type) {
case(Lisp_Object_Type::Nil): return "nil";
case(Lisp_Object_Type::T): return "t";
@@ -26,9 +27,9 @@ proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char* {
case(Lisp_Object_Type::HashMap): return "hashmap";
}
return "unknown";
}
}
Lisp_Object::~Lisp_Object() {
Lisp_Object::~Lisp_Object() {
free(sourceCodeLocation);
sourceCodeLocation = 0;
@@ -50,4 +51,5 @@ Lisp_Object::~Lisp_Object() {
} break;
default: break;
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
namespace Memory {
namespace Slime::Memory {
// ------------------
// global symbol / keyword table
+1 -1
View File
@@ -1,4 +1,4 @@
namespace Parser {
namespace Slime::Parser {
String* standard_in;
String* parser_file;
int parser_line;
+12 -9
View File
@@ -1,4 +1,6 @@
inline proc get_cwd() -> char* {
namespace Slime {
inline proc get_cwd() -> char* {
const int buf_size = 2048;
char* res = (char*)malloc(buf_size * sizeof(char));
@@ -9,19 +11,19 @@ inline proc get_cwd() -> char* {
#endif
return res;
}
}
inline proc change_cwd(char* dir) -> void {
inline proc change_cwd(char* dir) -> void {
#ifdef _MSC_VER
_chdir(dir);
#else
chdir(dir);
#endif
}
}
#ifdef _MSC_VER
int vasprintf(char **strp, const char *fmt, va_list ap) {
int vasprintf(char **strp, const char *fmt, va_list ap) {
// _vscprintf tells you how big the buffer needs to be
int len = _vscprintf(fmt, ap);
if (len == -1) {
@@ -40,18 +42,18 @@ int vasprintf(char **strp, const char *fmt, va_list ap) {
}
*strp = str;
return r;
}
}
int asprintf(char **strp, const char *fmt, ...) {
int asprintf(char **strp, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int r = vasprintf(strp, fmt, ap);
va_end(ap);
return r;
}
}
#endif
proc get_exe_dir() -> char* {
proc get_exe_dir() -> char* {
#ifdef _MSC_VER
DWORD last_error;
DWORD result;
@@ -164,4 +166,5 @@ proc get_exe_dir() -> char* {
return path;
#endif
}
}
+42 -40
View File
@@ -1,13 +1,14 @@
struct Lisp_Object;
struct String;
struct Environment;
namespace Slime {
struct Lisp_Object;
struct String;
struct Environment;
enum struct Thread_Type {
enum struct Thread_Type {
Main,
GarbageCollection
};
};
enum struct Lisp_Object_Type {
enum struct Lisp_Object_Type {
Nil,
T,
Symbol,
@@ -22,75 +23,75 @@ enum struct Lisp_Object_Type {
// OwningPointer,
Function,
CFunction,
};
};
enum class Lisp_Object_Flags
{
enum class Lisp_Object_Flags
{
// bits 1 to 5 (including) will be reserved for the type
Already_Garbage_Collected = 1 << 5,
Under_Construction = 1 << 6,
};
};
enum struct Function_Type {
enum struct Function_Type {
Lambda,
Macro
};
};
enum struct Log_Level {
enum struct Log_Level {
None,
Critical,
Warning,
Info,
Debug,
};
};
struct Continuation {
struct Continuation {
Array_List<Lisp_Object*> call_stack;
Array_List<Environment*> envi_stack;
};
};
struct String {
struct String {
int length;
char data;
};
};
struct Source_Code_Location {
struct Source_Code_Location {
String* file;
int line;
int column;
};
};
struct Pair {
struct Pair {
Lisp_Object* first;
Lisp_Object* rest;
};
};
struct Vector {
struct Vector {
int length;
Lisp_Object* data;
};
};
struct Positional_Arguments {
struct Positional_Arguments {
Array_List<Lisp_Object*> symbols;
};
};
struct Keyword_Arguments {
struct Keyword_Arguments {
// Array of Pointers to Lisp_Object<Keyword>
Array_List<Lisp_Object*> keywords;
// NOTE(Felix): values[i] will be nullptr if no defalut value was
// declared for key identifiers[i]
Array_List<Lisp_Object*> values;
};
};
struct Arguments {
struct Arguments {
Positional_Arguments positional;
Keyword_Arguments keyword;
// NOTE(Felix): rest_argument will be nullptr if no rest argument
// is declared otherwise its a symbol
Lisp_Object* rest;
};
};
struct Environment {
struct Environment {
Array_List<Environment*> parents;
Hash_Map<void*, Lisp_Object*> hm;
@@ -98,22 +99,22 @@ struct Environment {
parents.~Array_List();
hm.~Hash_Map();
}
};
};
struct Function {
struct Function {
Function_Type type;
Arguments args;
Lisp_Object* body; // maybe implicit begin
Environment* parent_environment; // we are doing closures now!!
};
};
struct cFunction {
struct cFunction {
Lisp_Object* (*body)();
Arguments args;
bool is_special_form;
};
};
struct Lisp_Object {
struct Lisp_Object {
Source_Code_Location* sourceCodeLocation;
u64 flags;
Lisp_Object* userType; // keyword
@@ -132,11 +133,12 @@ struct Lisp_Object {
~value() {}
} value;
~Lisp_Object();
};
};
struct Error {
struct Error {
Lisp_Object* position;
// type has to be a keyword
Lisp_Object* type;
String* message;
};
};
}
+44 -38
View File
@@ -1,3 +1,5 @@
namespace Slime {
#define epsilon 2.2204460492503131E-16
#define testresult int
@@ -113,7 +115,7 @@
} \
}
proc test_array_lists_adding_and_removing() -> testresult {
proc test_array_lists_adding_and_removing() -> testresult {
// test adding and removing
Array_List<int> list;
list.append(1);
@@ -137,9 +139,9 @@ proc test_array_lists_adding_and_removing() -> testresult {
assert_equal_int(list[1], 2);
return pass;
}
}
proc test_array_lists_sorting() -> testresult {
proc test_array_lists_sorting() -> testresult {
// test adding and removing
Array_List<int> list;
list.append(1);
@@ -171,9 +173,9 @@ proc test_array_lists_sorting() -> testresult {
assert_equal_int(list[5], 5);
return pass;
}
}
proc test_array_lists_searching() -> testresult {
proc test_array_lists_searching() -> testresult {
Array_List<int> list;
list.append(1);
list.append(2);
@@ -190,9 +192,9 @@ proc test_array_lists_searching() -> testresult {
assert_equal_int(index, -1);
return pass;
}
}
proc test_eval_operands() -> testresult {
proc test_eval_operands() -> testresult {
char operands_string[] = "((eval 1) (+ 1 2) \"okay\" (eval :haha))";
Lisp_Object* operands = Parser::parse_single_expression(operands_string);
try operands = eval_arguments(operands);
@@ -222,9 +224,9 @@ proc test_eval_operands() -> testresult {
assert_equal_string(operands->value.pair.first->value.symbol, "haha");
return pass;
}
}
proc test_parse_atom() -> testresult {
proc test_parse_atom() -> testresult {
int index_in_text = 0;
char string[] =
"123 -1.23e-2 " // numbers
@@ -278,9 +280,9 @@ proc test_parse_atom() -> testresult {
assert_equal_string(result->value.symbol, "+");
return pass;
}
}
proc test_parse_expression() -> testresult {
proc test_parse_expression() -> testresult {
int index_in_text = 0;
char string[] = "(fun + 12)";
@@ -333,9 +335,9 @@ proc test_parse_expression() -> testresult {
result = result->value.pair.rest;
return pass;
}
}
proc test_built_in_add() -> testresult {
proc test_built_in_add() -> testresult {
char exp_string[] = "(+ 10 4)";
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
Lisp_Object* result;
@@ -347,9 +349,9 @@ proc test_built_in_add() -> testresult {
assert_equal_double(result->value.number, 14);
return pass;
}
}
proc test_built_in_substract() -> testresult {
proc test_built_in_substract() -> testresult {
char exp_string[] = "(- 10 4)";
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
Lisp_Object* result;
@@ -362,10 +364,10 @@ proc test_built_in_substract() -> testresult {
assert_equal_double(result->value.number, 6);
return pass;
}
}
proc test_built_in_multiply() -> testresult {
proc test_built_in_multiply() -> testresult {
char exp_string[] = "(* 10 4)";
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
Lisp_Object* result;
@@ -377,10 +379,10 @@ proc test_built_in_multiply() -> testresult {
assert_equal_double(result->value.number, 40);
return pass;
}
}
proc test_built_in_divide() -> testresult {
proc test_built_in_divide() -> testresult {
char exp_string[] = "(/ 20 4)";
Lisp_Object* expression = Parser::parse_single_expression(exp_string);
Lisp_Object* result;
@@ -392,10 +394,10 @@ proc test_built_in_divide() -> testresult {
assert_equal_double(result->value.number, 5);
return pass;
}
}
proc test_built_in_if() -> testresult {
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;
@@ -416,9 +418,9 @@ proc test_built_in_if() -> testresult {
assert_equal_double(result->value.number, 5);
return pass;
}
}
proc test_built_in_and() -> testresult {
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;
@@ -438,9 +440,9 @@ proc test_built_in_and() -> testresult {
assert_equal_type(result, Lisp_Object_Type::Nil);
return pass;
}
}
proc test_built_in_or() -> testresult {
proc test_built_in_or() -> testresult {
char exp_string1[] = "(or \"asd\" nil)";
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
Lisp_Object* result;
@@ -460,10 +462,10 @@ proc test_built_in_or() -> testresult {
assert_equal_type(result, Lisp_Object_Type::Nil);
return pass;
}
}
proc test_built_in_not() -> testresult {
proc test_built_in_not() -> testresult {
char exp_string1[] = "(not ())";
Lisp_Object* expression = Parser::parse_single_expression(exp_string1);
Lisp_Object* result;
@@ -484,9 +486,9 @@ proc test_built_in_not() -> testresult {
assert_equal_type(result, Lisp_Object_Type::Nil);
return pass;
}
}
proc test_built_in_type() -> testresult {
proc test_built_in_type() -> testresult {
// Environment* env;
// try env = get_root_environment();
@@ -535,9 +537,9 @@ proc test_built_in_type() -> testresult {
assert_equal_string(result->value.symbol, "number");
return pass;
}
}
proc test_singular_t_and_nil() -> testresult {
proc test_singular_t_and_nil() -> testresult {
// nil testing
char exp_string1[] = "()";
char exp_string2[] = "nil";
@@ -567,9 +569,9 @@ proc test_singular_t_and_nil() -> testresult {
assert_not_null(result3);
return pass;
}
}
proc test_singular_symbols() -> testresult {
proc test_singular_symbols() -> testresult {
auto cc_s_aa = Memory::get_symbol("aa");
auto cc_s_aa2 = Memory::get_symbol("aa2");
auto s_s_aa = Memory::get_symbol(Memory::create_string("aa"));
@@ -580,9 +582,9 @@ proc test_singular_symbols() -> testresult {
assert_not_equal_int(cc_s_aa, cc_s_aa2);
return pass;
}
}
proc test_file(const char* file) -> testresult {
proc test_file(const char* file) -> testresult {
profile_with_name(file);
// Memory::reset();
// assert_no_error();
@@ -593,15 +595,17 @@ proc test_file(const char* file) -> testresult {
pop_environment();
return pass;
}
}
proc run_all_tests() -> bool {
proc run_all_tests() -> bool {
profile_this();
bool result = true;
try Memory::init(409600);
push_environment(Memory::create_child_environment(
get_current_environment()));
printf("-- Util --\n");
invoke_test(test_array_lists_adding_and_removing);
invoke_test(test_array_lists_sorting);
@@ -629,6 +633,7 @@ proc run_all_tests() -> bool {
invoke_test(test_singular_t_and_nil);
invoke_test(test_singular_symbols);
pop_environment();
printf("\n-- Test Files --\n");
invoke_test_script("evaluation_of_default_args");
@@ -644,7 +649,7 @@ proc run_all_tests() -> bool {
invoke_test_script("singular_imports");
return result;
}
}
#undef epsilon
#undef testresult
@@ -664,3 +669,4 @@ proc run_all_tests() -> bool {
#undef assert_not_null
#undef invoke_test
#undef invoke_test_script
}
+3 -1
View File
@@ -1,4 +1,5 @@
proc visualize_lisp_machine() -> void {
namespace Slime {
proc visualize_lisp_machine() -> void {
// // save the current working directory
// char* cwd = get_cwd();
@@ -551,4 +552,5 @@ proc visualize_lisp_machine() -> void {
// " viewBox='%012d %012d %012d %012d'"
// ">", -padding, -padding, max_x + 2*padding, max_y + 2*padding);
}
}