Skip to content

Commit

Permalink
Merge pull request #30 from roblox-compilers/all-contributors/add-Ari…
Browse files Browse the repository at this point in the history
…f812

added safeloop function
  • Loading branch information
AsynchronousAI authored Apr 28, 2024
2 parents d43d46e + dba1fe1 commit f6f7f06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

TYPS = """""" # old
errs = ["ValueError", "TypeError", "AttributeError", "IndexError", "KeyError", "ZeroDivisionError", "AssertionError", "NotImplementedError", "RuntimeError", "NameError", "SyntaxError", "IndentationError", "TabError", "ImportError", "ModuleNotFoundError", "OSError", "FileNotFoundError", "PermissionError", "EOFError", "ConnectionError", "TimeoutError", "UnboundLocalError", "RecursionError", "MemoryError", "OverflowError", "FloatingPointError", "ArithmeticError", "ReferenceError", "SystemError", "SystemExit", "GeneratorExit", "KeyboardInterrupt", "StopIteration", "Exception", "BaseException", "Error"]
libs = ["class", "op_is", "dict", "list", "op_in", "safeadd", "__name__", "range", "len", "abs", "str", "int", "sum", "max", "min", "reversed", "split", "round", "all", "any", "ord", "chr", "callable", "float", "super", "format", "hex", "id", "map", "bool", "divmod", "slice", "anext", "ascii", "dir", "getattr", "globals", "hasattr", "isinstance", "issubclass", "iter", "locals", "oct", "pow", "eval", "exec", "filter", "frozenset", "aiter", "bin", "complex", "deltaattr", "enumerate", "bytearray", "bytes", "compile", "help", "memoryview", "repr", "sorted", "vars"]
libs = ["class", "op_is", "dict", "list", "op_in", "safeadd", "safeloop", "__name__", "range", "len", "abs", "str", "int", "sum", "max", "min", "reversed", "split", "round", "all", "any", "ord", "chr", "callable", "float", "super", "format", "hex", "id", "map", "bool", "divmod", "slice", "anext", "ascii", "dir", "getattr", "globals", "hasattr", "isinstance", "issubclass", "iter", "locals", "oct", "pow", "eval", "exec", "filter", "frozenset", "aiter", "bin", "complex", "deltaattr", "enumerate", "bytearray", "bytes", "compile", "help", "memoryview", "repr", "sorted", "vars"]

DEPENDENCY = """\n\n--> imports
py = _G.rbxpy or require(game.ReplicatedStorage.Packages.pyruntime)
Expand Down
18 changes: 13 additions & 5 deletions src/nodevisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def visit_Assign(self, node):
local_keyword = "local "
last_ctx["locals"].add_symbol(target)

if target in reserves:
error(f"'{target}'is a reserved Luau keyword.")
if target in reserves or target in libs.libs:
error(f"'{target}' is a reserved Luau keyword.")

self.emit("{local}{target} = {value}".format(local=local_keyword,
target=target,
Expand Down Expand Up @@ -564,12 +564,19 @@ def visit_FunctionDef(self, node):

def visit_For(self, node):
"""Visit for loop"""
line = "for {target} in {iter} do"


values = {
"target": self.visit_all(node.target, inline=True),
"iter": self.visit_all(node.iter, inline=True),
}

for x in libs.libs:
if x in values["iter"]:
line = "for {target} in {iter} do"
break
else:
line = "for {target} in safeloop({iter}) do"
continue

self.emit(line.format(**values))

Expand Down Expand Up @@ -1146,4 +1153,5 @@ def depend(self, value):
def get_dependencies(self):
return dependencies
def get_exports(self):
return exports
return exports

0 comments on commit f6f7f06

Please sign in to comment.