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. "5754ecf6419457d349611293b56dd448579377fa" and "9431270504cbfdd1fbfe59ed02fb7a37f9350cce" have entirely different histories.

6 changed files with 9 additions and 41 deletions

View file

@ -7,14 +7,7 @@ fun main: int = do
return 69; return 69;
end; end;
``` ```
or with the pipe operator:
```sml
fun main: int = do
"Hello, World!\n"
|> @write();
return 69;
end;
```
Note: Everything in this project can be changed at anytime! (I'm still finding out what work best for lots of thing) if you have an idea, feel free to create an issues about it, or even create a PR! (I'd be very happy) Note: Everything in this project can be changed at anytime! (I'm still finding out what work best for lots of thing) if you have an idea, feel free to create an issues about it, or even create a PR! (I'd be very happy)
# Prerequistie # Prerequistie

View file

@ -2,11 +2,10 @@ use std::fmt::Display;
use hir::{IR, IRKind, Value}; use hir::{IR, IRKind, Value};
const MODULE_INCLUDES: [&str; 4] = [ const MODULE_INCLUDES: [&str; 3] = [
"\"hazure/io.hpp\"", "\"hazure/io.hpp\"", // `read()` and `write()`
"\"hazure/time.hpp\"", "<stdbool.h>", // bool type
"<stdbool.h>", "<string>", // string type
"<string>",
]; ];
pub struct Codegen { pub struct Codegen {
@ -64,8 +63,7 @@ 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!("hazure_write({}){}\n", self.gen_ir(&args[0], false), semicolon!()) },
"read" => { format!("hazure_read(){}\n", semicolon!()) }, "read" => { format!("hazure_read({}){}\n", self.gen_ir(&args[0], false), semicolon!()) },
"time" => { format!("hazure_get_time(){}\n", semicolon!()) },
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering _ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
} }
}, },

View file

@ -1,10 +1,9 @@
use std::ops::Range; use std::ops::Range;
use parser::Expr; use parser::Expr;
const INTRINSICS: [&str; 3] = [ const INTRINSICS: [&str; 2] = [
"write", "write",
"read", "read",
"time",
]; ];
#[derive(Debug)] #[derive(Debug)]

View file

@ -121,19 +121,10 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
.or(keyword) .or(keyword)
.recover_with(skip_then_retry_until([])); .recover_with(skip_then_retry_until([]));
// let comment = just("--").then(take_until(just('\n'))).padded(); let comment = just("--").then(take_until(just('\n'))).padded();
let comment = just('-')
.then_ignore(just('{')
.ignore_then(none_of('}').ignored().repeated())
.then_ignore(just("}-"))
.or(none_of('\n').ignored().repeated())
)
.padded()
.ignored()
.repeated();
token token
.padded_by(comment) .padded_by(comment.repeated())
.map_with_span(|token, span| (token, span)) .map_with_span(|token, span| (token, span))
.padded() .padded()
.repeated() .repeated()

View file

@ -1,4 +0,0 @@
fun main: int = do
@time()
|> @write();
end;

View file

@ -1,9 +0,0 @@
#pragma once
#include <ctime>
/*
* @brief Get time in seconds since the Epoch.
*/
int hazure_get_time() {
return std::time(0);
}