Browse Source

Renamed some generators, added RunTests

* In order to make generators more consistent, global-var is now
var-global, which matches the other namings
* def-function-signature is now default local, matching other
generators in a similar category (def-type-alias)
* Created RunTests.cake, which will replace most of what is in
BuildAndRunTests.sh. Writing the test suite in Cakelisp will A) make
it easier to port to Windows and B) provide a programming language I
am much more familiar with than batch/bash
precompiled-headers
Macoy Madson 4 months ago
parent
commit
dc93eddbf8
3 changed files with 61 additions and 39 deletions
  1. +2
    -31
      BuildAndRunTests.sh
  2. +13
    -8
      src/Generators.cpp
  3. +46
    -0
      test/RunTests.cake

+ 2
- 31
BuildAndRunTests.sh View File

@ -3,25 +3,12 @@
# Make sure Cakelisp is up to date
. ./Build.sh || exit $?
./bin/cakelisp runtime/Config_Linux.cake test/RunTests.cake || exit $?
# TODO: Add precompiled headers to build system. They are a 60% speedup for compile-time building
# See https://clang.llvm.org/docs/UsersManual.html#precompiled-headers
# clang -g -fPIC -x c++-header src/Evaluator.hpp -o src/Evaluator.hpp.pch
echo "\n============================\nCode Modification\n"
./bin/cakelisp --execute \
test/CodeModification.cake || exit $?
echo "\n============================\nBuild options\n"
./bin/cakelisp \
test/BuildOptions.cake || exit $?
echo "\n============================\nExecute\n"
./bin/cakelisp --execute \
test/Execute.cake || exit $?
echo "\n============================\nHot reloadable library\n"
./bin/cakelisp \
@ -36,20 +23,4 @@ echo "\n============================\nHot loader\n"
./bin/cakelisp \
runtime/Config_Linux.cake runtime/HotLoader.cake || exit $?
echo "\n============================\nCompile-time defines\n"
./bin/cakelisp --execute \
test/Defines.cake || exit $?
# ./bin/cakelisp CrossCompile_Windows.cake || exit $?
echo "\n============================\nMulti-line strings\n"
./bin/cakelisp --execute test/MultiLineStrings.cake || exit $?
echo "\n============================\nBuild helpers\n"
./bin/cakelisp --execute --verbose-processes test/BuildHelpers.cake || exit $?
# echo "\nLink options\n"
# ./bin/cakelisp --verbose-processes test/LinkOptions.cake || exit $?

+ 13
- 8
src/Generators.cpp View File

@ -1063,10 +1063,15 @@ bool DefFunctionSignatureGenerator(EvaluatorEnvironment& environment,
return false;
bool isModuleLocal =
tokens[startTokenIndex + 1].contents.compare("def-function-signature-local") == 0;
tokens[startTokenIndex + 1].contents.compare("def-function-signature-global") != 0;
if (context.scope != EvaluatorScope_Module && isModuleLocal)
NoteAtToken(tokens[startTokenIndex + 1], "no need to specify local if in body scope");
if (!isModuleLocal && context.scope != EvaluatorScope_Module)
{
ErrorAtToken(tokens[startTokenIndex + 1],
"cannot specify global if in body or expression scope. Move it to top-level "
"module scope");
return false;
}
std::vector<StringOutput>& outputDest = isModuleLocal ? output.source : output.header;
@ -1153,13 +1158,13 @@ bool VariableDeclarationGenerator(EvaluatorEnvironment& environment,
int endInvocationIndex = FindCloseParenTokenIndex(tokens, startTokenIndex);
// Global variables will get extern'd in the header
bool isGlobal = funcNameToken.contents.compare("global-var") == 0;
bool isGlobal = funcNameToken.contents.compare("var-global") == 0;
if (isGlobal && !ExpectEvaluatorScope("global variable declaration", tokens[startTokenIndex],
context, EvaluatorScope_Module))
return false;
// Only necessary for static variables declared inside a function
bool isStatic = funcNameToken.contents.compare("static-var") == 0;
bool isStatic = funcNameToken.contents.compare("var-static") == 0;
if (isStatic && !ExpectEvaluatorScope("static variable declaration", tokens[startTokenIndex],
context, EvaluatorScope_Body))
return false;
@ -2895,7 +2900,7 @@ void importFundamentalGenerators(EvaluatorEnvironment& environment)
environment.generators["defun-comptime"] = DefunGenerator;
environment.generators["def-function-signature"] = DefFunctionSignatureGenerator;
environment.generators["def-function-signature-local"] = DefFunctionSignatureGenerator;
environment.generators["def-function-signature-global"] = DefFunctionSignatureGenerator;
environment.generators["def-type-alias"] = DefTypeAliasGenerator;
environment.generators["def-type-alias-global"] = DefTypeAliasGenerator;
@ -2907,8 +2912,8 @@ void importFundamentalGenerators(EvaluatorEnvironment& environment)
environment.generators["defstruct-local"] = DefStructGenerator;
environment.generators["var"] = VariableDeclarationGenerator;
environment.generators["global-var"] = VariableDeclarationGenerator;
environment.generators["static-var"] = VariableDeclarationGenerator;
environment.generators["var-global"] = VariableDeclarationGenerator;
environment.generators["var-static"] = VariableDeclarationGenerator;
environment.generators["at"] = ArrayAccessGenerator;
environment.generators["nth"] = ArrayAccessGenerator;


+ 46
- 0
test/RunTests.cake View File

@ -0,0 +1,46 @@
;; (skip-build)
(add-cakelisp-search-directory "runtime")
(import &comptime-only "BuildTools.cake" "Macros.cake")
;; We don't actually test anything here; we use comptime to run the tests
(defun main (&return int)
(return 0))
(defun-comptime run-tests (manager (& ModuleManager) module (* Module) &return bool)
(var cakelisp-executable (* (const char)) "./bin/cakelisp")
(comptime-cond
('Windows
(set cakelisp-executable "./bin/cakelisp.exe"))
('Unix)
(true
(comptime-error "Please specify platform to run tests. You can do this by including
runtime/Config_[YOUR PLATFORM].cake before this file on the command, e.g.:
cakelisp runtime/Config_Linux.cake test/RunTests.cake")))
(defstruct cakelisp-test
test-name (* (const char))
test-file (* (const char)))
(var tests ([] (const cakelisp-test))
(array
(array "Code modification" "test/CodeModification.cake")
(array "Build options" "test/BuildOptions.cake")
(array "Execute" "test/Execute.cake")
(array "Defines" "test/Defines.cake")
(array "Multi-line strings" "test/MultiLineStrings.cake")
(array "Build helpers" "test/BuildHelpers.cake")))
(var i int 0)
(while (< i (array-size tests))
(var test-name (* (const char)) (field (at i tests) test-name))
(var test-file (* (const char)) (field (at i tests) test-file))
(Logf "\n===============\n%s\n\n" test-name)
(run-process-sequential-or
(cakelisp-executable "--execute" test-file)
(Logf "error: test %s failed" test-name)
(return false))
(Logf "\n%s succeeded\n" test-name)
(incr i))
(Log "\nAll tests succeeded!\n")
(return true))
(add-compile-time-hook-module pre-build run-tests)

Loading…
Cancel
Save