implement string context
This commit is contained in:
@@ -4,8 +4,7 @@ use fix_error::Source;
|
||||
use hashbrown::HashSet;
|
||||
|
||||
use crate::{
|
||||
AttrSet, Closure, ExtraScope, List, NixString, NixType, Null, Path, PrimOp, PrimOpApp,
|
||||
StaticValue, StrictValue, Thunk, ThunkState, Value,
|
||||
AttrSet, Closure, ExtraScope, List, NixString, NixType, Null, Path, PrimOp, PrimOpApp, StaticValue, StrictValue, StringContext, Thunk, ThunkState, Value
|
||||
};
|
||||
|
||||
pub trait VmContext {
|
||||
@@ -36,6 +35,9 @@ pub trait VmRuntimeCtxExt: VmRuntimeCtx {
|
||||
&'a mut self,
|
||||
val: StrictValue<'gc>,
|
||||
) -> std::result::Result<StringId, NixType>;
|
||||
/// Returns the string context attached to `val`, or `&[]` if `val` is
|
||||
/// either a non-string or a string without context.
|
||||
fn get_string_context<'gc>(&self, val: StrictValue<'gc>) -> &'gc StringContext;
|
||||
fn convert_value(&self, val: Value) -> fix_common::Value;
|
||||
}
|
||||
|
||||
@@ -73,6 +75,14 @@ impl<T: VmRuntimeCtx> VmRuntimeCtxExt for T {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_string_context<'gc>(&self, val: StrictValue<'gc>) -> &'gc StringContext {
|
||||
if let Some(ns) = val.as_gc::<NixString>() {
|
||||
ns.as_ref().context()
|
||||
} else {
|
||||
StringContext::empty()
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_value(&self, val: Value) -> fix_common::Value {
|
||||
self.convert_value_with_seen(val, &mut HashSet::new())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user