.
.
This commit is contained in:
Generated
+7
@@ -17,6 +17,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libm",
|
"libm",
|
||||||
"linked_list_allocator",
|
"linked_list_allocator",
|
||||||
|
"log",
|
||||||
"pc-keyboard",
|
"pc-keyboard",
|
||||||
"pic8259",
|
"pic8259",
|
||||||
"rand",
|
"rand",
|
||||||
@@ -218,6 +219,12 @@ dependencies = [
|
|||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "maybe-uninit"
|
name = "maybe-uninit"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ rand = { version = "0.8.5", default-features = false, features = ["small_rng"]}
|
|||||||
hashbrown = "0.13.2"
|
hashbrown = "0.13.2"
|
||||||
cmos-rtc = "0.1.2"
|
cmos-rtc = "0.1.2"
|
||||||
libm = "0.2.7"
|
libm = "0.2.7"
|
||||||
|
log = "0.4.20"
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|||||||
+14
-32
@@ -51,7 +51,7 @@ impl Interpreter {
|
|||||||
|
|
||||||
let inner = self.visit(self.get_node(node.clone(), "argument")?.expect("returned none").to_owned())?;
|
let inner = self.visit(self.get_node(node.clone(), "argument")?.expect("returned none").to_owned())?;
|
||||||
if let Value::Number(x) = inner {
|
if let Value::Number(x) = inner {
|
||||||
return Ok(Value::Number(super::functions::run_func(function_name, x).unwrap()));
|
return Ok(Value::Number(super::functions::run_func(function_name, x).map_err(|x| Error::Other(x.to_string()))?));
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::Other(String::from("function argument is not a number")))
|
return Err(Error::Other(String::from("function argument is not a number")))
|
||||||
}
|
}
|
||||||
@@ -416,44 +416,25 @@ fn calculate_inner(mut equation: String) -> Result<f64, Error> {
|
|||||||
let mut neweq = equation.clone();
|
let mut neweq = equation.clone();
|
||||||
neweq.pop();
|
neweq.pop();
|
||||||
|
|
||||||
|
|
||||||
let tokens = tokenise(&equation)?;
|
let tokens = tokenise(&equation)?;
|
||||||
|
|
||||||
let mut parser = Parser::new(tokens)?;
|
let mut parser = Parser::new(tokens)?;
|
||||||
let ast = parser.parse()?;
|
let ast = parser.parse()?;
|
||||||
|
|
||||||
|
|
||||||
let mut interpreter = Interpreter::new()?;
|
let mut interpreter = Interpreter::new()?;
|
||||||
let result = interpreter.visit(ast)?;
|
let result = interpreter.visit(ast)?;
|
||||||
|
let return_res = if let Value::Number(x) = result {
|
||||||
let return_res = {
|
|
||||||
if let Value::Number(x) = result {
|
|
||||||
x
|
x
|
||||||
} else {
|
} else { panic!("the value returned was not a float! THIS IS A BUG") };
|
||||||
panic!("did not return a float!");
|
|
||||||
}
|
println!("
|
||||||
};
|
|
||||||
println!("\n\n
|
[ EXPRESSION ]
|
||||||
_____ _ _
|
|
||||||
/ ____| | | | |
|
{}
|
||||||
| | _ __ _ _ ___| |_ __ _| |
|
|
||||||
| | | '__| | | / __| __/ _` | |
|
[ RESULT ]
|
||||||
| |____| | | |_| \\__ \\ || (_| | |
|
|
||||||
\\_____|_| \\__, |___/\\__\\__,_|_|
|
{}
|
||||||
_____ __/ |
|
|
||||||
/ ____||___/ |
|
|
||||||
| | __ _| | ___
|
|
||||||
| | / _` | |/ __|
|
|
||||||
| |___| (_| | | (__
|
|
||||||
\\_____\\__,_|_|\\___|
|
|
||||||
|
|
||||||
┌────────────────────────────────────────────┐
|
|
||||||
│ │
|
|
||||||
│ Expression -> [ {} ]
|
|
||||||
│ │
|
|
||||||
│ Calculated Solution -> [ {} ]
|
|
||||||
│ │
|
|
||||||
└────────────────────────────────────────────┘
|
|
||||||
", neweq, return_res);
|
", neweq, return_res);
|
||||||
|
|
||||||
Ok(return_res)
|
Ok(return_res)
|
||||||
@@ -481,6 +462,7 @@ fn tokenise(equation: &str) -> Result<Vec<Token>, Error> {
|
|||||||
tokens.push(Token::Func(current_string.clone()));
|
tokens.push(Token::Func(current_string.clone()));
|
||||||
}
|
}
|
||||||
is_var = false;
|
is_var = false;
|
||||||
|
current_string = "".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ use alloc::string::String;
|
|||||||
use crate::println;
|
use crate::println;
|
||||||
|
|
||||||
pub fn run_func(func: String, x: f64) -> Result<f64, String> {
|
pub fn run_func(func: String, x: f64) -> Result<f64, String> {
|
||||||
println!("function being run: {}({})", func, x);
|
|
||||||
|
|
||||||
match func.as_str() {
|
match func.as_str() {
|
||||||
"sqrt" => sqrt(x),
|
"sqrt" => sqrt(x),
|
||||||
"ln" => ln(x),
|
"ln" => ln(x),
|
||||||
|
"fact" => factorial(x),
|
||||||
|
"sin" => sin(x),
|
||||||
|
"cos" => cos(x),
|
||||||
|
"tan" => tan(x),
|
||||||
_ => Err(String::from(format!("unrecognised function name: {}", func))),
|
_ => Err(String::from(format!("unrecognised function name: {}", func))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,3 +27,23 @@ fn ln(x: f64) -> Result<f64, String> {
|
|||||||
}
|
}
|
||||||
Ok(libm::log(x))
|
Ok(libm::log(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn factorial(x: f64) -> Result<f64, String> {
|
||||||
|
if x < 0.0 {
|
||||||
|
return Err(String::from("Cannot take the factorial of a negative number"));
|
||||||
|
}
|
||||||
|
let x = x as u64;
|
||||||
|
Ok((1..=x).fold(1, |a, b| a * b) as f64)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sin(x: f64) -> Result<f64, String> {
|
||||||
|
Ok(libm::sin(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cos(x: f64) -> Result<f64, String> {
|
||||||
|
Ok(libm::cos(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tan(x: f64) -> Result<f64, String> {
|
||||||
|
Ok(libm::tan(x))
|
||||||
|
}
|
||||||
@@ -1,12 +1,40 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use alloc::{boxed::Box, string::String, vec::Vec};
|
use alloc::{boxed::Box, format, string::String, vec::Vec};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use crate::{std::os::OS, std::io::{Color, write, clear}, println, std::application::{
|
use crate::{std::os::OS, std::io::{Color, write, clear}, println, std::application::{
|
||||||
Application,
|
Application,
|
||||||
Error,
|
Error,
|
||||||
}, std};
|
}, std};
|
||||||
|
|
||||||
|
const CRYSTAL_LOGO: &str =
|
||||||
|
" $$$$$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$\\
|
||||||
|
$$ __$$\\ $$ | $$ $$ __$$\\$$ __$$\\
|
||||||
|
$$ / \\__|$$$$$$\\ $$\\ $$\\ $$$$$$$\\$$$$$$\\ $$$$$$\\ $$ $$ / $$ $$ / \\__|
|
||||||
|
$$ | $$ __$$\\$$ | $$ $$ _____\\_$$ _| \\____$$\\$$ $$ | $$ \\$$$$$$\\
|
||||||
|
$$ | $$ | \\__$$ | $$ \\$$$$$$\\ $$ | $$$$$$$ $$ $$ | $$ |\\____$$\\
|
||||||
|
$$ | $$\\$$ | $$ | $$ |\\____$$\\ $$ |$$\\$$ __$$ $$ $$ | $$ $$\\ $$ |
|
||||||
|
\\$$$$$$ $$ | \\$$$$$$$ $$$$$$$ | \\$$$$ \\$$$$$$$ $$ |$$$$$$ \\$$$$$$ |
|
||||||
|
\\______/\\__| \\____$$ \\_______/ \\$$$$$$\\_______\\__|\\______/ \\______/
|
||||||
|
$$\\ $$ | $$ __$$\\
|
||||||
|
\\$$$$$$ | $$\\ $$\\__/ $$ |
|
||||||
|
\\______/ \\$$\\ $$ $$$$$$ |
|
||||||
|
\\$$\\$$ $$ ____/
|
||||||
|
\\$$$ /$$ |
|
||||||
|
\\$ / $$$$$$$$\\
|
||||||
|
\\_/ \\________| ";
|
||||||
|
|
||||||
|
const ZXQ5_LOGO: &str = "
|
||||||
|
|
||||||
|
/$$$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$
|
||||||
|
|_____ $$ | $$ / $$ /$$__ $$ /$$__ $$ /$$__ $$ /$$$$
|
||||||
|
/$$/ | $$/ $$/| $$ \\ $$| $$ \\ $$| $$ \\__/ /$$ /$$|_ $$
|
||||||
|
/$$/ \\ $$$$/ | $$ | $$| $$ | $$| $$$$$$ | $$ /$$/ | $$
|
||||||
|
/$$/ >$$ $$ | $$ | $$| $$ | $$ \\____ $$ \\ $$/$$/ | $$
|
||||||
|
/$$/ /$$/\\ $$| $$/$$ $$| $$ | $$ /$$ \\ $$ \\ $$$/ | $$
|
||||||
|
/$$$$$$$$| $$ \\ $$| $$$$$$/| $$$$$$/| $$$$$$/ \\ $/ /$$$$$$
|
||||||
|
|________/|__/ |__/ \\____ $$$ \\______/ \\______/ \\_/ |______/
|
||||||
|
";
|
||||||
pub struct CrystalFetch {}
|
pub struct CrystalFetch {}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -23,29 +51,23 @@ impl Application for CrystalFetch {
|
|||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
write(format_args!("
|
let logo_string = CRYSTAL_LOGO;
|
||||||
/$$$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$
|
let info_string = format!(
|
||||||
|_____ $$ | $$ / $$ /$$__ $$ /$$__ $$ /$$__ $$ /$$$$
|
" [ OS » {}
|
||||||
/$$/ | $$/ $$/| $$ \\ $$| $$ \\ $$| $$ \\__/ /$$ /$$|_ $$
|
|
||||||
/$$/ \\ $$$$/ | $$ | $$| $$ | $$| $$$$$$ | $$ /$$/ | $$
|
|
||||||
/$$/ >$$ $$ | $$ | $$| $$ | $$ \\____ $$ \\ $$/$$/ | $$
|
|
||||||
/$$/ /$$/\\ $$| $$/$$ $$| $$ | $$ /$$ \\ $$ \\ $$$/ | $$
|
|
||||||
/$$$$$$$$| $$ \\ $$| $$$$$$/| $$$$$$/| $$$$$$/ \\ $/ /$$$$$$
|
|
||||||
|________/|__/ |__/ \\____ $$$ \\______/ \\______/ \\_/ |______/
|
|
||||||
"), (Color::Cyan, Color::Black));
|
|
||||||
println!("
|
|
||||||
|
|
||||||
|
|
||||||
[ OS » {}
|
|
||||||
[ BUILD » {}
|
[ BUILD » {}
|
||||||
[ Shell » CrySH
|
[ Shell » CrySH
|
||||||
[ Github » https://github.com/FantasyPvP/CrystalOS-Restructured
|
[ Github » https://github.com/FantasyPvP/CrystalOS-Restructured
|
||||||
[ Author » FantasyPvP / ZXQ5
|
[ Author » FantasyPvP / ZXQ5", os, version);
|
||||||
|
|
||||||
|
let spacer = "\n".repeat(24 - logo_string.lines().count() - 4 - info_string.lines().count());
|
||||||
|
|
||||||
|
// write values to console
|
||||||
|
write(format_args!("{}", logo_string), (Color::Cyan, Color::Black));
|
||||||
|
println!("\n\n");
|
||||||
|
println!("{}", info_string);
|
||||||
|
println!("{}", spacer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
", os, version);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use crate::{
|
|||||||
std::application::{Application, Error},
|
std::application::{Application, Error},
|
||||||
user::bin::*,
|
user::bin::*,
|
||||||
};
|
};
|
||||||
|
use crate::std::io::{Color, write};
|
||||||
use crate::user::bin::gigachad_detector::GigachadDetector;
|
use crate::user::bin::gigachad_detector::GigachadDetector;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@@ -54,7 +55,9 @@ pub async fn eventloop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_error(e: Error) {}
|
fn handle_error(e: Error) {
|
||||||
|
println!("there was an error! exiting program!");
|
||||||
|
}
|
||||||
|
|
||||||
async fn exec() -> Result<(), Error> {
|
async fn exec() -> Result<(), Error> {
|
||||||
let mut current = CMD.lock().current.clone();
|
let mut current = CMD.lock().current.clone();
|
||||||
@@ -189,11 +192,8 @@ impl CommandHandler {
|
|||||||
// TODO: coloured prompt
|
// TODO: coloured prompt
|
||||||
|
|
||||||
pub fn prompt(&self) {
|
pub fn prompt(&self) {
|
||||||
print!("\n [ Crystal ] >> ");
|
write(format_args!("\n Crystal> "), (Color::Cyan, Color::Black));
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function is run every time the enter key is pressed in the command line mode.
|
|
||||||
// it detects the command that is being run and then executes it, passing the arguments to it.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CmdHistory {
|
struct CmdHistory {
|
||||||
|
|||||||
Reference in New Issue
Block a user