d
This commit is contained in:
36
main-2.cpp
36
main-2.cpp
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
|
||||
// L4: Function.
|
||||
|
||||
std::map<int, int> memory_generateConstPlayfield(n: int) {
|
||||
idGroups: std::map<int, int> = { }
|
||||
id = 0
|
||||
for gid in range(0, n):
|
||||
idGroups[id] = gid
|
||||
id += 1
|
||||
idGroups[id] = gid
|
||||
id += 1
|
||||
}
|
||||
return idGroups
|
||||
}
|
||||
|
||||
// L20: Test.
|
||||
|
||||
str test_memory_generateConstPlayfield() {
|
||||
idGroups = memory_generateConstPlayfield(2)
|
||||
if (
|
||||
len(idGroups) == 4 and
|
||||
idGroups[0] == 0 and
|
||||
idGroups[1] == 0 and
|
||||
idGroups[2] == 1 and
|
||||
idGroups[3] == 1
|
||||
):
|
||||
return "OK: memory_generateConstPlayfield"
|
||||
}
|
||||
return "ERR: memory_generateConstPlayfield"
|
||||
}
|
||||
|
||||
// L36: Run.
|
||||
|
||||
print(test_memory_generateConstPlayfield())
|
||||
|
||||
4
main.cpp
4
main.cpp
@@ -3,9 +3,7 @@
|
||||
|
||||
// L4: Function.
|
||||
|
||||
std::map<int, int> memory_generateConstPlayfield(
|
||||
int n
|
||||
) {
|
||||
std::map<int, int> memory_generateConstPlayfield(int n) {
|
||||
std::map<int, int> idGroups;
|
||||
auto id = 0;
|
||||
for (auto gid = 0; gid < n; ++gid) {
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
IN=main.py
|
||||
OUT=main-2.cpp
|
||||
|
||||
# Simple check. TODO REMOVE later
|
||||
sed 's|# L4: Function.|// L4: Function.|' $IN > $OUT
|
||||
|
||||
# dict[X, Y] -> std::map<X, Y>
|
||||
sed -E 's|dict\[(.*), (.*)\]|std::map<\1, \2>|' $IN > $OUT
|
||||
# def functionName(X) -> Y -> Y functionName(X) {
|
||||
sed -E 's|def (.*) -> (.*):|\2 \1 {|' $OUT > $OUT
|
||||
sed -Ef sed.pythonToC++ <$IN >$OUT
|
||||
|
||||
12
sed.pythonToC++
Normal file
12
sed.pythonToC++
Normal file
@@ -0,0 +1,12 @@
|
||||
# #} -> }
|
||||
s|#}|}|
|
||||
|
||||
# # -> //
|
||||
s|#|//|
|
||||
|
||||
# dict[X, Y] -> std::map<X, Y>
|
||||
s_dict\[(.*), (.*)\]_std::map<\1, \2>_
|
||||
|
||||
# def functionName(X) -> Y -> Y functionName(X) {
|
||||
s|def (.*) -> (.*):|\2 \1 {|
|
||||
|
||||
Reference in New Issue
Block a user