Skip to content

Commit 687267a

Browse files
author
梶塚太智
authored
Merge pull request #12 from rensatopc/main
add command "index"
2 parents 3214f49 + b86373c commit 687267a

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Cargo.lock
1212

1313
# MSVC Windows builds of rustc generate these, which store debugging information
1414
*.pdb
15+
16+
hidden/

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ The powerful script language designed with a stack oriented approach for efficie
55

66
## Install
77

8+
### If you don't want to install...
9+
10+
```bash
11+
git clone https://github.com/Stack-Programing-Community/Stack-Programing-Language.git
12+
cd Stack-Programing-Language
13+
cargo build --release
14+
chmod +x ./run.stack.sh
15+
./run-stack.sh
16+
```
17+
18+
### Normal Install
19+
820
Stack programming language's interpreter binary files for Windows are in the [release](https://github.com/Stack-Programing-Community/Stack-Programing-Language/releases).
921

1022
the releases are Regularly when new function become stable, that's good way if you prize safety.

mylibrary/clone.stk

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

mylibrary/queue.stk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(
2+
(mode) var
3+
(item) var
4+
5+
(
6+
7+
)
8+
()
9+
mode equals (push)
10+
item
11+
) (queue) var

mysrc/stackprogramminglanguage.stk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(
2+
3+
(Welcome to...) print
4+
5+
(Stack) () true if
6+
7+
((str) var [str (ming)] () join) func var
8+
(Program) func eval
9+
10+
[(Lang) (uage) (fake)] l var
11+
l 0 get
12+
l 1 get
13+
(b) var
14+
(a) var
15+
[a b] () join
16+
17+
(a) var
18+
(b) var
19+
(c) var
20+
[c b a] ( ) join (a) var
21+
[a (!)] () join print
22+
23+
) (do) var
24+
do eval

run-stack.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
cd "$(dirname $0)"
4+
./target/release/stack $@

src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,20 @@ impl Executor {
12771277
})
12781278
}
12791279

1280+
"index" => {
1281+
let findhint = self.pop_stack().get_string();
1282+
let findtarget = self.pop_stack().get_list();
1283+
1284+
for index in 0..(findtarget.len()) {
1285+
if findhint == findtarget[index].clone().get_string() {
1286+
self.stack.push(Type::Number(index as f64));
1287+
return;
1288+
}
1289+
}
1290+
self.log_print(String::from("Error! item not found in this list").as_str().to_owned() + "\n");
1291+
self.stack.push(Type::Error(String::from("item-not-found")));
1292+
}
1293+
12801294
// If it is not recognized as a command, use it as a string.
12811295
_ => self.stack.push(Type::String(command)),
12821296
}

0 commit comments

Comments
 (0)