Browse Source

Added set-cakelisp-option

I want to rely on the files themselves dictating how to build rather
than having to remember command-line options.
GeneralDependencyResolver
Macoy Madson 1 month ago
parent
commit
e2dd239eb5
5 changed files with 80 additions and 4 deletions
  1. +11
    -1
      src/Evaluator.cpp
  2. +3
    -0
      src/Evaluator.hpp
  3. +62
    -1
      src/Generators.cpp
  4. +2
    -2
      test/Basic.cake
  5. +2
    -0
      test/Dependencies.cake

+ 11
- 1
src/Evaluator.cpp View File

@@ -752,10 +752,20 @@ int BuildEvaluateReferences(EvaluatorEnvironment& environment, int& numErrorsOut
continue;
}

char headerInclude[MAX_PATH_LENGTH] = {0};
if (environment.cakelispSrcDir.empty())
{
PrintBuffer(headerInclude, "-Isrc/");
}
else
{
PrintfBuffer(headerInclude, "-I%s", environment.cakelispSrcDir.c_str());
}

// TODO: Get arguments all the way from the top
// If not null terminated, the call will fail
const char* arguments[] = {fileToExec, "-g", "-c", sourceOutputName, "-o",
buildObjectName, "-Isrc/", "-fPIC", nullptr};
buildObjectName, headerInclude, "-fPIC", nullptr};
RunProcessArguments compileArguments = {};
compileArguments.fileToExecute = fileToExec;
compileArguments.arguments = arguments;


+ 3
- 0
src/Evaluator.hpp View File

@@ -197,6 +197,9 @@ struct EvaluatorEnvironment
// Generate code so that objects defined in Cakelisp can be reloaded at runtime
bool enableHotReloading;

// Added as a search directory for compile time code execution
std::string cakelispSrcDir;

// Will NOT clean up macroExpansions! Use environmentDestroyInvalidateTokens()
~EvaluatorEnvironment();
};


+ 62
- 1
src/Generators.cpp View File

@@ -9,6 +9,65 @@

#include <string.h>

bool SetCakelispOption(EvaluatorEnvironment& environment, const EvaluatorContext& context,
const std::vector<Token>& tokens, int startTokenIndex,
GeneratorOutput& output)
{
int endInvocationIndex = FindCloseParenTokenIndex(tokens, startTokenIndex);

int optionNameIndex =
getExpectedArgument("expected option name", tokens, startTokenIndex, 1, endInvocationIndex);
if (optionNameIndex == -1)
return false;

if (tokens[optionNameIndex].contents.compare("cakelisp-src-dir") == 0)
{
int pathIndex =
getExpectedArgument("expected path", tokens, startTokenIndex, 2, endInvocationIndex);
if (pathIndex == -1)
return false;

const Token& pathToken = tokens[pathIndex];

// This is a bit unfortunate. Because I don't have an interpreter, this must be a type we
// can recognize, and cannot be constructed procedurally
if (!ExpectTokenType("cakelisp-src-dir", pathToken, TokenType_String))
return false;

environment.cakelispSrcDir = pathToken.contents;
return true;
}

// This needs to be defined early, else things will only be partially supported
if (tokens[optionNameIndex].contents.compare("enable-hot-reloading") == 0)
{
int enableStateIndex =
getExpectedArgument("expected path", tokens, startTokenIndex, 2, endInvocationIndex);
if (enableStateIndex == -1)
return false;

const Token& enableStateToken = tokens[enableStateIndex];

if (!ExpectTokenType("enable-hot-reloading", enableStateToken, TokenType_Symbol))
return false;

if (enableStateToken.contents.compare("true") == 0)
environment.enableHotReloading = true;
else if (enableStateToken.contents.compare("false") == 0)
environment.enableHotReloading = false;
else
{
ErrorAtToken(enableStateToken, "expected true or false");
return false;
}

return true;
}

ErrorAtToken(tokens[optionNameIndex], "unrecognized option");
return false;
}

enum ImportState
{
WithDefinitions,
@@ -942,7 +1001,6 @@ static bool DefTypeAliasGenerator(EvaluatorEnvironment& environment,
if (-1 == typeIndex)
return false;

const Token& nameToken = tokens[nameIndex];
const Token& invocationToken = tokens[1 + startTokenIndex];

bool isGlobal = invocationToken.contents.compare("def-type-alias-global") == 0;
@@ -1617,6 +1675,9 @@ void importFundamentalGenerators(EvaluatorEnvironment& environment)
// Token manipulation
environment.generators["tokenize-push"] = TokenizePushGenerator;

// Cakelisp options
environment.generators["set-cakelisp-option"] = SetCakelispOption;

// Dispatches based on invocation name
const char* cStatementKeywords[] = {
"while", "for-in", "return", "continue", "break", "when", "unless", "array", "set", "scope",


+ 2
- 2
test/Basic.cake View File

@@ -54,8 +54,8 @@
;; Terminology notes: :thing is a keyword symbol. &thing is a symbol or marker symbol (maybe I call it a sentinel?)

;; Becomes add() once converted
(defun + (a int b int &return int)
(return 0))
;; (defun + (a int b int &return int)
;; (return 0))

(defun vec-+ (a int b int &return int)
(return 0))


+ 2
- 0
test/Dependencies.cake View File

@@ -1,3 +1,5 @@
(set-cakelisp-option cakelisp-src-dir "src")
(set-cakelisp-option enable-hot-reloading false)
(c-import "<stdio.h>")
(import "DependenciesModule.cake")



Loading…
Cancel
Save