Михаил Капелько 5 months ago
parent
commit
17a2615351
10 changed files with 246 additions and 9 deletions
  1. +1
    -4
      v4/ctx.py
  2. +86
    -0
      v4/ctx_test.cpp
  3. +3
    -1
      v4/ctx_test.py
  4. +142
    -0
      v4/ctx_test2.py
  5. +1
    -0
      v4/cxx-headers
  6. +1
    -0
      v4/gen-C++
  7. +4
    -0
      v4/main.h
  8. +5
    -4
      v4/main.py
  9. +2
    -0
      v4/tPythonC++/CPP.py
  10. +1
    -0
      v4/translate-py-cxx

+ 1
- 4
v4/ctx.py View File

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


+ 86
- 0
v4/ctx_test.cpp View File

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


+ 3
- 1
v4/ctx_test.py View File

@@ -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"
):


+ 142
- 0
v4/ctx_test2.py View File

@@ -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"
#}

+ 1
- 0
v4/cxx-headers View File

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


+ 1
- 0
v4/gen-C++ View File

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

+ 4
- 0
v4/main.h View File

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


+ 5
- 4
v4/main.py View File

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



+ 2
- 0
v4/tPythonC++/CPP.py View File

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


+ 1
- 0
v4/translate-py-cxx View File

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

Loading…
Cancel
Save