Skip to content

Commit

Permalink
Merge pull request #20 from JCBurnside/feature/extern-items
Browse files Browse the repository at this point in the history
Feature/extern items
  • Loading branch information
JCBurnside authored Mar 17, 2024
2 parents 3806190 + cebf2a0 commit ba30eff
Show file tree
Hide file tree
Showing 16 changed files with 764 additions and 322 deletions.
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
},
);

let (program, warnings) = compiler::from_file(&args.file, fwd_decl.clone(), "jit".to_string());
let (program, _warnings) = compiler::from_file(&args.file, fwd_decl.clone(), "jit".to_string());

match program {
Err(errors) => {
Expand Down
7 changes: 4 additions & 3 deletions cli/test.fb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ let test_ifs a b : bool -> bool -> int32 =
print_str "neither\n";
return 0;

for<T> let eq_check a b : T -> T -> bool = a < b || a > b

let test_ifexpr a b : bool -> bool -> int32 = if a then
0
else if b then
else if b then
1
else if true then
let x : int32 = 2;
Expand All @@ -21,6 +19,8 @@ let test_ifexpr a b : bool -> bool -> int32 = if a then
else
4

extern "C" let externed : int32 -> int32;

let show_short_curicuit _ : () -> () =
if (show_something ()) && (show_something_else ()) then
print_str "this is a seperator\n";
Expand All @@ -46,4 +46,5 @@ let main _ : () -> () =
| 2 -> print_str "two",
print_str "main";
show_short_curicuit ();
let y = externed 0;
return ();
24 changes: 18 additions & 6 deletions compiler/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ impl ModuleDeclaration {
continue;
}
Declaration::Value(v) => {
// todo check if externed. if so no work needed.
if v.value == ValueType::External {
continue;
}
let old = v.ident.clone();
v.ident = path.iter().cloned().join("::") + "::" + &v.ident;
(old, v.ident.clone())
Expand Down Expand Up @@ -187,6 +189,12 @@ pub struct ArgDeclaration {
pub ty: Option<ResolvedType>,
}

#[derive(PartialEq,Debug, Clone)]
pub struct Abi {
pub loc : crate::Location,
pub identifier : String,
}

#[derive(PartialEq, Debug)]
pub struct ValueDeclaration {
pub loc: crate::Location, //should be location of the ident.
Expand All @@ -196,6 +204,7 @@ pub struct ValueDeclaration {
pub ty: Option<ResolvedType>,
pub value: ValueType,
pub generictypes: Option<GenericsDecl>,
pub abi : Option<Abi>,
}
impl ValueDeclaration {
fn replace(&mut self, nice_name: &str, actual: &str) {
Expand All @@ -212,7 +221,7 @@ impl ValueDeclaration {
}
for arg in &self.args {
if let Some(ty) = &arg.ty {
let mut tys = ty.get_all_types();
let tys = ty.get_all_types();
output.extend(tys);
}
}
Expand All @@ -226,21 +235,23 @@ impl ValueDeclaration {
pub enum ValueType {
Expr(Expr),
Function(Vec<Statement>),
External,
}
impl ValueType {
fn replace(&mut self, nice_name: &str, actual: &str) {
match self {
ValueType::Expr(expr) => expr.replace(nice_name, actual),
ValueType::Function(stmnts) => stmnts
Self::Expr(expr) => expr.replace(nice_name, actual),
Self::Function(stmnts) => stmnts
.iter_mut()
.for_each(|it| it.replace(nice_name, actual)),
Self::External => (),
}
}

fn get_dependencies(&self, known_values: Vec<String>) -> HashSet<String> {
match self {
ValueType::Expr(expr) => expr.get_dependencies(known_values),
ValueType::Function(stmnts) => {
Self::Expr(expr) => expr.get_dependencies(known_values),
Self::Function(stmnts) => {
stmnts
.iter()
.fold(
Expand All @@ -255,6 +266,7 @@ impl ValueType {
)
.1
}
Self::External => HashSet::new(),
}
}
}
Expand Down
Loading

0 comments on commit ba30eff

Please sign in to comment.