Implemented `mutate'
This commit is contained in:
@@ -124,6 +124,7 @@ typedef enum {
|
||||
Built_In_Rest,
|
||||
Built_In_Load,
|
||||
Built_In_Define,
|
||||
Built_In_Mutate,
|
||||
Built_In_Lambda,
|
||||
Built_In_Eval,
|
||||
Built_In_Quote,
|
||||
@@ -159,6 +160,7 @@ char* Built_In_Name_to_string(Built_In_Name name) {
|
||||
case Built_In_List: return "list";
|
||||
case Built_In_Load: return "load";
|
||||
case Built_In_Multiplication: return "*";
|
||||
case Built_In_Mutate: return "mutate";
|
||||
case Built_In_Not: return "not";
|
||||
case Built_In_Or: return "or";
|
||||
case Built_In_Pair: return "pair";
|
||||
@@ -261,6 +263,7 @@ Ast_Node* create_ast_node_built_in_function(char* name) {
|
||||
else if (string_equal(name, "rest")) type = Built_In_Rest;
|
||||
else if (string_equal(name, "load")) type = Built_In_Load;
|
||||
else if (string_equal(name, "define")) type = Built_In_Define;
|
||||
else if (string_equal(name, "mutate")) type = Built_In_Mutate;
|
||||
else if (string_equal(name, "lambda")) type = Built_In_Lambda;
|
||||
else if (string_equal(name, "eval")) type = Built_In_Eval;
|
||||
else if (string_equal(name, "quote")) type = Built_In_Quote;
|
||||
|
||||
+18
-3
@@ -595,10 +595,25 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) {
|
||||
case Built_In_Equal: {
|
||||
return built_in_equals(evaluated_arguments);
|
||||
}
|
||||
case Built_In_Load: {
|
||||
try {
|
||||
arguments_length = list_length(arguments);
|
||||
case Built_In_Mutate: {
|
||||
if (arguments_length != 2)
|
||||
report_error(Error_Type_Wrong_Number_Of_Arguments);
|
||||
|
||||
if (arguments->value.pair->first->type == Ast_Node_Type_Nil ||
|
||||
arguments->value.pair->first->type == Ast_Node_Type_Keyword)
|
||||
{
|
||||
report_error(Error_Type_Type_Missmatch);
|
||||
}
|
||||
|
||||
Ast_Node* target = evaluated_arguments->value.pair->first;
|
||||
Ast_Node* source = evaluated_arguments->value.pair->rest->value.pair->first;
|
||||
|
||||
target->type = source->type;
|
||||
target->value = source->value;
|
||||
|
||||
return target;
|
||||
}
|
||||
case Built_In_Load: {
|
||||
if (arguments_length != 1)
|
||||
report_error(Error_Type_Wrong_Number_Of_Arguments);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user