Hayblock versions/0.1.0 Beta 1.5

import random import time import datetime import requests import re
 * 1) Imports

code = open("code.txt","r").read.split("\n") logs = [] doing = 0 module = "" command = "" params = []
 * 1) Get code and define helper vars

showerrors = True errorcount = 0 ram = [] vars = {} lockedvars = [] imported = []
 * 1) Define more vars

posmodules = ["sys","var","math","tt","datetime","web","os","lang"]
 * 1) Define possible modules

def log(message): logs.append(f"At line {doing + 1}: {message}")
 * 1) Generic log and error functions

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"]
 * 1) Is number checker

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.")
 * 1) Get variable

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"
 * 1) Get type of variable

def tify(list): return ", ".join(list)
 * 1) Join list into commas

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.")
 * 1) Get param/params

def funcReturn(message): print(f"A function returned: {message}") # Temporary
 * 1) Get what the function returned

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) Check parameter types and count

monthnames = { 1:"January", 2:"Febuary", 3:"March", 4:"April", 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", 12:"December", } downames = { 0:"Monday", 1:"Tuesday", 2:"Wednesday", 3:"Thursday", 4:"Friday", 5:"Saturday", 6:"Sunday", }
 * 1) Utility dicts


 * 1) Start main loop

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 == "math": # Mostly generated by copilot slr1 = checkParam(["string"],param(0)) if command == "add": funcReturn(slr1 + checkParam(["number"],param(1))) elif command == "subtract": funcReturn(slr1 - checkParam(["number"],param(1))) elif command == "multiply": funcReturn(slr1 * checkParam(["number"],param(1))) elif command == "divide": funcReturn(slr1 / checkParam(["number"],param(1))) elif command == "modulo": funcReturn(slr1 % checkParam(["number"],param(1))) elif command == "power": funcReturn(slr1 ** checkParam(["number"],param(1))) elif command == "infinity": funcReturn("9" * 260) # Temporary elif command == "floor": funcReturn(math.floor(slr1)) elif command == "ceil": funcReturn(math.ceil(slr1)) elif command == "round": funcReturn(round(slr1)) elif command == "random": funcReturn(random.randint(slr1,checkParam(["number"],param(1)))) elif command == "pi": funcReturn(math.pi) elif command == "euler": funcReturn(math.e)       elif command == "tau": funcReturn(math.tau) elif command == "sin": funcReturn(math.sin(slr1)) elif command == "cos": funcReturn(math.cos(slr1)) elif command == "tan": funcReturn(math.tan(slr1)) elif command == "asin": funcReturn(math.asin(slr1)) elif command == "acos": funcReturn(math.acos(slr1)) elif command == "atan": funcReturn(math.atan(slr1)) elif command == "factorial": funcReturn(math.factorial(slr1)) elif command == "abs": funcReturn(math.fabs(slr1)) elif command == "deg": funcReturn(math.degrees(slr1))

elif module == "tt": # TT = text tools = string module, most of the module is github copilot generated slr1 = checkParam(["string"],param(0)) if command == "length": funcReturn(len(slr1)) elif command == "upper": funcReturn(slr1.upper) elif command == "lower": funcReturn(slr1.lower) elif command == "sub": funcReturn(slr1[checkParam(["number"],param(1)):checkParam(["number"],param(2))]) elif command == "replace": funcReturn(slr1.replace(checkParam(["string"],param(1)),checkParam(["string"],param(2)))) elif command == "upfirst": funcReturn(slr1.capitalize) elif command == "upwords": funcReturn(slr1.title) elif command == "wrap": while " " in slr1: slr1 = slr1.replace(" "," ") funcReturn(slr1) elif command == "split": funcReturn(slr1.split(checkParam(["string"],param(1)))) elif command == "count": funcReturn(slr1.count(checkParam(["string"],param(1)))) elif command == "startswith": funcReturn(slr1.startswith(checkParam(["string"],param(1)))) elif command == "endswith": funcReturn(slr1.endswith(checkParam(["string"],param(1)))) elif command == "includes": funcReturn(slr1.find(checkParam(["string"],param(1))) != -1) elif command == "index": funcReturn(slr1.find(checkParam(["string"],param(1)))) elif command == "uplow": if slr1.islower: funcReturn("lower") elif slr1.isupper: funcReturn("upper") else: funcReturn("mixed") elif command == "isnum": funcReturn(slr1.isnumeric) elif command == "isblank": funcReturn(len(slr1.replace(" ","")) < 1) elif command == "findlast": funcReturn(slr1.rfind(checkParam(["string"],param(1)))) elif command == "swapcase": funcReturn(slr1.swapcase) elif command == "reverse": funcReturn(slr1[::-1]) elif command == "search": # Regex funcReturn(re.search(checkParam(["string"],param(1)),slr1)) elif command == "findall": # Another regex funcReturn(re.findall(checkParam(["string"],param(1)),slr1)) elif command == "split": # Even another regex funcReturn(re.split(checkParam(["string"],param(1)),slr1)) elif command == "sub": # Last regex funcReturn(re.sub(checkParam(["string"],param(1)),checkParam(["string"],param(2)),slr1))

elif module == "datetime": # Also mostly generated by copilot if command == "wait": time.sleep(checkParam(["number"],param(0))) elif command == "now": funcReturn(datetime.datetime.now) elif command == "timestamp": funcReturn(time.time) elif command == "century": funcReturn(datetime.datetime.now.year // 100) elif command == "decade": funcReturn(datetime.datetime.now.year // 10) elif command == "year": funcReturn(datetime.datetime.now.year) elif command == "month": funcReturn(datetime.datetime.now.month) elif command == "monthname": funcReturn(monthnames[datetime.datetime.now.month]) elif command == "week": funcReturn(datetime.datetime.now.isocalendar[1]) elif command == "dow": # Day of week funcReturn(datetime.datetime.now.weekday) elif command == "downame": funcReturn(downames[datetime.datetime.now.weekday]) elif command == "day": funcReturn(datetime.datetime.now.day) elif command == "hour": funcReturn(datetime.datetime.now.hour) elif command == "minute": funcReturn(datetime.datetime.now.minute) elif command == "second": funcReturn(datetime.datetime.now.second) elif command == "ms": funcReturn(datetime.datetime.now.microsecond) elif command == "format": funcReturn(datetime.datetime.now.strftime(checkParam(["string"],param(0)))) elif module == "web": slr1 = checkParam(["string"],param(0)) if command == "get": slr2 = requests.get(slr1) funcReturn(slr2.text) elif command == "extract": funcReturn(re.search("(?P https?://[^\s]+)",slr1).group("url")) elif command == "extractall": funcReturn(re.findall("(?P https?://[^\s]+)",slr1).group("url"))

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