1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00
This commit is contained in:
Natapat Samutpong 2022-03-13 07:01:39 +07:00
parent f67172b9a7
commit 5754ecf641
4 changed files with 22 additions and 6 deletions

View file

@ -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
}
},

View file

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

4
example/time.hz Normal file
View file

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

9
lib/time.hpp Normal file
View 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);
}