Compare commits

...

4 Commits

Author SHA1 Message Date
Михаил Капелько
110b44030d d 2024-03-29 23:23:50 +03:00
Михаил Капелько
9a17647cc2 d 2024-03-28 22:31:54 +03:00
Михаил Капелько
77bd59e50b d 2024-03-28 22:16:31 +03:00
Михаил Капелько
1b3a345818 d 2024-03-28 22:09:46 +03:00
9 changed files with 52 additions and 3 deletions

1
gen-Kotlin Executable file
View File

@@ -0,0 +1 @@
kotlinc-native -o test_memory_Kotlin -e my.program.main -Xadd-light-debug=disable main.kt

0
main-2.cpp Normal file
View File

40
main.kt Normal file
View File

@@ -0,0 +1,40 @@
package my.program
// L4: Function.
fun memory_generateConstPlayfield(
n: Int
): Map<Int, Int> {
var idGroups: MutableMap<Int, Int> = mutableMapOf()
var id = 0
for (gid in 0..<n) {
idGroups[id] = gid
id += 1
idGroups[id] = gid
id += 1
}
return idGroups
}
// L20: Test.
fun test_memory_generateConstPlayfield(): String {
val idGroups = memory_generateConstPlayfield(2)
if (
idGroups.count() == 4 &&
idGroups[0] == 0 &&
idGroups[1] == 0 &&
idGroups[2] == 1 &&
idGroups[3] == 1
) {
return "OK: memory_generateConstPlayfield"
}
return "ERR: memory_generateConstPlayfield"
}
// L36: Run.
fun main(args: Array<String>) {
println(test_memory_generateConstPlayfield())
}

View File

@@ -3,9 +3,7 @@
# L4: Function.
def memory_generateConstPlayfield(
n: int
) -> dict[int, int]:
def memory_generateConstPlayfield(n: int) -> dict[int, int]:
idGroups: dict[int, int] = { }
id = 0
for gid in range(0, n):

10
pythonToC++ Executable file
View File

@@ -0,0 +1,10 @@
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