windows works again and also alists working now

This commit is contained in:
FelixBrendel
2019-06-27 23:59:27 +02:00
parent efded2f9b8
commit 6da1530d0f
11 changed files with 142 additions and 69 deletions
+1 -1
View File
@@ -40,7 +40,7 @@
(error "key was not found in alist")) (error "key was not found in alist"))
((= (caar associations) key) ((= (caar associations) key)
(cdar associations)) (cdar associations))
(else (alist-get-intern (rest alist) key)))) (else (alist-get-intern (rest associations) key))))
(alist-get-intern associations key))) (alist-get-intern associations key)))
+2 -2
View File
@@ -18,7 +18,7 @@
(car (caar seq))) (car (caar seq)))
(define (caadr seq) (define (caadr seq)
(caar (cdr seq))) (car (cadr seq)))
(define (cadar seq) (define (cadar seq)
(car (cdr (car seq)))) (car (cdr (car seq))))
@@ -33,7 +33,7 @@
(cdr (car (cdr seq)))) (cdr (car (cdr seq))))
(define (cddar seq) (define (cddar seq)
(cddr (car seq))) (cdr (cdar seq)))
(define (cdddr seq) (define (cdddr seq)
(cdr (cddr seq))) (cdr (cddr seq)))
-1
View File
@@ -37,7 +37,6 @@
;; key1: value1) ;; key1: value1)
(assert (= (length (first a)) 3)) (assert (= (length (first a)) 3))
(pprint-alist a)
(assert (= (alist-get a 'key1) 'value4)) (assert (= (alist-get a 'key1) 'value4))
(alist-remove! a 'key1) (alist-remove! a 'key1)
+1 -1
View File
@@ -923,7 +923,7 @@ proc load_built_ins_into_environment(Environment* env) -> void {
try evaluated_arguments = eval_arguments(arguments, env, &arguments_length); try evaluated_arguments = eval_arguments(arguments, env, &arguments_length);
try assert_arguments_length(1, arguments_length); try assert_arguments_length(1, arguments_length);
return Memory::create_lisp_object_number((u64)&(evaluated_arguments->value.pair.first->value)); return Memory::create_lisp_object_number((float)((u64)&(evaluated_arguments->value.pair.first->value)));
}); });
defun("generate-docs", "TODO", __LINE__, cLambda { defun("generate-docs", "TODO", __LINE__, cLambda {
try arguments_length = list_length(arguments); try arguments_length = list_length(arguments);
+5 -5
View File
@@ -1,15 +1,15 @@
proc generate_docs(Environment* env, String* path) -> void { proc generate_docs(Environment* env, String* path) -> void {
// save the current working directory // save the current working directory
char cwd[1024]; char* cwd = get_cwd();
getcwd(cwd, 1024);
// get the direction of the exe // get the direction of the exe
char* exe_path = exe_dir(); char* exe_path = exe_dir();
chdir(exe_path); change_cwd(exe_path);
free(exe_path);
defer { defer {
// switch back to the users directory // switch back to the users directory
chdir(cwd); change_cwd(cwd);
free(exe_path);
free(cwd);
}; };
FILE *f = fopen(Memory::get_c_str(path), "w"); FILE *f = fopen(Memory::get_c_str(path), "w");
+41 -1
View File
@@ -388,11 +388,12 @@ proc log_error() -> void {
} }
proc exe_dir() -> char* { proc exe_dir() -> char* {
if_linux {
size_t size = 512, i, n; size_t size = 512, i, n;
char *path, *temp; char *path, *temp;
while (1) { while (1) {
ssize_t used; size_t used;
path = (char*)malloc(size); path = (char*)malloc(size);
if (!path) { if (!path) {
@@ -447,4 +448,43 @@ proc exe_dir() -> char* {
path[n+1] = '\0'; path[n+1] = '\0';
return path; return path;
}
if_windows {
DWORD last_error;
DWORD result;
DWORD path_size = 1024;
char* path = (char*)malloc(1024);
while (true) {
memset(path, 0, path_size);
result = GetModuleFileName(0, path, path_size - 1);
last_error = GetLastError();
if (0 == result) {
free(path);
path = 0;
break;
}
else if (result == path_size - 1) {
free(path);
/* May need to also check for ERROR_SUCCESS here if XP/2K */
if (ERROR_INSUFFICIENT_BUFFER != last_error) {
path = 0;
break;
}
path_size = path_size * 2;
path = (char*)malloc(path_size);
}
else
break;
}
if (!path) {
fprintf(stderr, "Failure: %d\n", last_error);
return "";
}
else
return path;
}
} }
+6 -4
View File
@@ -357,17 +357,19 @@ namespace Memory {
Parser::environment_for_macros = ret; Parser::environment_for_macros = ret;
// save the current working directory // save the current working directory
char cwd[1024]; char* cwd = get_cwd();
getcwd(cwd, 1024); defer {
free(cwd);
};
// get the direction of the exe // get the direction of the exe
char* exe_path = exe_dir(); char* exe_path = exe_dir();
chdir(exe_path); change_cwd(exe_path);
free(exe_path); free(exe_path);
built_in_load(Memory::create_string("pre.slime"), ret); built_in_load(Memory::create_string("pre.slime"), ret);
chdir(cwd); change_cwd(cwd);
return ret; return ret;
} }
+23
View File
@@ -0,0 +1,23 @@
inline proc get_cwd() -> char* {
const int buf_size = 2048;
char* res = (char*)malloc(buf_size * sizeof(char));
if_linux {
getcwd(res, buf_size);
}
if_windows {
_getcwd(res, buf_size);
}
return res;
}
inline proc change_cwd(char* dir) -> void {
if_linux {
chdir(dir);
}
if_windows {
_chdir(dir);
}
}
+9 -1
View File
@@ -3,7 +3,14 @@
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
# include <direct.h>
# include <windows.h>
size_t readlink(char*, char*, size_t);
#else
# include <unistd.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
@@ -19,6 +26,7 @@ namespace Slime {
# include "./defines.cpp" # include "./defines.cpp"
# include "./structs.cpp" # include "./structs.cpp"
# include "./forward_decls.cpp" # include "./forward_decls.cpp"
# include "./platform.cpp"
# include "./memory.cpp" # include "./memory.cpp"
# include "./lisp_object.cpp" # include "./lisp_object.cpp"
# include "./error.cpp" # include "./error.cpp"
+1 -1
View File
@@ -596,7 +596,7 @@ proc run_all_tests() -> bool {
char* exe_path = exe_dir(); char* exe_path = exe_dir();
// switch to the exe directory for loading pre.slime // switch to the exe directory for loading pre.slime
chdir(exe_path); change_cwd(exe_path);
free(exe_path); free(exe_path);
bool result = true; bool result = true;
+8 -7
View File
@@ -1,17 +1,18 @@
proc visualize_lisp_machine() -> void { proc visualize_lisp_machine() -> void {
// save the current working directory // save the current working directory
char cwd[1024]; char* cwd = get_cwd();
getcwd(cwd, 1024);
// get the direction of the exe // get the direction of the exe
char* exe_path = exe_dir(); char* exe_path = exe_dir();
// switch to the exe directory for loading pre.slime // switch to the exe directory for loading pre.slime
chdir(exe_path); change_cwd(exe_path);
free(exe_path); free(exe_path);
defer { defer {
// switch back to the users directory // switch back to the users directory
chdir(cwd); change_cwd(cwd);
free(cwd);
}; };
struct Drawn_Area { struct Drawn_Area {
@@ -180,7 +181,7 @@ proc visualize_lisp_machine() -> void {
case Lisp_Object_Type::T: return draw_text("t"); case Lisp_Object_Type::T: return draw_text("t");
case Lisp_Object_Type::Nil: return draw_text("()"); case Lisp_Object_Type::Nil: return draw_text("()");
case Lisp_Object_Type::Pair: return draw_pair(obj); case Lisp_Object_Type::Pair: return draw_pair(obj);
case Lisp_Object_Type::Number: return draw_float(obj->value.number); case Lisp_Object_Type::Number: return draw_float((float)obj->value.number);
case Lisp_Object_Type::Symbol: return draw_text(&obj->value.string->data); case Lisp_Object_Type::Symbol: return draw_text(&obj->value.string->data);
case Lisp_Object_Type::Keyword: { case Lisp_Object_Type::Keyword: {
Drawn_Area colon = draw_text(":", "#c61b6e"); Drawn_Area colon = draw_text(":", "#c61b6e");
@@ -303,7 +304,7 @@ proc visualize_lisp_machine() -> void {
// ------------------- // -------------------
draw_new_line(); draw_new_line();
int free_string_memory = Memory::next_free_spot_in_string_memory - Memory::string_memory; int free_string_memory = (int)(Memory::next_free_spot_in_string_memory - Memory::string_memory);
for (int i = 0; i < Memory::free_spots_in_string_memory->next_index; ++i) { for (int i = 0; i < Memory::free_spots_in_string_memory->next_index; ++i) {
free_string_memory += ((String*)(Memory::free_spots_in_string_memory->data[i]))->length; free_string_memory += ((String*)(Memory::free_spots_in_string_memory->data[i]))->length;
} }
@@ -491,7 +492,7 @@ proc visualize_lisp_machine() -> void {
draw_new_line(); draw_new_line();
write_x = start_x + 600; write_x = start_x + 600;
draw_float(numbers->data[i]->value.number); draw_float((float)(numbers->data[i]->value.number));
} }
write_x = start_x + 900; write_x = start_x + 900;