|
|
|
@@ -366,6 +366,10 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
create_error(_type, node->sourceCodeLocation); \ |
|
|
|
return nullptr; \ |
|
|
|
} |
|
|
|
#define report_error_operator(_type) { \ |
|
|
|
create_error(_type, operator->sourceCodeLocation); \ |
|
|
|
return nullptr; \ |
|
|
|
} |
|
|
|
|
|
|
|
if (error) |
|
|
|
return nullptr; |
|
|
|
@@ -416,7 +420,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
} |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
print(arguments->value.pair->first); |
|
|
|
@@ -494,7 +498,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
} |
|
|
|
if (arguments_length == 0) |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
|
|
|
|
|
|
|
|
Function* function = new(Function); |
|
|
|
@@ -632,7 +636,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
} |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
bool truthy; |
|
|
|
try { |
|
|
|
@@ -648,7 +652,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
|
|
|
|
if (arguments_length < 2) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
Ast_Node* condition_part = arguments->value.pair->first; |
|
|
|
Ast_Node* condition; |
|
|
|
@@ -674,7 +678,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
} |
|
|
|
if (arguments_length != 2 && arguments_length != 3) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
Ast_Node* condition = arguments->value.pair->first; |
|
|
|
@@ -700,7 +704,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
case Built_In_Quote: { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
return arguments->value.pair->first; |
|
|
|
} |
|
|
|
@@ -709,7 +713,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
} |
|
|
|
if (arguments_length != 2) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
Ast_Node* try_part = arguments->value.pair->first; |
|
|
|
@@ -731,7 +735,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
arguments_length = list_length(arguments); |
|
|
|
} |
|
|
|
if (arguments_length != 2) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
Ast_Node* symbol = arguments->value.pair->first; |
|
|
|
@@ -804,7 +808,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Mutate: { |
|
|
|
if (arguments_length != 2) |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
|
|
|
|
if (evaluated_arguments->value.pair->first->type == Ast_Node_Type_Nil || |
|
|
|
evaluated_arguments->value.pair->first->type == Ast_Node_Type_Keyword) |
|
|
|
@@ -820,7 +824,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Copy: { |
|
|
|
if (arguments_length != 1) |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
|
|
|
|
if (evaluated_arguments->value.pair->first->type == Ast_Node_Type_Nil || |
|
|
|
evaluated_arguments->value.pair->first->type == Ast_Node_Type_Keyword) |
|
|
|
@@ -836,7 +840,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Load: { |
|
|
|
if (arguments_length != 1) |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
|
|
|
|
if (evaluated_arguments->value.pair->first->type != Ast_Node_Type_String) |
|
|
|
report_error(Error_Type_Type_Missmatch); |
|
|
|
@@ -850,13 +854,13 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Pair: { |
|
|
|
if (arguments_length != 2) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
return create_ast_node_pair(evaluated_arguments->value.pair->first, evaluated_arguments->value.pair->rest->value.pair->first); |
|
|
|
} |
|
|
|
case Built_In_First: { |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
if (evaluated_arguments->value.pair->first->type == Ast_Node_Type_Nil) |
|
|
|
return create_ast_node_nil(); |
|
|
|
@@ -867,7 +871,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Rest: { |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
if (evaluated_arguments->value.pair->first->type == Ast_Node_Type_Nil) |
|
|
|
return create_ast_node_nil(); |
|
|
|
@@ -878,7 +882,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Eval: { |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
Ast_Node* result; |
|
|
|
try { |
|
|
|
@@ -905,13 +909,13 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Error: { |
|
|
|
if (arguments_length != 0) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
report_error(Error_Type_Unknown_Error); |
|
|
|
} |
|
|
|
case Built_In_Print: { |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
print(evaluated_arguments->value.pair->first); |
|
|
|
/* printf("\n"); */ |
|
|
|
@@ -919,7 +923,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Read: { |
|
|
|
if (arguments_length > 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
if (arguments_length == 1) { |
|
|
|
@@ -934,7 +938,7 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
} |
|
|
|
case Built_In_Type: { |
|
|
|
if (arguments_length != 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
Ast_Node_Type type = evaluated_arguments->value.pair->first->type; |
|
|
|
@@ -945,18 +949,18 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) { |
|
|
|
return create_ast_node_keyword("dynamic-macro"); |
|
|
|
return create_ast_node_keyword("dynamic-function"); |
|
|
|
} |
|
|
|
case Ast_Node_Type_Keyword: return create_ast_node_keyword("keyword"); |
|
|
|
case Ast_Node_Type_Nil: return create_ast_node_keyword("nil"); |
|
|
|
case Ast_Node_Type_T: return create_ast_node_keyword("t"); |
|
|
|
case Ast_Node_Type_Number: return create_ast_node_keyword("number"); |
|
|
|
case Ast_Node_Type_Pair: return create_ast_node_keyword("pair"); |
|
|
|
case Ast_Node_Type_String: return create_ast_node_keyword("string"); |
|
|
|
case Ast_Node_Type_Symbol: return create_ast_node_keyword("symbol"); |
|
|
|
case Ast_Node_Type_Keyword: return create_ast_node_keyword("keyword"); |
|
|
|
case Ast_Node_Type_Nil: return create_ast_node_keyword("nil"); |
|
|
|
case Ast_Node_Type_T: return create_ast_node_keyword("t"); |
|
|
|
case Ast_Node_Type_Number: return create_ast_node_keyword("number"); |
|
|
|
case Ast_Node_Type_Pair: return create_ast_node_keyword("pair"); |
|
|
|
case Ast_Node_Type_String: return create_ast_node_keyword("string"); |
|
|
|
case Ast_Node_Type_Symbol: return create_ast_node_keyword("symbol"); |
|
|
|
} |
|
|
|
} |
|
|
|
case Built_In_Exit: { |
|
|
|
if (arguments_length > 1) { |
|
|
|
report_error(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
report_error_operator(Error_Type_Wrong_Number_Of_Arguments); |
|
|
|
} |
|
|
|
|
|
|
|
if (arguments_length == 1) { |
|
|
|
|