├── examples ├── input.etrl ├── math.etrl └── array.etrl ├── makefile ├── .gitignore ├── .github └── workflows │ ├── build.yml │ ├── lint.yml │ └── devskim.yml ├── Cargo.toml ├── src ├── bin │ └── main.rs ├── evaluation │ ├── globals.rs │ ├── store.rs │ ├── library.rs │ ├── object.rs │ └── mod.rs ├── lib.rs ├── std_library │ ├── mod.rs │ ├── util.rs │ ├── string.rs │ ├── hash.rs │ ├── http.rs │ ├── fs.rs │ ├── json.rs │ ├── array.rs │ └── math.rs ├── repl.rs ├── ast │ ├── token.rs │ └── mod.rs ├── wasm │ └── main.rs ├── lexer.rs └── parser.rs ├── README.md ├── LICENSE └── Cargo.lock /examples/input.etrl: -------------------------------------------------------------------------------- 1 | include "std:util"; 2 | 3 | set main = fun() { 4 | set name = input("What is your name? "); 5 | set age = input("How old are you? "); 6 | 7 | put("Hello, " + name + "! You are " + age + " years old."); 8 | }; 9 | 10 | main() -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | build: 2 | RUSTFLAGS="-C target-cpu=native" cargo build --release --bin ethereal 3 | 4 | build-wasm: 5 | cargo build --release --bin wasm --target wasm32-unknown-unknown 6 | 7 | build-linux: 8 | cargo build --release --target x86_64-unknown-linux-gnu 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # These are backup files generated by rustfmt 7 | **/*.rs.bk 8 | 9 | # MSVC Windows builds of rustc generate these, which store debugging information 10 | *.pdb 11 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Build 20 | run: cargo build --verbose --bin ethereal 21 | -------------------------------------------------------------------------------- /examples/math.etrl: -------------------------------------------------------------------------------- 1 | set add = fun (x, y) { 2 | return x + y; 3 | }; 4 | 5 | set mul = fun (x, y) { 6 | return x * y; 7 | }; 8 | 9 | set sub = fun (x, y) { 10 | return x - y; 11 | }; 12 | 13 | set div = fun (x, y) { 14 | return x / y; 15 | }; 16 | 17 | put({"x": 1, "y": 2 }) 18 | put("Addition: ", add(1, 2)) 19 | put("Multiplication: ", mul(1, 2)) 20 | put("Subtraction: ", sub(1, 2)) 21 | put("Division: ", div(1, 2)) 22 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | lint: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v1 14 | - run: rustup component add clippy 15 | - uses: actions-rs/clippy-check@v1 16 | with: 17 | token: ${{ secrets.GITHUB_TOKEN }} 18 | args: --all-features -------------------------------------------------------------------------------- /examples/array.etrl: -------------------------------------------------------------------------------- 1 | include "std:array"; 2 | 3 | set main = fun () { 4 | set arr = [1, 2, 3, 4, 5]; 5 | 6 | put("Initial array: ", arr) 7 | 8 | anew arr = push(arr, 6); 9 | 10 | put("After Push: ", arr) 11 | 12 | anew arr = pop(arr); 13 | 14 | put("After Pop: ", arr) 15 | 16 | anew arr = map(arr, fun (x) { 17 | return x * 2; 18 | }); 19 | 20 | put("After Map: ", arr) 21 | 22 | }; 23 | 24 | main() -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ethereal_lang" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | lazy_static = "1.4.0" 8 | wasm-bindgen = "0.2.79" 9 | vfs = "0.6.2" 10 | rusty_express = "0.4.3" 11 | rand = "0.8.5" 12 | reqwest = { version = "0.11.10", features = ["blocking", "json"] } 13 | serde_json = "1.0.79" 14 | rust-crypto = "0.2.36" 15 | 16 | [lib] 17 | crate-type = ["cdylib", "rlib"] 18 | 19 | [[bin]] 20 | name = "ethereal" 21 | path = "src/bin/main.rs" 22 | 23 | [[bin]] 24 | name = "wasm" 25 | path = "src/wasm/main.rs" 26 | 27 | [profile.release] 28 | opt-level = 3 29 | lto = "fat" 30 | panic = "abort" 31 | codegen-units = 1 32 | -------------------------------------------------------------------------------- /src/bin/main.rs: -------------------------------------------------------------------------------- 1 | 2 | extern crate ethereal_lang; 3 | 4 | use std::env; 5 | use std::fs; 6 | use ethereal_lang::repl; 7 | fn main() { 8 | let args: Vec = env::args().collect(); 9 | if args.len() != 1 && args[1].as_str() == "run" { 10 | let filename = &args[2].split('.').collect::>(); 11 | if filename[filename.len() - 1] != "etrl" { 12 | println!("File must have the extention .etrl"); 13 | return; 14 | } 15 | let content = fs::read_to_string(&args[2]).expect("Could not read file."); 16 | 17 | ethereal_lang::interpret(content.as_str()); 18 | } else { 19 | 20 | println!( 21 | "Welcome to the Ethereal REPL. Type in commands to get started.", 22 | ); 23 | repl::start(); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/evaluation/globals.rs: -------------------------------------------------------------------------------- 1 | use super::object::*; 2 | use std::collections::HashMap; 3 | 4 | /// Adds the built-in functions to the global environment. 5 | /// This is called once at the start of the program. 6 | /// The global environment is a HashMap of names to objects. 7 | pub fn new_globals() -> HashMap { 8 | let mut globals = HashMap::new(); 9 | globals.insert(String::from("put"), Object::Inbuilt(log)); 10 | globals 11 | } 12 | 13 | /// The built-in function `log`. 14 | /// It takes an unlimited number of arguments, 15 | /// and logs them to the console. 16 | /// It returns `null`. 17 | fn log(args: Vec) -> Object { 18 | if args.is_empty() { 19 | return Object::Error(String::from("Wrong number of arguments")); 20 | } else { 21 | for arg in args { 22 | print!("{} ", arg); 23 | } 24 | println!(); 25 | } 26 | Object::Null 27 | } -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod ast; 2 | pub mod evaluation; 3 | pub mod lexer; 4 | pub mod parser; 5 | pub mod std_library; 6 | pub mod repl; 7 | use std::{rc::Rc, cell::RefCell}; 8 | 9 | use evaluation::{object::*, store::*, *}; 10 | use lexer::Lexer; 11 | use parser::Parser; 12 | 13 | pub fn interpret(content: &str) { 14 | let store = Store::new(); 15 | let mut evaluator = Eval { 16 | store: Rc::new(RefCell::new(store)), 17 | }; 18 | let lexer = Lexer::new(content.to_string()); 19 | let mut parser = Parser::new(lexer); 20 | let program = parser.parse_program(); 21 | if !parser.errors.is_empty() { 22 | for e in parser.errors.iter() { 23 | println!("\t{}", e); 24 | } 25 | return; 26 | } 27 | let res = evaluator.eval(program); 28 | 29 | if let Some(o) = res { 30 | match o { 31 | Object::Null => (), 32 | _ => println!("{}", o), 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /.github/workflows/devskim.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: DevSkim 7 | 8 | on: 9 | push: 10 | branches: [ main ] 11 | pull_request: 12 | branches: [ main ] 13 | schedule: 14 | - cron: '21 1 * * 5' 15 | 16 | jobs: 17 | lint: 18 | name: DevSkim 19 | runs-on: ubuntu-20.04 20 | permissions: 21 | actions: read 22 | contents: read 23 | security-events: write 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v2 27 | 28 | - name: Run DevSkim scanner 29 | uses: microsoft/DevSkim-Action@v1 30 | 31 | - name: Upload DevSkim scan results to GitHub Security tab 32 | uses: github/codeql-action/upload-sarif@v1 33 | with: 34 | sarif_file: devskim-results.sarif 35 | -------------------------------------------------------------------------------- /src/std_library/mod.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use crate::evaluation::object::Object; 4 | pub mod util; 5 | pub mod array; 6 | pub mod fs; 7 | pub mod string; 8 | pub mod math; 9 | pub mod json; 10 | pub mod http; 11 | pub mod hash; 12 | /// Function to load a standard library 13 | /// # Arguments 14 | /// * `lib` - The name of the library to load. 15 | /// # Returns 16 | /// `HashMap` - The environment with the library loaded. 17 | 18 | pub struct Res { 19 | pub globals: HashMap, 20 | pub raw: Option, 21 | } 22 | pub fn get_std_lib(lib: String) -> Option { 23 | match lib.as_str() { 24 | "std:util" => Some(util::add_globals()), 25 | "std:array" => Some(array::add_globals()), 26 | "std:string" => Some(string::add_globals()), 27 | "std:fs" => Some(fs::add_globals()), 28 | "std:math" => Some(math::add_globals()), 29 | "std:json" => Some(json::add_globals()), 30 | "std:http" => Some(http::add_globals()), 31 | "std:hash" => Some(hash::add_globals()), 32 | _ => None, 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/repl.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | evaluation::{store::Store, object::Object, Eval}, 3 | lexer::Lexer, 4 | parser::Parser, 5 | }; 6 | use std::{ 7 | cell::RefCell, 8 | io::{stdin, stdout, Write}, 9 | rc::Rc, 10 | }; 11 | 12 | pub fn start() { 13 | let env = Store::new(); 14 | let mut evaluator = Eval { 15 | store: Rc::new(RefCell::new(env)), 16 | }; 17 | loop { 18 | print!(">> "); 19 | let _ = stdout().flush(); 20 | let mut input_string = String::new(); 21 | stdin().read_line(&mut input_string).ok(); 22 | 23 | if input_string.is_empty() { 24 | println!("Invalid input."); 25 | continue; 26 | } 27 | 28 | let lexer = Lexer::new(input_string); 29 | let mut parser = Parser::new(lexer); 30 | let program = parser.parse_program(); 31 | if !parser.errors.is_empty() { 32 | print_parse_errors(parser.errors); 33 | continue; 34 | } 35 | let res = evaluator.eval(program); 36 | println!("{}", res.unwrap_or(Object::Null)); 37 | } 38 | } 39 | 40 | fn print_parse_errors(errors: Vec) { 41 | for e in errors.iter() { 42 | println!("\t{}", e); 43 | } 44 | } -------------------------------------------------------------------------------- /src/ast/token.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::{self, Display, Formatter}; 2 | 3 | #[derive(Debug, Clone, PartialEq)] 4 | pub enum Token { 5 | Eof, 6 | Illegal, 7 | Comment, 8 | 9 | // Literals 10 | Ident(String), 11 | Number(f64), 12 | String(String), 13 | Boolean(bool), 14 | 15 | // Operators 16 | Assign, 17 | Plus, 18 | Minus, 19 | Bang, 20 | Asterisk, 21 | Slash, 22 | Percent, 23 | Anew, 24 | In, 25 | 26 | // Bitwise operators 27 | AND, 28 | OR, 29 | XOR, 30 | LeftShift, 31 | RightShift, 32 | 33 | // Comparison 34 | Less, 35 | Greater, 36 | LessEqual, 37 | GreaterEqual, 38 | Equals, 39 | NotEquals, 40 | 41 | // Delimiters 42 | Comma, 43 | Colon, 44 | Semicolon, 45 | LeftParen, 46 | RightParen, 47 | LeftBrace, 48 | RightBrace, 49 | LeftBracket, 50 | RightBracket, 51 | 52 | // Keywords 53 | Set, 54 | Func, 55 | If, 56 | Else, 57 | Return, 58 | Include, 59 | Typeof, 60 | Loop, 61 | Break, 62 | Continue 63 | 64 | } 65 | 66 | impl Display for Token { 67 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { 68 | write!(f, "{:?}", self) 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | # Ethereal 7 | 8 | Simple yet fast general-purpose programming language. 9 | 10 | ![Build](https://github.com/Synthesized-Infinity/Ethereal/actions/workflows/build.yml/badge.svg) 11 | ![Lint](https://github.com/Synthesized-Infinity/Ethereal/actions/workflows/lint.yml/badge.svg) 12 | ![Security](https://github.com/Synthesized-Infinity/Ethereal/actions/workflows/devskim.yml/badge.svg) 13 | 14 | 15 | [Documentation](https://ethereal-docs.vercel.app/) 16 | 17 | 18 | Ethereal is a general-purpose programming language that is designed to be fast and simple. Heavly inspired by [Monkey](https://monkeylang.org/) and written in [Rust](https://rust-lang.org/) 19 | 20 |
21 | 22 | ### Features 23 | 24 | - Includes a Standard Library 25 | - Comes with a REPL 26 | - Runs in the Browser with WASM (Experimental) 27 | 28 | 29 | Want to contribute? Read the steps below on how to run ethereal on your local machine. 30 | 31 | ### Prerequisites 32 | 33 | * [Rust](https://rust-lang.org/) 34 | 35 | ### Running Locally 36 | 37 | 1. Clone the Repository 38 | 39 | ```bash 40 | git clone https://github.com/Synthesized-Infinity/Ethereal 41 | cd Ethereal 42 | ``` 43 | 44 | 2. Build the binary 45 | 46 | ```bash 47 | cargo build --bin ethereal-bin 48 | ``` 49 | 50 | 3. Run the binary 51 | 52 | ```bash 53 | ./target/debug/ethereal-bin 54 | ``` 55 | 56 | 57 | ---- 58 | 59 | ### Community 60 | 61 | Discord: 62 | 63 | [![DISCORD](https://invidget.switchblade.xyz/FJuArcCfQv)](https://discord.gg/FJuArcCfQv) 64 | 65 | -------------------------------------------------------------------------------- /src/std_library/util.rs: -------------------------------------------------------------------------------- 1 | use std::{format, collections::HashMap}; 2 | use crate::evaluation::object::Object; 3 | 4 | use super::Res; 5 | 6 | pub fn add_globals() -> Res { 7 | let mut globals = HashMap::new(); 8 | globals.insert(String::from("length"), Object::Inbuilt(length)); 9 | globals.insert(String::from("input"), Object::Inbuilt(input)); 10 | globals.insert(String::from("sleep"), Object::Inbuilt(sleep)); 11 | Res { globals, raw: None } 12 | } 13 | 14 | /// Function to get the length of an array or string. 15 | /// # Arguments 16 | /// * `args` - The array or string to get the length of. 17 | /// # Returns 18 | /// `Object` - The length of the array or string. 19 | pub fn length(args: Vec) -> Object { 20 | if args.len() != 1 { 21 | return Object::Error(format!( 22 | "Wrong number of arguments. Got {}. Expected 1.", 23 | args.len() 24 | 25 | )); 26 | } 27 | match &args[0] { 28 | Object::String(s) => Object::Number(s.len() as f64), 29 | Object::Array(a) => Object::Number(a.len() as f64), 30 | o => Object::Error(format!("Argument must be a string or array. Got {}", o)), 31 | } 32 | } 33 | 34 | pub fn input(args: Vec) -> Object { 35 | println!("{}", &args[0]); 36 | if let Object::String(s) = &args[0] { 37 | print!("{}", s); 38 | } 39 | let mut input = String::new(); 40 | std::io::stdin().read_line(&mut input).expect("Failed to read line"); 41 | Object::String(input) 42 | } 43 | 44 | pub fn sleep(args: Vec) -> Object { 45 | if args.len() != 1 { 46 | return Object::Error(format!( 47 | "Wrong number of arguments. Got {}. Expected 1.", 48 | args.len() 49 | )); 50 | } 51 | if let Object::Number(n) = &args[0] { 52 | std::thread::sleep(std::time::Duration::from_millis(*n as u64)); 53 | } 54 | Object::Null 55 | } -------------------------------------------------------------------------------- /src/std_library/string.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use crate::evaluation::object::Object; 4 | 5 | use super::Res; 6 | 7 | /// Adds the standard library to the global environment. 8 | pub fn add_globals() -> Res { 9 | let mut globals = HashMap::new(); 10 | globals.insert(String::from("replace"), Object::Inbuilt(replace)); 11 | globals.insert(String::from("to_string"), Object::Inbuilt(to_string)); 12 | Res { 13 | globals, 14 | raw: None, 15 | } 16 | } 17 | 18 | pub fn replace(args: Vec) -> Object { 19 | if args.len() != 3 { 20 | return Object::Error(format!( 21 | "Wrong number of arguments. Got {}. Expected 3.", 22 | args.len() 23 | )); 24 | } 25 | 26 | match &args[0] { 27 | Object::String(s) => { 28 | let mut s = s.clone(); 29 | s = s.replace(&args[1].to_string(), &args[2].to_string()); 30 | Object::String(s) 31 | } 32 | o => Object::Error(format!("First argument must be a string. Got {}", o)), 33 | } 34 | } 35 | 36 | pub fn to_string(args: Vec) -> Object { 37 | if args.len() != 1 { 38 | return Object::Error(format!( 39 | "Wrong number of arguments. Got {}. Expected 1.", 40 | args.len() 41 | )); 42 | } 43 | 44 | match &args[0] { 45 | Object::String(s) => Object::String(s.clone()), 46 | Object::Array(a) => { 47 | let mut s = String::new(); 48 | for o in a.iter() { 49 | s.push_str(&o.to_string()); 50 | } 51 | Object::String(s) 52 | }, 53 | Object::Number(n) => Object::String(n.to_string()), 54 | Object::Bool(b) => Object::String(b.to_string()), 55 | Object::Null => Object::String(String::from("null")), 56 | Object::Error(e) => Object::String(e.clone()), 57 | Object::Fn(..) => Object::String(String::from("[Function]")), 58 | Object::Inbuilt(..) => Object::String(String::from("[Inbuilt Function]")), 59 | o => Object::String(format!("{}", o)) 60 | } 61 | } -------------------------------------------------------------------------------- /src/evaluation/store.rs: -------------------------------------------------------------------------------- 1 | use super::object::Object; 2 | use std::{cell::RefCell, collections::HashMap, rc::Rc}; 3 | 4 | #[derive(PartialEq, Clone, Debug)] 5 | pub struct Store { 6 | pub store: HashMap, 7 | pub outer: Option>>, 8 | } 9 | 10 | impl Store { 11 | pub fn new() -> Self { 12 | Self { 13 | store: HashMap::new(), 14 | outer: None, 15 | } 16 | } 17 | 18 | pub fn from(store: HashMap) -> Self { 19 | Self { store, outer: None } 20 | } 21 | 22 | pub fn new_enclosed(outer: Rc>) -> Self { 23 | Self { 24 | store: HashMap::new(), 25 | outer: Some(outer), 26 | } 27 | } 28 | 29 | pub fn get(&mut self, name: &str) -> Option { 30 | match self.store.get(name) { 31 | Some(e) => Some(e).cloned(), 32 | None => { 33 | if let Some(ref o) = self.outer { 34 | return o.borrow_mut().get(name); 35 | } else { 36 | None 37 | } 38 | } 39 | } 40 | } 41 | 42 | pub fn set(&mut self, name: String, val: Object) -> Option { 43 | self.store.insert(name, val) 44 | } 45 | 46 | pub fn anew(&mut self, name: String, val: Object) -> Option { 47 | match self.store.get(&name) { 48 | Some(_e) => self.store.insert(name, val), 49 | None => { 50 | if let Some(ref o) = self.outer { 51 | let mut outer = o.borrow_mut(); 52 | match outer.get(&name) { 53 | Some(_) => outer.anew(name, val), 54 | None => None, 55 | } 56 | } else { 57 | None 58 | } 59 | } 60 | } 61 | } 62 | 63 | pub fn iter (&self) -> std::collections::hash_map::Iter { 64 | self.store.iter() 65 | } 66 | } 67 | 68 | impl Default for Store { 69 | fn default() -> Self { 70 | Self::new() 71 | } 72 | } -------------------------------------------------------------------------------- /src/wasm/main.rs: -------------------------------------------------------------------------------- 1 | extern crate ethereal_lang; 2 | 3 | use ethereal_lang::ast::Program; 4 | use ethereal_lang::evaluation::globals::new_globals; 5 | use ethereal_lang::evaluation::store::Store; 6 | use ethereal_lang::evaluation::object::Object; 7 | use ethereal_lang::evaluation::Eval; 8 | use ethereal_lang::lexer::Lexer; 9 | use ethereal_lang::parser::Parser; 10 | use std::cell::RefCell; 11 | use std::ffi::{CStr, CString}; 12 | use std::mem; 13 | use std::os::raw::{c_char, c_void}; 14 | use std::rc::Rc; 15 | 16 | fn main() {} 17 | 18 | extern "C" { 19 | fn print(input_ptr: *mut c_char); 20 | } 21 | 22 | pub fn internal_print(msg: &str) { 23 | unsafe { 24 | print(string_to_ptr(msg.to_string())); 25 | } 26 | } 27 | 28 | fn string_to_ptr(s: String) -> *mut c_char { 29 | CString::new(s).unwrap().into_raw() 30 | } 31 | 32 | fn parse(input: &str) -> Result { 33 | let mut parser = Parser::new(Lexer::new(input.to_string())); 34 | let program = parser.parse_program(); 35 | let errors = parser.errors; 36 | 37 | if !errors.is_empty() { 38 | let msg = errors 39 | .into_iter() 40 | .map(|e| format!("{}\n", e)) 41 | .collect::(); 42 | 43 | return Err(msg); 44 | } 45 | 46 | Ok(program) 47 | } 48 | 49 | #[no_mangle] 50 | pub fn alloc(size: usize) -> *mut c_void { 51 | let mut buf = Vec::with_capacity(size); 52 | let ptr = buf.as_mut_ptr(); 53 | mem::forget(buf); 54 | ptr as *mut c_void 55 | } 56 | 57 | /// # Safety 58 | /// 59 | /// This is unsafe because it is the caller's responsibility to ensure that the 60 | /// pointer is valid for the duration of the call. 61 | #[no_mangle] 62 | pub unsafe fn dealloc(ptr: *mut c_void, size: usize) { 63 | let _buf = Vec::from_raw_parts(ptr, 0, size); 64 | } 65 | 66 | /// # Safety 67 | /// 68 | /// This function is unsafe because it is the caller's responsibility to ensure 69 | /// that the pointer is valid. 70 | #[no_mangle] 71 | pub unsafe fn eval(input_ptr: *mut c_char) -> *mut c_char { 72 | let input = CStr::from_ptr(input_ptr).to_string_lossy().into_owned(); 73 | let program = match parse(&input) { 74 | Ok(program) => program, 75 | Err(msg) => return string_to_ptr(msg), 76 | }; 77 | 78 | let env = Store::from(new_globals()); 79 | 80 | let mut evaluation = Eval::new(Rc::new(RefCell::new(env))); 81 | let evaluated = evaluation.eval(program).unwrap_or(Object::Null); 82 | let output = format!("{}", evaluated); 83 | 84 | string_to_ptr(output) 85 | } 86 | -------------------------------------------------------------------------------- /src/std_library/hash.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap}; 2 | use crypto::md5::Md5; 3 | use crypto::sha1::Sha1; 4 | use crypto::sha2; 5 | use crypto::sha3::Sha3; 6 | use crypto::whirlpool::Whirlpool; 7 | use crypto::digest::Digest; 8 | 9 | use crate::evaluation::object::Object; 10 | 11 | use super::Res; 12 | 13 | /// Adds the standard library to the global environment. 14 | pub fn add_globals() -> Res { 15 | let mut globals = HashMap::new(); 16 | globals.insert(String::from("hasher"), Object::Inbuilt(hasher)); 17 | Res { 18 | globals, 19 | raw: None, 20 | } 21 | } 22 | 23 | pub fn hasher(args: Vec) -> Object { 24 | 25 | if args.len() != 2 { 26 | return Object::Error(format!( 27 | "Wrong number of arguments. Got {}. Expected mode and string", 28 | args.len() 29 | )); 30 | } 31 | 32 | match &args[0] { 33 | Object::String(s) => { 34 | let algo: &str = &s; 35 | match algo { 36 | "md5" => { 37 | let mut hasher = Md5::new(); 38 | hasher.input_str(&args[1].to_string()); 39 | let result = hasher.result_str(); 40 | return Object::String(result); 41 | }, 42 | "sha1" => { 43 | let mut hasher = Sha1::new(); 44 | hasher.input_str(&args[1].to_string()); 45 | let result = hasher.result_str(); 46 | return Object::String(result); 47 | }, 48 | "sha256" => { 49 | let mut hasher = sha2::Sha256::new(); 50 | hasher.input_str(&args[1].to_string()); 51 | let result = hasher.result_str(); 52 | return Object::String(result); 53 | }, 54 | "sha512" => { 55 | let mut hasher = sha2::Sha512::new(); 56 | hasher.input_str(&args[1].to_string()); 57 | let result = hasher.result_str(); 58 | return Object::String(result); 59 | }, 60 | "sha3_256" => { 61 | let mut hasher = Sha3::sha3_256(); 62 | hasher.input_str(&args[1].to_string()); 63 | let result = hasher.result_str(); 64 | return Object::String(result); 65 | }, 66 | "sha3_512" => { 67 | let mut hasher = Sha3::sha3_512(); 68 | hasher.input_str(&args[1].to_string()); 69 | let result = hasher.result_str(); 70 | return Object::String(result); 71 | }, 72 | "whirlpool" => { 73 | let mut hasher = Whirlpool::new(); 74 | hasher.input_str(&args[1].to_string()); 75 | let result = hasher.result_str(); 76 | return Object::String(result); 77 | }, 78 | _ => Object::Error("Algorithm not supported".to_string()) 79 | } 80 | } 81 | o => Object::Error(format!("First argument must be a string. Got {}", o)), 82 | } 83 | } -------------------------------------------------------------------------------- /src/std_library/http.rs: -------------------------------------------------------------------------------- 1 | use std::{format, collections::HashMap, str::FromStr}; 2 | use reqwest::{header::{HeaderMap, self}}; 3 | 4 | use crate::evaluation::object::Object; 5 | 6 | use super::Res; 7 | 8 | pub fn add_globals() -> Res { 9 | let mut globals = HashMap::new(); 10 | globals.insert("request".to_string(), Object::Inbuilt(request)); 11 | Res { globals, raw: None } 12 | } 13 | 14 | pub fn request(args: Vec) -> Object { 15 | if args.len() < 2 || args.len() > 4 { 16 | return Object::Error(format!( 17 | "Wrong number of arguments. Got {}. Expected 2-4.", 18 | args.len() 19 | )); 20 | } 21 | let method = match &args[0] { 22 | Object::String(s) => s, 23 | o => return Object::Error(format!("First argument must be a string. Got {}", o)), 24 | }; 25 | let url = match &args[1] { 26 | Object::String(s) => s, 27 | o => return Object::Error(format!("Second argument must be a string. Got {}", o)), 28 | }; 29 | let headers = match args.get(2) { 30 | Some(Object::Object(h)) =>{ 31 | let mut headers = HeaderMap::new(); 32 | for (k, v) in h.iter() { 33 | match (k, v) { 34 | (Object::String(k), Object::String(v)) => { 35 | let key = header::HeaderName::from_str(k).unwrap(); 36 | headers.insert(key, v.clone().parse().unwrap()); 37 | }, 38 | _ => { 39 | return Object::Error(format!("Headers must be a map of strings. Got {}", args[2])); 40 | } 41 | } 42 | } 43 | headers 44 | }, 45 | Some(o) => return Object::Error(format!("Third argument must be an Object. Got {}", o)), 46 | None => HeaderMap::new(), 47 | }; 48 | 49 | let client = reqwest::blocking::Client::new(); 50 | 51 | let body: String = match &args[3] { 52 | Object::String(s) => s.clone(), 53 | o=> o.to_string(), 54 | }; 55 | 56 | let response = match method.as_str() { 57 | "GET" => client.get(url).headers(headers).send(), 58 | "POST" => client.post(url).headers(headers).body::(body).send(), 59 | "PUT" => client.put(url).headers(headers).body::(body).send(), 60 | "DELETE" => client.delete(url).headers(headers).send(), 61 | _ => return Object::Error(format!("Unsupported HTTP method {}", method)), 62 | }; 63 | 64 | match response { 65 | Ok(res) => { 66 | let mut headers = HashMap::new(); 67 | for (k, v) in res.headers().iter() { 68 | headers.insert(Object::String(k.as_str().to_string()), Object::String(v.to_str().unwrap().to_string())); 69 | } 70 | let status = res.status(); 71 | let body = res.text().unwrap(); 72 | let status_code = status.as_u16(); 73 | let status_text = status.canonical_reason().unwrap_or(""); 74 | let status_line = format!("{} {}", status_code, status_text); 75 | let mut result = HashMap::new(); 76 | result.insert(Object::String("status".to_string()), Object::String(status_line)); 77 | result.insert(Object::String("headers".to_string()), Object::Object(headers)); 78 | result.insert(Object::String("body".to_string()), Object::String(body.to_string())); 79 | Object::Object(result) 80 | }, 81 | Err(e) => Object::Error(format!("{}", e)), 82 | } 83 | 84 | 85 | } -------------------------------------------------------------------------------- /src/std_library/fs.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::fs::File; 3 | use std::io::prelude::*; 4 | use std::path::Path; 5 | 6 | use crate::evaluation::object::Object; 7 | 8 | use super::Res; 9 | 10 | pub fn add_globals() -> Res { 11 | let mut globals = HashMap::new(); 12 | globals.insert(String::from("readFile"), Object::Inbuilt(read_file)); 13 | globals.insert(String::from("writeFile"), Object::Inbuilt(write_file)); 14 | globals.insert(String::from("exists"), Object::Inbuilt(file_exists)); 15 | Res { 16 | globals, 17 | raw: None 18 | } 19 | 20 | } 21 | 22 | pub fn read_file(args: Vec) -> Object { 23 | if args.len() != 1 { 24 | return Object::Error(format!( 25 | "Wrong number of arguments. Got {}. Expected 1.", 26 | args.len() 27 | )); 28 | } 29 | 30 | match &args[0] { 31 | Object::String(s) => { 32 | let path = Path::new(s); 33 | let display = path.display(); 34 | let mut file = match File::open(&path) { 35 | Err(why) => { 36 | return Object::Error(format!("Couldn't open {}: {}", display, why)) 37 | } 38 | Ok(file) => file, 39 | }; 40 | let mut s = String::new(); 41 | match file.read_to_string(&mut s) { 42 | Err(why) => { 43 | return Object::Error(format!("Couldn't read {}: {}", display, why)) 44 | } 45 | Ok(_) => { 46 | Object::String(s) 47 | } 48 | } 49 | } 50 | _ => Object::Error(format!("Argument must be a string. Got {}", args[0])) 51 | } 52 | } 53 | 54 | pub fn write_file(args: Vec) -> Object { 55 | if args.len() != 2 { 56 | return Object::Error(format!( 57 | "Wrong number of arguments. Got {}. Expected 2.", 58 | args.len() 59 | )); 60 | } 61 | match &args[0] { 62 | Object::String(s) => { 63 | let path = Path::new(s); 64 | let display = path.display(); 65 | let mut file = match File::create(&path) { 66 | Err(why) => { 67 | return Object::Error(format!("Couldn't create {}: {}", display, why)) 68 | } 69 | Ok(file) => file, 70 | }; 71 | match file.write_all(args[1].to_string().as_bytes()) { 72 | Err(why) => { 73 | return Object::Error(format!("Couldn't write to {}: {}", display, why)) 74 | } 75 | Ok(_) => { 76 | Object::Null 77 | } 78 | } 79 | } 80 | _ => Object::Error(format!("Argument must be a string. Got {}", args[0])) 81 | } 82 | } 83 | 84 | pub fn file_exists(args: Vec) -> Object { 85 | if args.len() != 1 { 86 | return Object::Error(format!( 87 | "Wrong number of arguments. Got {}. Expected 1.", 88 | args.len() 89 | )); 90 | } 91 | match &args[0] { 92 | Object::String(s) => { 93 | let path = Path::new(s); 94 | if path.exists() { 95 | Object::Bool(true) 96 | } else { 97 | Object::Bool(false) 98 | } 99 | } 100 | _ => Object::Error(format!("Argument must be a string. Got {}", args[0])) 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /src/evaluation/library.rs: -------------------------------------------------------------------------------- 1 | use super::{store::Store, object::*, Eval}; 2 | use crate::{lexer::Lexer, parser::Parser, std_library::*}; 3 | use std::{cell::RefCell, collections::{HashMap}, fs, rc::Rc}; 4 | use std::io::Read; 5 | /// Function to load an external file or a standard library onto the environment.\ 6 | /// The file is loaded as a string, and the string is parsed into an AST. 7 | /// The AST is then evaluated. 8 | /// The result is then added to the environment. 9 | /// # Arguments 10 | /// * `lib` - The name of the library to load. 11 | /// # Returns 12 | /// `HashMap` - The environment with the library loaded. 13 | /// 14 | pub fn load_etrl(lib: String) -> Option> { 15 | 16 | // check if lib is a url 17 | if lib.starts_with("http") || lib.starts_with("https") { 18 | // fetch the url resource 19 | let mut response = reqwest::blocking::get(lib).unwrap(); 20 | // read the response 21 | let mut contents = String::new(); 22 | response.read_to_string(&mut contents).unwrap(); 23 | // parse the contents 24 | let mut parser = Parser::new(Lexer::new(contents.to_string())); 25 | let program = parser.parse_program(); 26 | let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 27 | // Evaluates the program. 28 | eval.eval(program); 29 | let store = (&*eval.store.borrow()).to_owned().store; 30 | let mut final_env = HashMap::new(); 31 | // Returns the environment with the library loaded. 32 | for (k, v) in store.iter() { 33 | final_env.insert(k.clone(), v.clone()); 34 | } 35 | return Some(final_env); 36 | } 37 | // Checks if the library is a standard library. 38 | if lib.starts_with("std:") { 39 | // Loads the standard library. 40 | // The standard library is a HashMap of names to objects. 41 | let libs = get_std_lib(lib).unwrap(); 42 | let mut eval = Eval::new(Rc::new(RefCell::new( 43 | Store::from(libs.globals.clone()) 44 | ))); 45 | 46 | match &libs.raw { 47 | Some(s) => { 48 | let mut parser = Parser::new(Lexer::new(s.to_string())); 49 | let program = parser.parse_program(); 50 | eval.eval(program); 51 | let store = (&*eval.store.borrow()).to_owned().store; 52 | let mut final_env = HashMap::new(); 53 | for (k, v) in libs.globals.iter() { 54 | final_env.insert(k.to_string(), v.to_owned()); 55 | } 56 | for (k, v) in store.iter() { 57 | final_env.insert(k.clone(), v.clone()); 58 | } 59 | return Some(final_env) 60 | }, 61 | None => return Some(libs.globals), 62 | } 63 | } 64 | let filename =format!("./{}.etrl", lib); 65 | // File is read as a string. 66 | let file = fs::read_to_string(filename).expect("Lib not found."); 67 | let mut parser = Parser::new(Lexer::new(file)); 68 | let program = parser.parse_program(); 69 | if !parser.errors.is_empty() { 70 | for e in parser.errors.iter() { 71 | println!("\t{}", e); 72 | } 73 | return None; 74 | }; 75 | let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 76 | // Evaluates the program. 77 | eval.eval(program); 78 | let store = (&*eval.store.borrow()).to_owned().store; 79 | let mut final_env = HashMap::new(); 80 | // Returns the environment with the library loaded. 81 | for (k, v) in store.iter() { 82 | final_env.insert(k.clone(), v.clone()); 83 | } 84 | Some(final_env) 85 | } -------------------------------------------------------------------------------- /src/ast/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod token; 2 | use std::fmt::{self, Display, Formatter}; 3 | 4 | #[derive(PartialEq, Clone, Debug)] 5 | pub struct Ident(pub String); 6 | 7 | #[derive(PartialEq, Clone, Debug)] 8 | pub enum Prefix { 9 | Plus, 10 | Minus, 11 | Exclamation 12 | } 13 | 14 | #[derive(PartialEq, Clone, Debug)] 15 | pub enum Infix { 16 | In, 17 | Plus, 18 | Minus, 19 | Times, 20 | Divide, 21 | Modulo, 22 | Equals, 23 | NotEquals, 24 | LessThan, 25 | GreaterThan, 26 | LessThanEqual, 27 | GreaterThanEqual, 28 | LeftShift, 29 | RightShift, 30 | AND, 31 | OR, 32 | XOR, 33 | } 34 | 35 | #[derive(PartialEq, Clone, Debug)] 36 | pub enum Literal { 37 | Number(f64), 38 | String(String), 39 | Boolean(bool), 40 | Array(Vec), 41 | Object(Vec<(Expr, Expr)>) 42 | } 43 | 44 | #[derive(PartialEq, Clone, Debug)] 45 | pub enum Statement { 46 | Set(Ident, Expr), 47 | Return(Expr), 48 | Expression(Expr), 49 | Include(String), 50 | Anew(Ident, Expr), 51 | Break, 52 | Continue 53 | } 54 | 55 | #[derive(PartialEq, PartialOrd, Debug, Clone)] 56 | pub enum Precedence { 57 | Lowest, 58 | Equals, 59 | LessGreater, 60 | Sum, 61 | Product, 62 | Prefix, 63 | Call, 64 | Index, 65 | In, 66 | LeftShift, 67 | RightShift, 68 | AND, 69 | OR, 70 | XOR 71 | } 72 | 73 | pub type BlockStatement = Vec; 74 | 75 | #[derive(PartialEq, Clone, Debug)] 76 | pub enum Expr { 77 | Literal(Literal), 78 | Ident(Ident), 79 | Prefix(Prefix, Box), 80 | Infix(Infix, Box, Box), 81 | If { 82 | cond: Box, 83 | then: Box, 84 | else_: Option 85 | }, 86 | 87 | Fun { 88 | params: Vec, 89 | body: BlockStatement 90 | }, 91 | 92 | Call { 93 | function: Box, 94 | args: Vec 95 | }, 96 | 97 | Index { 98 | array: Box, 99 | index: Box 100 | }, 101 | 102 | Typeof { 103 | expr: Box 104 | }, 105 | 106 | Loop { 107 | body: BlockStatement 108 | } 109 | 110 | } 111 | 112 | #[derive(PartialEq, Clone, Debug)] 113 | pub struct Program { 114 | pub(crate) statements: Vec 115 | } 116 | 117 | // Implement the Display trait for all the types we have 118 | 119 | impl Display for Prefix { 120 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { 121 | match *self { 122 | Prefix::Plus => write!(f, "+"), 123 | Prefix::Minus => write!(f, "-"), 124 | Prefix::Exclamation => write!(f, "!"), 125 | } 126 | } 127 | } 128 | 129 | impl Display for Infix { 130 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { 131 | match *self { 132 | Infix::In => write!(f, "~"), 133 | Infix::Plus => write!(f, "+"), 134 | Infix::Minus => write!(f, "-"), 135 | Infix::Times => write!(f, "*"), 136 | Infix::Divide => write!(f, "/"), 137 | Infix::Modulo => write!(f, "%"), 138 | Infix::Equals => write!(f, "=="), 139 | Infix::NotEquals => write!(f, "!="), 140 | Infix::LessThan => write!(f, "<"), 141 | Infix::GreaterThan => write!(f, ">"), 142 | Infix::LessThanEqual => write!(f, "<="), 143 | Infix::GreaterThanEqual => write!(f, ">="), 144 | Infix::LeftShift => write!(f, "<<"), 145 | Infix::RightShift => write!(f, ">>"), 146 | Infix::AND => write!(f, "&"), 147 | Infix::OR => write!(f, "|"), 148 | Infix::XOR => write!(f, "^") 149 | } 150 | } 151 | } 152 | 153 | impl Display for Expr { 154 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { 155 | write!(f, "{:?}", self) 156 | } 157 | } -------------------------------------------------------------------------------- /src/std_library/json.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap}; 2 | 3 | use serde_json::Value; 4 | 5 | use crate::evaluation::object::Object; 6 | 7 | use super::Res; 8 | 9 | /// Adds the standard library to the global environment. 10 | pub fn add_globals() -> Res { 11 | let mut globals = HashMap::new(); 12 | globals.insert(String::from("parse_json"), Object::Inbuilt(parse_json)); 13 | Res { 14 | globals, 15 | raw:None 16 | } 17 | } 18 | 19 | pub fn parse_json(args: Vec) -> Object { 20 | match &args[0] { 21 | Object::String(s) => { 22 | let json_str = s.as_str(); 23 | let json: Result = serde_json::from_str(json_str); 24 | match json { 25 | Ok(json_obj) => { 26 | match json_obj { 27 | Value::Object(obj) => { 28 | let mut hash = HashMap::new(); 29 | for (key, value) in obj { 30 | let key = Object::String(key.to_string()); 31 | let value = match value { 32 | Value::Null => Object::Null, 33 | Value::Bool(_) => Object::Bool(value.as_bool().unwrap()), 34 | Value::Number(_) => Object::Number(value.as_f64().unwrap()), 35 | Value::String(_) => Object::String(value.as_str().unwrap().to_string()), 36 | Value::Array(_) => { 37 | let mut array = Vec::new(); 38 | for value in value.as_array().unwrap() { 39 | array.push(parse_json(vec![Object::String(value.to_string())])) 40 | } 41 | Object::Array(array) 42 | } 43 | Value::Object(_) => parse_json(vec![Object::String(value.to_string())]), 44 | }; 45 | hash.insert(key, value); 46 | } 47 | return Object::Object(hash); 48 | } 49 | Value::Array(arr) => { 50 | return Object::Array(arr.iter().map(|value| { 51 | match value { 52 | Value::Null => Object::Null, 53 | Value::Bool(_) => Object::Bool(value.as_bool().unwrap()), 54 | Value::Number(_) => Object::Number(value.as_f64().unwrap()), 55 | Value::String(_) => Object::String(value.as_str().unwrap().to_string()), 56 | Value::Array(_) => { 57 | let mut array = Vec::new(); 58 | for value in value.as_array().unwrap() { 59 | array.push(parse_json(vec![Object::String(value.to_string())])) 60 | } 61 | Object::Array(array) 62 | } 63 | Value::Object(_) => parse_json(vec![Object::String(value.to_string())]), 64 | } 65 | }).collect()); 66 | } 67 | _ => { 68 | return Object::Error(format!("Expected an object. Got {}", json_obj)); 69 | } 70 | } 71 | } 72 | Err(e) => { 73 | return Object::Error(format!("{}", e)); 74 | } 75 | } 76 | } 77 | _ => Object::Error(format!("Expected a string. Got {}", args[0])) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/std_library/array.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use crate::evaluation::object::Object; 4 | 5 | use super::Res; 6 | 7 | /// Adds the standard library to the global environment. 8 | pub fn add_globals() -> Res { 9 | let mut globals = HashMap::new(); 10 | globals.insert(String::from("pop"), Object::Inbuilt(pop)); 11 | globals.insert(String::from("head"), Object::Inbuilt(head)); 12 | globals.insert(String::from("tail"), Object::Inbuilt(tail)); 13 | globals.insert(String::from("push"), Object::Inbuilt(push)); 14 | globals.insert(String::from("includes"), Object::Inbuilt(includes)); 15 | Res { 16 | globals, 17 | raw: Some(" 18 | include \"std:util\"; 19 | 20 | set map = fun (arr, f) { 21 | set res = []; 22 | set iter = fun (array) { 23 | if (length(array) == 0) { 24 | return; 25 | } else { 26 | anew res = push(res, f(array[0])); 27 | iter(tail(array)); 28 | } 29 | }; 30 | iter(arr) 31 | return res; 32 | }; 33 | ".to_string()) 34 | } 35 | } 36 | 37 | /// The std:array-built-in function `push`. 38 | /// Pushes an object onto the end of an array. 39 | /// # Arguments 40 | /// * `args` - The array to push onto. 41 | pub fn push(args: Vec) -> Object { 42 | if args.len() != 2 { 43 | return Object::Error(format!( 44 | "Wrong number of arguments. Got {}. Expected 2.", 45 | args.len() 46 | )); 47 | } 48 | 49 | match &args[0] { 50 | Object::Array(a) => { 51 | let mut array = a.clone(); 52 | array.push(args[1].clone()); 53 | Object::Array(array) 54 | } 55 | o => Object::Error(format!("First argument must be an array. Got {}", o)), 56 | } 57 | } 58 | 59 | pub fn pop(args: Vec) -> Object { 60 | if args.len() != 1 { 61 | return Object::Error(format!( 62 | "Wrong number of arguments. Got {}. Expected 1.", 63 | args.len() 64 | )); 65 | } 66 | match &args[0] { 67 | Object::Array(a) => { 68 | let mut array = a.clone(); 69 | array.pop(); 70 | Object::Array(array) 71 | } 72 | o => Object::Error(format!("First argument must be an array. Got {}", o)), 73 | } 74 | } 75 | 76 | pub fn head (args: Vec) -> Object { 77 | if args.len() != 1 { 78 | return Object::Error(format!( 79 | "Wrong number of arguments. Got {}. Expected 1.", 80 | args.len() 81 | )); 82 | } 83 | match &args[0] { 84 | Object::Array(a) => { 85 | let mut array = a.clone(); 86 | array.pop(); 87 | Object::Array(array) 88 | } 89 | o => Object::Error(format!("First argument must be an array. Got {}", o)), 90 | } 91 | } 92 | 93 | pub fn tail (args: Vec) -> Object { 94 | if args.len() != 1 { 95 | return Object::Error(format!( 96 | "Wrong number of arguments. Got {}. Expected 1.", 97 | args.len() 98 | )); 99 | } 100 | match &args[0] { 101 | Object::Array(a) => Object::Array(a[1..].to_vec()), 102 | o => Object::Error(format!("First argument must be an array. Got {}", o)), 103 | } 104 | } 105 | 106 | pub fn includes (args: Vec) -> Object { 107 | if args.len() != 2 { 108 | return Object::Error(format!( 109 | "Wrong number of arguments. Got {}. Expected 2.", 110 | args.len() 111 | )); 112 | } 113 | match &args[0] { 114 | Object::Array(a) => { 115 | let array = a.clone(); 116 | Object::Bool(array.contains(&args[1])) 117 | } 118 | o => Object::Error(format!("First argument must be an array. Got {}", o)), 119 | } 120 | } -------------------------------------------------------------------------------- /src/evaluation/object.rs: -------------------------------------------------------------------------------- 1 | use super::store::Store; 2 | use crate::ast::{BlockStatement, Ident}; 3 | use std::{ 4 | cell::RefCell, 5 | collections::HashMap, 6 | fmt, 7 | hash::{Hash, Hasher}, 8 | rc::Rc, 9 | }; 10 | 11 | pub type InbuiltFunction = fn(Vec) -> Object; 12 | 13 | #[derive(Clone, Debug)] 14 | pub enum Object { 15 | Number(f64), 16 | String(String), 17 | Bool(bool), 18 | Null, 19 | Return(Box), 20 | Error(String), 21 | Fn(Vec, BlockStatement, Rc>), 22 | Inbuilt(InbuiltFunction), 23 | Array(Vec), 24 | Object(HashMap), 25 | Typeof(Box), 26 | Loop(Box), 27 | Break, 28 | Continue 29 | } 30 | 31 | impl PartialEq for Object { 32 | fn eq(&self, other: &Self) -> bool { 33 | match (self, other) { 34 | (Object::Number(a), Object::Number(b)) => a == b, 35 | (Object::String(a), Object::String(b)) => a == b, 36 | (Object::Bool(a), Object::Bool(b)) => a == b, 37 | (Object::Null, Object::Null) => true, 38 | (Object::Return(a), Object::Return(b)) => a == b, 39 | (Object::Error(a), Object::Error(b)) => a == b, 40 | (Object::Fn(a, b, c), Object::Fn(d, e, f)) => a == d && b == e && c == f, 41 | (Object::Inbuilt(a), Object::Inbuilt(b)) => a == b, 42 | (Object::Array(a), Object::Array(b)) => a == b, 43 | (Object::Object(a), Object::Object(b)) => a == b, 44 | (Object::Typeof(a), Object::Typeof(b)) => a == b, 45 | _ => false, 46 | } 47 | } 48 | } 49 | 50 | impl Eq for Object {} 51 | 52 | impl fmt::Display for Object { 53 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 54 | match *self { 55 | Object::Number(ref value) => write!(f, "{}", value), 56 | Object::String(ref value) => write!(f, "{}", value), 57 | Object::Bool(ref value) => write!(f, "{}", value), 58 | Object::Null => write!(f, "null"), 59 | Object::Return(ref value) => write!(f, "{}", value), 60 | Object::Error(ref value) => write!(f, "{}", value), 61 | Object::Fn(ref params, _, _) => { 62 | let mut result = String::new(); 63 | for (i, Ident(ref s)) in params.iter().enumerate() { 64 | if i < 1 { 65 | result.push_str(s); 66 | } else { 67 | result.push_str(&format!(", {}", s)); 68 | } 69 | } 70 | write!(f, "fn({}) {{ ... }}", result) 71 | } 72 | Object::Inbuilt(_) => write!(f, "[inbuilt fn]"), 73 | Object::Array(ref val) => { 74 | let mut result = String::new(); 75 | for (i, obj) in val.iter().enumerate() { 76 | if i < 1 { 77 | result.push_str(&format!("{}", obj)); 78 | } else { 79 | result.push_str(&format!(", {}", obj)); 80 | } 81 | } 82 | write!(f, "[{}]", result) 83 | } 84 | Object::Object(ref hash) => { 85 | let mut res = String::new(); 86 | for (i, (k, v)) in hash.iter().enumerate() { 87 | if i < 1 { 88 | res.push_str(&format!("{}: {}", k, v)); 89 | } else { 90 | res.push_str(&format!(", {}: {}", k, v)); 91 | } 92 | } 93 | 94 | write!(f, "{{{}}}", res) 95 | } 96 | Object::Typeof(ref obj) => write!(f, "typeof({})", obj), 97 | Object::Loop(ref _block) => write!(f, "loop {{ ... }}"), 98 | Object::Break => write!(f, "break"), 99 | Object::Continue => write!(f, "continue"), 100 | } 101 | } 102 | } 103 | 104 | impl Hash for Object { 105 | fn hash(&self, state: &mut H) { 106 | match *self { 107 | Object::Bool(ref b) => b.hash(state), 108 | Object::String(ref s) => s.hash(state), 109 | _ => "".hash(state), 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /src/std_library/math.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap}; 2 | use rand::{Rng}; 3 | 4 | use crate::evaluation::object::Object; 5 | 6 | use super::Res; 7 | 8 | /// Adds the standard library to the global environment. 9 | pub fn add_globals() -> Res { 10 | let mut globals = HashMap::new(); 11 | globals.insert(String::from("random"), Object::Inbuilt(random)); 12 | globals.insert(String::from("round"), Object::Inbuilt(round)); 13 | globals.insert(String::from("ceil"), Object::Inbuilt(ceil)); 14 | globals.insert(String::from("floor"), Object::Inbuilt(floor)); 15 | globals.insert(String::from("abs"), Object::Inbuilt(abs)); 16 | globals.insert(String::from("sqrt"), Object::Inbuilt(sqrt)); 17 | globals.insert(String::from("sin"), Object::Inbuilt(sin)); 18 | globals.insert(String::from("cos"), Object::Inbuilt(cos)); 19 | globals.insert(String::from("tan"), Object::Inbuilt(tan)); 20 | globals.insert(String::from("pow"), Object::Inbuilt(pow)); 21 | globals.insert(String::from("log2"), Object::Inbuilt(log2)); 22 | globals.insert(String::from("log10"), Object::Inbuilt(log10)); 23 | globals.insert(String::from("modulo"), Object::Inbuilt(modulo)); 24 | globals.insert(String::from("Math.PI"), Object::Number(std::f64::consts::PI)); 25 | globals.insert(String::from("Math.E"), Object::Number(std::f64::consts::E)); 26 | globals.insert(String::from("MAX_INT"), Object::Number(std::f64::MAX)); 27 | globals.insert(String::from("MIN_INT"), Object::Number(std::f64::MIN)); 28 | Res { 29 | globals, 30 | raw: None, 31 | } 32 | } 33 | 34 | pub fn random(args: Vec) -> Object { 35 | let min = match &args[0] { 36 | Object::Number(n) => *n, 37 | _ => 0.0, 38 | }; 39 | 40 | let max = match &args[1] { 41 | Object::Number(n) => *n, 42 | _ => 0.0, 43 | }; 44 | 45 | let mut rng = rand::thread_rng(); 46 | let random_number = rng.gen_range(min..max); 47 | Object::Number(random_number) 48 | } 49 | 50 | pub fn round(args: Vec) -> Object { 51 | match &args[0] { 52 | Object::Number(n) => Object::Number(n.round()), 53 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 54 | } 55 | } 56 | 57 | pub fn log2(args: Vec) -> Object { 58 | match &args[0] { 59 | Object::Number(n) => Object::Number(n.log2()), 60 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 61 | } 62 | } 63 | 64 | pub fn log10(args: Vec) -> Object { 65 | match &args[0] { 66 | Object::Number(n) => Object::Number(n.log10()), 67 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 68 | } 69 | } 70 | 71 | pub fn sin(args: Vec) -> Object { 72 | match &args[0] { 73 | Object::Number(n) => Object::Number(n.sin()), 74 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 75 | } 76 | } 77 | 78 | pub fn cos(args: Vec) -> Object { 79 | match &args[0] { 80 | Object::Number(n) => Object::Number(n.cos()), 81 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 82 | } 83 | } 84 | 85 | pub fn tan(args: Vec) -> Object { 86 | match &args[0] { 87 | Object::Number(n) => Object::Number(n.tan()), 88 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 89 | } 90 | } 91 | 92 | pub fn pow(args: Vec) -> Object { 93 | let base = match &args[0] { 94 | Object::Number(n) => *n, 95 | _ => 0.0, 96 | }; 97 | 98 | let to = match &args[1] { 99 | Object::Number(n) => *n, 100 | _ => 0.0, 101 | }; 102 | 103 | let result = f64::powf(base, to); 104 | Object::Number(result) 105 | } 106 | 107 | pub fn modulo(args: Vec) -> Object { 108 | let a = match &args[0] { 109 | Object::Number(n) => *n, 110 | _ => 0.0, 111 | }; 112 | 113 | let b = match &args[1] { 114 | Object::Number(n) => *n, 115 | _ => 0.0, 116 | }; 117 | 118 | let mut result = a % b; 119 | result = result + b; 120 | result = result % b; 121 | 122 | Object::Number(result) 123 | } 124 | 125 | 126 | pub fn floor(args: Vec) -> Object { 127 | match &args[0] { 128 | Object::Number(n) => Object::Number(n.floor()), 129 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 130 | } 131 | } 132 | 133 | pub fn ceil(args: Vec) -> Object { 134 | match &args[0] { 135 | Object::Number(n) => Object::Number(n.ceil()), 136 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 137 | } 138 | } 139 | 140 | pub fn abs(args: Vec) -> Object { 141 | match &args[0] { 142 | Object::Number(n) => Object::Number(n.abs()), 143 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 144 | } 145 | } 146 | 147 | pub fn sqrt(args: Vec) -> Object { 148 | match &args[0] { 149 | Object::Number(n) => Object::Number(n.sqrt()), 150 | _ => Object::Error(format!("Argument must be a number. Got {}", args[0])), 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/lexer.rs: -------------------------------------------------------------------------------- 1 | use crate::ast::token::Token; 2 | use std::collections::HashMap; 3 | 4 | lazy_static::lazy_static! { 5 | static ref KEYWORDS: HashMap<&'static str, Token> = { 6 | let mut keywords = HashMap::new(); 7 | keywords.insert("set", Token::Set); 8 | keywords.insert("anew", Token::Anew); 9 | keywords.insert("fun", Token::Func); 10 | keywords.insert("if", Token::If); 11 | keywords.insert("else", Token::Else); 12 | keywords.insert("return", Token::Return); 13 | keywords.insert("include", Token::Include); 14 | keywords.insert("true", Token::Boolean(true)); 15 | keywords.insert("false", Token::Boolean(false)); 16 | keywords.insert("typeof", Token::Typeof); 17 | keywords.insert("loop", Token::Loop); 18 | keywords.insert("break", Token::Break); 19 | keywords.insert("continue", Token::Continue); 20 | keywords 21 | }; 22 | } 23 | 24 | fn is_letter(c: char) -> bool { 25 | c.is_ascii_alphabetic() || c == '_' 26 | } 27 | 28 | pub fn find_indentifier(ident: &str) -> Option<&Token> { 29 | KEYWORDS.get(ident) 30 | } 31 | 32 | pub struct Lexer { 33 | input: String, 34 | position: usize, 35 | read_position: usize, 36 | ch: char, 37 | } 38 | 39 | impl Lexer { 40 | pub fn new(input: String) -> Lexer { 41 | Lexer { 42 | ch: input.chars().next().unwrap(), 43 | input, 44 | position: 0, 45 | read_position: 1, 46 | } 47 | } 48 | 49 | pub fn read_char(&mut self) { 50 | self.ch = if self.read_position >= self.input.len() { 51 | '\0' 52 | } else { 53 | self.input.chars().nth(self.read_position).unwrap() 54 | }; 55 | 56 | self.position = self.read_position; 57 | self.read_position += 1; 58 | } 59 | 60 | fn read_identifier(&mut self) -> String { 61 | let pos: usize = self.position; 62 | while is_letter(self.ch) { 63 | self.read_char() 64 | } 65 | self.input[pos..self.position].to_string() 66 | } 67 | 68 | fn read_number(&mut self) -> f64 { 69 | let pos: usize = self.position; 70 | while self.ch.is_numeric() || self.ch == '.' { 71 | self.read_char(); 72 | } 73 | self.input[pos..self.position].parse::().unwrap() 74 | } 75 | 76 | fn read_string(&mut self) -> String { 77 | let pos: usize = self.position + 1; 78 | loop { 79 | self.read_char(); 80 | if self.ch == '"' || self.ch == (0 as char) { 81 | break; 82 | } 83 | } 84 | self.input[pos..self.position].to_string() 85 | } 86 | 87 | pub fn read_comment(&mut self) -> String { 88 | let pos: usize = self.position; 89 | loop { 90 | self.read_char(); 91 | if self.ch == '\n' || self.ch == (0 as char) { 92 | break; 93 | } 94 | } 95 | self.input[pos..self.position].to_string() 96 | } 97 | 98 | fn skip_whitespace(&mut self) { 99 | while self.ch == ' ' || self.ch == '\t' || self.ch == '\n' || self.ch == '\r' { 100 | self.read_char() 101 | } 102 | } 103 | 104 | fn peek_char(&self) -> char { 105 | if self.read_position >= self.input.len() { 106 | return 0 as char; 107 | } 108 | self.input.chars().nth(self.read_position).unwrap() 109 | } 110 | 111 | pub fn next_token(&mut self) -> Token { 112 | self.skip_whitespace(); 113 | let tok: Token = match self.ch { 114 | '=' => { 115 | if self.peek_char() == '=' { 116 | self.read_char(); 117 | Token::Equals 118 | } else { 119 | Token::Assign 120 | } 121 | } 122 | ';' => Token::Semicolon, 123 | ':' => Token::Colon, 124 | ',' => Token::Comma, 125 | '+' => Token::Plus, 126 | '-' => Token::Minus, 127 | '&' => Token::AND, 128 | '|' => Token::OR, 129 | '^' => Token::XOR, 130 | '%' => Token::Percent, 131 | '!' => { 132 | if self.peek_char() == '=' { 133 | self.read_char(); 134 | Token::NotEquals 135 | } else { 136 | Token::Bang 137 | } 138 | } 139 | '~' => Token::In, 140 | '(' => Token::LeftParen, 141 | ')' => Token::RightParen, 142 | '{' => Token::LeftBrace, 143 | '}' => Token::RightBrace, 144 | '[' => Token::LeftBracket, 145 | ']' => Token::RightBracket, 146 | '*' => Token::Asterisk, 147 | '/' => { 148 | if self.peek_char() == '/' { 149 | self.read_comment(); 150 | Token::Comment 151 | } else { 152 | Token::Slash 153 | } 154 | } 155 | '<' => match self.peek_char() { 156 | '<' => Token::LeftShift, 157 | '=' => Token::LessEqual, 158 | _ => Token::Less 159 | }, 160 | '>' => match self.peek_char() { 161 | '>' => Token::RightShift, 162 | '=' => Token::GreaterEqual, 163 | _ => Token::Greater 164 | }, 165 | '"' => Token::String(self.read_string()), 166 | '\u{0}' => Token::Eof, 167 | _ => { 168 | if is_letter(self.ch) { 169 | let i: String = self.read_identifier(); 170 | return match find_indentifier(i.as_str()) { 171 | Some(a) => a.to_owned(), 172 | _ => Token::Ident(i), 173 | }; 174 | } else if self.ch.is_numeric() { 175 | let i: f64 = self.read_number(); 176 | return Token::Number(i); 177 | } else { 178 | Token::Illegal 179 | } 180 | } 181 | }; 182 | 183 | self.read_char(); 184 | tok 185 | } 186 | 187 | } -------------------------------------------------------------------------------- /src/parser.rs: -------------------------------------------------------------------------------- 1 | use crate::{ast::{*, token::Token}, lexer::Lexer}; 2 | 3 | pub struct Parser { 4 | lexer: Lexer, 5 | current_token: Token, 6 | peek_token: Token, 7 | pub errors: Vec 8 | } 9 | 10 | impl Parser { 11 | 12 | pub fn new(lexer: Lexer) -> Self { 13 | let mut p: Parser = Parser { 14 | lexer, 15 | current_token: Token::Eof, 16 | peek_token: Token::Eof, 17 | errors: vec![], 18 | }; 19 | p.next_token(); 20 | p.next_token(); 21 | p 22 | } 23 | 24 | pub fn next_token(&mut self) { 25 | self.current_token = self.peek_token.clone(); 26 | self.peek_token = self.lexer.next_token(); 27 | } 28 | 29 | pub fn parse_program(&mut self) -> Program { 30 | let mut statements: Vec = vec![]; 31 | while self.current_token != Token::Eof { 32 | let stmt: Option = self.parse_statement(); 33 | if stmt != None { 34 | statements.push(stmt.unwrap()); 35 | }; 36 | self.next_token(); 37 | } 38 | Program { statements } 39 | } 40 | 41 | pub fn parse_statement(&mut self) -> Option { 42 | match self.current_token { 43 | Token::Set => self.parse_set_statement(), 44 | Token::Return => self.parse_return_statement(), 45 | Token::Include => self.parse_include_statement(), 46 | Token::Anew => self.parse_anew_expr(), 47 | Token::Break => self.parse_break_statement(), 48 | Token::Continue => self.parse_continue_statement(), 49 | _ => self.parse_expr_statement(), 50 | } 51 | } 52 | 53 | 54 | pub fn parse_expr_statement(&mut self) -> Option { 55 | match self.parse_expr(Precedence::Lowest) { 56 | Some(expression) => { 57 | if self.peek_token(&Token::Semicolon) { 58 | self.next_token(); 59 | } 60 | Some(Statement::Expression(expression)) 61 | } 62 | None => None, 63 | } 64 | } 65 | 66 | pub fn parse_set_statement(&mut self) -> Option { 67 | match &self.peek_token { 68 | Token::Ident(_) => self.next_token(), 69 | _ => { 70 | self.peek_error(Token::Ident(String::new())); 71 | return None; 72 | } 73 | } 74 | 75 | let name: Ident = match self.parse_ident() { 76 | Some(Expr::Ident(ref mut s)) => s.clone(), 77 | _ => return None, 78 | }; 79 | 80 | if !self.expect_peek(Token::Assign) { 81 | return None; 82 | } 83 | 84 | self.next_token(); 85 | 86 | let lit: Expr = match self.parse_expr(Precedence::Lowest) { 87 | Some(e) => e, 88 | None => return None, 89 | }; 90 | 91 | while !self.current_token(Token::Semicolon) { 92 | self.next_token(); 93 | } 94 | 95 | Some(Statement::Set(name, lit)) 96 | } 97 | 98 | pub fn parse_return_statement(&mut self) -> Option { 99 | self.next_token(); 100 | 101 | let exp = match self.parse_expr(Precedence::Lowest) { 102 | Some(e) => e, 103 | None => return None, 104 | }; 105 | 106 | while !self.current_token(Token::Semicolon) { 107 | self.next_token(); 108 | } 109 | 110 | Some(Statement::Return(exp)) 111 | } 112 | 113 | pub fn parse_include_statement(&mut self) -> Option { 114 | self.next_token(); 115 | // the string next to the include keyword is the lib 116 | let lib = match &self.current_token { 117 | Token::String(ref s) => s.clone(), 118 | _ => { 119 | self.peek_error(Token::String(String::new())); 120 | return None; 121 | } 122 | }; 123 | while !self.current_token(Token::Semicolon) { 124 | self.next_token(); 125 | } 126 | Some(Statement::Include(lib)) 127 | } 128 | 129 | fn parse_block_statement(&mut self) -> BlockStatement { 130 | self.next_token(); 131 | 132 | let mut statements = vec![]; 133 | while !self.current_token(Token::RightBrace) && !self.current_token(Token::Eof) { 134 | if let Some(s) = self.parse_statement() { 135 | statements.push(s); 136 | } 137 | self.next_token(); 138 | } 139 | 140 | statements 141 | } 142 | 143 | pub fn parse_anew_expr(&mut self) -> Option { 144 | match &self.peek_token { 145 | Token::Ident(_) => self.next_token(), 146 | _ => { 147 | self.peek_error(Token::Ident(String::new())); 148 | return None; 149 | } 150 | } 151 | 152 | let name: Ident = match self.parse_ident() { 153 | Some(Expr::Ident(ref mut s)) => s.clone(), 154 | _ => return None, 155 | }; 156 | 157 | if !self.expect_peek(Token::Assign) { 158 | return None; 159 | } 160 | 161 | self.next_token(); 162 | 163 | let lit: Expr = match self.parse_expr(Precedence::Lowest) { 164 | Some(e) => e, 165 | None => return None, 166 | }; 167 | 168 | while !self.current_token(Token::Semicolon) { 169 | self.next_token(); 170 | } 171 | 172 | Some(Statement::Anew(name, lit)) 173 | } 174 | 175 | pub fn parse_break_statement(&mut self) -> Option { 176 | self.next_token(); 177 | while !self.current_token(Token::Semicolon) { 178 | self.next_token(); 179 | } 180 | Some(Statement::Break) 181 | } 182 | 183 | pub fn parse_continue_statement(&mut self) -> Option { 184 | self.next_token(); 185 | while !self.current_token(Token::Semicolon) { 186 | self.next_token(); 187 | } 188 | Some(Statement::Continue) 189 | } 190 | 191 | fn parse_typof_expr(&mut self) -> Option { 192 | self.next_token(); 193 | let expr = match self.parse_expr(Precedence::Lowest) { 194 | Some(e) => e, 195 | None => return None, 196 | }; 197 | Some(Expr::Typeof { expr: Box::new(expr) }) 198 | } 199 | 200 | fn parse_loop_expr(&mut self) -> Option { 201 | self.next_token(); 202 | let body = self.parse_block_statement(); 203 | Some(Expr::Loop { body }) 204 | } 205 | 206 | fn parse_expr(&mut self, precedence: Precedence) -> Option { 207 | let mut left: Option = match self.current_token { 208 | Token::Ident(_) => self.parse_ident(), 209 | Token::Bang | Token::Minus | Token::Plus => self.parse_prefix_expr(), 210 | Token::LeftParen => self.parse_grouped_expr(), 211 | Token::If => self.parse_if_expr(), 212 | Token::Func => self.parse_fn_expr(), 213 | Token::Number(_) => self.parse_int_literal(), 214 | Token::Boolean(_) => self.parse_boolean_literal(), 215 | Token::String(_) => self.parse_string_literal(), 216 | Token::LeftBracket => self.parse_array_literal(), 217 | Token::LeftBrace => self.parse_object_literal(), 218 | Token::Typeof => self.parse_typof_expr(), 219 | Token::Loop => self.parse_loop_expr(), 220 | _ => { 221 | None 222 | } 223 | }; 224 | 225 | while !self.peek_token(&Token::Semicolon) && precedence < self.next_token_precedence() { 226 | match self.peek_token { 227 | Token::Plus 228 | | Token::Minus 229 | | Token::Asterisk 230 | | Token::Equals 231 | | Token::Slash 232 | | Token::Percent 233 | | Token::NotEquals 234 | | Token::Less 235 | | Token::LessEqual 236 | | Token::Greater 237 | | Token::GreaterEqual 238 | | Token::AND 239 | | Token::OR 240 | | Token::XOR 241 | | Token::In => { 242 | self.next_token(); 243 | left = self.parse_infix_expr(left.unwrap()); 244 | } 245 | 246 | Token::LeftShift => { 247 | self.lexer.next_token(); 248 | self.next_token(); 249 | left = self.parse_infix_expr(left.unwrap()); 250 | } 251 | 252 | Token::RightShift => { 253 | self.lexer.next_token(); 254 | self.next_token(); 255 | left = self.parse_infix_expr(left.unwrap()); 256 | } 257 | 258 | Token::LeftParen => { 259 | self.next_token(); 260 | left = self.parse_call_expr(left.unwrap()); 261 | } 262 | Token::LeftBracket => { 263 | self.next_token(); 264 | left = self.parse_index_expr(left.unwrap()); 265 | } 266 | _ => return left, 267 | } 268 | } 269 | 270 | left 271 | } 272 | 273 | fn parse_object_literal(&mut self) -> Option { 274 | let mut obj = vec![]; 275 | while !self.peek_token(&Token::RightBrace) { 276 | self.next_token(); 277 | let key = match self.parse_expr(Precedence::Lowest) { 278 | Some(o) => o, 279 | None => return None, 280 | }; 281 | if !self.expect_peek(Token::Colon) { 282 | return None; 283 | } 284 | 285 | self.next_token(); 286 | let val = match self.parse_expr(Precedence::Lowest) { 287 | Some(o) => o, 288 | None => return None, 289 | }; 290 | obj.push((key, val)); 291 | if !self.peek_token(&Token::RightBrace) && !self.expect_peek(Token::Comma) { 292 | return None; 293 | } 294 | } 295 | if !self.expect_peek(Token::RightBrace) { 296 | return None; 297 | } 298 | 299 | Some(Expr::Literal(Literal::Object(obj))) 300 | } 301 | 302 | fn parse_int_literal(&mut self) -> Option { 303 | match self.current_token { 304 | Token::Number(ref mut int) => Some(Expr::Literal(Literal::Number(*int))), 305 | _ => None, 306 | } 307 | } 308 | 309 | fn parse_boolean_literal(&mut self) -> Option { 310 | match self.current_token { 311 | Token::Boolean(boolean) => Some(Expr::Literal(Literal::Boolean(boolean))), 312 | _ => None, 313 | } 314 | } 315 | 316 | fn parse_string_literal(&mut self) -> Option { 317 | match self.current_token { 318 | Token::String(ref mut str) => Some(Expr::Literal(Literal::String(str.clone()))), 319 | _ => None, 320 | } 321 | } 322 | 323 | fn parse_array_literal(&mut self) -> Option { 324 | self.parse_expr_list(Token::RightBracket) 325 | .map(|list| Expr::Literal(Literal::Array(list))) 326 | } 327 | 328 | 329 | 330 | fn parse_expr_list(&mut self, end: Token) -> Option> { 331 | let mut list = vec![]; 332 | if self.peek_token(&end) { 333 | self.next_token(); 334 | return Some(list); 335 | } 336 | 337 | self.next_token(); 338 | match self.parse_expr(Precedence::Lowest) { 339 | Some(a) => list.push(a), 340 | None => return None, 341 | }; 342 | while self.peek_token(&Token::Comma) { 343 | self.next_token(); 344 | if self.peek_token(&Token::RightBracket) { 345 | break; 346 | } 347 | self.next_token(); 348 | 349 | match self.parse_expr(Precedence::Lowest) { 350 | Some(expr) => list.push(expr), 351 | None => return None, 352 | } 353 | } 354 | 355 | if !self.expect_peek(end) { 356 | return None; 357 | } 358 | 359 | Some(list) 360 | } 361 | 362 | fn parse_ident(&mut self) -> Option { 363 | match self.current_token { 364 | Token::Ident(ref mut ident) => Some(Expr::Ident(Ident(ident.clone()))), 365 | _ => None, 366 | } 367 | } 368 | 369 | fn parse_prefix_expr(&mut self) -> Option { 370 | let prefix = match self.current_token { 371 | Token::Bang => Prefix::Exclamation, 372 | Token::Minus => Prefix::Minus, 373 | Token::Plus => Prefix::Plus, 374 | _ => return None, 375 | }; 376 | 377 | self.next_token(); 378 | 379 | self.parse_expr(Precedence::Prefix) 380 | .map(|expr| Expr::Prefix(prefix, Box::new(expr))) 381 | } 382 | 383 | fn parse_infix_expr(&mut self, left: Expr) -> Option { 384 | let infix = match self.current_token { 385 | Token::Plus => Infix::Plus, 386 | Token::Minus => Infix::Minus, 387 | Token::Slash => Infix::Divide, 388 | Token::Asterisk => Infix::Times, 389 | Token::Percent => Infix::Modulo, 390 | Token::Equals => Infix::Equals, 391 | Token::NotEquals => Infix::NotEquals, 392 | Token::Less => Infix::LessThan, 393 | Token::Greater => Infix::GreaterThan, 394 | Token::LessEqual => Infix::LessThanEqual, 395 | Token::GreaterEqual => Infix::GreaterThanEqual, 396 | Token::LeftShift => Infix::LeftShift, 397 | Token::RightShift => Infix::RightShift, 398 | Token::AND => Infix::AND, 399 | Token::OR => Infix::OR, 400 | Token::XOR => Infix::XOR, 401 | Token::In => Infix::In, 402 | _ => return None, 403 | }; 404 | 405 | let precedence = self.current_token_precedence(); 406 | self.next_token(); 407 | 408 | self.parse_expr(precedence) 409 | .map(|e| Expr::Infix(infix, Box::new(left), Box::new(e))) 410 | } 411 | 412 | fn parse_grouped_expr(&mut self) -> Option { 413 | let exp = self.parse_expr(Precedence::Lowest); 414 | if !self.expect_peek(Token::RightParen) { 415 | return None; 416 | } 417 | exp 418 | } 419 | 420 | fn parse_if_expr(&mut self) -> Option { 421 | if !self.expect_peek(Token::LeftParen) { 422 | return None; 423 | } 424 | 425 | self.next_token(); 426 | 427 | let expr: Expr = match self.parse_expr(Precedence::Lowest) { 428 | Some(e) => e, 429 | None => return None, 430 | }; 431 | 432 | if !self.expect_peek(Token::RightParen) || !self.expect_peek(Token::LeftBrace) { 433 | return None; 434 | } 435 | 436 | let cons: Vec = self.parse_block_statement(); 437 | let mut alternative: Option> = None; 438 | if self.peek_token(&Token::Else) { 439 | self.next_token(); 440 | 441 | if self.peek_token(&Token::If) { 442 | self.next_token(); 443 | let else_if = self.parse_if_expr(); 444 | alternative = Some(vec![Statement::Expression(else_if.unwrap())]); 445 | } else if !self.expect_peek(Token::LeftBrace) { 446 | return None; 447 | } else { 448 | alternative = Some(self.parse_block_statement()) 449 | }; 450 | } 451 | 452 | Some(Expr::If { 453 | cond: Box::new(expr), 454 | then: Box::new(cons), 455 | else_: alternative, 456 | }) 457 | } 458 | 459 | fn parse_fn_expr(&mut self) -> Option { 460 | if !self.expect_peek(Token::LeftParen) { 461 | return None; 462 | } 463 | let params = match self.parse_params() { 464 | Some(s) => s, 465 | None => return None, 466 | }; 467 | self.next_token(); 468 | let body = self.parse_block_statement(); 469 | 470 | Some(Expr::Fun { params, body }) 471 | } 472 | 473 | fn token_to_precedence(tok: &Token) -> Precedence { 474 | match tok { 475 | Token::Equals | Token::NotEquals => Precedence::Equals, 476 | Token::Less | Token::LessEqual => Precedence::LessGreater, 477 | Token::Greater | Token::GreaterEqual => Precedence::LessGreater, 478 | Token::Plus | Token::Minus => Precedence::Sum, 479 | Token::Slash | Token::Asterisk | Token::Percent => Precedence::Product, 480 | Token::LeftBracket => Precedence::Index, 481 | Token::LeftParen => Precedence::Call, 482 | Token::In => Precedence::In, 483 | Token::LeftShift => Precedence::LeftShift, 484 | Token::RightShift => Precedence::RightShift, 485 | Token::AND => Precedence::AND, 486 | Token::OR => Precedence::OR, 487 | Token::XOR => Precedence::XOR, 488 | _ => Precedence::Lowest, 489 | } 490 | } 491 | 492 | fn parse_params(&mut self) -> Option> { 493 | let mut idents: Vec = vec![]; 494 | if self.peek_token(&Token::RightParen) { 495 | self.next_token(); 496 | return Some(idents); 497 | } 498 | 499 | self.next_token(); 500 | match self.current_token { 501 | Token::Ident(ref mut ident) => idents.push(Ident(ident.clone())), 502 | _ => { 503 | self.errors.push( 504 | format!("Expected identifier as parameter name. Got: {}", self.current_token) 505 | ); 506 | return None; 507 | } 508 | }; 509 | 510 | while self.peek_token(&Token::Comma) { 511 | self.next_token(); 512 | self.next_token(); 513 | match self.current_token { 514 | Token::Ident(ref mut ident) => idents.push(Ident(ident.clone())), 515 | _ => return None, 516 | }; 517 | } 518 | 519 | if !self.expect_peek(Token::RightParen) { 520 | return None; 521 | } 522 | 523 | Some(idents) 524 | } 525 | 526 | fn parse_call_arguments(&mut self) -> Option> { 527 | let mut args: Vec = vec![]; 528 | 529 | if self.peek_token(&Token::RightParen) { 530 | self.next_token(); 531 | return Some(args); 532 | } 533 | 534 | self.next_token(); 535 | match self.parse_expr(Precedence::Lowest) { 536 | Some(e) => args.push(e), 537 | None => return None, 538 | }; 539 | 540 | while self.peek_token(&Token::Comma) { 541 | self.next_token(); 542 | self.next_token(); 543 | 544 | match self.parse_expr(Precedence::Lowest) { 545 | Some(e) => args.push(e), 546 | None => return None, 547 | }; 548 | } 549 | 550 | if !self.expect_peek(Token::RightParen) { 551 | return None; 552 | } 553 | 554 | Some(args) 555 | } 556 | 557 | fn parse_index_expr(&mut self, left: Expr) -> Option { 558 | self.next_token(); 559 | let expr = match self.parse_expr(Precedence::Lowest) { 560 | Some(e) => e, 561 | None => return None, 562 | }; 563 | if !self.expect_peek(Token::RightBracket) { 564 | return None; 565 | } 566 | 567 | Some(Expr::Index { 568 | array: Box::new(left), 569 | index: Box::new(expr), 570 | }) 571 | } 572 | 573 | fn parse_call_expr(&mut self, left: Expr) -> Option { 574 | let args = match self.parse_call_arguments() { 575 | Some(e) => e, 576 | None => return None, 577 | }; 578 | 579 | Some(Expr::Call { 580 | function: Box::new(left), 581 | args, 582 | }) 583 | } 584 | 585 | fn peek_token(&self, t: &Token) -> bool { 586 | self.peek_token == *t 587 | } 588 | 589 | fn current_token(&self, t: Token) -> bool { 590 | self.current_token == t 591 | } 592 | 593 | fn expect_peek(&mut self, t: Token) -> bool { 594 | if let Token::Ident(..) = t { 595 | self.next_token(); 596 | return true; 597 | } 598 | 599 | if self.peek_token(&t) { 600 | self.next_token(); 601 | true 602 | } else { 603 | self.peek_error(t); 604 | false 605 | } 606 | } 607 | 608 | fn peek_error(&mut self, t: Token) { 609 | let msg = format!( 610 | "Expected next token to be {}, got {} instead", 611 | t, 612 | self.peek_token 613 | ); 614 | self.errors.push(msg); 615 | } 616 | 617 | fn current_token_precedence(&mut self) -> Precedence { 618 | Self::token_to_precedence(&self.current_token) 619 | } 620 | 621 | fn next_token_precedence(&mut self) -> Precedence { 622 | Self::token_to_precedence(&self.peek_token) 623 | } 624 | } -------------------------------------------------------------------------------- /src/evaluation/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod object; 2 | pub mod store; 3 | pub mod library; 4 | pub mod globals; 5 | 6 | use crate::ast::*; 7 | use globals::new_globals; 8 | use store::Store; 9 | use object::Object; 10 | use std::{cell::RefCell, collections::HashMap, rc::Rc}; 11 | 12 | use library::load_etrl; 13 | 14 | /// ## Eval 15 | /// The Eval struct is used to evaluate an AST. 16 | /// It contains a reference to a Store, which is used to store variables. 17 | /// The Eval struct also contains a reference to the global environment. 18 | /// The global environment is a HashMap of names to objects. 19 | /// The Eval struct also contains a reference to the current environment. 20 | pub struct Eval { 21 | /// The current environment. 22 | pub store: Rc>, 23 | } 24 | 25 | impl Eval { 26 | /// ## new 27 | /// Creates a new Eval struct. 28 | /// # Arguments 29 | /// * `store` - The store to use. 30 | /// # Returns 31 | /// `Eval` - The new Eval struct. 32 | pub fn new(store: Rc>) -> Self { 33 | Eval { store } 34 | } 35 | 36 | /// ## is_truthy 37 | /// Checks if an object is truthy. 38 | /// # Arguments 39 | /// * `obj` - The object to check. 40 | /// # Returns 41 | /// `bool` - Whether the object is truthy. 42 | /// # Examples 43 | /// ``` 44 | /// use crate::eval::Eval; 45 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 46 | /// let obj = Object::Boolean(true); 47 | /// assert_eq!(true, is_truthy(obj)); 48 | /// ``` 49 | fn is_truthy(&mut self, object: Object) -> bool { 50 | !matches!(object, Object::Null | Object::Bool(false)) 51 | } 52 | 53 | /// ##is_error 54 | /// Checks if an object is an error. 55 | /// # Arguments 56 | /// * `object` - The object to check. 57 | /// # Returns 58 | /// `bool` - Whether the object is an error. 59 | /// # Examples 60 | /// ``` 61 | /// use crate::eval::Eval; 62 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 63 | /// let obj = Object::Error(String::from("Error")); 64 | /// assert_eq!(true, is_error(obj)); 65 | /// ``` 66 | fn is_error(&mut self, object: &Object) -> bool { 67 | matches!(object, Object::Error(_)) 68 | } 69 | 70 | /// ## eval 71 | /// Evaluates the program. 72 | /// It loops over all the statements in the program, 73 | /// and evaluates them. 74 | /// If an error occurs, it is returned. 75 | /// # Arguments 76 | /// * `program` - The program to evaluate. 77 | /// # Returns 78 | /// `Object` - The result of the evaluation. 79 | /// # Examples 80 | /// ``` 81 | /// use crate::eval::Eval; 82 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 83 | /// let program = Program { 84 | /// statements: vec![ 85 | /// Statement::Expression(Expression::Identifier(String::from("x"))), 86 | /// Statement::Expression(Expression::Identifier(String::from("y"))), 87 | /// Statement::Expression(Expression::Identifier(String::from("z"))), 88 | /// ], 89 | /// }; 90 | /// let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 91 | /// let result = eval.eval(program); 92 | /// assert_eq!(Object::Null, result); 93 | /// ``` 94 | pub fn eval(&mut self, program: Program) -> Option { 95 | let mut result = None; 96 | 97 | for statement in program.statements { 98 | match self.eval_statement(statement) { 99 | Some(Object::Error(val)) => return Some(Object::Error(val)), 100 | Some(Object::Return(val)) => return Some(*val), 101 | e => result = e, 102 | } 103 | } 104 | 105 | result 106 | } 107 | 108 | /// ## eval_statement 109 | /// Evaluates a statement. 110 | /// It matches the statement type, 111 | /// and calls the appropriate function to evaluate it. 112 | /// # Arguments 113 | /// * `statement` - The statement to evaluate. 114 | /// # Returns 115 | /// `Option` - The result of the evaluation. 116 | /// # Examples 117 | /// ``` 118 | /// use crate::eval::Eval; 119 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 120 | /// let statement = Statement::Expression(Expression::Identifier(String::from("x"))); 121 | /// let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 122 | /// let result = eval.eval_statement(statement); 123 | /// assert_eq!(Some(Object::Null), result); 124 | /// ``` 125 | fn eval_statement(&mut self, statement: Statement) -> Option { 126 | match statement { 127 | Statement::Expression(e) => self.eval_expr(e), 128 | Statement::Return(e) => { 129 | let val = match self.eval_expr(e) { 130 | Some(v) => v, 131 | None => return None, 132 | }; 133 | 134 | Some(Object::Return(Box::new(val))) 135 | } 136 | Statement::Set(i, v) => { 137 | let val = match self.eval_expr(v) { 138 | Some(value) => value, 139 | None => return None, 140 | }; 141 | if self.is_error(&val) { 142 | Some(val) 143 | } else { 144 | let Ident(name) = i; 145 | self.store.borrow_mut().set(name, val); 146 | None 147 | } 148 | } 149 | Statement::Anew(i, v) => { 150 | let Ident(name) = i; 151 | let val = match self.eval_expr(v) { 152 | Some(value) => value, 153 | None => return None, 154 | }; 155 | if self.is_error(&val) { 156 | Some(val) 157 | } else { 158 | let mut store = self.store.borrow_mut(); 159 | match store.get(&name) { 160 | Some(_) => { 161 | store.anew(name, val); 162 | None 163 | } 164 | None => Some(Object::Error(format!("identifier not found: {}", name))), 165 | } 166 | } 167 | } 168 | Statement::Include(i) => { 169 | let lib = i; 170 | self.extend_global_store(lib) 171 | }, 172 | Statement::Break => Some(Object::Break), 173 | Statement::Continue => Some(Object::Continue), 174 | } 175 | } 176 | 177 | /// ## eval_block_statement 178 | /// Evaluates a block statement. 179 | /// It loops over all the statements in the block, 180 | /// and evaluates them. 181 | /// If an error occurs, it is returned. 182 | /// # Arguments 183 | /// * `statements` - The block to evaluate. 184 | /// # Returns 185 | /// `Option` - The result of the evaluation. 186 | /// # Examples 187 | /// ``` 188 | /// use crate::eval::Eval; 189 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 190 | /// let block = Block { 191 | /// statements: vec![ 192 | /// Statement::Expression(Expression::Identifier(String::from("x"))), 193 | /// Statement::Expression(Expression::Identifier(String::from("y"))), 194 | /// Statement::Expression(Expression::Identifier(String::from("z"))), 195 | /// ], 196 | /// }; 197 | /// let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 198 | /// let result = eval.eval_block_statement(block); 199 | /// assert_eq!(Some(Object::Null), result); 200 | /// ``` 201 | fn eval_block_statement(&mut self, statements: BlockStatement) -> Option { 202 | let mut result = None; 203 | 204 | for statement in statements { 205 | match self.eval_statement(statement) { 206 | Some(Object::Return(e)) => return Some(Object::Return(e)), 207 | Some(Object::Error(e)) => return Some(Object::Error(e)), 208 | Some(Object::Break) => return Some(Object::Break), 209 | Some(Object::Continue) => return Some(Object::Continue), 210 | e => result = e, 211 | } 212 | } 213 | 214 | result 215 | } 216 | 217 | /// ## eval_expr 218 | /// Evaluates an expression. 219 | /// It matches the expression type, 220 | /// and calls the appropriate function to evaluate it. 221 | /// # Arguments 222 | /// * `expr` - The expression to evaluate. 223 | /// # Returns 224 | /// `Option` - The result of the evaluation. 225 | /// # Examples 226 | /// ``` 227 | /// use crate::eval::Eval; 228 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 229 | /// let expr = Expression::Identifier(String::from("x")); 230 | /// let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 231 | /// let result = eval.eval_expr(expr); 232 | /// assert_eq!(Some(Object::Null), result); 233 | /// ``` 234 | fn eval_expr(&mut self, expr: Expr) -> Option { 235 | match expr { 236 | Expr::Ident(ident) => Some(self.eval_ident(ident)), 237 | Expr::Literal(lit) => Some(self.eval_literal(lit)), 238 | Expr::Prefix(prefix, right) => self 239 | .eval_expr(*right) 240 | .map(|expr| self.eval_prefix_expr(prefix, expr)), 241 | Expr::Infix(infix, left, right) => { 242 | let left_expr = self.eval_expr(*left); 243 | let right_expr = self.eval_expr(*right); 244 | match left_expr.clone() { 245 | Some(l) => { 246 | if self.is_error(&l) { 247 | return left_expr; 248 | } 249 | if self.is_error(&right_expr.clone().unwrap()) { 250 | return right_expr; 251 | } 252 | right_expr.map(|r| self.eval_infix_expr(infix, left_expr.unwrap(), r)) 253 | } 254 | _ => None, 255 | } 256 | } 257 | Expr::If { 258 | cond: condition, 259 | then: consequence, 260 | else_: alternative, 261 | } => { 262 | let cond_expr = match self.eval_expr(*condition) { 263 | Some(e) => e, 264 | None => return None, 265 | }; 266 | 267 | if self.is_truthy(cond_expr) { 268 | self.eval_block_statement(*consequence) 269 | } else if let Some(a) = alternative { 270 | self.eval_block_statement(a) 271 | } else { 272 | None 273 | } 274 | } 275 | Expr::Fun { params, body } => Some(Object::Fn(params, body, self.store.clone())), 276 | Expr::Call { function, args } => Some(self.eval_call_expr(*function, args)), 277 | Expr::Index { array, index } => { 278 | let obj = self.eval_expr(*array); 279 | let i = self.eval_expr(*index); 280 | if let Some(Object::Object(obj)) = obj { 281 | let idx = match i { 282 | Some(Object::Number(i)) => Object::Number(i), 283 | Some(Object::String(i)) => Object::String(i), 284 | Some(Object::Bool(i)) => Object::Bool(i), 285 | _ => return None, 286 | }; 287 | Some(self.eval_index_expr(Object::Object(obj.clone()), idx)) 288 | } else if let Some(Object::Array(arr)) = obj { 289 | let idx = match i { 290 | Some(Object::Number(i)) => Object::Number(i), 291 | _ => return None, 292 | }; 293 | Some(self.eval_index_expr(Object::Array(arr.clone()), idx)) 294 | } else { 295 | None 296 | } 297 | } 298 | Expr::Typeof { expr } => Some(self.eval_typeof_expr(*expr)), 299 | 300 | Expr::Loop { body } => { 301 | let mut _result = None; 302 | loop { 303 | match self.eval_block_statement((*body).to_vec()) { 304 | Some(Object::Return(e)) => return Some(Object::Return(e)), 305 | Some(Object::Error(e)) => return Some(Object::Error(e)), 306 | Some(Object::Break) => { 307 | break Some(Object::Null); 308 | }, 309 | Some(Object::Continue) => continue, 310 | e => _result = e, 311 | } 312 | } 313 | } 314 | } 315 | } 316 | 317 | fn eval_typeof_expr(&mut self, expr: Expr) -> Object { 318 | let obj = self.eval_expr(expr); 319 | match &obj.unwrap() { 320 | Object::Null => Object::String(String::from("null")), 321 | Object::Bool(_) => Object::String(String::from("boolean")), 322 | Object::Number(_) => Object::String(String::from("number")), 323 | Object::String(_) => Object::String(String::from("string")), 324 | Object::Array(_) => Object::String(String::from("array")), 325 | Object::Object(_) => Object::String(String::from("object")), 326 | _ => Object::String(String::from("undefined")), 327 | } 328 | 329 | } 330 | 331 | /// ## eval_prefix_expr 332 | /// Evaluates a prefix expression. 333 | /// It matches the prefix operator, 334 | /// and calls the appropriate function to evaluate it. 335 | /// # Arguments 336 | /// * `prefix` - The prefix operator. 337 | /// * `expr` - The expression to evaluate.s 338 | /// # Returns 339 | /// `Option` - The result of the evaluation. 340 | fn eval_prefix_expr(&mut self, prefix: Prefix, expr: Object) -> Object { 341 | if self.is_error(&expr) { 342 | return expr; 343 | } 344 | match prefix { 345 | Prefix::Exclamation => self.eval_not_prefix_expr(expr), 346 | Prefix::Minus => self.eval_minus_prefix_expr(expr), 347 | Prefix::Plus => self.eval_plus_prefix_expr(expr), 348 | } 349 | } 350 | 351 | /// ## eval_not_prefix_expr 352 | /// Evaluates a `NOT` prefix expression. 353 | /// # Arguments 354 | /// * `expr` - The expression to evaluate. 355 | /// # Returns 356 | /// `Object` - The result of the evaluation. 357 | fn eval_not_prefix_expr(&mut self, expr: Object) -> Object { 358 | match expr { 359 | Object::Bool(true) => Object::Bool(false), 360 | Object::Bool(false) => Object::Bool(true), 361 | Object::Null => Object::Bool(true), 362 | _ => Object::Bool(false), 363 | } 364 | } 365 | 366 | /// ## eval_minus_prefix_expr 367 | /// Evaluates a `MINUS` prefix expression. 368 | /// # Arguments 369 | /// * `expr` - The expression to evaluate. 370 | /// # Returns 371 | /// `Object` - The result of the evaluation. 372 | /// # Examples 373 | /// ``` 374 | /// use crate::eval::Eval; 375 | /// let eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 376 | /// let expr = Expression::Literal(Literal::Number(1.0)); 377 | /// let mut eval = Eval::new(Rc::new(RefCell::new(Store::new()))); 378 | /// let result = eval.eval_minus_prefix_expr(expr); 379 | /// assert_eq!(Some(Object::Number(-1.0)), result); 380 | /// ``` 381 | fn eval_minus_prefix_expr(&mut self, expr: Object) -> Object { 382 | match expr { 383 | Object::Number(i) => Object::Number(-i), 384 | _ => Object::Error(format!("unknown operator: -{}", expr)), 385 | } 386 | } 387 | 388 | /// ## eval_plus_prefix_expr 389 | /// Evaluates a `PLUS` prefix expression. 390 | /// # Arguments 391 | /// * `expr` - The expression to evaluate. 392 | /// # Returns 393 | /// `Object` - The result of the evaluation. 394 | /// # Errors 395 | /// `Error` - If the expression is not a number. 396 | fn eval_plus_prefix_expr(&mut self, expr: Object) -> Object { 397 | match expr { 398 | Object::Number(i) => Object::Number(i), 399 | _ => Object::Error(format!("unknown operator: {}", expr)), 400 | } 401 | } 402 | 403 | /// ## eval_infix_expr 404 | /// Evaluates an infix expression. 405 | /// It matches the infix operator, 406 | /// and calls the appropriate function to evaluate it. 407 | /// # Arguments 408 | /// * `infix` - The infix operator. 409 | /// * `left` - The left expression. 410 | /// * `right` - The right expression. 411 | /// # Returns 412 | /// `Option` - The result of the evaluation. 413 | /// # Errors 414 | /// `Error` - If the expression is not a number. 415 | fn eval_infix_expr(&mut self, infix: Infix, left: Object, right: Object) -> Object { 416 | match left { 417 | Object::Number(left_expr) => { 418 | if let Object::Number(right_expr) = right { 419 | self.eval_int_infix_expr(infix, left_expr, right_expr) 420 | } else if let Object::Object(right_expr) = right { 421 | self.eval_object_infix_expr(infix, Object::Number(left_expr), Object::Object(right_expr)) 422 | } else { 423 | Object::Error(format!("type mismatch: {} {} {}", left, infix, right)) 424 | } 425 | } 426 | Object::String(left_expr) => { 427 | if let Object::String(right_expr) = right { 428 | self.eval_string_infix_expr(infix, left_expr, right_expr) 429 | } else if let Object::Object(right_expr) = right { 430 | self.eval_object_infix_expr(infix, Object::String(left_expr), Object::Object(right_expr)) 431 | } else { 432 | Object::Error(format!("type mismatch: {} {} {}", left_expr, infix, right)) 433 | } 434 | } 435 | _ => self.eval_object_infix_expr(infix, left, right) 436 | } 437 | } 438 | 439 | fn eval_string_infix_expr(&mut self, infix: Infix, left: String, right: String) -> Object { 440 | match infix { 441 | Infix::Plus => Object::String(format!("{}{}", left, right)), 442 | _ => Object::Error(format!("unknown operator: {} {} {}", left, infix, right)), 443 | } 444 | } 445 | 446 | fn eval_object_infix_expr(&mut self, infix: Infix, left: Object, right: Object) -> Object { 447 | match infix { 448 | Infix::In => { 449 | if let Object::Object(right) = right { 450 | Object::Bool(right.contains_key(&left)) 451 | } else if let Object::Array(right) = right { 452 | Object::Bool(right.contains(&left)) 453 | } else { 454 | Object::Error(format!("unknown operator: {} {} {}", left, infix, right)) 455 | } 456 | } 457 | _ => Object::Error(format!("unknown operator: {} {} {}", left, infix, right)), 458 | } 459 | } 460 | 461 | fn eval_int_infix_expr(&mut self, infix: Infix, left: f64, right: f64) -> Object { 462 | match infix { 463 | Infix::Plus => Object::Number(left + right), 464 | Infix::Minus => Object::Number(left - right), 465 | Infix::Times => Object::Number(left * right), 466 | Infix::Divide => Object::Number(left / right), 467 | Infix::Modulo => Object::Number(left % right), 468 | Infix::LessThan => Object::Bool(left < right), 469 | Infix::LessThanEqual => Object::Bool(left <= right), 470 | Infix::GreaterThan => Object::Bool(left > right), 471 | Infix::GreaterThanEqual => Object::Bool(left >= right), 472 | Infix::Equals => Object::Bool(left == right), 473 | Infix::NotEquals => Object::Bool(left != right), 474 | Infix::In => Object::Bool(left.to_string().contains(&right.to_string())), 475 | Infix::LeftShift => Object::Number(((left as i64) << (right as i64)) as f64), 476 | Infix::RightShift => Object::Number(((left as i64) >> (right as i64)) as f64), 477 | Infix::AND => Object::Number((left as i64 & right as i64) as f64), 478 | Infix::OR => Object::Number((left as i64 | right as i64) as f64), 479 | Infix::XOR => Object::Number((left as i64 ^ right as i64) as f64) 480 | } 481 | } 482 | 483 | fn eval_call_expr(&mut self, function: Expr, args: Vec) -> Object { 484 | let args = args 485 | .iter() 486 | .map(|a| self.eval_expr(a.clone()).unwrap_or(Object::Null)) 487 | .collect::>(); 488 | 489 | self.apply_function(function, args) 490 | } 491 | 492 | fn eval_index_expr(&mut self, left: Object, index: Object) -> Object { 493 | match left { 494 | Object::Array(ref arr) => { 495 | if let Object::Number(i) = index { 496 | self.eval_array_index_expr(arr.clone(), i) 497 | } else { 498 | Object::Error(format!("index operator not supported: {}", left)) 499 | } 500 | } 501 | Object::Object(ref hash) => match index { 502 | Object::Number(_) | Object::Bool(_) | Object::String(_) => match hash.get(&index) { 503 | Some(o) => o.clone(), 504 | None => { 505 | Object::Null 506 | }, 507 | }, 508 | Object::Error(_) => index, 509 | _ => Object::Error(format!("unsable as hash key: {}", index)), 510 | }, 511 | _ => Object::Error(format!("unknown operator: {} {}", left, index)), 512 | } 513 | } 514 | 515 | fn eval_array_index_expr(&mut self, array: Vec, index: f64) -> Object { 516 | let max = array.len() as f64; 517 | if index > max { 518 | return Object::Null; 519 | } 520 | 521 | if index < 0.0 { 522 | match array.get((array.len() as f64 + index) as usize) { 523 | Some(o) => return o.clone(), 524 | None => return Object::Null, 525 | } 526 | } 527 | match array.get(index as usize) { 528 | Some(o) => o.clone(), 529 | None => Object::Null, 530 | } 531 | } 532 | 533 | fn apply_function(&mut self, function: Expr, args: Vec) -> Object { 534 | let (params, body, store) = match self.eval_expr(function) { 535 | Some(Object::Fn(params, body, store)) => (params, body, store), 536 | Some(Object::Inbuilt(func)) => return func(args), 537 | Some(o) => return Object::Error(format!("function not found: {}", o)), 538 | None => return Object::Null, 539 | }; 540 | 541 | if params.len() != args.len() { 542 | return Object::Error(format!( 543 | "expected arguments: {}\ngiven arguments: {}", 544 | params.len(), 545 | args.len() 546 | )); 547 | }; 548 | 549 | let current_store = Rc::clone(&self.store); 550 | let extended_store = self.extended_function_store(params, store, args); 551 | self.store = Rc::new(RefCell::new(extended_store)); 552 | let evaluated = self.eval_block_statement(body); 553 | self.store = current_store; 554 | self.unwrap_return_value(evaluated) 555 | } 556 | 557 | fn extended_function_store( 558 | &mut self, 559 | params: Vec, 560 | store: Rc>, 561 | args: Vec, 562 | ) -> Store { 563 | let mut scope_store = Store::new_enclosed(store); 564 | 565 | for (ident, arg) in params.iter().zip(args.iter()) { 566 | let Ident(name) = ident.clone(); 567 | scope_store.set(name, arg.to_owned()); 568 | } 569 | 570 | scope_store 571 | } 572 | 573 | fn extend_global_store(&mut self, lib: String) -> Option { 574 | let lib_store = match load_etrl(lib.clone()) { 575 | Some(e) => e, 576 | None => return Some(Object::Error(format!("Could not load lib: {}", lib))), 577 | }; 578 | let mut new_store = Store::new_enclosed(self.store.clone()); 579 | for (k, v) in lib_store { 580 | new_store.set(k, v); 581 | } 582 | self.store = Rc::new(RefCell::new(new_store)); 583 | None 584 | } 585 | 586 | fn unwrap_return_value(&mut self, obj: Option) -> Object { 587 | match obj { 588 | Some(Object::Return(o)) => *o, 589 | Some(o) => o, 590 | None => Object::Null, 591 | } 592 | } 593 | 594 | fn eval_ident(&mut self, ident: Ident) -> Object { 595 | let Ident(i) = ident; 596 | let builtins = new_globals(); 597 | if builtins.contains_key(&i) { 598 | return builtins.get(&i).unwrap().clone(); 599 | }; 600 | match self.store.borrow_mut().get(&i) { 601 | Some(i) => i, 602 | None => Object::Error(format!("identifier not found: {}", i)), 603 | } 604 | } 605 | 606 | /// Evaluate a literal expression 607 | /// It matches the type of the literal and returns the appropriate object 608 | /// # Arguments 609 | /// * `lit` - The literal to be evaluated 610 | /// # Returns 611 | /// * `Object` - The object representing the literal 612 | /// # Returns 613 | /// * `Object` - If the literal is not a valid type 614 | fn eval_literal(&mut self, lit: Literal) -> Object { 615 | match lit { 616 | Literal::String(s) => Object::String(s), 617 | Literal::Number(i) => Object::Number(i), 618 | Literal::Boolean(b) => Object::Bool(b), 619 | Literal::Array(a) => Object::Array( 620 | a.iter() 621 | .map(|e| self.eval_expr(e.clone()).unwrap_or(Object::Null)) 622 | .collect::>(), 623 | ), 624 | Literal::Object(h) => self.eval_object_literal(h), 625 | } 626 | } 627 | 628 | /// Evaluate an object literal 629 | /// { "a": 1, "b": 2 } 630 | /// => { "a": 1, "b": 2 } 631 | /// # Examples 632 | /// ``` 633 | /// use etrl::{Evaluator, Literal, Ident}; 634 | /// let mut eval = Evaluator::new(); 635 | /// let obj = Literal::Object(vec![(Ident::new("a"), Literal::Number(1)), (Ident::new("b"), Literal::Number(2))]); 636 | /// let result = eval.eval_object_literal(obj); 637 | /// assert_eq!(result, Object::Object(vec![(Ident::new("a"), Object::Number(1)), (Ident::new("b"), Object::Number(2))])); 638 | /// ``` 639 | fn eval_object_literal(&mut self, h: Vec<(Expr, Expr)>) -> Object { 640 | let mut hash = HashMap::new(); 641 | 642 | for (k, v) in h { 643 | let key = self.eval_expr(k).unwrap_or(Object::Null); 644 | if self.is_error(&key) { 645 | return key; 646 | } 647 | 648 | let val = self.eval_expr(v).unwrap_or(Object::Null); 649 | if self.is_error(&val) { 650 | return val; 651 | } 652 | 653 | hash.insert(key, val); 654 | } 655 | Object::Object(hash) 656 | } 657 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.6.10" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "autocfg" 16 | version = "0.1.8" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" 19 | dependencies = [ 20 | "autocfg 1.1.0", 21 | ] 22 | 23 | [[package]] 24 | name = "autocfg" 25 | version = "1.1.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 28 | 29 | [[package]] 30 | name = "base64" 31 | version = "0.13.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 34 | 35 | [[package]] 36 | name = "bitflags" 37 | version = "1.3.2" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 40 | 41 | [[package]] 42 | name = "bumpalo" 43 | version = "3.9.1" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" 46 | 47 | [[package]] 48 | name = "byteorder" 49 | version = "1.4.3" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 52 | 53 | [[package]] 54 | name = "bytes" 55 | version = "1.1.0" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" 58 | 59 | [[package]] 60 | name = "cc" 61 | version = "1.0.73" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" 64 | 65 | [[package]] 66 | name = "cfg-if" 67 | version = "0.1.10" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 70 | 71 | [[package]] 72 | name = "cfg-if" 73 | version = "1.0.0" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 76 | 77 | [[package]] 78 | name = "chrono" 79 | version = "0.4.19" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" 82 | dependencies = [ 83 | "libc", 84 | "num-integer", 85 | "num-traits", 86 | "time", 87 | "winapi", 88 | ] 89 | 90 | [[package]] 91 | name = "cloudabi" 92 | version = "0.0.3" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 95 | dependencies = [ 96 | "bitflags", 97 | ] 98 | 99 | [[package]] 100 | name = "core-foundation" 101 | version = "0.9.3" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" 104 | dependencies = [ 105 | "core-foundation-sys", 106 | "libc", 107 | ] 108 | 109 | [[package]] 110 | name = "core-foundation-sys" 111 | version = "0.8.3" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" 114 | 115 | [[package]] 116 | name = "crossbeam-channel" 117 | version = "0.3.9" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa" 120 | dependencies = [ 121 | "crossbeam-utils", 122 | ] 123 | 124 | [[package]] 125 | name = "crossbeam-utils" 126 | version = "0.6.6" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" 129 | dependencies = [ 130 | "cfg-if 0.1.10", 131 | "lazy_static", 132 | ] 133 | 134 | [[package]] 135 | name = "encoding_rs" 136 | version = "0.8.30" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" 139 | dependencies = [ 140 | "cfg-if 1.0.0", 141 | ] 142 | 143 | [[package]] 144 | name = "ethereal_lang" 145 | version = "0.1.0" 146 | dependencies = [ 147 | "lazy_static", 148 | "rand 0.8.5", 149 | "reqwest", 150 | "rust-crypto", 151 | "rusty_express", 152 | "serde_json", 153 | "vfs", 154 | "wasm-bindgen", 155 | ] 156 | 157 | [[package]] 158 | name = "fastrand" 159 | version = "1.7.0" 160 | source = "registry+https://github.com/rust-lang/crates.io-index" 161 | checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" 162 | dependencies = [ 163 | "instant", 164 | ] 165 | 166 | [[package]] 167 | name = "fnv" 168 | version = "1.0.7" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 171 | 172 | [[package]] 173 | name = "foreign-types" 174 | version = "0.3.2" 175 | source = "registry+https://github.com/rust-lang/crates.io-index" 176 | checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" 177 | dependencies = [ 178 | "foreign-types-shared", 179 | ] 180 | 181 | [[package]] 182 | name = "foreign-types-shared" 183 | version = "0.1.1" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" 186 | 187 | [[package]] 188 | name = "form_urlencoded" 189 | version = "1.0.1" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" 192 | dependencies = [ 193 | "matches", 194 | "percent-encoding", 195 | ] 196 | 197 | [[package]] 198 | name = "fuchsia-cprng" 199 | version = "0.1.1" 200 | source = "registry+https://github.com/rust-lang/crates.io-index" 201 | checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 202 | 203 | [[package]] 204 | name = "futures-channel" 205 | version = "0.3.21" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" 208 | dependencies = [ 209 | "futures-core", 210 | ] 211 | 212 | [[package]] 213 | name = "futures-core" 214 | version = "0.3.21" 215 | source = "registry+https://github.com/rust-lang/crates.io-index" 216 | checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" 217 | 218 | [[package]] 219 | name = "futures-io" 220 | version = "0.3.21" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" 223 | 224 | [[package]] 225 | name = "futures-sink" 226 | version = "0.3.21" 227 | source = "registry+https://github.com/rust-lang/crates.io-index" 228 | checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" 229 | 230 | [[package]] 231 | name = "futures-task" 232 | version = "0.3.21" 233 | source = "registry+https://github.com/rust-lang/crates.io-index" 234 | checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" 235 | 236 | [[package]] 237 | name = "futures-util" 238 | version = "0.3.21" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" 241 | dependencies = [ 242 | "futures-core", 243 | "futures-io", 244 | "futures-task", 245 | "memchr", 246 | "pin-project-lite", 247 | "pin-utils", 248 | "slab", 249 | ] 250 | 251 | [[package]] 252 | name = "gcc" 253 | version = "0.3.55" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" 256 | 257 | [[package]] 258 | name = "getrandom" 259 | version = "0.2.5" 260 | source = "registry+https://github.com/rust-lang/crates.io-index" 261 | checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" 262 | dependencies = [ 263 | "cfg-if 1.0.0", 264 | "libc", 265 | "wasi", 266 | ] 267 | 268 | [[package]] 269 | name = "h2" 270 | version = "0.3.12" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "62eeb471aa3e3c9197aa4bfeabfe02982f6dc96f750486c0bb0009ac58b26d2b" 273 | dependencies = [ 274 | "bytes", 275 | "fnv", 276 | "futures-core", 277 | "futures-sink", 278 | "futures-util", 279 | "http", 280 | "indexmap", 281 | "slab", 282 | "tokio", 283 | "tokio-util", 284 | "tracing", 285 | ] 286 | 287 | [[package]] 288 | name = "hashbrown" 289 | version = "0.1.8" 290 | source = "registry+https://github.com/rust-lang/crates.io-index" 291 | checksum = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" 292 | dependencies = [ 293 | "byteorder", 294 | "scopeguard", 295 | ] 296 | 297 | [[package]] 298 | name = "hashbrown" 299 | version = "0.11.2" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" 302 | 303 | [[package]] 304 | name = "hermit-abi" 305 | version = "0.1.19" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 308 | dependencies = [ 309 | "libc", 310 | ] 311 | 312 | [[package]] 313 | name = "http" 314 | version = "0.2.6" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" 317 | dependencies = [ 318 | "bytes", 319 | "fnv", 320 | "itoa", 321 | ] 322 | 323 | [[package]] 324 | name = "http-body" 325 | version = "0.4.4" 326 | source = "registry+https://github.com/rust-lang/crates.io-index" 327 | checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" 328 | dependencies = [ 329 | "bytes", 330 | "http", 331 | "pin-project-lite", 332 | ] 333 | 334 | [[package]] 335 | name = "httparse" 336 | version = "1.6.0" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" 339 | 340 | [[package]] 341 | name = "httpdate" 342 | version = "1.0.2" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" 345 | 346 | [[package]] 347 | name = "hyper" 348 | version = "0.14.17" 349 | source = "registry+https://github.com/rust-lang/crates.io-index" 350 | checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" 351 | dependencies = [ 352 | "bytes", 353 | "futures-channel", 354 | "futures-core", 355 | "futures-util", 356 | "h2", 357 | "http", 358 | "http-body", 359 | "httparse", 360 | "httpdate", 361 | "itoa", 362 | "pin-project-lite", 363 | "socket2", 364 | "tokio", 365 | "tower-service", 366 | "tracing", 367 | "want", 368 | ] 369 | 370 | [[package]] 371 | name = "hyper-tls" 372 | version = "0.5.0" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" 375 | dependencies = [ 376 | "bytes", 377 | "hyper", 378 | "native-tls", 379 | "tokio", 380 | "tokio-native-tls", 381 | ] 382 | 383 | [[package]] 384 | name = "idna" 385 | version = "0.2.3" 386 | source = "registry+https://github.com/rust-lang/crates.io-index" 387 | checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" 388 | dependencies = [ 389 | "matches", 390 | "unicode-bidi", 391 | "unicode-normalization", 392 | ] 393 | 394 | [[package]] 395 | name = "indexmap" 396 | version = "1.8.0" 397 | source = "registry+https://github.com/rust-lang/crates.io-index" 398 | checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" 399 | dependencies = [ 400 | "autocfg 1.1.0", 401 | "hashbrown 0.11.2", 402 | ] 403 | 404 | [[package]] 405 | name = "instant" 406 | version = "0.1.12" 407 | source = "registry+https://github.com/rust-lang/crates.io-index" 408 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 409 | dependencies = [ 410 | "cfg-if 1.0.0", 411 | ] 412 | 413 | [[package]] 414 | name = "ipnet" 415 | version = "2.4.0" 416 | source = "registry+https://github.com/rust-lang/crates.io-index" 417 | checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c" 418 | 419 | [[package]] 420 | name = "itoa" 421 | version = "1.0.1" 422 | source = "registry+https://github.com/rust-lang/crates.io-index" 423 | checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" 424 | 425 | [[package]] 426 | name = "js-sys" 427 | version = "0.3.56" 428 | source = "registry+https://github.com/rust-lang/crates.io-index" 429 | checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" 430 | dependencies = [ 431 | "wasm-bindgen", 432 | ] 433 | 434 | [[package]] 435 | name = "lazy_static" 436 | version = "1.4.0" 437 | source = "registry+https://github.com/rust-lang/crates.io-index" 438 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 439 | 440 | [[package]] 441 | name = "libc" 442 | version = "0.2.119" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" 445 | 446 | [[package]] 447 | name = "lock_api" 448 | version = "0.1.5" 449 | source = "registry+https://github.com/rust-lang/crates.io-index" 450 | checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" 451 | dependencies = [ 452 | "owning_ref", 453 | "scopeguard", 454 | ] 455 | 456 | [[package]] 457 | name = "log" 458 | version = "0.4.14" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 461 | dependencies = [ 462 | "cfg-if 1.0.0", 463 | ] 464 | 465 | [[package]] 466 | name = "matches" 467 | version = "0.1.9" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" 470 | 471 | [[package]] 472 | name = "maybe-uninit" 473 | version = "2.0.0" 474 | source = "registry+https://github.com/rust-lang/crates.io-index" 475 | checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" 476 | 477 | [[package]] 478 | name = "memchr" 479 | version = "2.4.1" 480 | source = "registry+https://github.com/rust-lang/crates.io-index" 481 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 482 | 483 | [[package]] 484 | name = "mime" 485 | version = "0.3.16" 486 | source = "registry+https://github.com/rust-lang/crates.io-index" 487 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" 488 | 489 | [[package]] 490 | name = "mio" 491 | version = "0.8.0" 492 | source = "registry+https://github.com/rust-lang/crates.io-index" 493 | checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" 494 | dependencies = [ 495 | "libc", 496 | "log", 497 | "miow", 498 | "ntapi", 499 | "winapi", 500 | ] 501 | 502 | [[package]] 503 | name = "miow" 504 | version = "0.3.7" 505 | source = "registry+https://github.com/rust-lang/crates.io-index" 506 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 507 | dependencies = [ 508 | "winapi", 509 | ] 510 | 511 | [[package]] 512 | name = "native-tls" 513 | version = "0.2.8" 514 | source = "registry+https://github.com/rust-lang/crates.io-index" 515 | checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" 516 | dependencies = [ 517 | "lazy_static", 518 | "libc", 519 | "log", 520 | "openssl", 521 | "openssl-probe", 522 | "openssl-sys", 523 | "schannel", 524 | "security-framework", 525 | "security-framework-sys", 526 | "tempfile", 527 | ] 528 | 529 | [[package]] 530 | name = "ntapi" 531 | version = "0.3.7" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" 534 | dependencies = [ 535 | "winapi", 536 | ] 537 | 538 | [[package]] 539 | name = "num-integer" 540 | version = "0.1.44" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" 543 | dependencies = [ 544 | "autocfg 1.1.0", 545 | "num-traits", 546 | ] 547 | 548 | [[package]] 549 | name = "num-traits" 550 | version = "0.2.14" 551 | source = "registry+https://github.com/rust-lang/crates.io-index" 552 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 553 | dependencies = [ 554 | "autocfg 1.1.0", 555 | ] 556 | 557 | [[package]] 558 | name = "num_cpus" 559 | version = "1.13.1" 560 | source = "registry+https://github.com/rust-lang/crates.io-index" 561 | checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" 562 | dependencies = [ 563 | "hermit-abi", 564 | "libc", 565 | ] 566 | 567 | [[package]] 568 | name = "once_cell" 569 | version = "1.10.0" 570 | source = "registry+https://github.com/rust-lang/crates.io-index" 571 | checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" 572 | 573 | [[package]] 574 | name = "openssl" 575 | version = "0.10.38" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" 578 | dependencies = [ 579 | "bitflags", 580 | "cfg-if 1.0.0", 581 | "foreign-types", 582 | "libc", 583 | "once_cell", 584 | "openssl-sys", 585 | ] 586 | 587 | [[package]] 588 | name = "openssl-probe" 589 | version = "0.1.5" 590 | source = "registry+https://github.com/rust-lang/crates.io-index" 591 | checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" 592 | 593 | [[package]] 594 | name = "openssl-sys" 595 | version = "0.9.72" 596 | source = "registry+https://github.com/rust-lang/crates.io-index" 597 | checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" 598 | dependencies = [ 599 | "autocfg 1.1.0", 600 | "cc", 601 | "libc", 602 | "pkg-config", 603 | "vcpkg", 604 | ] 605 | 606 | [[package]] 607 | name = "owning_ref" 608 | version = "0.4.1" 609 | source = "registry+https://github.com/rust-lang/crates.io-index" 610 | checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" 611 | dependencies = [ 612 | "stable_deref_trait", 613 | ] 614 | 615 | [[package]] 616 | name = "parking_lot" 617 | version = "0.7.1" 618 | source = "registry+https://github.com/rust-lang/crates.io-index" 619 | checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" 620 | dependencies = [ 621 | "lock_api", 622 | "parking_lot_core", 623 | ] 624 | 625 | [[package]] 626 | name = "parking_lot_core" 627 | version = "0.4.0" 628 | source = "registry+https://github.com/rust-lang/crates.io-index" 629 | checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" 630 | dependencies = [ 631 | "libc", 632 | "rand 0.6.5", 633 | "rustc_version", 634 | "smallvec", 635 | "winapi", 636 | ] 637 | 638 | [[package]] 639 | name = "percent-encoding" 640 | version = "2.1.0" 641 | source = "registry+https://github.com/rust-lang/crates.io-index" 642 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 643 | 644 | [[package]] 645 | name = "pin-project-lite" 646 | version = "0.2.8" 647 | source = "registry+https://github.com/rust-lang/crates.io-index" 648 | checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" 649 | 650 | [[package]] 651 | name = "pin-utils" 652 | version = "0.1.0" 653 | source = "registry+https://github.com/rust-lang/crates.io-index" 654 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 655 | 656 | [[package]] 657 | name = "pkg-config" 658 | version = "0.3.24" 659 | source = "registry+https://github.com/rust-lang/crates.io-index" 660 | checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" 661 | 662 | [[package]] 663 | name = "ppv-lite86" 664 | version = "0.2.16" 665 | source = "registry+https://github.com/rust-lang/crates.io-index" 666 | checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" 667 | 668 | [[package]] 669 | name = "proc-macro2" 670 | version = "1.0.36" 671 | source = "registry+https://github.com/rust-lang/crates.io-index" 672 | checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 673 | dependencies = [ 674 | "unicode-xid", 675 | ] 676 | 677 | [[package]] 678 | name = "quote" 679 | version = "1.0.15" 680 | source = "registry+https://github.com/rust-lang/crates.io-index" 681 | checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" 682 | dependencies = [ 683 | "proc-macro2", 684 | ] 685 | 686 | [[package]] 687 | name = "rand" 688 | version = "0.3.23" 689 | source = "registry+https://github.com/rust-lang/crates.io-index" 690 | checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" 691 | dependencies = [ 692 | "libc", 693 | "rand 0.4.6", 694 | ] 695 | 696 | [[package]] 697 | name = "rand" 698 | version = "0.4.6" 699 | source = "registry+https://github.com/rust-lang/crates.io-index" 700 | checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" 701 | dependencies = [ 702 | "fuchsia-cprng", 703 | "libc", 704 | "rand_core 0.3.1", 705 | "rdrand", 706 | "winapi", 707 | ] 708 | 709 | [[package]] 710 | name = "rand" 711 | version = "0.6.5" 712 | source = "registry+https://github.com/rust-lang/crates.io-index" 713 | checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" 714 | dependencies = [ 715 | "autocfg 0.1.8", 716 | "libc", 717 | "rand_chacha 0.1.1", 718 | "rand_core 0.4.2", 719 | "rand_hc", 720 | "rand_isaac", 721 | "rand_jitter", 722 | "rand_os", 723 | "rand_pcg", 724 | "rand_xorshift", 725 | "winapi", 726 | ] 727 | 728 | [[package]] 729 | name = "rand" 730 | version = "0.8.5" 731 | source = "registry+https://github.com/rust-lang/crates.io-index" 732 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 733 | dependencies = [ 734 | "libc", 735 | "rand_chacha 0.3.1", 736 | "rand_core 0.6.3", 737 | ] 738 | 739 | [[package]] 740 | name = "rand_chacha" 741 | version = "0.1.1" 742 | source = "registry+https://github.com/rust-lang/crates.io-index" 743 | checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" 744 | dependencies = [ 745 | "autocfg 0.1.8", 746 | "rand_core 0.3.1", 747 | ] 748 | 749 | [[package]] 750 | name = "rand_chacha" 751 | version = "0.3.1" 752 | source = "registry+https://github.com/rust-lang/crates.io-index" 753 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" 754 | dependencies = [ 755 | "ppv-lite86", 756 | "rand_core 0.6.3", 757 | ] 758 | 759 | [[package]] 760 | name = "rand_core" 761 | version = "0.3.1" 762 | source = "registry+https://github.com/rust-lang/crates.io-index" 763 | checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 764 | dependencies = [ 765 | "rand_core 0.4.2", 766 | ] 767 | 768 | [[package]] 769 | name = "rand_core" 770 | version = "0.4.2" 771 | source = "registry+https://github.com/rust-lang/crates.io-index" 772 | checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" 773 | 774 | [[package]] 775 | name = "rand_core" 776 | version = "0.6.3" 777 | source = "registry+https://github.com/rust-lang/crates.io-index" 778 | checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" 779 | dependencies = [ 780 | "getrandom", 781 | ] 782 | 783 | [[package]] 784 | name = "rand_hc" 785 | version = "0.1.0" 786 | source = "registry+https://github.com/rust-lang/crates.io-index" 787 | checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" 788 | dependencies = [ 789 | "rand_core 0.3.1", 790 | ] 791 | 792 | [[package]] 793 | name = "rand_isaac" 794 | version = "0.1.1" 795 | source = "registry+https://github.com/rust-lang/crates.io-index" 796 | checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" 797 | dependencies = [ 798 | "rand_core 0.3.1", 799 | ] 800 | 801 | [[package]] 802 | name = "rand_jitter" 803 | version = "0.1.4" 804 | source = "registry+https://github.com/rust-lang/crates.io-index" 805 | checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" 806 | dependencies = [ 807 | "libc", 808 | "rand_core 0.4.2", 809 | "winapi", 810 | ] 811 | 812 | [[package]] 813 | name = "rand_os" 814 | version = "0.1.3" 815 | source = "registry+https://github.com/rust-lang/crates.io-index" 816 | checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" 817 | dependencies = [ 818 | "cloudabi", 819 | "fuchsia-cprng", 820 | "libc", 821 | "rand_core 0.4.2", 822 | "rdrand", 823 | "winapi", 824 | ] 825 | 826 | [[package]] 827 | name = "rand_pcg" 828 | version = "0.1.2" 829 | source = "registry+https://github.com/rust-lang/crates.io-index" 830 | checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" 831 | dependencies = [ 832 | "autocfg 0.1.8", 833 | "rand_core 0.4.2", 834 | ] 835 | 836 | [[package]] 837 | name = "rand_xorshift" 838 | version = "0.1.1" 839 | source = "registry+https://github.com/rust-lang/crates.io-index" 840 | checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" 841 | dependencies = [ 842 | "rand_core 0.3.1", 843 | ] 844 | 845 | [[package]] 846 | name = "rdrand" 847 | version = "0.4.0" 848 | source = "registry+https://github.com/rust-lang/crates.io-index" 849 | checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 850 | dependencies = [ 851 | "rand_core 0.3.1", 852 | ] 853 | 854 | [[package]] 855 | name = "redox_syscall" 856 | version = "0.2.11" 857 | source = "registry+https://github.com/rust-lang/crates.io-index" 858 | checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" 859 | dependencies = [ 860 | "bitflags", 861 | ] 862 | 863 | [[package]] 864 | name = "regex" 865 | version = "0.2.11" 866 | source = "registry+https://github.com/rust-lang/crates.io-index" 867 | checksum = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" 868 | dependencies = [ 869 | "aho-corasick", 870 | "memchr", 871 | "regex-syntax", 872 | "thread_local", 873 | "utf8-ranges", 874 | ] 875 | 876 | [[package]] 877 | name = "regex-syntax" 878 | version = "0.5.6" 879 | source = "registry+https://github.com/rust-lang/crates.io-index" 880 | checksum = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" 881 | dependencies = [ 882 | "ucd-util", 883 | ] 884 | 885 | [[package]] 886 | name = "remove_dir_all" 887 | version = "0.5.3" 888 | source = "registry+https://github.com/rust-lang/crates.io-index" 889 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 890 | dependencies = [ 891 | "winapi", 892 | ] 893 | 894 | [[package]] 895 | name = "reqwest" 896 | version = "0.11.10" 897 | source = "registry+https://github.com/rust-lang/crates.io-index" 898 | checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" 899 | dependencies = [ 900 | "base64", 901 | "bytes", 902 | "encoding_rs", 903 | "futures-core", 904 | "futures-util", 905 | "h2", 906 | "http", 907 | "http-body", 908 | "hyper", 909 | "hyper-tls", 910 | "ipnet", 911 | "js-sys", 912 | "lazy_static", 913 | "log", 914 | "mime", 915 | "native-tls", 916 | "percent-encoding", 917 | "pin-project-lite", 918 | "serde", 919 | "serde_json", 920 | "serde_urlencoded", 921 | "tokio", 922 | "tokio-native-tls", 923 | "url", 924 | "wasm-bindgen", 925 | "wasm-bindgen-futures", 926 | "web-sys", 927 | "winreg", 928 | ] 929 | 930 | [[package]] 931 | name = "rust-crypto" 932 | version = "0.2.36" 933 | source = "registry+https://github.com/rust-lang/crates.io-index" 934 | checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" 935 | dependencies = [ 936 | "gcc", 937 | "libc", 938 | "rand 0.3.23", 939 | "rustc-serialize", 940 | "time", 941 | ] 942 | 943 | [[package]] 944 | name = "rustc-serialize" 945 | version = "0.3.24" 946 | source = "registry+https://github.com/rust-lang/crates.io-index" 947 | checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" 948 | 949 | [[package]] 950 | name = "rustc_version" 951 | version = "0.2.3" 952 | source = "registry+https://github.com/rust-lang/crates.io-index" 953 | checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 954 | dependencies = [ 955 | "semver", 956 | ] 957 | 958 | [[package]] 959 | name = "rusty_express" 960 | version = "0.4.3" 961 | source = "registry+https://github.com/rust-lang/crates.io-index" 962 | checksum = "228974c2e3c62588e18465e739434b8fceace0041598e09571afcdadbc6a0ffe" 963 | dependencies = [ 964 | "chrono", 965 | "crossbeam-channel", 966 | "hashbrown 0.1.8", 967 | "lazy_static", 968 | "native-tls", 969 | "num_cpus", 970 | "parking_lot", 971 | "rand 0.4.6", 972 | "regex", 973 | ] 974 | 975 | [[package]] 976 | name = "ryu" 977 | version = "1.0.9" 978 | source = "registry+https://github.com/rust-lang/crates.io-index" 979 | checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" 980 | 981 | [[package]] 982 | name = "schannel" 983 | version = "0.1.19" 984 | source = "registry+https://github.com/rust-lang/crates.io-index" 985 | checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" 986 | dependencies = [ 987 | "lazy_static", 988 | "winapi", 989 | ] 990 | 991 | [[package]] 992 | name = "scopeguard" 993 | version = "0.3.3" 994 | source = "registry+https://github.com/rust-lang/crates.io-index" 995 | checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 996 | 997 | [[package]] 998 | name = "security-framework" 999 | version = "2.6.1" 1000 | source = "registry+https://github.com/rust-lang/crates.io-index" 1001 | checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" 1002 | dependencies = [ 1003 | "bitflags", 1004 | "core-foundation", 1005 | "core-foundation-sys", 1006 | "libc", 1007 | "security-framework-sys", 1008 | ] 1009 | 1010 | [[package]] 1011 | name = "security-framework-sys" 1012 | version = "2.6.1" 1013 | source = "registry+https://github.com/rust-lang/crates.io-index" 1014 | checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" 1015 | dependencies = [ 1016 | "core-foundation-sys", 1017 | "libc", 1018 | ] 1019 | 1020 | [[package]] 1021 | name = "semver" 1022 | version = "0.9.0" 1023 | source = "registry+https://github.com/rust-lang/crates.io-index" 1024 | checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1025 | dependencies = [ 1026 | "semver-parser", 1027 | ] 1028 | 1029 | [[package]] 1030 | name = "semver-parser" 1031 | version = "0.7.0" 1032 | source = "registry+https://github.com/rust-lang/crates.io-index" 1033 | checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 1034 | 1035 | [[package]] 1036 | name = "serde" 1037 | version = "1.0.136" 1038 | source = "registry+https://github.com/rust-lang/crates.io-index" 1039 | checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" 1040 | 1041 | [[package]] 1042 | name = "serde_json" 1043 | version = "1.0.79" 1044 | source = "registry+https://github.com/rust-lang/crates.io-index" 1045 | checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" 1046 | dependencies = [ 1047 | "itoa", 1048 | "ryu", 1049 | "serde", 1050 | ] 1051 | 1052 | [[package]] 1053 | name = "serde_urlencoded" 1054 | version = "0.7.1" 1055 | source = "registry+https://github.com/rust-lang/crates.io-index" 1056 | checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" 1057 | dependencies = [ 1058 | "form_urlencoded", 1059 | "itoa", 1060 | "ryu", 1061 | "serde", 1062 | ] 1063 | 1064 | [[package]] 1065 | name = "slab" 1066 | version = "0.4.5" 1067 | source = "registry+https://github.com/rust-lang/crates.io-index" 1068 | checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" 1069 | 1070 | [[package]] 1071 | name = "smallvec" 1072 | version = "0.6.14" 1073 | source = "registry+https://github.com/rust-lang/crates.io-index" 1074 | checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" 1075 | dependencies = [ 1076 | "maybe-uninit", 1077 | ] 1078 | 1079 | [[package]] 1080 | name = "socket2" 1081 | version = "0.4.4" 1082 | source = "registry+https://github.com/rust-lang/crates.io-index" 1083 | checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" 1084 | dependencies = [ 1085 | "libc", 1086 | "winapi", 1087 | ] 1088 | 1089 | [[package]] 1090 | name = "stable_deref_trait" 1091 | version = "1.2.0" 1092 | source = "registry+https://github.com/rust-lang/crates.io-index" 1093 | checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" 1094 | 1095 | [[package]] 1096 | name = "syn" 1097 | version = "1.0.86" 1098 | source = "registry+https://github.com/rust-lang/crates.io-index" 1099 | checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" 1100 | dependencies = [ 1101 | "proc-macro2", 1102 | "quote", 1103 | "unicode-xid", 1104 | ] 1105 | 1106 | [[package]] 1107 | name = "tempfile" 1108 | version = "3.3.0" 1109 | source = "registry+https://github.com/rust-lang/crates.io-index" 1110 | checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" 1111 | dependencies = [ 1112 | "cfg-if 1.0.0", 1113 | "fastrand", 1114 | "libc", 1115 | "redox_syscall", 1116 | "remove_dir_all", 1117 | "winapi", 1118 | ] 1119 | 1120 | [[package]] 1121 | name = "thread_local" 1122 | version = "0.3.6" 1123 | source = "registry+https://github.com/rust-lang/crates.io-index" 1124 | checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 1125 | dependencies = [ 1126 | "lazy_static", 1127 | ] 1128 | 1129 | [[package]] 1130 | name = "time" 1131 | version = "0.1.44" 1132 | source = "registry+https://github.com/rust-lang/crates.io-index" 1133 | checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" 1134 | dependencies = [ 1135 | "libc", 1136 | "wasi", 1137 | "winapi", 1138 | ] 1139 | 1140 | [[package]] 1141 | name = "tinyvec" 1142 | version = "1.5.1" 1143 | source = "registry+https://github.com/rust-lang/crates.io-index" 1144 | checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" 1145 | dependencies = [ 1146 | "tinyvec_macros", 1147 | ] 1148 | 1149 | [[package]] 1150 | name = "tinyvec_macros" 1151 | version = "0.1.0" 1152 | source = "registry+https://github.com/rust-lang/crates.io-index" 1153 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 1154 | 1155 | [[package]] 1156 | name = "tokio" 1157 | version = "1.17.0" 1158 | source = "registry+https://github.com/rust-lang/crates.io-index" 1159 | checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" 1160 | dependencies = [ 1161 | "bytes", 1162 | "libc", 1163 | "memchr", 1164 | "mio", 1165 | "num_cpus", 1166 | "pin-project-lite", 1167 | "socket2", 1168 | "winapi", 1169 | ] 1170 | 1171 | [[package]] 1172 | name = "tokio-native-tls" 1173 | version = "0.3.0" 1174 | source = "registry+https://github.com/rust-lang/crates.io-index" 1175 | checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" 1176 | dependencies = [ 1177 | "native-tls", 1178 | "tokio", 1179 | ] 1180 | 1181 | [[package]] 1182 | name = "tokio-util" 1183 | version = "0.6.9" 1184 | source = "registry+https://github.com/rust-lang/crates.io-index" 1185 | checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" 1186 | dependencies = [ 1187 | "bytes", 1188 | "futures-core", 1189 | "futures-sink", 1190 | "log", 1191 | "pin-project-lite", 1192 | "tokio", 1193 | ] 1194 | 1195 | [[package]] 1196 | name = "tower-service" 1197 | version = "0.3.1" 1198 | source = "registry+https://github.com/rust-lang/crates.io-index" 1199 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" 1200 | 1201 | [[package]] 1202 | name = "tracing" 1203 | version = "0.1.32" 1204 | source = "registry+https://github.com/rust-lang/crates.io-index" 1205 | checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" 1206 | dependencies = [ 1207 | "cfg-if 1.0.0", 1208 | "pin-project-lite", 1209 | "tracing-core", 1210 | ] 1211 | 1212 | [[package]] 1213 | name = "tracing-core" 1214 | version = "0.1.23" 1215 | source = "registry+https://github.com/rust-lang/crates.io-index" 1216 | checksum = "aa31669fa42c09c34d94d8165dd2012e8ff3c66aca50f3bb226b68f216f2706c" 1217 | dependencies = [ 1218 | "lazy_static", 1219 | ] 1220 | 1221 | [[package]] 1222 | name = "try-lock" 1223 | version = "0.2.3" 1224 | source = "registry+https://github.com/rust-lang/crates.io-index" 1225 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" 1226 | 1227 | [[package]] 1228 | name = "ucd-util" 1229 | version = "0.1.8" 1230 | source = "registry+https://github.com/rust-lang/crates.io-index" 1231 | checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" 1232 | 1233 | [[package]] 1234 | name = "unicode-bidi" 1235 | version = "0.3.7" 1236 | source = "registry+https://github.com/rust-lang/crates.io-index" 1237 | checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" 1238 | 1239 | [[package]] 1240 | name = "unicode-normalization" 1241 | version = "0.1.19" 1242 | source = "registry+https://github.com/rust-lang/crates.io-index" 1243 | checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" 1244 | dependencies = [ 1245 | "tinyvec", 1246 | ] 1247 | 1248 | [[package]] 1249 | name = "unicode-xid" 1250 | version = "0.2.2" 1251 | source = "registry+https://github.com/rust-lang/crates.io-index" 1252 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 1253 | 1254 | [[package]] 1255 | name = "url" 1256 | version = "2.2.2" 1257 | source = "registry+https://github.com/rust-lang/crates.io-index" 1258 | checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" 1259 | dependencies = [ 1260 | "form_urlencoded", 1261 | "idna", 1262 | "matches", 1263 | "percent-encoding", 1264 | ] 1265 | 1266 | [[package]] 1267 | name = "utf8-ranges" 1268 | version = "1.0.4" 1269 | source = "registry+https://github.com/rust-lang/crates.io-index" 1270 | checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" 1271 | 1272 | [[package]] 1273 | name = "vcpkg" 1274 | version = "0.2.15" 1275 | source = "registry+https://github.com/rust-lang/crates.io-index" 1276 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 1277 | 1278 | [[package]] 1279 | name = "vfs" 1280 | version = "0.6.2" 1281 | source = "registry+https://github.com/rust-lang/crates.io-index" 1282 | checksum = "28aa479622463b2e2775195731def3bf69bb4a0a73095467f80b1450c30d6e52" 1283 | 1284 | [[package]] 1285 | name = "want" 1286 | version = "0.3.0" 1287 | source = "registry+https://github.com/rust-lang/crates.io-index" 1288 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" 1289 | dependencies = [ 1290 | "log", 1291 | "try-lock", 1292 | ] 1293 | 1294 | [[package]] 1295 | name = "wasi" 1296 | version = "0.10.0+wasi-snapshot-preview1" 1297 | source = "registry+https://github.com/rust-lang/crates.io-index" 1298 | checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" 1299 | 1300 | [[package]] 1301 | name = "wasm-bindgen" 1302 | version = "0.2.79" 1303 | source = "registry+https://github.com/rust-lang/crates.io-index" 1304 | checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" 1305 | dependencies = [ 1306 | "cfg-if 1.0.0", 1307 | "wasm-bindgen-macro", 1308 | ] 1309 | 1310 | [[package]] 1311 | name = "wasm-bindgen-backend" 1312 | version = "0.2.79" 1313 | source = "registry+https://github.com/rust-lang/crates.io-index" 1314 | checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" 1315 | dependencies = [ 1316 | "bumpalo", 1317 | "lazy_static", 1318 | "log", 1319 | "proc-macro2", 1320 | "quote", 1321 | "syn", 1322 | "wasm-bindgen-shared", 1323 | ] 1324 | 1325 | [[package]] 1326 | name = "wasm-bindgen-futures" 1327 | version = "0.4.29" 1328 | source = "registry+https://github.com/rust-lang/crates.io-index" 1329 | checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" 1330 | dependencies = [ 1331 | "cfg-if 1.0.0", 1332 | "js-sys", 1333 | "wasm-bindgen", 1334 | "web-sys", 1335 | ] 1336 | 1337 | [[package]] 1338 | name = "wasm-bindgen-macro" 1339 | version = "0.2.79" 1340 | source = "registry+https://github.com/rust-lang/crates.io-index" 1341 | checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" 1342 | dependencies = [ 1343 | "quote", 1344 | "wasm-bindgen-macro-support", 1345 | ] 1346 | 1347 | [[package]] 1348 | name = "wasm-bindgen-macro-support" 1349 | version = "0.2.79" 1350 | source = "registry+https://github.com/rust-lang/crates.io-index" 1351 | checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" 1352 | dependencies = [ 1353 | "proc-macro2", 1354 | "quote", 1355 | "syn", 1356 | "wasm-bindgen-backend", 1357 | "wasm-bindgen-shared", 1358 | ] 1359 | 1360 | [[package]] 1361 | name = "wasm-bindgen-shared" 1362 | version = "0.2.79" 1363 | source = "registry+https://github.com/rust-lang/crates.io-index" 1364 | checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" 1365 | 1366 | [[package]] 1367 | name = "web-sys" 1368 | version = "0.3.56" 1369 | source = "registry+https://github.com/rust-lang/crates.io-index" 1370 | checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" 1371 | dependencies = [ 1372 | "js-sys", 1373 | "wasm-bindgen", 1374 | ] 1375 | 1376 | [[package]] 1377 | name = "winapi" 1378 | version = "0.3.9" 1379 | source = "registry+https://github.com/rust-lang/crates.io-index" 1380 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1381 | dependencies = [ 1382 | "winapi-i686-pc-windows-gnu", 1383 | "winapi-x86_64-pc-windows-gnu", 1384 | ] 1385 | 1386 | [[package]] 1387 | name = "winapi-i686-pc-windows-gnu" 1388 | version = "0.4.0" 1389 | source = "registry+https://github.com/rust-lang/crates.io-index" 1390 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1391 | 1392 | [[package]] 1393 | name = "winapi-x86_64-pc-windows-gnu" 1394 | version = "0.4.0" 1395 | source = "registry+https://github.com/rust-lang/crates.io-index" 1396 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1397 | 1398 | [[package]] 1399 | name = "winreg" 1400 | version = "0.10.1" 1401 | source = "registry+https://github.com/rust-lang/crates.io-index" 1402 | checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" 1403 | dependencies = [ 1404 | "winapi", 1405 | ] 1406 | --------------------------------------------------------------------------------