using stdint types
This commit is contained in:
+57
-67
@@ -12,7 +12,7 @@ namespace Slime {
|
||||
case Lisp_Object_Type::Symbol:
|
||||
case Lisp_Object_Type::Keyword:
|
||||
case Lisp_Object_Type::Function:
|
||||
// TODO(Felix): should a pointer
|
||||
// QUESTION(Felix): should a pointer
|
||||
// object compare the pointer?
|
||||
case Lisp_Object_Type::Pointer:
|
||||
case Lisp_Object_Type::Continuation: return false;
|
||||
@@ -36,7 +36,7 @@ namespace Slime {
|
||||
n1_keys.sort();
|
||||
n2_keys.sort();
|
||||
|
||||
for (int i = 0; i < n1_keys.next_index; ++i) {
|
||||
for (u32 i = 0; i < n1_keys.next_index; ++i) {
|
||||
if (!lisp_object_equal(n1_keys[i], n2_keys[i]))
|
||||
return false;
|
||||
if (!lisp_object_equal(n1->value.hashMap->get_object(n1_keys[i]),
|
||||
@@ -49,7 +49,7 @@ namespace Slime {
|
||||
case Lisp_Object_Type::Vector: {
|
||||
if (n1->value.vector.length != n2->value.vector.length )
|
||||
return false;
|
||||
for (int i = 0; i < n1->value.vector.length; ++i) {
|
||||
for (u32 i = 0; i < n1->value.vector.length; ++i) {
|
||||
if (!lisp_object_equal(n1->value.vector.data+i, n2->value.vector.data+i))
|
||||
return false;
|
||||
}
|
||||
@@ -149,12 +149,6 @@ namespace Slime {
|
||||
String file_name_built_ins = Memory::create_string(__FILE__);
|
||||
defer_free(file_name_built_ins.data);
|
||||
|
||||
define((remove_when_double_free_is_fixed (:k1 ()) (:k2 ()) . rest), "") {
|
||||
return Memory::nil;
|
||||
};
|
||||
define((remove_when_double_free_is_fixed_2 (:k1 ()) (:k2 ()) . rest), "") {
|
||||
return Memory::nil;
|
||||
};
|
||||
define_macro((apply fun fun_args), "TODO") {
|
||||
// NOTE(Felix): is has to be a macro because apply by
|
||||
// itself cannot return the result, we have to invoke eval
|
||||
@@ -207,7 +201,7 @@ namespace Slime {
|
||||
{
|
||||
define_symbol(
|
||||
Memory::get_symbol("c"),
|
||||
Memory::create_lisp_object((double)0));
|
||||
Memory::create_lisp_object((f64)0));
|
||||
String file_name_built_ins = Memory::create_string(__FILE__);
|
||||
define((lambda), "") {
|
||||
fetch(c);
|
||||
@@ -236,7 +230,7 @@ namespace Slime {
|
||||
profile_with_name("(begin)");
|
||||
using namespace Globals::Current_Execution;
|
||||
Lisp_Object* args = pcs[--pcs.next_index];
|
||||
int length = list_length(args);
|
||||
u32 length = list_length(args);
|
||||
cs.reserve(length);
|
||||
for_lisp_list(args) {
|
||||
cs.data[cs.next_index - 1 + (length - it_index)] = it;
|
||||
@@ -402,7 +396,7 @@ namespace Slime {
|
||||
define((> . args), "TODO") {
|
||||
profile_with_name("(>)");
|
||||
fetch(args);
|
||||
double last_number = strtod("Inf", NULL);
|
||||
f64 last_number = strtod("Inf", 0);
|
||||
|
||||
for_lisp_list (args) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -417,7 +411,7 @@ namespace Slime {
|
||||
{
|
||||
profile_with_name("(>=)");
|
||||
fetch(args);
|
||||
double last_number = strtod("Inf", NULL);
|
||||
f64 last_number = strtod("Inf", 0);
|
||||
|
||||
for_lisp_list (args) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -432,7 +426,7 @@ namespace Slime {
|
||||
{
|
||||
profile_with_name("(<)");
|
||||
fetch(args);
|
||||
double last_number = strtod("-Inf", NULL);
|
||||
f64 last_number = strtod("-Inf", 0);
|
||||
|
||||
for_lisp_list (args) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -447,7 +441,7 @@ namespace Slime {
|
||||
{
|
||||
profile_with_name("(<=)");
|
||||
fetch(args);
|
||||
double last_number = strtod("-Inf", NULL);
|
||||
f64 last_number = strtod("-Inf", 0);
|
||||
|
||||
for_lisp_list (args) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -463,7 +457,7 @@ namespace Slime {
|
||||
profile_with_name("(+)");
|
||||
fetch(args);
|
||||
|
||||
double sum = 0;
|
||||
f64 sum = 0;
|
||||
|
||||
for_lisp_list (args) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -481,7 +475,7 @@ namespace Slime {
|
||||
|
||||
|
||||
try assert_type(args->value.pair.first, Lisp_Object_Type::Number);
|
||||
double difference = args->value.pair.first->value.number;
|
||||
f64 difference = args->value.pair.first->value.number;
|
||||
|
||||
if (args->value.pair.rest == Memory::nil) {
|
||||
return Memory::create_lisp_object(-difference);
|
||||
@@ -502,7 +496,7 @@ namespace Slime {
|
||||
return Memory::create_lisp_object(1);
|
||||
}
|
||||
|
||||
double product = 1;
|
||||
f64 product = 1;
|
||||
|
||||
for_lisp_list (args) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -522,7 +516,7 @@ namespace Slime {
|
||||
|
||||
try assert_type(args->value.pair.first, Lisp_Object_Type::Number);
|
||||
|
||||
double quotient = args->value.pair.first->value.number;
|
||||
f64 quotient = args->value.pair.first->value.number;
|
||||
|
||||
for_lisp_list (args->value.pair.rest) {
|
||||
try assert_type(it, Lisp_Object_Type::Number);
|
||||
@@ -544,8 +538,8 @@ namespace Slime {
|
||||
fetch(a, b);
|
||||
try assert_type(a, Lisp_Object_Type::Number);
|
||||
try assert_type(b, Lisp_Object_Type::Number);
|
||||
return Memory::create_lisp_object((int)a->value.number %
|
||||
(int)b->value.number);
|
||||
return Memory::create_lisp_object((s32)a->value.number %
|
||||
(s32)b->value.number);
|
||||
};
|
||||
define((get-random-between a b), "TODO") {
|
||||
profile_with_name("(get-random-between)");
|
||||
@@ -553,9 +547,9 @@ namespace Slime {
|
||||
try assert_type(a, Lisp_Object_Type::Number);
|
||||
try assert_type(b, Lisp_Object_Type::Number);
|
||||
|
||||
double fa = a->value.number;
|
||||
double fb = b->value.number;
|
||||
double x = (double)rand()/(double)(RAND_MAX);
|
||||
f64 fa = a->value.number;
|
||||
f64 fb = b->value.number;
|
||||
f64 x = (f64)rand()/(f64)(RAND_MAX);
|
||||
x *= (fb - fa);
|
||||
x += fa;
|
||||
|
||||
@@ -585,7 +579,10 @@ namespace Slime {
|
||||
define_special((assert test), "TODO") {
|
||||
profile_with_name("(assert)");
|
||||
fetch(test);
|
||||
|
||||
// TODO(Felix): it's probably cleaner to have assert be a
|
||||
// macro + and_then_action to check for error. This is
|
||||
// also cool so we don't see an anditoinal recursive call
|
||||
// in the profiler
|
||||
in_caller_env {
|
||||
Lisp_Object* res;
|
||||
try res = eval_expr(test);
|
||||
@@ -598,8 +595,8 @@ namespace Slime {
|
||||
free(string);
|
||||
return nullptr;
|
||||
};
|
||||
define_special((define-syntax form . body), "TODO") {
|
||||
profile_with_name("(define-syntax)");
|
||||
define_special((define-macro form . body), "TODO") {
|
||||
profile_with_name("(define-macro)");
|
||||
fetch(form, body);
|
||||
// TODO(Felix): Macros cannot have docs now
|
||||
|
||||
@@ -623,8 +620,8 @@ namespace Slime {
|
||||
}
|
||||
return Memory::nil;
|
||||
};
|
||||
define((mutate target source), "TODO") {
|
||||
profile_with_name("(mutate)");
|
||||
define((mutate! target source), "TODO") {
|
||||
profile_with_name("(mutate!)");
|
||||
fetch(target, source);
|
||||
|
||||
if (target == Memory::nil ||
|
||||
@@ -650,7 +647,7 @@ namespace Slime {
|
||||
profile_with_name("(vector-length)");
|
||||
fetch(v);
|
||||
try assert_type(v, Lisp_Object_Type::Vector);
|
||||
return Memory::create_lisp_object((double)v->value.vector.length);
|
||||
return Memory::create_lisp_object((f64)v->value.vector.length);
|
||||
};
|
||||
define((vector-ref vec idx), "TODO") {
|
||||
profile_with_name("(vector-ref)");
|
||||
@@ -659,10 +656,10 @@ namespace Slime {
|
||||
try assert_type(vec, Lisp_Object_Type::Vector);
|
||||
try assert_type(idx, Lisp_Object_Type::Number);
|
||||
|
||||
int int_idx = ((int)idx->value.number);
|
||||
s32 int_idx = ((s32)idx->value.number);
|
||||
|
||||
try assert("vector access index must be >= 0", int_idx >= 0);
|
||||
try assert("vector access index must be < length", int_idx < vec->value.vector.length);
|
||||
try assert("vector access index must be < length", (u32)int_idx < vec->value.vector.length);
|
||||
|
||||
return vec->value.vector.data+int_idx;
|
||||
};
|
||||
@@ -673,10 +670,10 @@ namespace Slime {
|
||||
try assert_type(vec, Lisp_Object_Type::Vector);
|
||||
try assert_type(idx, Lisp_Object_Type::Number);
|
||||
|
||||
int int_idx = ((int)idx->value.number);
|
||||
s32 int_idx = ((s32)idx->value.number);
|
||||
|
||||
try assert("vector access index must be >= 0", int_idx >= 0);
|
||||
try assert("vector access index must be < length", int_idx < vec->value.vector.length);
|
||||
try assert("vector access index must be < length", (u32)int_idx < vec->value.vector.length);
|
||||
|
||||
vec->value.vector.data[int_idx] = *val;
|
||||
|
||||
@@ -920,28 +917,28 @@ namespace Slime {
|
||||
profile_with_name("(vector)");
|
||||
fetch(args);
|
||||
Lisp_Object* ret;
|
||||
int length = list_length(args);
|
||||
u32 length = list_length(args);
|
||||
try ret = Memory::create_lisp_object_vector(length, args);
|
||||
return ret;
|
||||
};
|
||||
define((pair car cdr), "TODO") {
|
||||
profile_with_name("(pair)");
|
||||
define((cons car cdr), "TODO") {
|
||||
profile_with_name("(cons)");
|
||||
fetch(car, cdr);
|
||||
|
||||
Lisp_Object* ret;
|
||||
try ret = Memory::create_lisp_object_pair(car, cdr);
|
||||
return ret;
|
||||
};
|
||||
define((first seq), "TODO") {
|
||||
profile_with_name("(first)");
|
||||
define((car seq), "TODO") {
|
||||
profile_with_name("(car)");
|
||||
fetch(seq);
|
||||
if (seq == Memory::nil)
|
||||
return Memory::nil;
|
||||
try assert_type(seq, Lisp_Object_Type::Pair);
|
||||
return seq->value.pair.first;
|
||||
};
|
||||
define((rest seq), "TODO") {
|
||||
profile_with_name("(rest)");
|
||||
define((cdr seq), "TODO") {
|
||||
profile_with_name("(cdr)");
|
||||
fetch(seq);
|
||||
if (seq == Memory::nil)
|
||||
return Memory::nil;
|
||||
@@ -1006,11 +1003,6 @@ namespace Slime {
|
||||
}
|
||||
return Memory::get_keyword("unknown");
|
||||
};
|
||||
// define((mem-reset), "TODO") {
|
||||
// profile_with_name("(mem-reset)");
|
||||
// Memory::reset();
|
||||
// return Memory::nil;
|
||||
// };
|
||||
define_special((info n), "TODO")
|
||||
{
|
||||
// NOTE(Felix): we need to define_special because the docstring is
|
||||
@@ -1049,7 +1041,7 @@ namespace Slime {
|
||||
if (args->positional.symbols.next_index != 0) {
|
||||
printf("%s",
|
||||
Memory::get_c_str(args->positional.symbols.data[0]->value.symbol));
|
||||
for (int i = 1; i < args->positional.symbols.next_index; ++i) {
|
||||
for (u32 i = 1; i < args->positional.symbols.next_index; ++i) {
|
||||
printf(", %s",
|
||||
Memory::get_c_str(args->positional.symbols.data[i]->value.symbol));
|
||||
}
|
||||
@@ -1064,7 +1056,7 @@ namespace Slime {
|
||||
print(args->keyword.values.data[0], true);
|
||||
printf(")");
|
||||
}
|
||||
for (int i = 1; i < args->keyword.values.next_index; ++i) {
|
||||
for (u32 i = 1; i < args->keyword.values.next_index; ++i) {
|
||||
printf(", %s",
|
||||
Memory::get_c_str(args->keyword.keywords.data[i]->value.symbol));
|
||||
if (args->keyword.values.data[i]) {
|
||||
@@ -1102,8 +1094,8 @@ namespace Slime {
|
||||
fetch(var);
|
||||
return Memory::create_lisp_object(&var);
|
||||
};
|
||||
define((generate-docs file_name), "TODO") {
|
||||
profile_with_name("(generate-docs)");
|
||||
define((generate-docs-file file_name), "TODO") {
|
||||
profile_with_name("(generate-docs-file)");
|
||||
fetch(file_name);
|
||||
try assert_type(file_name, Lisp_Object_Type::String);
|
||||
in_caller_env {
|
||||
@@ -1145,10 +1137,10 @@ namespace Slime {
|
||||
profile_with_name("(exit)");
|
||||
fetch(code);
|
||||
try assert_type(code, Lisp_Object_Type::Number);
|
||||
exit((int)code->value.number);
|
||||
exit((s32)code->value.number);
|
||||
};
|
||||
define((break), "TODO") {
|
||||
profile_with_name("(break)");
|
||||
define((show-environment), "TODO") {
|
||||
profile_with_name("(show-environment)");
|
||||
in_caller_env {
|
||||
print_environment(get_current_environment());
|
||||
}
|
||||
@@ -1159,8 +1151,8 @@ namespace Slime {
|
||||
Memory::print_status();
|
||||
return Memory::nil;
|
||||
};
|
||||
define_special((mytry try_part catch_part), "TODO") {
|
||||
profile_with_name("(mytry)");
|
||||
define_special((attempt try_part catch_part), "TODO") {
|
||||
profile_with_name("(attempt)");
|
||||
fetch(try_part, catch_part);
|
||||
|
||||
Lisp_Object* result;
|
||||
@@ -1204,8 +1196,6 @@ namespace Slime {
|
||||
define((copy obj), "TODO") {
|
||||
profile_with_name("(copy)");
|
||||
fetch(obj);
|
||||
// TODO(Felix): if we are copying string nodes, then
|
||||
// shouldn't the string itself also get copied??
|
||||
return Memory::copy_lisp_object(obj);
|
||||
};
|
||||
define((error type message), "TODO") {
|
||||
@@ -1229,6 +1219,14 @@ namespace Slime {
|
||||
try assert_type(sym, Lisp_Object_Type::Symbol);
|
||||
return Memory::get_keyword(sym->value.symbol);
|
||||
};
|
||||
define((symbol->string sym), "TODO") {
|
||||
profile_with_name("(symbol->string)");
|
||||
fetch(sym);
|
||||
|
||||
try assert_type(sym, Lisp_Object_Type::Symbol);
|
||||
return Memory::create_lisp_object(
|
||||
Memory::duplicate_string(sym->value.symbol));
|
||||
};
|
||||
define((string->symbol str), "TODO") {
|
||||
profile_with_name("(string->symbol)");
|
||||
fetch(str);
|
||||
@@ -1238,26 +1236,18 @@ namespace Slime {
|
||||
try assert_type(str, Lisp_Object_Type::String);
|
||||
return Memory::get_symbol(Memory::duplicate_string(str->value.string));
|
||||
};
|
||||
define((symbol->string sym), "TODO") {
|
||||
profile_with_name("(symbol->string)");
|
||||
fetch(sym);
|
||||
|
||||
try assert_type(sym, Lisp_Object_Type::Symbol);
|
||||
return Memory::create_lisp_object(
|
||||
Memory::duplicate_string(sym->value.symbol));
|
||||
};
|
||||
define((concat-strings . strings), "TODO") {
|
||||
profile_with_name("(concat-strings)");
|
||||
fetch(strings);
|
||||
|
||||
int resulting_string_len = 0;
|
||||
u32 resulting_string_len = 0;
|
||||
for_lisp_list (strings) {
|
||||
try assert_type(it, Lisp_Object_Type::String);
|
||||
resulting_string_len += it->value.string.length;
|
||||
}
|
||||
|
||||
String resulting_string = Memory::create_string("", resulting_string_len);
|
||||
int index_in_string = 0;
|
||||
u32 index_in_string = 0;
|
||||
|
||||
for_lisp_list (strings) {
|
||||
strcpy(resulting_string.data+index_in_string,
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
do { \
|
||||
if (Globals::log_level == Log_Level::Debug) { \
|
||||
printf("in"); \
|
||||
int spacing = 30-((int)strlen(__FILE__) + (int)log10(__LINE__));\
|
||||
s32 spacing = 30-((s32)strlen(__FILE__) + (s32)log10(__LINE__)); \
|
||||
if (spacing < 1) spacing = 1; \
|
||||
for (int i = 0; i < spacing;++i) \
|
||||
for (s32 i = 0; i < spacing;++i) \
|
||||
printf(" "); \
|
||||
printf("%s (%d) ", __FILE__, __LINE__); \
|
||||
printf("-> %s\n",__FUNCTION__); \
|
||||
@@ -139,7 +139,7 @@
|
||||
*/
|
||||
#define for_lisp_vector(v) \
|
||||
if (!v); else \
|
||||
if (int it_index = 0); else \
|
||||
if (u32 it_index = 0); else \
|
||||
for (auto it = v->value.vector.data; \
|
||||
it_index < v->value.vector.length; \
|
||||
it=v->value.vector.data+(++it_index))
|
||||
@@ -149,7 +149,7 @@
|
||||
*/
|
||||
#define for_lisp_list(l) \
|
||||
if (!l); else \
|
||||
if (int it_index = 0); else \
|
||||
if (u32 it_index = 0); else \
|
||||
for (Lisp_Object* head = l, *it; \
|
||||
head->type == Lisp_Object_Type::Pair && (it = head->value.pair.first); \
|
||||
head = head->value.pair.rest, ++it_index)
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace Slime {
|
||||
if (args->positional.symbols.next_index != 0) {
|
||||
fprintf(f, "\n - postitional :: ");
|
||||
fprintf(f, "=%s=", Memory::get_c_str(args->positional.symbols.data[0]->value.symbol));
|
||||
for (int i = 1; i < args->positional.symbols.next_index; ++i) {
|
||||
for (u32 i = 1; i < args->positional.symbols.next_index; ++i) {
|
||||
fprintf(f, ", =%s=", Memory::get_c_str(args->positional.symbols.data[i]->value.symbol));
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace Slime {
|
||||
print(args->keyword.values.data[0], true, f);
|
||||
fprintf(f, ")=");
|
||||
}
|
||||
for (int i = 1; i < args->keyword.values.next_index; ++i) {
|
||||
for (u32 i = 1; i < args->keyword.values.next_index; ++i) {
|
||||
fprintf(f, ", =%s=", Memory::get_c_str(args->keyword.keywords.data[i]->value.symbol));
|
||||
if (args->keyword.values.data[i]) {
|
||||
fprintf(f, " =(");
|
||||
@@ -135,7 +135,7 @@ namespace Slime {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < env->parents.next_index; ++i) {
|
||||
for (u32 i = 0; i < env->parents.next_index; ++i) {
|
||||
try_void rec(rec, env->parents.data[i], prefix);
|
||||
}
|
||||
};
|
||||
|
||||
+15
-17
@@ -29,26 +29,24 @@ namespace Slime {
|
||||
|
||||
proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* {
|
||||
// first check current environment
|
||||
static Lisp_Object* nil_sym = Memory::get_symbol("nil");
|
||||
static Lisp_Object* t_sym = Memory::get_symbol("t");
|
||||
|
||||
Lisp_Object* result;
|
||||
result = lookup_symbol_in_this_envt(node, env);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
for (int i = 0; i < env->parents.next_index; ++i) {
|
||||
for (u32 i = 0; i < env->parents.next_index; ++i) {
|
||||
result = try_lookup_symbol(node, env->parents.data[i]);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
|
||||
auto nil_sym = Memory::get_symbol("nil");
|
||||
auto t_sym = Memory::get_symbol("t");
|
||||
|
||||
if (node == nil_sym) {
|
||||
return Memory::nil;
|
||||
}
|
||||
if (node == t_sym) {
|
||||
} else if (node == t_sym) {
|
||||
return Memory::t;
|
||||
}
|
||||
|
||||
@@ -93,36 +91,36 @@ namespace Slime {
|
||||
}
|
||||
|
||||
|
||||
proc print_environment_indent(Environment* env, int indent) -> void {
|
||||
proc print_indent = [](int indent) {
|
||||
for (int i = 0; i < indent; ++i) {
|
||||
proc print_environment_indent(Environment* env, u32 indent) -> void {
|
||||
proc print_indent = [indent]() {
|
||||
for (u32 i = 0; i < indent; ++i) {
|
||||
printf(" ");
|
||||
}
|
||||
};
|
||||
|
||||
if(env == get_root_environment()) {
|
||||
print_indent(indent);
|
||||
printf("[built-ins]-Environment (%p)\n", env);
|
||||
print_indent();
|
||||
printf("[built-ins]-Environment (0x%p)\n", env);
|
||||
return;
|
||||
}
|
||||
|
||||
for_hash_map (env->hm) {
|
||||
print_indent(indent);
|
||||
print_indent();
|
||||
printf("-> %s :: ", (((Lisp_Object*)key)->value.symbol.data));
|
||||
print((Lisp_Object*)value);
|
||||
printf(" (0x%016llx)", (unsigned long long)value);
|
||||
printf(" (0x%p)", value);
|
||||
puts("");
|
||||
}
|
||||
for (int i = 0; i < env->parents.next_index; ++i) {
|
||||
print_indent(indent);
|
||||
printf("parent (%p)", env->parents.data[i]);
|
||||
for (u32 i = 0; i < env->parents.next_index; ++i) {
|
||||
print_indent();
|
||||
printf("parent (0x%p)", env->parents.data[i]);
|
||||
puts(":");
|
||||
print_environment_indent(env->parents.data[i], indent+4);
|
||||
}
|
||||
}
|
||||
|
||||
proc print_environment(Environment* env) -> void {
|
||||
printf("\n=== Environment === (%p)\n", env);
|
||||
printf("\n=== Environment === (0x%p)\n", env);
|
||||
print_environment_indent(env, 0);
|
||||
}
|
||||
|
||||
|
||||
+12
-15
@@ -7,7 +7,9 @@ namespace Slime {
|
||||
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,
|
||||
u32 c_file_line, Lisp_Object* type, String message) -> void
|
||||
{
|
||||
delete_error();
|
||||
if (Globals::breaking_on_errors) {
|
||||
debug_break();
|
||||
@@ -22,37 +24,32 @@ namespace Slime {
|
||||
if (Globals::log_level > Log_Level::None) {
|
||||
// c error location
|
||||
printf("in");
|
||||
int spacing = 30-((int)strlen(c_file_name) + (int)log10(c_file_line));
|
||||
s32 spacing = 30-((s32)strlen(c_file_name) + (s32)log10(c_file_line));
|
||||
if (spacing < 1) spacing = 1;
|
||||
for (int i = 0; i < spacing; ++i)
|
||||
for (s32 i = 0; i < spacing; ++i)
|
||||
printf(" ");
|
||||
printf("%s (%d) ", c_file_name, c_file_line);
|
||||
printf("%s (%u) ", c_file_name, c_file_line);
|
||||
printf("-> %s\n", c_func_name);
|
||||
}
|
||||
|
||||
// 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,
|
||||
u32 c_file_line, Lisp_Object* type, const char* format, ...) -> void {
|
||||
using Globals::error;
|
||||
|
||||
// TODO(Felix): is the length even used??
|
||||
int length = 200;
|
||||
String formatted_string = Memory::create_string("", length);
|
||||
if (error) {
|
||||
error = new(Error);
|
||||
error->type = type;
|
||||
}
|
||||
int written_length;
|
||||
// contents will be filled in
|
||||
String formatted_string = Memory::create_string("", 0);
|
||||
|
||||
va_list args;
|
||||
char* out_msg;
|
||||
va_start(args, format);
|
||||
written_length = vasprintf(&out_msg, format, args);
|
||||
formatted_string.length = vasprintf(&formatted_string.data, format, args);
|
||||
va_end(args);
|
||||
|
||||
formatted_string.length = written_length;
|
||||
strcpy(formatted_string.data, out_msg);
|
||||
free(out_msg);
|
||||
create_error(c_func_name, c_file_name, c_file_line, type, formatted_string);
|
||||
}
|
||||
}
|
||||
|
||||
+24
-20
@@ -2,13 +2,13 @@ namespace Slime {
|
||||
|
||||
proc create_extended_environment_for_function_application_nrc(
|
||||
Lisp_Object* function,
|
||||
int arg_start,
|
||||
int arg_end) -> Environment*
|
||||
u32 arg_start,
|
||||
u32 arg_end) -> Environment*
|
||||
{
|
||||
profile_this();
|
||||
using namespace Globals::Current_Execution;
|
||||
|
||||
int index_of_next_arg = arg_start;
|
||||
u32 index_of_next_arg = arg_start;
|
||||
bool is_c_function = function->value.function->is_c;
|
||||
Environment* env = Memory::create_child_environment(function->value.function->parent_environment);
|
||||
Arguments* arg_spec = &function->value.function->args;
|
||||
@@ -18,14 +18,14 @@ namespace Slime {
|
||||
defer {
|
||||
read_in_keywords.dealloc();
|
||||
};
|
||||
int obligatory_keywords_count = 0;
|
||||
int read_obligatory_keywords_count = 0;
|
||||
u32 obligatory_keywords_count = 0;
|
||||
u32 read_obligatory_keywords_count = 0;
|
||||
|
||||
Lisp_Object* sym;
|
||||
Lisp_Object* val;
|
||||
|
||||
// read positionals
|
||||
for (int i = 0; i < arg_spec->positional.symbols.next_index; ++i) {
|
||||
for (u32 i = 0; i < arg_spec->positional.symbols.next_index; ++i) {
|
||||
if (index_of_next_arg == arg_end) {
|
||||
create_parsing_error(
|
||||
"Not enough positional args supplied. Needed: %d suppied, %d.\n"
|
||||
@@ -51,7 +51,7 @@ namespace Slime {
|
||||
// if there are some left read keywords and rest
|
||||
if (index_of_next_arg != arg_end) {
|
||||
// find out how many keyword args we /have/ to read
|
||||
for (int i = 0; i < arg_spec->keyword.values.next_index; ++i) {
|
||||
for (u32 i = 0; i < arg_spec->keyword.values.next_index; ++i) {
|
||||
if (arg_spec->keyword.values.data[i] == nullptr)
|
||||
++obligatory_keywords_count;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ namespace Slime {
|
||||
while (cs.data[index_of_next_arg]->type == Lisp_Object_Type::Keyword) {
|
||||
// check if this one is even an accepted keyword
|
||||
bool accepted = false;
|
||||
for (int i = 0; i < arg_spec->keyword.keywords.next_index; ++i) {
|
||||
for (u32 i = 0; i < arg_spec->keyword.keywords.next_index; ++i) {
|
||||
if (cs.data[index_of_next_arg] == arg_spec->keyword.keywords.data[i]) {
|
||||
accepted = true;
|
||||
break;
|
||||
@@ -80,7 +80,7 @@ namespace Slime {
|
||||
}
|
||||
// This is an accepted kwarg; check if it was already
|
||||
// read in
|
||||
for (int i = 0; i < read_in_keywords.next_index; ++i) {
|
||||
for (u32 i = 0; i < read_in_keywords.next_index; ++i) {
|
||||
if (cs.data[index_of_next_arg] == read_in_keywords.data[i])
|
||||
{
|
||||
// if we already read it in but also finished
|
||||
@@ -130,10 +130,10 @@ namespace Slime {
|
||||
|
||||
kw_done:
|
||||
// check keywords for completeness
|
||||
for (int i = 0; i < arg_spec->keyword.values.next_index; ++i) {
|
||||
for (u32 i = 0; i < arg_spec->keyword.values.next_index; ++i) {
|
||||
auto defined_keyword = arg_spec->keyword.keywords.data[i];
|
||||
bool was_set = false;
|
||||
for (int j = 0; j < read_in_keywords.next_index; ++j) {
|
||||
for (u32 j = 0; j < read_in_keywords.next_index; ++j) {
|
||||
if (read_in_keywords.data[j] == defined_keyword) {
|
||||
was_set = true;
|
||||
break;
|
||||
@@ -271,13 +271,13 @@ namespace Slime {
|
||||
}
|
||||
|
||||
|
||||
proc list_length(Lisp_Object* node) -> int {
|
||||
proc list_length(Lisp_Object* node) -> u32 {
|
||||
if (node == Memory::nil)
|
||||
return 0;
|
||||
|
||||
try assert_type(node, Lisp_Object_Type::Pair);
|
||||
|
||||
int len = 0;
|
||||
u32 len = 0;
|
||||
|
||||
while (node->type == Lisp_Object_Type::Pair) {
|
||||
++len;
|
||||
@@ -369,9 +369,13 @@ namespace Slime {
|
||||
cs.data[cs.next_index-1] = pc->value.pair.first;
|
||||
ams.append(cs.next_index-1);
|
||||
|
||||
assert("invalid ams state",
|
||||
ams.data[ams.next_index-2] <=
|
||||
ams.data[ams.next_index-1]);
|
||||
if_debug {
|
||||
if (ams.next_index >= 2) {
|
||||
assert("invalid ams state",
|
||||
ams.data[ams.next_index-2] <=
|
||||
ams.data[ams.next_index-1]);
|
||||
}
|
||||
}
|
||||
|
||||
pcs.append(pc->value.pair.rest);
|
||||
mes.append(pc);
|
||||
@@ -400,9 +404,9 @@ namespace Slime {
|
||||
try pc->value.function->body.c_macro_body();
|
||||
} else if (pc->value.function->type.c_function_type == C_Function_Type::cSpecial)
|
||||
{
|
||||
// TODO(Felix): Why not call the function
|
||||
// right away, and instead push step, so
|
||||
// that step calls it?
|
||||
// QUESTION(Felix): Why not call the
|
||||
// function right away, and instead push
|
||||
// step, so that step calls it?
|
||||
push_pc_on_cs();
|
||||
nas->append(NasAction::Step);
|
||||
} else {
|
||||
@@ -438,7 +442,7 @@ namespace Slime {
|
||||
case NasAction::Step: {
|
||||
if (pcs.data[pcs.next_index-1] == Memory::nil) {
|
||||
--pcs.next_index;
|
||||
int am = ams.data[--ams.next_index];
|
||||
u32 am = ams.data[--ams.next_index];
|
||||
Lisp_Object* function = cs.data[am];
|
||||
try assert_type(function, Lisp_Object_Type::Function);
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ namespace Slime {
|
||||
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);
|
||||
void create_error(const char* c_func_name, const char* c_file_name, u32 c_file_line, Lisp_Object* type, const char* format, ...);
|
||||
void create_error(const char* c_func_name, const char* c_file_name, u32 c_file_line, Lisp_Object* type, String message);
|
||||
void create_error(Lisp_Object* type, const char* message, const char* c_file_name, u32 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*);
|
||||
u32 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);
|
||||
|
||||
@@ -46,12 +46,12 @@ namespace Slime {
|
||||
Lisp_Object* get_symbol(const char*);
|
||||
Lisp_Object* get_keyword(String identifier);
|
||||
Lisp_Object* get_keyword(const char*);
|
||||
Lisp_Object* create_lisp_object(double);
|
||||
Lisp_Object* create_lisp_object(f64);
|
||||
Lisp_Object* create_lisp_object(const char*);
|
||||
Lisp_Object* create_lisp_object_vector(Lisp_Object*);
|
||||
Lisp_Object* create_lisp_object_vector(Lisp_Object*, Lisp_Object*);
|
||||
Lisp_Object* create_lisp_object_vector(Lisp_Object*, Lisp_Object*, Lisp_Object*);
|
||||
Lisp_Object* create_lisp_object_vector(int, Lisp_Object*);
|
||||
Lisp_Object* create_lisp_object_vector(u32, Lisp_Object*);
|
||||
inline Lisp_Object* create_list(Lisp_Object*);
|
||||
inline Lisp_Object* create_list(Lisp_Object*,Lisp_Object*);
|
||||
inline Lisp_Object* create_list(Lisp_Object*,Lisp_Object*,Lisp_Object*);
|
||||
@@ -65,10 +65,10 @@ namespace Slime {
|
||||
|
||||
extern String standard_in;
|
||||
extern String parser_file;
|
||||
extern int parser_line;
|
||||
extern int parser_col;
|
||||
extern u32 parser_line;
|
||||
extern u32 parser_col;
|
||||
|
||||
Lisp_Object* parse_expression(char* text, int* index_in_text);
|
||||
Lisp_Object* parse_expression(char* text, u32* index_in_text);
|
||||
Lisp_Object* parse_single_expression(const char* text);
|
||||
Lisp_Object* parse_single_expression(char* text);
|
||||
Lisp_Object* parse_single_expression(wchar_t* text);
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ namespace Slime {
|
||||
#define STRINGIZE(s) STRINGIZE2(s)
|
||||
#define VERSION_STRING "v" STRINGIZE(v_major) "." STRINGIZE(v_minor) " - built on " __DATE__ " " __TIME__
|
||||
const char* version_string = VERSION_STRING;
|
||||
const int major_version = v_major;
|
||||
const int minor_version = v_minor;
|
||||
const u32 major_version = v_major;
|
||||
const u32 minor_version = v_minor;
|
||||
#undef v_major
|
||||
#undef v_minor
|
||||
#undef STRINGIZE2
|
||||
|
||||
+25
-27
@@ -2,7 +2,7 @@ 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++) {
|
||||
for(u32 i = 0; input[i] == check[i]; i++) {
|
||||
if (input[i] == '\0')
|
||||
return true;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Slime {
|
||||
|
||||
proc escape_string(char* in) -> char* {
|
||||
// TODO(Felix): add more escape sequences
|
||||
int i = 0, count = 0;
|
||||
u32 i = 0, count = 0;
|
||||
while (in[i] != '\0') {
|
||||
switch (in[i]) {
|
||||
case '\\':
|
||||
@@ -48,7 +48,7 @@ namespace Slime {
|
||||
|
||||
// copy in
|
||||
i = 0;
|
||||
int j = 0;
|
||||
u32 j = 0;
|
||||
while (in[i] != '\0') {
|
||||
switch (in[i]) {
|
||||
case '\\': ret[j++] = '\\'; ret[j++] = '\\'; break;
|
||||
@@ -62,7 +62,7 @@ namespace Slime {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc unescape_string(char* in) -> int {
|
||||
proc unescape_string(char* in) -> s32 {
|
||||
if (!in) return 0;
|
||||
|
||||
char *out = in, *p = in;
|
||||
@@ -114,7 +114,7 @@ namespace Slime {
|
||||
|
||||
/* Set the end of string. */
|
||||
*out = '\0';
|
||||
return (int)(out - in);
|
||||
return (s32)(out - in);
|
||||
}
|
||||
|
||||
proc read_entire_file(char* filename) -> char* {
|
||||
@@ -164,9 +164,9 @@ namespace Slime {
|
||||
|
||||
char* linep = line;
|
||||
size_t lenmax = 100, len = lenmax;
|
||||
int c;
|
||||
s32 c;
|
||||
|
||||
int nesting = 0;
|
||||
s32 nesting = 0;
|
||||
|
||||
while (true) {
|
||||
c = fgetc(stdin);
|
||||
@@ -204,9 +204,9 @@ namespace Slime {
|
||||
proc read_line() -> char* {
|
||||
char* line = (char*)malloc(100), * linep = line;
|
||||
size_t lenmax = 100, len = lenmax;
|
||||
int c;
|
||||
s32 c;
|
||||
|
||||
int nesting = 0;
|
||||
s32 nesting = 0;
|
||||
|
||||
if(line == nullptr)
|
||||
return nullptr;
|
||||
@@ -261,7 +261,7 @@ namespace Slime {
|
||||
|
||||
char* wchar_to_char(const wchar_t* pwchar) {
|
||||
// get the number of characters in the string.
|
||||
int currentCharIndex = 0;
|
||||
s32 currentCharIndex = 0;
|
||||
char currentChar = (char)pwchar[currentCharIndex];
|
||||
|
||||
while (currentChar != '\0')
|
||||
@@ -270,12 +270,12 @@ namespace Slime {
|
||||
currentChar = (char)pwchar[currentCharIndex];
|
||||
}
|
||||
|
||||
const int charCount = currentCharIndex + 1;
|
||||
const s32 charCount = currentCharIndex + 1;
|
||||
|
||||
// allocate a new block of memory size char (1 byte) instead of wide char (2 bytes)
|
||||
char* filePathC = (char*)malloc(sizeof(char) * charCount);
|
||||
|
||||
for (int i = 0; i < charCount; i++)
|
||||
for (s32 i = 0; i < charCount; i++)
|
||||
{
|
||||
// convert to char (1 byte)
|
||||
char character = (char)pwchar[i];
|
||||
@@ -302,7 +302,6 @@ namespace Slime {
|
||||
|
||||
proc string_buider_to_string(Array_List<char*> string_builder) -> char* {
|
||||
size_t len = 1;
|
||||
int idx = 0;
|
||||
for (auto str : string_builder) {
|
||||
len += strlen(str);
|
||||
}
|
||||
@@ -331,8 +330,8 @@ namespace Slime {
|
||||
case (Lisp_Object_Type::Continuation): return _strdup("[continuation]");
|
||||
case (Lisp_Object_Type::Pointer): return _strdup("[pointer]");
|
||||
case (Lisp_Object_Type::Number): {
|
||||
if (abs(node->value.number - (int)node->value.number) < 0.000001f)
|
||||
asprintf(&temp, "%d", (int)node->value.number);
|
||||
if (abs(node->value.number - (s32)node->value.number) < 0.000001f)
|
||||
asprintf(&temp, "%d", (s32)node->value.number);
|
||||
else
|
||||
asprintf(&temp, "%f", node->value.number);
|
||||
return temp;
|
||||
@@ -376,7 +375,7 @@ namespace Slime {
|
||||
string_builder.append(_strdup("["));
|
||||
if (node->value.vector.length > 0)
|
||||
string_builder.append(lisp_object_to_string(node->value.vector.data, print_repr));
|
||||
for (int i = 1; i < node->value.vector.length; ++i) {
|
||||
for (u32 i = 1; i < node->value.vector.length; ++i) {
|
||||
string_builder.append(_strdup(" "));
|
||||
string_builder.append(lisp_object_to_string(node->value.vector.data+i, print_repr));
|
||||
}
|
||||
@@ -388,11 +387,13 @@ namespace Slime {
|
||||
return temp;
|
||||
} break;
|
||||
case (Lisp_Object_Type::Function): {
|
||||
// TODO(Felix): Enable again when we have user types again:
|
||||
// if (node->userType) {
|
||||
// asprintf(&temp, "[%s]", Memory::get_c_str(node->userType->value.symbol));
|
||||
// return temp;
|
||||
// }
|
||||
if (Globals::user_types.key_exists(node)) {
|
||||
asprintf(&temp, "[%s]",
|
||||
((Lisp_Object*)Globals::user_types.key_exists(node))
|
||||
->value.symbol.data);
|
||||
return temp;
|
||||
}
|
||||
|
||||
if (node->value.function->is_c) {
|
||||
// NOTE(Felix): try to find the symbol it is bound to
|
||||
// in global env
|
||||
@@ -422,7 +423,6 @@ namespace Slime {
|
||||
}
|
||||
} break;
|
||||
case (Lisp_Object_Type::Pair): {
|
||||
// TODO
|
||||
Lisp_Object* head = node;
|
||||
|
||||
defer {
|
||||
@@ -489,7 +489,7 @@ namespace Slime {
|
||||
}
|
||||
default:
|
||||
create_generic_error("A Lisp_Object of type-id %d cannot be converted to a string",
|
||||
(int)(node->type));
|
||||
(u8)(node->type));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -528,12 +528,10 @@ namespace Slime {
|
||||
using Globals::Current_Execution::nass;
|
||||
using Globals::Current_Execution::ams;
|
||||
printf("cs:\n ");
|
||||
for (int i = 0; i < cs.next_index; ++i) {
|
||||
for (u32 i = 0; i < cs.next_index; ++i) {
|
||||
char* t = lisp_object_to_string(cs.data[i], true);
|
||||
defer_free(t);
|
||||
printf(" %d: %s\n ", i, t);
|
||||
defer {
|
||||
free(t);
|
||||
};
|
||||
}
|
||||
printf("\npcs:\n ");
|
||||
for (auto lo : pcs) {
|
||||
|
||||
+12
-13
@@ -20,19 +20,18 @@
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
Forward declare the hash functions for the hashmap (needed at least
|
||||
for clang++)
|
||||
#include "ftb/types.hpp"
|
||||
/* NOTE(Felix): Forward declare the hash functions for the hashmap
|
||||
(needed at least for clang++)
|
||||
*/
|
||||
namespace Slime {struct Lisp_Object;}
|
||||
bool hm_objects_match(char* a, char* b);
|
||||
bool hm_objects_match(void* a, void* b);
|
||||
bool hm_objects_match(Slime::Lisp_Object* a, Slime::Lisp_Object* b);
|
||||
unsigned int hm_hash(char* str);
|
||||
unsigned int hm_hash(void* ptr);
|
||||
unsigned int hm_hash(Slime::Lisp_Object* obj);
|
||||
u32 hm_hash(char* str);
|
||||
u32 hm_hash(void* ptr);
|
||||
u32 hm_hash(Slime::Lisp_Object* obj);
|
||||
#include "ftb/hashmap.hpp"
|
||||
#include "ftb/types.hpp"
|
||||
#include "ftb/arraylist.hpp"
|
||||
#include "ftb/bucket_allocator.hpp"
|
||||
#include "ftb/macros.hpp"
|
||||
@@ -59,20 +58,20 @@ inline bool hm_objects_match(Slime::Lisp_Object* a, Slime::Lisp_Object* b) {
|
||||
return Slime::lisp_object_equal(a, b);
|
||||
}
|
||||
|
||||
unsigned int hm_hash(char* str) {
|
||||
unsigned int value = str[0] << 7;
|
||||
int i = 0;
|
||||
u32 hm_hash(char* str) {
|
||||
u32 value = str[0] << 7;
|
||||
s32 i = 0;
|
||||
while (str[i]) {
|
||||
value = (10000003 * value) ^ str[i++];
|
||||
}
|
||||
return value ^ i;
|
||||
}
|
||||
|
||||
unsigned int hm_hash(void* ptr) {
|
||||
return ((unsigned long long)ptr * 2654435761) % 4294967296;
|
||||
u32 hm_hash(void* ptr) {
|
||||
return ((u64)ptr * 2654435761) % 4294967296;
|
||||
}
|
||||
|
||||
unsigned int hm_hash(Slime::Lisp_Object* obj) {
|
||||
u32 hm_hash(Slime::Lisp_Object* obj) {
|
||||
using namespace Slime;
|
||||
switch (obj->type) {
|
||||
// hash from adress: if two objects of these types have
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
namespace Slime {
|
||||
proc create_source_code_location(String file, int line, int col) -> Source_Code_Location* {
|
||||
proc create_source_code_location(String file, u32 line, u32 col) -> Source_Code_Location* {
|
||||
if (!file.data)
|
||||
return nullptr;
|
||||
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#include "libslime.cpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
s32 main(s32 argc, char* argv[]) {
|
||||
#ifdef _MSC_VER
|
||||
// enable colored terminal output for windows
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
@@ -12,12 +12,12 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if (argc > 1) {
|
||||
if (Slime::string_equal(argv[1], "--run-tests")) {
|
||||
int res = Slime::run_all_tests();
|
||||
s32 res = Slime::run_all_tests();
|
||||
return res ? 0 : 1;
|
||||
} else if (Slime::string_equal(argv[1], "--generate-docs")) {
|
||||
} else if (Slime::string_equal(argv[1], "--generate-docs-file")) {
|
||||
Slime::Memory::init();
|
||||
if (Slime::Globals::error) return 1;
|
||||
Slime::built_in_load(Slime::Memory::create_string("generate-docs.slime"));
|
||||
Slime::built_in_load(Slime::Memory::create_string("generate-docs-file.slime"));
|
||||
} else {
|
||||
Slime::interprete_file(argv[1]);
|
||||
}
|
||||
|
||||
+9
-9
@@ -64,7 +64,7 @@ namespace Slime::Memory {
|
||||
// TODO(Felix): When parsing symbols or keywords, compute the
|
||||
// hash while reading them in.
|
||||
u64 value = str.data[0] << 7;
|
||||
for (int i = 1; i < str.length; ++i) {
|
||||
for (u32 i = 1; i < str.length; ++i) {
|
||||
char c = str.data[i];
|
||||
value = (1000003 * value) ^ c;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace Slime::Memory {
|
||||
|
||||
}
|
||||
|
||||
proc create_string(const char* str, int len) -> String {
|
||||
proc create_string(const char* str, u32 len) -> String {
|
||||
String s = {
|
||||
len,
|
||||
(char*)malloc(sizeof(char) * len + 1)
|
||||
@@ -84,7 +84,7 @@ namespace Slime::Memory {
|
||||
}
|
||||
|
||||
proc create_string (const char* str) -> String {
|
||||
return create_string(str, (int)strlen(str));
|
||||
return create_string(str, (u32)strlen(str));
|
||||
}
|
||||
|
||||
proc duplicate_string(String str) -> String {
|
||||
@@ -247,7 +247,7 @@ namespace Slime::Memory {
|
||||
return node;
|
||||
}
|
||||
|
||||
proc create_lisp_object(double number) -> Lisp_Object* {
|
||||
proc create_lisp_object(f64 number) -> Lisp_Object* {
|
||||
Lisp_Object* node;
|
||||
try node = create_lisp_object();
|
||||
node->type = Lisp_Object_Type::Number;
|
||||
@@ -271,7 +271,7 @@ namespace Slime::Memory {
|
||||
return node;
|
||||
}
|
||||
|
||||
proc allocate_vector(int size) -> Lisp_Object* {
|
||||
proc allocate_vector(u32 size) -> Lisp_Object* {
|
||||
Lisp_Object* ret = object_memory.allocate(size);
|
||||
if (!ret) {
|
||||
create_out_of_memory_error("The vector is too big to fit in a memory bucket.");
|
||||
@@ -280,7 +280,7 @@ namespace Slime::Memory {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc create_lisp_object_vector(int length, Lisp_Object* element_list) -> Lisp_Object* {
|
||||
proc create_lisp_object_vector(u32 length, Lisp_Object* element_list) -> Lisp_Object* {
|
||||
try assert_type(element_list, Lisp_Object_Type::Pair);
|
||||
|
||||
Lisp_Object* node;
|
||||
@@ -292,7 +292,7 @@ namespace Slime::Memory {
|
||||
|
||||
Lisp_Object* head = element_list;
|
||||
|
||||
int i = 0;
|
||||
u32 i = 0;
|
||||
while (head != Memory::nil) {
|
||||
node->value.vector.data[i] = *head->value.pair.first;
|
||||
head = head->value.pair.rest;
|
||||
@@ -412,14 +412,14 @@ namespace Slime::Memory {
|
||||
Lisp_Object* node;
|
||||
try node = create_lisp_object();
|
||||
node->type = Lisp_Object_Type::Pair;
|
||||
// node->value.pair = new(Pair);
|
||||
node->value.pair.first = first;
|
||||
node->value.pair.rest = rest;
|
||||
return node;
|
||||
}
|
||||
|
||||
proc copy_lisp_object(Lisp_Object* n) -> Lisp_Object* {
|
||||
// TODO(Felix): If argument is a list (pair), do a FULL copy,
|
||||
// QUESTION(Felix): If argument is a list (cons), should we do
|
||||
// a full copy?
|
||||
|
||||
// we don't copy singleton objects
|
||||
if (n == Memory::nil || n == Memory::t) {
|
||||
|
||||
+25
-25
@@ -1,10 +1,10 @@
|
||||
namespace Slime::Parser {
|
||||
String standard_in;
|
||||
String parser_file;
|
||||
int parser_line;
|
||||
int parser_col;
|
||||
u32 parser_line;
|
||||
u32 parser_col;
|
||||
|
||||
proc eat_comment_line(char* text, int* index_in_text) -> void {
|
||||
proc eat_comment_line(char* text, u32* index_in_text) -> void {
|
||||
// safety check if we are actually starting a comment here
|
||||
if (text[*index_in_text] != ';')
|
||||
return;
|
||||
@@ -18,8 +18,8 @@ namespace Slime::Parser {
|
||||
text[(*index_in_text)] != '\0');
|
||||
}
|
||||
|
||||
proc step_char(char* text, int* index_in_text, int steps = 1) {
|
||||
for (int i = 0; i < steps; ++i) {
|
||||
proc step_char(char* text, u32* index_in_text, u32 steps = 1) {
|
||||
for (u32 i = 0; i < steps; ++i) {
|
||||
if (text[(*index_in_text)] == '\n') {
|
||||
++parser_line;
|
||||
parser_col = 0;
|
||||
@@ -29,7 +29,7 @@ namespace Slime::Parser {
|
||||
}
|
||||
}
|
||||
|
||||
proc eat_whitespace(char* text, int* index_in_text) -> void {
|
||||
proc eat_whitespace(char* text, u32* index_in_text) -> void {
|
||||
// skip whitespaces
|
||||
while (text[(*index_in_text)] == ' ' ||
|
||||
text[(*index_in_text)] == '\t' ||
|
||||
@@ -40,9 +40,9 @@ namespace Slime::Parser {
|
||||
}
|
||||
}
|
||||
|
||||
proc eat_until_code(char* text, int* index_in_text) -> void {
|
||||
proc eat_until_code(char* text, u32* index_in_text) -> void {
|
||||
profile_this();
|
||||
int position_before;
|
||||
u32 position_before;
|
||||
do {
|
||||
position_before = *index_in_text;
|
||||
eat_comment_line(text, index_in_text);
|
||||
@@ -50,12 +50,12 @@ namespace Slime::Parser {
|
||||
} while (position_before != *index_in_text);
|
||||
}
|
||||
|
||||
proc step_char_and_eat_until_code(char* text, int* index_in_text) {
|
||||
proc step_char_and_eat_until_code(char* text, u32* index_in_text) {
|
||||
step_char(text, index_in_text);
|
||||
eat_until_code(text, index_in_text);
|
||||
}
|
||||
|
||||
proc parse_fancy_delimiter(char* text, int* index_in_text, char l_delimiter, char r_delimiter, Lisp_Object* first_elem) -> Lisp_Object* {
|
||||
proc parse_fancy_delimiter(char* text, u32* index_in_text, char l_delimiter, char r_delimiter, Lisp_Object* first_elem) -> Lisp_Object* {
|
||||
profile_this();
|
||||
if (text[*index_in_text] != l_delimiter) {
|
||||
create_parsing_error("a fancy cannot be parsed here");
|
||||
@@ -83,8 +83,8 @@ namespace Slime::Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc get_atom_text_length(char* text, int* index_in_text) -> int {
|
||||
int atom_length = 0;
|
||||
proc get_atom_text_length(char* text, u32* index_in_text) -> u32 {
|
||||
u32 atom_length = 0;
|
||||
while (text[*index_in_text+atom_length] != ' ' &&
|
||||
text[*index_in_text+atom_length] != ')' &&
|
||||
text[*index_in_text+atom_length] != '(' &&
|
||||
@@ -102,26 +102,26 @@ namespace Slime::Parser {
|
||||
return atom_length;
|
||||
}
|
||||
|
||||
proc parse_number(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc parse_number(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
Lisp_Object* ret;
|
||||
try ret = Memory::create_lisp_object(0.0);
|
||||
|
||||
sscanf(text+*index_in_text, "%lf", &ret->value.number);
|
||||
|
||||
int atom_length = get_atom_text_length(text, index_in_text);
|
||||
u32 atom_length = get_atom_text_length(text, index_in_text);
|
||||
step_char(text, index_in_text, atom_length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc parse_symbol_or_keyword(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc parse_symbol_or_keyword(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
bool keyword = false;
|
||||
if (text[*index_in_text] == ':') {
|
||||
keyword = true;
|
||||
step_char(text, index_in_text);
|
||||
}
|
||||
|
||||
int atom_length = get_atom_text_length(text, index_in_text);
|
||||
u32 atom_length = get_atom_text_length(text, index_in_text);
|
||||
char orig = text[*index_in_text+atom_length];
|
||||
text[*index_in_text+atom_length] = '\0';
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace Slime::Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc parse_string(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc parse_string(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
// the first character is the '"'
|
||||
step_char(text, index_in_text);
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace Slime::Parser {
|
||||
}
|
||||
|
||||
// okay so the first letter was not actually closing the string...
|
||||
int string_length = 0;
|
||||
u32 string_length = 0;
|
||||
bool escaping = false;
|
||||
while (escaping || text[*index_in_text+string_length] != '"') {
|
||||
if (escaping) {
|
||||
@@ -181,7 +181,7 @@ namespace Slime::Parser {
|
||||
// NOTE(Felix): Tactic: Through unescaping the string will
|
||||
// only get shorter, so we replace it inplace and later jump
|
||||
// to the original end of the string.
|
||||
int new_len;
|
||||
u32 new_len;
|
||||
try new_len = unescape_string(text+(*index_in_text));
|
||||
|
||||
String string = Memory::create_string("", new_len);
|
||||
@@ -201,7 +201,7 @@ namespace Slime::Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc parse_atom(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc parse_atom(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
profile_this();
|
||||
Lisp_Object* ret;
|
||||
// numbers
|
||||
@@ -232,7 +232,7 @@ namespace Slime::Parser {
|
||||
|
||||
|
||||
|
||||
proc parse_list(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc parse_list(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
profile_this();
|
||||
if (text[*index_in_text] != '(') {
|
||||
create_parsing_error("a list cannot be parsed here");
|
||||
@@ -283,7 +283,7 @@ namespace Slime::Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc maybe_expand_short_form(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc maybe_expand_short_form(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
profile_this();
|
||||
Lisp_Object* vector_sym = Memory::get_symbol("vector");
|
||||
Lisp_Object* hash_map_sym = Memory::get_symbol("hash-map");
|
||||
@@ -340,7 +340,7 @@ namespace Slime::Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc parse_expression(char* text, int* index_in_text) -> Lisp_Object* {
|
||||
proc parse_expression(char* text, u32* index_in_text) -> Lisp_Object* {
|
||||
profile_this();
|
||||
Lisp_Object* ret;
|
||||
eat_until_code(text, index_in_text);
|
||||
@@ -378,7 +378,7 @@ namespace Slime::Parser {
|
||||
parser_line = 1;
|
||||
parser_col = 1;
|
||||
|
||||
int index_in_text = 0;
|
||||
u32 index_in_text = 0;
|
||||
Lisp_Object* ret;
|
||||
try ret = parse_expression(text, &index_in_text);
|
||||
return ret;
|
||||
@@ -394,7 +394,7 @@ namespace Slime::Parser {
|
||||
Array_List<Lisp_Object*>* program = (Array_List<Lisp_Object*>*)malloc(sizeof(Array_List<Lisp_Object*>));
|
||||
program->alloc();
|
||||
|
||||
int index_in_text = 0;
|
||||
u32 index_in_text = 0;
|
||||
Lisp_Object* parsed;
|
||||
|
||||
eat_until_code(text, &index_in_text);
|
||||
|
||||
+9
-9
@@ -1,7 +1,7 @@
|
||||
namespace Slime {
|
||||
|
||||
inline proc get_cwd() -> char* {
|
||||
const int buf_size = 2048;
|
||||
const u32 buf_size = 2048;
|
||||
char* res = (char*)malloc(buf_size * sizeof(char));
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -23,9 +23,9 @@ namespace Slime {
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||
s32 vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||
// _vscprintf tells you how big the buffer needs to be
|
||||
int len = _vscprintf(fmt, ap);
|
||||
s32 len = _vscprintf(fmt, ap);
|
||||
if (len == -1) {
|
||||
return -1;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace Slime {
|
||||
return -1;
|
||||
}
|
||||
// _vsprintf_s is the "secure" version of vsprintf
|
||||
int r = vsprintf_s(str, len + 1, fmt, ap);
|
||||
s32 r = vsprintf_s(str, len + 1, fmt, ap);
|
||||
if (r == -1) {
|
||||
free(str);
|
||||
return -1;
|
||||
@@ -44,10 +44,10 @@ namespace Slime {
|
||||
return r;
|
||||
}
|
||||
|
||||
int asprintf(char **strp, const char *fmt, ...) {
|
||||
s32 asprintf(char **strp, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int r = vasprintf(strp, fmt, ap);
|
||||
s32 r = vasprintf(strp, fmt, ap);
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
@@ -91,8 +91,8 @@ namespace Slime {
|
||||
else {
|
||||
// remove the exe name, so we are only left with the path
|
||||
|
||||
int index_in_path = -1;
|
||||
int last_backslash = -1;
|
||||
s32 index_in_path = -1;
|
||||
s32 last_backslash = -1;
|
||||
|
||||
char c;
|
||||
while ((c = path[++index_in_path]) != '\0') {
|
||||
@@ -121,7 +121,7 @@ namespace Slime {
|
||||
used = readlink("/proc/self/exe", path, size);
|
||||
|
||||
if (used == -1) {
|
||||
const int saved_errno = errno;
|
||||
const s32 saved_errno = errno;
|
||||
free(path);
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
|
||||
+7
-7
@@ -66,14 +66,14 @@ namespace Slime {
|
||||
};
|
||||
|
||||
struct String {
|
||||
int length;
|
||||
u32 length;
|
||||
char* data;
|
||||
};
|
||||
|
||||
struct Source_Code_Location {
|
||||
String file;
|
||||
int line;
|
||||
int column;
|
||||
u32 line;
|
||||
u32 column;
|
||||
};
|
||||
|
||||
struct Pair {
|
||||
@@ -82,7 +82,7 @@ namespace Slime {
|
||||
};
|
||||
|
||||
struct Vector {
|
||||
int length;
|
||||
u32 length;
|
||||
Lisp_Object* data;
|
||||
};
|
||||
|
||||
@@ -126,12 +126,12 @@ namespace Slime {
|
||||
} body;
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
// #pragma pack(1)
|
||||
struct Lisp_Object {
|
||||
Lisp_Object_Type type;
|
||||
union value {
|
||||
String symbol; // used for symbols and keywords
|
||||
double number;
|
||||
f64 number;
|
||||
String string;
|
||||
Pair pair;
|
||||
Vector vector;
|
||||
@@ -141,7 +141,7 @@ namespace Slime {
|
||||
Hash_Map<Lisp_Object*, Lisp_Object*>* hashMap;
|
||||
} value;
|
||||
};
|
||||
#pragma options align=reset
|
||||
// #pragma options align=reset
|
||||
struct Error {
|
||||
Lisp_Object* position;
|
||||
// type has to be a keyword
|
||||
|
||||
+26
-27
@@ -1,8 +1,7 @@
|
||||
namespace Slime {
|
||||
typedef s32 testresult;
|
||||
|
||||
#define epsilon 2.2204460492503131E-16
|
||||
|
||||
#define testresult int
|
||||
#define pass 1
|
||||
#define fail 0
|
||||
|
||||
@@ -46,15 +45,15 @@ namespace Slime {
|
||||
return fail; \
|
||||
} \
|
||||
|
||||
#define assert_equal_double(variable, value) \
|
||||
if (fabs((double)variable - (double)value) > epsilon) { \
|
||||
print_assert_equal_fail(variable, value, double, "%f"); \
|
||||
#define assert_equal_f64(variable, value) \
|
||||
if (fabs((f64)variable - (f64)value) > epsilon) { \
|
||||
print_assert_equal_fail(variable, value, f64, "%f"); \
|
||||
return fail; \
|
||||
}
|
||||
|
||||
#define assert_not_equal_double(variable, value) \
|
||||
if (fabs((double)variable - (double)value) <= epsilon) { \
|
||||
print_assert_not_equal_fail(variable, value, double, "%f"); \
|
||||
#define assert_not_equal_f64(variable, value) \
|
||||
if (fabs((f64)variable - (f64)value) <= epsilon) { \
|
||||
print_assert_not_equal_fail(variable, value, f64, "%f"); \
|
||||
return fail; \
|
||||
}
|
||||
|
||||
@@ -87,7 +86,7 @@ namespace Slime {
|
||||
} \
|
||||
else { \
|
||||
result = false; \
|
||||
for(int i = -1; i < 70; ++i) \
|
||||
for(s32 i = -1; i < 70; ++i) \
|
||||
fputs((i%3==1)? "." : " ", stdout); \
|
||||
fputs(console_red "failed\n" console_normal, stdout); \
|
||||
if(Globals::error) { \
|
||||
@@ -105,7 +104,7 @@ namespace Slime {
|
||||
} \
|
||||
else { \
|
||||
result = false; \
|
||||
for(int i = -1; i < 70; ++i) \
|
||||
for(s32 i = -1; i < 70; ++i) \
|
||||
fputs((i%3==1)? "." : " ", stdout); \
|
||||
fputs(console_red "failed\n" console_normal, stdout); \
|
||||
if(Globals::error) { \
|
||||
@@ -116,7 +115,7 @@ namespace Slime {
|
||||
|
||||
proc test_array_lists_adding_and_removing() -> testresult {
|
||||
// test adding and removing
|
||||
Array_List<int> list;
|
||||
Array_List<s32> list;
|
||||
list.alloc();
|
||||
defer {
|
||||
list.dealloc();
|
||||
@@ -146,7 +145,7 @@ namespace Slime {
|
||||
|
||||
proc test_array_lists_sorting() -> testresult {
|
||||
// test adding and removing
|
||||
Array_List<int> list;
|
||||
Array_List<s32> list;
|
||||
list.alloc();
|
||||
defer {
|
||||
list.dealloc();
|
||||
@@ -184,7 +183,7 @@ namespace Slime {
|
||||
}
|
||||
|
||||
proc test_array_lists_searching() -> testresult {
|
||||
Array_List<int> list;
|
||||
Array_List<s32> list;
|
||||
list.alloc();
|
||||
defer {
|
||||
list.dealloc();
|
||||
@@ -195,7 +194,7 @@ namespace Slime {
|
||||
list.append(3);
|
||||
list.append(4);
|
||||
|
||||
int index = list.sorted_find(3);
|
||||
s32 index = list.sorted_find(3);
|
||||
assert_equal_int(index, 2);
|
||||
|
||||
index = list.sorted_find(1);
|
||||
@@ -208,7 +207,7 @@ namespace Slime {
|
||||
}
|
||||
|
||||
proc test_parse_atom() -> testresult {
|
||||
int index_in_text = 0;
|
||||
u32 index_in_text = 0;
|
||||
char string[] =
|
||||
"123 -1.23e-2 " // numbers
|
||||
"\"asd\" " // strings
|
||||
@@ -219,13 +218,13 @@ namespace Slime {
|
||||
Lisp_Object* result = Parser::parse_atom(string, &index_in_text);
|
||||
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 123);
|
||||
assert_equal_f64(result->value.number, 123);
|
||||
|
||||
++index_in_text;
|
||||
|
||||
result = Parser::parse_atom(string, &index_in_text);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, -1.23e-2);
|
||||
assert_equal_f64(result->value.number, -1.23e-2);
|
||||
|
||||
// test strings
|
||||
++index_in_text;
|
||||
@@ -264,7 +263,7 @@ namespace Slime {
|
||||
}
|
||||
|
||||
proc test_parse_expression() -> testresult {
|
||||
int index_in_text = 0;
|
||||
u32 index_in_text = 0;
|
||||
char string[] = "(fun + 12)";
|
||||
|
||||
Lisp_Object* result = Parser::parse_expression(string, &index_in_text);
|
||||
@@ -284,7 +283,7 @@ namespace Slime {
|
||||
|
||||
assert_equal_type(result, Lisp_Object_Type::Pair);
|
||||
assert_equal_type(result->value.pair.first, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.pair.first->value.number, 12);
|
||||
assert_equal_f64(result->value.pair.first->value.number, 12);
|
||||
|
||||
result = result->value.pair.rest;
|
||||
|
||||
@@ -327,7 +326,7 @@ namespace Slime {
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 14);
|
||||
assert_equal_f64(result->value.number, 14);
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -342,7 +341,7 @@ namespace Slime {
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 6);
|
||||
assert_equal_f64(result->value.number, 6);
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -357,7 +356,7 @@ namespace Slime {
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 40);
|
||||
assert_equal_f64(result->value.number, 40);
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -372,7 +371,7 @@ namespace Slime {
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 5);
|
||||
assert_equal_f64(result->value.number, 5);
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -387,7 +386,7 @@ namespace Slime {
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 4);
|
||||
assert_equal_f64(result->value.number, 4);
|
||||
|
||||
char exp_string2[] = "(if () 4 5)";
|
||||
expression = Parser::parse_single_expression(exp_string2);
|
||||
@@ -396,7 +395,7 @@ namespace Slime {
|
||||
assert_no_error();
|
||||
assert_not_null(result);
|
||||
assert_equal_type(result, Lisp_Object_Type::Number);
|
||||
assert_equal_double(result->value.number, 5);
|
||||
assert_equal_f64(result->value.number, 5);
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -650,8 +649,8 @@ namespace Slime {
|
||||
#undef assert_no_error
|
||||
#undef assert_equal_int
|
||||
#undef assert_not_equal_int
|
||||
#undef assert_equal_double
|
||||
#undef assert_not_equal_double
|
||||
#undef assert_equal_f64
|
||||
#undef assert_not_equal_f64
|
||||
#undef assert_equal_string
|
||||
#undef assert_equal_type
|
||||
#undef assert_null
|
||||
|
||||
Reference in New Issue
Block a user