platform independent duplicacte_c_string
This commit is contained in:
@@ -21,6 +21,8 @@ namespace Slime {
|
||||
void print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout);
|
||||
void print_environment(Environment*);
|
||||
|
||||
inline char* duplicate_c_string(const char* str);
|
||||
|
||||
bool run_all_tests();
|
||||
|
||||
inline Environment* get_root_environment();
|
||||
|
||||
+22
-22
@@ -324,13 +324,13 @@ namespace Slime {
|
||||
string_builder.dealloc();
|
||||
};
|
||||
|
||||
if (!node) return _strdup("<nullptr>");
|
||||
if (!node) return duplicate_c_string("<nullptr>");
|
||||
|
||||
switch (node->type) {
|
||||
case (Lisp_Object_Type::Nil): return _strdup("()");
|
||||
case (Lisp_Object_Type::T): return _strdup("t");
|
||||
case (Lisp_Object_Type::Continuation): return _strdup("[continuation]");
|
||||
case (Lisp_Object_Type::Pointer): return _strdup("[pointer]");
|
||||
case (Lisp_Object_Type::Nil): return duplicate_c_string("()");
|
||||
case (Lisp_Object_Type::T): return duplicate_c_string("t");
|
||||
case (Lisp_Object_Type::Continuation): return duplicate_c_string("[continuation]");
|
||||
case (Lisp_Object_Type::Pointer): return duplicate_c_string("[pointer]");
|
||||
case (Lisp_Object_Type::Number): {
|
||||
if (abs(node->value.number - (s32)node->value.number) < 0.000001f)
|
||||
asprintf(&temp, "%d", (s32)node->value.number);
|
||||
@@ -370,18 +370,18 @@ namespace Slime {
|
||||
free(escaped);
|
||||
return temp;
|
||||
} else
|
||||
return _strdup(Memory::get_c_str(node->value.string));
|
||||
return duplicate_c_string(Memory::get_c_str(node->value.string));
|
||||
} break;
|
||||
case (Lisp_Object_Type::Vector): {
|
||||
|
||||
string_builder.append(_strdup("["));
|
||||
string_builder.append(duplicate_c_string("["));
|
||||
if (node->value.vector.length > 0)
|
||||
string_builder.append(lisp_object_to_string(node->value.vector.data, print_repr));
|
||||
for (u32 i = 1; i < node->value.vector.length; ++i) {
|
||||
string_builder.append(_strdup(" "));
|
||||
string_builder.append(duplicate_c_string(" "));
|
||||
string_builder.append(lisp_object_to_string(node->value.vector.data+i, print_repr));
|
||||
}
|
||||
string_builder.append(_strdup("]"));
|
||||
string_builder.append(duplicate_c_string("]"));
|
||||
temp = string_buider_to_string(string_builder);
|
||||
for (auto str : string_builder) {
|
||||
free(str);
|
||||
@@ -405,22 +405,22 @@ namespace Slime {
|
||||
case C_Function_Type::cFunction: asprintf(&temp, "[c-function %s]",name->value.symbol.data); break;
|
||||
case C_Function_Type::cSpecial: asprintf(&temp, "[c-special %s]", name->value.symbol.data); break;
|
||||
case C_Function_Type::cMacro: asprintf(&temp, "[c-macro %s]", name->value.symbol.data); break;
|
||||
default: return _strdup("[c-??]");
|
||||
default: return duplicate_c_string("[c-??]");
|
||||
}
|
||||
} else {
|
||||
switch (node->value.function->type.c_function_type) {
|
||||
case C_Function_Type::cFunction: asprintf(&temp, "[c-function]"); break;
|
||||
case C_Function_Type::cSpecial: asprintf(&temp, "[c-special]"); break;
|
||||
case C_Function_Type::cMacro: asprintf(&temp, "[c-macro]"); break;
|
||||
default: return _strdup("[c-??]");
|
||||
default: return duplicate_c_string("[c-??]");
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
} else {
|
||||
switch (node->value.function->type.lisp_function_type) {
|
||||
case Lisp_Function_Type::Lambda: return _strdup("[lambda]");
|
||||
case Lisp_Function_Type::Macro: return _strdup("[macro]");
|
||||
default: return _strdup("[??]");
|
||||
case Lisp_Function_Type::Lambda: return duplicate_c_string("[lambda]");
|
||||
case Lisp_Function_Type::Macro: return duplicate_c_string("[macro]");
|
||||
default: return duplicate_c_string("[??]");
|
||||
}
|
||||
}
|
||||
} break;
|
||||
@@ -446,11 +446,11 @@ namespace Slime {
|
||||
if (symbol == quote_sym || symbol == unquote_sym || symbol == unquote_splicing_sym)
|
||||
{
|
||||
if (symbol == quote_sym)
|
||||
string_builder.append(_strdup("\'"));
|
||||
string_builder.append(duplicate_c_string("\'"));
|
||||
else if (symbol == unquote_sym)
|
||||
string_builder.append(_strdup(","));
|
||||
string_builder.append(duplicate_c_string(","));
|
||||
else if (symbol == unquote_splicing_sym)
|
||||
string_builder.append(_strdup(",@"));
|
||||
string_builder.append(duplicate_c_string(",@"));
|
||||
|
||||
assert_type(head->value.pair.rest, Lisp_Object_Type::Pair);
|
||||
assert("The list must end here.",
|
||||
@@ -459,7 +459,7 @@ namespace Slime {
|
||||
string_builder.append(lisp_object_to_string(head->value.pair.rest->value.pair.first, print_repr));
|
||||
return string_buider_to_string(string_builder);
|
||||
} else if (symbol == quasiquote_sym) {
|
||||
string_builder.append(_strdup("`"));
|
||||
string_builder.append(duplicate_c_string("`"));
|
||||
assert_type(head->value.pair.rest, Lisp_Object_Type::Pair);
|
||||
string_builder.append(lisp_object_to_string(head->value.pair.rest->value.pair.first, print_repr));
|
||||
return string_buider_to_string(string_builder);
|
||||
@@ -467,7 +467,7 @@ namespace Slime {
|
||||
}
|
||||
}
|
||||
|
||||
string_builder.append(_strdup("("));
|
||||
string_builder.append(duplicate_c_string("("));
|
||||
|
||||
// NOTE(Felix): We could do a while true here, however in case
|
||||
// we want to print a broken list (for logging the error) we
|
||||
@@ -477,15 +477,15 @@ namespace Slime {
|
||||
head = head->value.pair.rest;
|
||||
if (!head) break;
|
||||
if (head->type != Lisp_Object_Type::Pair) break;
|
||||
string_builder.append(_strdup(" "));
|
||||
string_builder.append(duplicate_c_string(" "));
|
||||
}
|
||||
|
||||
if (head && head != Memory::nil) {
|
||||
string_builder.append(_strdup(" . "));
|
||||
string_builder.append(duplicate_c_string(" . "));
|
||||
string_builder.append(lisp_object_to_string(head, print_repr));
|
||||
}
|
||||
|
||||
string_builder.append(_strdup(")"));
|
||||
string_builder.append(duplicate_c_string(")"));
|
||||
|
||||
return string_buider_to_string(string_builder);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,14 @@ namespace Slime {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline proc duplicate_c_string(const char* str) -> char* {
|
||||
#ifdef _MSC_VER
|
||||
return _strdup(str);
|
||||
#else
|
||||
return strdup(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
s32 vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||
|
||||
Reference in New Issue
Block a user