Skip to content

Commit 77be112

Browse files
committed
stuff
1 parent 85bdda0 commit 77be112

16 files changed

+296
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
/dist
3+
/build

BScript Compiler GUI.spec

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
a = Analysis(
5+
['bscript-gui.py'],
6+
pathex=[],
7+
binaries=[],
8+
datas=[],
9+
hiddenimports=[],
10+
hookspath=[],
11+
hooksconfig={},
12+
runtime_hooks=[],
13+
excludes=[],
14+
noarchive=False,
15+
optimize=0,
16+
)
17+
pyz = PYZ(a.pure)
18+
19+
exe = EXE(
20+
pyz,
21+
a.scripts,
22+
a.binaries,
23+
a.datas,
24+
[],
25+
name='BScript Compiler GUI',
26+
debug=False,
27+
bootloader_ignore_signals=False,
28+
strip=False,
29+
upx=True,
30+
upx_exclude=[],
31+
runtime_tmpdir=None,
32+
console=False,
33+
disable_windowed_traceback=False,
34+
argv_emulation=False,
35+
target_arch=None,
36+
codesign_identity=None,
37+
entitlements_file=None,
38+
icon=['assets/icon.icns'],
39+
)
40+
app = BUNDLE(
41+
exe,
42+
name='BScript Compiler GUI.app',
43+
icon='assets/icon.icns',
44+
bundle_identifier=None,
45+
)

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,15 @@ BScript is a coding language that is terrible.
44

55
[Read the documentation here.](docs/Basics.md)
66

7-
All you get is simple variables that can only be added or subtracted to (only one), basic loops, really nothings else. It's probably easier than Brainfuck, though.
7+
All you get is simple variables that can only be added or subtracted to (only one), basic loops, really nothings else. It's probably easier than Brainfuck, though.
8+
9+
Wow, that description is a little outdated.
10+
11+
## Installation
12+
13+
First of all, install [the latest version of Python](https://www.python.org/downloads/).
14+
15+
16+
Secondly, download the source code from here.
17+
18+
Now, finally, run the `setup.py` file inside of Python. It will ask for things and then you can use the `bsc` command to compile BScript files! Neat!
289 Bytes
Binary file not shown.

__pycache__/setup.cpython-313.pyc

3.2 KB
Binary file not shown.

assets/icon.icns

15.5 KB
Binary file not shown.

assets/icon.png

7.13 KB
Loading

bscript-cli.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import argparse
2+
from compiler import BScriptCompiler
3+
import setup
4+
5+
with open("splash.txt", "r") as f:
6+
message = f.read()
7+
8+
def main():
9+
parser = argparse.ArgumentParser(description="BScript Compiler CLI")
10+
parser.add_argument("--file", help="BScript source file (.bs) (optional)")
11+
parser.add_argument("--out", "-o", help="Output C file (optional)")
12+
parser.add_argument("--compile", "-c", help="Compile the C file as an executable (optional)")
13+
args = parser.parse_args()
14+
15+
if args.file:
16+
with open(args.file, "r") as f:
17+
code = f.read()
18+
19+
compiler = BScriptCompiler()
20+
c_code = compiler.transpile(code)
21+
22+
out_file = args.out if args.out else args.file.rsplit(".", 1)[0] + ".c"
23+
with open(out_file, "w") as f:
24+
f.write(c_code)
25+
26+
if args.compile:
27+
try:
28+
compiler.compile("output", args.file)
29+
except:
30+
ValueError("Failed to compile. This is some .bs.")
31+
32+
print(f"C code written to {out_file}")
33+
34+
else:
35+
print(message)
36+
print("\n")
37+
print("BScript Compiler CLI")
38+
print("\n")
39+
print("Usage:")
40+
print(" --file <file> BScript source file (.bs) (optional)")
41+
print(" --out <file> Output C file (optional)")
42+
print(" --compile Compile the C file as an executable (optional)")
43+
44+
if __name__ == "__main__":
45+
main()

bscript-gui.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import tkinter as tk
2+
from tkinter import filedialog, messagebox, scrolledtext
3+
import compiler as c
4+
import os
5+
import tempfile
6+
7+
def transpile_code():
8+
code = code_input.get("1.0", tk.END)
9+
compiler = c.BScriptCompiler()
10+
try:
11+
c_code = compiler.transpile(code)
12+
output.delete("1.0", tk.END)
13+
output.insert(tk.END, c_code)
14+
except Exception as e:
15+
messagebox.showerror("Error", str(e))
16+
17+
def save_c_code():
18+
c_code = output.get("1.0", tk.END)
19+
if not c_code.strip():
20+
messagebox.showwarning("Warning", "No C code to save.")
21+
return
22+
file_path = filedialog.asksaveasfilename(defaultextension=".c", filetypes=[("C Files", "*.c")])
23+
if file_path:
24+
with open(file_path, "w") as f:
25+
f.write(c_code)
26+
messagebox.showinfo("Saved", f"C code saved to {file_path}")
27+
28+
def load_bs_file():
29+
file_path = filedialog.askopenfilename(filetypes=[("BScript Files", "*.bs")])
30+
if file_path:
31+
with open(file_path, "r") as f:
32+
code = f.read()
33+
code_input.delete("1.0", tk.END)
34+
code_input.insert(tk.END, code)
35+
36+
def compile_c_code():
37+
c_code = output.get("1.0", tk.END)
38+
if not c_code.strip():
39+
messagebox.showwarning("Warning", "No C code to compile.")
40+
return
41+
42+
# Save C code to a temporary file
43+
with tempfile.NamedTemporaryFile(delete=False, suffix=".c") as tmp_c:
44+
tmp_c.write(c_code.encode())
45+
c_file = tmp_c.name
46+
47+
# Ask user where to save the compiled binary
48+
output_path = filedialog.asksaveasfilename(defaultextension="", filetypes=[("Executable", "")])
49+
if not output_path:
50+
os.remove(c_file)
51+
return
52+
53+
compiler = c.BScriptCompiler()
54+
try:
55+
compiler.compile(c_file, output_path)
56+
messagebox.showinfo("Success", f"Compiled successfully to {output_path}")
57+
except Exception as e:
58+
messagebox.showerror("Compile Error", str(e))
59+
finally:
60+
os.remove(c_file)
61+
62+
root = tk.Tk()
63+
root.title("BScript Compiler GUI")
64+
65+
tk.Button(root, text="Load BScript File", command=load_bs_file).pack(pady=5)
66+
67+
tk.Label(root, text="BScript Code:").pack(anchor="w")
68+
code_input = scrolledtext.ScrolledText(root, width=60, height=15)
69+
code_input.pack(padx=10, pady=5)
70+
71+
tk.Button(root, text="Transpile to C", command=transpile_code).pack(pady=5)
72+
73+
tk.Label(root, text="Generated C Code:").pack(anchor="w")
74+
output = scrolledtext.ScrolledText(root, width=60, height=15)
75+
output.pack(padx=10, pady=5)
76+
77+
tk.Button(root, text="Save C Code", command=save_c_code).pack(pady=5)
78+
79+
tk.Button(root, text="Compile C Code", command=compile_c_code).pack(pady=5)
80+
81+
root.mainloop()

bscript.py

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

0 commit comments

Comments
 (0)