Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from matter-labs/development
Browse files Browse the repository at this point in the history
Release v0.1.3
  • Loading branch information
hedgar2017 authored Feb 17, 2020
2 parents d206cff + 038876b commit 9cdedf9
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 65 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# The Zinc changelog

## Version 0.1.3 (2020-02-17)

### Compiler

- fix the compile error with a comment at the end of a file
- add an empty statement to allow optional semicolons

## Version 0.1.2 (2020-02-14)

### Language
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM rust:1.41 as builder-linux-musl
COPY . .
COPY . zinc-dev/

WORKDIR /zinc-dev/
RUN apt update -y && apt install -y musl musl-dev musl-tools
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo build --verbose --release --target x86_64-unknown-linux-musl
2 changes: 1 addition & 1 deletion zargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zargo"
version = "0.1.2"
version = "0.1.3"
authors = ["hedgar2017 <[email protected]>"]
edition = "2018"
description = "The Zinc's circuit manager"
Expand Down
4 changes: 2 additions & 2 deletions zinc-book/src/05-operators/01-arithmetic.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Both operands of a binary operator must always be of the same type, e.g.:
- `i64` and `i64`
- `field` and `field`

> The operators `/`, `%`, `>=`, `>`, `<=`, `<` are temporarily forbidden for the
> The operators `/` and `%` are temporarily forbidden for the
> type `field`, but will probably become available soon.
> When is comes to the division of negative numbers, Zinc follows the Euclidean
> division concept. It means that `-45 / 7 == 4`. To get the detailed explanation
> division concept. It means that `-45 % 7 == 4`. To get the detailed explanation
> and some examples, see the [article](https://en.wikipedia.org/wiki/Euclidean_division).
#### Addition
Expand Down
3 changes: 3 additions & 0 deletions zinc-book/src/05-operators/02-comparison.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Comparison operators

> The operators `>=`, `>`, `<=`, `<` are temporarily forbidden for the
> type `field`, but will probably become available soon.
#### Equality

`==` is a binary operator.
Expand Down
2 changes: 1 addition & 1 deletion zinc-book/src/appendix/A-grammar-lexical.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These are the Zinc lexical grammar rules in the EWBF notation.
lexeme = comment | identifier | keyword | literal | symbol | EOF ;
comment = single_line_comment | multi_line_comment ;
single_line_comment = '//', ( ? ANY ? - '\n' ), '\n' ;
single_line_comment = '//', ( ? ANY ? - '\n' | EOF ), '\n' | EOF ;
multi_line_comment = '/*', ( ? ANY ? - '*/' ), '*/' ;
identifier = (
Expand Down
8 changes: 7 additions & 1 deletion zinc-book/src/appendix/B-grammar-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ module_local_statement =
| mod_statement
| use_statement
| impl_statement
| empty_statement
;
function_local_statement =
let_statement
| const_statement
| loop_statement
| empty_statement
| expression
;
implementation_local_statement =
const_statement
| fn_statement
';' ;
| empty_statement
;
let_statement = 'let', [ 'mut' ], identifier, [ ':', type ], '=', expression ;
loop_statement = 'for', identifier, 'in', expression, [ 'while', expression ], block_expression ;
Expand All @@ -37,6 +42,7 @@ fn_statement = 'fn', identifier, '(', field_list, ')', [ '->', type ], block_exp
mod_statement = 'mod', identifier ;
use_statement = 'use', path_expression ;
impl_statement = 'impl', identifier, '{', { implementation_local_statement }, '}' ;
empty_statement = ';' ;
(* Expressions *)
expression = operand_assignment, [ '=', operand_assignment ] ;
Expand Down
2 changes: 1 addition & 1 deletion zinc-bytecode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zinc-bytecode"
version = "0.1.2"
version = "0.1.3"
authors = [
"Alexander Movchan <[email protected]>",
"hedgar2017 <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion zinc-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zinc-compiler"
version = "0.1.2"
version = "0.1.3"
authors = [
"hedgar2017 <[email protected]>",
"Alexander Movchan <[email protected]>",
Expand Down
54 changes: 32 additions & 22 deletions zinc-compiler/src/lexical/stream/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,72 @@ pub fn parse(input: &str) -> Result<(usize, usize, usize, Comment), Error> {
let mut lines = 0;
let mut column = 1;

while let Some(character) = input.chars().nth(size) {
loop {
let character = input.chars().nth(size);
match state {
State::Start => match character {
'/' => {
Some('/') => {
size += 1;
column += 1;
state = State::Slash;
}
_ => return Err(Error::NotAComment),
Some(_) => return Err(Error::NotAComment),
None => break,
},
State::Slash => match character {
'/' => {
Some('/') => {
size += 1;
column += 1;
state = State::SingleLine;
}
'*' => {
Some('*') => {
size += 1;
column += 1;
state = State::MultiLine;
}
_ => return Err(Error::NotAComment),
Some(_) => return Err(Error::NotAComment),
None => break,
},
State::SingleLine => match character {
'\n' => {
Some('\n') | None => {
let comment = Comment::new(input[2..size].to_owned());
return Ok((size, lines, column, comment));
}
_ => {
Some(_) => {
size += 1;
column += 1;
}
},
State::MultiLine => match character {
'*' => {
Some('*') => {
size += 1;
column += 1;
state = State::MultiLineStar;
}
'\n' => {
Some('\n') => {
size += 1;
column = 1;
lines += 1;
}
_ => {
Some(_) => {
size += 1;
column += 1;
}
None => break,
},
State::MultiLineStar => match character {
'/' => {
Some('/') => {
size += 1;
column += 1;
let comment = Comment::new(input[2..size - 2].to_owned());
return Ok((size, lines, column, comment));
}
_ => {
Some(_) => {
size += 1;
column += 1;
state = State::MultiLine;
}
None => break,
},
}
}
Expand All @@ -103,7 +108,7 @@ mod tests {
use crate::lexical::token::lexeme::comment::Comment;

#[test]
fn ok_single_line() {
fn ok_single_line_with_break() {
let input = "//mega ultra comment text\n";
let expected = Ok((
25,
Expand All @@ -115,6 +120,19 @@ mod tests {
assert_eq!(result, expected);
}

#[test]
fn ok_single_line_with_eof() {
let input = "//mega ultra comment text";
let expected = Ok((
25,
0,
26,
Comment::new("mega ultra comment text".to_owned()),
));
let result = parse(input);
assert_eq!(result, expected);
}

#[test]
fn ok_multi_line() {
let input = r#"/*
Expand All @@ -130,14 +148,6 @@ mod tests {
assert_eq!(result, expected);
}

#[test]
fn err_single_line_unexpected_end() {
let input = "//mega ultra comment text";
let expected = Err(Error::UnexpectedEnd);
let result = parse(input);
assert_eq!(result, expected);
}

#[test]
fn err_multi_line_unexpected_end() {
let input = r#"/* This is the mega ultra test application!"#;
Expand Down
1 change: 1 addition & 0 deletions zinc-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//!
#![allow(clippy::implicit_hasher)]
#![allow(clippy::large_enum_variant)]

mod error;
mod lexical;
Expand Down
2 changes: 1 addition & 1 deletion zinc-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Arguments {
enum Error {
#[fail(display = "source file: {}", _0)]
SourceFile(FileError),
#[fail(display = "compiler: {}:{}", _0, _1)]
#[fail(display = "{}:{}", _0, _1)]
Compiler(String, zinc_compiler::Error),
#[fail(display = "witness template output: {}", _0)]
WitnessTemplateOutput(OutputError),
Expand Down
38 changes: 18 additions & 20 deletions zinc-compiler/src/semantic/analyzer/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,47 +73,45 @@ impl Analyzer {

pub fn module_local_statement(&mut self, statement: ModuleLocalStatement) -> Result<(), Error> {
match statement {
ModuleLocalStatement::Const(statement) => self.const_statement(statement)?,
ModuleLocalStatement::Static(statement) => self.static_statement(statement)?,
ModuleLocalStatement::Type(statement) => self.type_statement(statement)?,
ModuleLocalStatement::Struct(statement) => self.struct_statement(statement)?,
ModuleLocalStatement::Enum(statement) => self.enum_statement(statement)?,
ModuleLocalStatement::Fn(statement) => self.fn_statement(statement)?,
ModuleLocalStatement::Mod(statement) => self.mod_statement(statement)?,
ModuleLocalStatement::Use(statement) => self.use_statement(statement)?,
ModuleLocalStatement::Impl(statement) => self.impl_statement(statement)?,
ModuleLocalStatement::Const(statement) => self.const_statement(statement),
ModuleLocalStatement::Static(statement) => self.static_statement(statement),
ModuleLocalStatement::Type(statement) => self.type_statement(statement),
ModuleLocalStatement::Struct(statement) => self.struct_statement(statement),
ModuleLocalStatement::Enum(statement) => self.enum_statement(statement),
ModuleLocalStatement::Fn(statement) => self.fn_statement(statement),
ModuleLocalStatement::Mod(statement) => self.mod_statement(statement),
ModuleLocalStatement::Use(statement) => self.use_statement(statement),
ModuleLocalStatement::Impl(statement) => self.impl_statement(statement),
ModuleLocalStatement::Empty => Ok(()),
}

Ok(())
}

pub fn function_local_statement(
&mut self,
statement: FunctionLocalStatement,
) -> Result<(), Error> {
match statement {
FunctionLocalStatement::Let(statement) => self.let_statement(statement)?,
FunctionLocalStatement::Const(statement) => self.const_statement(statement)?,
FunctionLocalStatement::Loop(statement) => self.loop_statement(statement)?,
FunctionLocalStatement::Let(statement) => self.let_statement(statement),
FunctionLocalStatement::Const(statement) => self.const_statement(statement),
FunctionLocalStatement::Loop(statement) => self.loop_statement(statement),
FunctionLocalStatement::Expression(expression) => {
ExpressionAnalyzer::new(self.scope(), self.bytecode.clone())
.expression(expression, TranslationHint::ValueExpression)?;
Ok(())
}
FunctionLocalStatement::Empty => Ok(()),
}

Ok(())
}

pub fn implementation_local_statement(
&mut self,
statement: ImplementationLocalStatement,
) -> Result<(), Error> {
match statement {
ImplementationLocalStatement::Const(statement) => self.const_statement(statement)?,
ImplementationLocalStatement::Fn(statement) => self.fn_statement(statement)?,
ImplementationLocalStatement::Const(statement) => self.const_statement(statement),
ImplementationLocalStatement::Fn(statement) => self.fn_statement(statement),
ImplementationLocalStatement::Empty => Ok(()),
}

Ok(())
}

fn const_statement(&mut self, statement: ConstStatement) -> Result<(), Error> {
Expand Down
4 changes: 4 additions & 0 deletions zinc-compiler/src/syntax/parser/statement/local_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl Parser {
LoopStatementParser::default().parse(stream.clone(), Some(token))?;
FunctionLocalStatement::Loop(statement)
}
Token {
lexeme: Lexeme::Symbol(Symbol::Semicolon),
..
} => return Ok((FunctionLocalStatement::Empty, None, false)),
token => {
let (expression, next) =
ExpressionParser::default().parse(stream.clone(), Some(token))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::rc::Rc;
use crate::error::Error;
use crate::lexical::Keyword;
use crate::lexical::Lexeme;
use crate::lexical::Symbol;
use crate::lexical::Token;
use crate::lexical::TokenStream;
use crate::syntax::ConstStatementParser;
Expand Down Expand Up @@ -41,6 +42,10 @@ impl Parser {
} => FnStatementParser::default()
.parse(stream, Some(token))
.map(|(statement, next)| (ImplementationLocalStatement::Fn(statement), next)),
Token {
lexeme: Lexeme::Symbol(Symbol::Semicolon),
..
} => Ok((ImplementationLocalStatement::Empty, None)),
Token { lexeme, location } => Err(Error::Syntax(SyntaxError::Expected(
location,
vec!["const", "fn"],
Expand Down
Loading

0 comments on commit 9cdedf9

Please sign in to comment.