use crate::{
backends::ConvertTo,
functions::externals::ValkyrieExternalFunction,
modifiers::{AccessType, CurryType, InlineType},
modules::Hir2Mir,
types::ValkyrieMetaType,
values::symbols::AsSymbol,
ModuleItem, ModuleResolver, ValkyrieResult, ValkyrieSymbol, ValkyrieValue,
};
use indexmap::IndexMap;
use nyar_error::{Result, RuntimeError};
use nyar_wasm::FunctionType;
use shredder::Gc;
use std::{collections::BTreeMap, sync::Arc};
use valkyrie_ast::{FunctionDeclaration, StatementBlock};
mod codegen;
pub mod externals;
pub mod operators;
pub trait ValkyrieFunctionType {
fn boxed(self) -> ValkyrieValue;
fn type_info(&self) -> Gc<ValkyrieMetaType>;
}
#[derive(Clone, Debug)]
pub struct ValkyrieFunction {
name: ValkyrieSymbol,
}
impl ValkyrieFunction {
pub fn new(name: ValkyrieSymbol) -> Self {
Self { name }
}
}
#[derive(Clone, Debug)]
pub struct ValkyrieMonomorphicFunction {
pub curry: CurryType,
pub inline: InlineType,
pub access: AccessType,
pub positional: Vec<ValkyrieValue>,
pub mixed: IndexMap<String, ValkyrieValue>,
pub named: BTreeMap<String, ValkyrieValue>,
pub return_type: ValkyrieValue,
pub effect_type: ValkyrieValue,
}
#[derive(Clone, Debug)]
pub struct ValkyriePartialFunction {
pub prototype: Arc<ValkyrieFunction>,
pub generic: Vec<ValkyrieValue>,
pub positional: Vec<ValkyrieValue>,
pub named: BTreeMap<String, ValkyrieValue>,
pub continuation: Option<StatementBlock>,
}
pub struct ValkyrieContinuation {
pub scope: ValkyrieMetaType,
pub block: StatementBlock,
}
#[derive(Clone, Debug)]
pub struct ValkyrieFunctionInstance {
pub return_type: ValkyrieValue,
}
impl ValkyrieFunction {
pub fn instance(self: Arc<Self>) -> ValkyriePartialFunction {
ValkyriePartialFunction {
prototype: self.clone(),
generic: vec![],
positional: vec![],
named: Default::default(),
continuation: None,
}
}
}
impl ValkyrieMonomorphicFunction {
pub fn can_invoke(partial: &ValkyriePartialFunction) {
todo!()
}
}
impl ValkyriePartialFunction {
pub fn can_invoke(&self) -> bool {
todo!()
}
pub fn add_continuation(&mut self, continuation: StatementBlock) -> ValkyrieResult<()> {
match self.continuation {
Some(_) => Err(RuntimeError::new("continuation already exists"))?,
None => {
self.continuation = Some(continuation);
Ok(())
}
}
}
pub fn add_positional(&mut self, value: ValkyrieValue) -> ValkyrieResult<()> {
todo!()
}
pub fn add_named(&mut self, name: String, value: ValkyrieValue) -> ValkyrieResult<()> {
match self.named.get(&name) {
Some(_) => Err(RuntimeError::new("named argument already exists"))?,
None => {
self.named.insert(name, value);
Ok(())
}
}
}
}