From 196f75b2bb3e50329b60f4409a1ec9e9d0ab0cb9 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Tue, 13 Nov 2018 16:32:51 +0100 Subject: [PATCH] Implemented while --- build.bat | 13 ++++++------- build/slime.exe.dbg | Bin 0 -> 52 bytes debug.bat | 4 ++-- src/ast.c | 3 +++ src/eval.c | 17 +++++++++++++++++ src/io.c | 14 ++++++++++---- vs/slime.vcxproj | 4 ++-- 7 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 build/slime.exe.dbg diff --git a/build.bat b/build.bat index 40bdcbc..806cf4d 100644 --- a/build.bat +++ b/build.bat @@ -5,23 +5,22 @@ pushd %~dp0 set exeName=slime.exe set binDir=bin -mkdir quickbuild 2>nul -pushd quickbuild +mkdir build 2>nul +pushd build taskkill /F /IM %exeName% > NUL 2> NUL echo ---------- Compiling ---------- -call timecmd cl ../src/main.c /Fe%exeName% /W3 /Ox /O2 /Oi /TC /nologo /EHsc /link +call timecmd cl ../src/main.c /Fe%exeName% /D_DEBUG /W3 /TC /Zi /nologo /EHsc /link if %errorlevel% == 0 ( echo. - if not exist ..\%binDir% mkdir ..\%binDir% - move %exeName% ..\%binDir%\ > NUL + echo Done ) else ( echo. - echo Fucki'n 'ell + echo Fuckin' ell ) popd -rd quickbuild /S /Q +rem rd build /S /Q popd diff --git a/build/slime.exe.dbg b/build/slime.exe.dbg new file mode 100644 index 0000000000000000000000000000000000000000..d5b5597d557e4fb293008e10ae1033a823e4946f GIT binary patch literal 52 ycmb=*a8+hvU|`?`VhJElvx;#`&B?5Y$;m7(h$+s=%uS6+%FK&l1ImHafdBw3WeVj0 literal 0 HcmV?d00001 diff --git a/debug.bat b/debug.bat index 8bba81a..c1bf6ab 100644 --- a/debug.bat +++ b/debug.bat @@ -1,4 +1,4 @@ @echo off -pushd %~dp0\vs -start slime.sln +pushd %~dp0 +start "" "cdbg64.exe" build\slime.exe popd diff --git a/src/ast.c b/src/ast.c index dc10bff..d2021c2 100644 --- a/src/ast.c +++ b/src/ast.c @@ -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); diff --git a/src/eval.c b/src/eval.c index e920782..120700c 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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); diff --git a/src/io.c b/src/io.c index 48d26ad..c553285 100644 --- a/src/io.c +++ b/src/io.c @@ -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, diff --git a/vs/slime.vcxproj b/vs/slime.vcxproj index b74f8cc..8236687 100644 --- a/vs/slime.vcxproj +++ b/vs/slime.vcxproj @@ -1,4 +1,4 @@ - + @@ -30,7 +30,7 @@ 15.0 {1A47A3ED-871F-4CB4-875B-8CAA385B1771} slime - 10.0.16299.0 + 10.0.15063.0 slime