e
E
This commit is contained in:
@@ -24,6 +24,19 @@ pub fn _print(args: core::fmt::Arguments) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
pub fn serial_reply(chr: char) -> char {
|
||||||
|
use core::fmt::Write;
|
||||||
|
use x86_64::instructions::interrupts;
|
||||||
|
|
||||||
|
let mut chr_return: char = 'X';
|
||||||
|
|
||||||
|
interrupts::without_interrupts(|| {
|
||||||
|
SERIAL1.lock().send(chr as u8);
|
||||||
|
chr_return = SERIAL1.lock().receive() as char ;
|
||||||
|
});
|
||||||
|
|
||||||
|
chr_return
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! serial_print {
|
macro_rules! serial_print {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use alloc::vec::Vec;
|
|||||||
|
|
||||||
pub use crate::{print, println, serial_print, serial_println};
|
pub use crate::{print, println, serial_print, serial_println};
|
||||||
pub use crate::kernel::render::Color;
|
pub use crate::kernel::render::Color;
|
||||||
|
use crate::kernel::serial::serial_reply;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
@@ -30,6 +31,14 @@ impl Stdin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Serial {}
|
||||||
|
|
||||||
|
impl Serial {
|
||||||
|
pub fn reply_char(c: char) -> char {
|
||||||
|
serial_reply(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Screen {}
|
pub struct Screen {}
|
||||||
impl Screen {
|
impl Screen {
|
||||||
pub fn terminal_mode() {
|
pub fn terminal_mode() {
|
||||||
|
|||||||
@@ -126,11 +126,7 @@ impl Interpreter {
|
|||||||
},
|
},
|
||||||
Operator::Exp => {
|
Operator::Exp => {
|
||||||
return Ok(Value::Number({
|
return Ok(Value::Number({
|
||||||
let mut val = 1.0;
|
super::functions::exp(left, right)
|
||||||
for _ in 0..(right as i64) {
|
|
||||||
val *= left
|
|
||||||
};
|
|
||||||
val
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ use alloc::format;
|
|||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use crate::println;
|
use crate::println;
|
||||||
|
|
||||||
|
const PI: f64 = 3.14159265358979323846264338327950288419716939937510;
|
||||||
|
|
||||||
pub fn run_func(func: String, x: f64) -> Result<f64, String> {
|
pub fn run_func(func: String, x: f64) -> Result<f64, String> {
|
||||||
match func.as_str() {
|
match func.as_str() {
|
||||||
"sqrt" => sqrt(x),
|
"sqrt" => sqrt(x),
|
||||||
@@ -36,14 +38,51 @@ fn factorial(x: f64) -> Result<f64, String> {
|
|||||||
Ok((1..=x).fold(1, |a, b| a * b) as f64)
|
Ok((1..=x).fold(1, |a, b| a * b) as f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sin(x: f64) -> Result<f64, String> {
|
fn cos(mut x: f64) -> Result<f64, String> {
|
||||||
Ok(libm::sin(x))
|
while x > PI {
|
||||||
|
x -= PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = 1.0 - trig_term(x, 2) + trig_term(x, 4) - trig_term(x, 6) + trig_term(x, 8) - trig_term(x, 10);
|
||||||
|
if res >= -1.0 && res <= 1.0 {
|
||||||
|
Ok(res)
|
||||||
|
} else {
|
||||||
|
panic!("something is very wrong with the cos function : {}", res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cos(x: f64) -> Result<f64, String> {
|
fn sin(mut x: f64) -> Result<f64, String> {
|
||||||
Ok(libm::cos(x))
|
while x > PI {
|
||||||
|
x -= PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let res = x - trig_term(x, 3) + trig_term(x, 5) - trig_term(x, 7) + trig_term(x, 9) - trig_term(x, 11);
|
||||||
|
if res >= -1.0 && res <= 1.0 {
|
||||||
|
Ok(res)
|
||||||
|
} else {
|
||||||
|
panic!("something is very wrong with the sin function: {}", res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tan(x: f64) -> Result<f64, String> {
|
fn tan(x: f64) -> Result<f64, String> {
|
||||||
Ok(libm::tan(x))
|
Ok(libm::tan(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exp(x: f64, y: f64) -> f64 {
|
||||||
|
let mut res = 1.0;
|
||||||
|
for _ in 0..(y as usize) {
|
||||||
|
res *= x
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trig_term(x: f64, y: usize) -> f64 {
|
||||||
|
let mut ex = 1.0;
|
||||||
|
for _ in 0..y {
|
||||||
|
ex *= x;
|
||||||
|
}
|
||||||
|
let fact = (1..=y).fold(1, |a, b| a*b);
|
||||||
|
|
||||||
|
ex as f64 / fact as f64
|
||||||
|
}
|
||||||
@@ -43,7 +43,7 @@ const RICKROLL2: &str = "
|
|||||||
1a###w#*mObo*oatXkW*oo#*###p `--' `---' `----' `-----' | |-'
|
1a###w#*mObo*oatXkW*oo#*###p `--' `---' `----' `-----' | |-'
|
||||||
`--'";
|
`--'";
|
||||||
|
|
||||||
use crate::{println};
|
use crate::{println, serial_println};
|
||||||
use alloc::{string::String, boxed::Box, vec::Vec};
|
use alloc::{string::String, boxed::Box, vec::Vec};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec};
|
|||||||
use vga::writers::{GraphicsWriter, PrimitiveDrawing};
|
use vga::writers::{GraphicsWriter, PrimitiveDrawing};
|
||||||
|
|
||||||
use crate::{print, printerr, println, std, std::application::{Application, Error}, user::bin::*};
|
use crate::{print, printerr, println, std, std::application::{Application, Error}, user::bin::*};
|
||||||
use crate::std::io::{Color, write, Screen, Stdin};
|
use crate::std::io::{Color, write, Screen, Stdin, Serial};
|
||||||
use crate::std::random::Random;
|
use crate::std::random::Random;
|
||||||
use crate::user::bin::gigachad_detector::GigachadDetector;
|
use crate::user::bin::gigachad_detector::GigachadDetector;
|
||||||
use crate::user::bin::grapher::Grapher;
|
use crate::user::bin::grapher::Grapher;
|
||||||
@@ -122,6 +122,10 @@ async fn exec() -> Result<(), Error> {
|
|||||||
let mut game = snake::Game::new();
|
let mut game = snake::Game::new();
|
||||||
game.run(args).await?;
|
game.run(args).await?;
|
||||||
}
|
}
|
||||||
|
"serial" => {
|
||||||
|
let c = Serial::reply_char('e');
|
||||||
|
println!("{}", c);
|
||||||
|
}
|
||||||
"gameoflife" => {
|
"gameoflife" => {
|
||||||
let mut game = gameoflife::GameOfLife::new();
|
let mut game = gameoflife::GameOfLife::new();
|
||||||
game.run(Vec::new()).await?;
|
game.run(Vec::new()).await?;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn rotated_around(&self, angle: Direction, p: Position) -> Position { // rotates by an angle around a point
|
pub fn rotated_aroundte(&self, angle: Direction, p: Position) -> Position { // rotates by an angle around a point
|
||||||
|
|
||||||
// gets coords relative to point to rotate around
|
// gets coords relative to point to rotate around
|
||||||
let mut p_offset = self.get_offset(&p);
|
let mut p_offset = self.get_offset(&p);
|
||||||
|
|||||||
Reference in New Issue
Block a user