cargo fix&fmt
This commit is contained in:
parent
2ce44f2b55
commit
4d4799a76f
4 changed files with 132 additions and 91 deletions
|
@ -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(
|
||||||
|
Value::Func(AFunc::new(Func {
|
||||||
ret_count: 0,
|
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(),
|
origin: stack.get_frame(),
|
||||||
})).spl());
|
}))
|
||||||
|
.spl(),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
panic!("incorrect usage of dyn-call");
|
panic!("incorrect usage of dyn-call");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -172,7 +172,8 @@ 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::Int(match o {
|
||||||
Value::Null => panic!("incompatible: null - int"),
|
Value::Null => panic!("incompatible: null - int"),
|
||||||
Value::Int(x) => x,
|
Value::Int(x) => x,
|
||||||
Value::Long(x) => x as i32,
|
Value::Long(x) => x as i32,
|
||||||
|
@ -182,12 +183,15 @@ pub fn to_int(stack: &mut Stack) {
|
||||||
Value::Func(_) => panic!("incompatible: func - int"),
|
Value::Func(_) => panic!("incompatible: func - int"),
|
||||||
Value::Array(_) => panic!("incompatible: array - int"),
|
Value::Array(_) => panic!("incompatible: array - int"),
|
||||||
Value::Str(x) => x.parse().expect("invalid int"),
|
Value::Str(x) => x.parse().expect("invalid int"),
|
||||||
}).spl())
|
})
|
||||||
|
.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::Long(match o {
|
||||||
Value::Null => panic!("incompatible: null - long"),
|
Value::Null => panic!("incompatible: null - long"),
|
||||||
Value::Int(x) => x as i64,
|
Value::Int(x) => x as i64,
|
||||||
Value::Long(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::Func(_) => panic!("incompatible: func - long"),
|
||||||
Value::Array(_) => panic!("incompatible: array - long"),
|
Value::Array(_) => panic!("incompatible: array - long"),
|
||||||
Value::Str(x) => x.parse().expect("invalid long"),
|
Value::Str(x) => x.parse().expect("invalid long"),
|
||||||
}).spl())
|
})
|
||||||
|
.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::Mega(match o {
|
||||||
Value::Null => panic!("incompatible: null - mega"),
|
Value::Null => panic!("incompatible: null - mega"),
|
||||||
Value::Int(x) => x as i128,
|
Value::Int(x) => x as i128,
|
||||||
Value::Long(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::Func(_) => panic!("incompatible: func - mega"),
|
||||||
Value::Array(_) => panic!("incompatible: array - mega"),
|
Value::Array(_) => panic!("incompatible: array - mega"),
|
||||||
Value::Str(x) => x.parse().expect("invalid mega"),
|
Value::Str(x) => x.parse().expect("invalid mega"),
|
||||||
}).spl())
|
})
|
||||||
|
.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::Float(match o {
|
||||||
Value::Null => panic!("incompatible: null - float"),
|
Value::Null => panic!("incompatible: null - float"),
|
||||||
Value::Int(x) => x as f32,
|
Value::Int(x) => x as f32,
|
||||||
Value::Long(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::Func(_) => panic!("incompatible: func - float"),
|
||||||
Value::Array(_) => panic!("incompatible: array - float"),
|
Value::Array(_) => panic!("incompatible: array - float"),
|
||||||
Value::Str(x) => x.parse().expect("invalid float"),
|
Value::Str(x) => x.parse().expect("invalid float"),
|
||||||
}).spl())
|
})
|
||||||
|
.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::Double(match o {
|
||||||
Value::Null => panic!("incompatible: null - double"),
|
Value::Null => panic!("incompatible: null - double"),
|
||||||
Value::Int(x) => x as f64,
|
Value::Int(x) => x as f64,
|
||||||
Value::Long(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::Func(_) => panic!("incompatible: func - double"),
|
||||||
Value::Array(_) => panic!("incompatible: array - double"),
|
Value::Array(_) => panic!("incompatible: array - double"),
|
||||||
Value::Str(x) => x.parse().expect("invalid double"),
|
Value::Str(x) => x.parse().expect("invalid double"),
|
||||||
}).spl())
|
})
|
||||||
|
.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::Array(match o {
|
||||||
Value::Null => panic!("incompatible: null - array"),
|
Value::Null => panic!("incompatible: null - array"),
|
||||||
Value::Int(_) => panic!("incompatible: int - array"),
|
Value::Int(_) => panic!("incompatible: int - array"),
|
||||||
Value::Long(_) => panic!("incompatible: long - 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::Double(_) => panic!("incompatible: double - array"),
|
||||||
Value::Func(_) => panic!("incompatible: func - array"),
|
Value::Func(_) => panic!("incompatible: func - array"),
|
||||||
Value::Array(x) => x,
|
Value::Array(x) => x,
|
||||||
Value::Str(x) => x.chars().map(|x| Value::Int(x as u32 as i32).spl()).collect(),
|
Value::Str(x) => x
|
||||||
}).spl())
|
.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::Str(match o {
|
||||||
Value::Null => panic!("incompatible: null - str"),
|
Value::Null => panic!("incompatible: null - str"),
|
||||||
Value::Int(x) => x.to_string(),
|
Value::Int(x) => x.to_string(),
|
||||||
Value::Long(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::Float(x) => x.to_string(),
|
||||||
Value::Double(x) => x.to_string(),
|
Value::Double(x) => x.to_string(),
|
||||||
Value::Func(_) => panic!("incompatible: func - str"),
|
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}"),
|
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,
|
Value::Str(x) => x,
|
||||||
}).spl())
|
})
|
||||||
|
.spl(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call(stack: &mut Stack) {
|
pub fn call(stack: &mut Stack) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue