Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced the String in Token with &'a str #559

Merged
merged 10 commits into from
Sep 11, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.DS_Store
17 changes: 8 additions & 9 deletions numbat-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,11 @@ impl Cli {
}),
};

let (result, registry) = {
let mut ctx = self.context.lock().unwrap();
let registry = ctx.dimension_registry().clone(); // TODO: get rid of this clone
(
ctx.interpret_with_settings(&mut settings, input, code_source),
registry,
)
};
let result =
self.context
.lock()
.unwrap()
.interpret_with_settings(&mut settings, input, code_source);

let interactive = execution_mode == ExecutionMode::Interactive;

Expand Down Expand Up @@ -504,9 +501,11 @@ impl Cli {
println!();
}

let ctx = self.context.lock().unwrap();
let registry = ctx.dimension_registry();
let result_markup = interpreter_result.to_markup(
statements.last(),
&registry,
registry,
interactive || pretty_print,
interactive || pretty_print,
);
Expand Down
2 changes: 1 addition & 1 deletion numbat/src/ffi/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) fn functions() -> &'static HashMap<String, ForeignFunction> {
m.insert(
$fn_name.to_string(),
ForeignFunction {
name: $fn_name.to_string(),
name: $fn_name,
arity: $arity,
callable: Callable::Function(Box::new($callable)),
},
Expand Down
2 changes: 1 addition & 1 deletion numbat/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) enum Callable {
}

pub(crate) struct ForeignFunction {
pub(crate) name: String,
pub(crate) name: &'static str,
pub(crate) arity: ArityRange,
pub(crate) callable: Callable,
}
Expand Down
6 changes: 3 additions & 3 deletions numbat/src/ffi/procedures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ pub(crate) fn procedures() -> &'static HashMap<ProcedureKind, ForeignFunction> {
m.insert(
ProcedureKind::Print,
ForeignFunction {
name: "print".into(),
name: "print",
arity: 0..=1,
callable: Callable::Procedure(print),
},
);
m.insert(
ProcedureKind::Assert,
ForeignFunction {
name: "assert".into(),
name: "assert",
arity: 1..=1,
callable: Callable::Procedure(assert),
},
);
m.insert(
ProcedureKind::AssertEq,
ForeignFunction {
name: "assert_eq".into(),
name: "assert_eq",
arity: 2..=3,
callable: Callable::Procedure(assert_eq),
},
Expand Down
Loading
Loading