platform independent duplicacte_c_string
This commit is contained in:
@@ -23,7 +23,7 @@ rem call ..\timecmd clang-cl ../src/main.cpp -o %exeName% /O2 /std:c++latest /W3
|
|||||||
|
|
||||||
if %errorlevel% == 0 (
|
if %errorlevel% == 0 (
|
||||||
echo.
|
echo.
|
||||||
echo ---- Running Tests ----
|
echo -------- Running Tests --------
|
||||||
echo.
|
echo.
|
||||||
call slime.exe --run-tests
|
call slime.exe --run-tests
|
||||||
) else (
|
) else (
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ namespace Slime {
|
|||||||
void print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout);
|
void print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout);
|
||||||
void print_environment(Environment*);
|
void print_environment(Environment*);
|
||||||
|
|
||||||
|
inline char* duplicate_c_string(const char* str);
|
||||||
|
|
||||||
bool run_all_tests();
|
bool run_all_tests();
|
||||||
|
|
||||||
inline Environment* get_root_environment();
|
inline Environment* get_root_environment();
|
||||||
|
|||||||
+22
-22
@@ -324,13 +324,13 @@ namespace Slime {
|
|||||||
string_builder.dealloc();
|
string_builder.dealloc();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!node) return _strdup("<nullptr>");
|
if (!node) return duplicate_c_string("<nullptr>");
|
||||||
|
|
||||||
switch (node->type) {
|
switch (node->type) {
|
||||||
case (Lisp_Object_Type::Nil): return _strdup("()");
|
case (Lisp_Object_Type::Nil): return duplicate_c_string("()");
|
||||||
case (Lisp_Object_Type::T): return _strdup("t");
|
case (Lisp_Object_Type::T): return duplicate_c_string("t");
|
||||||
case (Lisp_Object_Type::Continuation): return _strdup("[continuation]");
|
case (Lisp_Object_Type::Continuation): return duplicate_c_string("[continuation]");
|
||||||
case (Lisp_Object_Type::Pointer): return _strdup("[pointer]");
|
case (Lisp_Object_Type::Pointer): return duplicate_c_string("[pointer]");
|
||||||
case (Lisp_Object_Type::Number): {
|
case (Lisp_Object_Type::Number): {
|
||||||
if (abs(node->value.number - (s32)node->value.number) < 0.000001f)
|
if (abs(node->value.number - (s32)node->value.number) < 0.000001f)
|
||||||
asprintf(&temp, "%d", (s32)node->value.number);
|
asprintf(&temp, "%d", (s32)node->value.number);
|
||||||
@@ -370,18 +370,18 @@ namespace Slime {
|
|||||||
free(escaped);
|
free(escaped);
|
||||||
return temp;
|
return temp;
|
||||||
} else
|
} else
|
||||||
return _strdup(Memory::get_c_str(node->value.string));
|
return duplicate_c_string(Memory::get_c_str(node->value.string));
|
||||||
} break;
|
} break;
|
||||||
case (Lisp_Object_Type::Vector): {
|
case (Lisp_Object_Type::Vector): {
|
||||||
|
|
||||||
string_builder.append(_strdup("["));
|
string_builder.append(duplicate_c_string("["));
|
||||||
if (node->value.vector.length > 0)
|
if (node->value.vector.length > 0)
|
||||||
string_builder.append(lisp_object_to_string(node->value.vector.data, print_repr));
|
string_builder.append(lisp_object_to_string(node->value.vector.data, print_repr));
|
||||||
for (u32 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(duplicate_c_string(" "));
|
||||||
string_builder.append(lisp_object_to_string(node->value.vector.data+i, print_repr));
|
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);
|
temp = string_buider_to_string(string_builder);
|
||||||
for (auto str : string_builder) {
|
for (auto str : string_builder) {
|
||||||
free(str);
|
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::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::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;
|
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 {
|
} else {
|
||||||
switch (node->value.function->type.c_function_type) {
|
switch (node->value.function->type.c_function_type) {
|
||||||
case C_Function_Type::cFunction: asprintf(&temp, "[c-function]"); break;
|
case C_Function_Type::cFunction: asprintf(&temp, "[c-function]"); break;
|
||||||
case C_Function_Type::cSpecial: asprintf(&temp, "[c-special]"); break;
|
case C_Function_Type::cSpecial: asprintf(&temp, "[c-special]"); break;
|
||||||
case C_Function_Type::cMacro: asprintf(&temp, "[c-macro]"); break;
|
case C_Function_Type::cMacro: asprintf(&temp, "[c-macro]"); break;
|
||||||
default: return _strdup("[c-??]");
|
default: return duplicate_c_string("[c-??]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
} else {
|
} else {
|
||||||
switch (node->value.function->type.lisp_function_type) {
|
switch (node->value.function->type.lisp_function_type) {
|
||||||
case Lisp_Function_Type::Lambda: return _strdup("[lambda]");
|
case Lisp_Function_Type::Lambda: return duplicate_c_string("[lambda]");
|
||||||
case Lisp_Function_Type::Macro: return _strdup("[macro]");
|
case Lisp_Function_Type::Macro: return duplicate_c_string("[macro]");
|
||||||
default: return _strdup("[??]");
|
default: return duplicate_c_string("[??]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@@ -446,11 +446,11 @@ namespace Slime {
|
|||||||
if (symbol == quote_sym || symbol == unquote_sym || symbol == unquote_splicing_sym)
|
if (symbol == quote_sym || symbol == unquote_sym || symbol == unquote_splicing_sym)
|
||||||
{
|
{
|
||||||
if (symbol == quote_sym)
|
if (symbol == quote_sym)
|
||||||
string_builder.append(_strdup("\'"));
|
string_builder.append(duplicate_c_string("\'"));
|
||||||
else if (symbol == unquote_sym)
|
else if (symbol == unquote_sym)
|
||||||
string_builder.append(_strdup(","));
|
string_builder.append(duplicate_c_string(","));
|
||||||
else if (symbol == unquote_splicing_sym)
|
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_type(head->value.pair.rest, Lisp_Object_Type::Pair);
|
||||||
assert("The list must end here.",
|
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));
|
string_builder.append(lisp_object_to_string(head->value.pair.rest->value.pair.first, print_repr));
|
||||||
return string_buider_to_string(string_builder);
|
return string_buider_to_string(string_builder);
|
||||||
} else if (symbol == quasiquote_sym) {
|
} 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);
|
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));
|
string_builder.append(lisp_object_to_string(head->value.pair.rest->value.pair.first, print_repr));
|
||||||
return string_buider_to_string(string_builder);
|
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
|
// NOTE(Felix): We could do a while true here, however in case
|
||||||
// we want to print a broken list (for logging the error) we
|
// we want to print a broken list (for logging the error) we
|
||||||
@@ -477,15 +477,15 @@ namespace Slime {
|
|||||||
head = head->value.pair.rest;
|
head = head->value.pair.rest;
|
||||||
if (!head) break;
|
if (!head) break;
|
||||||
if (head->type != Lisp_Object_Type::Pair) break;
|
if (head->type != Lisp_Object_Type::Pair) break;
|
||||||
string_builder.append(_strdup(" "));
|
string_builder.append(duplicate_c_string(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (head && head != Memory::nil) {
|
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(lisp_object_to_string(head, print_repr));
|
||||||
}
|
}
|
||||||
|
|
||||||
string_builder.append(_strdup(")"));
|
string_builder.append(duplicate_c_string(")"));
|
||||||
|
|
||||||
return string_buider_to_string(string_builder);
|
return string_buider_to_string(string_builder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ namespace Slime {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline proc duplicate_c_string(const char* str) -> char* {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
return _strdup(str);
|
||||||
|
#else
|
||||||
|
return strdup(str);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
s32 vasprintf(char **strp, const char *fmt, va_list ap) {
|
s32 vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||||
|
|||||||
@@ -37,6 +37,11 @@
|
|||||||
CLOSED: [2020-03-31 Di 11:58]
|
CLOSED: [2020-03-31 Di 11:58]
|
||||||
* DONE update header files
|
* DONE update header files
|
||||||
CLOSED: [2020-03-31 Di 11:58]
|
CLOSED: [2020-03-31 Di 11:58]
|
||||||
|
* TODO Make specific SLIME macros
|
||||||
|
- =SLIME_WINDOWS=
|
||||||
|
- =SLIME_DEBUG=
|
||||||
|
- =SLIME_RELEASE=
|
||||||
|
- =SLIME_DISTRIBUTE=
|
||||||
* TODO assert list length for arguemns of macros
|
* TODO assert list length for arguemns of macros
|
||||||
because all the args are in last of pcs, so we can assert length
|
because all the args are in last of pcs, so we can assert length
|
||||||
* TODO rename cs to stack
|
* TODO rename cs to stack
|
||||||
|
|||||||
Reference in New Issue
Block a user