Skip to content

Commit b9ebd1b

Browse files
committed
More wild migration [No Value]
1 parent 8776ca5 commit b9ebd1b

File tree

9 files changed

+449
-320
lines changed

9 files changed

+449
-320
lines changed

core/src/eval/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
382382

383383
env = current_evaled.env;
384384

385-
match current_evaled.value.content() {
385+
match current_evaled.value.content_ref() {
386386
ValueContentRef::Record(RecordBody(record_data)) => {
387387
let Some(next_field) = record_data.fields.get(id).cloned() else {
388388
return Err(EvalError::FieldMissing {
@@ -482,7 +482,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
482482
// it was accessed:
483483
let mut closure = self.cache.get(idx);
484484

485-
if let ValueContentRef::Term(term) = closure.value.content() {
485+
if let ValueContentRef::Term(term) = closure.value.content_ref() {
486486
if let Term::RuntimeError(EvalError::MissingFieldDef {
487487
id,
488488
metadata,
@@ -530,7 +530,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
530530
let pos_idx = closure.value.pos_idx();
531531
let has_cont_on_stack = self.stack.is_top_idx() || self.stack.is_top_cont();
532532

533-
closure = match value.content() {
533+
closure = match value.content_ref() {
534534
ValueContentRef::Thunk(thunk_body) => todo!(),
535535
ValueContentRef::Term(TermBody(Term::Value(value))) => Closure { value, env },
536536
ValueContentRef::Term(TermBody(Term::Sealed(key, inner, label))) => {
@@ -1060,7 +1060,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
10601060
acc.push(e);
10611061
this.reset();
10621062
}
1063-
Ok(val) => match val.content() {
1063+
Ok(val) => match val.content_ref() {
10641064
ValueContentRef::Array(data) => {
10651065
for elt in data.array.iter() {
10661066
// After eval_closure, all the array elements are

core/src/term/make/builder.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
//! Using this module, you can define Nickel records using a builder style. For example:
44
//!
55
//! ```rust
6-
//! # use nickel_lang_core::term::{MergePriority, Term, RichTerm, make::builder::Record};
6+
//! # use nickel_lang_core::term::{MergePriority, Term, NickelValue, make::builder::Record};
77
//! let b = Record::new()
88
//! .field("foo")
99
//! .priority(MergePriority::Bottom)
1010
//! .doc("foo?")
1111
//! .not_exported()
1212
//! .value(Term::Str("foo".into()));
13-
//! let t : RichTerm = b
13+
//! let t : NickelValue = b
1414
//! .field("bar")
1515
//! .value(Term::Num(42.into()))
1616
//! .into();
@@ -19,13 +19,14 @@
1919
use indexmap::IndexMap;
2020

2121
use crate::{
22+
bytecode::value::NickelValue,
2223
combine::Combine,
2324
identifier::{Ident, LocIdent},
2425
label::Label,
2526
term::{
2627
make::op2,
2728
record::{self, FieldMetadata, RecordAttrs, RecordData},
28-
BinaryOp, LabeledType, MergePriority, RichTerm, Term,
29+
BinaryOp, LabeledType, MergePriority,
2930
},
3031
typ::Type,
3132
};
@@ -36,7 +37,7 @@ type StaticPath = Vec<Ident>;
3637
pub struct Incomplete();
3738

3839
/// Typestate style tag for `Field`s that have been finalized
39-
pub struct Complete(Option<RichTerm>);
40+
pub struct Complete(Option<NickelValue>);
4041

4142
/// A Nickel record field being constructed
4243
#[derive(Debug)]
@@ -155,7 +156,7 @@ impl Field<Incomplete> {
155156
}
156157

157158
/// Finalize the [`Field`] by setting its value
158-
pub fn value(self, value: impl Into<RichTerm>) -> Field<Complete> {
159+
pub fn value(self, value: impl Into<NickelValue>) -> Field<Complete> {
159160
Field {
160161
record: Complete(Some(value.into())),
161162
path: self.path,
@@ -194,7 +195,7 @@ impl Field<Record> {
194195
}
195196

196197
/// Finalize the [`Field`] by setting its a value
197-
pub fn value(mut self, value: impl Into<RichTerm>) -> Record {
198+
pub fn value(mut self, value: impl Into<NickelValue>) -> Record {
198199
self.record.fields.push((
199200
self.path,
200201
record::Field {
@@ -223,16 +224,16 @@ where
223224
let fst = it.next().unwrap();
224225

225226
let content = it.rev().fold(content, |acc, id| {
226-
record::Field::from(RichTerm::from(Term::Record(RecordData {
227+
record::Field::from(NickelValue::record_posless(RecordData {
227228
fields: [(LocIdent::from(id), acc)].into(),
228229
..Default::default()
229-
})))
230+
}))
230231
});
231232

232233
(fst.into(), content)
233234
}
234235

235-
fn build_record<I>(fields: I, attrs: RecordAttrs) -> Term
236+
fn build_record<I>(fields: I, attrs: RecordAttrs) -> NickelValue
236237
where
237238
I: IntoIterator<Item = (LocIdent, record::Field)>,
238239
{
@@ -262,7 +263,8 @@ where
262263
}
263264
}
264265
}
265-
Term::Record(RecordData::new(static_fields, attrs, None))
266+
267+
NickelValue::record_posless(RecordData::new(static_fields, attrs, None))
266268
}
267269

268270
impl Record {
@@ -336,13 +338,13 @@ impl Record {
336338
self
337339
}
338340

339-
/// Finalize the record and turn it into a [`crate::term::RichTerm`]
340-
pub fn build(self) -> RichTerm {
341+
/// Finalize the record and turn it into a [`crate::term::NickelValue`]
342+
pub fn build(self) -> NickelValue {
341343
let elaborated = self
342344
.fields
343345
.into_iter()
344346
.map(|(path, rt)| elaborate_field_path(path, rt));
345-
build_record(elaborated, self.attrs).into()
347+
build_record(elaborated, self.attrs)
346348
}
347349
}
348350

@@ -362,7 +364,7 @@ where
362364
}
363365
}
364366

365-
impl From<Record> for RichTerm {
367+
impl From<Record> for NickelValue {
366368
fn from(val: Record) -> Self {
367369
val.build()
368370
}
@@ -372,7 +374,7 @@ impl From<Record> for RichTerm {
372374
mod tests {
373375
use crate::{
374376
position::TermPos,
375-
term::{RichTerm, TypeAnnotation},
377+
term::{NickelValue, TypeAnnotation},
376378
typ::{Type, TypeF},
377379
};
378380

@@ -381,12 +383,12 @@ mod tests {
381383
use super::*;
382384

383385
fn term(t: Term) -> record::Field {
384-
record::Field::from(RichTerm::from(t))
386+
record::Field::from(NickelValue::from(t))
385387
}
386388

387389
#[test]
388390
fn trivial() {
389-
let t: RichTerm = Record::new()
391+
let t: NickelValue = Record::new()
390392
.field("foo")
391393
.value(Term::Str("bar".into()))
392394
.into();
@@ -402,7 +404,7 @@ mod tests {
402404

403405
#[test]
404406
fn from_iter() {
405-
let t: RichTerm = Record::from([
407+
let t: NickelValue = Record::from([
406408
Field::name("foo").value(Term::Null),
407409
Field::name("bar").value(Term::Null),
408410
])
@@ -422,7 +424,7 @@ mod tests {
422424

423425
#[test]
424426
fn some_doc() {
425-
let t: RichTerm = Record::from([
427+
let t: NickelValue = Record::from([
426428
Field::name("foo").some_doc(Some("foo")).no_value(),
427429
Field::name("bar").some_doc(None as Option<&str>).no_value(),
428430
Field::name("baz").doc("baz").no_value(),
@@ -456,7 +458,7 @@ mod tests {
456458

457459
#[test]
458460
fn fields() {
459-
let t: RichTerm = Record::new()
461+
let t: NickelValue = Record::new()
460462
.fields([
461463
Field::name("foo").value(Term::Str("foo".into())),
462464
Field::name("bar").value(Term::Str("bar".into())),
@@ -477,7 +479,7 @@ mod tests {
477479

478480
#[test]
479481
fn fields_metadata() {
480-
let t: RichTerm = Record::new()
482+
let t: NickelValue = Record::new()
481483
.fields([
482484
Field::name("foo").optional().no_value(),
483485
Field::name("bar").optional().no_value(),
@@ -510,7 +512,7 @@ mod tests {
510512

511513
#[test]
512514
fn overriding() {
513-
let t: RichTerm = Record::new()
515+
let t: NickelValue = Record::new()
514516
.path(vec!["terraform", "required_providers"])
515517
.value(Record::from([
516518
Field::name("foo").value(Term::Null),
@@ -551,7 +553,7 @@ mod tests {
551553

552554
#[test]
553555
fn open_record() {
554-
let t: RichTerm = Record::new().open().into();
556+
let t: NickelValue = Record::new().open().into();
555557
assert_eq!(
556558
t,
557559
build_record(
@@ -567,7 +569,7 @@ mod tests {
567569

568570
#[test]
569571
fn prio_metadata() {
570-
let t: RichTerm = Record::new()
572+
let t: NickelValue = Record::new()
571573
.field("foo")
572574
.priority(MergePriority::Top)
573575
.no_value()
@@ -590,7 +592,7 @@ mod tests {
590592

591593
#[test]
592594
fn contract() {
593-
let t: RichTerm = Record::new()
595+
let t: NickelValue = Record::new()
594596
.field("foo")
595597
.contract(TypeF::String)
596598
.no_value()
@@ -619,7 +621,7 @@ mod tests {
619621

620622
#[test]
621623
fn exercise_metadata() {
622-
let t: RichTerm = Record::new()
624+
let t: NickelValue = Record::new()
623625
.field("foo")
624626
.priority(MergePriority::Bottom)
625627
.doc("foo?")

core/src/term/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use smallvec::SmallVec;
1111
use string::NickelString;
1212

1313
use crate::{
14+
bytecode::value::{self, Array, NickelValue},
1415
cache::InputFormat,
1516
combine::Combine,
1617
error::{EvalError, ParseError},
@@ -19,11 +20,10 @@ use crate::{
1920
identifier::{Ident, LocIdent},
2021
impl_display_from_pretty,
2122
label::{Label, MergeLabel},
22-
position::{RawSpan, PosIdx},
23+
position::{PosIdx, RawSpan},
2324
pretty::PrettyPrintCap,
2425
traverse::*,
2526
typ::{Type, UnboundTypeVariableError},
26-
bytecode::value::{self, NickelValue, Array},
2727
};
2828

2929
use crate::metrics::increment;
@@ -385,10 +385,10 @@ impl RuntimeContract {
385385
self.contract,
386386
NickelValue::label_posless(self.label),
387387
)
388-
.with_pos_idx(pos_idx),
388+
.with_block_pos_idx(pos_idx),
389389
value
390390
)
391-
.with_pos_idx(pos_idx)
391+
.with_block_pos_idx(pos_idx)
392392
}
393393

394394
/// Apply a series of contracts to a value, in order.
@@ -2307,7 +2307,7 @@ pub mod make {
23072307
$(
23082308
fields.insert($id.into(), $body.into());
23092309
)*
2310-
$crate::bytecode::value::NickelValue::record(
2310+
$crate::bytecode::value::NickelValue::record_posless(
23112311
$crate::term::record::RecordData::with_field_values(fields)
23122312
)
23132313
}

0 commit comments

Comments
 (0)