Skip to content

Commit

Permalink
Split into subcrates and start VS Code extension
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Oct 15, 2018
1 parent 0d5b4b4 commit 0b8383c
Show file tree
Hide file tree
Showing 79 changed files with 3,707 additions and 344 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/target/
**/*.rs.bk
.vscode
Cargo.lock
repl-history
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cache:
cargo: true
directories:
- book/highlight.js/node_modules
- editors/code/node_modules
rust:
- 1.28.0
- stable
Expand All @@ -14,14 +15,16 @@ matrix:
- rust: nightly

install:
- ci/install-cargo-updates
- ci/build-highlight-js
- tools/install-cargo-updates
- tools/build-highlight-js
- cargo build --verbose # https://docs.travis-ci.com/user/languages/rust/#Dependency-Management
- (cd editors/code && npm install)

script:
- cargo build --verbose --all # https://docs.travis-ci.com/user/languages/rust/#Default-Build-Script
- cargo test --verbose --all # https://docs.travis-ci.com/user/languages/rust/#Default-Build-Script
- ci/build-book
- (cd editors/code && npm travis)
- tools/build-book

deploy:
# Deploy the book to Github Pages
Expand Down
51 changes: 8 additions & 43 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
[package]
name = "pikelet"
version = "0.1.0"
readme = "README.md"
license = "Apache-2.0"
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>"]
description = "An implementation of a small dependently typed lambda calculus in Rust."
homepage = "https://github.com/pikelet-lang/pikelet"
repository = "https://github.com/pikelet-lang/pikelet"
publish = false

[features]
default = ["cli"]
cli = [
"linefeed",
"structopt",
"term_size",
[workspace]
members = [
"./crates/pikelet",
"./crates/pikelet-driver",
"./crates/pikelet-elaborate",
"./crates/pikelet-language-server",
"./crates/pikelet-repl",
"./crates/pikelet-syntax",
]

[[bin]]
name = "pikelet"
required-features = ["cli"]

[dependencies]
codespan = "0.2.0"
codespan-reporting = "0.2.0"
failure = "0.1.2"
im = "12.2.0"
lalrpop-util = "0.16.0"
moniker = { version = "0.5.0", features = ["codespan", "im"] }
pretty = { version = "0.5.2", features = ["termcolor"] }
unicode-xid = "0.1.0"

# cli dependencies
linefeed = { version = "0.5.1", optional = true }
structopt = { version = "0.2.10", optional = true }
term_size = { version = "0.3.1", optional = true }

[build-dependencies]
lalrpop = "0.16.0"

[dev-dependencies]
goldenfile = "0.7.1"
pretty_assertions = "0.5.1"
2 changes: 1 addition & 1 deletion book/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ better or worse, we've included this as a submodule as a temporary solution.
To build this, we've included a handy script:

```sh
ci/build-highlight-js
tools/build-highlight-js
```

This should update/initialize the submodule, update the npm dependencies,
Expand Down
16 changes: 16 additions & 0 deletions crates/pikelet-driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "pikelet-driver"
version = "0.1.0"
license = "Apache-2.0"
readme = "../../README.md"
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>"]
homepage = "https://github.com/pikelet-lang/pikelet"
repository = "https://github.com/pikelet-lang/pikelet"
publish = false

[dependencies]
codespan = "0.2.0"
codespan-reporting = "0.2.0"
pikelet-elaborate = { version = "0.1.0", path = "../pikelet-elaborate" }
pikelet-library = { version = "0.1.0", path = "../pikelet-library" }
pikelet-syntax = { version = "0.1.0", path = "../pikelet-syntax" }
167 changes: 80 additions & 87 deletions src/lib.rs → crates/pikelet-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,68 @@
//! parsed, desugared, and type checked/elaborated:
//!
//! ```bob
//! .------------.
//! | String |
//! '------------'
//! |
//! - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//! Frontend |
//! |
//! syntax::parse::lexer
//! |
//! v
//! .-----------------------------.
//! | syntax::parse::lexer::Token |
//! '-----------------------------'
//! |
//! syntax::parse::grammar
//! |
//! v
//! .------------------------.
//! | syntax::concrete::Term |---------> Code formatter (TODO)
//! '------------------------'
//! |
//! syntax::translation::desugar
//! |
//! v
//! .-------------------.
//! | syntax::raw::Term |
//! '-------------------'
//! | .---------------------.
//! semantics::{check,infer} <---------- | syntax::core::Value |
//! | '---------------------'
//! v ^
//! .--------------------. |
//! | syntax::core::Term | - semantics::normalize -'
//! '--------------------'
//! |
//! |
//! - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//! Middle (TODO) |
//! |
//! v
//! A-Normal Form (ANF)
//! |
//! v
//! Closure Conversion (CC)
//! |
//! v
//! Static Single Assignment (SSA)
//! |
//! |
//! - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//! Backend (TODO) |
//! |
//! v
//! Codegen
//! |
//! *-------> Bytecode?
//! |
//! *-------> WASM?
//! |
//! *-------> Cranelift IR?
//! |
//! '-------> LLVM IR?
//! .------------.
//! | String |
//! '------------'
//! |
//! - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//! Frontend |
//! |
//! pikelet_syntax::parse::lexer
//! |
//! v
//! .-------------------------------------.
//! | pikelet_syntax::parse::lexer::Token |
//! '-------------------------------------'
//! |
//! pikelet_syntax::parse::grammar
//! |
//! v
//! .--------------------------------.
//! | pikelet_syntax::concrete::Term |---------> Code formatter (TODO)
//! '--------------------------------'
//! |
//! pikelet_syntax::translation::desugar
//! |
//! v
//! .---------------------------.
//! | pikelet_syntax::raw::Term |
//! '---------------------------'
//! | .-----------------------------.
//! pikelet_elaborate::{check,infer} <------------- | pikelet_syntax::core::Value |
//! | '-----------------------------'
//! v ^
//! .----------------------------. |
//! | pikelet_syntax::core::Term | - pikelet_elaborate::normalize -'
//! '----------------------------'
//! |
//! |
//! - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//! Middle (TODO) |
//! |
//! v
//! A-Normal Form (ANF)
//! |
//! v
//! Closure Conversion (CC)
//! |
//! v
//! Static Single Assignment (SSA)
//! |
//! |
//! - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//! Backend (TODO) |
//! |
//! v
//! Codegen
//! |
//! *-------> Bytecode?
//! |
//! *-------> WASM?
//! |
//! *-------> Cranelift IR?
//! |
//! '-------> LLVM IR?
//! ```
//!
//! As you can see we have only built the front-end as of the time of writing. When
Expand Down Expand Up @@ -127,21 +127,9 @@
extern crate codespan;
extern crate codespan_reporting;
#[macro_use]
extern crate failure;
extern crate im;
extern crate lalrpop_util;
#[macro_use]
extern crate moniker;
extern crate pretty;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
extern crate unicode_xid;

mod library;
pub mod semantics;
pub mod syntax;
extern crate pikelet_elaborate;
extern crate pikelet_library;
extern crate pikelet_syntax;

#[cfg(feature = "cli")]
extern crate linefeed;
Expand All @@ -158,9 +146,9 @@ use codespan::{CodeMap, FileMap, FileName};
use codespan_reporting::Diagnostic;
use std::sync::Arc;

use semantics::{Import, TcEnv};
use syntax::translation::{Desugar, DesugarEnv, Resugar};
use syntax::{core, raw};
use pikelet_elaborate::{Import, TcEnv};
use pikelet_syntax::translation::{Desugar, DesugarEnv, Resugar};
use pikelet_syntax::{core, raw};

/// An environment that keeps track of the state of a Pikelet program during
/// compilation or interactive sessions
Expand Down Expand Up @@ -193,12 +181,12 @@ impl Pikelet {

let prim_path = "prim".to_owned();
let prim_name = FileName::virtual_("prim");
let prim_src = library::PRIM.to_owned();
let prim_src = pikelet_library::PRIM.to_owned();
let prim_file = pikelet.code_map.add_filemap(prim_name, prim_src);

let prelude_path = "prelude".to_owned();
let prelude_name = FileName::virtual_("prelude");
let prelude_src = library::PRELUDE.to_owned();
let prelude_src = pikelet_library::PRELUDE.to_owned();
let prelude_file = pikelet.code_map.add_filemap(prelude_name, prelude_src);

pikelet.load_file(prim_path, prim_file).unwrap();
Expand All @@ -212,7 +200,7 @@ impl Pikelet {
internal_path: String,
file_map: Arc<FileMap>,
) -> Result<(), Vec<Diagnostic>> {
let (concrete_term, _import_paths, errors) = syntax::parse::term(&file_map);
let (concrete_term, _import_paths, errors) = pikelet_syntax::parse::term(&file_map);
if !errors.is_empty() {
return Err(errors.iter().map(|error| error.to_diagnostic()).collect());
}
Expand Down Expand Up @@ -248,11 +236,11 @@ impl Pikelet {
&self,
raw_term: &raw::RcTerm,
) -> Result<(core::RcTerm, core::RcType), Vec<Diagnostic>> {
semantics::infer_term(&self.tc_env, &raw_term).map_err(|e| vec![e.to_diagnostic()])
pikelet_elaborate::infer_term(&self.tc_env, &raw_term).map_err(|e| vec![e.to_diagnostic()])
}

pub fn nf_term(&self, term: &core::RcTerm) -> Result<core::RcValue, Vec<Diagnostic>> {
semantics::nf_term(&self.tc_env, term).map_err(|e| vec![e.to_diagnostic()])
pikelet_elaborate::nf_term(&self.tc_env, term).map_err(|e| vec![e.to_diagnostic()])
}

pub fn resugar<T>(&self, src: &impl Resugar<T>) -> T {
Expand All @@ -266,19 +254,24 @@ mod tests {

use super::*;

#[test]
fn with_prelude() {
let _pikelet = Pikelet::with_prelude();
}

#[test]
fn prelude() {
let mut pikelet = Pikelet::new();
let writer = StandardStream::stdout(ColorChoice::Always);

let prim_path = "prim".to_owned();
let prim_name = FileName::virtual_("prim");
let prim_src = library::PRIM.to_owned();
let prim_src = pikelet_library::PRIM.to_owned();
let prim_file = pikelet.code_map.add_filemap(prim_name, prim_src);

let prelude_path = "prelude".to_owned();
let prelude_name = FileName::virtual_("prelude");
let prelude_src = library::PRELUDE.to_owned();
let prelude_src = pikelet_library::PRELUDE.to_owned();
let prelude_file = pikelet.code_map.add_filemap(prelude_name, prelude_src);

if let Err(diagnostics) = pikelet.load_file(prim_path, prim_file) {
Expand Down
20 changes: 20 additions & 0 deletions crates/pikelet-elaborate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "pikelet-elaborate"
version = "0.1.0"
license = "Apache-2.0"
readme = "../../README.md"
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>"]
homepage = "https://github.com/pikelet-lang/pikelet"
repository = "https://github.com/pikelet-lang/pikelet"
publish = false

[dependencies]
codespan = "0.2.0"
codespan-reporting = "0.2.0"
failure = "0.1.2"
im = "12.2.0"
moniker = { version = "0.5.0", features = ["codespan", "im"] }
pikelet-syntax = { version = "0.1.0", path = "../pikelet-syntax" }

[dev-dependencies]
goldenfile = "0.7.1"
10 changes: 5 additions & 5 deletions src/semantics/env.rs → crates/pikelet-elaborate/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use moniker::{Binder, FreeVar, Var};
use std::fmt;
use std::rc::Rc;

use syntax::core::{Literal, RcTerm, RcType, RcValue, Value};
use syntax::translation::{Resugar, ResugarEnv};
use syntax::{FloatFormat, IntFormat};
use pikelet_syntax::core::{Literal, RcTerm, RcType, RcValue, Value};
use pikelet_syntax::translation::{Resugar, ResugarEnv};
use pikelet_syntax::{FloatFormat, IntFormat};

// Some helper traits for marshalling between Rust and Pikelet values
//
Expand Down Expand Up @@ -253,7 +253,7 @@ impl Default for TcEnv {
fn default() -> TcEnv {
use moniker::{Embed, Scope};

use syntax::core::Term;
use pikelet_syntax::core::Term;

let var_bool = FreeVar::fresh_named("Bool");
let var_true = FreeVar::fresh_named("true");
Expand Down Expand Up @@ -558,7 +558,7 @@ impl TcEnv {
}

pub fn array<'a>(&self, ty: &'a RcType) -> Option<(u64, &'a RcType)> {
use syntax::LevelShift;
use pikelet_syntax::LevelShift;

match ty.free_var_app() {
// Conservatively forcing the shift to be zero for now. Perhaps this
Expand Down
Loading

0 comments on commit 0b8383c

Please sign in to comment.