-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_opcode_backend.py
More file actions
98 lines (70 loc) · 2.36 KB
/
build_opcode_backend.py
File metadata and controls
98 lines (70 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from opcode_backend import OpcodeBackend
# optional: if you want dataset export
import json
import csv
# =========================================================
# CONFIG
# =========================================================
BASE_OPCODES = [
"LOAD", "STORE", "MOVE",
"ADD", "SUB", "MUL", "DIV",
"CMP", "JMP", "JZ", "JNZ",
"CALL", "RET", "PRINT"
]
LANGUAGES = [
"python",
"javascript",
"c",
"rust",
"go",
"lua"
]
# =========================================================
# EXPORT HELPERS
# =========================================================
def export_jsonl(data, path="opcode_dataset.jsonl"):
with open(path, "w") as f:
for row in data:
f.write(json.dumps(row) + "\n")
def export_csv(data, path="opcode_dataset.csv"):
with open(path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["opcode", "language", "implementation", "score"])
for row in data:
writer.writerow([
row["opcode"],
row["language"],
row["implementation"],
row["score"]
])
# =========================================================
# MAIN BUILD PIPELINE
# =========================================================
def build(llm, persistent_memory=None):
print("🧠 Initializing Opcode Backend...")
backend = OpcodeBackend(
llm=llm,
persistent_memory=persistent_memory
)
print("⚙️ Generating opcode implementations...")
dataset = backend.build(BASE_OPCODES, LANGUAGES)
print("💾 Exporting dataset...")
export_jsonl(dataset)
export_csv(dataset)
print("🔁 Syncing best implementations to memory...")
if persistent_memory:
persistent_memory.data["opcode_backend_best"] = backend.best_map
persistent_memory.save()
print("✅ Opcode backend build complete.")
return backend, dataset
# =========================================================
# CLI ENTRY
# =========================================================
if __name__ == "__main__":
# replace with your real LLM wrapper
from llm import LLM
from persistent_memory import PersistentMemory
llm = LLM()
memory = PersistentMemory("memory_store.json")
backend, dataset = build(llm, memory)
print(f"Generated {len(dataset)} opcode implementations.")