diff --git a/mers_lib/src/data/defs.rs b/mers_lib/src/data/defs.rs index 895a3b9..0d5da2a 100755 --- a/mers_lib/src/data/defs.rs +++ b/mers_lib/src/data/defs.rs @@ -1,15 +1,25 @@ -use crate::program::run::CheckError; +use super::Data; -use super::{Data, MersType, Type}; - -pub fn assign(from: Data, target: &Data) { - let target = target.get(); +pub fn assign(from: &Data, target: &Data) { if let Some(r) = target + .get() .as_any() .downcast_ref::() { - *r.0.lock().unwrap().get_mut() = from.get().clone(); + *r.0.lock().unwrap() = from.clone(); + } else if let (Some(from), Some(target)) = ( + from.get() + .as_any() + .downcast_ref::(), + target + .get() + .as_any() + .downcast_ref::(), + ) { + for (from, target) in from.0.iter().zip(target.0.iter()) { + assign(from, target); + } } else { - todo!("assignment to non-reference") + unreachable!("invalid assignment") } } diff --git a/mers_lib/src/data/function.rs b/mers_lib/src/data/function.rs index 17fa54f..df08911 100755 --- a/mers_lib/src/data/function.rs +++ b/mers_lib/src/data/function.rs @@ -4,10 +4,7 @@ use std::{ sync::{Arc, Mutex}, }; -use crate::program::{ - self, - run::{CheckError, CheckInfo, Info}, -}; +use crate::program::run::{CheckError, CheckInfo, Info}; use super::{Data, MersData, MersType, Type}; diff --git a/mers_lib/src/parsing/mod.rs b/mers_lib/src/parsing/mod.rs index b3ddb86..623d474 100755 --- a/mers_lib/src/parsing/mod.rs +++ b/mers_lib/src/parsing/mod.rs @@ -1,24 +1,85 @@ use std::sync::Arc; -use crate::program; +use crate::program::{self, parsed::block::Block}; pub mod errors; pub mod statements; pub mod types; pub fn parse(src: &mut Source) -> Result, ()> { - Ok(Box::new(statements::parse_block(src)?)) + let pos_in_src = src.get_pos(); + Ok(Box::new(Block { + pos_in_src, + statements: statements::parse_multiple(src, "")?, + })) } pub struct Source { + src_raw_len: usize, src: String, + /// (start, content) of each comment, including start/end (//, \n, /* and */) + comments: Vec<(usize, String)>, i: usize, sections: Vec, } impl Source { - pub fn new(src: String) -> Self { + pub fn new(source: String) -> Self { + let mut src = String::with_capacity(source.len()); + let mut comment = (0, String::new()); + let mut comments = Vec::new(); + let mut chars = source.char_indices().peekable(); + let mut in_comment = None; + loop { + if let Some((i, ch)) = chars.next() { + match in_comment { + Some(false) => { + comment.1.push(ch); + if ch == '\n' { + in_comment = None; + comments.push(( + comment.0, + std::mem::replace(&mut comment.1, String::new()), + )); + } + } + Some(true) => { + comment.1.push(ch); + if ch == '*' && matches!(chars.peek(), Some((_, '/'))) { + chars.next(); + comment.1.push('/'); + in_comment = None; + comments.push(( + comment.0, + std::mem::replace(&mut comment.1, String::new()), + )); + } + } + None => match ch { + '/' if matches!(chars.peek(), Some((_, '/'))) => { + chars.next(); + in_comment = Some(false); + comment.0 = i; + comment.1.push('/'); + comment.1.push('/'); + } + '/' if matches!(chars.peek(), Some((_, '*'))) => { + chars.next(); + in_comment = Some(true); + comment.0 = i; + comment.1.push('/'); + comment.1.push('*'); + } + _ => src.push(ch), + }, + } + } else { + break; + } + } Self { + src_raw_len: source.len(), src, + comments, i: 0, sections: vec![], } @@ -105,6 +166,37 @@ impl Source { pub fn sections(&self) -> &Vec { &self.sections } + + pub fn format(&self, insertions: &Vec<(usize, bool, String)>) -> String { + let mut o = String::with_capacity(self.src_raw_len); + let mut insertions = insertions.iter().peekable(); + let mut comments = self.comments.iter().peekable(); + for (i, ch) in self.src.char_indices() { + let insert = if let Some((index, pre, _)) = insertions.peek() { + if *index <= i { + Some(*pre) + } else { + None + } + } else { + None + }; + if let Some((index, comment)) = comments.peek() { + if *index == i { + comments.next(); + o.push_str(comment); + } + } + if let Some(true) = insert { + o.push_str(&insertions.next().unwrap().2); + } + o.push(ch); + if let Some(false) = insert { + o.push_str(&insertions.next().unwrap().2); + } + } + o + } } impl Drop for Source { @@ -144,7 +236,7 @@ impl SectionMarker { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct SourcePos(usize); impl SourcePos { fn diff(&self, rhs: &Self) -> usize { diff --git a/mers_lib/src/parsing/statements.rs b/mers_lib/src/parsing/statements.rs index 90cdfca..e2443fc 100755 --- a/mers_lib/src/parsing/statements.rs +++ b/mers_lib/src/parsing/statements.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use super::Source; use crate::{ data::Data, @@ -16,32 +14,43 @@ pub fn parse(src: &mut Source) -> Result" => { + let pos_in_src = src.get_pos(); src.next_word(); first = Box::new(program::parsed::function::Function { + pos_in_src, arg: first, run: parse(src)?.expect("err: bad eof, fn needs some statement"), }); } _ => loop { + let pos_in_src = src.get_pos(); src.skip_whitespace(); if let Some('.') = src.peek_char() { src.next_char(); let chained = parse_no_chain(src)?.expect("err: EOF instead of chain"); - first = Box::new(program::parsed::chain::Chain { first, chained }); + first = Box::new(program::parsed::chain::Chain { + pos_in_src, + first, + chained, + }); } else { break; } @@ -52,23 +61,12 @@ pub fn parse(src: &mut Source) -> Result Result { - Ok(program::parsed::block::Block { - statements: parse_multiple(src, '}')?, - }) -} -pub fn parse_tuple(src: &mut Source) -> Result { - Ok(program::parsed::tuple::Tuple { - elems: parse_multiple(src, ')')?, - }) -} -pub fn parse_multiple(src: &mut Source, end: char) -> Result>, ()> { +pub fn parse_multiple(src: &mut Source, end: &str) -> Result>, ()> { src.section_begin("block".to_string()); let mut statements = vec![]; loop { src.skip_whitespace(); - if matches!(src.peek_char(), Some(e) if e == end) { + if src.peek_char().is_some_and(|ch| end.contains(ch)) { src.next_char(); break; } else if let Some(s) = parse(src)? { @@ -87,15 +85,24 @@ pub fn parse_no_chain( src.skip_whitespace(); match src.peek_char() { Some('{') => { + let pos_in_src = src.get_pos(); src.next_char(); - return Ok(Some(Box::new(parse_block(src)?))); + return Ok(Some(Box::new(program::parsed::block::Block { + pos_in_src, + statements: parse_multiple(src, "}")?, + }))); } Some('(') => { + let pos_in_src = src.get_pos(); src.next_char(); - return Ok(Some(Box::new(parse_tuple(src)?))); + return Ok(Some(Box::new(program::parsed::tuple::Tuple { + pos_in_src, + elems: parse_multiple(src, ")")?, + }))); } Some('"') => { src.section_begin("string literal".to_string()); + let pos_in_src = src.get_pos(); src.next_char(); let mut s = String::new(); loop { @@ -118,16 +125,19 @@ pub fn parse_no_chain( todo!("err: eof in string") } } - return Ok(Some(Box::new(program::parsed::value::Value(Data::new( - crate::data::string::String(s), - ))))); + return Ok(Some(Box::new(program::parsed::value::Value { + pos_in_src, + data: Data::new(crate::data::string::String(s)), + }))); } _ => {} } + let pos_in_src = src.get_pos(); Ok(Some(match src.next_word() { "if" => { src.section_begin("if".to_string()); Box::new(program::parsed::r#if::If { + pos_in_src, condition: parse(src)?.expect("err: EOF instead of condition"), on_true: parse(src)?.expect("err: EOF instead of on_true"), on_false: { @@ -142,16 +152,14 @@ pub fn parse_no_chain( }, }) } - "switch" => { - src.section_begin("loop".to_string()); - todo!() - } - "true" => Box::new(program::parsed::value::Value(Data::new( - crate::data::bool::Bool(true), - ))), - "false" => Box::new(program::parsed::value::Value(Data::new( - crate::data::bool::Bool(false), - ))), + "true" => Box::new(program::parsed::value::Value { + pos_in_src, + data: Data::new(crate::data::bool::Bool(true)), + }), + "false" => Box::new(program::parsed::value::Value { + pos_in_src, + data: Data::new(crate::data::bool::Bool(false)), + }), "" => return Ok(None), o => { let o = o.to_string(); @@ -161,28 +169,33 @@ pub fn parse_no_chain( let here = src.get_pos(); src.next_char(); if let Ok(num) = format!("{o}.{}", src.next_word()).parse() { - Box::new(program::parsed::value::Value(Data::new( - crate::data::float::Float(num), - ))) + Box::new(program::parsed::value::Value { + pos_in_src, + data: Data::new(crate::data::float::Float(num)), + }) } else { src.set_pos(here); - Box::new(program::parsed::value::Value(Data::new( - crate::data::int::Int(n), - ))) + Box::new(program::parsed::value::Value { + pos_in_src, + data: Data::new(crate::data::int::Int(n)), + }) } } else { - Box::new(program::parsed::value::Value(Data::new( - crate::data::int::Int(n), - ))) + Box::new(program::parsed::value::Value { + pos_in_src, + data: Data::new(crate::data::int::Int(n)), + }) } } else { if let Some('&') = o.chars().next() { Box::new(program::parsed::variable::Variable { + pos_in_src, is_ref: true, var: o[1..].to_string(), }) } else { Box::new(program::parsed::variable::Variable { + pos_in_src, is_ref: false, var: o.to_string(), }) diff --git a/mers_lib/src/program/configs/with_base.rs b/mers_lib/src/program/configs/with_base.rs index a0eb758..1afd53a 100755 --- a/mers_lib/src/program/configs/with_base.rs +++ b/mers_lib/src/program/configs/with_base.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, program::run::{CheckInfo, Info}, }; @@ -18,7 +18,6 @@ impl Config { info: Arc::new(Info::neverused()), info_check: Arc::new(Mutex::new(CheckInfo::neverused())), out: Arc::new(|a, i| { - dbg!(a); let mut o = Type::empty(); for t in &a.types { if let Some(t) = t.as_any().downcast_ref::() { diff --git a/mers_lib/src/program/parsed/assign_to.rs b/mers_lib/src/program/parsed/assign_to.rs index ed2285b..4013b0e 100755 --- a/mers_lib/src/program/parsed/assign_to.rs +++ b/mers_lib/src/program/parsed/assign_to.rs @@ -1,9 +1,10 @@ -use crate::program; +use crate::{parsing::SourcePos, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct AssignTo { + pub pos_in_src: SourcePos, pub target: Box, pub source: Box, } @@ -18,6 +19,7 @@ impl MersStatement for AssignTo { comp: CompInfo, ) -> Result, String> { Ok(Box::new(program::run::assign_to::AssignTo { + pos_in_src: self.pos_in_src, is_init: false, target: self.target.compile(info, comp)?, source: self.source.compile(info, comp)?, diff --git a/mers_lib/src/program/parsed/block.rs b/mers_lib/src/program/parsed/block.rs index c7407e3..b98a421 100755 --- a/mers_lib/src/program/parsed/block.rs +++ b/mers_lib/src/program/parsed/block.rs @@ -1,9 +1,10 @@ -use crate::{info, program}; +use crate::{info, parsing::SourcePos, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct Block { + pub pos_in_src: SourcePos, pub statements: Vec>, } impl MersStatement for Block { @@ -16,6 +17,7 @@ impl MersStatement for Block { comp: CompInfo, ) -> Result, String> { Ok(Box::new(program::run::block::Block { + pos_in_src: self.pos_in_src, statements: self .statements .iter() diff --git a/mers_lib/src/program/parsed/chain.rs b/mers_lib/src/program/parsed/chain.rs index 4236866..9f5c116 100755 --- a/mers_lib/src/program/parsed/chain.rs +++ b/mers_lib/src/program/parsed/chain.rs @@ -1,9 +1,11 @@ +use crate::parsing::SourcePos; use crate::{info, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct Chain { + pub pos_in_src: SourcePos, pub first: Box, pub chained: Box, } @@ -17,6 +19,7 @@ impl MersStatement for Chain { comp: CompInfo, ) -> Result, String> { Ok(Box::new(program::run::chain::Chain { + pos_in_src: self.pos_in_src, first: self.first.compile(info, comp)?, chained: self.chained.compile(info, comp)?, })) diff --git a/mers_lib/src/program/parsed/function.rs b/mers_lib/src/program/parsed/function.rs index 841b15c..9276a10 100755 --- a/mers_lib/src/program/parsed/function.rs +++ b/mers_lib/src/program/parsed/function.rs @@ -1,3 +1,4 @@ +use crate::parsing::SourcePos; use std::sync::{Arc, Mutex}; use crate::{ @@ -9,6 +10,7 @@ use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct Function { + pub pos_in_src: SourcePos, pub arg: Box, pub run: Box, } @@ -30,6 +32,7 @@ impl MersStatement for Function { let arg2 = Arc::clone(&arg_target); let run2 = Arc::clone(&run); Ok(Box::new(program::run::function::Function { + pos_in_src: self.pos_in_src, func_no_info: data::function::Function { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new(CheckInfo::neverused())), @@ -38,7 +41,7 @@ impl MersStatement for Function { Ok(run2.check(i, None)?) }), run: Arc::new(move |arg, info| { - data::defs::assign(arg, &arg_target.run(info)); + data::defs::assign(&arg, &arg_target.run(info)); run.run(info) }), }, diff --git a/mers_lib/src/program/parsed/if.rs b/mers_lib/src/program/parsed/if.rs index 8804349..51751f0 100755 --- a/mers_lib/src/program/parsed/if.rs +++ b/mers_lib/src/program/parsed/if.rs @@ -1,9 +1,10 @@ -use crate::program; +use crate::{parsing::SourcePos, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct If { + pub pos_in_src: SourcePos, pub condition: Box, pub on_true: Box, pub on_false: Option>, @@ -19,6 +20,7 @@ impl MersStatement for If { comp: CompInfo, ) -> Result, String> { Ok(Box::new(program::run::r#if::If { + pos_in_src: self.pos_in_src, condition: self.condition.compile(info, comp)?, on_true: self.on_true.compile(info, comp)?, on_false: if let Some(v) = &self.on_false { diff --git a/mers_lib/src/program/parsed/init_to.rs b/mers_lib/src/program/parsed/init_to.rs index 34b41e1..256f996 100755 --- a/mers_lib/src/program/parsed/init_to.rs +++ b/mers_lib/src/program/parsed/init_to.rs @@ -1,9 +1,11 @@ +use crate::parsing::SourcePos; use crate::program; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct InitTo { + pub pos_in_src: SourcePos, pub target: Box, pub source: Box, } @@ -22,6 +24,7 @@ impl MersStatement for InitTo { comp.is_init = false; let source = self.source.compile(info, comp)?; Ok(Box::new(program::run::assign_to::AssignTo { + pos_in_src: self.pos_in_src, is_init: true, target, source, diff --git a/mers_lib/src/program/parsed/tuple.rs b/mers_lib/src/program/parsed/tuple.rs index 29b35c6..5a33a72 100755 --- a/mers_lib/src/program/parsed/tuple.rs +++ b/mers_lib/src/program/parsed/tuple.rs @@ -1,9 +1,10 @@ -use crate::{info, program}; +use crate::{info, parsing::SourcePos, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct Tuple { + pub pos_in_src: SourcePos, pub elems: Vec>, } impl MersStatement for Tuple { @@ -16,6 +17,7 @@ impl MersStatement for Tuple { comp: CompInfo, ) -> Result, String> { Ok(Box::new(program::run::tuple::Tuple { + pos_in_src: self.pos_in_src, elems: self .elems .iter() diff --git a/mers_lib/src/program/parsed/value.rs b/mers_lib/src/program/parsed/value.rs index 8e20eaa..f4dbbf9 100755 --- a/mers_lib/src/program/parsed/value.rs +++ b/mers_lib/src/program/parsed/value.rs @@ -1,9 +1,13 @@ +use crate::parsing::SourcePos; use crate::{data::Data, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] -pub struct Value(pub Data); +pub struct Value { + pub pos_in_src: SourcePos, + pub data: Data, +} impl MersStatement for Value { fn has_scope(&self) -> bool { @@ -15,7 +19,8 @@ impl MersStatement for Value { _comp: CompInfo, ) -> Result, String> { Ok(Box::new(program::run::value::Value { - val: self.0.clone(), + pos_in_src: self.pos_in_src, + val: self.data.clone(), })) } } diff --git a/mers_lib/src/program/parsed/variable.rs b/mers_lib/src/program/parsed/variable.rs index a94118d..e035d50 100755 --- a/mers_lib/src/program/parsed/variable.rs +++ b/mers_lib/src/program/parsed/variable.rs @@ -1,9 +1,10 @@ -use crate::{info::Local, program}; +use crate::{info::Local, parsing::SourcePos, program}; use super::{CompInfo, MersStatement}; #[derive(Debug)] pub struct Variable { + pub pos_in_src: SourcePos, pub is_ref: bool, pub var: String, } @@ -27,6 +28,7 @@ impl MersStatement for Variable { ) } Ok(Box::new(program::run::variable::Variable { + pos_in_src: self.pos_in_src, is_init: comp.is_init, is_ref: comp.is_init || self.is_ref, var: if let Some(v) = info.get_var(&self.var) { diff --git a/mers_lib/src/program/run/assign_to.rs b/mers_lib/src/program/run/assign_to.rs index 545ba30..152d146 100755 --- a/mers_lib/src/program/run/assign_to.rs +++ b/mers_lib/src/program/run/assign_to.rs @@ -1,9 +1,13 @@ -use crate::data::{self, Type}; +use crate::{ + data::{self, Type}, + parsing::SourcePos, +}; use super::{CheckError, CheckInfo, MersStatement}; #[derive(Debug)] pub struct AssignTo { + pub pos_in_src: SourcePos, pub is_init: bool, pub target: Box, pub source: Box, @@ -27,10 +31,13 @@ impl MersStatement for AssignTo { fn run_custom(&self, info: &mut super::Info) -> crate::data::Data { let source = self.source.run(info); let target = self.target.run(info); - data::defs::assign(source, &target); + data::defs::assign(&source, &target); target } fn has_scope(&self) -> bool { false } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/block.rs b/mers_lib/src/program/run/block.rs index 10a3212..3ced007 100755 --- a/mers_lib/src/program/run/block.rs +++ b/mers_lib/src/program/run/block.rs @@ -1,9 +1,10 @@ -use crate::data::Type; +use crate::{data::Type, parsing::SourcePos}; use super::{CheckError, MersStatement}; #[derive(Debug)] pub struct Block { + pub pos_in_src: SourcePos, pub statements: Vec>, } impl MersStatement for Block { @@ -31,4 +32,7 @@ impl MersStatement for Block { fn has_scope(&self) -> bool { true } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/chain.rs b/mers_lib/src/program/run/chain.rs index 1647c2a..224ef15 100755 --- a/mers_lib/src/program/run/chain.rs +++ b/mers_lib/src/program/run/chain.rs @@ -1,11 +1,15 @@ use std::sync::Arc; -use crate::data::{Data, Type}; +use crate::{ + data::{Data, Type}, + parsing::SourcePos, +}; use super::{CheckError, MersStatement}; #[derive(Debug)] pub struct Chain { + pub pos_in_src: SourcePos, pub first: Box, pub chained: Box, } @@ -54,4 +58,7 @@ impl MersStatement for Chain { fn has_scope(&self) -> bool { false } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/function.rs b/mers_lib/src/program/run/function.rs index f34ca7e..651e238 100755 --- a/mers_lib/src/program/run/function.rs +++ b/mers_lib/src/program/run/function.rs @@ -1,11 +1,15 @@ use std::sync::Arc; -use crate::data::{self, Data, MersData, Type}; +use crate::{ + data::{self, Data, MersData, Type}, + parsing::SourcePos, +}; use super::{CheckError, MersStatement}; #[derive(Debug)] pub struct Function { + pub pos_in_src: SourcePos, pub func_no_info: data::function::Function, } @@ -29,4 +33,7 @@ impl MersStatement for Function { fn has_scope(&self) -> bool { true } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/if.rs b/mers_lib/src/program/run/if.rs index 113bfe6..a4a275f 100755 --- a/mers_lib/src/program/run/if.rs +++ b/mers_lib/src/program/run/if.rs @@ -1,11 +1,15 @@ use std::sync::Arc; -use crate::data::{self, Data, MersType, Type}; +use crate::{ + data::{self, Data, MersType, Type}, + parsing::SourcePos, +}; use super::{CheckError, MersStatement}; #[derive(Debug)] pub struct If { + pub pos_in_src: SourcePos, pub condition: Box, pub on_true: Box, pub on_false: Option>, @@ -55,4 +59,7 @@ impl MersStatement for If { fn has_scope(&self) -> bool { true } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/mod.rs b/mers_lib/src/program/run/mod.rs index 97521ae..5db0447 100755 --- a/mers_lib/src/program/run/mod.rs +++ b/mers_lib/src/program/run/mod.rs @@ -6,6 +6,7 @@ use std::{ use crate::{ data::{self, Data, Type}, info, + parsing::SourcePos, }; #[cfg(feature = "run")] @@ -34,6 +35,7 @@ pub trait MersStatement: Debug + Send + Sync { fn run_custom(&self, info: &mut Info) -> Data; /// if true, local variables etc. will be contained inside their own scope. fn has_scope(&self) -> bool; + fn pos_in_src(&self) -> &SourcePos; fn check(&self, info: &mut CheckInfo, assign: Option<&Type>) -> Result { if self.has_scope() { info.create_scope(); diff --git a/mers_lib/src/program/run/tuple.rs b/mers_lib/src/program/run/tuple.rs index ef5bee1..e7ff5ac 100755 --- a/mers_lib/src/program/run/tuple.rs +++ b/mers_lib/src/program/run/tuple.rs @@ -1,11 +1,15 @@ use std::sync::Arc; -use crate::data::{self, tuple::TupleT, Data, Type}; +use crate::{ + data::{self, tuple::TupleT, Data, Type}, + parsing::SourcePos, +}; use super::{CheckError, MersStatement}; #[derive(Debug)] pub struct Tuple { + pub pos_in_src: SourcePos, pub elems: Vec>, } impl MersStatement for Tuple { @@ -31,7 +35,7 @@ impl MersStatement for Tuple { } } else { return Err(CheckError( - "can't init to statement type Tuple with value type {t}, which is part of {init_to} - only tuples can be assigned to tuples".to_string(), + format!("can't init to statement type Tuple with value type {t}, which is part of {init_to} - only tuples can be assigned to tuples"), )); } } @@ -64,4 +68,7 @@ impl MersStatement for Tuple { fn has_scope(&self) -> bool { false } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/value.rs b/mers_lib/src/program/run/value.rs index d4487d7..21b9cdf 100755 --- a/mers_lib/src/program/run/value.rs +++ b/mers_lib/src/program/run/value.rs @@ -1,9 +1,13 @@ -use crate::data::{Data, Type}; +use crate::{ + data::{Data, Type}, + parsing::SourcePos, +}; use super::{CheckError, MersStatement}; #[derive(Debug)] pub struct Value { + pub pos_in_src: SourcePos, pub val: Data, } @@ -24,4 +28,7 @@ impl MersStatement for Value { fn run_custom(&self, _info: &mut super::Info) -> Data { self.val.clone() } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } } diff --git a/mers_lib/src/program/run/variable.rs b/mers_lib/src/program/run/variable.rs index 1546fbe..6d69cc2 100755 --- a/mers_lib/src/program/run/variable.rs +++ b/mers_lib/src/program/run/variable.rs @@ -1,11 +1,15 @@ use std::sync::{Arc, Mutex}; -use crate::data::{self, Data, Type}; +use crate::{ + data::{self, Data, Type}, + parsing::SourcePos, +}; use super::MersStatement; #[derive(Debug)] pub struct Variable { + pub pos_in_src: SourcePos, pub is_init: bool, pub is_ref: bool, pub var: (usize, usize), @@ -55,4 +59,7 @@ impl MersStatement for Variable { .clone() } } + fn pos_in_src(&self) -> &SourcePos { + &self.pos_in_src + } }