1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

Also substitute type

This commit is contained in:
azur 2023-07-02 16:35:46 +07:00
parent 3a837e30be
commit 5dd41a62a1
7 changed files with 25 additions and 365 deletions

341
Cargo.lock generated
View file

@ -62,18 +62,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "anyhow"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "arbitrary"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e"
[[package]]
name = "ariadne"
version = "0.2.0"
@ -84,12 +72,6 @@ dependencies = [
"yansi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bin"
version = "0.1.0"
@ -109,12 +91,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bumpalo"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
name = "cc"
version = "1.0.79"
@ -133,7 +109,7 @@ version = "1.0.0-alpha.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "379cdc19530b72a1e76d94a350676eaea1455375533eb38f18dfa712f9996902"
dependencies = [
"hashbrown 0.13.2",
"hashbrown",
"stacker",
]
@ -190,144 +166,10 @@ name = "com"
version = "0.1.0"
dependencies = [
"chumsky",
"cranelift",
"cranelift-jit",
"cranelift-module",
"cranelift-native",
"syntax",
"typing",
]
[[package]]
name = "cranelift"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "128089b15e74e782e4e1a51c4b5b3bd4fbc35755777988aff24300dfa120f1c9"
dependencies = [
"cranelift-codegen",
"cranelift-frontend",
]
[[package]]
name = "cranelift-bforest"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c064a534a914eb6709d198525321a386dad50627aecfaf64053f369993a3e5a"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619ed4d24acef0bd58b16a1be39077c0b36c65782e6c933892439af5e799110e"
dependencies = [
"bumpalo",
"cranelift-bforest",
"cranelift-codegen-meta",
"cranelift-codegen-shared",
"cranelift-control",
"cranelift-entity",
"cranelift-isle",
"gimli",
"hashbrown 0.13.2",
"log",
"regalloc2",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-codegen-meta"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c777ce22678ae1869f990b2f31e0cd7ca109049213bfc0baf3e2205a18b21ebb"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb65884d17a1fa55990dd851c43c140afb4c06c3312cf42cfa1222c3b23f9561"
[[package]]
name = "cranelift-control"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a0cea8abc90934d0a7ee189a29fd35fecd5c40f59ae7e6aab1805e8ab1a535e"
dependencies = [
"arbitrary",
]
[[package]]
name = "cranelift-entity"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e50bebc05f2401a1320169314b62f91ad811ef20163cac00151d78e0684d4c"
[[package]]
name = "cranelift-frontend"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b82ccfe704d53f669791399d417928410785132d809ec46f5e2ce069e9d17c8"
dependencies = [
"cranelift-codegen",
"log",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-isle"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2515d8e7836f9198b160b2c80aaa1f586d7749d57d6065af86223fb65b7e2c3"
[[package]]
name = "cranelift-jit"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e3830a0c5c18c5ddf1c6d4a3dc049a3723d4606e24699796116963ac5bb0404"
dependencies = [
"anyhow",
"cranelift-codegen",
"cranelift-control",
"cranelift-entity",
"cranelift-module",
"cranelift-native",
"libc",
"log",
"region",
"target-lexicon",
"wasmtime-jit-icache-coherence",
"windows-sys",
]
[[package]]
name = "cranelift-module"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2709ba70d7340ef9ffc408df1905bfd02f33eddeb6f8a7198d93c1d0c1154c3"
dependencies = [
"anyhow",
"cranelift-codegen",
"cranelift-control",
]
[[package]]
name = "cranelift-native"
version = "0.96.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcb47ffdcdac7e9fed6e4a618939773a4dc4a412fa7da9e701ae667431a10af3"
dependencies = [
"cranelift-codegen",
"libc",
"target-lexicon",
]
[[package]]
name = "errno"
version = "0.3.1"
@ -349,29 +191,6 @@ dependencies = [
"libc",
]
[[package]]
name = "fallible-iterator"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]]
name = "gimli"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
dependencies = [
"fallible-iterator",
"indexmap",
"stable_deref_trait",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.13.2"
@ -393,16 +212,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
]
[[package]]
name = "io-lifetimes"
version = "1.0.10"
@ -419,9 +228,6 @@ name = "ir"
version = "0.1.0"
dependencies = [
"chumsky",
"serde",
"serde-lexpr",
"serde_derive",
"syntax",
"typing",
]
@ -438,38 +244,11 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "itoa"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "lexpr"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a84de6a9df442363b08f5dbf0cd5b92edc70097b89c4ce4bfea4679fe48bc67"
dependencies = [
"itoa",
"lexpr-macros",
"ryu",
]
[[package]]
name = "lexpr-macros"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36b5cb8bb985c81a8ac1a0f8b5c4865214f574ddd64397ef7a99c236e21f35bb"
dependencies = [
"proc-macro2",
"quote",
]
[[package]]
name = "libc"
version = "0.2.142"
version = "0.2.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
name = "linux-raw-sys"
@ -477,21 +256,6 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf"
[[package]]
name = "log"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "mach"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa"
dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.17.1"
@ -525,37 +289,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "regalloc2"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4a52e724646c6c0800fc456ec43b4165d2f91fba88ceaca06d9e0b400023478"
dependencies = [
"hashbrown 0.13.2",
"log",
"rustc-hash",
"slice-group-by",
"smallvec",
]
[[package]]
name = "region"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0"
dependencies = [
"bitflags",
"libc",
"mach",
"winapi",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.37.14"
@ -570,57 +303,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "serde"
version = "1.0.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
[[package]]
name = "serde-lexpr"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb4cda13396159f59e7946118cdac0beadeecfb7cf76b197f4147e546f4ead6f"
dependencies = [
"lexpr",
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "slice-group-by"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7"
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "stacker"
version = "0.1.15"
@ -658,12 +340,6 @@ dependencies = [
"chumsky",
]
[[package]]
name = "target-lexicon"
version = "0.12.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5"
[[package]]
name = "typing"
version = "0.1.0"
@ -696,17 +372,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasmtime-jit-icache-coherence"
version = "9.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "374ff63b3eb41db57c56682a9ef7737d2c9efa801f5dbf9da93941c9dd436a06"
dependencies = [
"cfg-if",
"libc",
"windows-sys",
]
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -5,9 +5,5 @@ edition = "2021"
[dependencies]
chumsky = "1.0.0-alpha.3"
cranelift = "0.96.3"
cranelift-jit = "0.96.3"
cranelift-module = "0.96.3"
cranelift-native = "0.96.3"
syntax = { path = "../syntax" }
typing = { path = "../typing" }

10
example/err_ty.hlm Normal file
View file

@ -0,0 +1,10 @@
let f = fun (a (Int) -> Int, y Int) -> a(y);
let g = fun (a (Int, Int) -> Int, y Int) -> a(y, 1);
let a = fun (x Int) -> x + 1;
let b = fun (x Int, y Int) -> x + y;
f(a, 1);
g(a, 1);
f(b, 1);
g(b, 1);

View file

@ -1,7 +1,7 @@
let add = fun (x Int, y Int) Int -> x + y;
let add = fun (x Int, y Int) Int -> x + y;
let succ = fun (x) -> x + 1;
let mul = fun (x, y) -> x * y;
let mul = fun (x, y) -> x * y;
add(33, 34)
|> fun (x) -> succ(x)
|> fun (x) -> mul(x, 10)
add(33, 35)
|> fun (x) -> succ(x)
|> fun (x) -> mul(x, 10)

View file

@ -5,8 +5,5 @@ edition = "2021"
[dependencies]
chumsky = "1.0.0-alpha.3"
serde = "1.0.164"
serde-lexpr = "0.1.3"
serde_derive = "1.0.164"
syntax = { path = "../syntax" }
typing = { path = "../typing" }

View file

@ -1,7 +1,7 @@
use typing::typed::TExpr;
use syntax::expr::{Lit as ExprLit, UnaryOp, BinaryOp};
use std::fmt::{self, Display, Formatter, Result as FmtResult};
use std::fmt::{Display, Formatter, Result as FmtResult};
#[derive(Clone, Debug)]
pub enum Lit<'src> {

View file

@ -187,22 +187,11 @@ impl<'src> Infer<'src> {
(Func(a1, r1), Func(a2, r2)) => {
// Check the number of arguments
if a1.len() != a2.len() {
let mut e = InferError::new("Argument length mismatch", c.span)
let e = InferError::new("Argument length mismatch", c.span)
.add_error(format!(
"This function is expected to take {} arguments, found {}",
a2.len(), a1.len()
), c.span);
if a2.len() > a1.len() {
// Get the types of the needed arguments
let mut args = Vec::new();
for i in a1.len()..a2.len() {
args.push(self.substitute(a2[i].clone()).to_string());
}
e = e.add_hint(format!(
"Need arguments of type `{}` to call this function",
args.join(", ")
), c.span);
}
return Err(e);
}
// Unify the arguments
@ -243,7 +232,6 @@ impl<'src> Infer<'src> {
}
/// Solve the constraints by unifying them
fn solve(&mut self) -> Vec<InferError> {
let mut errors = Vec::new();
for c in self.constraints.clone().into_iter() {
@ -737,8 +725,12 @@ pub fn infer_exprs(es: Vec<(Expr, SimpleSpan)>) -> (Vec<(TExpr, SimpleSpan)>, Ve
let solve_errors = inf.solve();
if !solve_errors.is_empty() {
errors.extend(solve_errors);
} else {
// Substitute the types
tes = tes.into_iter()
.map(|(te, s)| (inf.substitute_texp(te), s))
.collect();
}
(rename_exprs(tes), errors)
}