diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c2ed3a1..150a4ef 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,18 +17,12 @@ jobs: steps: - name: Set up rust uses: actions/checkout@v3 - - name: Install latest nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - components: rustfmt, clippy - name: Install cargo-audit run: cargo install cargo-audit - name: Build - run: cargo +nightly build --verbose + run: cargo build --verbose - name: Unit Tests - run: cargo +nightly test --verbose --all + run: cargo test --verbose --all - name: Clippy run: cargo clippy --verbose -- -D warnings - name: Audit diff --git a/bytecode/src/lib.rs b/bytecode/src/lib.rs index 98bfce6..bb224d0 100644 --- a/bytecode/src/lib.rs +++ b/bytecode/src/lib.rs @@ -1,6 +1,5 @@ //! This is the API for all-things-bytecode. -#![feature(box_patterns)] #![allow(dead_code)] pub(crate) mod context; diff --git a/compiler/src/ast.rs b/compiler/src/ast.rs index 9a89194..c5f7bcf 100644 --- a/compiler/src/ast.rs +++ b/compiler/src/ast.rs @@ -209,9 +209,9 @@ impl<'a> Dependency<'a> { let other_ty: &TypeLayout = other.ident.ty()?.as_ref(); let self_ty: &TypeLayout = self.ident.ty()?.as_ref(); - if let TypeLayout::CallbackVariable(box ptr_ty) = other_ty { + if let TypeLayout::CallbackVariable(ptr_ty) = other_ty { if other.cycles_needed > 0 { - return Ok(self_ty == ptr_ty) + return Ok(self_ty == ptr_ty.as_ref()) } } diff --git a/compiler/src/ast/assignment_no_type.rs b/compiler/src/ast/assignment_no_type.rs index de7a1ad..20bcedd 100644 --- a/compiler/src/ast/assignment_no_type.rs +++ b/compiler/src/ast/assignment_no_type.rs @@ -1,10 +1,8 @@ -use std::borrow::Cow; - use anyhow::Result; use crate::parser::{Node, Parser}; -use super::{map_err_messages, r#type::IntoType, Assignment, Value}; +use super::{map_err_messages, Assignment}; impl Parser { pub fn assignment_no_type(input: Node, is_const: bool) -> Result<(Assignment, bool)> { @@ -16,7 +14,7 @@ impl Parser { let mut ident = Self::ident(ident)?; let did_exist_before = input.user_data().has_name_been_mapped_local(ident.name()); - + if is_const { ident.mark_const(); } @@ -25,37 +23,8 @@ impl Parser { let user_data = input.user_data(); - let maybe_error: Result<()> = try { - match value { - Value::Function(ref f) => { - ident.link_force_no_inherit(user_data, Cow::Owned(f.for_type()?))?; - } - Value::Ident(..) => { - ident.link_from_pointed_type_with_lookup(user_data)?; - } - Value::Number(ref number) => { - let ty = number.for_type()?; - ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; - } - Value::String(ref string) => { - let ty = string.for_type()?; - ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; - } - Value::MathExpr(ref math_expr) => { - let ty = math_expr.for_type()?; - ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; - } - Value::Callable(ref callback) => { - let ty = callback.for_type()?; - ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; - } - Value::Boolean(ref boolean) => { - let ty = boolean.for_type()?; - ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; - } - } - }; - + let maybe_error = value.associate_with_ident(&mut ident, user_data); + map_err_messages( maybe_error, input.as_span(), diff --git a/compiler/src/ast/callable.rs b/compiler/src/ast/callable.rs index 8aa9e8d..63cdae5 100644 --- a/compiler/src/ast/callable.rs +++ b/compiler/src/ast/callable.rs @@ -23,7 +23,7 @@ impl IntoType for Callable { let ident = self.ident.ty()?; let ident = ident.get_type_recursively(); - let (box ScopeReturnStatus::Should(ref return_type) | box ScopeReturnStatus::Did(ref return_type)) = ident.is_function().context("not a function")?.return_type else { + let (ScopeReturnStatus::Should(ref return_type) | ScopeReturnStatus::Did(ref return_type)) = ident.is_function().context("not a function")?.return_type.as_ref() else { bail!("function returns void") }; diff --git a/compiler/src/ast/function.rs b/compiler/src/ast/function.rs index 56ee7aa..1edb2db 100644 --- a/compiler/src/ast/function.rs +++ b/compiler/src/ast/function.rs @@ -66,9 +66,9 @@ impl FunctionType { impl Display for FunctionType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let return_type: Cow<'static, str> = if let box ScopeReturnStatus::Should(return_type) - | box ScopeReturnStatus::Did(return_type) = - &self.return_type + let return_type: Cow<'static, str> = if let ScopeReturnStatus::Should(return_type) + | ScopeReturnStatus::Did(return_type) = + &self.return_type.as_ref() { let actual_type = match return_type.as_ref() { TypeLayout::Function(..) => { @@ -154,10 +154,9 @@ impl Function { arguments.push(format!("{x}#{id}")); - dependencies - .iter() - .map(|ident| ident.name().clone()) - .collect_into(&mut arguments); + for dependency in dependencies { + arguments.push(dependency.name().clone()); + } let arguments = arguments.into_boxed_slice(); diff --git a/compiler/src/ast/math_expr.rs b/compiler/src/ast/math_expr.rs index f5ef822..735c2b2 100644 --- a/compiler/src/ast/math_expr.rs +++ b/compiler/src/ast/math_expr.rs @@ -188,7 +188,7 @@ fn compile_depth( match expr { Expr::Value(val) => val.compile(function_buffer), Expr::UnaryMinus(expr) => { - if let box Expr::Value(value) = expr { + if let Expr::Value(value) = expr.as_ref() { match value { Value::Ident(ident) => { let x = ident.ty().context("no type data")?; diff --git a/compiler/src/ast/value.rs b/compiler/src/ast/value.rs index c9738f4..65b4e10 100644 --- a/compiler/src/ast/value.rs +++ b/compiler/src/ast/value.rs @@ -1,10 +1,12 @@ +use std::{borrow::Cow, ops::Deref}; + use anyhow::Result; -use crate::parser::{Node, Parser, Rule}; +use crate::parser::{AssocFileData, Node, Parser, Rule}; use super::{ - math_expr::Expr, r#type::IntoType, string::AstString, Compile, CompiledItem, Dependencies, - Dependency, Function, Ident, Number, TypeLayout, Callable, + math_expr::Expr, r#type::IntoType, string::AstString, Callable, Compile, CompiledItem, + Dependencies, Dependency, Function, Ident, Number, TypeLayout, }; #[derive(Debug)] @@ -15,12 +17,54 @@ pub(crate) enum Value { String(AstString), MathExpr(Box), Callable(Callable), - Boolean(bool) + Boolean(bool), } impl Value { pub fn is_callable(&self) -> bool { - matches!(self, Value::Callable(..) | Value::MathExpr(box Expr::Value(Value::Callable(..)))) + match self { + Value::Callable(..) => true, + Value::MathExpr(maybe_value) + if matches!(maybe_value.deref(), Expr::Value(Value::Callable(..))) => + { + true + } + _ => false, + } + } + + pub fn associate_with_ident(&self, ident: &mut Ident, user_data: &AssocFileData) -> Result<()> { + match self { + Self::Function(ref f) => { + let ty = f.for_type()?; + ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; + } + Self::Ident(..) => { + ident.link_from_pointed_type_with_lookup(user_data)?; + } + Self::Number(ref number) => { + let ty = number.for_type()?; + ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; + } + Self::String(ref string) => { + let ty = string.for_type()?; + ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; + } + Self::MathExpr(ref math_expr) => { + let ty = math_expr.for_type()?; + ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; + } + Self::Callable(ref callback) => { + let ty = callback.for_type()?; + ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; + } + Self::Boolean(ref boolean) => { + let ty = boolean.for_type()?; + ident.link_force_no_inherit(user_data, Cow::Owned(ty))?; + } + } + + Ok(()) } } diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index bc76cc6..e9294c2 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -1,8 +1,3 @@ -#![feature(box_patterns)] -#![feature(iter_intersperse)] -#![feature(iter_collect_into)] -#![feature(try_blocks)] - /// for #[derive()] macro in `parser.rs` extern crate alloc; diff --git a/src/main.rs b/src/main.rs index 3275a62..52a170a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![feature(box_patterns)] - mod cli; use anyhow::{bail, Context, Result};