cargo fix&fmt

This commit is contained in:
Daniella / Tove 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 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 {
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())),
to_call: FuncImpl::SPL(lexer::lex(
s,
"dyn-read@".to_owned() + &stack.get_origin().file,
stack.get_frame(),
)),
origin: stack.get_frame(),
})).spl());
}))
.spl(),
);
} else {
panic!("incorrect usage of dyn-call");
}

View file

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

View file

@ -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 {

View file

@ -172,7 +172,8 @@ 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 {
stack.push(
Value::Int(match o {
Value::Null => panic!("incompatible: null - int"),
Value::Int(x) => x,
Value::Long(x) => x as i32,
@ -182,12 +183,15 @@ pub fn to_int(stack: &mut Stack) {
Value::Func(_) => panic!("incompatible: func - int"),
Value::Array(_) => panic!("incompatible: array - int"),
Value::Str(x) => x.parse().expect("invalid int"),
}).spl())
})
.spl(),
)
}
pub fn to_long(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Long(match o {
stack.push(
Value::Long(match o {
Value::Null => panic!("incompatible: null - long"),
Value::Int(x) => x as i64,
Value::Long(x) => x as i64,
@ -197,12 +201,15 @@ pub fn to_long(stack: &mut Stack) {
Value::Func(_) => panic!("incompatible: func - long"),
Value::Array(_) => panic!("incompatible: array - long"),
Value::Str(x) => x.parse().expect("invalid long"),
}).spl())
})
.spl(),
)
}
pub fn to_mega(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Mega(match o {
stack.push(
Value::Mega(match o {
Value::Null => panic!("incompatible: null - mega"),
Value::Int(x) => x as i128,
Value::Long(x) => x as i128,
@ -212,12 +219,15 @@ pub fn to_mega(stack: &mut Stack) {
Value::Func(_) => panic!("incompatible: func - mega"),
Value::Array(_) => panic!("incompatible: array - mega"),
Value::Str(x) => x.parse().expect("invalid mega"),
}).spl())
})
.spl(),
)
}
pub fn to_float(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Float(match o {
stack.push(
Value::Float(match o {
Value::Null => panic!("incompatible: null - float"),
Value::Int(x) => x as f32,
Value::Long(x) => x as f32,
@ -227,12 +237,15 @@ pub fn to_float(stack: &mut Stack) {
Value::Func(_) => panic!("incompatible: func - float"),
Value::Array(_) => panic!("incompatible: array - float"),
Value::Str(x) => x.parse().expect("invalid float"),
}).spl())
})
.spl(),
)
}
pub fn to_double(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Double(match o {
stack.push(
Value::Double(match o {
Value::Null => panic!("incompatible: null - double"),
Value::Int(x) => x as f64,
Value::Long(x) => x as f64,
@ -242,12 +255,15 @@ pub fn to_double(stack: &mut Stack) {
Value::Func(_) => panic!("incompatible: func - double"),
Value::Array(_) => panic!("incompatible: array - double"),
Value::Str(x) => x.parse().expect("invalid double"),
}).spl())
})
.spl(),
)
}
pub fn to_array(stack: &mut Stack) {
let o = stack.pop().lock_ro().native.clone();
stack.push(Value::Array(match o {
stack.push(
Value::Array(match o {
Value::Null => panic!("incompatible: null - array"),
Value::Int(_) => panic!("incompatible: int - array"),
Value::Long(_) => panic!("incompatible: long - array"),
@ -256,13 +272,19 @@ pub fn to_array(stack: &mut Stack) {
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())
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 {
stack.push(
Value::Str(match o {
Value::Null => panic!("incompatible: null - str"),
Value::Int(x) => x.to_string(),
Value::Long(x) => x.to_string(),
@ -270,12 +292,16 @@ pub fn to_str(stack: &mut Stack) {
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::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")
})),
_ => panic!("incompatible: !int - __str_element"),
}))
}
Value::Str(x) => x,
}).spl())
})
.spl(),
)
}
pub fn call(stack: &mut Stack) {