Skip to content

Commit

Permalink
needed a lot of conditional compilation
Browse files Browse the repository at this point in the history
added needed feature gates.
  • Loading branch information
JCBurnside committed Feb 1, 2024
1 parent c2a8369 commit 42a9fe8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
24 changes: 15 additions & 9 deletions compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::PathBuf;

pub mod ast;
// mod langstd;
#[cfg(feature = "full")]
mod code_gen;
mod lexer;
mod parser;
Expand All @@ -12,18 +13,15 @@ pub mod typed_ast;
pub mod types;
mod util;

use code_gen::CodeGen;
use typed_ast::{ResolvedTypeDeclaration, TypedDeclaration, TypedModuleDeclaration};
// use code_gen::CodeGen;
use inkwell::{
module::Module,
targets::{CodeModel, Target, TargetMachine},
};


use lexer::TokenStream;
use parser::Parser;
use types::{ResolvedType, TypeResolver};

use inkwell::context::Context;
use types::ResolvedType;
#[cfg(feature="full")]
use types::TypeResolver;
use multimap::MultiMap;
type Location = (usize, usize);

Expand All @@ -32,6 +30,9 @@ pub fn get_untyped_ast(input:&str,file_name:&str) -> ast::ModuleDeclaration{
Parser::from_stream(ts).module(file_name.to_string())
}

#[cfg(feature="full")]
use inkwell::{context::Context, module::Module};

#[cfg(feature = "full")]
pub fn from_file<'ctx>(
file: &PathBuf,
Expand All @@ -40,6 +41,11 @@ pub fn from_file<'ctx>(
is_debug: bool,
project_name: String,
) -> Result<Module<'ctx>, Vec<Box<dyn Display>>> {

use code_gen::CodeGen;
use inkwell::{
targets::{CodeModel, Target, TargetMachine},
};
// TODO: I would like to make this work for now I will read the whole file to a string then
// let file = File::open(file).map_err(Box::new).map_err(|err| vec![err as Box<dyn Display>])?;
// let file = BufReader::new(file);
Expand Down Expand Up @@ -85,7 +91,7 @@ pub fn from_file<'ctx>(

let mut ast = parser.module(file_name.to_str().unwrap().to_string());
ast.canonialize(vec![project_name]);
let mut ast = TypedModuleDeclaration::from(ast, &fwd_declarations,&HashMap::new(), &HashMap::new()); //TODO: foward declare std lib
let mut ast = TypedModuleDeclaration::from(ast, &fwd_declarations,); //TODO: foward declare std lib

ast.lower_generics(&HashMap::new());
ast.declarations.retain(|it| match it {
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::HashMap, mem::size_of};

use crate::{typed_ast, util::ExtraUtilFunctions};
#[cfg(feature = "full")]
use inkwell::{
context::Context,
debug_info::{DIFile, DIFlags, DIFlagsConstants, DISubroutineType, DIType, DebugInfoBuilder},
Expand All @@ -9,6 +10,8 @@ use inkwell::{
AddressSpace,
};


use itertools::Itertools;
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub enum IntWidth {
Eight,
Expand Down Expand Up @@ -490,15 +493,17 @@ mod consts {
pub const UNIT: ResolvedType = ResolvedType::Unit;
}
pub use consts::*;
use itertools::Itertools;

#[cfg(feature="full")]
pub struct TypeResolver<'ctx> {
known: HashMap<ResolvedType, AnyTypeEnum<'ctx>>,
ctx: &'ctx Context,
ditypes: HashMap<ResolvedType, DIType<'ctx>>,
target_data: TargetData,
}

#[cfg(feature="full")]

impl<'ctx> TypeResolver<'ctx> {
pub fn new(ctx: &'ctx Context, target_data: TargetData) -> Self {
let unit = ctx.const_struct(&[], false);
Expand Down

0 comments on commit 42a9fe8

Please sign in to comment.