From 1764617f5675c736453c1a96d94dd7fc27a4b50c Mon Sep 17 00:00:00 2001 From: Champii Date: Thu, 9 Jun 2022 20:51:02 +0200 Subject: [PATCH 01/22] Bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20f42240..2c951765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -473,7 +473,7 @@ checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "rock" -version = "0.4.0" +version = "0.4.1" dependencies = [ "bincode", "bitflags", diff --git a/Cargo.toml b/Cargo.toml index e4cda772..68efdaac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rock" -version = "0.4.0" +version = "0.4.1" authors = ["champii "] edition = "2018" diff --git a/README.md b/README.md index 2fcd796c..896b299b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Rock v0.4.0 +# Rock v0.4.1 [![Rust](https://github.com/Champii/Rock/actions/workflows/rust.yml/badge.svg?branch=master)](https://github.com/Champii/Rock/actions/workflows/rust.yml) @@ -11,7 +11,7 @@ No to be taken seriously (yet) ## Index -- [Rock v0.4.0](#rock-v0.4.0) +- [Rock v0.4.1](#rock-v0.4.1) - [Index](#index) - [Features](#features) - [Install](#install) @@ -55,10 +55,10 @@ You will need `clang` somewhere in your $PATH Linux x86_64 only -[Rock v0.4.0](https://github.com/Champii/Rock/releases/download/v0.4.0/rock) (Tested on arch, btw) +[Rock v0.4.1](https://github.com/Champii/Rock/releases/download/v0.4.1/rock) (Tested on arch, btw) ``` sh -wget https://github.com/Champii/Rock/releases/download/v0.4.0/rock +wget https://github.com/Champii/Rock/releases/download/v0.4.1/rock chmod +x rock ./rock -V ``` From d5ee7a3ef145c05c8d11b3ef0e27d7c42aafbe27 Mon Sep 17 00:00:00 2001 From: Champii Date: Thu, 9 Jun 2022 21:24:05 +0200 Subject: [PATCH 02/22] Fix readme indentation --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 896b299b..2b2ac6c4 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,9 @@ rock new factorial && cd factorial ```haskell fact: x -> - if x <= 1 - then 1 - else x * fact (x - 1) + if x <= 1 + then 1 + else x * fact (x - 1) main: -> fact 4 .print! ``` From 3d57628c32cb06b1e0cc341fce10454a7ada7aa0 Mon Sep 17 00:00:00 2001 From: Champii Date: Fri, 10 Jun 2022 04:02:09 +0200 Subject: [PATCH 03/22] Add indented comments --- src/bin/main.rs | 2 +- src/lib/parser/mod.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 32e9c0b6..edf84a66 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -89,7 +89,7 @@ fn run(config: Config) { fn main() { let matches = App::new("Rock") .version(env!("CARGO_PKG_VERSION")) - .about("Simple toy language") + .about("A compiler for the Rock programming language") .arg( Arg::with_name("verbose") .takes_value(false) diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index edf9571d..d0fc0f91 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -263,7 +263,11 @@ pub fn parse_top_level(input: Parser) -> Res { } pub fn parse_comment(input: Parser) -> Res { - let (input, _) = tuple((tag("#"), many0(satisfy(|c: char| c != '\n'))))(input)?; + let (input, _) = tuple(( + opt(parse_block_indent), + tag("#"), + many0(satisfy(|c: char| c != '\n')), + ))(input)?; Ok((input, ())) } From 9571af5974f24823e496ebdce44b620baf7086bb Mon Sep 17 00:00:00 2001 From: Champii Date: Fri, 10 Jun 2022 04:15:48 +0200 Subject: [PATCH 04/22] Better indented comments --- src/lib/parser/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index d0fc0f91..0ac741dd 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -265,6 +265,7 @@ pub fn parse_top_level(input: Parser) -> Res { pub fn parse_comment(input: Parser) -> Res { let (input, _) = tuple(( opt(parse_block_indent), + space0, tag("#"), many0(satisfy(|c: char| c != '\n')), ))(input)?; From b4be46832284efc1d6131d8cfb0ddc38daa5a6b2 Mon Sep 17 00:00:00 2001 From: Champii Date: Sun, 12 Jun 2022 16:43:31 +0200 Subject: [PATCH 05/22] Fix dot and indices as lefthand side of assignment --- README.md | 10 +++++++++- src/lib/ast_lowering/ast_lowering_context.rs | 20 ++++++++++++-------- src/lib/codegen/codegen_context.rs | 1 - src/lib/infer/constraint.rs | 2 ++ src/lib/parser/mod.rs | 5 ++--- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2b2ac6c4..097df910 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,17 @@ $ rock run 24 ``` +Rock should have produced a `./build/` folder, that contains your `a.out` executable. +You can execute it directly: + +```sh +$ ./build/a.out +24 +``` + Take a look at `rock --help` for a quick tour of its flags and arguments -Note that you currently must be at the project root to run the compiler. (i.e. inside the `./factorial/` folder) +Note that you currently MUST be at the project root to run the compiler. (i.e. inside the `./factorial/` folder) ## Showcases diff --git a/src/lib/ast_lowering/ast_lowering_context.rs b/src/lib/ast_lowering/ast_lowering_context.rs index 84175cab..5b3caa09 100644 --- a/src/lib/ast_lowering/ast_lowering_context.rs +++ b/src/lib/ast_lowering/ast_lowering_context.rs @@ -289,25 +289,29 @@ impl AstLoweringContext { } AssignLeftSide::Indice(indice) => { let expr_hir = self.lower_expression(indice); - let indice = match &*expr_hir.kind { - hir::ExpressionKind::Indice(indice) => indice, + let res = match &*expr_hir.kind { + hir::ExpressionKind::Dot(dot) => hir::AssignLeftSide::Dot(dot.clone()), + hir::ExpressionKind::Indice(indice) => { + hir::AssignLeftSide::Indice(indice.clone()) + } _ => unimplemented!( - "Assign left hand side can be Identifiers, Indices or dot notation" + "Assign left hand side can be Identifiers, Indices or dot notation, found {:#?}", expr_hir ), }; - hir::AssignLeftSide::Indice(indice.clone()) + res } AssignLeftSide::Dot(dot) => { let expr_hir = self.lower_expression(dot); - let dot = match &*expr_hir.kind { - hir::ExpressionKind::Dot(dot) => dot, + let res = match &*expr_hir.kind { + hir::ExpressionKind::Dot(dot) => hir::AssignLeftSide::Dot(dot.clone()), + hir::ExpressionKind::Indice(indice) => hir::AssignLeftSide::Indice(indice.clone()), _ => unimplemented!( - "Assign left hand side can be Identifiers, Indices or dot notation" + "Assign left hand side can be Identifiers, Indices or dot notation, found {:#?}", expr_hir ), }; - hir::AssignLeftSide::Dot(dot.clone()) + res } } } diff --git a/src/lib/codegen/codegen_context.rs b/src/lib/codegen/codegen_context.rs index d9bd3a93..e4252ffe 100644 --- a/src/lib/codegen/codegen_context.rs +++ b/src/lib/codegen/codegen_context.rs @@ -543,7 +543,6 @@ impl<'a> CodegenContext<'a> { builder.position_at_end(*block_a); - builder.build_unconditional_branch(exit_block); phi.add_incoming(&[(value_a, *block_a)]); diff --git a/src/lib/infer/constraint.rs b/src/lib/infer/constraint.rs index 5fac2d21..50ae4ede 100644 --- a/src/lib/infer/constraint.rs +++ b/src/lib/infer/constraint.rs @@ -160,10 +160,12 @@ impl<'a> ConstraintContext<'a> { .envs .set_current_fn((p.hir_id.clone(), p.signature.clone())) { + error!("cannot set current fn"); return; } if !self.envs.set_current_fn(old_f) { + error!("cannot set current fn"); return; } diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 0ac741dd..3ac503ca 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -490,7 +490,6 @@ pub fn parse_fn(input: Parser) -> Res { terminated(space0, tag(":")), space1, separated_list0(tuple((space0, tag(","), space0)), parse_identifier), - // many0(preceded(space1, parse_identifier)), )), delimited(space0, tag("->"), space0), ), @@ -605,7 +604,7 @@ pub fn parse_if(input: Parser) -> Res { } pub fn parse_then_multi(input: Parser) -> Res { - // NOTE: This is a tweek for then block that are at indent 0 (i.e. in the test files) + // NOTE: This is a tweek for then blocks that are at indent 0 (i.e. in the test files) let (input, indent) = if input.extra.first_indent.is_some() && input.extra.block_indent > 0 { parse_block_indent(input)? } else { @@ -625,7 +624,7 @@ pub fn parse_then_multi(input: Parser) -> Res { } pub fn parse_else(input: Parser) -> Res { - // NOTE: This is a tweek for else block that are at indent 0 (i.e. in the test files) + // NOTE: This is a tweek for else blocks that are at indent 0 (i.e. in the test files) let (input, indent) = if input.extra.first_indent.is_some() && input.extra.block_indent > 0 { parse_block_indent(input)? } else { From ba5ff46adfabb4be42003f62630f10df2a51c092 Mon Sep 17 00:00:00 2001 From: Champii Date: Mon, 13 Jun 2022 01:02:07 +0200 Subject: [PATCH 06/22] Add negative integers and float (#114) --- Cargo.toml | 2 +- src/lib/codegen/codegen_context.rs | 10 ++++- src/lib/parser/mod.rs | 16 +++++++- src/lib/parser/source_file.rs | 39 +++++++++++++------ .../basic/negative_floats/0_arg_fn/main.rk | 3 ++ .../negative_floats/0_arg_fn/main.rk.out | 1 + .../negative_floats/0_arg_fn/main.rk.stdout | 0 .../testcases/basic/negative_floats/main.rk | 14 +++++++ .../basic/negative_floats/main.rk.out | 1 + .../basic/negative_floats/main.rk.stdout | 0 .../basic/negative_numbers/0_arg_fn/main.rk | 3 ++ .../negative_numbers/0_arg_fn/main.rk.out | 1 + .../negative_numbers/0_arg_fn/main.rk.stdout | 0 .../testcases/basic/negative_numbers/main.rk | 9 +++++ .../basic/negative_numbers/main.rk.out | 1 + .../basic/negative_numbers/main.rk.stdout | 0 src/lib/tests.rs | 16 ++++++++ 17 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk create mode 100644 src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.out create mode 100644 src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.stdout create mode 100644 src/lib/testcases/basic/negative_floats/main.rk create mode 100644 src/lib/testcases/basic/negative_floats/main.rk.out create mode 100644 src/lib/testcases/basic/negative_floats/main.rk.stdout create mode 100644 src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk create mode 100644 src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.out create mode 100644 src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.stdout create mode 100644 src/lib/testcases/basic/negative_numbers/main.rk create mode 100644 src/lib/testcases/basic/negative_numbers/main.rk.out create mode 100644 src/lib/testcases/basic/negative_numbers/main.rk.stdout diff --git a/Cargo.toml b/Cargo.toml index 68efdaac..64c3b914 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] clap = "2.32.0" lazy_static = "1.2.0" -regex = "1" +regex = "1.5.6" env_logger = "0.5.12" log = "0.4" bitflags = "1.2.1" diff --git a/src/lib/codegen/codegen_context.rs b/src/lib/codegen/codegen_context.rs index e4252ffe..a9dce4cb 100644 --- a/src/lib/codegen/codegen_context.rs +++ b/src/lib/codegen/codegen_context.rs @@ -756,10 +756,16 @@ impl<'a> CodegenContext<'a> { builder: &'a Builder, ) -> Result, ()> { Ok(match &lit.kind { - LiteralKind::Number(n) => { + LiteralKind::Number(mut n) => { let i64_type = self.context.i64_type(); - i64_type.const_int((*n).try_into().unwrap(), false).into() + let mut negative = false; + if n < 0 { + negative = true; + n = -n; + } + + i64_type.const_int((n).try_into().unwrap(), negative).into() } LiteralKind::Float(n) => { let f64_type = self.context.f64_type(); diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 3ac503ca..56a82581 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -1046,25 +1046,37 @@ pub fn parse_bool(input: Parser) -> Res { } pub fn parse_float(input: Parser) -> Res { + let (input, is_neg) = opt(char('-'))(input)?; + let (input, float_parsed) = recognize(tuple((parse_number, char('.'), opt(parse_number))))(input)?; - let num: f64 = float_parsed + let mut num: f64 = float_parsed .parse() .map_err(|_| Err::Error(make_error(input.clone(), ErrorKind::Digit)))?; + if is_neg.is_some() { + num *= -1.0; + } + let (input, node_id) = new_identity(input, &float_parsed); Ok((input, Literal::new_float(num, node_id))) } pub fn parse_number(input: Parser) -> Res { + let (input, is_neg) = opt(char('-'))(input)?; + let (input, parsed) = take_while(is_digit)(input)?; - let num: i64 = parsed + let mut num: i64 = parsed .parse() .map_err(|_| Err::Error(make_error(input.clone(), ErrorKind::Digit)))?; + if is_neg.is_some() { + num *= -1; + } + let (input, node_id) = new_identity(input, &parsed); Ok((input, Literal::new_number(num, node_id))) diff --git a/src/lib/parser/source_file.rs b/src/lib/parser/source_file.rs index ef6587a5..0fecee8b 100644 --- a/src/lib/parser/source_file.rs +++ b/src/lib/parser/source_file.rs @@ -3,6 +3,8 @@ use std::{ path::{Path, PathBuf}, }; +use regex::Regex; + use crate::diagnostics::Diagnostic; use super::span::Span; @@ -22,9 +24,11 @@ impl SourceFile { fs::read_to_string(in_name.clone()).map_err(|_| { Diagnostic::new_file_not_found(Span::new_placeholder(), in_name.clone()) })? - // We manually add a endofline to avoid out of bounds error - // as the parser requires a newline at the end of the file - } + "\n"; + }; + + let content = Self::filter_content(&content); + + let content = content.replace("^[ \t]*\n", "\n"); let mut mod_path = PathBuf::from(in_name.clone()); @@ -42,12 +46,12 @@ impl SourceFile { mod_path.set_extension(""); + let content = Self::filter_content(&content); + Ok(SourceFile { file_path: PathBuf::from(path.clone()), mod_path, - // We manually add a endofline to avoid out of bounds error - // as the parser requires a newline at the end of the file - content: content.to_string() + "\n", + content, }) } @@ -78,12 +82,12 @@ custom = .to_owned() + &expr; + let content = Self::filter_content(&top_levels); + Ok(SourceFile { file_path: PathBuf::from("./src/main.rk"), mod_path: PathBuf::from("root"), - // We manually add a endofline to avoid out of bounds error - // as the parser requires a newline at the end of the file - content: top_levels + "\n", + content, }) } @@ -97,9 +101,9 @@ custom = let content = match fs::read_to_string(file_path.to_str().unwrap().to_string()) { Ok(content) => content, Err(_) => return Err(mod_path.as_path().to_str().unwrap().to_string()), - // We manually add a endofline to avoid out of bounds error - // as the parser requires a newline at the end of the file - } + "\n"; + }; + + let content = Self::filter_content(&content); Ok(Self { file_path, @@ -107,4 +111,15 @@ custom = content, }) } + + // This function replace the lines containing only whitespaces and tabs with a newline + // And append a \n at the end of file to avoid out of bounds error as the parser requires + // a newline at the end of the file + fn filter_content(content: &str) -> String { + Regex::new(r"[ \t]+\n") + .unwrap() + .replace_all(content, "\n\n") + .to_string() + + "\n" + } } diff --git a/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk b/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk new file mode 100644 index 00000000..805265cf --- /dev/null +++ b/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk @@ -0,0 +1,3 @@ +f: -> 42 +main: -> f() + diff --git a/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.out b/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.stdout b/src/lib/testcases/basic/negative_floats/0_arg_fn/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/testcases/basic/negative_floats/main.rk b/src/lib/testcases/basic/negative_floats/main.rk new file mode 100644 index 00000000..d296940f --- /dev/null +++ b/src/lib/testcases/basic/negative_floats/main.rk @@ -0,0 +1,14 @@ +infix + 5 +infix - 5 +infix * 4 +infix == 3 ++: a, b -> ~FAdd a b +-: a, b -> ~FSub a b +*: a, b -> ~FMul a b +==: a, b -> ~FEq a b +f: -> -42.0 +main: -> + if f() * -1.0 + 1.0 - 1.0 == 42.0 + then 42 + else 0 + diff --git a/src/lib/testcases/basic/negative_floats/main.rk.out b/src/lib/testcases/basic/negative_floats/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/negative_floats/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/negative_floats/main.rk.stdout b/src/lib/testcases/basic/negative_floats/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk b/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk new file mode 100644 index 00000000..805265cf --- /dev/null +++ b/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk @@ -0,0 +1,3 @@ +f: -> 42 +main: -> f() + diff --git a/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.out b/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.stdout b/src/lib/testcases/basic/negative_numbers/0_arg_fn/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/testcases/basic/negative_numbers/main.rk b/src/lib/testcases/basic/negative_numbers/main.rk new file mode 100644 index 00000000..edd29d4c --- /dev/null +++ b/src/lib/testcases/basic/negative_numbers/main.rk @@ -0,0 +1,9 @@ +infix + 5 +infix - 5 +infix * 4 ++: a, b -> ~IAdd a b +-: a, b -> ~ISub a b +*: a, b -> ~IMul a b +f: -> -42 +main: -> f() * -1 + 1 - 1 + diff --git a/src/lib/testcases/basic/negative_numbers/main.rk.out b/src/lib/testcases/basic/negative_numbers/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/negative_numbers/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/negative_numbers/main.rk.stdout b/src/lib/testcases/basic/negative_numbers/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/tests.rs b/src/lib/tests.rs index bb92f7ae..96b56080 100644 --- a/src/lib/tests.rs +++ b/src/lib/tests.rs @@ -118,6 +118,14 @@ fn testcases_basic_bool_false_main() { run("testcases/basic/bool_false/main.rk", include_str!("testcases/basic/bool_false/main.rk"), include_str!("testcases/basic/bool_false/main.rk.out"), include_str!("testcases/basic/bool_false/main.rk.stdout")); } #[test] +fn testcases_basic_negative_floats_main() { + run("testcases/basic/negative_floats/main.rk", include_str!("testcases/basic/negative_floats/main.rk"), include_str!("testcases/basic/negative_floats/main.rk.out"), include_str!("testcases/basic/negative_floats/main.rk.stdout")); +} +#[test] +fn testcases_basic_negative_floats_0_arg_fn_main() { + run("testcases/basic/negative_floats/0_arg_fn/main.rk", include_str!("testcases/basic/negative_floats/0_arg_fn/main.rk"), include_str!("testcases/basic/negative_floats/0_arg_fn/main.rk.out"), include_str!("testcases/basic/negative_floats/0_arg_fn/main.rk.stdout")); +} +#[test] fn testcases_basic_nested_array_main() { run("testcases/basic/nested_array/main.rk", include_str!("testcases/basic/nested_array/main.rk"), include_str!("testcases/basic/nested_array/main.rk.out"), include_str!("testcases/basic/nested_array/main.rk.stdout")); } @@ -190,6 +198,14 @@ fn testcases_basic_2_arg_fn_main() { run("testcases/basic/2_arg_fn/main.rk", include_str!("testcases/basic/2_arg_fn/main.rk"), include_str!("testcases/basic/2_arg_fn/main.rk.out"), include_str!("testcases/basic/2_arg_fn/main.rk.stdout")); } #[test] +fn testcases_basic_negative_numbers_main() { + run("testcases/basic/negative_numbers/main.rk", include_str!("testcases/basic/negative_numbers/main.rk"), include_str!("testcases/basic/negative_numbers/main.rk.out"), include_str!("testcases/basic/negative_numbers/main.rk.stdout")); +} +#[test] +fn testcases_basic_negative_numbers_0_arg_fn_main() { + run("testcases/basic/negative_numbers/0_arg_fn/main.rk", include_str!("testcases/basic/negative_numbers/0_arg_fn/main.rk"), include_str!("testcases/basic/negative_numbers/0_arg_fn/main.rk.out"), include_str!("testcases/basic/negative_numbers/0_arg_fn/main.rk.stdout")); +} +#[test] fn testcases_basic_dot_assign_main() { run("testcases/basic/dot_assign/main.rk", include_str!("testcases/basic/dot_assign/main.rk"), include_str!("testcases/basic/dot_assign/main.rk.out"), include_str!("testcases/basic/dot_assign/main.rk.stdout")); } From 19b40df4a2cc140c1fd1139844024ee6ffbd82fa Mon Sep 17 00:00:00 2001 From: Champii Date: Mon, 13 Jun 2022 02:34:56 +0200 Subject: [PATCH 07/22] Add one liner struct ctor --- src/lib/parser/mod.rs | 69 ++++++++++++++----- .../basic/multi_style_struct_ctor/main.rk | 14 ++++ .../basic/multi_style_struct_ctor/main.rk.out | 1 + .../multi_style_struct_ctor/main.rk.stdout | 0 src/lib/tests.rs | 4 ++ 5 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 src/lib/testcases/basic/multi_style_struct_ctor/main.rk create mode 100644 src/lib/testcases/basic/multi_style_struct_ctor/main.rk.out create mode 100644 src/lib/testcases/basic/multi_style_struct_ctor/main.rk.stdout diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 56a82581..62d28cde 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -263,12 +263,7 @@ pub fn parse_top_level(input: Parser) -> Res { } pub fn parse_comment(input: Parser) -> Res { - let (input, _) = tuple(( - opt(parse_block_indent), - space0, - tag("#"), - many0(satisfy(|c: char| c != '\n')), - ))(input)?; + let (input, _) = tuple((space0, tag("#"), many0(satisfy(|c: char| c != '\n'))))(input)?; Ok((input, ())) } @@ -717,7 +712,10 @@ pub fn parse_assign_left_side(input: Parser) -> Res { pub fn parse_expression(input: Parser) -> Res { alt(( - map(parse_struct_ctor, Expression::new_struct_ctor), + map( + alt((parse_struct_ctor, parse_struct_ctor_one_line)), + Expression::new_struct_ctor, + ), map( preceded(terminated(tag("return"), space1), parse_expression), Expression::new_return, @@ -781,23 +779,58 @@ pub fn parse_native_operator( )(input.clone()) } -pub fn parse_struct_ctor(input: Parser) -> Res { +pub fn parse_struct_ctor_one_line(input: Parser) -> Res { map( tuple(( - // parse_identity, - terminated(parse_capitalized_identifier, line_ending), - indent(separated_list0( + terminated(parse_capitalized_identifier, space1), + separated_list0( + terminated(tag(","), space0), + tuple(( + terminated(parse_identifier, delimited(space0, tag(":"), space0)), + parse_expression, + )), + ), + )), + |(name, decls)| StructCtor::new(name, decls.into_iter().collect()), + )(input) +} + +pub fn parse_struct_ctor(input: Parser) -> Res { + alt(( + map( + tuple(( line_ending, - preceded( + indent(tuple(( parse_block_indent, - tuple(( - terminated(parse_identifier, delimited(space0, tag(":"), space0)), - parse_expression, - )), - ), + terminated(parse_capitalized_identifier, line_ending), + parse_struct_ctor_decls, + ))), + )), + |(_, (_, name, decls))| StructCtor::new(name, decls.into_iter().collect()), + ), + map( + tuple(( + terminated(parse_capitalized_identifier, line_ending), + parse_struct_ctor_decls, )), + |(name, decls)| StructCtor::new(name, decls.into_iter().collect()), + ), + ))(input) +} + +fn parse_struct_ctor_decls(input: Parser) -> Res> { + map( + indent(separated_list0( + line_ending, + preceded( + parse_block_indent, + tuple(( + terminated(parse_identifier, delimited(space0, tag(":"), space0)), + parse_expression, + )), + ), )), - |(name, decls)| StructCtor::new(name, decls.into_iter().collect()), + |decls| decls.into_iter().collect(), )(input) } diff --git a/src/lib/testcases/basic/multi_style_struct_ctor/main.rk b/src/lib/testcases/basic/multi_style_struct_ctor/main.rk new file mode 100644 index 00000000..aabfb39e --- /dev/null +++ b/src/lib/testcases/basic/multi_style_struct_ctor/main.rk @@ -0,0 +1,14 @@ +struct Foo + bar: Int64 + bar2: String +main: -> + let foo = Foo bar: 42, bar2: "hello" + let foo2 = + Foo + bar: 3 + bar2: "world" + let foo3 = Foo + bar: 4 + bar2: "world2" + foo.bar + diff --git a/src/lib/testcases/basic/multi_style_struct_ctor/main.rk.out b/src/lib/testcases/basic/multi_style_struct_ctor/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/multi_style_struct_ctor/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/multi_style_struct_ctor/main.rk.stdout b/src/lib/testcases/basic/multi_style_struct_ctor/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/tests.rs b/src/lib/tests.rs index 96b56080..ff73cf91 100644 --- a/src/lib/tests.rs +++ b/src/lib/tests.rs @@ -162,6 +162,10 @@ fn testcases_basic_fn_arg_main() { run("testcases/basic/fn_arg/main.rk", include_str!("testcases/basic/fn_arg/main.rk"), include_str!("testcases/basic/fn_arg/main.rk.out"), include_str!("testcases/basic/fn_arg/main.rk.stdout")); } #[test] +fn testcases_basic_multi_style_struct_ctor_main() { + run("testcases/basic/multi_style_struct_ctor/main.rk", include_str!("testcases/basic/multi_style_struct_ctor/main.rk"), include_str!("testcases/basic/multi_style_struct_ctor/main.rk.out"), include_str!("testcases/basic/multi_style_struct_ctor/main.rk.stdout")); +} +#[test] fn testcases_basic_fn_arg_array_main() { run("testcases/basic/fn_arg_array/main.rk", include_str!("testcases/basic/fn_arg_array/main.rk"), include_str!("testcases/basic/fn_arg_array/main.rk.out"), include_str!("testcases/basic/fn_arg_array/main.rk.stdout")); } From 480f67798abd5144b206b8923f9b20b7972d469e Mon Sep 17 00:00:00 2001 From: Champii Date: Mon, 13 Jun 2022 02:51:20 +0200 Subject: [PATCH 08/22] Add comments and multiple line endings virtually everywhere --- src/lib/parser/mod.rs | 25 +++++-------------------- src/lib/parser/source_file.rs | 17 ++++++++++------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 62d28cde..537bb4fd 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -238,10 +238,7 @@ pub fn parse_root(input: Parser) -> Res { pub fn parse_mod(input: Parser) -> Res { map( - many1(terminated( - parse_top_level, - many1(preceded(opt(parse_comment), line_ending)), - )), + many1(terminated(parse_top_level, many1(line_ending))), Mod::new, )(input) } @@ -262,18 +259,6 @@ pub fn parse_top_level(input: Parser) -> Res { ))(input) } -pub fn parse_comment(input: Parser) -> Res { - let (input, _) = tuple((space0, tag("#"), many0(satisfy(|c: char| c != '\n'))))(input)?; - - Ok((input, ())) -} - -pub fn parse_eol(input: Parser) -> Res { - let (input, _) = tuple((opt(parse_comment), line_ending))(input)?; - - Ok((input, ())) -} - pub fn parse_mod_decl(input: Parser) -> Res { let config = input.extra.config.clone(); @@ -349,7 +334,7 @@ pub fn parse_trait(input: Parser) -> Res { many0(delimited(space1, parse_type, space0)), many0(line_ending), indent(separated_list1( - line_ending, + many1(line_ending), preceded(parse_block_indent, parse_prototype), )), )), @@ -381,7 +366,7 @@ pub fn parse_struct_decl(input: Parser) -> Res { opt(preceded( many0(line_ending), indent(separated_list1( - line_ending, + many1(line_ending), preceded(parse_block_indent, parse_prototype), )), )), @@ -558,12 +543,12 @@ pub fn parse_block_indent_plus_one(input: Parser) -> Res { } pub fn parse_body(input: Parser) -> Res { - let (input, opt_eol) = opt(line_ending)(input)?; // NOTE: should not fail + let (input, opt_eol) = opt(many1(line_ending))(input)?; // NOTE: should not fail if opt_eol.is_some() { indent(map( separated_list1( - many1(parse_eol), + many1(line_ending), preceded(parse_block_indent, parse_statement), ), Body::new, diff --git a/src/lib/parser/source_file.rs b/src/lib/parser/source_file.rs index 0fecee8b..af525bca 100644 --- a/src/lib/parser/source_file.rs +++ b/src/lib/parser/source_file.rs @@ -26,7 +26,7 @@ impl SourceFile { })? }; - let content = Self::filter_content(&content); + let content = Self::sanitize_content(&content); let content = content.replace("^[ \t]*\n", "\n"); @@ -46,7 +46,7 @@ impl SourceFile { mod_path.set_extension(""); - let content = Self::filter_content(&content); + let content = Self::sanitize_content(&content); Ok(SourceFile { file_path: PathBuf::from(path.clone()), @@ -82,7 +82,7 @@ custom = .to_owned() + &expr; - let content = Self::filter_content(&top_levels); + let content = Self::sanitize_content(&top_levels); Ok(SourceFile { file_path: PathBuf::from("./src/main.rk"), @@ -103,7 +103,7 @@ custom = Err(_) => return Err(mod_path.as_path().to_str().unwrap().to_string()), }; - let content = Self::filter_content(&content); + let content = Self::sanitize_content(&content); Ok(Self { file_path, @@ -112,13 +112,16 @@ custom = }) } - // This function replace the lines containing only whitespaces and tabs with a newline + // This function Remove all the comments + // Then replace the lines containing only whitespaces and tabs with a newline // And append a \n at the end of file to avoid out of bounds error as the parser requires // a newline at the end of the file - fn filter_content(content: &str) -> String { + fn sanitize_content(content: &str) -> String { + let without_comments = Regex::new(r#"#.*\n"#).unwrap().replace_all(content, "\n"); + Regex::new(r"[ \t]+\n") .unwrap() - .replace_all(content, "\n\n") + .replace_all(&without_comments, "\n\n") .to_string() + "\n" } From d3f5662a341b630efb130da228038526fbc1ef96 Mon Sep 17 00:00:00 2001 From: Champii Date: Mon, 13 Jun 2022 03:04:59 +0200 Subject: [PATCH 09/22] Add for basic char support --- src/lib/ast/tree.rs | 8 ++++++++ src/lib/ast/visit.rs | 1 + src/lib/ast_lowering/ast_lowering_context.rs | 1 + src/lib/codegen/codegen_context.rs | 5 +++++ src/lib/hir/tree.rs | 1 + src/lib/hir/visit.rs | 1 + src/lib/hir/visit_mut.rs | 1 + src/lib/infer/constraint.rs | 1 + src/lib/parser/mod.rs | 17 ++++++++++++++++- src/lib/parser/tests.rs | 9 +++++++++ src/lib/ty/primitive_type.rs | 7 +++++++ 11 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/lib/ast/tree.rs b/src/lib/ast/tree.rs index d9c1d1ef..056bbf77 100644 --- a/src/lib/ast/tree.rs +++ b/src/lib/ast/tree.rs @@ -829,6 +829,13 @@ impl Literal { } } + pub fn new_char(c: char, node_id: NodeId) -> Self { + Self { + kind: LiteralKind::Char(c), + node_id, + } + } + pub fn as_i64(&self) -> i64 { match self.kind { LiteralKind::Number(n) => n, @@ -844,6 +851,7 @@ pub enum LiteralKind { Float(f64), Array(Array), String(String), + Char(char), } #[derive(Debug, Clone)] diff --git a/src/lib/ast/visit.rs b/src/lib/ast/visit.rs index 2d5208be..9c0517e8 100644 --- a/src/lib/ast/visit.rs +++ b/src/lib/ast/visit.rs @@ -277,6 +277,7 @@ pub fn walk_literal<'a, V: Visitor<'a>>(visitor: &mut V, literal: &'a Literal) { LiteralKind::String(s) => visitor.visit_primitive(s), LiteralKind::Bool(b) => visitor.visit_primitive(b), LiteralKind::Array(arr) => visitor.visit_array(arr), + LiteralKind::Char(c) => visitor.visit_primitive(c), } } diff --git a/src/lib/ast_lowering/ast_lowering_context.rs b/src/lib/ast_lowering/ast_lowering_context.rs index 5b3caa09..8fa34b7a 100644 --- a/src/lib/ast_lowering/ast_lowering_context.rs +++ b/src/lib/ast_lowering/ast_lowering_context.rs @@ -450,6 +450,7 @@ impl AstLoweringContext { LiteralKind::String(s) => hir::LiteralKind::String(s.clone()), LiteralKind::Bool(b) => hir::LiteralKind::Bool(*b), LiteralKind::Array(arr) => hir::LiteralKind::Array(self.lower_array(arr)), + LiteralKind::Char(c) => hir::LiteralKind::Char(*c), }, } } diff --git a/src/lib/codegen/codegen_context.rs b/src/lib/codegen/codegen_context.rs index a9dce4cb..81522d64 100644 --- a/src/lib/codegen/codegen_context.rs +++ b/src/lib/codegen/codegen_context.rs @@ -809,6 +809,11 @@ impl<'a> CodegenContext<'a> { ptr.as_basic_value_enum() } + LiteralKind::Char(c) => { + let char_type = self.context.i8_type(); + + char_type.const_int(*c as u64, false).into() + } }) } diff --git a/src/lib/hir/tree.rs b/src/lib/hir/tree.rs index df2efb3c..95e86b2b 100644 --- a/src/lib/hir/tree.rs +++ b/src/lib/hir/tree.rs @@ -627,6 +627,7 @@ pub enum LiteralKind { String(String), Bool(bool), Array(Array), + Char(char), } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/lib/hir/visit.rs b/src/lib/hir/visit.rs index 3d8f49d9..febfcc6f 100644 --- a/src/lib/hir/visit.rs +++ b/src/lib/hir/visit.rs @@ -226,6 +226,7 @@ pub fn walk_literal<'a, V: Visitor<'a>>(visitor: &mut V, literal: &'a Literal) { LiteralKind::String(s) => visitor.visit_primitive(s), LiteralKind::Bool(b) => visitor.visit_primitive(b), LiteralKind::Array(arr) => visitor.visit_array(arr), + LiteralKind::Char(c) => visitor.visit_primitive(c), } } diff --git a/src/lib/hir/visit_mut.rs b/src/lib/hir/visit_mut.rs index cae78a52..1de968ea 100644 --- a/src/lib/hir/visit_mut.rs +++ b/src/lib/hir/visit_mut.rs @@ -236,6 +236,7 @@ pub fn walk_literal<'a, V: VisitorMut<'a>>(visitor: &mut V, literal: &'a mut Lit LiteralKind::String(s) => visitor.visit_primitive(s), LiteralKind::Bool(b) => visitor.visit_primitive(b), LiteralKind::Array(arr) => visitor.visit_array(arr), + LiteralKind::Char(c) => visitor.visit_primitive(c), } } diff --git a/src/lib/infer/constraint.rs b/src/lib/infer/constraint.rs index 50ae4ede..2545d552 100644 --- a/src/lib/infer/constraint.rs +++ b/src/lib/infer/constraint.rs @@ -695,6 +695,7 @@ impl<'a, 'ar> Visitor<'a> for ConstraintContext<'ar> { arr.values.len(), )) } + LiteralKind::Char(_c) => Type::Primitive(PrimitiveType::Char), }; self.envs.set_type(&lit.hir_id, &t); diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 537bb4fd..89efa4d6 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -6,7 +6,9 @@ use std::{ use nom::{ branch::alt, bytes::complete::{tag, take_while}, - character::complete::{alphanumeric0, char, line_ending, one_of, satisfy, space0, space1}, + character::complete::{ + alphanumeric0, anychar, char, line_ending, one_of, satisfy, space0, space1, + }, combinator::{eof, map, opt, peek, recognize}, error::{make_error, ErrorKind, FromExternalError, ParseError, VerboseError}, error_position, @@ -1019,6 +1021,7 @@ pub fn parse_literal(input: Parser) -> Res { parse_number, parse_array, parse_string, + parse_char, ))(input) } @@ -1100,6 +1103,18 @@ pub fn parse_number(input: Parser) -> Res { Ok((input, Literal::new_number(num, node_id))) } +pub fn parse_char(input: Parser) -> Res { + map( + tuple(( + parse_identity, + terminated(tag("'"), space0), + anychar, + tag("'"), + )), + |(node_id, _, s, _)| Literal::new_char(s, node_id), + )(input) +} + // Types pub fn parse_signature(input: Parser) -> Res { diff --git a/src/lib/parser/tests.rs b/src/lib/parser/tests.rs index d37096ad..bb314bfd 100644 --- a/src/lib/parser/tests.rs +++ b/src/lib/parser/tests.rs @@ -32,6 +32,15 @@ mod parse_literal { assert!(matches!(num_parsed.kind, LiteralKind::Float(f) if f == 42.42)); } + + #[test] + fn char() { + let input = Parser::new_extra("'a'", ParserCtx::new(PathBuf::new(), Config::default())); + + let (_rest, num_parsed) = parse_char(input).finish().unwrap(); + + assert!(matches!(num_parsed.kind, LiteralKind::Char(c) if c == 'a')); + } } #[cfg(test)] diff --git a/src/lib/ty/primitive_type.rs b/src/lib/ty/primitive_type.rs index c09bef96..56fefd51 100644 --- a/src/lib/ty/primitive_type.rs +++ b/src/lib/ty/primitive_type.rs @@ -11,6 +11,7 @@ pub enum PrimitiveType { Float64, String, Array(Box, usize), + Char, } impl PrimitiveType { @@ -33,6 +34,7 @@ impl PrimitiveType { Self::Float64 => "Float64".to_string(), Self::String => "String".to_string(), Self::Array(t, _size) => format!("[{}]", t.get_name()), + Self::Char => "Char".to_string(), } } @@ -46,6 +48,7 @@ impl PrimitiveType { "Int64" => Some(Self::Int64), "Float64" => Some(Self::Float64), "String" => Some(Self::String), + "Char" => Some(Self::Char), _ => None, } } @@ -82,6 +85,10 @@ impl PrimitiveType { matches!(self, PrimitiveType::Array(_, _)) } + pub fn is_char(&self) -> bool { + matches!(self, PrimitiveType::Char) + } + pub fn try_as_array(&self) -> Option<(Type, usize)> { if let PrimitiveType::Array(t, s) = self { Some((*t.clone(), *s)) From a680b4495de7262f3cd7d32344699e303eefe15f Mon Sep 17 00:00:00 2001 From: Champii Date: Mon, 13 Jun 2022 03:50:56 +0200 Subject: [PATCH 10/22] Allow for some escaped chars --- Cargo.lock | 11 ++------- Cargo.toml | 2 +- src/lib/codegen/codegen_context.rs | 1 + src/lib/parser/mod.rs | 39 ++++++++++++++++++++---------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c951765..9c301213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,13 +335,12 @@ dependencies = [ [[package]] name = "nom" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" dependencies = [ "memchr", "minimal-lexical", - "version_check", ] [[package]] @@ -652,12 +651,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "version_check" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" - [[package]] name = "walkdir" version = "2.3.2" diff --git a/Cargo.toml b/Cargo.toml index 64c3b914..fc2f8ae8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ bincode = "*" colored = "2.0.0" paste = "1.0.5" rustyline = "9.0.0" -nom = "7.0.0" +nom = "7.1.1" nom_locate = "4.0.0" itertools = "0.10.3" diff --git a/src/lib/codegen/codegen_context.rs b/src/lib/codegen/codegen_context.rs index 81522d64..ddcbb085 100644 --- a/src/lib/codegen/codegen_context.rs +++ b/src/lib/codegen/codegen_context.rs @@ -107,6 +107,7 @@ impl<'a> CodegenContext<'a> { Type::Primitive(PrimitiveType::Int64) => self.context.i64_type().into(), Type::Primitive(PrimitiveType::Float64) => self.context.f64_type().into(), Type::Primitive(PrimitiveType::Bool) => self.context.bool_type().into(), + Type::Primitive(PrimitiveType::Char) => self.context.i8_type().into(), Type::Primitive(PrimitiveType::String) => self .context .i8_type() diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 89efa4d6..2904bbb1 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -5,11 +5,11 @@ use std::{ use nom::{ branch::alt, - bytes::complete::{tag, take_while}, + bytes::complete::{escaped_transform, tag, take_while}, character::complete::{ - alphanumeric0, anychar, char, line_ending, one_of, satisfy, space0, space1, + alphanumeric0, char, line_ending, none_of, one_of, satisfy, space0, space1, }, - combinator::{eof, map, opt, peek, recognize}, + combinator::{eof, map, opt, peek, recognize, value}, error::{make_error, ErrorKind, FromExternalError, ParseError, VerboseError}, error_position, multi::{many0, many1, separated_list0, separated_list1}, @@ -1030,7 +1030,15 @@ pub fn parse_string(input: Parser) -> Res { tuple(( parse_identity, terminated(tag("\""), space0), - recognize(take_while(|c: char| c != '"')), + recognize(many0(escaped_transform( + none_of("\""), + '\\', + alt(( + value("\\", tag("\\")), + value("\"", tag("\"")), + value("\n", tag("\n")), + )), + ))), tag("\""), )), |(node_id, _, s, _)| Literal::new_string(String::from(*s.fragment()), node_id), @@ -1104,17 +1112,22 @@ pub fn parse_number(input: Parser) -> Res { } pub fn parse_char(input: Parser) -> Res { - map( - tuple(( - parse_identity, - terminated(tag("'"), space0), - anychar, - tag("'"), + let esc = escaped_transform( + none_of("\\\'"), + '\\', + alt(( + value("\\", tag("\\")), + value("\'", tag("\'")), + value("\n", tag("n")), )), - |(node_id, _, s, _)| Literal::new_char(s, node_id), - )(input) -} + ); + let res = delimited(tag("'"), esc, tag("'")); + + map(tuple((parse_identity, res)), |(node_id, s)| { + Literal::new_char(s.chars().nth(0).unwrap(), node_id) + })(input) +} // Types pub fn parse_signature(input: Parser) -> Res { From 02f18253761d7a1e560d76e18211919363d06ca2 Mon Sep 17 00:00:00 2001 From: Champii Date: Mon, 13 Jun 2022 04:01:54 +0200 Subject: [PATCH 11/22] Update std to include char --- src/lib/parser/mod.rs | 1 + src/lib/ty/type.rs | 1 + std/src/eq.rk | 7 +++++++ std/src/num.rk | 6 ++++++ std/src/print.rk | 3 +++ std/src/show.rk | 6 ++++++ 6 files changed, 24 insertions(+) diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 2904bbb1..a70671db 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -1166,6 +1166,7 @@ pub fn parse_type(input: Parser) -> Res { map(tag("Int64"), |_| PrimitiveType::Int64), map(tag("Float64"), |_| PrimitiveType::Float64), map(tag("String"), |_| PrimitiveType::String), + map(tag("Char"), |_| PrimitiveType::Char), )), |t| Type::from(t), ), diff --git a/src/lib/ty/type.rs b/src/lib/ty/type.rs index 301065ed..4b8df50f 100644 --- a/src/lib/ty/type.rs +++ b/src/lib/ty/type.rs @@ -150,6 +150,7 @@ impl Type { impl fmt::Debug for Type { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s = match self { + Self::Primitive(p) => format!("{:?}", p), Self::Func(f) => format!("{:?}", f), Self::Struct(s) => format!("{:?}", s), Self::Trait(t) => format!("Trait {:?}", t), diff --git a/std/src/eq.rk b/std/src/eq.rk index 76540e6b..ac77561a 100644 --- a/std/src/eq.rk +++ b/std/src/eq.rk @@ -32,6 +32,13 @@ impl Eq Bool <: i, j -> ~BEq i j >: i, j -> ~BEq i j +impl Eq Char + ==: e, f -> ~IEq e f + <=: e, f -> ~Ile e f + >=: e, f -> ~Ige e f + <: e, f -> ~Ilt e f + >: e, f -> ~Igt e f + use super::externs::strcmp impl Eq String diff --git a/std/src/num.rk b/std/src/num.rk index cd10f280..5036602b 100644 --- a/std/src/num.rk +++ b/std/src/num.rk @@ -21,6 +21,12 @@ impl Num Float64 *: c, d -> ~FMul c d /: c, d -> ~FDiv c d +impl Num Char + +: a, b -> ~IAdd a b + -: a, b -> ~ISub a b + *: a, b -> ~IMul a b + /: a, b -> ~IDiv a b + use super::externs::malloc use super::externs::strlen use super::externs::strcpy diff --git a/std/src/print.rk b/std/src/print.rk index 673f1230..75ff5de3 100644 --- a/std/src/print.rk +++ b/std/src/print.rk @@ -23,3 +23,6 @@ impl Print Float64 impl Print String @print: -> printl @ +impl Print Char + @print: -> printl @ + diff --git a/std/src/show.rk b/std/src/show.rk index 7c98de57..44c6a0d6 100644 --- a/std/src/show.rk +++ b/std/src/show.rk @@ -36,6 +36,12 @@ impl Show String strcpy s, @ s +impl Show Char + @show: -> + let s = malloc 2 + s[0] = @ + s + show_arr: a -> let s = malloc 100 strcpy s, "[" From 7d90422256dea885d284d0bf05b935d7a67c6f76 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 14 Jun 2022 12:21:00 +0200 Subject: [PATCH 12/22] Escaped strings are working --- Cargo.lock | 37 ++++++++++++++++ Cargo.toml | 1 + src/lib/codegen/codegen_context.rs | 1 + src/lib/infer/constraint.rs | 43 +++++++++++++++++++ src/lib/parser/mod.rs | 15 +++++-- .../testcases/basic/escaped_string/main.rk | 4 ++ .../basic/escaped_string/main.rk.out | 1 + .../basic/escaped_string/main.rk.stdout | 0 src/lib/testcases/basic/simple_char/main.rk | 5 +++ .../testcases/basic/simple_char/main.rk.out | 1 + .../basic/simple_char/main.rk.stdout | 0 src/lib/tests.rs | 8 ++++ src/lib/ty/func_type.rs | 2 +- src/lib/ty/type.rs | 4 +- 14 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 src/lib/testcases/basic/escaped_string/main.rk create mode 100644 src/lib/testcases/basic/escaped_string/main.rk.out create mode 100644 src/lib/testcases/basic/escaped_string/main.rk.stdout create mode 100644 src/lib/testcases/basic/simple_char/main.rk create mode 100644 src/lib/testcases/basic/simple_char/main.rk.out create mode 100644 src/lib/testcases/basic/simple_char/main.rk.stdout diff --git a/Cargo.lock b/Cargo.lock index 9c301213..f9151510 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -491,6 +491,7 @@ dependencies = [ "rustyline", "serde", "serde_derive", + "snailquote", "walkdir", ] @@ -574,6 +575,16 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +[[package]] +name = "snailquote" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec62a949bda7f15800481a711909f946e1204f2460f89210eaf7f57730f88f86" +dependencies = [ + "thiserror", + "unicode_categories", +] + [[package]] name = "str-buf" version = "1.0.5" @@ -615,6 +626,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thiserror" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ucd-trie" version = "0.1.3" @@ -639,6 +670,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "utf8parse" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index fc2f8ae8..d76bf2af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ rustyline = "9.0.0" nom = "7.1.1" nom_locate = "4.0.0" itertools = "0.10.3" +snailquote = "0.3.1" [build-dependencies] walkdir = "2" diff --git a/src/lib/codegen/codegen_context.rs b/src/lib/codegen/codegen_context.rs index ddcbb085..683765a2 100644 --- a/src/lib/codegen/codegen_context.rs +++ b/src/lib/codegen/codegen_context.rs @@ -695,6 +695,7 @@ impl<'a> CodegenContext<'a> { let const_0 = i64_type.const_zero(); + // FIXME: This segfaults if the operand is a String (#115) let ptr = unsafe { builder.build_gep(op, &[const_0, indice], "index") }; Ok(ptr.as_basic_value_enum()) diff --git a/src/lib/infer/constraint.rs b/src/lib/infer/constraint.rs index 2545d552..031217c6 100644 --- a/src/lib/infer/constraint.rs +++ b/src/lib/infer/constraint.rs @@ -512,6 +512,8 @@ impl<'a, 'ar> Visitor<'a> for ConstraintContext<'ar> { self.visit_expression(&assign.value); self.visit_assign_left_side(&assign.name); + // FIXME: This is problematic, the value's type should not dictate the type of the + // operand's index. This makes the string indexing think a character is an Int64. Spooky self.envs .set_type_eq(&assign.name.get_hir_id(), &assign.value.get_hir_id()); } @@ -634,6 +636,47 @@ impl<'a, 'ar> Visitor<'a> for ConstraintContext<'ar> { } } } + Type::Primitive(PrimitiveType::String) => { + self.envs + .set_type(&i.get_hir_id(), &Type::Primitive(PrimitiveType::Int8)); + + match self.envs.get_type(&i.value.get_hir_id()).unwrap().clone() { + Type::Primitive(PrimitiveType::Int64) => { + // if let ExpressionKind::Lit(literal) = &*i.value.kind { + // if literal.as_number() >= size as i64 { + // Deactivated for now + // self.envs.diagnostics.push_error( + // Diagnostic::new_out_of_bounds( + // self.envs + // .spans + // .get(&i.value.get_hir_id()) + // .unwrap() + // .clone(), + // i.value.as_literal().as_number() as u64, + // size as u64, + // ), + // ) + // } + // } + } + other => { + self.envs + .diagnostics + .push_error(Diagnostic::new_type_conflict( + self.envs + .spans + .get(&i.value.get_hir_id()) + .unwrap() + .clone() + .into(), + Type::Primitive(PrimitiveType::Int64), + other.clone(), + Type::Primitive(PrimitiveType::Int64), + other, + )) + } + } + } other => self .envs .diagnostics diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index a70671db..2174b7dc 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -17,6 +17,8 @@ use nom::{ Err, IResult, }; +use snailquote::unescape; + use nom_locate::{position, LocatedSpan}; use crate::{ @@ -1031,17 +1033,24 @@ pub fn parse_string(input: Parser) -> Res { parse_identity, terminated(tag("\""), space0), recognize(many0(escaped_transform( - none_of("\""), + none_of("\\\'\"\n\r"), '\\', alt(( value("\\", tag("\\")), + value("\'", tag("\'")), value("\"", tag("\"")), - value("\n", tag("\n")), + value("\n", tag("n")), + value("\r", tag("r")), )), ))), tag("\""), )), - |(node_id, _, s, _)| Literal::new_string(String::from(*s.fragment()), node_id), + |(node_id, _, s, _)| { + Literal::new_string( + String::from(unescape(&("\"".to_owned() + *s.fragment() + "\"")).unwrap()), + node_id, + ) + }, )(input) } diff --git a/src/lib/testcases/basic/escaped_string/main.rk b/src/lib/testcases/basic/escaped_string/main.rk new file mode 100644 index 00000000..5d9eefe7 --- /dev/null +++ b/src/lib/testcases/basic/escaped_string/main.rk @@ -0,0 +1,4 @@ +main: -> + let str = "Hell\no, W\\or\"ld!n" + 42 + diff --git a/src/lib/testcases/basic/escaped_string/main.rk.out b/src/lib/testcases/basic/escaped_string/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/escaped_string/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/escaped_string/main.rk.stdout b/src/lib/testcases/basic/escaped_string/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/testcases/basic/simple_char/main.rk b/src/lib/testcases/basic/simple_char/main.rk new file mode 100644 index 00000000..63441da5 --- /dev/null +++ b/src/lib/testcases/basic/simple_char/main.rk @@ -0,0 +1,5 @@ +main: -> + let a = 'a' + let star = '*' + let bn = '\n' + star diff --git a/src/lib/testcases/basic/simple_char/main.rk.out b/src/lib/testcases/basic/simple_char/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/simple_char/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/simple_char/main.rk.stdout b/src/lib/testcases/basic/simple_char/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/tests.rs b/src/lib/tests.rs index ff73cf91..d30ba202 100644 --- a/src/lib/tests.rs +++ b/src/lib/tests.rs @@ -66,6 +66,10 @@ fn testcases_basic_1_arg_fn_main() { run("testcases/basic/1_arg_fn/main.rk", include_str!("testcases/basic/1_arg_fn/main.rk"), include_str!("testcases/basic/1_arg_fn/main.rk.out"), include_str!("testcases/basic/1_arg_fn/main.rk.stdout")); } #[test] +fn testcases_basic_simple_char_main() { + run("testcases/basic/simple_char/main.rk", include_str!("testcases/basic/simple_char/main.rk"), include_str!("testcases/basic/simple_char/main.rk.out"), include_str!("testcases/basic/simple_char/main.rk.stdout")); +} +#[test] fn testcases_basic_indice_assign_main() { run("testcases/basic/indice_assign/main.rk", include_str!("testcases/basic/indice_assign/main.rk"), include_str!("testcases/basic/indice_assign/main.rk.out"), include_str!("testcases/basic/indice_assign/main.rk.stdout")); } @@ -90,6 +94,10 @@ fn testcases_basic_nested_struct_dect_multiline_main() { run("testcases/basic/nested_struct_dect_multiline/main.rk", include_str!("testcases/basic/nested_struct_dect_multiline/main.rk"), include_str!("testcases/basic/nested_struct_dect_multiline/main.rk.out"), include_str!("testcases/basic/nested_struct_dect_multiline/main.rk.stdout")); } #[test] +fn testcases_basic_escaped_string_main() { + run("testcases/basic/escaped_string/main.rk", include_str!("testcases/basic/escaped_string/main.rk"), include_str!("testcases/basic/escaped_string/main.rk.out"), include_str!("testcases/basic/escaped_string/main.rk.stdout")); +} +#[test] fn testcases_basic_let_main() { run("testcases/basic/let/main.rk", include_str!("testcases/basic/let/main.rk"), include_str!("testcases/basic/let/main.rk.out"), include_str!("testcases/basic/let/main.rk.stdout")); } diff --git a/src/lib/ty/func_type.rs b/src/lib/ty/func_type.rs index 6bdd662c..e42a10f3 100644 --- a/src/lib/ty/func_type.rs +++ b/src/lib/ty/func_type.rs @@ -39,7 +39,7 @@ impl fmt::Debug for FuncType { .map(|arg| format!("{:?}", arg)) .chain(vec![format!("{:?}", self.ret)].into_iter()) .collect::>() - .join(&" -> ".magenta().to_string()); + .join(&" => ".magenta().to_string()); write!(f, "{}{}{}", "(".green(), s, ")".green(),) } diff --git a/src/lib/ty/type.rs b/src/lib/ty/type.rs index 4b8df50f..b7ec72d9 100644 --- a/src/lib/ty/type.rs +++ b/src/lib/ty/type.rs @@ -1,7 +1,5 @@ use std::fmt; -use colored::*; - use crate::{ast, hir}; use super::{FuncType, PrimitiveType, StructType}; @@ -156,7 +154,7 @@ impl fmt::Debug for Type { Self::Trait(t) => format!("Trait {:?}", t), Self::ForAll(t) => format!("forall. {:?}", t), Self::Undefined(t) => format!("UNDEFINED {:?}", t), - _ => self.get_name().cyan().to_string(), + // _ => self.get_name().cyan().to_string(), }; write!(f, "{}", s) From 3d94868c35583862a87d3f7ea7c99c6f5a310542 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 14 Jun 2022 19:46:01 +0200 Subject: [PATCH 13/22] Readme clarity --- README.md | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 097df910..fccb7c33 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,9 @@ No to be taken seriously (yet) ## Install -Warning: This project has only been tested on Linux x86_64. - -How to install and run the compiler: - ### Using Released Binary -You will need `clang` somewhere in your $PATH - -Linux x86_64 only - -[Rock v0.4.1](https://github.com/Champii/Rock/releases/download/v0.4.1/rock) (Tested on arch, btw) +[Rock v0.4.1](https://github.com/Champii/Rock/releases/download/v0.4.1/rock) ``` sh wget https://github.com/Champii/Rock/releases/download/v0.4.1/rock @@ -63,13 +55,9 @@ chmod +x rock ./rock -V ``` -### From source - -You will need `llvm-12.0.1` and `clang-12.0.1` somewhere in your $PATH - -Rock has been tested against Rust stable v1.60.0 and nightly +You will need `clang` somewhere in your $PATH -[Adding Rust Nightly](https://github.com/Champii/Rock/wiki/Adding-Rust-Nightly) +### From source #### With Cargo from Git @@ -83,10 +71,18 @@ rock -V ```sh git clone https://github.com/Champii/Rock.git rock cd rock -cargo run -- -- -V +cargo run --release -- -V ``` -Note: If you clone and build manually, make sure to add `/[...]/rock/target//` to you `$PATH` so you can run it anywhere on your system. +Note: If you clone and build manually, make sure to add `rock/target/release/` to you `$PATH` so you can run it anywhere on your system. + +--- + +You will also need `llvm-12.0.1` and `clang-12.0.1` somewhere in your $PATH + +Rock has been tested against Rust stable v1.60.0 and nightly + +[Adding Rust Nightly](https://github.com/Champii/Rock/wiki/Adding-Rust-Nightly) ## Quickstart From 10f659c45ca51fa625c5e2a6aeef5d3b752c810b Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 14 Jun 2022 19:46:01 +0200 Subject: [PATCH 14/22] Readme clarity --- README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 097df910..bd305983 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,9 @@ No to be taken seriously (yet) ## Install -Warning: This project has only been tested on Linux x86_64. - -How to install and run the compiler: - ### Using Released Binary -You will need `clang` somewhere in your $PATH - -Linux x86_64 only - -[Rock v0.4.1](https://github.com/Champii/Rock/releases/download/v0.4.1/rock) (Tested on arch, btw) +[Rock v0.4.1](https://github.com/Champii/Rock/releases/download/v0.4.1/rock) ``` sh wget https://github.com/Champii/Rock/releases/download/v0.4.1/rock @@ -63,13 +55,9 @@ chmod +x rock ./rock -V ``` -### From source - -You will need `llvm-12.0.1` and `clang-12.0.1` somewhere in your $PATH - -Rock has been tested against Rust stable v1.60.0 and nightly +You will need `clang` somewhere in your $PATH -[Adding Rust Nightly](https://github.com/Champii/Rock/wiki/Adding-Rust-Nightly) +### From source #### With Cargo from Git @@ -83,10 +71,18 @@ rock -V ```sh git clone https://github.com/Champii/Rock.git rock cd rock -cargo run -- -- -V +cargo run --release -- -V ``` -Note: If you clone and build manually, make sure to add `/[...]/rock/target//` to you `$PATH` so you can run it anywhere on your system. +Note: If you clone and build manually, make sure to add `rock/target/release/` to you `$PATH` so you can run it anywhere on your system. + +You will also need `llvm-12.0.1` and `clang-12.0.1` somewhere in your $PATH + +Rock has been tested against Rust stable v1.60.0 and nightly + +[Adding Rust Nightly](https://github.com/Champii/Rock/wiki/Adding-Rust-Nightly) + +--- ## Quickstart @@ -126,6 +122,8 @@ Take a look at `rock --help` for a quick tour of its flags and arguments Note that you currently MUST be at the project root to run the compiler. (i.e. inside the `./factorial/` folder) +--- + ## Showcases ### Polymorphic function @@ -301,6 +299,8 @@ Note that we could have skiped the if we wrote `main: -> foo::bar 1 .print!` +--- + ## Development notes This project, its syntax and its APIs are subject to change at any moment. From ea4acb4d6273c50411f9ca4251968144e09bc060 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 14 Jun 2022 19:50:32 +0200 Subject: [PATCH 15/22] Readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f2c3b75b..8942f07a 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ You will need `clang` somewhere in your $PATH ### From source +You will need `llvm-12.0.1` and `clang-12.0.1` somewhere in your $PATH + #### With Cargo from Git ```sh @@ -76,10 +78,6 @@ cargo run --release -- -V Note: If you clone and build manually, make sure to add `rock/target/release/` to you `$PATH` so you can run it anywhere on your system. ---- - -You will also need `llvm-12.0.1` and `clang-12.0.1` somewhere in your $PATH - Rock has been tested against Rust stable v1.60.0 and nightly [Adding Rust Nightly](https://github.com/Champii/Rock/wiki/Adding-Rust-Nightly) From 283c8c8b6e2bc880327557b811c19a60481926f5 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 14 Jun 2022 19:53:02 +0200 Subject: [PATCH 16/22] Fixed dangling println --- README.md | 1 - src/lib/diagnostics/diagnostic.rs | 1 - src/lib/diagnostics/diagnostics_list.rs | 1 - src/lib/parser/mod.rs | 1 - 4 files changed, 4 deletions(-) diff --git a/README.md b/README.md index 8942f07a..755b8ad1 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ No to be taken seriously (yet) - [Install](#install) - [Using Released Binary](#using-released-binary) - [From source](#from-source) - - [Adding Rust Nightly](#adding-rust-nightly) - [With Cargo from Git](#with-cargo-from-git) - [Manual Clone and Build from Git](#manual-clone-and-build-from-git) - [Quickstart](#quickstart) diff --git a/src/lib/diagnostics/diagnostic.rs b/src/lib/diagnostics/diagnostic.rs index c952b8d2..29612527 100644 --- a/src/lib/diagnostics/diagnostic.rs +++ b/src/lib/diagnostics/diagnostic.rs @@ -298,7 +298,6 @@ impl<'a> From> for Diagnostic { impl<'a> From>> for Diagnostic { fn from(err: VerboseError>) -> Self { - println!("VERBOSE {:#?}", err); let (input, _kind) = err.errors.iter().next().unwrap().clone(); let span2 = Span2::from(input); diff --git a/src/lib/diagnostics/diagnostics_list.rs b/src/lib/diagnostics/diagnostics_list.rs index e4b8e706..539ac4d5 100644 --- a/src/lib/diagnostics/diagnostics_list.rs +++ b/src/lib/diagnostics/diagnostics_list.rs @@ -43,7 +43,6 @@ impl Diagnostics { } pub fn print(&self, files: &HashMap) { - println!("WESH {:#?}", self.list); for (i, diag) in self.list.iter().enumerate() { let input = match files.get(&diag.span.file_path) { Some(input) => input, diff --git a/src/lib/parser/mod.rs b/src/lib/parser/mod.rs index 9d07c24d..55c35f72 100644 --- a/src/lib/parser/mod.rs +++ b/src/lib/parser/mod.rs @@ -1279,7 +1279,6 @@ pub fn parse(parsing_ctx: &mut ParsingCtx) -> Result { Ok(ast) } Err(e) => { - println!("ERROOOOOR: {:#?}", e); parsing_ctx .files .extend(e.errors.get(0).unwrap().clone().0.extra.files()); From 6cd2866a1ce87cbd58ca4560cd201542f9e9a630 Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 15 Jun 2022 01:31:40 +0200 Subject: [PATCH 17/22] Indexable strings --- Cargo.lock | 240 ++++++++++++------ Cargo.toml | 3 +- src/lib/codegen/codegen_context.rs | 22 +- src/lib/infer/constraint.rs | 2 +- src/lib/testcases/basic/string_index/main.rk | 3 + .../testcases/basic/string_index/main.rk.out | 1 + .../basic/string_index/main.rk.stdout | 0 src/lib/tests.rs | 4 + 8 files changed, 191 insertions(+), 84 deletions(-) create mode 100644 src/lib/testcases/basic/string_index/main.rk create mode 100644 src/lib/testcases/basic/string_index/main.rk.out create mode 100644 src/lib/testcases/basic/string_index/main.rk.stdout diff --git a/Cargo.lock b/Cargo.lock index f9151510..98f0ab53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "ansi_term" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ "winapi", ] @@ -33,9 +33,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bincode" @@ -54,15 +54,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bytecount" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72feb31ffc86498dacdbd0fcebb56138e7177a8cc5cea4516031d15ae85a742e" +checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" [[package]] name = "cc" -version = "1.0.70" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" [[package]] name = "cfg-if" @@ -72,9 +72,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", @@ -87,9 +87,9 @@ dependencies = [ [[package]] name = "clipboard-win" -version = "4.2.1" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4ea1881992efc993e4dc50a324cdbd03216e41bdc8385720ff47efc9bd2ca8" +checksum = "2f3e1238132dc01f081e1cbb9dace14e5ef4c3a51ee244bd982275fb514605db" dependencies = [ "error-code", "str-buf", @@ -153,11 +153,32 @@ dependencies = [ "termcolor", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "error-code" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5115567ac25674e0043e472be13d14e537f37ea8aa4bdc4aef0c89add1db1ff" +checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" dependencies = [ "libc", "str-buf", @@ -165,20 +186,20 @@ dependencies = [ [[package]] name = "fd-lock" -version = "3.0.0" +version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8806dd91a06a7a403a8e596f9bfbfb34e469efbc363fc9c9713e79e26472e36" +checksum = "46e245f4c8ec30c6415c56cb132c07e69e74f1942f6b4a4061da748b49f486ca" dependencies = [ "cfg-if", - "libc", - "winapi", + "rustix", + "windows-sys", ] [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", "libc", @@ -205,9 +226,9 @@ dependencies = [ [[package]] name = "inkwell" -version = "0.1.0-beta.3" +version = "0.1.0-beta.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3b605692df6dfbbaf596f7f15b7e3a629a32bd32e5dc28400fcb8bd07e6ad8" +checksum = "2223d0eba0ae6d40a3e4680c6a3209143471e1f38b41746ea309aa36dde9f90b" dependencies = [ "either", "inkwell_internals", @@ -220,9 +241,9 @@ dependencies = [ [[package]] name = "inkwell_internals" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185190cd08999fdedf30920ba83ab9c05c786c27b657865422caf51a11e31a8a" +checksum = "3c7090af3d300424caa81976b8c97bca41cd70e861272c072e188ae082fb49f9" dependencies = [ "proc-macro2", "quote", @@ -231,13 +252,19 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9448015e586b611e5d322f6703812bbca2f1e709d5773ecd38ddb4e3bb649504" + [[package]] name = "itertools" version = "0.10.3" @@ -255,15 +282,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.103" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "linux-raw-sys" +version = "0.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "llvm-sys" -version = "120.2.1" +version = "130.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a810627ac62b396f5fd2214ba9bbd8748d4d6efdc4d2c1c1303ea7a75763ce" +checksum = "bdb6ea20e8a348f6db0b43a7f009fa7d981d22edf4cbe2e0c7b2247dbb25be61" dependencies = [ "cc", "lazy_static", @@ -274,33 +307,34 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ + "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ "autocfg", ] @@ -356,9 +390,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" [[package]] name = "parking_lot" @@ -387,9 +421,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.5" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" +checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" [[package]] name = "pest" @@ -402,11 +436,11 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -417,9 +451,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.9" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ "proc-macro2", ] @@ -436,21 +470,22 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags", ] [[package]] name = "redox_users" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom", "redox_syscall", + "thiserror", ] [[package]] @@ -495,6 +530,20 @@ dependencies = [ "walkdir", ] +[[package]] +name = "rustix" +version = "0.34.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2079c267b8394eb529872c3cf92e181c378b41fea36e68130357b52493701d2e" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "winapi", +] + [[package]] name = "rustyline" version = "9.1.2" @@ -554,15 +603,15 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -571,9 +620,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "snailquote" @@ -587,9 +636,9 @@ dependencies = [ [[package]] name = "str-buf" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a" +checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" [[package]] name = "strsim" @@ -599,20 +648,20 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.78" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4eac2e6c19f5c3abc0c229bea31ff0b9b091c7b14990e8924b92902a303a0c0" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] @@ -652,11 +701,17 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +[[package]] +name = "unicode-ident" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" + [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-width" @@ -664,12 +719,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - [[package]] name = "unicode_categories" version = "0.1.1" @@ -701,9 +750,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" @@ -735,3 +784,46 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "030b7ff91626e57a05ca64a07c481973cbb2db774e4852c9c7ca342408c6a99a" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29277a4435d642f775f63c7d1faeb927adba532886ce0287bd985bffb16b6bca" + +[[package]] +name = "windows_i686_gnu" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1145e1989da93956c68d1864f32fb97c8f561a8f89a5125f6a2b7ea75524e4b8" + +[[package]] +name = "windows_i686_msvc" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a09e3a0d4753b73019db171c1339cd4362c8c44baf1bcea336235e955954a6" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca64fcb0220d58db4c119e050e7af03c69e6f4f415ef69ec1773d9aab422d5a" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08cabc9f0066848fef4bc6a1c1668e6efce38b661d2aeec75d18d8617eebb5f1" diff --git a/Cargo.toml b/Cargo.toml index d76bf2af..7730dc36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,7 @@ regex = "1.5.6" env_logger = "0.5.12" log = "0.4" bitflags = "1.2.1" -# inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm11-0"] } -inkwell = { version = "0.1.0-beta.3", features = ["llvm12-0"] } +inkwell = { version = "0.1.0-beta.4", features = ["llvm13-0"] } either = "1.5" serde = "*" serde_derive = '*' diff --git a/src/lib/codegen/codegen_context.rs b/src/lib/codegen/codegen_context.rs index 683765a2..a94e22b8 100644 --- a/src/lib/codegen/codegen_context.rs +++ b/src/lib/codegen/codegen_context.rs @@ -132,7 +132,7 @@ impl<'a> CodegenContext<'a> { let mut args_ret = vec![]; for arg in args { - args_ret.push(arg?); + args_ret.push(arg?.into()); } let args = args_ret; @@ -186,7 +186,7 @@ impl<'a> CodegenContext<'a> { let mut args = vec![]; for arg in &p.signature.arguments { - args.push(self.lower_type(arg, builder)?); + args.push(self.lower_type(arg, builder)?.into()); } let fn_type = if let Type::Primitive(PrimitiveType::Void) = *ret_t { @@ -242,7 +242,7 @@ impl<'a> CodegenContext<'a> { let mut args_ret = vec![]; for arg in args { - args_ret.push(arg?); + args_ret.push(arg?.into()); } let args = args_ret; @@ -664,7 +664,7 @@ impl<'a> CodegenContext<'a> { let mut arguments = vec![]; for arg in &fc.args { - arguments.push(self.lower_expression(arg, builder)?); + arguments.push(self.lower_expression(arg, builder)?.into()); } Ok(builder @@ -687,7 +687,7 @@ impl<'a> CodegenContext<'a> { .lower_expression(&indice.op, builder)? .into_pointer_value(); - let indice = self + let idx = self .lower_expression(&indice.value, builder)? .into_int_value(); @@ -695,8 +695,16 @@ impl<'a> CodegenContext<'a> { let const_0 = i64_type.const_zero(); - // FIXME: This segfaults if the operand is a String (#115) - let ptr = unsafe { builder.build_gep(op, &[const_0, indice], "index") }; + let indexes = match self.hir.node_types.get(&indice.op.get_hir_id()) { + Some(t) => match t { + Type::Primitive(PrimitiveType::Array(_, _)) => [const_0, idx].to_vec(), + Type::Primitive(PrimitiveType::String) => [idx].to_vec(), + _ => panic!("indice on non-array"), + }, + None => panic!("indice on non-type"), + }; + + let ptr = unsafe { builder.build_gep(op, &indexes, "index") }; Ok(ptr.as_basic_value_enum()) } diff --git a/src/lib/infer/constraint.rs b/src/lib/infer/constraint.rs index 031217c6..f7acfa8a 100644 --- a/src/lib/infer/constraint.rs +++ b/src/lib/infer/constraint.rs @@ -638,7 +638,7 @@ impl<'a, 'ar> Visitor<'a> for ConstraintContext<'ar> { } Type::Primitive(PrimitiveType::String) => { self.envs - .set_type(&i.get_hir_id(), &Type::Primitive(PrimitiveType::Int8)); + .set_type(&i.get_hir_id(), &Type::Primitive(PrimitiveType::Char)); match self.envs.get_type(&i.value.get_hir_id()).unwrap().clone() { Type::Primitive(PrimitiveType::Int64) => { diff --git a/src/lib/testcases/basic/string_index/main.rk b/src/lib/testcases/basic/string_index/main.rk new file mode 100644 index 00000000..b4f0a41f --- /dev/null +++ b/src/lib/testcases/basic/string_index/main.rk @@ -0,0 +1,3 @@ +f: -> "hell* world" +main: -> f![4] + diff --git a/src/lib/testcases/basic/string_index/main.rk.out b/src/lib/testcases/basic/string_index/main.rk.out new file mode 100644 index 00000000..f70d7bba --- /dev/null +++ b/src/lib/testcases/basic/string_index/main.rk.out @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/src/lib/testcases/basic/string_index/main.rk.stdout b/src/lib/testcases/basic/string_index/main.rk.stdout new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/tests.rs b/src/lib/tests.rs index d30ba202..2ab4efd5 100644 --- a/src/lib/tests.rs +++ b/src/lib/tests.rs @@ -234,6 +234,10 @@ fn testcases_basic_no_newline_end_main() { run("testcases/basic/no_newline_end/main.rk", include_str!("testcases/basic/no_newline_end/main.rk"), include_str!("testcases/basic/no_newline_end/main.rk.out"), include_str!("testcases/basic/no_newline_end/main.rk.stdout")); } #[test] +fn testcases_basic_string_index_main() { + run("testcases/basic/string_index/main.rk", include_str!("testcases/basic/string_index/main.rk"), include_str!("testcases/basic/string_index/main.rk.out"), include_str!("testcases/basic/string_index/main.rk.stdout")); +} +#[test] fn testcases_trait_multi_resolution_main() { run("testcases/trait/multi_resolution/main.rk", include_str!("testcases/trait/multi_resolution/main.rk"), include_str!("testcases/trait/multi_resolution/main.rk.out"), include_str!("testcases/trait/multi_resolution/main.rk.stdout")); } From 6e25c0903e7c227706a97d3db7ca96339cf498a7 Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 15 Jun 2022 01:37:04 +0200 Subject: [PATCH 18/22] Trying to upgrade to llvm13 on the github test pipeline --- .github/workflows/rust.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d2064d36..5660c165 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,13 +12,13 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: arch-latest steps: - name: Apt Update run: | - sudo apt update - sudo apt install llvm clang + sudo pacman -Sy + sudo pacman -S llvm13 clang - name: Rust Cache uses: Swatinem/rust-cache@v1.3.0 From b7883cab493f9a725c7361d895bf9155b1734ee1 Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 15 Jun 2022 01:48:26 +0200 Subject: [PATCH 19/22] Trying to make the github pipeline work --- .github/workflows/rust.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5660c165..5ec0a86a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,13 +12,13 @@ env: jobs: build: - runs-on: arch-latest + runs-on: ubuntu-latest steps: - name: Apt Update run: | - sudo pacman -Sy - sudo pacman -S llvm13 clang + sudo apt update + sudo apt install llvm-13 clang - name: Rust Cache uses: Swatinem/rust-cache@v1.3.0 From e12d18a908315399a29526a5f990880e873d4b03 Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 15 Jun 2022 01:52:59 +0200 Subject: [PATCH 20/22] Github workflow --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5ec0a86a..8c626e39 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,8 +11,8 @@ env: jobs: build: - - runs-on: ubuntu-latest + container: ubuntu:21.10 + # runs-on: ubuntu-latest steps: - name: Apt Update From da672be5116bcfbf679a9e9a13254066e2471145 Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 15 Jun 2022 01:52:59 +0200 Subject: [PATCH 21/22] Github workflow --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5ec0a86a..fce2af0d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,8 +11,8 @@ env: jobs: build: - - runs-on: ubuntu-latest + runs-on: ubuntu:21.10 + # runs-on: ubuntu-latest steps: - name: Apt Update From 7a8854d382cd7c5809e6d42010529aeaedf2a167 Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 15 Jun 2022 01:56:54 +0200 Subject: [PATCH 22/22] Github workflow --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 99b0d686..a77180c6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ env: jobs: build: - runs-on: ubuntu:21.10 + runs-on: ubuntu-22.04 steps: - name: Apt Update