-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
129 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
use crate::ValkyrieCodegen; | ||
|
||
pub trait FromFrontend<Item> { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> nyar_error::Result<Item>; | ||
} | ||
|
||
pub trait IntoBackend<Item> { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> nyar_error::Result<Item>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use crate::{ValkyrieStructure, ValkyrieSymbol}; | ||
use indexmap::IndexMap; | ||
use nyar_error::{NyarError, Result}; | ||
use nyar_wasm::Operation; | ||
use std::mem::take; | ||
use valkyrie_ast::{NamespaceDeclaration, ProgramRoot, StatementKind}; | ||
use valkyrie_parser::StatementNode; | ||
|
||
pub struct ValkyrieModule {} | ||
|
||
/// Convert file to module | ||
pub struct ModuleContext { | ||
/// The declared namespace | ||
namespace: Option<ValkyrieSymbol>, | ||
/// main function of the file | ||
main: Vec<StatementNode>, | ||
/// The declared items in file | ||
items: IndexMap<String, ModuleItem>, | ||
/// Collect errors | ||
errors: Vec<NyarError>, | ||
} | ||
|
||
pub enum ModuleItem { | ||
Structure(ValkyrieStructure), | ||
} | ||
|
||
trait AsModuleItem { | ||
type Output = (); | ||
fn send_module(self, ctx: &mut ModuleContext) -> Result<Self::Output>; | ||
} | ||
|
||
impl AsModuleItem for ProgramRoot { | ||
fn send_module(self, ctx: &mut ModuleContext) -> Result<Self::Output> { | ||
for statement in self.statements { | ||
statement.send_module(ctx)? | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl AsModuleItem for StatementKind { | ||
fn send_module(self, ctx: &mut ModuleContext) -> Result<Self::Output> { | ||
match self { | ||
Self::Nothing => {} | ||
Self::Document(_) => {} | ||
Self::Annotation(_) => {} | ||
Self::Namespace(v) => v.send_module(ctx)?, | ||
Self::Import(_) => {} | ||
Self::Class(_) => {} | ||
Self::Union(_) => {} | ||
Self::Enumerate(_) => {} | ||
Self::Trait(_) => {} | ||
Self::Extends(_) => {} | ||
Self::Function(_) => {} | ||
Self::Variable(_) => {} | ||
Self::Guard(_) => {} | ||
Self::While(_) => {} | ||
Self::For(_) => {} | ||
Self::Control(_) => {} | ||
Self::Expression(_) => {} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl AsModuleItem for NamespaceDeclaration { | ||
fn send_module(self, ctx: &mut ModuleContext) -> Result<Self::Output> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl ModuleContext { | ||
pub fn visit(&mut self, root: ProgramRoot) -> Vec<NyarError> { | ||
let progress = root.send_module(self); | ||
let mut errors = take(&mut self.errors); | ||
match progress { | ||
Ok(_) => {} | ||
Err(e) => errors.push(e), | ||
} | ||
errors | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1 @@ | ||
use super::*; | ||
|
||
impl FromFrontend<ValkyrieStructure> for ClassDeclaration { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> Result<ValkyrieStructure> { | ||
let mut output = ValkyrieStructure::new(&state.current_namespace, &self.name); | ||
// state.register_class(output.clone()); | ||
|
||
for x in &self.terms { | ||
match x { | ||
ClassTerm::Macro(_) => {} | ||
ClassTerm::Field(v) => match output.add_field(v.build(state)?) { | ||
Err(e) if !state.interactive => state.add_error(e), | ||
_ => {} | ||
}, | ||
ClassTerm::Method(v) => match output.add_method(v.build(state)?) { | ||
Err(e) if !state.interactive => state.add_error(e), | ||
_ => {} | ||
}, | ||
ClassTerm::Domain(_) => {} | ||
} | ||
} | ||
Ok(output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1 @@ | ||
use super::*; | ||
|
||
impl FromFrontend<FieldDefinition> for FieldDeclaration { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> Result<FieldDefinition> { | ||
let mut output = FieldDefinition::new(&self.name); | ||
match &self.typing { | ||
Some(s) => output.set_type(s.clone()), | ||
None => {} | ||
} | ||
Ok(output) | ||
} | ||
} | ||
|
||
impl IntoBackend<FieldType> for FieldDefinition { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> nyar_error::Result<FieldType> { | ||
let mut output = FieldType::new(Symbol::from(self.name())); | ||
output.mutable = true; | ||
match self.get_type() { | ||
Some(ExpressionKind::Symbol(v)) => match v.to_string().as_str() { | ||
"u32" => output.r#type = NyarType::U32, | ||
"u64" => output.r#type = NyarType::I64, | ||
"i32" => output.r#type = NyarType::I32, | ||
"i64" => output.r#type = NyarType::I64, | ||
"f32" => output.r#type = NyarType::F32, | ||
"f64" => output.r#type = NyarType::F64, | ||
"Any" => output.r#type = NyarType::Any, | ||
"core::primitive::u32" => output.r#type = NyarType::U32, | ||
s => output.r#type = NyarType::Named { symbol: Symbol::new(s), nullable: self.get_optional() }, | ||
}, | ||
Some(ExpressionKind::GenericCall(v)) => match &v.base { | ||
ExpressionKind::Symbol(s) => match s.to_string().as_str() { | ||
"Array" => match &v.term { | ||
GenericCallTerm::Associated(_) => {} | ||
GenericCallTerm::Generic(g) => match g.terms.first() { | ||
None => {} | ||
Some(v) => match &v.value { | ||
ExpressionKind::Symbol(v) => match v.to_string().as_str() { | ||
"u8" => output.r#type = NyarType::Array { inner: Box::new(NyarType::U8), nullable: false }, | ||
_ => {} | ||
}, | ||
_ => {} | ||
}, | ||
}, | ||
}, | ||
_ => {} | ||
}, | ||
s => { | ||
println!("UNKNOWN_FIELD_GENERIC: {s:?}") | ||
} | ||
}, | ||
Some(s) => { | ||
println!("UNKNOWN_FIELD_TYPE: {s:?}") | ||
} | ||
None => {} | ||
} | ||
Ok(output) | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
projects/valkyrie-types/src/types/function_type/codegen.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1 @@ | ||
use super::*; | ||
use nyar_wasm::FunctionType; | ||
|
||
impl FromFrontend<FunctionDefinition> for FunctionDeclaration { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> Result<FunctionDefinition> { | ||
let mut output = FunctionDefinition::new(&state.current_namespace, &self.name)?; | ||
|
||
Ok(output) | ||
} | ||
} | ||
|
||
impl IntoBackend<FunctionType> for FunctionDefinition { | ||
fn build(&self, state: &mut ValkyrieCodegen) -> Result<FunctionType> { | ||
let mut output = FunctionType::new(Symbol::from(self.name())); | ||
|
||
Ok(output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use super::*; | ||
|
||
pub struct ValkyrieSymbol { | ||
path: Vec<Arc<str>>, | ||
span: FileSpan, | ||
} | ||
|
||
impl Debug for ValkyrieSymbol { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.write_str(&self.path.join("∷")) | ||
} | ||
} | ||
|
||
trait AsValkyrieSymbol { | ||
fn as_valkyrie_symbol(&self) -> ValkyrieSymbol; | ||
} | ||
|
||
impl AsValkyrieSymbol for NamePathNode { | ||
fn as_valkyrie_symbol(&self) -> ValkyrieSymbol { | ||
ValkyrieSymbol { path: self.path.iter().map(|s| Arc::from(s.name.as_str())).collect(), span: self.span.clone() } | ||
} | ||
} | ||
|
||
impl ValkyrieSymbol { | ||
pub fn new<S: AsValkyrieSymbol>(id: S) -> Self { | ||
id.as_valkyrie_symbol() | ||
} | ||
pub fn with_span(self, span: FileSpan) -> Self { | ||
Self { span, ..self } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters