From dcb10f9601b1618b2187179bcaf0d23b400a2140 Mon Sep 17 00:00:00 2001 From: Robert-M-Lucas <100799838+Robert-M-Lucas@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:21:11 +0100 Subject: [PATCH] Added imports --- build/out.asm | 275 ++++++++++++++++++++++++++++++- build/out.o | Bin 592 -> 2608 bytes build/out.out | Bin 16480 -> 17664 bytes main.why | 13 +- src/root/errors/parser_errors.rs | 2 + src/root/parser/handle_errors.rs | 6 +- src/root/parser/location.rs | 22 +++ src/root/parser/parse.rs | 36 +++- src/root/parser/use_parser.rs | 41 +++++ todo.md | 2 +- 10 files changed, 372 insertions(+), 25 deletions(-) diff --git a/build/out.asm b/build/out.asm index ace0deb..6ce2918 100644 --- a/build/out.asm +++ b/build/out.asm @@ -5,10 +5,281 @@ section .text main: push rbp mov rbp, rsp - mov qword [rbp-8], 3 - mov qword [rbp-16], 8 + sub rsp, 24 + call _10 + add rsp, 24 + mov rax, qword [rbp-24] + mov qword [rbp-8], rax + mov rax, rbp + add rax, -8 + mov qword [rbp-32], rax + mov qword [rbp-40], 12 + mov rax, qword [rbp-40] + mov qword [rbp-64], rax + mov rax, qword [rbp-32] + mov qword [rbp-72], rax + sub rsp, 72 + call _11 + add rsp, 72 + mov rax, rbp + add rax, -8 + mov qword [rbp-64], rax + mov rax, qword [rbp-64] + mov qword [rbp-72], rax + sub rsp, 72 + call _12 + add rsp, 72 + mov qword [rbp-72], 8 + mov rax, qword [rbp-72] + leave + ret + + +_10: + push rbp + mov rbp, rsp + mov qword [rbp+16], 0 + leave + ret + + +_11: + push rbp + mov rbp, rsp + mov rax, [rbp+16] + add rax, 0 + mov qword [rbp-17], rax + mov rdx, qword [rbp-17] + mov rax, qword [rdx+0] + mov qword [rbp-9], rax + mov rax, qword [rbp-9] + cmp rax, 0 + jz __36_12 + mov byte [rbp-1], 0 + jmp __36_13 + __36_12: + mov byte [rbp-1], 1 + __36_13: + cmp byte [rbp-1], 0 + jz _11_15 + mov rax, [rbp+16] + add rax, 0 + mov qword [rbp-25], rax + mov rax, qword [rbp+24] + mov qword [rbp-41], rax + mov rax, qword [rbp-41] + mov qword [rbp-57], rax + sub rsp, 57 + call _13 + add rsp, 57 + mov rax, qword [rbp-49] + mov qword [rbp-33], rax + mov rdx, qword [rbp-25] + mov rax, qword [rbp-33] + mov qword [rdx+0], rax + jmp _11_14 + _11_15: + mov rax, [rbp+16] + add rax, 0 + mov qword [rbp-25], rax + mov rdx, qword [rbp-25] + mov rax, qword [rdx+0] + mov qword [rbp-33], rax + mov rax, qword [rbp+24] + mov qword [rbp-41], rax + mov rax, qword [rbp-41] + mov qword [rbp-65], rax + mov rax, qword [rbp-33] + mov qword [rbp-73], rax + sub rsp, 73 + call _14 + add rsp, 73 + _11_16: + _11_14: + +leave +ret + +_12: + push rbp + mov rbp, rsp + mov rax, [rbp+16] + add rax, 0 + mov qword [rbp-18], rax + mov rdx, qword [rbp-18] + mov rax, qword [rdx+0] + mov qword [rbp-10], rax + mov rax, qword [rbp-10] + cmp rax, 0 + jz __36_0 + mov byte [rbp-2], 0 + jmp __36_1 + __36_0: + mov byte [rbp-2], 1 + __36_1: + mov al, byte [rbp-2] + cmp al, 0 + jz __23_2 + mov byte [rbp-1], 0 + jmp __23_3 + __23_2: + mov byte [rbp-1], 1 + __23_3: + cmp byte [rbp-1], 0 + jz _12_4 + mov rax, [rbp+16] + add rax, 0 + mov qword [rbp-26], rax + mov rdx, qword [rbp-26] + mov rax, qword [rdx+0] + mov qword [rbp-34], rax + mov rax, qword [rbp-34] + mov qword [rbp-42], rax + sub rsp, 42 + call _15 + add rsp, 42 + _12_5: + _12_4: + +leave +ret + +_13: + push rbp + mov rbp, rsp + mov rax, qword [rbp+16] + mov qword [rbp-16], rax + mov qword [rbp-8], 0 + mov rdi, 16 + sub rsp, 16 + extern malloc + call malloc + add rsp, 16 + mov qword [rbp-24], rax + mov rdx, qword [rbp-24] mov rax, qword [rbp-16] + mov qword [rdx+0], rax + mov rax, qword [rbp-8] + mov qword [rdx+8], rax + mov rax, qword [rbp-24] + mov qword [rbp+24], rax leave ret +_14: + push rbp + mov rbp, rsp + mov rax, [rbp+16] + add rax, 8 + mov qword [rbp-17], rax + mov rdx, qword [rbp-17] + mov rax, qword [rdx+0] + mov qword [rbp-9], rax + mov rax, qword [rbp-9] + cmp rax, 0 + jz __36_17 + mov byte [rbp-1], 0 + jmp __36_18 + __36_17: + mov byte [rbp-1], 1 + __36_18: + cmp byte [rbp-1], 0 + jz _14_20 + mov rax, [rbp+16] + add rax, 8 + mov qword [rbp-25], rax + mov rax, qword [rbp+24] + mov qword [rbp-41], rax + mov rax, qword [rbp-41] + mov qword [rbp-57], rax + sub rsp, 57 + call _13 + add rsp, 57 + mov rax, qword [rbp-49] + mov qword [rbp-33], rax + mov rdx, qword [rbp-25] + mov rax, qword [rbp-33] + mov qword [rdx+0], rax + jmp _14_19 + _14_20: + mov rax, [rbp+16] + add rax, 8 + mov qword [rbp-25], rax + mov rdx, qword [rbp-25] + mov rax, qword [rdx+0] + mov qword [rbp-33], rax + mov rax, qword [rbp+24] + mov qword [rbp-41], rax + mov rax, qword [rbp-41] + mov qword [rbp-65], rax + mov rax, qword [rbp-33] + mov qword [rbp-73], rax + sub rsp, 73 + call _14 + add rsp, 73 + _14_21: + _14_19: + +leave +ret + +_15: + push rbp + mov rbp, rsp + mov rax, [rbp+16] + add rax, 0 + mov qword [rbp-16], rax + mov rdx, qword [rbp-16] + mov rax, qword [rdx+0] + mov qword [rbp-8], rax + mov rdi, __8_fstr + mov rsi, [rbp-8] + mov al, 0 + sub rsp, 16 + extern printf + call printf + add rsp, 16 + mov rax, [rbp+16] + add rax, 8 + mov qword [rbp-34], rax + mov rdx, qword [rbp-34] + mov rax, qword [rdx+0] + mov qword [rbp-26], rax + mov rax, qword [rbp-26] + cmp rax, 0 + jz __36_6 + mov byte [rbp-18], 0 + jmp __36_7 + __36_6: + mov byte [rbp-18], 1 + __36_7: + mov al, byte [rbp-18] + cmp al, 0 + jz __23_8 + mov byte [rbp-17], 0 + jmp __23_9 + __23_8: + mov byte [rbp-17], 1 + __23_9: + cmp byte [rbp-17], 0 + jz _15_10 + mov rax, [rbp+16] + add rax, 8 + mov qword [rbp-42], rax + mov rdx, qword [rbp-42] + mov rax, qword [rdx+0] + mov qword [rbp-50], rax + mov rax, qword [rbp-50] + mov qword [rbp-58], rax + sub rsp, 58 + call _15 + add rsp, 58 + _15_11: + _15_10: + +leave +ret + +section .data_readonly + __8_fstr db `Integer: %ld\n`,0 \ No newline at end of file diff --git a/build/out.o b/build/out.o index 3add5ba63690c0c311b1cefa34a37ca0eb187a4c..279baffcf26b7f606138251d6312e62e8b0bb85a 100644 GIT binary patch literal 2608 zcmbW2O>9h26vyw3qC}X8$Sf@CD-n@0Gg?|AC3$iy782>k!t+M-*=k{nM zqAE{BZBbLR3RS9YYRKa@HCxRH(f=D#FS1!OJ!-)Y(IO_|W@AqI96ssYHPa5~PZB$j z@3t6Nv@n7DIDgY0@*Ciny(#4?=kMd!K6rf>Y9kK<5V`&Zr)8-p(U;(RqvcAaoSk zk31c;**rZJPyWG4|Er3B$myr%aP~iYWZDin<}`U$bYf_zkT|Z39k3{d-x2;@=S#|; z^~5QwPj&c>oI6ui{uX#D2_G?zBl->W4Ri=AYYCp)&Mkm10Y^}k0!MTq`e`!;p=@$c zJH-4_Xu!rh_ffDtcxVf@Ph0R9O2eqaH)MRPEO^2!cp`GqnbVFNVYbwP1)UL?JlBZS_z()p)2(ey|?o zpZ1y(s_(U1E|<~%w|mXmf4A2iw&3)={(`rI(N2~00KGOny4Y8`BX+``Fm=V2cEBhH zn+)R*YRsI^7|v(Rp3k@e^|g&mP%@w0HZN zLz!G_!^&)WE}=$0bJAChY0vlET*gcHbZ1Yg#@@rde$MyyV|1#^D$jG7tY>pVzm{@27~mAovoFza#hx=Jy0&!`ytXAzzC5dU2t( z*5F&2H;Z_OxhMEe<{80vGtUXWhxu{AJ?1wBKU9NvF~23^Pcr{1_-W=##L=8*-XQoT z=4rt%GrubMl^XmS^Xnr1HuH%1r*xP3Ou-*8UnuxP=8FY?%3KTnvIZYETr3i70W4PK zJ3nT)N&4mIMh&j^_jP8|YkT_qMz6O^b$OlL%1x|;C6w!?n%zW_HAT!#G+Al3vL3<# z$T9JdWXdH7p`@fsIZ2mdQ|OS*_8hfMd*LEJD(J>~C>c5oT&2kt9+26#)!9X^WJ%t@Aq;xRPOPnEX! Avj6}9 literal 592 zcmb<-^>JfjWMqH=Mg}_u1P><4z~F#jLfH-stPD&@qU13_c7ZS(n)U{$Bc#y81K(7s$UUJ4k`>66$G-d`QidpVFFYo3y=oc!vW<>Kxs*+IFt*g44{UJz(pVo zbo)a+I-hzRcl`k}8%TcuneWl<`r+hZs7Ae#)QS=Yz2c1GlA@BtBp|CY7eYh$P-TQD ski9GnAOB-h$BZS$`GE=ru!u7xm1gFo=;xP~=p`2CGUO&^=Ajq~0N2PPwg3PC diff --git a/build/out.out b/build/out.out index 329ee4f4a7bdf308587d47faee9bad17f78c3590..9b29bb0d2119a5615421fe04eca098a8792fd450 100755 GIT binary patch literal 17664 zcmeHPYiu0V6~4O;#Npv=9uSkzW@r->(t7Q+9mm=57~5HUi~f=u$$UY{gu@E{%9nkq(s&Aidq|Ewua1Jsi|vqld*1f zsj}5o%2F2snT5^P8j_|a@@Uj3L^iTr10?a9siLJlLtd#{N{N&RNfPgLvAJsGiVI9r zq>7m~@wAHDijPm^L+n(fpQlxp@uMu;R9HU7ut-0Tax>jx45qKMbw%WroEM9w@Tf_= z#<(_Djn~_{BJxE}gh=d-)P@I+eBQL*$M{#gp|Hs;;NJdx|zP9)h=+5Ebf zq54PdZzJ<8i@YEn&ZEd>238`azgxhgyqs^5)4YlMJKK3^mpIZZrMwhJa;smE2yzjuHbD~1XH@Y)WG_|-afZI-X337t9NvQIWk%-Fw>>3qd5AA z&Hx>A6yuA@G3mw^=jKp$KEv4K-}(+Nhp1XjN|d8F*jmyxLNQA@=EM0CH!9oKayIt< zd^h@VIzM3vGZ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4epp79Hfn3$Myr<6cq=?7=5 zTGQ6}K{X~^Co%AcX&Muwe<{+$`iB-$Yuo4_m}sK@VIa|zXk#%ok(lT?``#|4R_F3| zW_~j}yR$nxcl`Pz!6YeCgO;tNsgy2xW}LQZ1{CTmU2ClB zqBhV)p^h5IihQQvM79CuRe@j1u=P}*X$gXV$-^vhF6K$-#pdPsyd0k=_%!$D9M02^ zby>4Q6InAYLGVT!CXFyFJ$T3e?c_3#c$q?#W3T`Di>3R2tUMi=y0iIR?S&f-Wn1tS zIO=#DG-uGY9V2QmC;218!%vMr@#OGiv2eIJyuUC$L6~k#9xys!!l^Z}pcH>Twtbcw%%U7S0H5im5du7EW<$8z_^82V!tG;Ay{zmQAKQG)=r_Z@f zljM5YSoED^F1eQ%ik|ZfC@+srUl_gVT&tSoQ_KIvuWq;^>(mXu$Ps@FEjh@h(TCs^<5fRcd&?;2G-n+zdo=wKjlACJs)@F9j7!oL?ezKcBm45@>;pf z%Em-~A7r#>Xz6;n+>8jxR>~~pIDXd$F_oHdDE5p4%LlJ51pauS zp(7dBwm-aYM9US5TB6-Z7>QjSE#QmCJefzk+Ycs^9dURz-snI_n6df%NAV`=5%1-Ie4~N?7 z@AZ;t9*!qSk|;>TyK#~N&!Ip`fH<)p7>N^p#FFdq%)V-?Z}k$wSF@aOc-68i8)q)? zcR+6o(6emxd}8^?m)B30)y#}-$wd3S&OJmA1cnN#^o9PY26{+F2 zg=g6UQZ@XMx(J2tNx0gbf@IIP!SRXlA~A~lj^H?o3Na2J7%3DB(6f8-!`?i_w@~Pd zDQ>5|jGHIe31<*BIcjpW0#*>saWuzK4fJ%(Gse*|cr4utpQU%xw}6^zrV2N2CCey5Ej G81fHZqc!pX diff --git a/main.why b/main.why index c328c4b..44fb610 100644 --- a/main.why +++ b/main.why @@ -1,17 +1,10 @@ use linked_list; -struct Test { - a: int -} - -impl Test { - fn static() { - - } -} fn main() -> int { - let x: Test = Test { a: 3 }; + let x: LL = LL::new(); + x.add(12); + x.print(); return 8; } diff --git a/src/root/errors/parser_errors.rs b/src/root/errors/parser_errors.rs index 3e76768..b631090 100644 --- a/src/root/errors/parser_errors.rs +++ b/src/root/errors/parser_errors.rs @@ -13,6 +13,8 @@ pub enum ParseError { Expected(String), #[error("Failed parsing {0}")] NomErrorKind(String), + #[error("Failed to open file [{0}]")] + FailedToOpenFile(String) } pub fn create_custom_error(e: String, l: Span) -> nom::Err { diff --git a/src/root/parser/handle_errors.rs b/src/root/parser/handle_errors.rs index 8c54119..6dbde53 100644 --- a/src/root/parser/handle_errors.rs +++ b/src/root/parser/handle_errors.rs @@ -6,9 +6,9 @@ use crate::root::parser::location::Location; use crate::root::parser::parse::{ErrorTree, ParseResult, Span}; use crate::root::parser::parse_toplevel::TopLevelTokens; -pub fn handle_error<'a>( - res: ParseResult<'a, Span<'a>, Vec>, -) -> Result<(Span<'a>, Vec), WErr> { +pub fn handle_error( + res: ParseResult, +) -> Result<(A, B), WErr> { match res { Ok(v) => Ok(v), Err(e) => match &e { diff --git a/src/root/parser/location.rs b/src/root/parser/location.rs index dedadd9..7add73e 100644 --- a/src/root/parser/location.rs +++ b/src/root/parser/location.rs @@ -8,6 +8,28 @@ use color_print::cformat; use nom::InputTake; use crate::root::parser::parse::Span; +pub enum ToLocation<'a> { + Location(Location), + Span(Span<'a>) +} + +impl<'a> ToLocation<'a> { + pub fn from_location(location: Location) -> ToLocation<'a> { + ToLocation::Location(location) + } + + pub fn from_span(span: Span<'a>) -> ToLocation<'a> { + ToLocation::Span(span) + } + + pub fn to_location(self) -> Location { + match self { + ToLocation::Location(location) => location, + ToLocation::Span(s) => Location::from_span(&s) + } + } +} + #[derive(Debug, Clone, Hash)] struct InnerLocation { /// Path of file diff --git a/src/root/parser/parse.rs b/src/root/parser/parse.rs index 438ea89..48b7203 100644 --- a/src/root/parser/parse.rs +++ b/src/root/parser/parse.rs @@ -5,11 +5,13 @@ use std::rc::Rc; use nom::IResult; use nom_locate::LocatedSpan; use nom_supreme::error::GenericErrorTree; - +use crate::root::errors::parser_errors::ParseError; use crate::root::errors::WErr; use crate::root::parser::handle_errors::handle_error; +use crate::root::parser::location::{Location, ToLocation}; use crate::root::parser::parse_toplevel; use crate::root::parser::parse_toplevel::TopLevelTokens; +use crate::root::parser::use_parser::parse_uses; pub type Span<'a> = LocatedSpan<&'a str, &'a Rc>; @@ -17,14 +19,30 @@ pub type ParseResult<'a, I = Span<'a>, O = Span<'a>, E = ErrorTree<'a>> = IResul pub type ErrorTree<'a> = GenericErrorTree, &'static str, &'static str, String>; pub fn parse(path: PathBuf) -> Result, WErr> { - let text = fs::read_to_string(&path).unwrap(); - let path = Rc::new(path); - let base = Span::new_extra(&text, &path); - - let res = parse_toplevel::parse_toplevel(base); - let (remaining, output) = handle_error(res)?; - - debug_assert!(remaining.is_empty()); + let mut path_queue = vec![(path, Location::builtin())]; + let mut output = Vec::new(); + + while let Some((path, location)) = path_queue.pop() { + print!("\n - {}", path.display()); + let Ok(text) = fs::read_to_string(path.as_path()) else { + return WErr::ne( + ParseError::FailedToOpenFile(format!("{}", path.display())), + location + ); + }; + + let path = Rc::new(path); + let base = Span::new_extra(&text, &path); + + let (after_use, found_paths) = handle_error(parse_uses(base))?; + path_queue.extend(found_paths); + + let res = parse_toplevel::parse_toplevel(after_use); + let (remaining, new_output) = handle_error(res)?; + debug_assert!(remaining.is_empty()); + output.extend(new_output); + } + println!(); Ok(output) } diff --git a/src/root/parser/use_parser.rs b/src/root/parser/use_parser.rs index e69de29..e28a964 100644 --- a/src/root/parser/use_parser.rs +++ b/src/root/parser/use_parser.rs @@ -0,0 +1,41 @@ +use std::fmt::format; +use std::path::PathBuf; +use nom::bytes::complete::{tag, take_till}; +use nom::character::complete::anychar; +use nom::complete::take; +use crate::root::errors::parser_errors::create_custom_error; +use crate::root::parser::location::{Location, ToLocation}; +use crate::root::parser::parse::{ErrorTree, ParseResult, Span}; +use crate::root::parser::parse_util::discard_ignored; + +pub fn parse_uses(s: Span) -> ParseResult> { + let mut s = s; + let mut found_paths = Vec::new(); + loop { + let (ns, _) = discard_ignored(s)?; + let Ok((ns, _)) = tag::<_, _, ErrorTree>("use")(ns) else { + return Ok((ns, found_paths)); + }; + + let (ns, _) = discard_ignored(ns)?; + let Ok((pre_s, path)) = take_till::<_, _, ErrorTree>(|c| c == ';' || c =='\n' || c=='\r')(ns) else { + return Err(create_custom_error( + "Did not find ending ';' when parsing path".to_string(), + ns, + )); + }; + + let (ns, next) = anychar::<_, ErrorTree>(pre_s).unwrap(); + if next != ';' { + return Err(create_custom_error( + "Use path cannot be broken by newline".to_string(), + pre_s, + )); + } + + let path_buf = PathBuf::from(format!("{}.why", path)); + found_paths.push((path_buf, Location::from_span(&path))); + + s = ns; + } +} \ No newline at end of file diff --git a/todo.md b/todo.md index 959d0d6..8c7865f 100644 --- a/todo.md +++ b/todo.md @@ -1,3 +1,3 @@ - Add array support -- Add support for multiple files +- Namespacing