Progress
This commit is contained in:
parent
e86271b190
commit
b95a39b1e8
8 changed files with 80 additions and 15 deletions
15
default.nix
15
default.nix
|
@ -1,15 +1,16 @@
|
||||||
{ rustPlatform, lib, nix-gitignore, llvmPackages_12 }:
|
{ rustPlatform, lib, nix-gitignore, llvmPkgs, libffi }:
|
||||||
|
|
||||||
let llvmPkgs = llvmPackages_12;
|
with llvmPkgs;
|
||||||
|
|
||||||
in with llvmPkgs;
|
|
||||||
|
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
name = "e0";
|
name = "e0";
|
||||||
src = nix-gitignore.gitignoreSource [ ./.gitignore ] ./.;
|
src = nix-gitignore.gitignoreSource [ ./.gitignore ] ./.;
|
||||||
|
|
||||||
buildInputs = [ llvmPkgs.llvm.dev ];
|
nativeBuildInputs = [ llvm.dev ];
|
||||||
|
buildInputs = [ libffi ];
|
||||||
|
|
||||||
cargoSha256 = lib.fakeSha256;
|
LLVM_SYS_120_PREFIX = "${llvm.dev}";
|
||||||
# cargoSha256 = "sha256-rWMnlkb/XoycP69NOOmg7Wd4qPgliuvOKGWaEth/8tg=";
|
|
||||||
|
# cargoSha256 = lib.fakeSha256;
|
||||||
|
cargoSha256 = "sha256-gPaYoHcNltAe/lK3pLhLZnX3Q8Pxj6yB45L/XWn3ZKc=";
|
||||||
}
|
}
|
||||||
|
|
13
examples/struct.e0
Normal file
13
examples/struct.e0
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
type IntPair = struct {
|
||||||
|
fst: int,
|
||||||
|
snd: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> int {
|
||||||
|
let x = IntPair {
|
||||||
|
fst: 4,
|
||||||
|
snd: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
return x.fst + x.snd;
|
||||||
|
}
|
12
flake.lock
12
flake.lock
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1648219316,
|
"lastModified": 1652252629,
|
||||||
"narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=",
|
"narHash": "sha256-SvT64apetqc8P5nYp1/fOZvUmHUPdPFUZbhSpKy+1aI=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634",
|
"rev": "d2fc6856824cb87742177eefc8dd534bdb6c3439",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -22,11 +22,11 @@
|
||||||
},
|
},
|
||||||
"utils": {
|
"utils": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1648297722,
|
"lastModified": 1649676176,
|
||||||
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=",
|
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade",
|
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -7,9 +7,15 @@
|
||||||
utils.lib.eachDefaultSystem (system:
|
utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
myPkgs = rec { e0 = pkgs.callPackage ./. { }; };
|
llvmPkgs = pkgs.llvmPackages_12;
|
||||||
|
myPkgs = rec { e0 = pkgs.callPackage ./. { inherit llvmPkgs; }; };
|
||||||
|
|
||||||
in rec {
|
in rec {
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [ llvmPkgs.clangUseLLVM cargo-watch ];
|
||||||
|
inputsFrom = [ myPkgs.e0 ];
|
||||||
|
};
|
||||||
|
|
||||||
packages = utils.lib.flattenTree myPkgs;
|
packages = utils.lib.flattenTree myPkgs;
|
||||||
defaultPackage = packages.e0;
|
defaultPackage = packages.e0;
|
||||||
});
|
});
|
||||||
|
|
25
scripts/e0c
Executable file
25
scripts/e0c
Executable file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SOURCE=$?
|
||||||
|
BITCODE=$(mktemp -d)
|
||||||
|
OUTPUT=./a.out
|
||||||
|
|
||||||
|
usage() { echo "$0 options:" && grep " .)\ #" $0; exit 0; }
|
||||||
|
|
||||||
|
[ $# -eq 0 ] && usage
|
||||||
|
while getopts ":hs:p:" arg; do
|
||||||
|
case $arg in
|
||||||
|
o) # Binary output
|
||||||
|
OUTPUT=${OPTARG}
|
||||||
|
;;
|
||||||
|
h | *) # Display help.
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
cargo run -- -o $BITCODE $SOURCE
|
||||||
|
clang -o $OUTPUT $BITCODE
|
|
@ -75,5 +75,6 @@ pub enum Type {
|
||||||
Int,
|
Int,
|
||||||
Bool,
|
Bool,
|
||||||
|
|
||||||
|
StructInst(Vec<(String, Type)>),
|
||||||
Func(Vec<Type>, Box<Type>),
|
Func(Vec<Type>, Box<Type>),
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub enum Type_ {
|
||||||
Int,
|
Int,
|
||||||
Bool,
|
Bool,
|
||||||
|
|
||||||
|
StructInst(Vec<(String, Type_)>),
|
||||||
Func(Vec<Type_>, Box<Type_>),
|
Func(Vec<Type_>, Box<Type_>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +31,12 @@ impl Type_ {
|
||||||
let ret = Type_::from_type(*ret);
|
let ret = Type_::from_type(*ret);
|
||||||
Type_::Func(args, Box::new(ret))
|
Type_::Func(args, Box::new(ret))
|
||||||
}
|
}
|
||||||
|
Type::StructInst(fields) => Type_::StructInst(
|
||||||
|
fields
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, ty)| (name, Type_::from_type(ty)))
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +58,12 @@ impl Type_ {
|
||||||
let ret = ret.convert(assignments)?;
|
let ret = ret.convert(assignments)?;
|
||||||
Type::Func(args, Box::new(ret))
|
Type::Func(args, Box::new(ret))
|
||||||
}
|
}
|
||||||
|
Type_::StructInst(fields) => Type::StructInst(
|
||||||
|
fields
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, ty)| Ok((name.clone(), ty.convert(assignments)?)))
|
||||||
|
.collect::<Result<_>>()?,
|
||||||
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,6 +338,12 @@ fn substitute_types(assignments: &Assignments, ty: &Type_) -> Type_ {
|
||||||
let ret = substitute_types(assignments, &*ret);
|
let ret = substitute_types(assignments, &*ret);
|
||||||
Type_::Func(args, Box::new(ret))
|
Type_::Func(args, Box::new(ret))
|
||||||
}
|
}
|
||||||
|
Type_::StructInst(fields) => Type_::StructInst(
|
||||||
|
fields
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, ty)| (name.clone(), substitute_types(assignments, ty)))
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
Type_::Int | Type_::Bool => ty.clone(),
|
Type_::Int | Type_::Bool => ty.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -501,7 +520,6 @@ pub fn convert(ast: Vec<Decl<()>>) -> Result<Vec<Decl<Type>>> {
|
||||||
collect_info(scoped_env, func)?;
|
collect_info(scoped_env, func)?;
|
||||||
env = *env2.parent.unwrap();
|
env = *env2.parent.unwrap();
|
||||||
|
|
||||||
|
|
||||||
let assignments = unify_constraints(&constraints)?;
|
let assignments = unify_constraints(&constraints)?;
|
||||||
|
|
||||||
let typed_func = substitute_in_func(&assignments, decorated_func)?;
|
let typed_func = substitute_in_func(&assignments, decorated_func)?;
|
||||||
|
|
1
tokei.toml
Normal file
1
tokei.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[[languages]]
|
Loading…
Reference in a new issue