println -> print. update readme

This commit is contained in:
collin 2020-07-09 18:55:53 -07:00
parent b4e608e8c4
commit cd38e3a476
10 changed files with 42 additions and 42 deletions

View File

@ -545,17 +545,17 @@ test function expect_fail() {
}
```
## Macros
## Logging
Leo supports `println!`, `debug!`, and `error!` macros.
Leo supports `print!`, `debug!`, and `error!` logging macros.
Macros support string formatting arguments `[macro]!("{} {}", [argument_1], [argument_2])`
#### `println!`
#### `print!`
Directly calls the `println!` macro in rust.
```js
function main(a: u32) {
println!("a is {}", a);
print!("a is {}", a);
}
```

View File

@ -372,11 +372,11 @@ macro_symbol = {"!"}
macro_name = {
debug
| error
| println
| print
}
// Declared in macros/println.rs
println = {"println"}
// Declared in macros/print.rs
print = {"print"}
// Declared in macros/debug.rs
debug = {"debug"}

View File

@ -1,6 +1,6 @@
use crate::{
ast::Rule,
macros::{Debug, Error, PrintLine},
macros::{Debug, Error, Print},
};
use pest_ast::FromPest;
@ -11,7 +11,7 @@ use std::fmt;
pub enum MacroName<'ast> {
Debug(Debug<'ast>),
Error(Error<'ast>),
PrintLine(PrintLine<'ast>),
Print(Print<'ast>),
}
impl<'ast> fmt::Display for MacroName<'ast> {
@ -19,7 +19,7 @@ impl<'ast> fmt::Display for MacroName<'ast> {
match *self {
MacroName::Debug(ref debug) => write!(f, "{}", debug),
MacroName::Error(ref error) => write!(f, "{}", error),
MacroName::PrintLine(ref print_line) => write!(f, "{}", print_line),
MacroName::Print(ref print_line) => write!(f, "{}", print_line),
}
}
}

View File

@ -25,5 +25,5 @@ pub use macro_name::*;
pub mod macro_symbol;
pub use macro_symbol::*;
pub mod println;
pub use println::*;
pub mod print;
pub use print::*;

View File

@ -5,14 +5,14 @@ use pest_ast::FromPest;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::println))]
pub struct PrintLine<'ast> {
#[pest_ast(rule(Rule::print))]
pub struct Print<'ast> {
#[pest_ast(outer())]
pub span: Span<'ast>,
}
impl<'ast> fmt::Display for PrintLine<'ast> {
impl<'ast> fmt::Display for Print<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "println")
write!(f, "print")
}
}

View File

@ -24,7 +24,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
match macro_.name {
MacroName::Debug(_) => log::debug!("{}\n", string),
MacroName::Error(_) => log::error!("{}\n", string),
MacroName::PrintLine(_) => println!("{}\n", string),
MacroName::Print(_) => println!("{}", string),
}
Ok(())

View File

@ -1,4 +1,4 @@
use crate::{Debug, ErrorMacro, PrintLine};
use crate::{Debug, ErrorMacro, Print};
use leo_ast::macros::MacroName as AstMacroName;
use serde::{Deserialize, Serialize};
@ -8,7 +8,7 @@ use std::fmt;
pub enum MacroName {
Debug(Debug),
Error(ErrorMacro),
PrintLine(PrintLine),
Print(Print),
}
impl<'ast> From<AstMacroName<'ast>> for MacroName {
@ -16,7 +16,7 @@ impl<'ast> From<AstMacroName<'ast>> for MacroName {
match name {
AstMacroName::Debug(debug) => MacroName::Debug(Debug::from(debug)),
AstMacroName::Error(error) => MacroName::Error(ErrorMacro::from(error)),
AstMacroName::PrintLine(print_line) => MacroName::PrintLine(PrintLine::from(print_line)),
AstMacroName::Print(print_line) => MacroName::Print(Print::from(print_line)),
}
}
}
@ -26,7 +26,7 @@ impl fmt::Display for MacroName {
match *self {
MacroName::Debug(ref debug) => write!(f, "{}", debug),
MacroName::Error(ref error) => write!(f, "{}", error),
MacroName::PrintLine(ref print_line) => write!(f, "{}", print_line),
MacroName::Print(ref print_line) => write!(f, "{}", print_line),
}
}
}

View File

@ -19,5 +19,5 @@ pub use formatted_parameter::*;
pub mod macro_name;
pub use macro_name::*;
pub mod print_line;
pub use print_line::*;
pub mod print;
pub use print::*;

19
types/src/macros/print.rs Normal file
View File

@ -0,0 +1,19 @@
use leo_ast::macros::Print as AstPrint;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Print {}
impl<'ast> From<AstPrint<'ast>> for Print {
fn from(_print: AstPrint<'ast>) -> Self {
Self {}
}
}
impl fmt::Display for Print {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "print")
}
}

View File

@ -1,19 +0,0 @@
use leo_ast::macros::PrintLine as AstPrintLine;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PrintLine {}
impl<'ast> From<AstPrintLine<'ast>> for PrintLine {
fn from(_print_line: AstPrintLine<'ast>) -> Self {
Self {}
}
}
impl fmt::Display for PrintLine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "println")
}
}