Skip to content

Commit 48adca9

Browse files
committed
feat: support thread run func
1 parent ea21a1a commit 48adca9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

interpreter/src/evaluator/builtins.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ fn three_body_threading(args: Vec<Object>) -> Object {
365365
{
366366
fn three_body_thread_new(args: Vec<Object>) -> Object {
367367
match &args[0] {
368-
Object::String(input) => {
369-
let input = (*input).clone();
368+
Object::Function(params, ast, env ) => {
370369

370+
let stmts = ast.clone();
371371
let mut handle = std::thread::spawn(move || {
372372
let local_set = tokio::task::LocalSet::new();
373373
let rt = tokio::runtime::Builder::new_current_thread()
@@ -376,7 +376,12 @@ fn three_body_threading(args: Vec<Object>) -> Object {
376376
.unwrap();
377377

378378
// 在 LocalSet 中安排任务
379-
local_set.spawn_local(async move { eval(&input) });
379+
local_set.spawn_local(async move {
380+
let mut ev = evaluator::Evaluator {
381+
env: Rc::new(RefCell::new(evaluator::env::Env::from(new_builtins()))),
382+
};
383+
ev.eval(&stmts);
384+
});
380385

381386
// 运行 LocalSet 直到其中的任务完成
382387
rt.block_on(local_set);
@@ -385,7 +390,7 @@ fn three_body_threading(args: Vec<Object>) -> Object {
385390
let handle = Box::leak(Box::new(handle));
386391
let handle_ptr = &mut *handle as *mut std::thread::JoinHandle<()>;
387392
Object::Native(Box::new(NativeObject::Thread(handle_ptr)))
388-
},
393+
}
389394
_ => panic!()
390395
}
391396
}

0 commit comments

Comments
 (0)