package up for the bot
This commit is contained in:
parent
6de9b49349
commit
ddab1e71f1
6 changed files with 165 additions and 5 deletions
38
default.nix
Normal file
38
default.nix
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# ty https://hoverbear.org/blog/a-flake-for-your-crate/
|
||||
|
||||
{ lib
|
||||
, naersk
|
||||
, stdenv
|
||||
, clangStdenv
|
||||
, hostPlatform
|
||||
, targetPlatform
|
||||
, pkg-config
|
||||
, libiconv
|
||||
, rustfmt
|
||||
, cargo
|
||||
, rustc
|
||||
}:
|
||||
|
||||
let
|
||||
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
|
||||
in
|
||||
|
||||
naersk.lib."${targetPlatform.system}".buildPackage rec {
|
||||
src = ./.;
|
||||
|
||||
buildInputs = [
|
||||
rustfmt
|
||||
pkg-config
|
||||
cargo
|
||||
rustc
|
||||
];
|
||||
checkInputs = [ cargo rustc ];
|
||||
|
||||
doCheck = true;
|
||||
CARGO_BUILD_INCREMENTAL = "false";
|
||||
RUST_BACKTRACE = "full";
|
||||
copyLibs = true;
|
||||
|
||||
name = cargoToml.package.name;
|
||||
version = cargoToml.package.version;
|
||||
}
|
||||
48
flake.lock
Normal file
48
flake.lock
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"nodes": {
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1745925850,
|
||||
"narHash": "sha256-cyAAMal0aPrlb1NgzMxZqeN1mAJ2pJseDhm2m6Um8T0=",
|
||||
"owner": "nmattia",
|
||||
"repo": "naersk",
|
||||
"rev": "38bc60bbc157ae266d4a0c96671c6c742ee17a5f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nmattia",
|
||||
"repo": "naersk",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1751382304,
|
||||
"narHash": "sha256-p+UruOjULI5lV16FkBqkzqgFasLqfx0bihLBeFHiZAs=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d31a91c9b3bee464d054633d5f8b84e17a637862",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
63
flake.nix
Normal file
63
flake.nix
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# ty https://hoverbear.org/blog/a-flake-for-your-crate/
|
||||
{
|
||||
description = "puyo TWO";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
naersk.url = "github:nmattia/naersk";
|
||||
naersk.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, naersk }:
|
||||
let
|
||||
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
|
||||
in
|
||||
{
|
||||
overlay = final: prev: {
|
||||
"${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; };
|
||||
};
|
||||
|
||||
packages = forAllSystems (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
self.overlay
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
|
||||
});
|
||||
|
||||
|
||||
defaultPackage = forAllSystems (system: (import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlay ];
|
||||
})."${cargoToml.package.name}");
|
||||
|
||||
checks = forAllSystems (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
self.overlay
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
format = pkgs.runCommand "check-format"
|
||||
{
|
||||
buildInputs = with pkgs; [ rustfmt cargo ];
|
||||
} ''
|
||||
${pkgs.rustfmt}/bin/cargo-fmt fmt --manifest-path ${./.}/Cargo.toml -- --check
|
||||
${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.}
|
||||
touch $out # it worked!
|
||||
'';
|
||||
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
1
result
Symbolic link
1
result
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/nix/store/ysnlms9yadny09279xks5h0k1dzx1iqa-puyo-lang-0.1.0
|
||||
18
src/eval.rs
18
src/eval.rs
|
|
@ -2,6 +2,7 @@ use core::fmt;
|
|||
use std::{
|
||||
cell::RefCell,
|
||||
collections::{HashMap, hash_map::Entry},
|
||||
io::{self, Write},
|
||||
ops, process,
|
||||
rc::Rc,
|
||||
};
|
||||
|
|
@ -181,8 +182,8 @@ fn eval<'a>(insts: &'a [Inst<'a>], stack: &mut Stack<'a>, env: &Rc<RefCell<Env<'
|
|||
"floor" => stack.run_monadic(f64::floor),
|
||||
"round" => stack.run_monadic(f64::round),
|
||||
"expt" => stack.run_dyadic(f64::powf),
|
||||
"=" => stack.run_dyadic(|a, b| if (a - b).abs() < 1e-10 { 1. } else { 0. }),
|
||||
"<" => stack.run_dyadic(|a, b| if a < b { 1. } else { 0. }),
|
||||
"=" => stack.run_dyadic(|a, b| ((a - b).abs() < 1e-10).into()),
|
||||
"<" => stack.run_dyadic(|a, b| (a < b).into()),
|
||||
"dup" => {
|
||||
let top = stack.pop_default();
|
||||
stack.push(top.clone());
|
||||
|
|
@ -195,7 +196,12 @@ fn eval<'a>(insts: &'a [Inst<'a>], stack: &mut Stack<'a>, env: &Rc<RefCell<Env<'
|
|||
stack.push(b);
|
||||
}
|
||||
"print" => {
|
||||
println!("{}", stack.pop_default());
|
||||
print!("{}", stack.pop_default());
|
||||
}
|
||||
"put" => {
|
||||
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
let byte = stack.pop_num() as u8;
|
||||
io::stdout().write_all(&[byte]).unwrap();
|
||||
}
|
||||
"explode" => {
|
||||
eprintln!("I ESPLODED");
|
||||
|
|
@ -214,7 +220,11 @@ fn eval<'a>(insts: &'a [Inst<'a>], stack: &mut Stack<'a>, env: &Rc<RefCell<Env<'
|
|||
then.call(stack);
|
||||
}
|
||||
}
|
||||
_ => stack.push(env.borrow().get(var).expect("idk this var")),
|
||||
_ => stack.push(
|
||||
env.borrow()
|
||||
.get(var)
|
||||
.unwrap_or_else(|| panic!("unknown variable: {var}")),
|
||||
),
|
||||
},
|
||||
Inst::Num(n) => stack.push(Val::Num(*n)),
|
||||
Inst::Call => {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
let _ = io::stdin().read_to_string(&mut src).unwrap();
|
||||
|
||||
let insts = parse(&src);
|
||||
eprintln!("{}!\n{insts:#?}", Inst::Block(insts.clone()));
|
||||
eprintln!("{}!", Inst::Block(insts.clone()));
|
||||
|
||||
run(&insts);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue