Skip to content

Commit

Permalink
Warning fixing, and improve Bracket Span
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Apr 7, 2024
1 parent fb35e5d commit 7c04071
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn walk_name_color(all_objects : &[NameElem], linker : &Linker) -> Vec<(IDEI
}
WireSource::UnaryOp { op:_, right:_ } => {}
WireSource::BinaryOp { op:_, left:_, right:_ } => {}
WireSource::ArrayAccess { arr:_, arr_idx:_ } => {}
WireSource::ArrayAccess { arr:_, arr_idx:_, bracket_span:_ } => {}
WireSource::Constant(_) => {}
WireSource::NamedConstant(_name) => {
result.push((IDEIdentifierType::Constant, w.span));
Expand Down
53 changes: 4 additions & 49 deletions src/file_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ impl From<Range<usize>> for Span {
impl Span {
/// Only really used for having a span with the maximum size.
pub const MAX_POSSIBLE_SPAN : Span = Span(0, usize::MAX);
pub const INVALID_SPAN : Span = Span(usize::MAX, usize::MAX);

pub fn into_range(&self) -> Range<usize> {
self.0..self.1
Expand All @@ -33,33 +32,6 @@ impl Span {
pub fn size(&self) -> usize {
self.1 - self.0
}
#[track_caller]
pub fn difference_left(outer : Span, inner : Span) -> Span {
assert!(outer.0 <= inner.0);
assert!(outer.1 >= inner.1);

Span(outer.0, inner.0)
}
#[track_caller]
pub fn shrunk_front(outer : Span, inner : Span) -> Span {
assert!(outer.0 <= inner.0);
assert!(outer.1 >= inner.1);

Span(inner.0, outer.1)
}
#[track_caller]
pub fn difference_right(outer : Span, inner : Span) -> Span {
assert!(outer.0 <= inner.0);
assert!(outer.1 >= inner.1);

Span(inner.1, outer.1)
}
#[track_caller]
pub fn into_single_char_span(self) -> SingleCharSpan {
assert!(self.1 == self.0+1);
SingleCharSpan{char_idx: self.0}
}

pub fn empty_span_at_front(self) -> Span {
Span(self.0, self.0)
}
Expand Down Expand Up @@ -93,28 +65,11 @@ impl BracketSpan {
pub fn outer_span(&self) -> Span {
self.0
}
pub fn open_bracket(&self) -> SingleCharSpan {
SingleCharSpan{char_idx : self.0.0}
}
pub fn close_bracket(&self) -> SingleCharSpan {
SingleCharSpan{char_idx : self.0.1 - 1}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct SingleCharSpan {
pub char_idx : usize
}

impl Into<Span> for SingleCharSpan {
fn into(self) -> Span {
Span(self.char_idx, self.char_idx+1)
pub fn open_bracket(&self) -> Span {
Span(self.0.0, self.0.0+1)
}
}

impl Into<Span> for &SingleCharSpan {
fn into(self) -> Span {
Span(self.char_idx, self.char_idx+1)
pub fn close_bracket(&self) -> Span {
Span(self.0.1 - 1, self.0.1)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/flattening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub enum WireSource {
WireRead(FlatID), // Used to add a span to the reference of a wire.
UnaryOp{op : UnaryOperator, right : FlatID},
BinaryOp{op : BinaryOperator, left : FlatID, right : FlatID},
ArrayAccess{arr : FlatID, arr_idx : FlatID},
ArrayAccess{arr : FlatID, arr_idx : FlatID, bracket_span : BracketSpan},
Constant(Value),
NamedConstant(ConstantUUID),
}
Expand All @@ -182,7 +182,7 @@ impl WireSource {
&WireSource::WireRead(from_wire) => {func(from_wire)}
&WireSource::UnaryOp { op:_, right } => {func(right)}
&WireSource::BinaryOp { op:_, left, right } => {func(left); func(right)}
&WireSource::ArrayAccess { arr, arr_idx } => {func(arr); func(arr_idx)}
&WireSource::ArrayAccess { arr, arr_idx, bracket_span:_ } => {func(arr); func(arr_idx)}
WireSource::Constant(_) => {}
WireSource::NamedConstant(_) => {}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<'l> FlatteningContext<'l> {

let (array_size_wire_id, bracket_span) = cursor.field(SUS.arr_idx_field, |cursor| self.flatten_array_bracket_tree(cursor));

WrittenType::Array(span, Box::new((array_element_type, array_size_wire_id)))
WrittenType::Array(span, Box::new((array_element_type, array_size_wire_id, bracket_span)))
})
}

Expand Down Expand Up @@ -495,7 +495,7 @@ impl<'l> FlatteningContext<'l> {
args = &args[..expected_arg_count];
} else {
// Too few args, mention missing argument names
self.errors.error_with_info(arguments_span.close_bracket().into(), format!("Too few arguments. Function takes {expected_arg_count} args, but {arg_count} were passed."), module_info);
self.errors.error_with_info(arguments_span.close_bracket(), format!("Too few arguments. Function takes {expected_arg_count} args, but {arg_count} were passed."), module_info);
}
}

Expand Down Expand Up @@ -584,7 +584,7 @@ impl<'l> FlatteningContext<'l> {

let (arr_idx, bracket_span) = cursor.field(SUS.arr_idx_field, |cursor| self.flatten_array_bracket_tree(cursor));

WireSource::ArrayAccess{arr, arr_idx}
WireSource::ArrayAccess{arr, arr_idx, bracket_span}
})
} else if kind == SUS.func_call_kind {
if let Some((_module_name_span, md, interface_wires)) = self.desugar_func_call_tree(cursor) {
Expand Down Expand Up @@ -991,7 +991,7 @@ impl<'l> FlatteningContext<'l> {
self.typecheck_wire_is_of_type(right_wire, &input_right_type, &format!("{op} right"));
output_type
}
&WireSource::ArrayAccess{arr, arr_idx} => {
&WireSource::ArrayAccess{arr, arr_idx, bracket_span:_} => {
let arr_wire = self.instructions[arr].extract_wire();
let arr_idx_wire = self.instructions[arr_idx].extract_wire();

Expand Down
4 changes: 2 additions & 2 deletions src/instantiation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
let right_val = self.get_generation_value(right)?;
compute_binary_op(left_val, op, right_val)
}
&WireSource::ArrayAccess{arr, arr_idx} => {
&WireSource::ArrayAccess{arr, arr_idx, bracket_span:_} => {
let Value::Array(arr_val) = self.get_generation_value(arr)? else {return None};
let arr_idx_wire = self.flattened.instructions[arr_idx].extract_wire();
let idx : usize = self.extract_integer_from_generative(arr_idx)?;
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
let right = self.get_wire_or_constant_as_wire(right)?;
RealWireDataSource::BinaryOp{op, left, right}
}
&WireSource::ArrayAccess{arr, arr_idx} => {
&WireSource::ArrayAccess{arr, arr_idx, bracket_span:_} => {
let arr = self.get_wire_or_constant_as_wire(arr)?;
match &self.generation_state[arr_idx] {
SubModuleOrWire::SubModule(_) => unreachable!(),
Expand Down
10 changes: 5 additions & 5 deletions src/typing.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::ops::Deref;

use crate::{arena_alloc::ArenaAllocator, errors::ErrorCollector, file_position::Span, flattening::{BinaryOperator, FlatID, UnaryOperator}, linker::{get_builtin_type, Linkable, Linker, NamedType, TypeUUID, TypeUUIDMarker}, value::Value};
use crate::{arena_alloc::ArenaAllocator, errors::ErrorCollector, file_position::{BracketSpan, Span}, flattening::{BinaryOperator, FlatID, UnaryOperator}, linker::{get_builtin_type, Linkable, Linker, NamedType, TypeUUID, TypeUUIDMarker}, value::Value};

// These are
#[derive(Debug, Clone)]
pub enum WrittenType {
Error(Span),
Named(Span, TypeUUID),
Array(Span, Box<(WrittenType, FlatID)>)
Array(Span, Box<(WrittenType, FlatID, BracketSpan)>)
}

impl WrittenType {
Expand All @@ -16,7 +16,7 @@ impl WrittenType {
WrittenType::Error(span) => {f(None, *span)}
WrittenType::Named(span, id) => {f(Some(*id), *span)}
WrittenType::Array(_span, arr_box) => {
let (arr, _idx) = arr_box.deref();
let (arr, _idx, _br_span) = arr_box.deref();
arr.for_each_located_type(f);
}
}
Expand All @@ -34,7 +34,7 @@ impl WrittenType {
match self {
WrittenType::Error(_span) | WrittenType::Named(_span, _) => {}
WrittenType::Array(_span, arr_box) => {
let (arr_typ, _idx) = arr_box.deref();
let (arr_typ, _idx, _br_span) = arr_box.deref();
let sub = arr_typ.get_deepest_selected(position);
if sub.is_some() {
return sub;
Expand All @@ -52,7 +52,7 @@ impl WrittenType {
WrittenType::Error(_) => Type::Error,
WrittenType::Named(_, id) => Type::Named(*id),
WrittenType::Array(_, arr_box) => {
let (elem_typ, arr_idx) = arr_box.deref();
let (elem_typ, arr_idx, _br_span) = arr_box.deref();
Type::Array(Box::new((elem_typ.to_type(), *arr_idx)))
}
}
Expand Down

0 comments on commit 7c04071

Please sign in to comment.