@@ -32,10 +32,7 @@ class ctx_Controller: | |||
self.callbacks.append(cb) | |||
def registerFieldCallback(self, fieldName, cb): | |||
def execCB(c): | |||
if c.recentField == fieldName: | |||
cb(c) | |||
self.callbacks.append(execCB) | |||
self.callbacks.append(lambda c: cb(c) if c.recentField == fieldName else None) | |||
def registerFunction(self, f): | |||
self.functions.append(f) | |||
@@ -0,0 +1,86 @@ | |||
#include <map> | |||
#include <string> | |||
#include <vector> | |||
#include "ctx.h" | |||
#include "llm.h" | |||
#include "memory_Context.h" | |||
#include "main.h" | |||
std::string ctx_test_Controller_executeFunctions_set( | |||
) { | |||
auto c = memory_createContext(); | |||
auto ctrl = ctx_Controller(c); | |||
// Disable automatic invocation of executeFunctions. | |||
ctrl.isProcessingQueue = true; | |||
ctrl.set("input", "123"); | |||
ctrl.registerFunction(__processInput); | |||
// Apply 'input'. | |||
ctrl.executeFunctions(); | |||
// Apply 'outputHelp'. | |||
ctrl.executeFunctions(); | |||
if ( | |||
c.input == "123" && | |||
c.outputHelp == "Checked" | |||
) { | |||
return "OK: ctx_Controller_executeFunctions_set"; | |||
} | |||
return "ERR: ctx_Controller_executeFunctions_set"; | |||
} | |||
std::string ctx_test_Controller_processQueue( | |||
) { | |||
auto c = memory_createContext(); | |||
auto ctrl = ctx_Controller(c); | |||
ctrl.registerFunction(__processInput); | |||
ctrl.set("input", "abc");; | |||
if ( | |||
c.input == "abc" && | |||
c.outputHelp == "Checked" | |||
) { | |||
return "OK: ctx_Controller_processQueue"; | |||
} | |||
return "ERR: ctx_Controller_processQueue"; | |||
} | |||
std::string ctx_test_memoryContext_field( | |||
) { | |||
auto c = memory_createContext(); | |||
c.input = "abc"; | |||
if ( | |||
c.field("input") == "abc" | |||
) { | |||
return "OK: ctx_memoryContext_field"; | |||
} | |||
return "ERR: ctx_memoryContext_field"; | |||
} | |||
std::string ctx_test_memoryContext_setField( | |||
) { | |||
auto c = memory_createContext(); | |||
c.input = "abc"; | |||
c.setField("input", "123"); | |||
if ( | |||
c.field("input") == "123" | |||
) { | |||
return "OK: ctx_memoryContext_setField"; | |||
} | |||
return "ERR: ctx_memoryContext_setField"; | |||
} | |||
// Auxiliary functions. | |||
memory_Context __processInput( | |||
memory_Context c | |||
) { | |||
if ( | |||
c.recentField == "input" | |||
) { | |||
c.outputHelp = "Checked"; | |||
c.recentField = "outputHelp"; | |||
return c; | |||
} | |||
c.recentField = "none"; | |||
return c; | |||
} | |||
@@ -66,7 +66,9 @@ def ctx_test_memoryContext_setField( | |||
# Auxiliary functions. | |||
@llm_by_value | |||
def __processInput(c): | |||
def __processInput( | |||
c: memory_Context | |||
) -> memory_Context: | |||
if ( | |||
c.recentField == "input" | |||
): | |||
@@ -0,0 +1,142 @@ | |||
from ctx import * | |||
from memory import * | |||
from memory_Context import * | |||
def ctx_test_Controller_executeFunctions_set( | |||
) -> str: | |||
c = memory_createContext() | |||
ctrl = ctx_Controller(c) | |||
# Disable automatic invocation of executeFunctions. | |||
ctrl.isProcessingQueue = True | |||
ctrl.set("input", "123") | |||
@llm_by_value | |||
def processInput(c): | |||
if ( | |||
c.recentField == "input" | |||
): | |||
c.outputHelp = "Checked" | |||
c.recentField = "outputHelp" | |||
return c | |||
#} | |||
c.recentField = "none" | |||
return c | |||
#} | |||
ctrl.registerFunction(processInput) | |||
# Apply 'input'. | |||
ctrl.executeFunctions() | |||
# Apply 'outputHelp'. | |||
ctrl.executeFunctions() | |||
if ( | |||
c.input == "123" and | |||
c.outputHelp == "Checked" | |||
): | |||
return "OK: ctx_Controller_executeFunctions_set" | |||
#} | |||
return "ERR: ctx_Controller_executeFunctions_set" | |||
#} | |||
def ctx_test_Controller_processQueue( | |||
) -> str: | |||
c = memory_createContext() | |||
ctrl = ctx_Controller(c) | |||
@llm_by_value | |||
def processInput(c): | |||
if ( | |||
c.recentField == "input" | |||
): | |||
c.outputHelp = "Checked" | |||
c.recentField = "outputHelp" | |||
return c | |||
#} | |||
c.recentField = "none" | |||
return c | |||
#} | |||
ctrl.registerFunction(processInput) | |||
ctrl.set("input", "abc"); | |||
if ( | |||
c.input == "abc" and | |||
c.outputHelp == "Checked" | |||
): | |||
return "OK: ctx_Controller_processQueue" | |||
#} | |||
return "ERR: ctx_Controller_processQueue" | |||
#} | |||
def ctx_test_Controller_registerFieldCallback_match( | |||
) -> str: | |||
c = memory_createContext() | |||
ctrl = ctx_Controller(c) | |||
c.input = "123" | |||
c.recentField = "input" | |||
globals()["callbackInput"] = "" | |||
def setCallbackInput(c): | |||
if ( | |||
c.recentField == "input" | |||
): | |||
globals()["callbackInput"] = c.input | |||
ctrl.registerFieldCallback("input", setCallbackInput) | |||
ctrl.reportContext() | |||
if ( | |||
c.input == globals()["callbackInput"] | |||
): | |||
return "OK: ctx_Controller_registerFieldCallback_match" | |||
#} | |||
return f"ERR: ctx_Controller_registerFieldCallback_match" | |||
#} | |||
def ctx_test_Controller_registerFieldCallback_mismatch( | |||
) -> str: | |||
c = memory_createContext() | |||
ctrl = ctx_Controller(c) | |||
c.input = "123" | |||
c.outputHelp = "you" | |||
# A field other than 'input' is marked recent. | |||
c.recentField = "outputHelp" | |||
globals()["callbackInput"] = "" | |||
def setCallbackInput(c): | |||
if ( | |||
c.recentField == "input" | |||
): | |||
globals()["callbackInput"] = c.input | |||
ctrl.registerFieldCallback("input", setCallbackInput) | |||
ctrl.reportContext() | |||
if ( | |||
globals()["callbackInput"] == "" | |||
): | |||
return "OK: ctx_Controller_registerFieldCallback_mismatch" | |||
#} | |||
return f"ERR: ctx_Controller_registerFieldCallback_mismatch" | |||
#} | |||
def ctx_test_memoryContext_field( | |||
) -> str: | |||
c = memory_createContext() | |||
c.input = "abc" | |||
if ( | |||
c.field("input") == "abc" | |||
): | |||
return "OK: ctx_memoryContext_field" | |||
#} | |||
return "ERR: ctx_memoryContext_field" | |||
#} | |||
def ctx_test_memoryContext_setField( | |||
) -> str: | |||
c = memory_createContext() | |||
c.input = "abc" | |||
c.setField("input", "123") | |||
if ( | |||
c.input == "123" | |||
): | |||
return "OK: ctx_memoryContext_setField" | |||
#} | |||
return "ERR: ctx_memoryContext_setField" | |||
#} |
@@ -7,6 +7,7 @@ grep '^memory_Context ' memory.cpp > $TMP | |||
grep '^std::string ' memory_test.cpp >> $TMP | |||
grep '^memory_Context ' cli.cpp >> $TMP | |||
grep '^std::string ' cli_test.cpp >> $TMP | |||
grep '^std::string ' ctx_test.cpp >> $TMP | |||
grep '^std::string ' llm_test.cpp >> $TMP | |||
IN=$TMP | |||
@@ -6,4 +6,5 @@ c++ -o test_memory_C++ -std=c++11 -I. \ | |||
llm_test.cpp \ | |||
cli.cpp \ | |||
cli_test.cpp \ | |||
ctx_test2.cpp \ | |||
main.cpp |
@@ -40,6 +40,10 @@ std::string cli_test_selectItem(); | |||
std::string cli_test_showHelp_h(); | |||
std::string cli_test_showHelp_help(); | |||
std::string cli_test_reportVictory(); | |||
std::string ctx_test_Controller_executeFunctions_set(); | |||
std::string ctx_test_Controller_processQueue(); | |||
std::string ctx_test_memoryContext_field(); | |||
std::string ctx_test_memoryContext_setField(); | |||
std::string llm_test_isDigit_digit(); | |||
std::string llm_test_isDigit_notDigit(); | |||
std::string llm_test_strToInt(); | |||
@@ -1,8 +1,9 @@ | |||
from cli import * | |||
from cli_test import * | |||
from ctx import * | |||
from ctx_test import * | |||
from ctx_test_Python import * | |||
from ctx_test2 import * | |||
#from ctx_test import * | |||
#from ctx_test_Python import * | |||
from llm_test import * | |||
from llm_test_Python import * | |||
from memory_test import * | |||
@@ -10,8 +11,8 @@ import sys | |||
print(ctx_test_Controller_executeFunctions_set()) | |||
print(ctx_test_Controller_processQueue()) | |||
print(ctx_test_Python_Controller_registerFieldCallback_match()) | |||
print(ctx_test_Python_Controller_registerFieldCallback_mismatch()) | |||
print(ctx_test_Controller_registerFieldCallback_match()) | |||
print(ctx_test_Controller_registerFieldCallback_mismatch()) | |||
print(ctx_test_memoryContext_field()) | |||
print(ctx_test_memoryContext_setField()) | |||
@@ -55,6 +55,7 @@ def translateStatement(s, state): | |||
posColon = ss.find(": ") | |||
posComma = ss.find(", ") | |||
posComment = ss.find("# ") | |||
posCtrl = ss.find("ctrl.") | |||
posCtx = ss.find("c.") | |||
posEqual = ss.find(" = ") | |||
posFor = ss.find("for ") | |||
@@ -97,6 +98,7 @@ def translateStatement(s, state): | |||
# name = value -> auto name = value | |||
if ( | |||
posCtx == -1 and | |||
posCtrl == -1 and | |||
posColon == -1 and | |||
posOpenSquareBracket == -1 and | |||
posEqual >= 0 | |||
@@ -7,5 +7,6 @@ $TR $DIR/memory.py > $DIR/memory.cpp | |||
$TR $DIR/memory_test.py > $DIR/memory_test.cpp | |||
$TR $DIR/cli.py > $DIR/cli.cpp | |||
$TR $DIR/cli_test.py > $DIR/cli_test.cpp | |||
$TR $DIR/ctx_test.py > $DIR/ctx_test.cpp | |||
$TR $DIR/llm_test.py > $DIR/llm_test.cpp | |||
$DIR/cxx-headers |