microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
compiler/qsc_eval/src/debug.rs
57lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use qsc_data_structures::span::Span; |
| 5 | |
| 6 | use crate::val::FunctorApp; |
| 7 | use qsc_fir::fir; |
| 8 | use qsc_fir::fir::{PackageId, StoreItemId}; |
| 9 | use qsc_hir::hir; |
| 10 | |
| 11 | #[derive(Clone, Copy, Debug, PartialEq)] |
| 12 | pub struct Frame { |
| 13 | pub span: Span, |
| 14 | pub id: StoreItemId, |
| 15 | pub caller: PackageId, |
| 16 | pub functor: FunctorApp, |
| 17 | } |
| 18 | |
| 19 | #[derive(Debug, Default, Clone, PartialEq)] |
| 20 | pub struct CallStack { |
| 21 | frames: Vec<Frame>, |
| 22 | } |
| 23 | |
| 24 | impl CallStack { |
| 25 | #[must_use] |
| 26 | pub fn is_empty(&self) -> bool { |
| 27 | self.frames.is_empty() |
| 28 | } |
| 29 | |
| 30 | #[must_use] |
| 31 | pub fn len(&self) -> usize { |
| 32 | self.frames.len() |
| 33 | } |
| 34 | |
| 35 | #[must_use] |
| 36 | pub fn into_frames(self) -> Vec<Frame> { |
| 37 | self.frames |
| 38 | } |
| 39 | |
| 40 | pub fn push_frame(&mut self, frame: Frame) { |
| 41 | self.frames.push(frame); |
| 42 | } |
| 43 | |
| 44 | pub fn pop_frame(&mut self) -> Option<Frame> { |
| 45 | self.frames.pop() |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #[must_use] |
| 50 | pub fn map_hir_package_to_fir(package: hir::PackageId) -> fir::PackageId { |
| 51 | fir::PackageId::from(<hir::PackageId as Into<usize>>::into(package)) |
| 52 | } |
| 53 | |
| 54 | #[must_use] |
| 55 | pub fn map_fir_package_to_hir(package: fir::PackageId) -> hir::PackageId { |
| 56 | hir::PackageId::from(<fir::PackageId as Into<usize>>::into(package)) |
| 57 | } |
| 58 | |