swamp_script_code_gen/
ctx.rs1use crate::alloc::FrameMemoryRegion;
2use swamp_vm_types::{FrameMemoryAddress, MemorySize};
3
4pub struct Context {
5 target_info: FrameMemoryRegion,
6 comment: String,
7}
8
9impl Context {
10 pub(crate) fn comment(&self) -> &str {
11 &self.comment
12 }
13}
14
15impl Context {}
16
17impl Context {}
18
19impl Context {
20 pub(crate) const fn target(&self) -> FrameMemoryRegion {
21 self.target_info
22 }
23}
24
25impl Context {
26 pub(crate) fn with_offset(&self, offset: MemorySize) -> Self {
27 Self {
28 target_info: FrameMemoryRegion {
29 addr: self.addr().add(offset),
30 size: MemorySize(self.target_info.size.0 - 1),
31 },
32 comment: "".to_string(),
33 }
34 }
35}
36
37impl Context {
38 #[must_use]
39 pub fn new(target_info: FrameMemoryRegion) -> Self {
40 Self {
41 target_info,
42 comment: String::new(),
43 }
44 }
45
46 pub const fn addr(&self) -> FrameMemoryAddress {
47 self.target_info.addr
48 }
49 pub const fn target_size(&self) -> MemorySize {
50 self.target_info.size
51 }
52
53 #[must_use]
54 pub fn with_target(&self, target_info: FrameMemoryRegion, comment: &str) -> Self {
55 Self {
56 target_info,
57 comment: comment.to_string(),
58 }
59 }
60
61 #[must_use]
62 pub fn create_scope(&self) -> Self {
63 Self {
64 target_info: self.target_info,
65 comment: self.comment.clone(),
66 }
67 }
68
69 #[must_use]
70 pub fn create_function_scope(&self, return_target: FrameMemoryRegion, comment: &str) -> Self {
71 Self {
72 target_info: self.target_info,
73 comment: comment.to_string(),
74 }
75 }
76}