mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-28 17:16:31 +01:00
mers rewrite is starting to be usable
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{info::Local, program};
|
||||
use crate::program;
|
||||
|
||||
use super::{CompInfo, MersStatement};
|
||||
|
||||
@@ -15,9 +15,10 @@ impl MersStatement for AssignTo {
|
||||
fn compile_custom(
|
||||
&self,
|
||||
info: &mut crate::info::Info<super::Local>,
|
||||
mut comp: CompInfo,
|
||||
comp: CompInfo,
|
||||
) -> Result<Box<dyn program::run::MersStatement>, String> {
|
||||
Ok(Box::new(program::run::assign_to::AssignTo {
|
||||
is_init: false,
|
||||
target: self.target.compile(info, comp)?,
|
||||
source: self.source.compile(info, comp)?,
|
||||
}))
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::{
|
||||
data::{self, Data},
|
||||
info::Local,
|
||||
program,
|
||||
data,
|
||||
program::{self, run::CheckInfo},
|
||||
};
|
||||
|
||||
use super::{CompInfo, MersStatement};
|
||||
@@ -17,7 +16,7 @@ pub struct Function {
|
||||
impl MersStatement for Function {
|
||||
fn has_scope(&self) -> bool {
|
||||
// TODO: what???
|
||||
false
|
||||
true
|
||||
}
|
||||
fn compile_custom(
|
||||
&self,
|
||||
@@ -25,15 +24,21 @@ impl MersStatement for Function {
|
||||
mut comp: CompInfo,
|
||||
) -> Result<Box<dyn program::run::MersStatement>, String> {
|
||||
comp.is_init = true;
|
||||
let arg = self.arg.compile(info, comp)?;
|
||||
let arg_target = Arc::new(self.arg.compile(info, comp)?);
|
||||
comp.is_init = false;
|
||||
let run = self.run.compile(info, comp)?;
|
||||
let run = Arc::new(self.run.compile(info, comp)?);
|
||||
let arg2 = Arc::clone(&arg_target);
|
||||
let run2 = Arc::clone(&run);
|
||||
Ok(Box::new(program::run::function::Function {
|
||||
func_no_info: data::function::Function {
|
||||
info: program::run::Info::neverused(),
|
||||
out: Arc::new(|_i| todo!()),
|
||||
run: Arc::new(move |i, info| {
|
||||
data::defs::assign(i, &arg.run(info));
|
||||
info: Arc::new(program::run::Info::neverused()),
|
||||
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
|
||||
out: Arc::new(move |a, i| {
|
||||
arg2.check(i, Some(a))?;
|
||||
Ok(run2.check(i, None)?)
|
||||
}),
|
||||
run: Arc::new(move |arg, info| {
|
||||
data::defs::assign(arg, &arg_target.run(info));
|
||||
run.run(info)
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ impl MersStatement for If {
|
||||
) -> Result<Box<dyn program::run::MersStatement>, String> {
|
||||
Ok(Box::new(program::run::r#if::If {
|
||||
condition: self.condition.compile(info, comp)?,
|
||||
on_true: self.condition.compile(info, comp)?,
|
||||
on_true: self.on_true.compile(info, comp)?,
|
||||
on_false: if let Some(v) = &self.on_false {
|
||||
Some(v.compile(info, comp)?)
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{info::Local, program};
|
||||
use crate::program;
|
||||
|
||||
use super::{CompInfo, MersStatement};
|
||||
|
||||
@@ -22,6 +22,7 @@ impl MersStatement for InitTo {
|
||||
comp.is_init = false;
|
||||
let source = self.source.compile(info, comp)?;
|
||||
Ok(Box::new(program::run::assign_to::AssignTo {
|
||||
is_init: true,
|
||||
target,
|
||||
source,
|
||||
}))
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
use crate::program;
|
||||
|
||||
use super::{CompInfo, MersStatement};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Loop {
|
||||
pub inner: Box<dyn MersStatement>,
|
||||
}
|
||||
|
||||
impl MersStatement for Loop {
|
||||
fn has_scope(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn compile_custom(
|
||||
&self,
|
||||
info: &mut crate::info::Info<super::Local>,
|
||||
comp: CompInfo,
|
||||
) -> Result<Box<dyn program::run::MersStatement>, String> {
|
||||
Ok(Box::new(program::run::r#loop::Loop {
|
||||
inner: self.inner.compile(info, comp)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,13 @@ pub mod r#if;
|
||||
#[cfg(feature = "parse")]
|
||||
pub mod init_to;
|
||||
#[cfg(feature = "parse")]
|
||||
pub mod r#loop;
|
||||
#[cfg(feature = "parse")]
|
||||
pub mod switch;
|
||||
#[cfg(feature = "parse")]
|
||||
pub mod tuple;
|
||||
#[cfg(feature = "parse")]
|
||||
pub mod value;
|
||||
#[cfg(feature = "parse")]
|
||||
pub mod variable;
|
||||
|
||||
pub trait MersStatement: Debug {
|
||||
pub trait MersStatement: Debug + Send + Sync {
|
||||
fn has_scope(&self) -> bool;
|
||||
fn compile_custom(
|
||||
&self,
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
use crate::data::Type;
|
||||
|
||||
use super::{CompInfo, MersStatement};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Switch {
|
||||
source: Box<dyn MersStatement>,
|
||||
arms: Vec<SwitchArm>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SwitchArm {
|
||||
requires_type: Type,
|
||||
}
|
||||
|
||||
impl MersStatement for Switch {
|
||||
fn has_scope(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn compile_custom(
|
||||
&self,
|
||||
info: &mut crate::info::Info<super::Local>,
|
||||
comp: CompInfo,
|
||||
) -> Result<Box<dyn crate::program::run::MersStatement>, String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ impl MersStatement for Value {
|
||||
}
|
||||
fn compile_custom(
|
||||
&self,
|
||||
info: &mut crate::info::Info<super::Local>,
|
||||
comp: CompInfo,
|
||||
_info: &mut crate::info::Info<super::Local>,
|
||||
_comp: CompInfo,
|
||||
) -> Result<Box<dyn program::run::MersStatement>, String> {
|
||||
Ok(Box::new(program::run::value::Value {
|
||||
val: self.0.clone(),
|
||||
|
||||
@@ -27,6 +27,7 @@ impl MersStatement for Variable {
|
||||
)
|
||||
}
|
||||
Ok(Box::new(program::run::variable::Variable {
|
||||
is_init: comp.is_init,
|
||||
is_ref: comp.is_init || self.is_ref,
|
||||
var: if let Some(v) = info.get_var(&self.var) {
|
||||
*v
|
||||
|
||||
Reference in New Issue
Block a user