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.
9431270504
...
1f5eaab23a
4
Makefile
4
Makefile
|
@ -1,4 +0,0 @@
|
||||||
build-lib:
|
|
||||||
@echo "Building lib..."
|
|
||||||
cp ./lib/. /usr/include/hazure/ -r
|
|
||||||
@echo "Building lib... done"
|
|
|
@ -12,7 +12,6 @@ Note: Everything in this project can be changed at anytime! (I'm still finding o
|
||||||
|
|
||||||
# Prerequistie
|
# Prerequistie
|
||||||
- `clang++`(preferred, default) or any C++ compiler
|
- `clang++`(preferred, default) or any C++ compiler
|
||||||
- `make` for Makefile
|
|
||||||
- Rust (if you're going to build from source)
|
- Rust (if you're going to build from source)
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
@ -22,5 +21,13 @@ You can also configurate Hades compiler (currently you can only change the C++ c
|
||||||
compiler = "clang++"
|
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
|
# 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)
|
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
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt::Display;
|
||||||
use hir::{IR, IRKind, Value};
|
use hir::{IR, IRKind, Value};
|
||||||
|
|
||||||
const MODULE_INCLUDES: [&str; 3] = [
|
const MODULE_INCLUDES: [&str; 3] = [
|
||||||
"\"hazure/io.hpp\"", // `read()` and `write()`
|
"<iostream>", // stdin `@read()` and stdout `@write()`
|
||||||
"<stdbool.h>", // bool type
|
"<stdbool.h>", // bool type
|
||||||
"<string>", // string type
|
"<string>", // string type
|
||||||
];
|
];
|
||||||
|
@ -62,8 +62,8 @@ impl Codegen {
|
||||||
|
|
||||||
IRKind::Intrinsic { name, args } => {
|
IRKind::Intrinsic { name, args } => {
|
||||||
match name.as_str() {
|
match name.as_str() {
|
||||||
"write" => { format!("hazure_write({}){}\n", self.gen_ir(&args[0], false), semicolon!()) },
|
"write" => { format!("std::cout << {};\n", self.gen_ir(&args[0], false)) },
|
||||||
"read" => { format!("hazure_read({}){}\n", self.gen_ir(&args[0], false), semicolon!()) },
|
"read" => { format!("std::cin >> {};\n", self.gen_ir(&args[0], false)) },
|
||||||
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
|
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -105,8 +105,7 @@ pub fn expr_to_ir(expr: &Expr) -> (Option<IRKind>, Option<LoweringError>) {
|
||||||
if_err_return!(lhs_ir.1);
|
if_err_return!(lhs_ir.1);
|
||||||
|
|
||||||
match &rhs.0 {
|
match &rhs.0 {
|
||||||
call @ Expr::Call { name, args }
|
call @ Expr::Call { name, args } => {
|
||||||
| call @ Expr::Intrinsic { name, args } => {
|
|
||||||
let name = match &name.0 {
|
let name = match &name.0 {
|
||||||
Expr::Identifier(s) => s.clone(),
|
Expr::Identifier(s) => s.clone(),
|
||||||
// Should never happen because the parser should have caught this
|
// 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()];
|
let mut args = vec![lhs_ir.0.unwrap()];
|
||||||
args.append(&mut largs);
|
args.append(&mut largs);
|
||||||
|
|
||||||
let ir_kind = match call.0.unwrap() {
|
return (Some(IRKind::Call { name, args }), None);
|
||||||
IRKind::Call { .. } => IRKind::Call { name, args },
|
|
||||||
IRKind::Intrinsic { .. } => IRKind::Intrinsic { name, args },
|
|
||||||
_ => unreachable!()
|
|
||||||
};
|
|
||||||
|
|
||||||
return (Some(ir_kind), None);
|
|
||||||
},
|
},
|
||||||
_ => return (None, Some(LoweringError {
|
_ => return (None, Some(LoweringError {
|
||||||
span: rhs.1.clone(),
|
span: rhs.1.clone(),
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
fun main: int = do
|
|
||||||
"Hello, World!\n"
|
|
||||||
|> @write();
|
|
||||||
end;
|
|
|
@ -2,13 +2,13 @@ fun foo (xs: int): int = return xs + 1;
|
||||||
fun bar (xs: int) (x: int): int = return xs - x;
|
fun bar (xs: int) (x: int): int = return xs - x;
|
||||||
|
|
||||||
fun main: int = do
|
fun main: int = do
|
||||||
foo(69)
|
let res: int = foo(69)
|
||||||
|> bar(1)
|
|> bar(1);
|
||||||
|> @write();
|
@write(res);
|
||||||
|
|
||||||
@write("\n");
|
@write("\n");
|
||||||
|
|
||||||
68
|
let y: int = 68
|
||||||
|> foo()
|
|> foo();
|
||||||
|> @write();
|
@write(y);
|
||||||
end;
|
end;
|
22
lib/io.hpp
22
lib/io.hpp
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in a new issue