Skip to content

Commit

Permalink
Move flattening.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Oct 3, 2023
1 parent f0e369f commit 0866e90
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/code_generation/mod.rs → src/flattening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ use crate::{



#[derive(Debug)]
struct LocalVariable {
pub location : Span,
pub typ : Option<SpanTypeExpression>
}

// These are assignable connections
#[derive(Debug)]
enum ConnectionRead {
Local(usize),
ArrayIdx{arr_local : usize, idx_local : usize},
//StructField{struct_local : usize, field : usize},
FuncOutput{instantiation_idx : usize, field : usize},
Constant(Value)
}
#[derive(Debug)]
enum ConnectionWrite {
Local(usize),
ArrayIdx(Box<(ConnectionWrite, usize)>),
Expand All @@ -30,12 +33,14 @@ enum ConnectionWrite {

type SpanConnectionRead = (ConnectionRead, Span);

#[derive(Debug)]
enum Instantiation {
Named(ValueUUID),
UnaryOp(Operator),
BinaryOp(Operator)
}

#[derive(Debug)]
struct Connection {
num_regs : u32,
from : SpanConnectionRead,
Expand Down Expand Up @@ -253,6 +258,7 @@ pub fn flatten(module : &Module, linker : &Linker, errors : &mut ErrorCollector)
FlattenedModule { locals: result.locals, instantiations: result.instantiations, connections: result.connections }
}

#[derive(Debug)]
pub struct FlattenedModule {
locals : Vec<LocalVariable>,
instantiations : Vec<Instantiation>,
Expand Down
6 changes: 3 additions & 3 deletions src/linker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::{HashMap, HashSet}, ops::{IndexMut, Index}};

use crate::{ast::{Module, LinkInfo, Span, Value, GlobalReference}, arena_alloc::{ArenaAllocator, UUID}, parser::{FullParseResult, TokenTreeNode}, tokenizer::Token, errors::{ErrorCollector, error_info}, code_generation::flatten};
use crate::{ast::{Module, LinkInfo, Span, Value, GlobalReference}, arena_alloc::{ArenaAllocator, UUID}, parser::{FullParseResult, TokenTreeNode}, tokenizer::Token, errors::{ErrorCollector, error_info}, flattening::flatten};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NamedUUIDMarker;
Expand Down Expand Up @@ -493,8 +493,8 @@ impl Linker {
if !md.link_info.is_fully_linked {
continue;
}
let _flt = flatten(md, &self, errors);
// TODO use
let flt = flatten(md, &self, errors);
println!("{:?}", flt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod tokenizer;
mod parser;
mod errors;
mod ast;
mod code_generation;
mod flattening;
mod arena_alloc;

mod dev_aid;
Expand Down

0 comments on commit 0866e90

Please sign in to comment.