Михаил Капелько hace 6 meses
padre
commit
ed7d1cd486
Se han modificado 23 ficheros con 234 adiciones y 41 borrados
  1. +4
    -0
      v4/Controller.py
  2. +3
    -2
      v4/cli.cpp
  3. +2
    -2
      v4/cli.py
  4. +1
    -0
      v4/cli_test.cpp
  5. +1
    -0
      v4/cpp.includes
  6. +3
    -1
      v4/cxx-headers
  7. +4
    -3
      v4/gen-C++
  8. +11
    -0
      v4/llm.cpp
  9. +9
    -0
      v4/llm.h
  10. +9
    -1
      v4/llm.py
  11. +37
    -0
      v4/llm_test.cpp
  12. +31
    -0
      v4/llm_test.py
  13. +21
    -0
      v4/llm_test_Python.py
  14. +33
    -1
      v4/main.cpp
  15. +26
    -0
      v4/main.h
  16. +23
    -16
      v4/main.py
  17. +1
    -0
      v4/memory.cpp
  18. +10
    -0
      v4/memory_Context.h
  19. +1
    -0
      v4/memory_Context.py
  20. +1
    -0
      v4/memory_test.cpp
  21. +0
    -15
      v4/memory_test.h
  22. +1
    -0
      v4/tPythonC++/CPP.py
  23. +2
    -0
      v4/translate-py-cxx

+ 4
- 0
v4/Controller.py Ver fichero

@@ -38,6 +38,10 @@ class Controller:
def registerFunction(self, f):
self.functions.append(f)

def registerFunctions(self, funcs):
for f in funcs:
self.functions.append(f)

def reportContext(self):
for cb in self.callbacks:
cb(self.context)


+ 3
- 2
v4/cli.cpp Ver fichero

@@ -1,6 +1,7 @@
#include <map>
#include <string>
#include <vector>
#include "llm.h"
#include "memory_Context.h"
#include "main.h"

@@ -135,11 +136,11 @@ memory_Context cli_selectItem(
) {
if (
c.recentField == "input" &&
c.input.isdigit()
llm_isDigit(c.input)
) {
// CLI ids start with 1 while memory module has ids starting with 0
// Convert CLI id to memory id
c.selectedId = int(c.input) - 1;
c.selectedId = llm_strToInt(c.input) - 1;
c.recentField = "selectedId";
return c;
}


+ 2
- 2
v4/cli.py Ver fichero

@@ -139,11 +139,11 @@ def cli_selectItem(
) -> memory_Context:
if (
c.recentField == "input" and
c.input.isdigit()
llm_isDigit(c.input)
):
# CLI ids start with 1 while memory module has ids starting with 0
# Convert CLI id to memory id
c.selectedId = int(c.input) - 1
c.selectedId = llm_strToInt(c.input) - 1
c.recentField = "selectedId"
return c
#}


+ 1
- 0
v4/cli_test.cpp Ver fichero

@@ -1,6 +1,7 @@
#include <map>
#include <string>
#include <vector>
#include "llm.h"
#include "memory_Context.h"
#include "main.h"



+ 1
- 0
v4/cpp.includes Ver fichero

@@ -1,5 +1,6 @@
#include <map>
#include <string>
#include <vector>
#// file unused
#include "memory.h"
#include "memory_Context.h"

+ 3
- 1
v4/cxx-headers Ver fichero

@@ -5,7 +5,9 @@ TMP=/tmp/cxx-headers.tmp

grep '^memory_Context ' memory.cpp > $TMP
grep '^std::string ' memory_test.cpp >> $TMP
#grep '^memory_Context ' cli.cpp >> $TMP
grep '^memory_Context ' cli.cpp >> $TMP
grep '^std::string ' cli_test.cpp >> $TMP
grep '^std::string ' llm_test.cpp >> $TMP

IN=$TMP
OUT=$DIR/main.h


+ 4
- 3
v4/gen-C++ Ver fichero

@@ -2,7 +2,8 @@ c++ -o test_memory_C++ -std=c++11 -I. \
memory.cpp \
memory_Context.cpp \
memory_test.cpp \
llm.cpp \
llm_test.cpp \
cli.cpp \
cli_test.cpp \
main.cpp

# cli.cpp \
# cli_test.cpp \

+ 11
- 0
v4/llm.cpp Ver fichero

@@ -0,0 +1,11 @@
#include "llm.h"

bool llm_isDigit(const std::string &str) {
return
!str.empty() &&
str.find_first_not_of("0123456789") == std::string::npos;
}

int llm_strToInt(const std::string &str) {
return std::stoi(str);
}

+ 9
- 0
v4/llm.h Ver fichero

@@ -0,0 +1,9 @@
#ifndef llm_HEADER
#define llm_HEADER

#include <string>

bool llm_isDigit(const std::string &str);
int llm_strToInt(const std::string &str);

#endif // llm_HEADER

+ 9
- 1
v4/llm.py Ver fichero

@@ -1,6 +1,6 @@
import copy

# Make deep copies of arguments to mimic behaviour of strongly typed languages.
# Make deep copies of arguments to treat the arguments as structs.
# https://stackoverflow.com/a/15398021
def llm_by_value(f):
def _f(*args, **kwargs):
@@ -8,3 +8,11 @@ def llm_by_value(f):
kwargsCopy = copy.deepcopy(kwargs)
return f(*argsCopy, **kwargsCopy)
return _f

# Tell if string is a digit
def llm_isDigit(s):
return s.isdigit()

# Convert string to integer
def llm_strToInt(s):
return int(s)

+ 37
- 0
v4/llm_test.cpp Ver fichero

@@ -0,0 +1,37 @@
#include <map>
#include <string>
#include <vector>
#include "llm.h"
#include "memory_Context.h"
#include "main.h"

std::string llm_test_isDigit_digit(
) {
if (
llm_isDigit("123")
) {
return "OK: llm_isDigit_digit";
}
return "ERR: llm_isDigit_digit";
}

std::string llm_test_isDigit_notDigit(
) {
if (
llm_isDigit("abc")
) {
return "ERR: llm_isDigit_notDigit";
}
return "OK: llm_isDigit_notDigit";
}

std::string llm_test_strToInt(
) {
if (
llm_strToInt("123") == 123
) {
return "OK: llm_strToInt";
}
return "ERR: llm_strToInt";
}


+ 31
- 0
v4/llm_test.py Ver fichero

@@ -0,0 +1,31 @@
from llm import *

def llm_test_isDigit_digit(
) -> str:
if (
llm_isDigit("123")
):
return "OK: llm_isDigit_digit"
#}
return "ERR: llm_isDigit_digit"
#}

def llm_test_isDigit_notDigit(
) -> str:
if (
llm_isDigit("abc")
):
return "ERR: llm_isDigit_notDigit"
#}
return "OK: llm_isDigit_notDigit"
#}

def llm_test_strToInt(
) -> str:
if (
llm_strToInt("123") == 123
):
return "OK: llm_strToInt"
#}
return "ERR: llm_strToInt"
#}

+ 21
- 0
v4/llm_test_Python.py Ver fichero

@@ -0,0 +1,21 @@
from llm import *
from memory_Context import *

def llm_test_Python_copyByValue(
) -> str:
c = memory_createContext()
c.input = "abc"

@llm_by_value
def alterValue(c):
c.input = "alteredValue"

alterValue(c)

if (
c.input == "abc"
):
return "OK: llm_Python_copyByValue"
#}
return "ERR: llm_Python_copyByValue"
#}

+ 33
- 1
v4/main.cpp Ver fichero

@@ -5,6 +5,15 @@
#include "memory_Context.h"

int main() {
std::cout
<< llm_test_isDigit_digit()
<< std::endl
<< llm_test_isDigit_notDigit()
<< std::endl
<< llm_test_strToInt()
<< std::endl
;

std::cout
<< memory_test_detectMismatchedItems()
<< std::endl
@@ -24,16 +33,39 @@ int main() {
<< std::endl
;

/*
std::cout
<< cli_test_exit_e()
<< std::endl
<< cli_test_exit_exit()
<< std::endl
<< cli_test_exit_victory()
<< std::endl
<< cli_test_exit_q()
<< std::endl
<< cli_test_exit_quit()
<< std::endl
<< cli_test_goOn()
<< std::endl
<< cli_test_greetUser()
<< std::endl
<< cli_test_showHelp_h()
<< std::endl
<< cli_test_showHelp_help()
<< std::endl
<< cli_test_selectItem()
<< std::endl
<< cli_test_promptSecondItemSelection()
<< std::endl
<< cli_test_reportMatchedItems()
<< std::endl
<< cli_test_reportMismatchedItems()
<< std::endl
<< cli_test_reportVictory()
<< std::endl
;

/*

auto c = shell_createContext();
c.cCLI = cli_createContext();
c = shell_launch(c);


+ 26
- 0
v4/main.h Ver fichero

@@ -17,6 +17,32 @@ std::string memory_test_hideMatchingItems();
std::string memory_test_selectItem_1x();
std::string memory_test_selectItem_2x();
std::string memory_test_selectItem_3x();
memory_Context cli_exit(memory_Context);
memory_Context cli_goOn(memory_Context);
memory_Context cli_greetUser(memory_Context);
memory_Context cli_promptSecondItemSelection(memory_Context);
memory_Context cli_reportMatchedItems(memory_Context);
memory_Context cli_reportVictory(memory_Context);
memory_Context cli_selectItem(memory_Context);
memory_Context cli_showHelp(memory_Context);
memory_Context cli_reportMismatchedItems(memory_Context);
std::string cli_test_exit_e();
std::string cli_test_exit_exit();
std::string cli_test_exit_victory();
std::string cli_test_exit_q();
std::string cli_test_exit_quit();
std::string cli_test_goOn();
std::string cli_test_greetUser();
std::string cli_test_promptSecondItemSelection();
std::string cli_test_reportMatchedItems();
std::string cli_test_reportMismatchedItems();
std::string cli_test_selectItem();
std::string cli_test_showHelp_h();
std::string cli_test_showHelp_help();
std::string cli_test_reportVictory();
std::string llm_test_isDigit_digit();
std::string llm_test_isDigit_notDigit();
std::string llm_test_strToInt();

#endif // main_HEADER


+ 23
- 16
v4/main.py Ver fichero

@@ -1,9 +1,16 @@
from cli import *
from cli_test import *
from llm_test import *
from llm_test_Python import *
from memory_test import *
from Controller import *
import sys

print(llm_test_Python_copyByValue())
print(llm_test_isDigit_digit())
print(llm_test_isDigit_notDigit())
print(llm_test_strToInt())

print(memory_test_detectMismatchedItems())
print(memory_test_detectMismatchedItems_itemTwice())
print(memory_test_detectVictory())
@@ -28,28 +35,28 @@ print(cli_test_reportMatchedItems())
print(cli_test_reportMismatchedItems())
print(cli_test_reportVictory())


ctrl = Controller(memory_createContext())
ctrl.registerFunction(cli_exit)
ctrl.registerFunction(cli_goOn)
ctrl.registerFunction(cli_greetUser)
ctrl.registerFunction(cli_promptSecondItemSelection)
ctrl.registerFunction(cli_reportMatchedItems)
ctrl.registerFunction(cli_reportMismatchedItems)
ctrl.registerFunction(cli_reportVictory)
ctrl.registerFunction(cli_selectItem)
ctrl.registerFunction(cli_showHelp)
ctrl.registerFunction(memory_detectMismatchedItems)
ctrl.registerFunction(memory_detectVictory)
ctrl.registerFunction(memory_generateConstPlayfield)
ctrl.registerFunction(memory_hideMatchingItems)
ctrl.registerFunction(memory_selectItem)
ctrl.registerFunctions([
cli_exit,
cli_goOn,
cli_greetUser,
cli_promptSecondItemSelection,
cli_reportMatchedItems,
cli_reportMismatchedItems,
cli_reportVictory,
cli_selectItem,
cli_showHelp,
memory_detectMismatchedItems,
memory_detectVictory,
memory_generateConstPlayfield,
memory_hideMatchingItems,
memory_selectItem,
])

def printOutput(c):
if c.recentField.startswith("output"):
print(c.field(c.recentField))
ctrl.registerCallback(printOutput)
#ctrl.registerCallback(lambda c: print(f"ИГР App.dbg ctx: '{c}'"))
ctrl.registerFieldCallback("exit", lambda c: sys.exit(0))

ctrl.set("didLaunch", True)


+ 1
- 0
v4/memory.cpp Ver fichero

@@ -1,6 +1,7 @@
#include <map>
#include <string>
#include <vector>
#include "llm.h"
#include "memory_Context.h"
#include "main.h"



+ 10
- 0
v4/memory_Context.h Ver fichero

@@ -6,8 +6,18 @@
#define memory_Context_HEADER

struct memory_Context {
bool didLaunch = false;
bool exit = false;
std::string input = "";
std::vector<int> hiddenItems;
std::vector<int> mismatchedItems;
std::string outputGoOn = "";
std::string outputGreeting = "";
std::string outputHelp = "";
std::string outputMatchedItems = "";
std::string outputMismatchedItems = "";
std::string outputPromptSelection = "";
std::string outputVictory = "";
std::map<int, int> playfieldItems;
int playfieldSize = 0;
std::string recentField = "none";


+ 1
- 0
v4/memory_Context.py Ver fichero

@@ -1,6 +1,7 @@
class memory_Context:
def __init__(self):
self.didLaunch = False
self.exit = False
self.hiddenItems = []
self.input = ""
self.mismatchedItems = []


+ 1
- 0
v4/memory_test.cpp Ver fichero

@@ -1,6 +1,7 @@
#include <map>
#include <string>
#include <vector>
#include "llm.h"
#include "memory_Context.h"
#include "main.h"



+ 0
- 15
v4/memory_test.h Ver fichero

@@ -1,15 +0,0 @@
#include <string>

#ifndef memory_test_HEADER
#define memory_test_HEADER

std::string memory_test_generateConstPlayfield();
std::string memory_test_selectItem_1x();
std::string memory_test_selectItem_2x();
std::string memory_test_selectItem_3x();
std::string memory_test_shouldDeselectMismatchedItems();
std::string memory_test_shouldDeselectMismatchedItems_itemTwice();
std::string memory_test_shouldDetectVictory();
std::string memory_test_shouldHideMatchingItems();

#endif // memory_test_HEADER

+ 1
- 0
v4/tPythonC++/CPP.py Ver fichero

@@ -4,6 +4,7 @@ def includes():
return """#include <map>
#include <string>
#include <vector>
#include "llm.h"
#include "memory_Context.h"
#include "main.h"
"""


+ 2
- 0
v4/translate-py-cxx Ver fichero

@@ -7,3 +7,5 @@ $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/llm_test.py > $DIR/llm_test.cpp
$DIR/cxx-headers

Cargando…
Cancelar
Guardar