add sync logic keywords

main
NotAFile 2022-08-07 18:14:55 +02:00
parent f037357ded
commit aeaf487de7
5 changed files with 19 additions and 9 deletions

View File

@ -1,5 +1,6 @@
proc counter() -> Logic<8> {
reg count = 8'0;
count = count + 1;
// TODO: no addition yet :(
next count = count ^ 1;
count
}

View File

@ -247,7 +247,7 @@ impl Context {
BlockExpr::Block(block) => {
// TODO: we need to find some way of resolving a name to an expression
todo!("can not convert blocks to typed_ir yet");
for (name, expr) in &block.assignments {
for (kind, name, expr) in &block.assignments {
let signal = typed_ir::Signal {
id: typed_ir::DefId(self.ids.next() as u32),
typ: self.types.primitives.infer,
@ -330,7 +330,8 @@ impl Context {
let mut exprs = Default::default();
let root_expr = self.type_expression(&mut exprs, &comb.expr)?;
// TODO: fixme
let root_expr = self.type_expression(&mut exprs, &comb.expr.value)?;
Ok(typed_ir::Body {
signature: callable_id,

View File

@ -15,7 +15,7 @@ use crate::parser::{
/// a block that is a single expression
#[derive(Debug, Clone)]
pub struct ExpressionBlock<'a> {
pub assignments: Vec<(Token<'a>, Expression<'a>)>,
pub assignments: Vec<(Token<'a>, Token<'a>, Expression<'a>)>,
pub value: Expression<'a>,
}
@ -59,11 +59,12 @@ fn match_block(input: TokenSpan) -> IResult<TokenSpan, MatchBlock> {
)(input)
}
fn expression_block(input: TokenSpan) -> IResult<TokenSpan, ExpressionBlock> {
pub fn expression_block(input: TokenSpan) -> IResult<TokenSpan, ExpressionBlock> {
map(
tuple((
many0(tuple((
delimited(token(tk::Let), token(tk::Ident), token(tk::EqAssign)),
alt((token(tk::Let), token(tk::Reg), token(tk::Next))),
terminated(token(tk::Ident), token(tk::EqAssign)),
terminated(expression, token(tk::Semicolon)),
))),
expression,

View File

@ -1,4 +1,5 @@
use super::{
block_expression::{expression_block, ExpressionBlock},
declaration::TypeName,
expression::{expression, Expression},
module::inputs_list,
@ -10,6 +11,7 @@ use nom::sequence::delimited;
use nom::sequence::preceded;
use nom::sequence::tuple;
use nom::{
branch::alt,
combinator::{cut, map, opt},
multi::many1,
};
@ -20,13 +22,14 @@ pub struct CombBlock<'a> {
pub ports: Vec<PortDecl<'a>>,
pub genparams: Vec<TypeName<'a>>,
pub ret: TypeName<'a>,
pub expr: Expression<'a>,
pub expr: ExpressionBlock<'a>,
}
pub fn comb_block(input: TokenSpan) -> IResult<TokenSpan, CombBlock> {
map(
preceded(
token(tk::Comb),
// TODO: rename to not just be comb
alt((token(tk::Comb), token(tk::Proc))),
cut(tuple((
token(tk::Ident),
opt(delimited(
@ -36,7 +39,7 @@ pub fn comb_block(input: TokenSpan) -> IResult<TokenSpan, CombBlock> {
)),
delimited(token(tk::LParen), inputs_list, token(tk::RParen)),
preceded(token(tk::RArrow), typename),
delimited(token(tk::LBrace), expression, token(tk::RBrace)),
delimited(token(tk::LBrace), expression_block, token(tk::RBrace)),
))),
),
|(name, genparams, inputs, ret, expr)| CombBlock {

View File

@ -88,6 +88,8 @@ pub enum TokenKind {
Comb,
Let,
Struct,
Reg,
Next,
// whitespace
Comment,
// Error
@ -237,6 +239,8 @@ fn lex_keywords(input: Span) -> IResult<Span, Token> {
map(tag("state"), |_| TokenKind::State),
map(tag("let"), |_| TokenKind::Let),
map(tag("struct"), |_| TokenKind::Struct),
map(tag("reg"), |_| TokenKind::Reg),
map(tag("next"), |_| TokenKind::Next),
))),
peek(not(alt((alpha1, tag("_"))))),
),