feat: add repl bin
This commit is contained in:
parent
b086a89557
commit
e79e44c0df
18
.envrc
18
.envrc
@ -1 +1,17 @@
|
|||||||
use flake
|
#!/usr/bin/env bash
|
||||||
|
# ^ make editor happy
|
||||||
|
|
||||||
|
#
|
||||||
|
# Use https://direnv.net/ to automatically load the dev shell.
|
||||||
|
#
|
||||||
|
|
||||||
|
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
|
||||||
|
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
|
||||||
|
fi
|
||||||
|
|
||||||
|
watch_file nix/**
|
||||||
|
watch_file -- **/*.nix
|
||||||
|
# Adding files to git includes them in a flake
|
||||||
|
# But it is also a bit much reloading.
|
||||||
|
# watch_file .git/index .git/HEAD
|
||||||
|
use flake . --show-trace
|
||||||
|
|||||||
@ -6,6 +6,14 @@ version = "0.1.0"
|
|||||||
|
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "demo"
|
||||||
|
path = "src/demo.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "repl"
|
||||||
|
path = "src/repl.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
as-any = "0.3.1"
|
as-any = "0.3.1"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
|
|||||||
49
flake.nix
49
flake.nix
@ -18,17 +18,20 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
nixConfig = {
|
nixConfig = {
|
||||||
|
extra-trusted-public-keys = "eigenvalue.cachix.org-1:ykerQDDa55PGxU25CETy9wF6uVDpadGGXYrFNJA3TUs=";
|
||||||
|
extra-substituters = "https://eigenvalue.cachix.org";
|
||||||
allow-import-from-derivation = true;
|
allow-import-from-derivation = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = inputs @ {
|
||||||
inputs @ { self
|
self,
|
||||||
, nixpkgs
|
nixpkgs,
|
||||||
, flake-parts
|
flake-parts,
|
||||||
, rust-overlay
|
rust-overlay,
|
||||||
, crate2nix
|
crate2nix,
|
||||||
, ...
|
...
|
||||||
}: flake-parts.lib.mkFlake { inherit inputs; } {
|
}:
|
||||||
|
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||||
systems = [
|
systems = [
|
||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
"aarch64-linux"
|
"aarch64-linux"
|
||||||
@ -41,29 +44,41 @@
|
|||||||
./nix/devshell/flake-module.nix
|
./nix/devshell/flake-module.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
perSystem = { system, pkgs, lib, inputs', ... }:
|
perSystem = {
|
||||||
let
|
system,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
inputs',
|
||||||
|
...
|
||||||
|
}: let
|
||||||
# If you dislike IFD, you can also generate it with `crate2nix generate`
|
# If you dislike IFD, you can also generate it with `crate2nix generate`
|
||||||
# on each dependency change and import it here with `import ./Cargo.nix`.
|
# on each dependency change and import it here with `import ./Cargo.nix`.
|
||||||
cargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix {
|
cargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix {
|
||||||
name = "rustnix";
|
name = "rustnix";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
};
|
};
|
||||||
in
|
in rec {
|
||||||
rec {
|
|
||||||
checks = {
|
checks = {
|
||||||
rustnix = cargoNix.rootCrate.build.override {
|
rustnix = cargoNix.rootCrate.build.override {
|
||||||
runTests = true;
|
runTests = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = rec {
|
apps = rec {
|
||||||
|
demo = {
|
||||||
|
type = "app";
|
||||||
|
program = "${packages.default}/bin/demo";
|
||||||
|
};
|
||||||
|
repl = {
|
||||||
|
type = "app";
|
||||||
|
program = "${packages.default}/bin/repl";
|
||||||
|
};
|
||||||
|
default = demo;
|
||||||
|
};
|
||||||
|
|
||||||
|
packages = {
|
||||||
rustnix = cargoNix.rootCrate.build;
|
rustnix = cargoNix.rootCrate.build;
|
||||||
default = packages.rustnix;
|
default = packages.rustnix;
|
||||||
dockerImage = pkgs.dockerTools.buildImage {
|
|
||||||
name = "lispers";
|
|
||||||
config = { Cmd = [ "${rustnix}/bin/lispers" ]; };
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit (pkgs) rust-toolchain;
|
inherit (pkgs) rust-toolchain;
|
||||||
|
|
||||||
|
|||||||
33
src/repl.rs
Normal file
33
src/repl.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use lisp::Expression;
|
||||||
|
use parser::ParserError;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
mod parser;
|
||||||
|
mod lisp;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let env = lisp::Environment::default();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
print!("> ");
|
||||||
|
std::io::stdout().flush().unwrap();
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
if std::io::stdin().read_line(&mut input).unwrap() == 0 {
|
||||||
|
println!("Exiting REPL...");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
match parser::ExpressionStream::from_char_stream(input.chars()).collect::<Result<Vec<Expression>, ParserError>>() {
|
||||||
|
Err(e) => println!("Parser Error: {:?}", e),
|
||||||
|
Ok(exprs) => {
|
||||||
|
for expr in exprs {
|
||||||
|
match lisp::eval(&env, expr) {
|
||||||
|
Err(e) => println!("Eval Error: {}", e),
|
||||||
|
Ok(val) => println!("{}", val),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user