fixed let not coying the initial value nodes
This commit is contained in:
+10
-5
@@ -65,10 +65,12 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
Lisp_Object* evaluated_arguments;
|
||||
|
||||
#define cLambda [=](Lisp_Object* arguments, Environment* env) mutable -> Lisp_Object*
|
||||
#define report_error(_type) { \
|
||||
printf("Error occurred\nin %s:%d\n", __FILE__, __LINE__); \
|
||||
create_error(_type, current_source_code_location); \
|
||||
return nullptr; \
|
||||
#define report_error(_type) { \
|
||||
if (log_level == Log_Level::Debug) { \
|
||||
printf("Error occurred\nin %s:%d\n", __FILE__, __LINE__); \
|
||||
} \
|
||||
create_error(_type, current_source_code_location); \
|
||||
return nullptr; \
|
||||
}
|
||||
|
||||
proc defun = [&](const char* name, auto fun) {
|
||||
@@ -682,7 +684,10 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
|
||||
Lisp_Object* value = eval_expr(rest_sym->value.pair->first, env);
|
||||
|
||||
define_symbol(sym, value, let_env);
|
||||
// NOTE(Felix): We have to copy the value here because
|
||||
// if the let body modifies the value, it would bake
|
||||
// in... bad bad...
|
||||
define_symbol(sym, Memory::copy_lisp_object(value), let_env);
|
||||
|
||||
bindings = bindings->value.pair->rest;
|
||||
}
|
||||
|
||||
+62
-25
@@ -23,39 +23,45 @@ constexpr bool is_debug_build = false;
|
||||
#define assert(cond) \
|
||||
if_debug { \
|
||||
if (!cond) { \
|
||||
printf("Assertion failed: %s %d", __FILE__, __LINE__); \
|
||||
if (log_level == Log_Level::Debug) { \
|
||||
printf("Assertion failed: %s %d", __FILE__, __LINE__); \
|
||||
} \
|
||||
debug_break(); \
|
||||
} \
|
||||
} else {} \
|
||||
|
||||
#define concat_( a, b) a##b
|
||||
#define label(prefix, lnum) concat_(prefix,lnum)
|
||||
#define try \
|
||||
if (1) \
|
||||
goto label(body,__LINE__); \
|
||||
else \
|
||||
while (1) \
|
||||
if (1) { \
|
||||
if(error) { \
|
||||
printf("in %s:%d\n", __FILE__, __LINE__); \
|
||||
return 0; \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
#define try \
|
||||
if (1) \
|
||||
goto label(body,__LINE__); \
|
||||
else \
|
||||
while (1) \
|
||||
if (1) { \
|
||||
if(error) { \
|
||||
if (log_level == Log_Level::Debug) { \
|
||||
printf("in %s:%d\n", __FILE__, __LINE__); \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
else label(body,__LINE__):
|
||||
|
||||
#define try_void \
|
||||
if (1) \
|
||||
goto label(body,__LINE__); \
|
||||
else \
|
||||
while (1) \
|
||||
if (1) { \
|
||||
if(error) { \
|
||||
printf("in %s:%d\n", __FILE__, __LINE__); \
|
||||
return; \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
#define try_void \
|
||||
if (1) \
|
||||
goto label(body,__LINE__); \
|
||||
else \
|
||||
while (1) \
|
||||
if (1) { \
|
||||
if(error) { \
|
||||
if (log_level == Log_Level::Debug) { \
|
||||
printf("in %s:%d\n", __FILE__, __LINE__); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
else label(body,__LINE__):
|
||||
|
||||
|
||||
@@ -85,6 +91,37 @@ constexpr bool is_debug_build = false;
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
template<typename F>
|
||||
class defer_finalizer {
|
||||
F f;
|
||||
bool moved;
|
||||
public:
|
||||
template<typename T>
|
||||
defer_finalizer(T && f_) : f(std::forward<T>(f_)), moved(false) { }
|
||||
|
||||
defer_finalizer(const defer_finalizer &) = delete;
|
||||
|
||||
defer_finalizer(defer_finalizer && other) : f(std::move(other.f)), moved(other.moved) {
|
||||
other.moved = true;
|
||||
}
|
||||
|
||||
~defer_finalizer() {
|
||||
if (!moved) f();
|
||||
}
|
||||
};
|
||||
|
||||
struct {
|
||||
template<typename F>
|
||||
defer_finalizer<F> operator<<(F && f) {
|
||||
return defer_finalizer<F>(std::forward<F>(f));
|
||||
}
|
||||
} deferrer;
|
||||
|
||||
#define TOKENPASTE(x, y) x ## y
|
||||
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
||||
#define defer auto TOKENPASTE2(__deferred_lambda_call, __COUNTER__) = deferrer << [&]
|
||||
|
||||
#define console_normal "\x1B[0m"
|
||||
#define console_red "\x1B[31m"
|
||||
#define console_green "\x1B[32m"
|
||||
|
||||
@@ -39,10 +39,8 @@ proc Error_Type_to_string(Error_Type type) -> const char* {
|
||||
}
|
||||
|
||||
proc assert_type(Lisp_Object* node, Lisp_Object_Type type) -> void {
|
||||
if_debug {
|
||||
if (!node)
|
||||
create_error(Error_Type::Unknown_Error, nullptr);
|
||||
if (node->type == type) return;
|
||||
create_error(Error_Type::Type_Missmatch, node->sourceCodeLocation);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -486,7 +486,12 @@ proc test_lexical_scope() -> testresult {
|
||||
}
|
||||
|
||||
proc run_all_tests() -> bool {
|
||||
// log_level = Log_Level::None;
|
||||
Log_Level log_level_before = log_level;
|
||||
log_level = Log_Level::None;
|
||||
defer {
|
||||
log_level = log_level_before;
|
||||
};
|
||||
|
||||
Memory::init();
|
||||
Parser::init(Memory::create_built_ins_environment());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user