mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
updated a bunch of stuff
This commit is contained in:
parent
660464638f
commit
67bb5fe8fd
24 changed files with 683 additions and 702 deletions
|
|
@ -11,14 +11,19 @@ use super::{Runtime, Value};
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LoxFunction {
|
||||
name: String,
|
||||
name: Box<str>,
|
||||
closure: Scope,
|
||||
param_names: Vec<String>,
|
||||
param_names: Vec<Box<str>>,
|
||||
body: Box<Stmt>,
|
||||
}
|
||||
|
||||
impl LoxFunction {
|
||||
pub fn new(name: impl Into<String>, closure: Scope, param_names: Vec<String>, body: Stmt) -> Rc<Self> {
|
||||
pub fn new(
|
||||
name: impl Into<Box<str>>,
|
||||
closure: Scope,
|
||||
param_names: Vec<Box<str>>,
|
||||
body: Stmt,
|
||||
) -> Rc<Self> {
|
||||
let name = name.into();
|
||||
let body = Box::new(body);
|
||||
let fun = LoxFunction {
|
||||
|
|
@ -38,7 +43,7 @@ impl LoxFunction {
|
|||
&self.closure
|
||||
}
|
||||
|
||||
pub fn param_names(&self) -> &[String] {
|
||||
pub fn param_names(&self) -> &[Box<str>] {
|
||||
&self.param_names
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +55,7 @@ impl LoxFunction {
|
|||
self.param_names().len()
|
||||
}
|
||||
|
||||
pub fn inject_closed_var(&mut self, name: impl Into<String>, value: Value) {
|
||||
pub fn inject_closed_var(&mut self, name: impl Into<Box<str>>, value: Value) {
|
||||
let name = name.into();
|
||||
let heaped_value = HeapedValue::new(value);
|
||||
self.closure.insert(name, heaped_value);
|
||||
|
|
@ -88,7 +93,11 @@ impl LoxExternFunction {
|
|||
pub fn new(name: impl Into<String>, arity: usize, closure: ExternFunClosure) -> Self {
|
||||
let name = name.into();
|
||||
|
||||
LoxExternFunction { name, arity, closure }
|
||||
LoxExternFunction {
|
||||
name,
|
||||
arity,
|
||||
closure,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue