Skip to content

Commit a30f13a

Browse files
committed
Core lib construction underway and call less functions underway.
1 parent d8b7b4e commit a30f13a

6 files changed

Lines changed: 24 additions & 5 deletions

File tree

stroll/lib/core.sr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
(native "print(value)")
33
)
44
(fn scan prompt
5-
(native "input(prompt)")
5+
(return (native "input(prompt)"))
66
)

stroll/lib/fileIO.sr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
(fn readFile)
1+
(fn readFile filename
2+
(native 'open(filename, "r").read()')
3+
)
4+
5+
(fn writeFile filename|content
6+
(native 'open(filename, "w").write(content)')
7+
)

stroll/lib/string.sr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(fn )

stroll/src/runtime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def import_module(kind: str, name: str, env: dict, here_file: str) -> str:
5151
"min": builtins.min,
5252
"max": builtins.max,
5353
"sum": builtins.sum,
54+
"open":builtins.open,
5455
},
5556
"math": math,
5657
}
@@ -78,7 +79,9 @@ def evaluate(ast, env=None):
7879

7980
for idx, token in enumerate(ast):
8081
if token not in KW:
81-
continue
82+
if token in env:
83+
if _is_lang_fn(env[token]):
84+
8285

8386
if token == "*": return E(ast[idx + 1]) * E(ast[idx + 2])
8487
if token == "/": return E(ast[idx + 1]) / E(ast[idx + 2])

stroll/tests/fileIO.sr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(use "std" "core")
2+
(use "std" "fileIO")
3+
4+
(let name (call scan "filename?"))
5+
(call print (call readFile name))
6+
7+
(call writeFile "newfile.sr" "NEW CONTENT YAy")
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(use "std" "core")
22

3-
(call print (+ "a" "b"))
43
(let x (call scan "Name:"))
5-
(call print x)
4+
(call print x)
5+
(call print (+ "a" "b"))
6+
7+
(print (call scan "Name-"))

0 commit comments

Comments
 (0)