From 4d4799a76f9f7a0d55b0822ea8f30ab6bfed4a3f Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 18 Feb 2023 18:45:15 +0100 Subject: [PATCH] cargo fix&fmt --- src/dyn_fns.rs | 19 +++-- src/main.rs | 5 +- src/runtime.rs | 13 +++- src/std_fns.rs | 186 ++++++++++++++++++++++++++++--------------------- 4 files changed, 132 insertions(+), 91 deletions(-) diff --git a/src/dyn_fns.rs b/src/dyn_fns.rs index e70816d..6f7dc8f 100644 --- a/src/dyn_fns.rs +++ b/src/dyn_fns.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::{mutex::Mut, runtime::*, lexer}; +use crate::{lexer, runtime::*}; pub fn dyn_dump(stack: &mut Stack) { Words { @@ -179,11 +179,18 @@ pub fn dyn_all_types(stack: &mut Stack) { pub fn dyn_read(stack: &mut Stack) { if let Value::Str(s) = stack.pop().lock_ro().native.clone() { - stack.push(Value::Func(AFunc::new(Func { - ret_count: 0, - to_call: FuncImpl::SPL(lexer::lex(s, "dyn-read@".to_owned() + &stack.get_origin().file, stack.get_frame())), - origin: stack.get_frame(), - })).spl()); + stack.push( + Value::Func(AFunc::new(Func { + ret_count: 0, + to_call: FuncImpl::SPL(lexer::lex( + s, + "dyn-read@".to_owned() + &stack.get_origin().file, + stack.get_frame(), + )), + origin: stack.get_frame(), + })) + .spl(), + ); } else { panic!("incorrect usage of dyn-call"); } diff --git a/src/main.rs b/src/main.rs index 480ac27..e013fbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,6 @@ use spl::{lexer::lex, runtime::*}; -use std::{ - fs, - vec, -}; +use std::{fs, vec}; fn main() { let rt = Runtime::new(); diff --git a/src/runtime.rs b/src/runtime.rs index 12902f5..4994680 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -702,7 +702,18 @@ impl Words { let o = o.lock_ro(); // TODO: raise error if not found let f0 = o.kind.lock_ro(); - let f = f0.functions.get(&x).unwrap_or_else(|| panic!("objcall not possible. {} {:?} {}", o.kind.lock_ro().name, o.native, x)).clone(); + let f = f0 + .functions + .get(&x) + .unwrap_or_else(|| { + panic!( + "objcall not possible. {} {:?} {}", + o.kind.lock_ro().name, + o.native, + x + ) + }) + .clone(); mem::drop(f0); mem::drop(o); if ra != 0 { diff --git a/src/std_fns.rs b/src/std_fns.rs index 5f39618..00142c9 100644 --- a/src/std_fns.rs +++ b/src/std_fns.rs @@ -172,110 +172,136 @@ pub fn star(stack: &mut Stack) { pub fn to_int(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Int(match o { - Value::Null => panic!("incompatible: null - int"), - Value::Int(x) => x, - Value::Long(x) => x as i32, - Value::Mega(x) => x as i32, - Value::Float(x) => x as i32, - Value::Double(x) => x as i32, - Value::Func(_) => panic!("incompatible: func - int"), - Value::Array(_) => panic!("incompatible: array - int"), - Value::Str(x) => x.parse().expect("invalid int"), - }).spl()) + stack.push( + Value::Int(match o { + Value::Null => panic!("incompatible: null - int"), + Value::Int(x) => x, + Value::Long(x) => x as i32, + Value::Mega(x) => x as i32, + Value::Float(x) => x as i32, + Value::Double(x) => x as i32, + Value::Func(_) => panic!("incompatible: func - int"), + Value::Array(_) => panic!("incompatible: array - int"), + Value::Str(x) => x.parse().expect("invalid int"), + }) + .spl(), + ) } pub fn to_long(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Long(match o { - Value::Null => panic!("incompatible: null - long"), - Value::Int(x) => x as i64, - Value::Long(x) => x as i64, - Value::Mega(x) => x as i64, - Value::Float(x) => x as i64, - Value::Double(x) => x as i64, - Value::Func(_) => panic!("incompatible: func - long"), - Value::Array(_) => panic!("incompatible: array - long"), - Value::Str(x) => x.parse().expect("invalid long"), - }).spl()) + stack.push( + Value::Long(match o { + Value::Null => panic!("incompatible: null - long"), + Value::Int(x) => x as i64, + Value::Long(x) => x as i64, + Value::Mega(x) => x as i64, + Value::Float(x) => x as i64, + Value::Double(x) => x as i64, + Value::Func(_) => panic!("incompatible: func - long"), + Value::Array(_) => panic!("incompatible: array - long"), + Value::Str(x) => x.parse().expect("invalid long"), + }) + .spl(), + ) } pub fn to_mega(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Mega(match o { - Value::Null => panic!("incompatible: null - mega"), - Value::Int(x) => x as i128, - Value::Long(x) => x as i128, - Value::Mega(x) => x as i128, - Value::Float(x) => x as i128, - Value::Double(x) => x as i128, - Value::Func(_) => panic!("incompatible: func - mega"), - Value::Array(_) => panic!("incompatible: array - mega"), - Value::Str(x) => x.parse().expect("invalid mega"), - }).spl()) + stack.push( + Value::Mega(match o { + Value::Null => panic!("incompatible: null - mega"), + Value::Int(x) => x as i128, + Value::Long(x) => x as i128, + Value::Mega(x) => x as i128, + Value::Float(x) => x as i128, + Value::Double(x) => x as i128, + Value::Func(_) => panic!("incompatible: func - mega"), + Value::Array(_) => panic!("incompatible: array - mega"), + Value::Str(x) => x.parse().expect("invalid mega"), + }) + .spl(), + ) } pub fn to_float(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Float(match o { - Value::Null => panic!("incompatible: null - float"), - Value::Int(x) => x as f32, - Value::Long(x) => x as f32, - Value::Mega(x) => x as f32, - Value::Float(x) => x as f32, - Value::Double(x) => x as f32, - Value::Func(_) => panic!("incompatible: func - float"), - Value::Array(_) => panic!("incompatible: array - float"), - Value::Str(x) => x.parse().expect("invalid float"), - }).spl()) + stack.push( + Value::Float(match o { + Value::Null => panic!("incompatible: null - float"), + Value::Int(x) => x as f32, + Value::Long(x) => x as f32, + Value::Mega(x) => x as f32, + Value::Float(x) => x as f32, + Value::Double(x) => x as f32, + Value::Func(_) => panic!("incompatible: func - float"), + Value::Array(_) => panic!("incompatible: array - float"), + Value::Str(x) => x.parse().expect("invalid float"), + }) + .spl(), + ) } pub fn to_double(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Double(match o { - Value::Null => panic!("incompatible: null - double"), - Value::Int(x) => x as f64, - Value::Long(x) => x as f64, - Value::Mega(x) => x as f64, - Value::Float(x) => x as f64, - Value::Double(x) => x as f64, - Value::Func(_) => panic!("incompatible: func - double"), - Value::Array(_) => panic!("incompatible: array - double"), - Value::Str(x) => x.parse().expect("invalid double"), - }).spl()) + stack.push( + Value::Double(match o { + Value::Null => panic!("incompatible: null - double"), + Value::Int(x) => x as f64, + Value::Long(x) => x as f64, + Value::Mega(x) => x as f64, + Value::Float(x) => x as f64, + Value::Double(x) => x as f64, + Value::Func(_) => panic!("incompatible: func - double"), + Value::Array(_) => panic!("incompatible: array - double"), + Value::Str(x) => x.parse().expect("invalid double"), + }) + .spl(), + ) } pub fn to_array(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Array(match o { - Value::Null => panic!("incompatible: null - array"), - Value::Int(_) => panic!("incompatible: int - array"), - Value::Long(_) => panic!("incompatible: long - array"), - Value::Mega(_) => panic!("incompatible: mega - array"), - Value::Float(_) => panic!("incompatible: float - array"), - Value::Double(_) => panic!("incompatible: double - array"), - Value::Func(_) => panic!("incompatible: func - array"), - Value::Array(x) => x, - Value::Str(x) => x.chars().map(|x| Value::Int(x as u32 as i32).spl()).collect(), - }).spl()) + stack.push( + Value::Array(match o { + Value::Null => panic!("incompatible: null - array"), + Value::Int(_) => panic!("incompatible: int - array"), + Value::Long(_) => panic!("incompatible: long - array"), + Value::Mega(_) => panic!("incompatible: mega - array"), + Value::Float(_) => panic!("incompatible: float - array"), + Value::Double(_) => panic!("incompatible: double - array"), + Value::Func(_) => panic!("incompatible: func - array"), + Value::Array(x) => x, + Value::Str(x) => x + .chars() + .map(|x| Value::Int(x as u32 as i32).spl()) + .collect(), + }) + .spl(), + ) } pub fn to_str(stack: &mut Stack) { let o = stack.pop().lock_ro().native.clone(); - stack.push(Value::Str(match o { - Value::Null => panic!("incompatible: null - str"), - Value::Int(x) => x.to_string(), - Value::Long(x) => x.to_string(), - Value::Mega(x) => x.to_string(), - Value::Float(x) => x.to_string(), - Value::Double(x) => x.to_string(), - Value::Func(_) => panic!("incompatible: func - str"), - Value::Array(x) => String::from_iter(x.into_iter().map(|x| match &x.lock_ro().native { - Value::Int(x) => char::from_u32(*x as u32).expect("invalid Unicode Char: {x}"), - _ => panic!("incompatible: !int - __str_element") - })), - Value::Str(x) => x, - }).spl()) + stack.push( + Value::Str(match o { + Value::Null => panic!("incompatible: null - str"), + Value::Int(x) => x.to_string(), + Value::Long(x) => x.to_string(), + Value::Mega(x) => x.to_string(), + Value::Float(x) => x.to_string(), + Value::Double(x) => x.to_string(), + Value::Func(_) => panic!("incompatible: func - str"), + Value::Array(x) => { + String::from_iter(x.into_iter().map(|x| match &x.lock_ro().native { + Value::Int(x) => char::from_u32(*x as u32).expect("invalid Unicode Char: {x}"), + _ => panic!("incompatible: !int - __str_element"), + })) + } + Value::Str(x) => x, + }) + .spl(), + ) } pub fn call(stack: &mut Stack) {