Skip to content

Commit

Permalink
feat: set correct env scope and add threading safe ci
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Nov 4, 2024
1 parent 6f97356 commit 354bac1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/Threading.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ jobs:
- name: Threading Safe
run: |
./target/release/3body -c '给 cx 以 程心(); 给 执剑人 以 "程心女士"; 给 星环公司 以 法则(name, y, limit) { 给 掩体纪年 以 y; 面壁 (掩体纪年 <= limit) { 冬眠(1000); 广播([name, 掩体纪年, 执剑人]); 掩体纪年 = 掩体纪年 + 1; } } cx.thread(星环公司, ["掩体工程", 0, 11]) 冬眠(5000) cx.thread(星环公司, ["研制曲率飞船", 5, 11]) 冬眠(6000)'
./target/release/3body -c '
给 cx 以 程心();
给 掩体工程进展 以 0;
给 研制曲率飞船进展 以 0;

cx.thread(法则() {
给 掩体纪年 以 0;
面壁 (掩体纪年 <= 11) {
冬眠(1000);
广播(["掩体工程进展", 掩体工程进展]);
掩体工程进展 = 掩体工程进展 + 1;
掩体纪年 = 掩体纪年 + 1;
}
}, [])

冬眠(5000)

cx.thread(法则() {
给 掩体纪年 以 5;
面壁 (掩体纪年 <= 11) {
冬眠(1000);
广播(["研制曲率飞船进展", 研制曲率飞船进展]);
研制曲率飞船进展 = 研制曲率飞船进展 + 1;
掩体纪年 = 掩体纪年 + 1;
}
}, [])

冬眠(6000)
'
- name: Threading Unsafe
run: |
Expand Down
7 changes: 3 additions & 4 deletions interpreter/src/evaluator/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,18 @@ fn three_body_threading(_: Vec<Object>) -> Object {
Object::Function(params, stmts, env ) => {
let mut ev = Evaluator {
env: {
let scoped_env = env.clone();
let mut scoped_env = Env::new_with_outer(Rc::clone(&env));
let list = params.iter().zip({
match &args[1] {
Object::Array(arr) => arr,
_ => panic!()
}
}.iter());
let mut scoped_env_mut = scoped_env.borrow_mut();
for (_, (ident, o)) in list.enumerate() {
let ast::Ident(name) = ident.clone();
scoped_env_mut.set(name, o.clone());
scoped_env.set(name, o.clone());
}
scoped_env.clone()
Rc::new(RefCell::new(scoped_env))
},
};
ev.eval(&stmts);
Expand Down

0 comments on commit 354bac1

Please sign in to comment.