| @@ -14,26 +14,6 @@ | |||
| (define (force promise) (promise)) | |||
| (define (pair-stream oject expression) (pair object (delay expression))) | |||
| (define stream-first first) | |||
| (define (stream-rest stream) (force (rest stream))) | |||
| (define (stream-ref s n) (if (= n 0) (stream-first s) (stream-ref (stream-rest s) (- n 1)))) | |||
| (define (stream-filter pred stream) (cond ((stream-null? stream) the-empty-stream) ((pred (stream-first stream)) (pair-stream (stream-first stream) (stream-filter pred (stream-rest stream)))) (else (stream-filter pred (stream-rest stream))))) | |||
| (define (stream-map proc s) (if (stream-null? s) the-empty-stream (pair-stream (proc (stream-first s)) (stream-map proc (stream-rest s))))) | |||
| (define (stream-for-each proc s) (if (stream-null? s) 'done (begin (proc (stream-first s)) (stream-for-each proc (stream-rest s))))) | |||
| (define (stream-enumerate-interval low high) (if (> low high) the-empty-stream (pair-stream low (stream-enumerate-interval (+ low 1) high)))) | |||
| (define (prime? x) (define (prime-helper x k) (cond ((= x k) t) ((= (% x k) 0) ()) (else (prime-helper x (+ k 1))))) (cond ((= x 1) ()) ((= x 2) t) (else (prime-helper x 2)))) | |||
| (define (a) (stream-first (stream-rest (stream-filter prime? (stream-enumerate-interval 10000 1020))))) | |||
| (define-syntax (when condition . body) :doc "Special form for when multiple actions should be done if a\ncondition is true.\n\n{{{example_start}}}\n(when (not ())\n (print "Hello ")\n (print "from ")\n (print "when!"))\n\n(when ()\n (print "Goodbye ")\n (print "World!"))\n{{{example_end}}}\n" (if (= (rest body) ()) `(if ,condition (unquote-splicing body) nil) `(if ,condition (begin (unquote-splicing body)) nil))) | |||
| (define-syntax (unless condition . body) :doc "Special form for when multiple actions should be done if a\ncondition is false." (if (= (rest body) ()) `(if ,condition nil (unquote-splicing body)) `(if ,condition nil (begin (unquote-splicing body))))) | |||
| @@ -42,6 +42,12 @@ proc lisp_object_equal(Lisp_Object* n1, Lisp_Object* n2) -> bool { | |||
| return false; | |||
| } | |||
| proc add_to_load_path(const char* path) -> void { | |||
| using Globals::load_path; | |||
| append_to_array_list(&load_path, (void*)path); | |||
| } | |||
| proc built_in_load(String* file_name) -> Lisp_Object* { | |||
| // char* full_file_name = find_slime_file(file_name); | |||
| char* file_content; | |||
| @@ -50,33 +56,25 @@ proc built_in_load(String* file_name) -> Lisp_Object* { | |||
| file_content = read_entire_file(Memory::get_c_str(file_name)); | |||
| if (!file_content) { | |||
| // try slime's bin dir | |||
| // save the current working directory | |||
| // get the direction of the exe | |||
| char* exe_path = get_exe_dir(); | |||
| defer { | |||
| free(exe_path); | |||
| }; | |||
| fullpath[0] = '\0'; | |||
| sprintf(fullpath, "%s%s", exe_path, Memory::get_c_str(file_name)); | |||
| // printf("Fullpath: %s\n", fullpath); | |||
| file_content = read_entire_file(fullpath); | |||
| for_array_list (Globals::load_path) { | |||
| fullpath[0] = '\0'; | |||
| sprintf(fullpath, "%s%s", (char*)it, Memory::get_c_str(file_name)); | |||
| file_content = read_entire_file(fullpath); | |||
| if (file_content) | |||
| break; | |||
| } | |||
| if (!file_content) { | |||
| char* cwd = get_cwd(); | |||
| defer { | |||
| free(cwd); | |||
| }; | |||
| create_generic_error("The file to load '%s' was not found: " | |||
| "neither in the cwd (%s) " | |||
| "nor in slime's exe dir (%s)", | |||
| Memory::get_c_str(file_name), cwd, fullpath); | |||
| return nullptr; | |||
| printf("Load path:\n"); | |||
| for_array_list (Globals::load_path) { | |||
| printf(" - %s\n", (char*) it); | |||
| } | |||
| create_generic_error("The file to load '%s' was not found in the load path.", | |||
| Memory::get_c_str(file_name)); | |||
| } | |||
| } | |||
| Lisp_Object* result = Memory::nil; | |||
| Lisp_Object_Array_List program; | |||
| try program = Parser::parse_program(Memory::create_string(fullpath), file_content); | |||
| @@ -175,7 +173,7 @@ proc load_built_ins_into_environment() -> void { | |||
| assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \ | |||
| auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \ | |||
| auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \ | |||
| /*NOTE(Felix): for evaluating default args*/ \ | |||
| /*NOTE(Felix): for evaluating default args*/ \ | |||
| /*push_environment(get_root_environment());*/ \ | |||
| create_arguments_from_lambda_list_and_inject(label(params,__LINE__)->value.pair.rest, label(sfun,__LINE__)); \ | |||
| /*pop_environment(); */ \ | |||
| @@ -1,4 +1,5 @@ | |||
| // proc assert_type(Lisp_Object*, Lisp_Object_Type) -> void; | |||
| proc add_to_load_path(const char*) -> void; | |||
| proc lisp_object_equal(Lisp_Object*,Lisp_Object*) -> bool; | |||
| proc built_in_load(String*) -> Lisp_Object*; | |||
| proc built_in_import(String*) -> Lisp_Object*; | |||
| @@ -45,6 +46,7 @@ namespace Globals { | |||
| char* bin_path = nullptr; | |||
| Log_Level log_level = Log_Level::Debug; | |||
| Void_Ptr_Array_List load_path = create_Void_Ptr_array_list(); | |||
| namespace Current_Execution { | |||
| Lisp_Object_Array_List call_stack = create_Lisp_Object_array_list(); | |||
| Environment_Array_List envi_stack = create_Environment_array_list(); | |||
| @@ -174,6 +174,10 @@ namespace Memory { | |||
| } | |||
| proc init(int oms, int ems, int sms) { | |||
| char* exe_path = get_exe_dir(); | |||
| defer {free(exe_path);}; | |||
| add_to_load_path(exe_path); | |||
| global_symbol_table = create_String_hashmap(); | |||
| global_keyword_table = create_String_hashmap(); | |||
| @@ -21,9 +21,6 @@ | |||
| # include <signal.h> | |||
| #endif | |||
| #undef _CRT_SECURE_NO_DEPRECATE | |||
| #undef _CRT_SECURE_NO_WARNINGS | |||
| #include "./ftb/macros.hpp" | |||
| #include "./ftb/profiler.hpp" | |||
| #include "./ftb/hashmap.hpp" | |||
| @@ -45,5 +42,5 @@ namespace Slime { | |||
| # include "./docgeneration.cpp" | |||
| # include "./built_ins.cpp" | |||
| # include "./testing.cpp" | |||
| # include "./undefines.cpp" | |||
| // # include "./undefines.cpp" | |||
| } | |||