schala/README.md

111 lines
4.1 KiB
Markdown
Raw Permalink Normal View History

2017-08-29 00:28:19 -07:00
# Schala - a programming language meta-interpreter
2017-04-10 00:56:55 -07:00
2018-11-09 01:51:25 -08:00
Schala is a Rust framework written to make it easy to create and experiment
2021-10-20 18:43:41 -07:00
with multiple toy programming languages. It provides a cross-language REPL and
2018-11-09 01:51:25 -08:00
provisions for tokenizing text, parsing tokens, evaluating an abstract syntax
2021-10-20 18:43:41 -07:00
tree, and other tasks that are common to all programming languages, as well as
sharing state between multiple programming languages.
2018-11-09 01:51:25 -08:00
2021-10-20 18:43:41 -07:00
Schala is implemented as a Rust library `schala-repl`, which provides a `Repl`
data structure that takes in a value implementing the
`ProgrammingLanguageInterface` trait. Individual programming language
implementations are Rust types that implement `ProgrammingLanguageInterface`
and store whatever persistent state is relevant to that language.
2017-04-10 00:56:55 -07:00
2021-10-20 18:43:41 -07:00
## Running
Run schala with the normal `cargo run`. This will drop you into a REPL
environment. Type `:help` for more information, or type in text in any
supported programming language (currently only `schala-lang`) to evaluate it in
the REPL.
2017-12-13 00:52:54 -08:00
2024-08-05 01:15:49 -07:00
### Examples
Try running the following `schala-lang` code example in the REPL:
```
>> 1 + 1
(Total time)=> 736.368µs
=> 2
>> fn foo(x) { x + 10 }
(Total time)=> 772.496µs
=>
>> foo(0)
(Total time)=> 593.591µs
=> 10
>> 5 + foo(1)
(Total time)=> 1.119916ms
=> 16
>>
```
2018-11-09 01:51:25 -08:00
## History
2017-12-13 00:52:54 -08:00
2017-04-10 00:56:55 -07:00
Schala started out life as an experiment in writing a Javascript-like
2017-08-29 00:28:19 -07:00
programming language that would never encounter any kind of runtime value
error, but rather always return `null` under any kind of error condition. I had
seen one too many Javascript `Uncaught TypeError: Cannot read property ___ of
undefined` messages, and I was a bit frustrated. Plus I had always wanted to
write a programming langauge from scratch, and Rust is a fun language to
program in. Over time I became interested in playing around with other sorts
of programming languages as well, and wanted to make the process as general as
possible.
The name of the project comes from Schala the Princess of Zeal from the 1995
SNES RPG *Chrono Trigger*. I like classic JRPGs and enjoyed the thought of
creating a language name confusingly close to Scala. The naming scheme for
languages implemented with the Schala meta-interpreter is Chrono Trigger
characters.
2019-03-20 01:09:38 -07:00
Schala and languages implemented with it are incomplete alpha software and are
not ready for public release.
2017-12-13 00:52:54 -08:00
2017-08-29 00:28:19 -07:00
## Languages implemented using the meta-interpreter
2019-03-20 01:09:38 -07:00
* The eponymous *Schala* language is a work-in-progress general purpose
programming language with static typing and algebraic data types. Its design
goals include having a very straightforward implemenation and being syntactically
minimal.
2017-04-10 00:56:55 -07:00
2019-03-20 01:09:38 -07:00
* *Maaru* is a very simple dynamically-typed scripting language, with the semantics
that all runtime errors return a `null` value rather than fail.
2017-04-10 00:59:38 -07:00
2017-08-29 00:28:19 -07:00
* *Robo* is an experiment in creating a lazy, functional, strongly-typed language
much like Haskell
2017-04-10 00:56:55 -07:00
2017-12-13 00:25:59 -08:00
* *Rukka* is a straightforward LISP implementation
2017-08-29 00:28:19 -07:00
## Reference works
2017-04-10 00:56:55 -07:00
Here's a partial list of resources I've made use of in the process
of learning how to write a programming language.
2019-06-16 00:22:18 -07:00
### General
2021-10-20 18:43:41 -07:00
* http://thume.ca/2019/04/18/writing-a-compiler-in-rust/
2019-06-16 00:22:18 -07:00
2017-10-03 21:28:17 -07:00
### Type-checking
2021-10-20 18:43:41 -07:00
* https://skillsmatter.com/skillscasts/10868-inside-the-rust-compiler
* https://www.youtube.com/watch?v=il3gD7XMdmA
* http://dev.stephendiehl.com/fun/006_hindley_milner.html
* https://rust-lang-nursery.github.io/rustc-guide/type-inference.html
* https://eli.thegreenplace.net/2018/unification/
* https://eli.thegreenplace.net/2018/type-inference/
* http://smallcultfollowing.com/babysteps/blog/2017/03/25/unification-in-chalk-part-1/
* http://reasonableapproximation.net/2019/05/05/hindley-milner.html
https://rickyhan.com/jekyll/update/2018/05/26/hindley-milner-tutorial-rust.html
2019-02-18 23:49:34 -08:00
2017-08-29 00:28:19 -07:00
### Evaluation
2017-10-03 21:28:17 -07:00
2021-10-20 18:43:41 -07:00
* _Understanding Computation_, Tom Stuart, O'Reilly 2013
* _Basics of Compiler Design_, Torben Mogensen
2017-04-10 00:56:55 -07:00
2017-08-29 00:28:19 -07:00
### Parsing
2021-10-20 18:43:41 -07:00
* http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
* https://soc.github.io/languages/unified-condition-syntax
* [Crafting Interpreters](http://www.craftinginterpreters.com/)
2017-04-10 00:56:55 -07:00
2017-08-29 00:28:19 -07:00
### LLVM
2021-10-20 18:43:41 -07:00
* http://blog.ulysse.io/2016/07/03/llvm-getting-started.html