Beispiel #1
0
def load_script(path: str) -> List[str]:
    """Loads a *.RTLS into a `List[str]`."""
    log(f"Loading script from {path}...", LL_debug)
    file = open(path, "rt")
    script = file.readlines()
    file.close()
    return script
Beispiel #2
0
def run_code(code: Code) -> None:
    """Runs a `Code` object."""
    log("Running code...", LL_debug)
    if code == None:
        log("    Nothing to run.", LL_warning)
        return
    log(code, LL_debug)
    state = RunState(code)
    state.start()
Beispiel #3
0
def disassemble_code(code: Code) -> None:
    """Disassembles a `Code` object and prints the result to the terminal for debuging purposes."""
    log("Disassembling code...", LL_debug)
Beispiel #4
0
def save_script(script: List[str], path: str) -> None:
    """Saves an array of lines into a file (used for formatting)."""
    log(f"Saving script to {path}...", LL_debug)
    file = open(path, "wt")
    file.writelines(script)
    file.close()
Beispiel #5
0
def save_code(code: Code, path: str) -> None:
    """Serializes a `Code` object and saves it into a file."""
    log(f"Saving code to {path}...", LL_debug)
Beispiel #6
0
def format_script(script: List[str]) -> List[str]:
    """Formats script according to the chosen options."""
    log("Formating script...", LL_debug)
Beispiel #7
0
def run_script(script: List[str]) -> None:
    """Performs all the necessary steps to run a script (represented as a line array)."""
    log("Running script...", LL_debug)
    run_code(build_script(script))
Beispiel #8
0
def load_code(path: str) -> Code:
    """Loads a *.RTLS into a `Code` object."""
    log(f"Loading code from {path}...", LL_debug)
Beispiel #9
0
def build_script(script: List[str]) -> Code:
    """Builds a given script into bytecode."""
    log("Building script...", LL_debug)
    tokens = tokenize(script)
    return build_tokens(tokens)
Beispiel #10
0
    file.close()

def disassemble_code(code: Code) -> None:
    """Disassembles a `Code` object and prints the result to the terminal for debuging purposes."""
    log("Disassembling code...", LL_debug)


if __name__ == "__main__":
    args = sys.argv.copy()
    args.pop(0)
    
    if "-loglevel" in args:
        set_log_level(int(args[args.index("-loglevel") + 1]))
    
    if len(args) == 0:
        log("You passed no arguments to RTL_COMP, so it assumed, you need some help.", LL_output, 0)
        log("If you do, visit https://github.com/VojtechBrezina/RTLScript", LL_output, 0)
    else:
        if args[0] == "-build":
            path = args[1]
            script = Script(path)
            #TODO build sript
            if len(args) >= 4 and args[2] == "-path":
                path = args[3]
            else:
                path = ".".join(path.split(".")[:-1]) + ".RTLC"
            #TODO save the code
        else: #run
            path = args[0]
            if path.endswith(".RTLC"):
                pass #TODO run code