aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-15 22:13:24 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-15 22:13:24 +0300
commit1a38462fbefd58cc7aff98f28520152e37c5ae55 (patch)
treed168a4d53991bbd65c20f18bc2b92d39913d3830
parent95e69fb5d1c3c47650c4df38d3fc62c7f0eed9c1 (diff)
downloadmyslip-1a38462fbefd58cc7aff98f28520152e37c5ae55.tar.gz
myslip-1a38462fbefd58cc7aff98f28520152e37c5ae55.zip
feat: standard library & loading it by default
-rw-r--r--src/main.rs7
-rw-r--r--stdlib.slip21
2 files changed, 27 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 639e675..2e9ee5f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -38,9 +38,10 @@ fn main() {
let mut file_to_execute: Option<String> = None;
- let mut bind_files: Vec<String> = vec![];
+ let mut bind_files: Vec<String> = vec!["stdlib.slip".to_string()];
let mut next_is_load = false;
+ let mut no_stdlib = false;
for arg in env::args() {
if next_is_load {
@@ -52,6 +53,7 @@ fn main() {
match arg.as_str() {
s if s.ends_with("myslip") => continue,
"-l" | "--load" => next_is_load = true,
+ "--no-stdlib" => no_stdlib = true,
s => match file_to_execute {
Some(n) => {
println!("Error: can't execute both '{}' and '{}', please specify just one file", s, n);
@@ -68,6 +70,9 @@ fn main() {
);
return;
}
+ if no_stdlib {
+ bind_files.remove(0);
+ }
let binds = match read_bind_files(bind_files) {
Ok(x) => x,
diff --git a/stdlib.slip b/stdlib.slip
new file mode 100644
index 0000000..9e20c64
--- /dev/null
+++ b/stdlib.slip
@@ -0,0 +1,21 @@
+(let if
+ (fn (cond iftrue iffalse) (Bool T T) T
+ (case cond
+ (true iftrue)
+ (_ iffalse))
+ )
+)
+
+
+(let ++
+ (fn x Int Int
+ (+ x 1)
+ )
+)
+
+
+(let --
+ (fn x Int Int
+ (- x 1)
+ )
+) \ No newline at end of file