Skip to content

Commit 1e4c366

Browse files
removed trash. updated libriary system
1 parent e9b5357 commit 1e4c366

35 files changed

+149
-479
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ Ponyscript comes with its own compiler, enabling easy transformation of Ponyscri
1717
## Example Code
1818

1919
```ponyscript
20-
using libspace std;
2120
22-
num magic->>(int argc, char *argv[])
21+
int magic(int argc, char *argv[])
2322
{
24-
string a = replaceAll->>("Sample string", "Sample", "pony");
25-
neigh->>(a);
23+
string a = "Hello Equestria";
24+
neighln(a);
2625
}
2726
```
2827

compiler.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from logs import *
99
from datetime import datetime
1010
from headergenerator import *
11+
1112
try:
13+
absp = os.path.abspath(__file__).replace("compiler.py", "")
1214

1315
floader_dir = sys.argv[1]
1416

@@ -105,10 +107,24 @@ def extract_additional_files(file_path):
105107
for i in find_variables(tokens):
106108
variables[i] = find_variables(tokens)[i]
107109

110+
for i in includes:
111+
temptokens = lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.h", "r").read())
112+
tempvariables = find_variables(temptokens)
113+
for j in tempvariables:
114+
variables[j] = tempvariables[j]
115+
116+
117+
108118
print_log("Class analysis")
109119
classes_list, updated_tokens = find_classes(tokens)
110120
for i in classes_list:
111121
classes.append(i)
122+
123+
for i in includes:
124+
tempclasses, temptokens = find_classes(lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.h", "r").read()))
125+
for j in tempclasses:
126+
classes.append(j)
127+
112128
print_log("Translation")
113129

114130
tokens = translate_tokens(updated_tokens, variables, classes)
@@ -130,16 +146,17 @@ def extract_additional_files(file_path):
130146
if cfgline.split("=")[0].strip() == "[File Name]":
131147
settings["filename"] = cfgline.split("=")[1].strip()
132148

133-
absp = os.path.abspath(__file__).replace("compiler.py", "")
134149

135-
lib = "/lib" #Эта фигня нужна для дебага, gcc переодически теряет файлы в каталого lib. "/lib" - значение для каталога lib
136-
try:
137-
shutil.rmtree(f"{bin_dir}{lib}") #Удаляем каталог lib, если он существует
138-
except: pass
139-
try:
140-
os.mkdir(f"{bin_dir}{lib}")
141-
except FileExistsError:
142-
pass
150+
151+
lib = "" #Эта фигня нужна для дебага, gcc переодически теряет файлы в каталого lib. "/lib" - значение для каталога lib
152+
if lib != "":
153+
try:
154+
shutil.rmtree(f"{bin_dir}{lib}") #Удаляем каталог lib, если он существует
155+
except: pass
156+
try:
157+
os.mkdir(f"{bin_dir}{lib}")
158+
except FileExistsError:
159+
pass
143160

144161
print_log("Copying built in libriaries")
145162

@@ -154,8 +171,8 @@ def extract_additional_files(file_path):
154171

155172
print_log("Copying additional built in libriaries")
156173
for i in includes:
157-
shutil.copy(f"{absp}lib/{i.strip()}.cpp", bin_dir + lib)
158-
shutil.copy(f"{absp}lib/{i.strip()}.h", bin_dir + lib)
174+
shutil.copy(f"{absp}lib/{i.strip()}/{i.strip()}.cpp", bin_dir + lib)
175+
shutil.copy(f"{absp}lib/{i.strip()}/{i.strip()}.h", bin_dir + lib)
159176
buildfiles = buildfiles + f"{bin_dir}{lib}/{i}.cpp "
160177
buildfiles = buildfiles + f"{bin_dir}{lib}/{i}.h "
161178

@@ -168,16 +185,15 @@ def extract_additional_files(file_path):
168185
print_log("Writing run.cpp")
169186

170187
shutil.copy(f"{absp}lib/run.cpp", bin_dir+ lib)
171-
for file in extract_additional_files(f"{floader_dir}/.ponycfg"):
172-
buildfiles = buildfiles + file + " "
188+
173189

174190
print_log("Starting gcc compyler")
175191
print(f"{absp}ucrt64\\bin\\g++.exe -o {bin_dir}/{settings['filename']} -I {absp}lib -L {absp}lib/dlls -l ponylib -finput-charset=UTF-8 {buildfiles} -lws2_32")
176192

177193
result = subprocess.run(f"{absp}ucrt64\\bin\\g++.exe -o {bin_dir}/{settings['filename']} -I {absp}lib -L {absp}lib/dlls -l ponylib -finput-charset=UTF-8 {buildfiles} -lws2_32", capture_output=True)
178194

179-
print(result.stdout)
180-
# print_log(gccdocksparser.parse(result.stderr.decode()))
195+
# print(result.stderr.decode())
196+
print_log(gccdocksparser.parse(result.stderr.decode()))
181197

182198
if result.returncode == 0:
183199
print_log("\n")

example.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

lastest.log

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
[13:52:20] Compiler started
2-
[13:52:20] Bin directory already exists
3-
[13:52:20] Reading files in floader
4-
[13:52:20] Compiling file prog.psc
5-
[13:52:20] Lexical analysis
6-
[13:52:20] Variable analysis
7-
[13:52:20] Class analysis
8-
[13:52:20] Translation
9-
[13:52:20] Assembling code
10-
[13:52:20] Writing code to file
11-
[13:52:20] Finished compiling file prog.psc
12-
[13:52:20] Reading configuration file
13-
[13:52:20] Copying built in libriaries
14-
[13:52:20] Copying additional files
15-
[13:52:20] Copying additional built in libriaries
16-
[13:52:20] Building executable
17-
[13:52:20] Writing run.h
18-
[13:52:20] Writing run.cpp
19-
[13:52:20] Starting gcc compyler
20-
[13:52:23]
1+
[19:56:45] Compiler started
2+
[19:56:45] Bin directory already exists
3+
[19:56:45] Reading files in floader
4+
[19:56:45] Compiling file prog.psc
5+
[19:56:45] Lexical analysis
6+
[19:56:45] Variable analysis
7+
[19:56:45] Class analysis
8+
[19:56:45] Translation
9+
[19:56:45] Assembling code
10+
[19:56:45] Writing code to file
11+
[19:56:45] Finished compiling file prog.psc
12+
[19:56:45] Reading configuration file
13+
[19:56:45] Copying built in libriaries
14+
[19:56:45] Copying additional files
15+
[19:56:45] Copying additional built in libriaries
16+
[19:56:45] Building executable
17+
[19:56:45] Writing run.h
18+
[19:56:45] Writing run.cpp
19+
[19:56:45] Starting gcc compyler
20+
[19:56:48]
2121

22-
[13:52:23] Compilation successful!
22+
[19:56:48] Compilation successful!

launcher/programm.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
11
#include <iostream>
22
#include <filesystem>
33
#include <format>
4+
#include <fstream>
45

56

67
using namespace std;
78
using std::filesystem::current_path;
89

910
int main(int argc, char *argv[]){
1011

11-
bool launch = false;
12-
13-
std::string path = argv[0];
14-
1512
std::filesystem::path exePath = std::filesystem::absolute(std::filesystem::path(argv[0]));
1613

1714
std::filesystem::path exeDir = exePath.parent_path();
1815

1916
filesystem::path directoryPath = exeDir;
20-
string stringpath = directoryPath.generic_string();
17+
string stringpath = directoryPath.generic_string();
18+
19+
if (argv[0] == "version")
20+
{
21+
22+
cout << "Version: 0.0.1 alpha" << endl;
23+
return 0;
24+
}
25+
26+
27+
if (argv[0] == "libinfo")
28+
{
29+
std::ifstream file;
30+
file.open(stringpath + "/lib/" + argv[1] + "/libinfo");
31+
if (file.is_open())
32+
{
33+
string line;
34+
while (getline(file, line))
35+
{
36+
cout << line << endl;
37+
}
38+
}
39+
40+
return 0;
41+
42+
}
43+
44+
45+
std::string path = argv[0];
2146

2247
string command = stringpath + "/python/python.exe" + " " + stringpath + "/compiler.py" + " " + argv[1];
2348

2449
system(command.c_str());
50+
2551
}

lexer.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import re
2-
from lib.wordlist import wordlist
3-
from lib.constants import constants
4-
from lib.libs import libs
5-
from lib.classes import buildintclasses
2+
from wordlist import wordlist
3+
from libparser import parcse_libs
4+
65
replacements = wordlist
76

87
variable_types = ['int', 'float', 'double', 'char', 'bool', 'string']
98
list_types = ['List', 'PPair']
109

10+
libs = parcse_libs()
1111

1212
def find_variables(tokens):
1313
variables = {}
@@ -40,7 +40,7 @@ def find_includes(tokens):
4040
for i in range(0, len(tokens)):
4141
if tokens[i] == 'friend':
4242
if tokens[i+1] in libs:
43-
tokens[i+1] = f'"{libs[tokens[i+1]]}.h"'
43+
tokens[i+1] = f'"{tokens[i+1]}.h"'
4444
else: tokens[i+1] = f'"{tokens[i+1]}.h"'
4545
includes.append(tokens[i+1])
4646

@@ -67,15 +67,13 @@ def find_classes(tokens:list):
6767
return classes, tokens
6868

6969
def translate_tokens(tokens, variables, classes:list):
70-
for i in buildintclasses:
71-
classes.append(i)
7270
includes = find_includes(tokens)
7371
for i in range(0, len(tokens)):
7472
try:
7573
if tokens[i] in variables:
76-
print(tokens[i])
74+
pass
7775
else:
78-
if tokens[i+1] != '(' and tokens[i] not in variables and tokens[i] not in list_types and tokens[i] not in includes and tokens[i] != '\n' and tokens[i] not in ['+', '-', '*', '/', '=', '.', ',', ';', '(', ')', '[', ']', '{', '}', ':', '<', '>'] and not tokens[i].startswith('"') and not tokens[i].endswith('"') and not tokens[i].isdigit() and tokens[i] not in classes and tokens[i] not in constants and not tokens[i].startswith('<') and not tokens[i].endswith('>'):
76+
if tokens[i+1] != '(' and tokens[i] not in variables and tokens[i] not in list_types and tokens[i] not in includes and tokens[i] != '\n' and tokens[i] not in ['+', '-', '*', '/', '=', '.', ',', ';', '(', ')', '[', ']', '{', '}', ':', '<', '>'] and not tokens[i].startswith('"') and not tokens[i].endswith('"') and not tokens[i].isdigit() and tokens[i] not in classes and not tokens[i].startswith('<') and not tokens[i].endswith('>'):
7977
if tokens[i] in replacements:
8078
tokens[i] = replacements[tokens[i]]
8179
else:

lib/classes.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/constants.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)