Skip to content

Commit

Permalink
Update main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KajizukaTaichi committed Jan 3, 2025
1 parent df77112 commit 1cae3f0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use reqwest::blocking;
use rustyline::{error::ReadlineError, DefaultEditor};
use std::{
collections::HashMap,
f64::consts::PI,
fs::{read_to_string, File},
io::{self, Write},
process::exit,
Expand Down Expand Up @@ -67,11 +68,25 @@ type Program = Vec<Statement>;
#[derive(Debug, Clone)]
struct Engine {
env: Scope,
protect: Vec<String>,
}

impl Engine {
fn new() -> Engine {
Engine {
protect: vec![
"type".to_string(),
"env".to_string(),
"free".to_string(),
"eval".to_string(),
"alphaConvert".to_string(),
"input".to_string(),
"range".to_string(),
"exit".to_string(),
"load".to_string(),
"save".to_string(),
"pi".to_string(),
],
env: HashMap::from([
(
"type".to_string(),
Expand Down Expand Up @@ -213,6 +228,7 @@ impl Engine {
}
})),
),
("pi".to_string(), Type::Number(PI)),
]),
}
}
Expand Down Expand Up @@ -269,6 +285,9 @@ impl Statement {
}
Statement::Let(name, sig, expr) => {
let val = expr.eval(engine)?;
if engine.protect.contains(name) {
return None;
}
if let Some(sig) = sig {
if val.get_type().format() != sig.format() {
return None;
Expand Down

0 comments on commit 1cae3f0

Please sign in to comment.