Skip to content

Commit d8b7b4e

Browse files
committed
Builtin port 1
1 parent dc2c9c5 commit d8b7b4e

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

stroll/lib/core.sr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
(fn print value
22
(native "print(value)")
3+
)
4+
(fn scan prompt
5+
(native "input(prompt)")
36
)

stroll/lib/fileIO.sr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(fn )
1+
(fn readFile)

stroll/src/newstdIO.sr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(use "std" "core")
2+
3+
(call print (+ "a" "b"))
4+
(let x (call scan "Name:"))
5+
(call print x)

stroll/src/runtime.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def import_module(kind: str, name: str, env: dict, here_file: str) -> str:
4444
NATIVE_GLOBALS = {
4545
"__builtins__": {
4646
"print": builtins.print,
47+
"input": builtins.input,
4748
"len": builtins.len,
4849
"range": builtins.range,
4950
"abs": builtins.abs,
@@ -63,11 +64,11 @@ def evaluate(ast, env=None):
6364
env = {}
6465

6566
KW = [
66-
"*", "/", "-", "+", "let", "print", "scan", "if", "elif", "else", "while",
67+
"*", "/", "-", "+", "let", "if", "elif", "else", "while",
6768
"list", "append", "index", ">", "<", ">=", "<=", "==", "!=",
6869
"true", "false", "&", "|", "sqrt", "pow", "mod", "abs",
6970
"len", "reverse", "concat", "strlen", "substr",
70-
"fn", "call", "native", "use"
71+
"fn", "call", "native", "use", "return"
7172
]
7273

7374
E = lambda x: evaluate(x, env)
@@ -98,6 +99,8 @@ def evaluate(ast, env=None):
9899
if token == "&": return bool(E(ast[idx + 1]) and E(ast[idx + 2]))
99100
if token == "|": return bool(E(ast[idx + 1]) or E(ast[idx + 2]))
100101

102+
if token == "return": return E(ast[idx + 1])
103+
101104
# --- Variables ---
102105
if token == "let":
103106
name = ast[idx + 1]
@@ -156,6 +159,7 @@ def evaluate(ast, env=None):
156159
return s[start:end]
157160

158161
# --- I/O ---
162+
"""
159163
if token == "print":
160164
value = E(ast[idx + 1])
161165
print(value)
@@ -164,6 +168,7 @@ def evaluate(ast, env=None):
164168
if token == "scan":
165169
prompt = E(ast[idx + 1])
166170
return input(prompt)
171+
"""
167172

168173
# --- Control Flow ---
169174
if token == "if":

0 commit comments

Comments
 (0)