diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-03-09 17:01:53 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-03-09 17:01:53 +0100 |
| commit | 9ef8eaa4564b2e498c56cad50491f2fdcea9d643 (patch) | |
| tree | ba25bbccda274c8edd45b999fd41b9dc9c6eb841 /src/compiler.rs | |
| parent | 50e3477ed34697be12890081b03d8412703ba8b3 (diff) | |
| download | sylt-9ef8eaa4564b2e498c56cad50491f2fdcea9d643.tar.gz | |
change union to hashset from vector
Diffstat (limited to 'src/compiler.rs')
| -rw-r--r-- | src/compiler.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index bdc5901..588a9e9 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; use std::cell::RefCell; -use std::collections::{HashMap, hash_map::Entry}; +use std::collections::{HashMap, HashSet, hash_map::Entry}; use std::rc::Rc; use crate::{Blob, Block, Op, Prog, RustFunction, Type, Value}; @@ -1403,18 +1403,19 @@ impl Compiler { } fn parse_type(&mut self) -> Result<Type, ()> { - let mut tys = vec![self.parse_simple_type()?]; + let mut tys = HashSet::new(); + tys.insert(self.parse_simple_type()?); loop { match self.peek() { Token::Questionmark => { self.eat(); - tys.push(Type::Void); + tys.insert(Type::Void); return Ok(Type::Union(tys)); }, Token::Pipe => { self.eat(); - tys.push(self.parse_simple_type()?); + tys.insert(self.parse_simple_type()?); }, _ => { @@ -1423,7 +1424,7 @@ impl Compiler { } } if tys.len() == 1 { - Ok(tys[0].clone()) + Ok(tys.iter().next().unwrap().clone()) } else { Ok(Type::Union(tys)) } |
