]> Repositorios git - scryer-prolog.git/commitdiff
print index_ptr offset (#1534)
authorMark Thom <[email protected]>
Fri, 22 Jul 2022 19:10:12 +0000 (13:10 -0600)
committerMark Thom <[email protected]>
Thu, 27 Oct 2022 05:36:07 +0000 (23:36 -0600)
build/static_string_indexing.rs
src/heap_print.rs
src/machine/machine_indices.rs

index 6f57b37ffb62399f1bc00d0bd8cb488d0952f7af..ca5ac7658d9a1699d5a62272a037ee86f83ee243 100644 (file)
@@ -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);
 
index 28c2e3724c0400fd69e80f10ef677f1d7b8a7632..54f52cd6cf7cd0b29e76c5c883ad9dc5e3c29495 100644 (file)
@@ -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);
                     }
                     _ => {
                     }
index 26776d6f6e58b03a0038c1197487150f29531e16..1fcd41e4a364e3d00592d003774fce181c9654c0 100644 (file)
@@ -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),