microimprovements to oxidizer
This commit is contained in:
parent
fbd6d9d43f
commit
ef266f3811
6 changed files with 69 additions and 75 deletions
|
@ -13,7 +13,7 @@ pub fn dyn_dump(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_def(stack: &mut Stack) -> OError {
|
pub fn dyn_def(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-def".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-def".to_owned()));
|
||||||
};
|
};
|
||||||
Words {
|
Words {
|
||||||
words: vec![Word::Key(Keyword::Def(s))],
|
words: vec![Word::Key(Keyword::Def(s))],
|
||||||
|
@ -23,14 +23,11 @@ pub fn dyn_def(stack: &mut Stack) -> OError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dyn_func(stack: &mut Stack) -> OError {
|
pub fn dyn_func(stack: &mut Stack) -> OError {
|
||||||
let (
|
let (Value::Str(s), Value::Func(f)) = (
|
||||||
Value::Str(s),
|
|
||||||
Value::Func(f),
|
|
||||||
) = (
|
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
) else {
|
) else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-func".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-func".to_owned()));
|
||||||
};
|
};
|
||||||
stack.define_func(s, f);
|
stack.define_func(s, f);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -38,7 +35,7 @@ pub fn dyn_func(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_construct(stack: &mut Stack) -> OError {
|
pub fn dyn_construct(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-construct".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-construct".to_owned()));
|
||||||
};
|
};
|
||||||
Words {
|
Words {
|
||||||
words: vec![Word::Key(Keyword::Construct(
|
words: vec![Word::Key(Keyword::Construct(
|
||||||
|
@ -54,7 +51,7 @@ pub fn dyn_construct(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_namespace(stack: &mut Stack) -> OError {
|
pub fn dyn_namespace(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-construct".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-construct".to_owned()));
|
||||||
};
|
};
|
||||||
Words {
|
Words {
|
||||||
words: vec![Word::Key(Keyword::Construct(
|
words: vec![Word::Key(Keyword::Construct(
|
||||||
|
@ -69,14 +66,11 @@ pub fn dyn_namespace(stack: &mut Stack) -> OError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dyn_def_field(stack: &mut Stack) -> OError {
|
pub fn dyn_def_field(stack: &mut Stack) -> OError {
|
||||||
let (
|
let (Value::Str(s), Value::Str(name)) = (
|
||||||
Value::Str(s),
|
|
||||||
Value::Str(name),
|
|
||||||
) = (
|
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
) else {
|
) else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-def-field".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-def-field".to_owned()));
|
||||||
};
|
};
|
||||||
runtime(|rt| rt.get_type_by_name(&s))
|
runtime(|rt| rt.get_type_by_name(&s))
|
||||||
.ok_or_else(|| stack.error(ErrorKind::TypeNotFound(s)))?
|
.ok_or_else(|| stack.error(ErrorKind::TypeNotFound(s)))?
|
||||||
|
@ -86,16 +80,12 @@ pub fn dyn_def_field(stack: &mut Stack) -> OError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dyn_def_method(stack: &mut Stack) -> OError {
|
pub fn dyn_def_method(stack: &mut Stack) -> OError {
|
||||||
let (
|
let (Value::Str(s), Value::Str(name), Value::Func(f)) = (
|
||||||
Value::Str(s),
|
|
||||||
Value::Str(name),
|
|
||||||
Value::Func(f),
|
|
||||||
) = (
|
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
) else {
|
) else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-def-method".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-def-method".to_owned()));
|
||||||
};
|
};
|
||||||
runtime(|rt| rt.get_type_by_name(&s))
|
runtime(|rt| rt.get_type_by_name(&s))
|
||||||
.ok_or_else(|| stack.error(ErrorKind::TypeNotFound(s)))?
|
.ok_or_else(|| stack.error(ErrorKind::TypeNotFound(s)))?
|
||||||
|
@ -106,14 +96,11 @@ pub fn dyn_def_method(stack: &mut Stack) -> OError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dyn_include(stack: &mut Stack) -> OError {
|
pub fn dyn_include(stack: &mut Stack) -> OError {
|
||||||
let (
|
let (Value::Str(b), Value::Str(a)) = (
|
||||||
Value::Str(b),
|
|
||||||
Value::Str(a),
|
|
||||||
) = (
|
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
) else {
|
) else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-include".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-include".to_owned()));
|
||||||
};
|
};
|
||||||
Words {
|
Words {
|
||||||
words: vec![Word::Key(Keyword::Include(a, b))],
|
words: vec![Word::Key(Keyword::Include(a, b))],
|
||||||
|
@ -123,14 +110,11 @@ pub fn dyn_include(stack: &mut Stack) -> OError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dyn_while(stack: &mut Stack) -> OError {
|
pub fn dyn_while(stack: &mut Stack) -> OError {
|
||||||
let (
|
let (Value::Func(blk), Value::Func(cond)) = (
|
||||||
Value::Func(blk),
|
|
||||||
Value::Func(cond),
|
|
||||||
) = (
|
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
) else {
|
) else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-while".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-while".to_owned()));
|
||||||
};
|
};
|
||||||
loop {
|
loop {
|
||||||
cond.to_call.call(stack)?;
|
cond.to_call.call(stack)?;
|
||||||
|
@ -144,7 +128,7 @@ pub fn dyn_while(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_if(stack: &mut Stack) -> OError {
|
pub fn dyn_if(stack: &mut Stack) -> OError {
|
||||||
let Value::Func(blk) = stack.pop().lock_ro().native.clone() else {
|
let Value::Func(blk) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-if".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-if".to_owned()));
|
||||||
};
|
};
|
||||||
if stack.pop().lock_ro().is_truthy() {
|
if stack.pop().lock_ro().is_truthy() {
|
||||||
blk.to_call.call(stack)?;
|
blk.to_call.call(stack)?;
|
||||||
|
@ -154,7 +138,7 @@ pub fn dyn_if(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_call(stack: &mut Stack) -> OError {
|
pub fn dyn_call(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-call".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-call".to_owned()));
|
||||||
};
|
};
|
||||||
let mut words = Vec::new();
|
let mut words = Vec::new();
|
||||||
let mut ra = 0;
|
let mut ra = 0;
|
||||||
|
@ -173,7 +157,7 @@ pub fn dyn_call(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_objcall(stack: &mut Stack) -> OError {
|
pub fn dyn_objcall(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-objcall".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-objcall".to_owned()));
|
||||||
};
|
};
|
||||||
let mut words = Vec::new();
|
let mut words = Vec::new();
|
||||||
let mut ra = 0;
|
let mut ra = 0;
|
||||||
|
@ -205,7 +189,7 @@ pub fn dyn_all_types(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn dyn_read(stack: &mut Stack) -> OError {
|
pub fn dyn_read(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-read".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-read".to_owned()));
|
||||||
};
|
};
|
||||||
stack.push(
|
stack.push(
|
||||||
Value::Func(AFunc::new(Func {
|
Value::Func(AFunc::new(Func {
|
||||||
|
@ -224,14 +208,11 @@ pub fn dyn_read(stack: &mut Stack) -> OError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dyn_readf(stack: &mut Stack) -> OError {
|
pub fn dyn_readf(stack: &mut Stack) -> OError {
|
||||||
let (
|
let (Value::Str(s), Value::Str(n)) = (
|
||||||
Value::Str(s),
|
|
||||||
Value::Str(n),
|
|
||||||
) = (
|
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
stack.pop().lock_ro().native.clone(),
|
stack.pop().lock_ro().native.clone(),
|
||||||
) else {
|
) else {
|
||||||
return stack.err(ErrorKind::InvalidCall("dyn-readf".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("dyn-readf".to_owned()));
|
||||||
};
|
};
|
||||||
stack.push(
|
stack.push(
|
||||||
Value::Func(AFunc::new(Func {
|
Value::Func(AFunc::new(Func {
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -1,13 +1,14 @@
|
||||||
use spl::{find_in_splpath, lex, oxidizer::RustAppBuilder, start_file};
|
use spl::{find_in_splpath, lex, oxidizer::RustAppBuilder, start_file_in_runtime, Runtime, SetRuntime};
|
||||||
|
|
||||||
use std::{env::args, fs};
|
use std::{env::args, fs};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Runtime::new().set();
|
||||||
let mut args = args().skip(1);
|
let mut args = args().skip(1);
|
||||||
let arg = &args
|
let arg = &args
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or_else(|| find_in_splpath("repl.spl").expect("no file to be run"));
|
.unwrap_or_else(|| find_in_splpath("repl.spl").expect("no file to be run"));
|
||||||
if arg == "--build" || arg == "--run" {
|
if arg == "--build" || arg == "--run" || arg == "--buildrun" {
|
||||||
let file = args.next().unwrap();
|
let file = args.next().unwrap();
|
||||||
let data = fs::read_to_string(file.clone()).expect("unable to read specified file");
|
let data = fs::read_to_string(file.clone()).expect("unable to read specified file");
|
||||||
let build_only = arg == "--build";
|
let build_only = arg == "--build";
|
||||||
|
@ -29,20 +30,24 @@ fn main() {
|
||||||
if build_only {
|
if build_only {
|
||||||
println!("Building...");
|
println!("Building...");
|
||||||
}
|
}
|
||||||
let app = builder.build(build_only).unwrap();
|
let app = builder.build(build_only || arg == "--buildrun").unwrap();
|
||||||
if build_only {
|
if build_only {
|
||||||
println!("Built! Binary is {}", app.get_binary());
|
println!("Built! Binary is {}", app.get_binary());
|
||||||
} else {
|
} else {
|
||||||
let mut args: Vec<String> = args.collect();
|
let mut args: Vec<String> = args.collect();
|
||||||
args.insert(0, file);
|
args.insert(0, file);
|
||||||
let mut command = app.execute(args).unwrap();
|
let mut command = app.execute(args).unwrap();
|
||||||
app.delete();
|
if arg != "--buildrun" {
|
||||||
|
println!("spl: cleaning temporary dir (run with --buildrun to keep)");
|
||||||
|
app.delete();
|
||||||
|
}
|
||||||
command.wait().unwrap();
|
command.wait().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Err(x) = start_file(arg) {
|
if let Err(x) = start_file_in_runtime(arg) {
|
||||||
println!("{x:?}");
|
println!("{x:?}");
|
||||||
}
|
}
|
||||||
|
Runtime::reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,16 +146,16 @@ impl RustAppBuilder {
|
||||||
let mut code = String::new();
|
let mut code = String::new();
|
||||||
for func in self.rust_functions.into_iter().enumerate() {
|
for func in self.rust_functions.into_iter().enumerate() {
|
||||||
code += &format!(
|
code += &format!(
|
||||||
"fn spl_oxidizer_{}(stack: &mut Stack) -> OError {{ {} Ok(()) }}",
|
"fn spl_oxidizer_{}(stack: &mut Stack) -> OError {{ {} Ok(()) }}\n",
|
||||||
func.0, func.1.content
|
func.0, func.1.content
|
||||||
);
|
);
|
||||||
runtime_init += &format!(
|
runtime_init += &format!(
|
||||||
"rt.native_functions.insert({:?}, (0, FuncImpl::Native(spl_oxidizer_{})));",
|
"rt.native_functions.insert({:?}, (0, FuncImpl::Native(spl_oxidizer_{})));\n",
|
||||||
func.1.fn_name, func.0
|
func.1.fn_name, func.0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
for (name, data) in self.to_embed.into_iter() {
|
for (name, data) in self.to_embed.into_iter() {
|
||||||
runtime_init += &format!("rt.embedded_files.insert({:?}, {:?});", name, data);
|
runtime_init += &format!("rt.embedded_files.insert({:?}, {:?});\n", name, data);
|
||||||
}
|
}
|
||||||
fs::write(
|
fs::write(
|
||||||
format!("{tmp}/spl-{name}/src/main.rs"),
|
format!("{tmp}/spl-{name}/src/main.rs"),
|
||||||
|
@ -164,21 +164,18 @@ impl RustAppBuilder {
|
||||||
|
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
|
||||||
pub fn start_file(path: &str) -> Result<Stack, Error> {
|
fn main() {
|
||||||
let mut rt = Runtime::new();
|
let mut rt = Runtime::new();
|
||||||
runtime_init
|
runtime_init
|
||||||
rt.set();
|
rt.set();
|
||||||
(start_file_in_runtime(path), Runtime::reset()).0
|
if let Err(x) = start_file_in_runtime(
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
if let Err(x) = start_file(
|
|
||||||
&args()
|
&args()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.unwrap_or_else(|| find_in_splpath("default_file").expect("no file to be run")),
|
.unwrap_or_else(|| find_in_splpath("default_file").expect("no file to be run")),
|
||||||
) {
|
) {
|
||||||
println!("{x:?}");
|
println!("{x:?}");
|
||||||
}
|
}
|
||||||
|
Runtime::reset();
|
||||||
}
|
}
|
||||||
}.to_owned().replace("default_file", &self.default_file).replace("runtime_init", &runtime_init) + &code,
|
}.to_owned().replace("default_file", &self.default_file).replace("runtime_init", &runtime_init) + &code,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -4,12 +4,16 @@ use super::RustFunction;
|
||||||
|
|
||||||
/// Parses a #-expression and returns the string to be inserted in its place.
|
/// Parses a #-expression and returns the string to be inserted in its place.
|
||||||
fn parse_hash_expr(s: String, name: &str) -> String {
|
fn parse_hash_expr(s: String, name: &str) -> String {
|
||||||
|
if &s == "drop" {
|
||||||
|
return "let _ = stack.pop();".to_owned();
|
||||||
|
}
|
||||||
if &s == "pop" {
|
if &s == "pop" {
|
||||||
return "stack.pop().lock_ro()".to_owned();
|
return "stack.pop().lock_ro()".to_owned();
|
||||||
}
|
}
|
||||||
if &s == "pop_mut" {
|
if &s == "pop_mut" {
|
||||||
return "stack.pop().lock()".to_owned();
|
return "stack.pop().lock()".to_owned();
|
||||||
}
|
}
|
||||||
|
// TODO: broken. fix.
|
||||||
if &s == "pop:Array" {
|
if &s == "pop:Array" {
|
||||||
return format!("{{ require_array_on_stack!(tmp, stack, {name:?}); tmp }}");
|
return format!("{{ require_array_on_stack!(tmp, stack, {name:?}); tmp }}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -517,8 +517,13 @@ impl Stack {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop_until(&mut self, obj: AMObject) -> Vec<AMObject> {
|
pub fn pop_until(&mut self, obj: AMObject) -> Vec<AMObject> {
|
||||||
let Some((idx, ..)) = self.object_stack.iter().enumerate().rfind(|o| *o.1.lock_ro() == *obj.lock_ro()) else {
|
let Some((idx, ..)) = self
|
||||||
return Vec::new()
|
.object_stack
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.rfind(|o| *o.1.lock_ro() == *obj.lock_ro())
|
||||||
|
else {
|
||||||
|
return Vec::new();
|
||||||
};
|
};
|
||||||
let items = self.object_stack[idx + 1..].to_vec();
|
let items = self.object_stack[idx + 1..].to_vec();
|
||||||
self.object_stack = self.object_stack[0..idx].to_vec();
|
self.object_stack = self.object_stack[0..idx].to_vec();
|
||||||
|
@ -1182,7 +1187,9 @@ impl Words {
|
||||||
Value::Str(t.lock_ro().get_name()).into()
|
Value::Str(t.lock_ro().get_name()).into()
|
||||||
};
|
};
|
||||||
if name.contains(':') {
|
if name.contains(':') {
|
||||||
let Some((a, mut name)) = name.split_once(':') else { unreachable!() };
|
let Some((a, mut name)) = name.split_once(':') else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
let mut f = stack.get_var(a.to_owned())?;
|
let mut f = stack.get_var(a.to_owned())?;
|
||||||
while let Some((a, b)) = name.split_once(':') {
|
while let Some((a, b)) = name.split_once(':') {
|
||||||
name = b;
|
name = b;
|
||||||
|
|
|
@ -31,7 +31,7 @@ macro_rules! array {
|
||||||
|
|
||||||
pub fn print(stack: &mut Stack) -> OError {
|
pub fn print(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("print".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("print".to_owned()));
|
||||||
};
|
};
|
||||||
print!("{s}");
|
print!("{s}");
|
||||||
stdout().lock().flush().unwrap();
|
stdout().lock().flush().unwrap();
|
||||||
|
@ -65,7 +65,7 @@ pub fn swap(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn mswap(stack: &mut Stack) -> OError {
|
pub fn mswap(stack: &mut Stack) -> OError {
|
||||||
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("nswap".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("nswap".to_owned()));
|
||||||
};
|
};
|
||||||
let mut array = VecDeque::with_capacity(i as usize);
|
let mut array = VecDeque::with_capacity(i as usize);
|
||||||
for _ in 0..i {
|
for _ in 0..i {
|
||||||
|
@ -80,7 +80,7 @@ pub fn mswap(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn settype(stack: &mut Stack) -> OError {
|
pub fn settype(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("settype".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("settype".to_owned()));
|
||||||
};
|
};
|
||||||
let o = stack.pop();
|
let o = stack.pop();
|
||||||
let kind = runtime(|rt| rt.get_type_by_name(&s))
|
let kind = runtime(|rt| rt.get_type_by_name(&s))
|
||||||
|
@ -101,7 +101,7 @@ pub fn gettype(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn array_new(stack: &mut Stack) -> OError {
|
pub fn array_new(stack: &mut Stack) -> OError {
|
||||||
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("anew".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("anew".to_owned()));
|
||||||
};
|
};
|
||||||
stack.push(Value::Array(vec![Value::Null.spl(); i as usize]).spl());
|
stack.push(Value::Array(vec![Value::Null.spl(); i as usize]).spl());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -110,7 +110,7 @@ pub fn array_new(stack: &mut Stack) -> OError {
|
||||||
pub fn array_len(stack: &mut Stack) -> OError {
|
pub fn array_len(stack: &mut Stack) -> OError {
|
||||||
let binding = stack.pop();
|
let binding = stack.pop();
|
||||||
let Value::Array(ref a) = binding.lock_ro().native else {
|
let Value::Array(ref a) = binding.lock_ro().native else {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-len".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("array-len".to_owned()));
|
||||||
};
|
};
|
||||||
stack.push(Value::Mega(a.len() as i128).spl());
|
stack.push(Value::Mega(a.len() as i128).spl());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -119,10 +119,10 @@ pub fn array_len(stack: &mut Stack) -> OError {
|
||||||
pub fn array_get(stack: &mut Stack) -> OError {
|
pub fn array_get(stack: &mut Stack) -> OError {
|
||||||
let binding = stack.pop();
|
let binding = stack.pop();
|
||||||
let Value::Array(ref a) = binding.lock_ro().native else {
|
let Value::Array(ref a) = binding.lock_ro().native else {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-get".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("array-get".to_owned()));
|
||||||
};
|
};
|
||||||
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-get".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("array-get".to_owned()));
|
||||||
};
|
};
|
||||||
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
|
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -131,10 +131,10 @@ pub fn array_get(stack: &mut Stack) -> OError {
|
||||||
pub fn array_set(stack: &mut Stack) -> OError {
|
pub fn array_set(stack: &mut Stack) -> OError {
|
||||||
let binding = stack.pop();
|
let binding = stack.pop();
|
||||||
let Value::Array(ref mut a) = binding.lock().native else {
|
let Value::Array(ref mut a) = binding.lock().native else {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()));
|
||||||
};
|
};
|
||||||
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()));
|
||||||
};
|
};
|
||||||
let o = stack.pop();
|
let o = stack.pop();
|
||||||
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
|
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
|
||||||
|
@ -467,14 +467,14 @@ pub fn to_str(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn call(stack: &mut Stack) -> OError {
|
pub fn call(stack: &mut Stack) -> OError {
|
||||||
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("call".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("call".to_owned()));
|
||||||
};
|
};
|
||||||
stack.call(&a)
|
stack.call(&a)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn callp(stack: &mut Stack) -> OError {
|
pub fn callp(stack: &mut Stack) -> OError {
|
||||||
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("callp".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("callp".to_owned()));
|
||||||
};
|
};
|
||||||
stack.call(&a)?;
|
stack.call(&a)?;
|
||||||
for _ in 0..a.ret_count {
|
for _ in 0..a.ret_count {
|
||||||
|
@ -505,14 +505,14 @@ pub fn mr_trace(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn exit(stack: &mut Stack) -> OError {
|
pub fn exit(stack: &mut Stack) -> OError {
|
||||||
let Value::Int(a) = stack.pop().lock_ro().native.clone().try_mega_to_int() else {
|
let Value::Int(a) = stack.pop().lock_ro().native.clone().try_mega_to_int() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("exit".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("exit".to_owned()));
|
||||||
};
|
};
|
||||||
process::exit(a)
|
process::exit(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(stack: &mut Stack) -> OError {
|
pub fn exec(stack: &mut Stack) -> OError {
|
||||||
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("exec".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("exec".to_owned()));
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
let f = stack.pop_frame(0);
|
let f = stack.pop_frame(0);
|
||||||
|
@ -524,7 +524,7 @@ pub fn exec(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn exec2(stack: &mut Stack) -> OError {
|
pub fn exec2(stack: &mut Stack) -> OError {
|
||||||
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("exec2".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("exec2".to_owned()));
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
let f = stack.pop_frame(0);
|
let f = stack.pop_frame(0);
|
||||||
|
@ -538,7 +538,7 @@ pub fn exec2(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn exec3(stack: &mut Stack) -> OError {
|
pub fn exec3(stack: &mut Stack) -> OError {
|
||||||
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
let Value::Func(a) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("exec3".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("exec3".to_owned()));
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
let f = stack.pop_frame(0);
|
let f = stack.pop_frame(0);
|
||||||
|
@ -554,7 +554,7 @@ pub fn exec3(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn stop(stack: &mut Stack) -> OError {
|
pub fn stop(stack: &mut Stack) -> OError {
|
||||||
let Value::Int(i) = stack.pop().lock_ro().native.clone().try_mega_to_int() else {
|
let Value::Int(i) = stack.pop().lock_ro().native.clone().try_mega_to_int() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("stop".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("stop".to_owned()));
|
||||||
};
|
};
|
||||||
stack.return_accumultor += i as u32;
|
stack.return_accumultor += i as u32;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -580,7 +580,7 @@ pub fn get_env(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn read_file(stack: &mut Stack) -> OError {
|
pub fn read_file(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("read_file".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("read_file".to_owned()));
|
||||||
};
|
};
|
||||||
stack.push(
|
stack.push(
|
||||||
Value::Str(
|
Value::Str(
|
||||||
|
@ -600,7 +600,7 @@ pub fn alit_end(stack: &mut Stack) -> OError {
|
||||||
|
|
||||||
pub fn import(stack: &mut Stack) -> OError {
|
pub fn import(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("import".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("import".to_owned()));
|
||||||
};
|
};
|
||||||
let fallback = s
|
let fallback = s
|
||||||
.as_str()
|
.as_str()
|
||||||
|
@ -680,7 +680,7 @@ pub fn readln(stack: &mut Stack) -> OError {
|
||||||
pub fn command(stack: &mut Stack) -> OError {
|
pub fn command(stack: &mut Stack) -> OError {
|
||||||
let binding = stack.pop();
|
let binding = stack.pop();
|
||||||
let Value::Array(ref a) = binding.lock_ro().native else {
|
let Value::Array(ref a) = binding.lock_ro().native else {
|
||||||
return stack.err(ErrorKind::InvalidCall("command".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("command".to_owned()));
|
||||||
};
|
};
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
for item in a.iter() {
|
for item in a.iter() {
|
||||||
|
@ -704,7 +704,7 @@ pub fn command(stack: &mut Stack) -> OError {
|
||||||
pub fn command_wait(stack: &mut Stack) -> OError {
|
pub fn command_wait(stack: &mut Stack) -> OError {
|
||||||
let binding = stack.pop();
|
let binding = stack.pop();
|
||||||
let Value::Array(ref a) = binding.lock_ro().native else {
|
let Value::Array(ref a) = binding.lock_ro().native else {
|
||||||
return stack.err(ErrorKind::InvalidCall("command".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("command".to_owned()));
|
||||||
};
|
};
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
for item in a.iter() {
|
for item in a.iter() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue