Skip to content

Commit

Permalink
Merge pull request #3 from Rigidity/optimizations
Browse files Browse the repository at this point in the history
Optimizations and server side rendered docs site
  • Loading branch information
Rigidity authored Jun 22, 2024
2 parents b5e97a6 + 1da02a3 commit b3b7864
Show file tree
Hide file tree
Showing 99 changed files with 5,715 additions and 2,433 deletions.
760 changes: 706 additions & 54 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
[workspace]
resolver = "2"
members = ["crates/*"]

[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"

[[workspace.metadata.leptos]]
name = "rue-web"
bin-package = "rue-web"
lib-package = "rue-web"
site-root = "target/site"
assets-dir = "crates/rue-web/public"
site-addr = "127.0.0.1:3000"
reload-port = 3001
browserquery = "defaults"
env = "DEV"
bin-features = ["ssr"]
lib-features = ["hydrate"]
lib-profile-release = "wasm-release"
style-file = "crates/rue-web/style/output.css"
watch-additional-files = ["crates/rue-web/docs", "crates/rue-web/docs.json"]
2 changes: 2 additions & 0 deletions crates/rue-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ thiserror = "1.0.58"
num-traits = "0.2.18"
num-iter = "0.1.44"
num-bigint = "0.4.4"
log = "0.4.21"
hex = "0.4.3"
36 changes: 24 additions & 12 deletions crates/rue-compiler/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Ops {
pubkey_for_exp: NodePtr,
not: NodePtr,
any: NodePtr,
all: NodePtr,
}

impl<'a> Codegen<'a> {
Expand Down Expand Up @@ -61,6 +62,7 @@ impl<'a> Codegen<'a> {
pubkey_for_exp: allocator.new_small_number(30).unwrap(),
not: allocator.new_small_number(32).unwrap(),
any: allocator.new_small_number(33).unwrap(),
all: allocator.new_small_number(34).unwrap(),
};
Self { db, allocator, ops }
}
Expand All @@ -69,6 +71,7 @@ impl<'a> Codegen<'a> {
match self.db.lir(lir_id).clone() {
Lir::Atom(atom) => self.gen_atom(atom.clone()),
Lir::Pair(first, rest) => self.gen_pair(first, rest),
Lir::Quote(value) => self.gen_quote(value),
Lir::Path(path) => self.allocator.new_small_number(path).unwrap(),
Lir::Run(program, args) => self.gen_run(program, args),
Lir::Curry(body, args) => self.gen_apply(body, args),
Expand All @@ -77,7 +80,7 @@ impl<'a> Codegen<'a> {
Lir::First(value) => self.gen_first(value),
Lir::Rest(value) => self.gen_rest(value),
Lir::Raise(value) => self.gen_raise(value),
Lir::Sha256(value) => self.gen_sha256(value),
Lir::Sha256(values) => self.gen_sha256(values),
Lir::IsCons(value) => self.gen_is_cons(value),
Lir::Strlen(value) => self.gen_strlen(value),
Lir::PubkeyForExp(value) => self.gen_pubkey_for_exp(value),
Expand All @@ -88,6 +91,7 @@ impl<'a> Codegen<'a> {
}
Lir::Not(value) => self.gen_not(value),
Lir::Any(values) => self.gen_any(values),
Lir::All(values) => self.gen_all(values),
Lir::Add(values) => self.gen_add(values),
Lir::Sub(values) => self.gen_sub(values),
Lir::Mul(values) => self.gen_mul(values),
Expand All @@ -109,9 +113,11 @@ impl<'a> Codegen<'a> {
self.list(&[self.ops.c, first, rest])
}

fn gen_run(&mut self, program: LirId, args: LirId) -> NodePtr {
fn gen_run(&mut self, program: LirId, args: Option<LirId>) -> NodePtr {
let program = self.gen_lir(program);
let args = self.gen_lir(args);
let args = args
.map(|args| self.gen_lir(args))
.unwrap_or(self.allocator.one());
self.list(&[self.ops.a, program, args])
}

Expand Down Expand Up @@ -152,9 +158,12 @@ impl<'a> Codegen<'a> {
}
}

fn gen_sha256(&mut self, value: LirId) -> NodePtr {
let value = self.gen_lir(value);
self.list(&[self.ops.sha256, value])
fn gen_sha256(&mut self, values: Vec<LirId>) -> NodePtr {
let mut args = vec![self.ops.sha256];
for value in values {
args.push(self.gen_lir(value));
}
self.list(&args)
}

fn gen_is_cons(&mut self, value: LirId) -> NodePtr {
Expand Down Expand Up @@ -192,12 +201,7 @@ impl<'a> Codegen<'a> {
let condition = self.gen_lir(condition);
let then_branch = self.gen_lir(then_branch);
let else_branch = self.gen_lir(else_branch);

let then_branch = self.quote(then_branch);
let else_branch = self.quote(else_branch);

let conditional = self.list(&[self.ops.i, condition, then_branch, else_branch]);
self.list(&[self.ops.a, conditional, self.ops.q])
self.list(&[self.ops.i, condition, then_branch, else_branch])
}

fn gen_not(&mut self, value: LirId) -> NodePtr {
Expand All @@ -213,6 +217,14 @@ impl<'a> Codegen<'a> {
self.list(&args)
}

fn gen_all(&mut self, values: Vec<LirId>) -> NodePtr {
let mut args = vec![self.ops.all];
for value in values {
args.push(self.gen_lir(value));
}
self.list(&args)
}

fn gen_add(&mut self, values: Vec<LirId>) -> NodePtr {
let mut args = vec![self.ops.add];
for value in values {
Expand Down
Loading

0 comments on commit b3b7864

Please sign in to comment.