cargo fix&fmt

This commit is contained in:
Daniella 2023-02-18 18:45:15 +01:00
parent 2ce44f2b55
commit 4d4799a76f
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
4 changed files with 132 additions and 91 deletions

View file

@ -1,6 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use crate::{mutex::Mut, runtime::*, lexer}; use crate::{lexer, runtime::*};
pub fn dyn_dump(stack: &mut Stack) { pub fn dyn_dump(stack: &mut Stack) {
Words { Words {
@ -179,11 +179,18 @@ pub fn dyn_all_types(stack: &mut Stack) {
pub fn dyn_read(stack: &mut Stack) { pub fn dyn_read(stack: &mut Stack) {
if let Value::Str(s) = stack.pop().lock_ro().native.clone() { if let Value::Str(s) = stack.pop().lock_ro().native.clone() {
stack.push(Value::Func(AFunc::new(Func { stack.push(
ret_count: 0, Value::Func(AFunc::new(Func {
to_call: FuncImpl::SPL(lexer::lex(s, "dyn-read@".to_owned() + &stack.get_origin().file, stack.get_frame())), ret_count: 0,
origin: stack.get_frame(), to_call: FuncImpl::SPL(lexer::lex(
})).spl()); s,
"dyn-read@".to_owned() + &stack.get_origin().file,
stack.get_frame(),
)),
origin: stack.get_frame(),
}))
.spl(),
);
} else { } else {
panic!("incorrect usage of dyn-call"); panic!("incorrect usage of dyn-call");
} }

View file

@ -1,9 +1,6 @@
use spl::{lexer::lex, runtime::*}; use spl::{lexer::lex, runtime::*};
use std::{ use std::{fs, vec};
fs,
vec,
};
fn main() { fn main() {
let rt = Runtime::new(); let rt = Runtime::new();

View file

@ -702,7 +702,18 @@ impl Words {
let o = o.lock_ro(); let o = o.lock_ro();
// TODO: raise error if not found // TODO: raise error if not found
let f0 = o.kind.lock_ro(); 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(f0);
mem::drop(o); mem::drop(o);
if ra != 0 { if ra != 0 {

View file

@ -172,110 +172,136 @@ pub fn star(stack: &mut Stack) {
pub fn to_int(stack: &mut Stack) { pub fn to_int(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Int(match o { stack.push(
Value::Null => panic!("incompatible: null - int"), Value::Int(match o {
Value::Int(x) => x, Value::Null => panic!("incompatible: null - int"),
Value::Long(x) => x as i32, Value::Int(x) => x,
Value::Mega(x) => x as i32, Value::Long(x) => x as i32,
Value::Float(x) => x as i32, Value::Mega(x) => x as i32,
Value::Double(x) => x as i32, Value::Float(x) => x as i32,
Value::Func(_) => panic!("incompatible: func - int"), Value::Double(x) => x as i32,
Value::Array(_) => panic!("incompatible: array - int"), Value::Func(_) => panic!("incompatible: func - int"),
Value::Str(x) => x.parse().expect("invalid int"), Value::Array(_) => panic!("incompatible: array - int"),
}).spl()) Value::Str(x) => x.parse().expect("invalid int"),
})
.spl(),
)
} }
pub fn to_long(stack: &mut Stack) { pub fn to_long(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Long(match o { stack.push(
Value::Null => panic!("incompatible: null - long"), Value::Long(match o {
Value::Int(x) => x as i64, Value::Null => panic!("incompatible: null - long"),
Value::Long(x) => x as i64, Value::Int(x) => x as i64,
Value::Mega(x) => x as i64, Value::Long(x) => x as i64,
Value::Float(x) => x as i64, Value::Mega(x) => x as i64,
Value::Double(x) => x as i64, Value::Float(x) => x as i64,
Value::Func(_) => panic!("incompatible: func - long"), Value::Double(x) => x as i64,
Value::Array(_) => panic!("incompatible: array - long"), Value::Func(_) => panic!("incompatible: func - long"),
Value::Str(x) => x.parse().expect("invalid long"), Value::Array(_) => panic!("incompatible: array - long"),
}).spl()) Value::Str(x) => x.parse().expect("invalid long"),
})
.spl(),
)
} }
pub fn to_mega(stack: &mut Stack) { pub fn to_mega(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Mega(match o { stack.push(
Value::Null => panic!("incompatible: null - mega"), Value::Mega(match o {
Value::Int(x) => x as i128, Value::Null => panic!("incompatible: null - mega"),
Value::Long(x) => x as i128, Value::Int(x) => x as i128,
Value::Mega(x) => x as i128, Value::Long(x) => x as i128,
Value::Float(x) => x as i128, Value::Mega(x) => x as i128,
Value::Double(x) => x as i128, Value::Float(x) => x as i128,
Value::Func(_) => panic!("incompatible: func - mega"), Value::Double(x) => x as i128,
Value::Array(_) => panic!("incompatible: array - mega"), Value::Func(_) => panic!("incompatible: func - mega"),
Value::Str(x) => x.parse().expect("invalid mega"), Value::Array(_) => panic!("incompatible: array - mega"),
}).spl()) Value::Str(x) => x.parse().expect("invalid mega"),
})
.spl(),
)
} }
pub fn to_float(stack: &mut Stack) { pub fn to_float(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Float(match o { stack.push(
Value::Null => panic!("incompatible: null - float"), Value::Float(match o {
Value::Int(x) => x as f32, Value::Null => panic!("incompatible: null - float"),
Value::Long(x) => x as f32, Value::Int(x) => x as f32,
Value::Mega(x) => x as f32, Value::Long(x) => x as f32,
Value::Float(x) => x as f32, Value::Mega(x) => x as f32,
Value::Double(x) => x as f32, Value::Float(x) => x as f32,
Value::Func(_) => panic!("incompatible: func - float"), Value::Double(x) => x as f32,
Value::Array(_) => panic!("incompatible: array - float"), Value::Func(_) => panic!("incompatible: func - float"),
Value::Str(x) => x.parse().expect("invalid float"), Value::Array(_) => panic!("incompatible: array - float"),
}).spl()) Value::Str(x) => x.parse().expect("invalid float"),
})
.spl(),
)
} }
pub fn to_double(stack: &mut Stack) { pub fn to_double(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Double(match o { stack.push(
Value::Null => panic!("incompatible: null - double"), Value::Double(match o {
Value::Int(x) => x as f64, Value::Null => panic!("incompatible: null - double"),
Value::Long(x) => x as f64, Value::Int(x) => x as f64,
Value::Mega(x) => x as f64, Value::Long(x) => x as f64,
Value::Float(x) => x as f64, Value::Mega(x) => x as f64,
Value::Double(x) => x as f64, Value::Float(x) => x as f64,
Value::Func(_) => panic!("incompatible: func - double"), Value::Double(x) => x as f64,
Value::Array(_) => panic!("incompatible: array - double"), Value::Func(_) => panic!("incompatible: func - double"),
Value::Str(x) => x.parse().expect("invalid double"), Value::Array(_) => panic!("incompatible: array - double"),
}).spl()) Value::Str(x) => x.parse().expect("invalid double"),
})
.spl(),
)
} }
pub fn to_array(stack: &mut Stack) { pub fn to_array(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Array(match o { stack.push(
Value::Null => panic!("incompatible: null - array"), Value::Array(match o {
Value::Int(_) => panic!("incompatible: int - array"), Value::Null => panic!("incompatible: null - array"),
Value::Long(_) => panic!("incompatible: long - array"), Value::Int(_) => panic!("incompatible: int - array"),
Value::Mega(_) => panic!("incompatible: mega - array"), Value::Long(_) => panic!("incompatible: long - array"),
Value::Float(_) => panic!("incompatible: float - array"), Value::Mega(_) => panic!("incompatible: mega - array"),
Value::Double(_) => panic!("incompatible: double - array"), Value::Float(_) => panic!("incompatible: float - array"),
Value::Func(_) => panic!("incompatible: func - array"), Value::Double(_) => panic!("incompatible: double - array"),
Value::Array(x) => x, Value::Func(_) => panic!("incompatible: func - array"),
Value::Str(x) => x.chars().map(|x| Value::Int(x as u32 as i32).spl()).collect(), Value::Array(x) => x,
}).spl()) Value::Str(x) => x
.chars()
.map(|x| Value::Int(x as u32 as i32).spl())
.collect(),
})
.spl(),
)
} }
pub fn to_str(stack: &mut Stack) { pub fn to_str(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone(); let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Str(match o { stack.push(
Value::Null => panic!("incompatible: null - str"), Value::Str(match o {
Value::Int(x) => x.to_string(), Value::Null => panic!("incompatible: null - str"),
Value::Long(x) => x.to_string(), Value::Int(x) => x.to_string(),
Value::Mega(x) => x.to_string(), Value::Long(x) => x.to_string(),
Value::Float(x) => x.to_string(), Value::Mega(x) => x.to_string(),
Value::Double(x) => x.to_string(), Value::Float(x) => x.to_string(),
Value::Func(_) => panic!("incompatible: func - str"), Value::Double(x) => x.to_string(),
Value::Array(x) => String::from_iter(x.into_iter().map(|x| match &x.lock_ro().native { Value::Func(_) => panic!("incompatible: func - str"),
Value::Int(x) => char::from_u32(*x as u32).expect("invalid Unicode Char: {x}"), Value::Array(x) => {
_ => panic!("incompatible: !int - __str_element") 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}"),
Value::Str(x) => x, _ => panic!("incompatible: !int - __str_element"),
}).spl()) }))
}
Value::Str(x) => x,
})
.spl(),
)
} }
pub fn call(stack: &mut Stack) { pub fn call(stack: &mut Stack) {