Parcourir la source

Implemented while

master
Felix Brendel il y a 7 ans
Parent
révision
196f75b2bb
7 fichiers modifiés avec 40 ajouts et 15 suppressions
  1. +6
    -7
      build.bat
  2. BIN
     
  3. +2
    -2
      debug.bat
  4. +3
    -0
      src/ast.c
  5. +17
    -0
      src/eval.c
  6. +10
    -4
      src/io.c
  7. +2
    -2
      vs/slime.vcxproj

+ 6
- 7
build.bat Voir le fichier

@@ -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


+ 2
- 2
debug.bat Voir le fichier

@@ -1,4 +1,4 @@
@echo off
pushd %~dp0\vs
start slime.sln
pushd %~dp0
start "" "cdbg64.exe" build\slime.exe
popd

+ 3
- 0
src/ast.c Voir le fichier

@@ -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
- 0
src/eval.c Voir le fichier

@@ -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);


+ 10
- 4
src/io.c Voir le fichier

@@ -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,


+ 2
- 2
vs/slime.vcxproj Voir le fichier

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@@ -30,7 +30,7 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{1A47A3ED-871F-4CB4-875B-8CAA385B1771}</ProjectGuid>
<RootNamespace>slime</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<ProjectName>slime</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />


Chargement…
Annuler
Enregistrer