Hayblock versions/0.1.0 Beta 1

code = open("code.txt","r").read.split("\n") logs = [] doing = 0 module = "" command = "" params = []

showerrors = True errorcount = 0 ram = [] vars = {} lockedvars = [] imported = [] posmodules = ["sys","math","var"]

def log(message): logs.append(f"At line {doing + 1}: {message}")

def error(message): log(f"Error at line {doing + 1}: {message}") global errorcount errorcount += 1 if showerrors: print(f"Error at line {doing + 1}:\n {message}")

str0to9 = ["0","1","2","3","4","5","6","7","8","9"]

def isNumber(tocheck): hasdecimals = False for i in range(len(str(tocheck))): if not str(tocheck)[i] in str0to9: if str(tocheck)[i] == ".": hasdecimals = True else: return "nan" if hasdecimals: return "decimal" else: return "whole"

def getVar(varname): if varname in vars: return vars[varname] else: error(f"Attempted to get data in variable {varname}, which doesn't exist.")

def getType(tocheck): if str(tocheck)[0] == "\"":   return "string"  elif str(tocheck)[0] == "-":    return "varinput"  elif tocheck == "true" or tocheck == "false":    return "bool"  elif isNumber(tocheck) == "whole" or isNumber(tocheck) == "decimal":    return "number"  else:    return "invalid"

def tify(list): return ", ".join(list)

def param(num): # Use param(0) instead of params[0] try: if len(params[num]) < 1: error(f"Expected positional parameter {num + 1}, but nothing found.") else: return params[num] except IndexError: error(f"Expected positional parameter {num + 1}, but nothing found.")

def checkParam(wanted,tocheck): if getType(tocheck) == "string": if "string" in wanted: return tocheck[1:] else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.") elif getType(tocheck) == "bool": if "bool" in wanted: return tocheck else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.") elif getType(tocheck) == "number": if "number" in wanted: return tocheck else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.") elif getType(tocheck) == "varinput": return getVar(tocheck[1:]) else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.")


 * 1) Start main code

while len(code) > doing: if len(code[doing].replace(" ","")) < 1: log("A blank line has been skipped over.") doing += 1 elif f"{code[doing][0]}{code[doing][1]}" == "#-": log("A comment has been skipped over.") doing += 1 else: params = code[doing].split(".") try: module = params.pop(0) except IndexError: error("No module is found.") try: command = params.pop(0) except IndexError: error("No command is found.") if module in imported:

if module == "sys": if command == "print": print(checkParam(["string"],param(0))) elif module == "var": slr1 = checkParam(["string"],param(0)) if command == "create": if slr1 in vars: error(f"Variable {slr1} already exists.") else: vars[slr1] = "" elif command == "edit": if slr1 in lockedvars: error(f"Attempted to edit locked variable {slr1}.") elif slr1 in vars: vars[slr1] = checkParam(["string"],param(1)) else: error(f"Attempted to edit variable {slr1}, which doesn't exist.") elif command == "lock": if slr1 in lockedvars: error(f"Attempted to lock variable {slr1}, but it is already locked.") elif slr1 in vars: lockedvars.append(checkParam(["string"],param(0))) else: error(f"Attempted to lock variable {slr1}, but it doesn't exist.") elif command == "unlock": if slr1 in lockedvars: lockedvars.remove(checkParam(["string"],param(0))) elif slr1 in vars: error(f"Attempted to unlock variable {slr1}, but it is already unlocked.") else: error(f"Attempted to unlock variable {slr1}, but it doesn't exist.") elif command == "delete": if slr1 in lockedvars: error(f"Attempted to delete locked variable {slr1}.") elif slr1 in vars: del vars[slr1] else: error(f"Attempted to delete variable {slr1}, but it doesn't exist.")

elif module == "import": if command in imported: error(f"Module {command} can't be imported again because it is already imported.") elif command in posmodules: imported.append(command) else: error(f"Module {command} can't be imported because it doesn't exist.") elif module in posmodules: error(f"Module {module} is not imported.") else: error(f"Module {module} is not imported and doesn't exist.") doing += 1