add sync logic keywords

This commit is contained in:
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> { proc counter() -> Logic<8> {
reg count = 8'0; reg count = 8'0;
count = count + 1; // TODO: no addition yet :(
next count = count ^ 1;
count count
} }

View File

@ -247,7 +247,7 @@ impl Context {
BlockExpr::Block(block) => { BlockExpr::Block(block) => {
// TODO: we need to find some way of resolving a name to an expression // TODO: we need to find some way of resolving a name to an expression
todo!("can not convert blocks to typed_ir yet"); 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 { let signal = typed_ir::Signal {
id: typed_ir::DefId(self.ids.next() as u32), id: typed_ir::DefId(self.ids.next() as u32),
typ: self.types.primitives.infer, typ: self.types.primitives.infer,
@ -330,7 +330,8 @@ impl Context {
let mut exprs = Default::default(); 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 { Ok(typed_ir::Body {
signature: callable_id, signature: callable_id,

View File

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

View File

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

View File

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