Rename the language to Drim

This commit is contained in:
Alex Bethel 2022-08-10 23:05:07 -05:00
parent 6669460326
commit f870bbe3c7
18 changed files with 118 additions and 117 deletions

View file

@ -7,24 +7,20 @@ is formatted correctly! ~~abb
-->
# AlexScript
# Drim
AlexScript is a programming language designed to have the very
high-level ergonomics and provable correctness of a purely functional
language, while maintaining speed using strictly-controlled,
deterministic memory management. The language is capable of compiling
to C (and possibly other languages in the future), allowing for
maximum portability without having to write a new backend for the
compiler for every possible target; also, the compiler and tooling
will eventually be rewritten in AlexScript to allow for maximum
portability.
Drim is a programming language designed to have the very high-level
ergonomics and provable correctness of a purely functional language,
while maintaining speed using strictly-controlled, deterministic
memory management. The language is capable of compiling to C (and
possibly other languages in the future), allowing for maximum
portability without having to write a new backend for the compiler for
every possible target; also, the compiler and tooling will eventually
be rewritten in Drim to allow for maximum portability.
Syntactically, the language primarily resembles a mixture between
standard ML and Rust; the language always ignores whitespace.
AlexScript is a misnomer; the language is not actually a scripting
language and will probably be renamed in the near future.
## Example
```
@ -55,33 +51,32 @@ Note that type annotations are always optional; here they're given for
## Tools
This repository contains the following tools:
- `axc-rs`, the Stage-1 AlexScript compiler, written in Rust. This can
be used as a binary with a fairly standard compiler CLI, or as a
- `drimc-rs`, the Stage-1 Drim compiler, written in Rust. This can be
used as a binary with a fairly standard compiler CLI, or as a
library for use in other Rust programs.
The following tools do not exist yet, but are planned:
- `axc`, the main AlexScript compiler written in AlexScript. This
program supports a superset of the behavior of `axc-rs`, and exposes
a library that can be used by other AlexScript programs in addition
to a the compiler CLI.
- `axci`, the interactive AlexScript interpreter, a wrapper around
`axc`.
- `axcd`, the Language Server Protocol (LSP) server for AlexScript
code support in editors, supporting definition peeking and lookup,
- `drimc`, the main Drim compiler written in Drim. This program
supports a superset of the behavior of `drimc-rs`, and exposes a
library that can be used by other Drim programs in addition to a the
compiler CLI.
- `drim`, the interactive Drim interpreter, a wrapper around `drimc`.
- `drimd`, the Language Server Protocol (LSP) server for Drim code
support in editors, supporting definition peeking and lookup,
renaming variables and modules, etc.
- `axfmt`, the standard formatter for AlexScript code; all AlexScript
code used in this repository must be formatted with `axfmt`, and its
use is recommended for other projects.
- `axdoc`, the documentation generator.
- `alexscript-mode`, an Emacs mode for editing AlexScript code,
supporting syntax highlighting, automatic indentation, some basic
keybindings for common tasks, Emacs-side LSP integration for
communicating with `acxd`, and a collection of `yasnippet` snippets
for inserting common AlexScript constructs.
- `alexscript-vsc`, Visual Studio Code plugins and tools for editing
- `drimfmt`, the standard formatter for Drim code; all Drim code used
in this repository must be formatted with `drimfmt`, and its use is
recommended for other projects.
- `drimdoc`, the documentation generator.
- `drim-mode`, an Emacs mode for editing Drim code, supporting syntax
highlighting, automatic indentation, some basic keybindings for
common tasks, Emacs-side LSP integration for communicating with
`drimd`, and a collection of `yasnippet` snippets for inserting
common Drim constructs.
- `drim-vsc`, Visual Studio Code plugins and tools for editing
AlexScript code.
- `alexscript-vim`, tools and configuration files for optimizing Vim
and Neovim for editing AlexScript code.
- `drim-vim`, tools and configuration files for optimizing Vim
and Neovim for editing Drim code.
## Language features
@ -130,7 +125,7 @@ Some features the language will most likely have:
## Compilation
When invoked with no flags, AlexScript by default compiles source code
When invoked with no flags, Drim by default compiles source code
directly to code that is valid C and C++, then calls the system C
compiler to generate an object file, then calls the system linker to
generate an executable file.

View file

@ -1,49 +0,0 @@
// AlexScript test
extern def core::intrinsic::negate_u32 : U32 -> U32;
extern def core::intrinsic::pow_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::mul_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::div_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::mod_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::plus_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::minus_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::equal_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::notEqual_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::lessThan_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::lessThanEq_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::greaterThan_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::greaterThanEq_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::and_u32 : U32 -> U32 -> U32;
extern def core::intrinsic::or_u32 : U32 -> U32 -> U32;
extern data U32;
class Group n {
def plus : n -> n -> n;
def zero : n;
def negate : n -> n;
}
class Group n => Ring n {
def mul : n -> n -> n;
def one : n;
}
instance Group U32 {
def plus = core::intrinsic::plus_u32;
def zero = 0;
def negate = core::intrinsic::negate_u32;
}
instance Ring U32 {
def mul = core::intrinsics::mul_u32;
def one = 1;
}
extern def print_u32 : U32 -> ();
// Impurity expliot to chain together actions.
def progn (l: ()) (r: ()) : () = ();
def main : () =
print_u32 (2 + 2);

View file

@ -1,12 +0,0 @@
//! AlexScript compiler.
//!
//! AlexScript is a based programming language, for based people.
#![deny(missing_docs)]
pub mod ast2ir;
pub mod backends;
pub mod ir;
pub mod parser;
pub mod syntax;
pub mod typeck;

View file

@ -28,15 +28,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axc"
version = "0.1.0"
dependencies = [
"chumsky",
"clap",
"num-bigint",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -125,6 +116,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "drimc_rs"
version = "0.1.0"
dependencies = [
"chumsky",
"clap",
"num-bigint",
]
[[package]]
name = "getrandom"
version = "0.2.7"

View file

@ -1,5 +1,5 @@
[package]
name = "axc"
name = "drimc_rs"
version = "0.1.0"
edition = "2021"

51
drimc_rs/foo.drim Normal file
View file

@ -0,0 +1,51 @@
// AlexScript test
def extern core::intrinsic::negate_u32 : U32 -> U32;
def extern core::intrinsic::pow_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::mul_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::div_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::mod_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::plus_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::minus_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::equal_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::notEqual_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::lessThan_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::lessThanEq_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::greaterThan_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::greaterThanEq_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::and_u32 : U32 -> U32 -> U32;
def extern core::intrinsic::or_u32 : U32 -> U32 -> U32;
data extern U32;
class Group n {
def plus : n -> n -> n;
def zero : n;
def negate : n -> n;
}
class Group n => Ring n {
def mul : n -> n -> n;
def one : n;
}
instance Group U32 {
def plus = core::intrinsic::plus_u32;
def zero = 0;
def negate = core::intrinsic::negate_u32;
}
instance Ring U32 {
def mul = core::intrinsics::mul_u32;
def one = 1;
}
def extern print_u32 : U32 -> ();
// Impurity expliot to chain together actions.
def progn (l: ()) (r: ()) : () = ();
def main : () =
progn (print_u32 (2 + 2))
(progn (print_u32 (3 * 3))
(progn (print_u32 (4 ^ 4))));

13
drimc_rs/src/lib.rs Normal file
View file

@ -0,0 +1,13 @@
//! Drim compiler.
//!
//! Drim is a modern, purely-functional programming language with a powerful linear type system and
//! an emphasis on performance.
#![deny(missing_docs)]
pub mod ast2ir;
pub mod backends;
pub mod ir;
pub mod parser;
pub mod syntax;
pub mod typeck;

View file

@ -1,8 +1,8 @@
//! AlexScript CLI.
//! Drim compiler CLI.
use std::{error::Error, fmt::Display, fs::File, io::Write, process::exit, str::FromStr};
use axc::{
use drimc_rs::{
ast2ir::ast2ir,
backends,
parser::{parser, ParserError, ParserMeta},
@ -225,7 +225,7 @@ impl FromStr for Target {
}
}
/// The AlexScript compiler.
/// The Drim compiler.
#[derive(Parser, Debug)]
#[clap(version = "0.1.0")]
struct Args {
@ -286,7 +286,7 @@ fn main() {
match main_e() {
Ok(()) => (),
Err(e) => {
eprintln!("axc fatal error: {}", e);
eprintln!("drimc-rs fatal error: {}", e);
exit(1);
}
}

View file

@ -1,4 +1,4 @@
//! AlexScript parser.
//! Drim parser.
use std::{error::Error, fmt::Display};
@ -28,7 +28,7 @@ impl Display for ParserError {
impl Error for ParserError {}
/// Information required to be able to parse AlexScript code, beyond the code itself.
/// Information required to be able to parse Drim code, beyond the code itself.
pub struct ParserMeta {
// This struct is just a total hacky workaround for the fact that chumsky isn't capable of
// parsing a context-sensitive grammar. I don't intend on ever fixing this: the stage-1 compiler
@ -233,7 +233,7 @@ impl Default for ParserMeta {
}
}
/// The list of reserved words that cannot be used as identifiers in AlexScript.
/// The list of reserved words that cannot be used as identifiers in Drim.
#[rustfmt::skip] // keep this on separate lines for sorting
pub const RESERVED: &[&str] = &[
"_",
@ -248,7 +248,7 @@ pub const RESERVED: &[&str] = &[
"type",
];
/// Parser for AlexScript code.
/// Parser for Drim code.
pub fn parser<'a>(m: &'a ParserMeta) -> impl Parser<char, SyntaxTree, Error = Simple<char>> + 'a {
whitespace_cmt().ignore_then(
parse_statement(m)

View file

@ -1,8 +1,8 @@
//! Syntax tree for AlexScript code.
//! Syntax tree for Drim code.
use num_bigint::BigUint;
/// A concrete syntax tree. This represents the full content of an AlexScript program, including all
/// A concrete syntax tree. This represents the full content of a Drim program, including all
/// whitespace, comments, and tokens: the source code of the original program can be recovered
/// completely using the syntax tree.
#[derive(Clone, Debug)]

3
drimc_rs/stdlib/std.axs Normal file
View file

@ -0,0 +1,3 @@
// Drim standard library.
// Copyright (C) 2022 by Alexander Bethel.