From 1cae3f06dd7750ce272cc4139df4544f28226e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Fri, 3 Jan 2025 21:26:18 +0900 Subject: [PATCH] Update main.rs --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.rs b/src/main.rs index cb49180..79263d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, @@ -67,11 +68,25 @@ type Program = Vec; #[derive(Debug, Clone)] struct Engine { env: Scope, + protect: Vec, } 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(), @@ -213,6 +228,7 @@ impl Engine { } })), ), + ("pi".to_string(), Type::Number(PI)), ]), } } @@ -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;