This repository was archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpogscript.py
121 lines (95 loc) · 2.58 KB
/
pogscript.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from json import dump
from re import S
from sys import argv, exit
from os import (
chdir,
mkdir,
remove,
)
from os.path import (
dirname,
exists
)
from shutil import move, rmtree
from subprocess import run as sub_run
exe_dir = dirname(argv[0]).replace("\\", "/")
DEFAULT_CONFIG = {
"$schema" : f"{exe_dir}/pogfig_schema/pogfig_schema.json",
"imports.paths" : ["%FILE%/imports",
"%COMPILER%/imports"],
"imports.names" : {
"projlib" : ".projlib"
},
"compiler.optimizations" : 0
}
def newproj():
try:
projname = argv[2]
except IndexError:
print("Project name not specified.")
exit(1)
if exists(projname):
rmtree(projname)
mkdir(projname)
chdir(projname)
with open("main.pog", "w") as f:
f.write("#your code here...")
with open(".main_pogfig.json", "w") as f:
dump(DEFAULT_CONFIG, f, indent="\t")
mkdir("modifiers")
mkdir("imports")
with open("imports/.projlib", "w") as f:
f.write("mylib.lib || mylib.pog")
with open("imports/mylib.pog", "w") as f:
f.write("#write your library here...")
def build():
rmtree(f"{exe_dir}/tests")
rmtree(f"{exe_dir}/docs")
rmtree(f"{exe_dir}/deprecated")
rmtree(f"{exe_dir}/syntax_highlighting")
remove(f"{exe_dir}/package.json")
remove(f"{exe_dir}/README.md")
remove(f"{exe_dir}/LICENSE")
remove(f"{exe_dir}/.gitignore")
remove(f"{exe_dir}/.gitattributes")
chdir(f"{exe_dir}/src")
sub_run(["python", "-m", "nuitka", "--onefile", "pogc2.py"])
move(f"pogc2.exe", f"{exe_dir}/pogc2.exe")
move(f"cleanup.bat", f"{exe_dir}/cleanup.bat")
move(f"assemble.bat", f"{exe_dir}/assemble.bat")
chdir("..")
rmtree(f"{exe_dir}/src")
def rename_mod(modname: str, newname: str):
print("WARNING: this will replace any file named with the new name")
input("Continue (CTRL-C => NO, Enter => YES)?")
with open(f"{modname}.asm", 'r') as f:
code = f.read().splitlines()
try:
globaldecl = code.index(f"\tglobal _{modname}_init.1")
moddecl = code.index(f"_{modname}_init.1:")
except ValueError:
print("Module not named correctly. Try recompiling.")
exit(1)
code[globaldecl] = f"\tglobal _{newname}_init.1"
code[moddecl] = f"_{newname}_init.1:"
with open(f"{newname}.asm", 'w') as f:
f.write(
'\n'.join(code)
)
if len(argv) < 2:
print("No option specified.")
exit(1)
if argv[1] == "new":
newproj()
elif argv[1] == "compile":
try: sub_run(["pogc2.py"]+argv[2:])
except OSError:
try: sub_run(["pogc2"]+argv[2:])
except OSError: print("Please add pogc2 to your PATH.")
elif argv[1] == "build":
build()
elif argv[1] == "rename":
if len(argv) < 4:
print("Not enough arguments.")
exit(1)
rename_mod(argv[2], argv[3])