1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

Compare commits

..

No commits in common. "9431270504cbfdd1fbfe59ed02fb7a37f9350cce" and "1f5eaab23a0dcf1ac5bdac3e8f8c03b3dfb89847" have entirely different histories.

7 changed files with 20 additions and 50 deletions

View file

@ -1,4 +0,0 @@
build-lib:
@echo "Building lib..."
cp ./lib/. /usr/include/hazure/ -r
@echo "Building lib... done"

View file

@ -12,7 +12,6 @@ Note: Everything in this project can be changed at anytime! (I'm still finding o
# Prerequistie
- `clang++`(preferred, default) or any C++ compiler
- `make` for Makefile
- Rust (if you're going to build from source)
# Configuration
@ -22,5 +21,13 @@ You can also configurate Hades compiler (currently you can only change the C++ c
compiler = "clang++"
```
# TODO
> This is only contains important TODOs, smaller TODOs isn't listed here and instead scattered around among sources code.
- More compiler configuration (e.x. complier options)
- Optimization (IR)
- Standard library & Runtime stuff
# License
Hades is licensed under both [MIT license](https://github.com/azur1s/hades/blob/master/LICENSE-MIT) and [Apache License](https://github.com/azur1s/hades/blob/master/LICENSE-APACHE)
Anything helps! :D

View file

@ -3,7 +3,7 @@ use std::fmt::Display;
use hir::{IR, IRKind, Value};
const MODULE_INCLUDES: [&str; 3] = [
"\"hazure/io.hpp\"", // `read()` and `write()`
"<iostream>", // stdin `@read()` and stdout `@write()`
"<stdbool.h>", // bool type
"<string>", // string type
];
@ -62,8 +62,8 @@ impl Codegen {
IRKind::Intrinsic { name, args } => {
match name.as_str() {
"write" => { format!("hazure_write({}){}\n", self.gen_ir(&args[0], false), semicolon!()) },
"read" => { format!("hazure_read({}){}\n", self.gen_ir(&args[0], false), semicolon!()) },
"write" => { format!("std::cout << {};\n", self.gen_ir(&args[0], false)) },
"read" => { format!("std::cin >> {};\n", self.gen_ir(&args[0], false)) },
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
}
},

View file

@ -105,8 +105,7 @@ pub fn expr_to_ir(expr: &Expr) -> (Option<IRKind>, Option<LoweringError>) {
if_err_return!(lhs_ir.1);
match &rhs.0 {
call @ Expr::Call { name, args }
| call @ Expr::Intrinsic { name, args } => {
call @ Expr::Call { name, args } => {
let name = match &name.0 {
Expr::Identifier(s) => s.clone(),
// Should never happen because the parser should have caught this
@ -126,13 +125,7 @@ pub fn expr_to_ir(expr: &Expr) -> (Option<IRKind>, Option<LoweringError>) {
let mut args = vec![lhs_ir.0.unwrap()];
args.append(&mut largs);
let ir_kind = match call.0.unwrap() {
IRKind::Call { .. } => IRKind::Call { name, args },
IRKind::Intrinsic { .. } => IRKind::Intrinsic { name, args },
_ => unreachable!()
};
return (Some(ir_kind), None);
return (Some(IRKind::Call { name, args }), None);
},
_ => return (None, Some(LoweringError {
span: rhs.1.clone(),

View file

@ -1,4 +0,0 @@
fun main: int = do
"Hello, World!\n"
|> @write();
end;

View file

@ -2,13 +2,13 @@ fun foo (xs: int): int = return xs + 1;
fun bar (xs: int) (x: int): int = return xs - x;
fun main: int = do
foo(69)
|> bar(1)
|> @write();
let res: int = foo(69)
|> bar(1);
@write(res);
@write("\n");
68
|> foo()
|> @write();
let y: int = 68
|> foo();
@write(y);
end;

View file

@ -1,22 +0,0 @@
#pragma once
#include <iostream>
template<typename T>
/**
* @brief Read the value from stdin and return it.
*/
T hazure_read() {
T x;
std::cin >> x;
return x;
}
template<typename T>
/**
* @brief Prints the value of the variable to the stdout.
*
* @param value The value to print.
*/
void hazure_write(T x) {
std::cout << x;
}