Implemented while
This commit is contained in:
@@ -156,6 +156,7 @@ typedef enum {
|
||||
Built_In_Rest,
|
||||
Built_In_Subtraction,
|
||||
Built_In_Type,
|
||||
Built_In_While,
|
||||
} Built_In_Name;
|
||||
|
||||
/**
|
||||
@@ -196,6 +197,7 @@ char* Built_In_Name_to_string(Built_In_Name name) {
|
||||
case Built_In_Rest: return "rest";
|
||||
case Built_In_Subtraction: return "-";
|
||||
case Built_In_Type: return "type";
|
||||
case Built_In_While: return "while";
|
||||
}
|
||||
|
||||
return "Built in string missing in Built_In_Name_to_string";
|
||||
@@ -311,6 +313,7 @@ Ast_Node* create_ast_node_built_in_function(char* name) {
|
||||
else if (string_equal(name, "read")) type = Built_In_Read;
|
||||
else if (string_equal(name, "rest")) type = Built_In_Rest;
|
||||
else if (string_equal(name, "type")) type = Built_In_Type;
|
||||
else if (string_equal(name, "while")) type = Built_In_While;
|
||||
else return nullptr;
|
||||
|
||||
Ast_Node* node = new(Ast_Node);
|
||||
|
||||
+17
@@ -632,6 +632,23 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) {
|
||||
return create_ast_node_nil();
|
||||
return create_ast_node_t();
|
||||
}
|
||||
case Built_In_While: {
|
||||
try {
|
||||
arguments_length = list_length(arguments);
|
||||
}
|
||||
|
||||
if (arguments_length < 2) {
|
||||
report_error(Error_Type_Wrong_Number_Of_Arguments);
|
||||
}
|
||||
Ast_Node* condition = arguments->value.pair->first;
|
||||
Ast_Node* then_part = arguments->value.pair->rest;
|
||||
Ast_Node* result = create_ast_node_nil();
|
||||
while (eval_expr(condition, env)->type != Ast_Node_Type_Nil) {
|
||||
result = eval_expr(then_part->value.pair->first, env);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
case Built_In_If: {
|
||||
try {
|
||||
arguments_length = list_length(arguments);
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
#define console_normal "\x1B[0m"
|
||||
#define console_red "\x1B[31m"
|
||||
#define console_green "\x1B[32m"
|
||||
#define console_cyan "\x1B[36m"
|
||||
/* #define console_normal "\x1B[0m" */
|
||||
/* #define console_red "\x1B[31m" */
|
||||
/* #define console_green "\x1B[32m" */
|
||||
/* #define console_cyan "\x1B[36m" */
|
||||
|
||||
#define console_normal ""
|
||||
#define console_red ""
|
||||
#define console_green ""
|
||||
#define console_cyan ""
|
||||
|
||||
|
||||
typedef enum {
|
||||
Log_Level_None,
|
||||
|
||||
Reference in New Issue
Block a user