diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-17 21:15:54 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-17 21:15:54 +0100 |
| commit | 090dd8c52e4ae60742fe8bad7b74e18bb808ba0d (patch) | |
| tree | 249b5857b5dc8d8be7b89a136405fce50856730a /src/lib.rs | |
| parent | b205748bde51c551468a8dc89123f85b67c660dd (diff) | |
| download | sylt-090dd8c52e4ae60742fe8bad7b74e18bb808ba0d.tar.gz | |
use enums instead of 2 bools
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -626,17 +626,23 @@ mod op { } #[derive(Debug)] +enum BlockLinkState { + Linked, + Unlinked, + Nothing, +} + +#[derive(Debug)] pub struct Block { pub ty: Type, upvalues: Vec<(usize, bool, Type)>, + linking: BlockLinkState, pub name: String, pub file: PathBuf, ops: Vec<Op>, last_line_offset: usize, line_offsets: HashMap<usize, usize>, - linked: bool, - constant: bool, } impl Block { @@ -644,16 +650,31 @@ impl Block { Self { ty: Type::Void, upvalues: Vec::new(), + linking: BlockLinkState::Nothing, + name: String::from(name), file: file.to_owned(), ops: Vec::new(), last_line_offset: 0, line_offsets: HashMap::new(), - linked: false, - constant: false, } } + fn mark_constant(&mut self) { + if self.upvalues.is_empty() { + return; + } + self.linking = BlockLinkState::Unlinked; + } + + fn link(&mut self) { + self.linking = BlockLinkState::Linked; + } + + fn needs_linking(&self) -> bool { + matches!(self.linking, BlockLinkState::Unlinked) + } + // Used to create empty functions. fn stubbed_block(ty: &Type) -> Self { let mut block = Block::new("/empty/", Path::new("")); |
