Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added new built-in functions including min, max, print, not, push-back#11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
rachana192837 wants to merge1 commit intostroll-script:main
base:main
Choose a base branch
Loading
fromrachana192837:feature/newfeatureiadded
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletionsstroll/src/runtime.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,7 +57,7 @@ def evaluate(ast, env=None):
"list", "append", "index", ">", "<", ">=", "<=", "==", "!=",
"true", "false", "&", "|", "sqrt", "pow", "mod", "abs",
"len", "reverse", "concat", "strlen", "substr",
"fn", "call", "native", "use", "return"
"fn", "call", "native", "use", "return","max","min","&","|","not","push-front","print","range"
] # we are transitioning from putting builtings in the KW to the core and lib folder

E = lambda x: evaluate(x, env) # lambda func cause it looks cool and does stuff xD
Expand DownExpand Up@@ -109,6 +109,9 @@ def evaluate(ast, env=None):
if token == "pow": return math.pow(E(ast[idx + 1]), E(ast[idx + 2]))
if token == "sqrt": return math.sqrt(E(ast[idx + 1]))
if token == "abs": return abs(E(ast[idx + 1]))
if token == "max": return max(E(ast[idx + 1]), E(ast[idx + 2]))
if token == "min": return min(E(ast[idx + 1]), E(ast[idx + 2]))


# comapritives
if token == ">": return E(ast[idx + 1]) > E(ast[idx + 2])
Expand All@@ -121,6 +124,8 @@ def evaluate(ast, env=None):
# logic
if token == "&": return bool(E(ast[idx + 1]) and E(ast[idx + 2]))
if token == "|": return bool(E(ast[idx + 1]) or E(ast[idx + 2]))
if token == "not": return not E(ast[idx + 1])


# return as in return
if token == "return": raise _Return(E(ast[idx + 1]))
Expand All@@ -132,6 +137,20 @@ def evaluate(ast, env=None):
env[name] = value
return (name, value)

if token == "push-front":
name = ast[idx + 1]
value = E(ast[idx + 2])
if not isinstance(env[name], list):
raise TypeError
env[name].insert(0, value)
return env[name]

#for print
if token == "print":
val = E(ast[idx + 1])
print(val)
return val

# Array stuff
# list for initiating a dynamic array
if token == "list":
Expand DownExpand Up@@ -293,7 +312,12 @@ def evaluate(ast, env=None):
exec(code, NATIVE_GLOBALS, native_locals)
env.update(native_locals)
return None

if token == "range":
args = [E(a) for a in ast[idx+1:]]
if len(args) == 1:
return list(range(args[0]))
return list(range(args[0], args[1]))

#finally out of kw hell
elif isinstance(ast, (int, float)):
return ast
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp