Getting the manual going
This commit is contained in:
+14
-2
@@ -230,8 +230,11 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
defun("-", cLambda {
|
||||
int arguments_length;
|
||||
try arguments = eval_arguments(arguments, env, &arguments_length);
|
||||
try assert_type(arguments->value.pair.first, Lisp_Object_Type::Number);
|
||||
|
||||
if (arguments_length == 0)
|
||||
return Memory::create_lisp_object_number(0);
|
||||
|
||||
try assert_type(arguments->value.pair.first, Lisp_Object_Type::Number);
|
||||
double difference = arguments->value.pair.first->value.number;
|
||||
|
||||
if (arguments_length == 1) {
|
||||
@@ -250,6 +253,11 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
defun("*", cLambda {
|
||||
int arguments_length;
|
||||
try arguments = eval_arguments(arguments, env, &arguments_length);
|
||||
|
||||
if (arguments_length == 0) {
|
||||
return Memory::create_lisp_object_number(1);
|
||||
}
|
||||
|
||||
try assert_type(arguments->value.pair.first, Lisp_Object_Type::Number);
|
||||
|
||||
double product = arguments->value.pair.first->value.number;
|
||||
@@ -266,6 +274,11 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
defun("/", cLambda {
|
||||
int arguments_length;
|
||||
try arguments = eval_arguments(arguments, env, &arguments_length);
|
||||
|
||||
if (arguments_length == 0) {
|
||||
return Memory::create_lisp_object_number(1);
|
||||
}
|
||||
|
||||
try assert_type(arguments->value.pair.first, Lisp_Object_Type::Number);
|
||||
|
||||
double quotient = arguments->value.pair.first->value.number;
|
||||
@@ -890,7 +903,6 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
|
||||
});
|
||||
defun("copy", cLambda {
|
||||
|
||||
// TODO(Felix): if we are copying string nodes, then
|
||||
// shouldn't the string itself also get copied??
|
||||
try evaluated_arguments = eval_arguments(arguments, env, &arguments_length);
|
||||
|
||||
+1
-1
@@ -462,7 +462,7 @@ proc interprete_file (char* file_name) -> Lisp_Object* {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
print(result);
|
||||
// print(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+35
-1
@@ -243,7 +243,12 @@ proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) ->
|
||||
switch (Memory::get_type(node)) {
|
||||
case (Lisp_Object_Type::Nil): fputs("()", file); break;
|
||||
case (Lisp_Object_Type::T): fputs("t", file); break;
|
||||
case (Lisp_Object_Type::Number): fprintf(file, "%f", node->value.number); break;
|
||||
case (Lisp_Object_Type::Number): {
|
||||
if (abs(node->value.number - (int)node->value.number) < 0.000001f)
|
||||
fprintf(file, "%d", (int)node->value.number);
|
||||
else
|
||||
fprintf(file, "%f", node->value.number);
|
||||
} break;
|
||||
case (Lisp_Object_Type::Keyword): fputs(":", file); // NOTE(Felix): intentionall fallthough
|
||||
case (Lisp_Object_Type::Symbol): fprintf(file, "%s", Memory::get_c_str(node->value.symbol.identifier)); break;
|
||||
case (Lisp_Object_Type::CFunction): fputs("[C-function]", file); break;
|
||||
@@ -268,6 +273,35 @@ proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) ->
|
||||
} break;
|
||||
case (Lisp_Object_Type::Pair): {
|
||||
Lisp_Object* head = node;
|
||||
|
||||
// first check if it is a quotation form, in that case we want
|
||||
// to print it prettier
|
||||
if (Memory::get_type(head->value.pair.first) == Lisp_Object_Type::Symbol) {
|
||||
String* identifier = head->value.pair.first->value.symbol.identifier;
|
||||
|
||||
// TODO(Felix): Lisp_Node* symbol = head->value.pair.first;
|
||||
// TODO(Felix): if (symbol == Memory::get_or_create_symbol("quote"))
|
||||
if (string_equal(identifier, "quote") ||
|
||||
string_equal(identifier, "unquote"))
|
||||
{
|
||||
putc((string_equal(identifier, "quote"))
|
||||
? '\''
|
||||
: ',', file);
|
||||
|
||||
assert_type(head->value.pair.rest, Lisp_Object_Type::Pair);
|
||||
assert(head->value.pair.rest->value.pair.rest == Memory::nil);
|
||||
|
||||
print(head->value.pair.rest->value.pair.first, print_quotes, file);
|
||||
break;
|
||||
}
|
||||
else if (string_equal(identifier, "quasiquote")) {
|
||||
putc('`', file);
|
||||
assert_type(head->value.pair.rest, Lisp_Object_Type::Pair);
|
||||
print(head->value.pair.rest->value.pair.first, print_quotes, file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
putc('(', file);
|
||||
|
||||
// NOTE(Felix): We cold do a while true here, however in case
|
||||
|
||||
Reference in New Issue
Block a user