mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
3 commits
9431270504
...
5754ecf641
Author | SHA1 | Date | |
---|---|---|---|
Natapat Samutpong | 5754ecf641 | ||
Natapat Samutpong | f67172b9a7 | ||
Natapat Samutpong | 7be91158dc |
|
@ -7,7 +7,14 @@ fun main: int = do
|
|||
return 69;
|
||||
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)
|
||||
|
||||
# Prerequistie
|
||||
|
|
|
@ -2,10 +2,11 @@ use std::fmt::Display;
|
|||
|
||||
use hir::{IR, IRKind, Value};
|
||||
|
||||
const MODULE_INCLUDES: [&str; 3] = [
|
||||
"\"hazure/io.hpp\"", // `read()` and `write()`
|
||||
"<stdbool.h>", // bool type
|
||||
"<string>", // string type
|
||||
const MODULE_INCLUDES: [&str; 4] = [
|
||||
"\"hazure/io.hpp\"",
|
||||
"\"hazure/time.hpp\"",
|
||||
"<stdbool.h>",
|
||||
"<string>",
|
||||
];
|
||||
|
||||
pub struct Codegen {
|
||||
|
@ -63,7 +64,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!()) },
|
||||
"read" => { format!("hazure_read(){}\n", semicolon!()) },
|
||||
"time" => { format!("hazure_get_time(){}\n", semicolon!()) },
|
||||
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::ops::Range;
|
||||
use parser::Expr;
|
||||
|
||||
const INTRINSICS: [&str; 2] = [
|
||||
const INTRINSICS: [&str; 3] = [
|
||||
"write",
|
||||
"read",
|
||||
"time",
|
||||
];
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -121,10 +121,19 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
|||
.or(keyword)
|
||||
.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
|
||||
.padded_by(comment.repeated())
|
||||
.padded_by(comment)
|
||||
.map_with_span(|token, span| (token, span))
|
||||
.padded()
|
||||
.repeated()
|
||||
|
|
4
example/time.hz
Normal file
4
example/time.hz
Normal file
|
@ -0,0 +1,4 @@
|
|||
fun main: int = do
|
||||
@time()
|
||||
|> @write();
|
||||
end;
|
9
lib/time.hpp
Normal file
9
lib/time.hpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
#include <ctime>
|
||||
|
||||
/*
|
||||
* @brief Get time in seconds since the Epoch.
|
||||
*/
|
||||
int hazure_get_time() {
|
||||
return std::time(0);
|
||||
}
|
Loading…
Reference in a new issue