Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions block-lang/.github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy
on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install mdbook
run: |
mkdir mdbook
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
- name: Deploy GitHub Pages
run: |
# This assumes your book is in the root of your repository.
# Just add a `cd` here if you need to change to another directory.
mdbook build
git worktree add gh-pages
git config user.name "Deploy from CI"
git config user.email ""
cd gh-pages
# Delete the ref to avoid keeping history.
git update-ref -d refs/heads/gh-pages
rm -rf *
mv ../docs/ .
sed '/^\/docs\/$/d' .gitignore -i
git add .
git commit -m "Deploy $GITHUB_SHA to gh-pages"
git push --force --set-upstream origin gh-pages
2 changes: 2 additions & 0 deletions block-lang/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
# Added by cargo

/target

/docs/
7 changes: 5 additions & 2 deletions block-lang/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix",
"rust-analyzer.server.extraEnv": {"RUSTUP_TOOLCHAIN": "nightly"}
"rust-analyzer.server.extraEnv": {
"RUSTUP_TOOLCHAIN": "nightly"
},
"nixEnvSelector.suggestion": false,
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix"
}
40 changes: 21 additions & 19 deletions block-lang/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions block-lang/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "tmp-lang"
name = "block-lang"
version = "0.1.0"
edition = "2021"
default-run = "tmp-lang"
default-run = "block-lang"

[[bin]]
name = "cli"
Expand All @@ -29,16 +29,12 @@ anyhow = "1.0.58"
bytecheck = "0.6.8"
rkyv = { version = "0.7.39", features = ["validation"] }
thiserror = "1.0.31"
bevy_pancam = { version = "*" }
bevy_mouse_tracking_plugin = { version = "*" }
bevy_pancam = { git = "https://github.com/zyansheep/bevy_pancam" }
bevy_mouse_tracking_plugin = { git = "https://github.com/zyansheep/bevy-mouse-tracking" }
iyes_loopless = "0.6.1"
rustyline = "10.0.0"
bevy_prototype_lyon = "0.5.0"

[patch.crates-io]
bevy_mouse_tracking_plugin = { path = "vendor/bevy-mouse-tracking" }
bevy_pancam = { path = "vendor/bevy_pancam" }

# Stuff for Zyansheep, I use NixOS btw :)
[package.metadata.nix]
build = true
Expand All @@ -51,6 +47,7 @@ nativeBuildInputs = [
"pkgconfig",
"cmake",
"mold",
"rust-analyzer",
]
buildInputs = [
# Window and Input
Expand Down
15 changes: 6 additions & 9 deletions block-lang/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# tmp-lang
# Block Lang
*Functional Blocks*

Some unwritten language...
See the website: https://zyansheep.github.io/tmp-lang/

## General idea

Expand All @@ -10,12 +11,8 @@ Lambda calculus, but a visual drag-n-drop application, a bit like MIT Scratch

Putting blocks together counts as assembly

The beautiful part, is animating the reductions
The beautiful part, is animating the reductions (Not finished yet)

Gui: `cargo run --release`

## How to run:

```bash
cargo run --release
```
(may need some graphics libraries, should be fine on windows)
Cli: `cargo run --package cli --release`
Binary file added block-lang/assets/AppState=None.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added block-lang/assets/AppState=Placed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added block-lang/assets/AppState=Slotted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added block-lang/assets/LamState=Connected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added block-lang/assets/LamState=None.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added block-lang/assets/LamState=Placed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed block-lang/assets/Lambda.png
Binary file not shown.
File renamed without changes
9 changes: 9 additions & 0 deletions block-lang/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[book]
authors = ["SimonFJ20", "Zyansheep"]
language = "en"
multilingual = false
src = "pages"
title = "Block Lang Documentation"

[build]
build-dir = "docs"
5 changes: 5 additions & 0 deletions block-lang/pages/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Summary

- [Introduction](./introduction.md)
- [Build instructions](./build_instruction.md)
- [How 2 use](./how_to_use.md)
10 changes: 10 additions & 0 deletions block-lang/pages/build_instruction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Build instruction

`cargo run`

Or

`cargo run --features bevy/dynamic` to avoid having to recompile bevy.


23 changes: 23 additions & 0 deletions block-lang/pages/how_to_use.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# How 2 use

This program is for making lambda calculus expressions.

Lambda consists of three elements
* Variables `x` is the green block
* Functions `λx.x` is the red block
* Applications `(λx.x) x` is the purple block

## Step by step example

Press `a` to make an application. The block will now follow your mouse cursor, until you click somewhere on the canvas.

Now press `f` ~~to pay respect~~ to make a function, and place it on the left side of the application.

Then press `v` to make a variable and place it on the top-half of the function.

Hover on the varible, press `c`, and then click the function block. Now the variable is bound to the function.

Make another function, place it on the right side of the application and insert a variable on the bottom.

Now hover the mouse directly on the frame of the application and press `r`. That will read the expression, show it in text form on the sidebar. It will also reduce the expression, and show the reduced expression in text form, below the original expression.
14 changes: 14 additions & 0 deletions block-lang/pages/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Block Lang

MIT Scratch, but for lambda calculus, because we all have trouble finding the 'λ'-key, when trying to type it.

## General idea

Lambda calculus, but a visual drag-n-drop application, a bit like MIT Scratch

## Theme: Beautiful assembly

Putting blocks together counts as assembly

The beautiful part, is animating the reductions (Not finished yet)
60 changes: 34 additions & 26 deletions block-lang/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,44 @@ use std::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, PI};

use bevy::prelude::*;

use crate::{expr::{Binding, Expr}, mouseover::{HoverState, TopHover}, placing::Placing};
use crate::{expr::{BindTree, Expr}, mouseover::{HoverState, TopHover}, placing::Placing};

/* pub enum Binding {
None,
End,
Branch(Box<Binding>, Box<Binding>)
}
/// Associated `Entity` with a variable
pub type BindEntityTree = BindTree<'static, Entity>;

#[derive(Component, Default)]
pub enum Expr {
Function { bind: Binding, expr: Option<Entity> },
Application { func: Option<Entity>, args: Option<Entity> },
#[default]
Variable,
} */
#[derive(Clone, Copy, Debug)]
pub enum PartialForm {
Func, Args
}

#[derive(Component, Clone, Debug)]
pub enum WrappedExpr {
Variable { bound: Option<Entity> },
Variable { formed: (&'static Expr<'static>, &'static BindEntityTree) },
Lambda {
bind_entity: Option<Entity>,
expr_entity: Option<Entity>,
formed: Option<Expr<'static>>,
is_bound: bool,
formed: Option<(&'static Expr<'static>, &'static BindEntityTree)>,
},
Application {
func_entity: Option<Entity>,
args_entity: Option<Entity>,
formed: Option<Expr<'static>>,
partial_formed: Option<(&'static Expr<'static>, &'static BindEntityTree, PartialForm)>,
formed: Option<(&'static Expr<'static>, &'static BindEntityTree)>,
}
}
impl WrappedExpr {
pub const APPLICATION: WrappedExpr = WrappedExpr::Application { func_entity: None, args_entity: None, formed: None };
pub const LAMBDA: WrappedExpr = WrappedExpr::Lambda { bind_entity: None, expr_entity: None, formed: None };
pub const VARIABLE: WrappedExpr = WrappedExpr::Variable { bound: None };
pub const APPLICATION: WrappedExpr = WrappedExpr::Application { func_entity: None, args_entity: None, partial_formed: None, formed: None };
pub const LAMBDA: WrappedExpr = WrappedExpr::Lambda { is_bound: false, expr_entity: None, formed: None };
pub const VARIABLE: WrappedExpr = WrappedExpr::Variable { formed: (Expr::VAR, BindTree::NONE) };
pub fn unform(&mut self) {
match self {
Self::Application { formed, partial_formed, .. } => {
*formed = None; *partial_formed = None;
}
Self::Lambda { formed, .. } => *formed = None,
_ => {},
}
}
}
impl Default for WrappedExpr { fn default() -> Self { Self::VARIABLE } }

Expand Down Expand Up @@ -80,12 +84,16 @@ impl ObjectData {
}
pub fn gen_texture(expr: &WrappedExpr, asset_server: &AssetServer) -> Handle<Image> {
match expr {
WrappedExpr::Variable { .. } => asset_server.load("VariableDot.png"),
WrappedExpr::Variable { bound: Some(_) } => asset_server.load("VariableBound.png"),
WrappedExpr::Lambda { expr_entity: None, formed: None, .. } => asset_server.load("Lambda.png"),
WrappedExpr::Lambda { expr_entity: Some(_), formed: None, .. } => asset_server.load("LambdaEmpty.png"),
WrappedExpr::Lambda { formed: Some(_), .. } => asset_server.load("LambdaDot.png"),
WrappedExpr::Application { .. } => asset_server.load("Application.png"),
WrappedExpr::Variable { formed: (_, BindEntityTree::End(_)) } => asset_server.load("VarState=Connected.png"),
WrappedExpr::Variable { .. } => asset_server.load("VarState=Placed.png"),
WrappedExpr::Lambda { formed: Some(_), is_bound: true, .. } => asset_server.load("LamState=FormedConnected.png"),
WrappedExpr::Lambda { formed: Some(_), .. } => asset_server.load("LamState=Formed.png"),
WrappedExpr::Lambda { expr_entity: Some(_), is_bound: true, .. } => asset_server.load("LamState=Connected.png"),
WrappedExpr::Lambda { expr_entity: Some(_), .. } => asset_server.load("LamState=Placed.png"),
WrappedExpr::Lambda { expr_entity: None, .. } => asset_server.load("LamState=None.png"),
WrappedExpr::Application { formed: Some(_), .. } => asset_server.load("AppState=Formed.png"),
WrappedExpr::Application { func_entity: Some(_), args_entity: Some(_), .. } => asset_server.load("AppState=Slotted.png"),
WrappedExpr::Application { .. } => asset_server.load("AppState=Placed.png"),
}
}
pub fn gen_transform(&self, z_loc: f32) -> Transform {
Expand Down
11 changes: 5 additions & 6 deletions block-lang/src/block_to_expr.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{expr::Expr, block::WrappedExpr};


pub fn block_to_expr(wrapped: &WrappedExpr) -> Result<&Expr<'static>, String> {
pub fn block_to_expr(wrapped: &WrappedExpr) -> Result<&Expr<'static>, Box<dyn std::error::Error>> {
match wrapped {
WrappedExpr::Variable { bound } => Ok(&Expr::Variable),
WrappedExpr::Lambda { bind_entity, expr_entity, formed: Some(expr) } => Ok(expr),
WrappedExpr::Application { func_entity, args_entity, formed: Some(expr) } => Ok(expr),
_ => Err("malformed expression".into()),
WrappedExpr::Variable { formed: (expr, _) }
| WrappedExpr::Lambda { formed: Some((expr, _)), .. }
| WrappedExpr::Application { formed: Some((expr, _)), .. } => Ok(expr),
_ => Err(format!("unformed expression for {wrapped:?}"))?,
}
}
2 changes: 1 addition & 1 deletion block-lang/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn cli_editor() {
use parse::Command;
use rustyline::Editor;

println!("tmp-lang cli editor!");
println!("block-lang cli editor!");
let mut editor = Editor::<()>::new().unwrap();
if editor.load_history(".editor_history").is_err() {}

Expand Down
Loading