Rename the language to Drim

main
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 Drim is a programming language designed to have the very high-level
high-level ergonomics and provable correctness of a purely functional ergonomics and provable correctness of a purely functional language,
language, while maintaining speed using strictly-controlled, while maintaining speed using strictly-controlled, deterministic
deterministic memory management. The language is capable of compiling memory management. The language is capable of compiling to C (and
to C (and possibly other languages in the future), allowing for possibly other languages in the future), allowing for maximum
maximum portability without having to write a new backend for the portability without having to write a new backend for the compiler for
compiler for every possible target; also, the compiler and tooling every possible target; also, the compiler and tooling will eventually
will eventually be rewritten in AlexScript to allow for maximum be rewritten in Drim to allow for maximum portability.
portability.
Syntactically, the language primarily resembles a mixture between Syntactically, the language primarily resembles a mixture between
standard ML and Rust; the language always ignores whitespace. 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 ## Example
``` ```
@ -55,33 +51,32 @@ Note that type annotations are always optional; here they're given for
## Tools ## Tools
This repository contains the following tools: This repository contains the following tools:
- `axc-rs`, the Stage-1 AlexScript compiler, written in Rust. This can - `drimc-rs`, the Stage-1 Drim compiler, written in Rust. This can be
be used as a binary with a fairly standard compiler CLI, or as a used as a binary with a fairly standard compiler CLI, or as a
library for use in other Rust programs. library for use in other Rust programs.
The following tools do not exist yet, but are planned: The following tools do not exist yet, but are planned:
- `axc`, the main AlexScript compiler written in AlexScript. This - `drimc`, the main Drim compiler written in Drim. This program
program supports a superset of the behavior of `axc-rs`, and exposes supports a superset of the behavior of `drimc-rs`, and exposes a
a library that can be used by other AlexScript programs in addition library that can be used by other Drim programs in addition to a the
to a the compiler CLI. compiler CLI.
- `axci`, the interactive AlexScript interpreter, a wrapper around - `drim`, the interactive Drim interpreter, a wrapper around `drimc`.
`axc`. - `drimd`, the Language Server Protocol (LSP) server for Drim code
- `axcd`, the Language Server Protocol (LSP) server for AlexScript support in editors, supporting definition peeking and lookup,
code support in editors, supporting definition peeking and lookup,
renaming variables and modules, etc. renaming variables and modules, etc.
- `axfmt`, the standard formatter for AlexScript code; all AlexScript - `drimfmt`, the standard formatter for Drim code; all Drim code used
code used in this repository must be formatted with `axfmt`, and its in this repository must be formatted with `drimfmt`, and its use is
use is recommended for other projects. recommended for other projects.
- `axdoc`, the documentation generator. - `drimdoc`, the documentation generator.
- `alexscript-mode`, an Emacs mode for editing AlexScript code, - `drim-mode`, an Emacs mode for editing Drim code, supporting syntax
supporting syntax highlighting, automatic indentation, some basic highlighting, automatic indentation, some basic keybindings for
keybindings for common tasks, Emacs-side LSP integration for common tasks, Emacs-side LSP integration for communicating with
communicating with `acxd`, and a collection of `yasnippet` snippets `drimd`, and a collection of `yasnippet` snippets for inserting
for inserting common AlexScript constructs. common Drim constructs.
- `alexscript-vsc`, Visual Studio Code plugins and tools for editing - `drim-vsc`, Visual Studio Code plugins and tools for editing
AlexScript code. AlexScript code.
- `alexscript-vim`, tools and configuration files for optimizing Vim - `drim-vim`, tools and configuration files for optimizing Vim
and Neovim for editing AlexScript code. and Neovim for editing Drim code.
## Language features ## Language features
@ -130,7 +125,7 @@ Some features the language will most likely have:
## Compilation ## 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 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 compiler to generate an object file, then calls the system linker to
generate an executable file. 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axc"
version = "0.1.0"
dependencies = [
"chumsky",
"clap",
"num-bigint",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -125,6 +116,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "drimc_rs"
version = "0.1.0"
dependencies = [
"chumsky",
"clap",
"num-bigint",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.7" version = "0.2.7"

View File

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

View File

@ -1,4 +1,4 @@
//! AlexScript parser. //! Drim parser.
use std::{error::Error, fmt::Display}; use std::{error::Error, fmt::Display};
@ -28,7 +28,7 @@ impl Display for ParserError {
impl Error 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 { pub struct ParserMeta {
// This struct is just a total hacky workaround for the fact that chumsky isn't capable of // 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 // 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 #[rustfmt::skip] // keep this on separate lines for sorting
pub const RESERVED: &[&str] = &[ pub const RESERVED: &[&str] = &[
"_", "_",
@ -248,7 +248,7 @@ pub const RESERVED: &[&str] = &[
"type", "type",
]; ];
/// Parser for AlexScript code. /// Parser for Drim code.
pub fn parser<'a>(m: &'a ParserMeta) -> impl Parser<char, SyntaxTree, Error = Simple<char>> + 'a { pub fn parser<'a>(m: &'a ParserMeta) -> impl Parser<char, SyntaxTree, Error = Simple<char>> + 'a {
whitespace_cmt().ignore_then( whitespace_cmt().ignore_then(
parse_statement(m) parse_statement(m)

View File

@ -1,8 +1,8 @@
//! Syntax tree for AlexScript code. //! Syntax tree for Drim code.
use num_bigint::BigUint; 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 /// whitespace, comments, and tokens: the source code of the original program can be recovered
/// completely using the syntax tree. /// completely using the syntax tree.
#[derive(Clone, Debug)] #[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.