diff --git a/.gitignore b/.gitignore index ea8c4bf..68f7583 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +*.sh \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3ec421c --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Akai Lang + +Akai Lang (yeah I'm not creative and the name is still unused on github, sooo) is a programming language I'm building as a side project to my Moonhare Game Engine. + +**Work in Progress - doesn't work yet** + +## Planned Features +- Object-Oriented +- dynamic typing +- LLVM Backend + +## Hello World +```AkaiLang +fun helloWorld() { + print("Hello World!") +} +``` \ No newline at end of file diff --git a/src/language_frontend/mod.rs b/src/language_frontend/mod.rs index 851c0bc..2e33aaf 100644 --- a/src/language_frontend/mod.rs +++ b/src/language_frontend/mod.rs @@ -1 +1,3 @@ pub mod ast; +pub mod parser; +pub mod tokens; \ No newline at end of file diff --git a/src/parser.rs b/src/language_frontend/parser.rs similarity index 96% rename from src/parser.rs rename to src/language_frontend/parser.rs index b8dde67..2790b65 100644 --- a/src/parser.rs +++ b/src/language_frontend/parser.rs @@ -1,6 +1,6 @@ use chumsky::{combinator::Or, prelude::{choice, just, recursive}, recursive, select, text::{self, ascii::ident}, IterParser, Parser}; -use crate::{ast::ast::Expression, tokens::Token}; +use crate::{language_frontend::ast::ast::Expression, language_frontend::tokens::Token}; #[allow(clippy::let_and_return)] diff --git a/src/tokens.rs b/src/language_frontend/tokens.rs similarity index 100% rename from src/tokens.rs rename to src/language_frontend/tokens.rs diff --git a/src/llvm_backend/compiler.rs b/src/llvm_backend/compiler.rs deleted file mode 100644 index 4a24b53..0000000 --- a/src/llvm_backend/compiler.rs +++ /dev/null @@ -1,4 +0,0 @@ -use std::collections::HashMap; - -use inkwell::{builder::Builder, context::Context, module::Module, values::{FunctionValue, PointerValue}}; - diff --git a/src/llvm_backend/mod.rs b/src/llvm_backend/mod.rs deleted file mode 100644 index eaa9f91..0000000 --- a/src/llvm_backend/mod.rs +++ /dev/null @@ -1,103 +0,0 @@ -use std::collections::HashMap; - -use inkwell::values::{BasicValueEnum, FunctionValue, PointerValue}; - -use crate::ast::ast::Expression; - -pub mod compiler; - -// LLVM Codegen - -struct CodegenContext<'ctx> { - builder: inkwell::builder::Builder<'ctx>, - module: inkwell::module::Module<'ctx>, - context: &'ctx inkwell::context::Context, - variables: HashMap>, - functions: HashMap>, -} - - -impl<'ctx, 'src> Expression<'src> { - fn codegen(&self, ctx: &mut CodegenContext<'ctx>) -> BasicValueEnum<'ctx> { - match self { - Expression::VariableName(name) => { - todo!() - }, - - Expression::Integer(_) => { - todo!() - }, - - Expression::Float(_) => { - todo!() - }, - - Expression::String(_) => { - todo!() - }, - - Expression::Bool(_) => { - todo!() - }, - - Expression::Negatation(expression) => { - todo!() - }, - - Expression::Add( - lhs, - rhs - ) => { - let l = lhs.codegen(ctx).into_int_value(); - let r = rhs.codegen(ctx).into_int_value(); - ctx.builder.build_int_add(l, r, "addtmp").unwrap().into() - }, - - Expression::Substract( - lhs, - rhs - ) => { - todo!() - }, - - Expression::Multiply( - lhs, - rhs - ) => { - todo!() - }, - - Expression::Divide( - lhs, - rhs - ) => { - todo!() - }, - - Expression::Var { - name, - rhs, - then - } => { - let value = rhs.codegen(ctx); - let ptr = ctx.builder.build_alloca(ctx.context.f32_type(), name).unwrap(); - let _ = ctx.builder.build_store(ptr, value); - ctx.variables.insert(name.to_string(), ptr); - then.codegen(ctx) - }, - - Expression::Function { - name, - args, - body, - then - } => { - todo!() - }, - - Expression::Unit => { - todo!() - }, - } - } -} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9acea71..7a64e31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,9 @@ use chumsky::Parser; use logos::Logos; -use crate::{parser::parser, tokens::Token}; +use crate::{language_frontend::parser::parser, language_frontend::tokens::Token}; -mod tokens; mod language_frontend; -mod parser; -mod llvm_backend; fn main() { let lexer = Token::lexer("(1 + 1) * 3"); diff --git a/syntax.akai b/syntax.akai index 40c7e25..52ad6bb 100644 --- a/syntax.akai +++ b/syntax.akai @@ -18,14 +18,14 @@ class Cat derive Animal: fun helloWorld() { // Variables either dynamically or statically typed var String: test = "I'm a string" - var foo = 12 + var foo = 12 // reads as int var bar = foo + 10 print("Hello World " + bar) } -fun returnsInteger(int: i): int { +fun returnsIntegerPlusOne(int: i): int { -> i + 1 }