Files
aster/aster-core/src/runtime/builtins/mod.rs
T
0264408andClaude fa6ea512b3 refactor: VM-only architecture — remove tree-walking interpreter
Eliminate dual-engine architecture (Interpreter + Vm) in favor of
a single bytecode VM executor.

- Extract shared types (Value, FunctionProto, Closure, UpvalueObj,
  Runtime trait, NativeFn) into new  module
- Consolidate builtin registration in  — single
   used by VM, eliminates 40-line duplicate
- Delete tree-walker: exec.rs, eval.rs, interpreter.rs, env.rs, module.rs
- Change Value::Function(Rc<Function>) → Value::Function(Rc<Closure>)
  eliminating the closures HashMap pointer-key hack
- Fix VM semantic gaps found during migration:
  * Structural equality for Object/Array in is_equal
  * CompoundAssignGlobal opcode (global compound assigns were broken)
  * 9 string methods added to VM get_property
  * ForInInit error on non-iterable values
- Switch run_file/run_repl to VM; remove --vm CLI flag
- Move 327 tests from interpreter/ to vm/ — all pass

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-26 10:31:32 +08:00

46 lines
2.0 KiB
Rust

//! Builtin function modules.
pub mod core;
pub mod io;
pub mod os;
pub mod string;
use crate::runtime::Value;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
/// Register all standard library functions into a HashMap.
pub fn register_all(map: &mut HashMap<String, Value>) {
// io
let mut io_map = HashMap::new();
io_map.insert("print".into(), Value::NativeFunction(Rc::new(io::print)));
io_map.insert("input".into(), Value::NativeFunction(Rc::new(io::input)));
map.insert("io".into(), Value::Object(Rc::new(RefCell::new(io_map))));
map.insert("print".into(), Value::NativeFunction(Rc::new(io::print)));
map.insert("input".into(), Value::NativeFunction(Rc::new(io::input)));
// os
let mut os_map = HashMap::new();
os_map.insert("clock".into(), Value::NativeFunction(Rc::new(os::clock)));
map.insert("os".into(), Value::Object(Rc::new(RefCell::new(os_map))));
map.insert("clock".into(), Value::NativeFunction(Rc::new(os::clock)));
// core
map.insert("len".into(), Value::NativeFunction(Rc::new(core::len)));
map.insert("typeof".into(), Value::NativeFunction(Rc::new(core::typeof_fn)));
map.insert("push".into(), Value::NativeFunction(Rc::new(core::push)));
map.insert("pop".into(), Value::NativeFunction(Rc::new(core::pop)));
// string
map.insert("split".into(), Value::NativeFunction(Rc::new(string::split)));
map.insert("trim".into(), Value::NativeFunction(Rc::new(string::trim)));
map.insert("substring".into(), Value::NativeFunction(Rc::new(string::substring)));
map.insert("replace".into(), Value::NativeFunction(Rc::new(string::replace)));
map.insert("contains".into(), Value::NativeFunction(Rc::new(string::contains)));
map.insert("upper".into(), Value::NativeFunction(Rc::new(string::upper)));
map.insert("lower".into(), Value::NativeFunction(Rc::new(string::lower)));
map.insert("starts_with".into(), Value::NativeFunction(Rc::new(string::starts_with)));
map.insert("ends_with".into(), Value::NativeFunction(Rc::new(string::ends_with)));
}