print index_ptr offset (#1534)
This commit is contained in:
@@ -66,7 +66,7 @@ impl<'ast> Visit<'ast> for StaticStrVisitor {
|
||||
if let Some(Lit::Str(string)) = m.parse_body::<Lit>().ok() {
|
||||
self.static_strs.insert(string.value());
|
||||
}
|
||||
} else if path.is_ident("read_heap_cell") {
|
||||
} else if path.is_ident("read_heap_cell") || path.is_ident("match_untyped_arena_ptr") {
|
||||
if let Some(m) = m.parse_body::<ReadHeapCellExprAndArms>().ok() {
|
||||
self.visit_expr(&m.expr);
|
||||
|
||||
|
||||
@@ -762,7 +762,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
false
|
||||
}
|
||||
|
||||
// TODO: remove ClauseType here?
|
||||
fn format_clause(
|
||||
&mut self,
|
||||
max_depth: usize,
|
||||
@@ -1376,6 +1375,31 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_index_ptr(&mut self, index_ptr: IndexPtr, max_depth: usize) {
|
||||
if self.format_struct(max_depth, 1, atom!("$index_ptr")) {
|
||||
let atom = self.state_stack.pop().unwrap();
|
||||
|
||||
self.state_stack.pop();
|
||||
self.state_stack.pop();
|
||||
|
||||
let offset = if index_ptr.is_undefined() || index_ptr.is_dynamic_undefined() {
|
||||
TokenOrRedirect::Atom(atom!("undefined"))
|
||||
} else {
|
||||
let idx = index_ptr.p() as i64;
|
||||
|
||||
TokenOrRedirect::NumberFocus(
|
||||
max_depth,
|
||||
NumberFocus::Unfocused(Number::Fixnum(Fixnum::build_with(idx))),
|
||||
None,
|
||||
)
|
||||
};
|
||||
|
||||
self.state_stack.push(offset);
|
||||
self.state_stack.push(TokenOrRedirect::Open);
|
||||
self.state_stack.push(atom);
|
||||
}
|
||||
}
|
||||
|
||||
fn print_stream(&mut self, stream: Stream, max_depth: usize) {
|
||||
if let Some(alias) = stream.options().get_alias() {
|
||||
self.print_atom(alias);
|
||||
@@ -1523,13 +1547,13 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
self.print_stream(stream, max_depth);
|
||||
}
|
||||
(ArenaHeaderTag::OssifiedOpDir, _op_dir) => {
|
||||
append_str!(self, "'$ossified_op_dir'");
|
||||
self.print_atom(atom!("$ossified_op_dir"));
|
||||
}
|
||||
(ArenaHeaderTag::Dropped, _value) => {
|
||||
append_str!(self, "'$dropped_value'");
|
||||
self.print_atom(atom!("$dropped_value"));
|
||||
}
|
||||
(ArenaHeaderTag::IndexPtr, _index_ptr) => {
|
||||
append_str!(self, "'$index_ptr'");
|
||||
(ArenaHeaderTag::IndexPtr, index_ptr) => {
|
||||
self.print_index_ptr(*index_ptr, max_depth);
|
||||
}
|
||||
_ => {
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ pub struct IndexPtr {
|
||||
}
|
||||
|
||||
impl IndexPtr {
|
||||
#[inline(always)]
|
||||
pub(crate) fn dynamic_undefined() -> Self {
|
||||
IndexPtr::new()
|
||||
.with_p(0)
|
||||
@@ -99,6 +100,7 @@ impl IndexPtr {
|
||||
.with_tag(IndexPtrTag::DynamicUndefined)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn undefined() -> Self {
|
||||
IndexPtr::new()
|
||||
.with_p(0)
|
||||
@@ -106,6 +108,7 @@ impl IndexPtr {
|
||||
.with_tag(IndexPtrTag::Undefined)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dynamic_index(p: usize) -> Self {
|
||||
IndexPtr::new()
|
||||
.with_p(p as u64)
|
||||
@@ -113,12 +116,29 @@ impl IndexPtr {
|
||||
.with_tag(IndexPtrTag::DynamicIndex)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn index(p: usize) -> Self {
|
||||
IndexPtr::new()
|
||||
.with_p(p as u64)
|
||||
.with_m(false)
|
||||
.with_tag(IndexPtrTag::Index)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn is_undefined(&self) -> bool {
|
||||
match self.tag() {
|
||||
IndexPtrTag::Undefined => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn is_dynamic_undefined(&self) -> bool {
|
||||
match self.tag() {
|
||||
IndexPtrTag::DynamicUndefined => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Ord, Hash, PartialOrd, Eq, PartialEq)]
|
||||
@@ -126,6 +146,22 @@ pub struct CodeIndex(TypedArenaPtr<IndexPtr>);
|
||||
|
||||
const_assert!(std::mem::align_of::<CodeIndex>() == 8);
|
||||
|
||||
impl Deref for CodeIndex {
|
||||
type Target = TypedArenaPtr<IndexPtr>;
|
||||
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &TypedArenaPtr<IndexPtr> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for CodeIndex {
|
||||
#[inline(always)]
|
||||
fn deref_mut(&mut self) -> &mut TypedArenaPtr<IndexPtr> {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CodeIndex> for UntypedArenaPtr {
|
||||
#[inline(always)]
|
||||
fn from(ptr: CodeIndex) -> UntypedArenaPtr {
|
||||
@@ -158,14 +194,6 @@ impl CodeIndex {
|
||||
CodeIndex::new(IndexPtr::undefined(), arena)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn is_undefined(&self) -> bool {
|
||||
match self.0.tag() {
|
||||
IndexPtrTag::Undefined => true, // | &IndexPtr::DynamicUndefined => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn local(&self) -> Option<usize> {
|
||||
match self.0.tag() {
|
||||
IndexPtrTag::Index => Some(self.0.p() as usize),
|
||||
|
||||
Reference in New Issue
Block a user