mers rewrite is starting to be usable

This commit is contained in:
Mark
2023-08-14 17:17:08 +02:00
parent e549b1a5be
commit 2a7cb08596
50 changed files with 1411 additions and 407 deletions

View File

@@ -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)?,
}))

View File

@@ -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)
}),
},

View File

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

View File

@@ -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,
}))

View File

@@ -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)?,
}))
}
}

View File

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

View File

@@ -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!()
}
}

View File

@@ -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(),

View File

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