Savtis 2 years ago
parent
commit
59b01bac8b

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+*.*
+!*.py
+!*.c
+test.c
+!.gitignore
+!LICENSE
+!README.md
+__pycache__/

+ 2 - 1
README.md

@@ -1,2 +1,3 @@
-# lol_build
+# OMBS
+## One More Build System
 

+ 22 - 0
src/main.py

@@ -0,0 +1,22 @@
+#!/usr/bin/python3
+
+def main():
+    import sys
+    import os
+    sys.path.append('ombs_src')
+    import output
+    import error_class
+    import error_list
+    output.color_println('cyan', output.LOGO)
+    if len(sys.argv) < 2:
+        error_class.call_error('script_not_specified')
+    import script_loader as sl
+    sl.loader(sys.argv[1])
+    import cdll_class
+    import ctypes
+    a = cdll_class.C_Library('./lib.so', ctypes.c_int)
+    print(a.main())
+
+
+if __name__ == '__main__':
+    main()

+ 0 - 0
src/ombs_src/c/lexer.c


+ 0 - 0
src/ombs_src/py/__init__.py


+ 10 - 0
src/ombs_src/py/cdll_class.py

@@ -0,0 +1,10 @@
+from ctypes import *
+
+class C_Library(object):
+    def __init__(self, path:str, retype:type(c_int)):
+        self.path:str = path
+        self.lib:_DLLT = cdll.LoadLibrary(path)
+        self.lib.main.restype = retype
+        self.func:CDLL = self.lib.main
+    def main(self, *args):
+        return self.func(*args)

+ 40 - 0
src/ombs_src/py/error_class.py

@@ -0,0 +1,40 @@
+from output import *
+import sys
+
+error_list: dict = {}
+
+
+class Error(object):
+    line: int = -1
+    column: int = -1
+    error_id: int = 1
+    curr_token_list: list = []
+    has_occur: bool = False
+
+    def __init__(self, text: str, is_code_error: bool):
+        self.text = text
+        self.is_code_error = is_code_error
+        self.id = Error.error_id
+        Error.error_id += 1
+
+    def call(self):
+        Error.has_occur = True
+        color_println('red', self.text)
+        if self.is_code_error:
+            color_println('red', f'line = {self.line}')
+            for i in range(len(Error.curr_token_list)):
+                if i == self.column:
+                    color_print('red', Error.curr_token_list[i], True)
+                else:
+                    color_print('red', Error.curr_token_list[i])
+                print(' ', end='')
+            print()
+        exit(self.id)
+
+
+def add_error(name: str, text: str, is_code_error: bool = False):
+    error_list.update({name: Error(text, is_code_error)})
+
+
+def call_error(name: str):
+    error_list[name].call()

+ 4 - 0
src/ombs_src/py/error_list.py

@@ -0,0 +1,4 @@
+from error_class import add_error
+
+add_error('file_not_found', 'cannot find file')
+add_error('script_not_specified', 'script file not specified')

+ 33 - 0
src/ombs_src/py/output.py

@@ -0,0 +1,33 @@
+LOGO = """   _____            _                      
+  / ____|          | |                     
+ | |    _   _ _ __ | | __ _ _ __ __ ___  __
+ | |   | | | | '_ \| |/ _` | '__/ _` \ \/ /
+ | |___| |_| | |_) | | (_| | | | (_| |>  < 
+  \_____\__,_| .__/|_|\__,_|_|  \__,_/_/\_\\
+             | |                           
+   ____  __  | |____   _____               
+  / __ \|  \/  |  _ \ / ____|              
+ | |  | | \  / | |_) | (___                
+ | |  | | |\/| |  _ < \___ \               
+ | |__| | |  | | |_) |____) |              
+  \____/|_|  |_|____/|_____/                 
+"""
+
+COLOR_CODES = {
+    "red": 31,
+    "green": 32,
+    "yellow": 33,
+    "blue": 34,
+    "magenta": 35,
+    "cyan": 96
+}
+
+
+def color_print(color_name: str, text: str, underline: bool = False):
+    print(
+        f'\033[{4 if underline else ""};{COLOR_CODES[color_name]}m{text}\033[0m', end='')
+
+
+def color_println(color_name: str, text: str, underline: bool = False):
+    color_print(color_name, text, underline)
+    print()

+ 13 - 0
src/ombs_src/py/script_loader.py

@@ -0,0 +1,13 @@
+from error_class import call_error
+from output import *
+
+
+def loader(path: str):
+    lines = None
+    try:
+        with open(path, 'r') as code_file:
+            lines = code_file.readlines()
+    except FileNotFoundError:
+        call_error('file_not_found')
+    color_println('green', f'{path} is loaded')
+    return lines