Skip to content

Commit 55b6ba1

Browse files
author
梶塚太智
committed
Develop multi thread system
1 parent e6b9811 commit 55b6ba1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

examples/thread.stk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
( (name) var
2+
1 4 1 range (i) (
3+
name i concat print
4+
0.7 sleep
5+
) for
6+
) (hey) var
7+
8+
((太郎) hey eval) thread
9+
((次郎) hey eval) thread
10+
(三郎) hey eval

src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use powershell_script::PsScriptBuilder;
22
use rand::seq::SliceRandom;
33
use std::collections::HashMap;
44
use std::env;
5+
use std::thread;
56
use std::fs::File;
67
use std::io::{self, Error, Read, Write};
78
use std::thread::sleep;
@@ -143,6 +144,7 @@ impl Type {
143144
}
144145

145146
/// プログラム実行を管理
147+
#[derive(Clone, Debug)]
146148
struct Executor {
147149
stack: Vec<Type>, // スタック
148150
memory: HashMap<String, Type>, // 変数のメモリ領域
@@ -564,6 +566,14 @@ impl Executor {
564566
}
565567
}
566568

569+
"thread" => {
570+
let code = self.pop_stack().get_string();
571+
let mut executor = self.clone();
572+
thread::spawn(move || {
573+
executor.evaluate_program(code)
574+
});
575+
}
576+
567577
// シェルコマンドを実行
568578
"shell" => {
569579
let ps = PsScriptBuilder::new()

0 commit comments

Comments
 (0)