mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
use const for function declaration, comma separated args
This commit is contained in:
parent
1968e7ff14
commit
40f48cbbf1
|
@ -1,4 +1,4 @@
|
|||
let foo: int = 1;
|
||||
let foo: string = 1;
|
||||
|
||||
fun bar (baz: int) -> int = baz + 1;
|
||||
fun qux (quux: int) -> int = do
|
||||
|
@ -6,4 +6,7 @@ fun qux (quux: int) -> int = do
|
|||
bar(corge);
|
||||
end;
|
||||
|
||||
fun add (lhs: int, rhs: int) -> int = lhs + rhs;
|
||||
print(add(34, 35));
|
||||
|
||||
print(qux(5));
|
|
@ -46,7 +46,7 @@ fn gen_ir(ir: &IR) -> String {
|
|||
};
|
||||
|
||||
format!(
|
||||
"function {}({}) {{ {} }}",
|
||||
"const {} = ({}) => {{ {} }};",
|
||||
name,
|
||||
args,
|
||||
body
|
||||
|
|
|
@ -12,7 +12,7 @@ pub enum Token {
|
|||
Delimiter(char),
|
||||
Semicolon,
|
||||
Assign, Colon,
|
||||
Comma,
|
||||
Comma, Dot,
|
||||
ReturnHint,
|
||||
|
||||
// Keywords
|
||||
|
@ -46,6 +46,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
|||
just(':').to(Token::Colon),
|
||||
just(',').to(Token::Comma),
|
||||
just("->").to(Token::ReturnHint),
|
||||
just(".").to(Token::Dot),
|
||||
));
|
||||
|
||||
let operator = choice((
|
||||
|
@ -152,9 +153,8 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
|
|||
|
||||
let expr = recursive(|expr| {
|
||||
let args = expr.clone()
|
||||
.repeated()
|
||||
.or_not()
|
||||
.map(|item| item.unwrap_or_else(Vec::new));
|
||||
.separated_by(just(Token::Comma))
|
||||
.allow_trailing();
|
||||
|
||||
let atom = literal
|
||||
.or(ident.map(Expr::Ident))
|
||||
|
@ -177,7 +177,7 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
|
|||
args,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let unary = choice((
|
||||
just(Token::Operator("-".to_string())).to("-"),
|
||||
just(Token::Operator("!".to_string())).to("!")))
|
||||
|
@ -263,7 +263,8 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
|
|||
(ident
|
||||
.then_ignore(just(Token::Colon))
|
||||
.then(ident))
|
||||
.repeated()
|
||||
.separated_by(just(Token::Comma))
|
||||
.allow_trailing()
|
||||
)
|
||||
.then_ignore(just(Token::Delimiter(')')))
|
||||
.then_ignore(just(Token::ReturnHint))
|
||||
|
|
|
@ -25,6 +25,7 @@ use middle::ir;
|
|||
/// Contains code generator.
|
||||
pub mod back;
|
||||
|
||||
/// Utility functions.
|
||||
pub mod util;
|
||||
use crate::util::log;
|
||||
|
||||
|
|
|
@ -1,27 +1,13 @@
|
|||
use core::fmt;
|
||||
|
||||
use crate::front::parse::Expr;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TypeHint {
|
||||
Int,
|
||||
Float, Double,
|
||||
Float,
|
||||
Bool,
|
||||
String,
|
||||
}
|
||||
|
||||
impl fmt::Display for TypeHint {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
TypeHint::Int => write!(f, "int"),
|
||||
TypeHint::Float => write!(f, "float"),
|
||||
TypeHint::Double => write!(f, "double"),
|
||||
TypeHint::Bool => write!(f, "bool"),
|
||||
TypeHint::String => write!(f, "char*"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Value {
|
||||
Int(i64),
|
||||
|
|
Loading…
Reference in a new issue