mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-23 18:21:38 +03:00
Merge pull request #1201 from AleoHQ/feature/console-refactor-and-outs
[Feature Implmentation] Stderr and debug remove
This commit is contained in:
commit
806e16f5bb
@ -238,9 +238,7 @@ impl<'a, T: Monoid, R: MonoidalReducerStatement<'a, T>> MonoidalDirector<'a, T,
|
|||||||
pub fn reduce_console(&mut self, input: &ConsoleStatement<'a>) -> T {
|
pub fn reduce_console(&mut self, input: &ConsoleStatement<'a>) -> T {
|
||||||
let argument = match &input.function {
|
let argument = match &input.function {
|
||||||
ConsoleFunction::Assert(e) => self.reduce_expression(e.get()),
|
ConsoleFunction::Assert(e) => self.reduce_expression(e.get()),
|
||||||
ConsoleFunction::Debug(f) | ConsoleFunction::Error(f) | ConsoleFunction::Log(f) => {
|
ConsoleFunction::Error(f) | ConsoleFunction::Log(f) => self.reduce_formatted_string(f),
|
||||||
self.reduce_formatted_string(f)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.reducer.reduce_console(input, argument)
|
self.reducer.reduce_console(input, argument)
|
||||||
|
@ -259,7 +259,7 @@ impl<'a, R: ReconstructingReducerStatement<'a>> ReconstructingDirector<'a, R> {
|
|||||||
let argument = self.reduce_expression(argument.get());
|
let argument = self.reduce_expression(argument.get());
|
||||||
self.reducer.reduce_console_assert(input, argument)
|
self.reducer.reduce_console_assert(input, argument)
|
||||||
}
|
}
|
||||||
ConsoleFunction::Debug(f) | ConsoleFunction::Error(f) | ConsoleFunction::Log(f) => {
|
ConsoleFunction::Error(f) | ConsoleFunction::Log(f) => {
|
||||||
let formatted = self.reduce_formatted_string(f.clone());
|
let formatted = self.reduce_formatted_string(f.clone());
|
||||||
self.reducer.reduce_console_log(input, formatted)
|
self.reducer.reduce_console_log(input, formatted)
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,6 @@ pub trait ReconstructingReducerStatement<'a>: ReconstructingReducerExpression<'a
|
|||||||
span: input.span,
|
span: input.span,
|
||||||
function: match input.function {
|
function: match input.function {
|
||||||
ConsoleFunction::Assert(_) => unimplemented!(),
|
ConsoleFunction::Assert(_) => unimplemented!(),
|
||||||
ConsoleFunction::Debug(_) => ConsoleFunction::Debug(argument),
|
|
||||||
ConsoleFunction::Error(_) => ConsoleFunction::Error(argument),
|
ConsoleFunction::Error(_) => ConsoleFunction::Error(argument),
|
||||||
ConsoleFunction::Log(_) => ConsoleFunction::Log(argument),
|
ConsoleFunction::Log(_) => ConsoleFunction::Log(argument),
|
||||||
},
|
},
|
||||||
|
@ -336,9 +336,7 @@ impl<'a, R: StatementVisitor<'a>> VisitorDirector<'a, R> {
|
|||||||
VisitResult::VisitChildren => {
|
VisitResult::VisitChildren => {
|
||||||
match &input.function {
|
match &input.function {
|
||||||
ConsoleFunction::Assert(e) => self.visit_expression(e)?,
|
ConsoleFunction::Assert(e) => self.visit_expression(e)?,
|
||||||
ConsoleFunction::Debug(f) | ConsoleFunction::Error(f) | ConsoleFunction::Log(f) => {
|
ConsoleFunction::Error(f) | ConsoleFunction::Log(f) => self.visit_formatted_string(f)?,
|
||||||
self.visit_formatted_string(f)?
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ pub struct ConsoleArgs<'a> {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum ConsoleFunction<'a> {
|
pub enum ConsoleFunction<'a> {
|
||||||
Assert(Cell<&'a Expression<'a>>),
|
Assert(Cell<&'a Expression<'a>>),
|
||||||
Debug(ConsoleArgs<'a>),
|
|
||||||
Error(ConsoleArgs<'a>),
|
Error(ConsoleArgs<'a>),
|
||||||
Log(ConsoleArgs<'a>),
|
Log(ConsoleArgs<'a>),
|
||||||
}
|
}
|
||||||
@ -89,7 +88,6 @@ impl<'a> FromAst<'a, leo_ast::ConsoleStatement> for ConsoleStatement<'a> {
|
|||||||
AstConsoleFunction::Assert(expression) => ConsoleFunction::Assert(Cell::new(
|
AstConsoleFunction::Assert(expression) => ConsoleFunction::Assert(Cell::new(
|
||||||
<&Expression<'a>>::from_ast(scope, expression, Some(Type::Boolean.into()))?,
|
<&Expression<'a>>::from_ast(scope, expression, Some(Type::Boolean.into()))?,
|
||||||
)),
|
)),
|
||||||
AstConsoleFunction::Debug(args) => ConsoleFunction::Debug(ConsoleArgs::from_ast(scope, args, None)?),
|
|
||||||
AstConsoleFunction::Error(args) => ConsoleFunction::Error(ConsoleArgs::from_ast(scope, args, None)?),
|
AstConsoleFunction::Error(args) => ConsoleFunction::Error(ConsoleArgs::from_ast(scope, args, None)?),
|
||||||
AstConsoleFunction::Log(args) => ConsoleFunction::Log(ConsoleArgs::from_ast(scope, args, None)?),
|
AstConsoleFunction::Log(args) => ConsoleFunction::Log(ConsoleArgs::from_ast(scope, args, None)?),
|
||||||
},
|
},
|
||||||
@ -103,7 +101,6 @@ impl<'a> Into<leo_ast::ConsoleStatement> for &ConsoleStatement<'a> {
|
|||||||
leo_ast::ConsoleStatement {
|
leo_ast::ConsoleStatement {
|
||||||
function: match &self.function {
|
function: match &self.function {
|
||||||
Assert(e) => AstConsoleFunction::Assert(e.get().into()),
|
Assert(e) => AstConsoleFunction::Assert(e.get().into()),
|
||||||
Debug(args) => AstConsoleFunction::Debug(args.into()),
|
|
||||||
Error(args) => AstConsoleFunction::Error(args.into()),
|
Error(args) => AstConsoleFunction::Error(args.into()),
|
||||||
Log(args) => AstConsoleFunction::Log(args.into()),
|
Log(args) => AstConsoleFunction::Log(args.into()),
|
||||||
},
|
},
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
function main() {
|
|
||||||
console.debug("hello debug");
|
|
||||||
}
|
|
@ -40,14 +40,6 @@ fn test_log_input() {
|
|||||||
load_asg(program_string).unwrap();
|
load_asg(program_string).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug() {
|
|
||||||
let program_string = include_str!("debug.leo");
|
|
||||||
load_asg(program_string).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error
|
// Error
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{LeoError, Span};
|
use crate::{LeoError, Span};
|
||||||
|
|
||||||
use std::{fmt, sync::Arc};
|
use std::{fmt, sync::Arc};
|
||||||
|
|
||||||
pub const INDENT: &str = " ";
|
pub const INDENT: &str = " ";
|
||||||
@ -77,20 +76,21 @@ impl fmt::Display for FormattedError {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let underline = underline(self.col_start, self.col_stop);
|
let underline = underline(self.col_start, self.col_stop);
|
||||||
|
|
||||||
write!(
|
let error_message = format!(
|
||||||
f,
|
|
||||||
"{indent }--> {path}:{line_start}:{start}\n\
|
"{indent }--> {path}:{line_start}:{start}\n\
|
||||||
{indent } |\n",
|
{indent } ",
|
||||||
indent = INDENT,
|
indent = INDENT,
|
||||||
path = &*self.path,
|
path = &*self.path,
|
||||||
line_start = self.line_start,
|
line_start = self.line_start,
|
||||||
start = self.col_start,
|
start = self.col_start,
|
||||||
)?;
|
);
|
||||||
|
|
||||||
|
write!(f, "{}", error_message)?;
|
||||||
|
|
||||||
for (line_no, line) in self.content.lines().enumerate() {
|
for (line_no, line) in self.content.lines().enumerate() {
|
||||||
writeln!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
"{line_no:width$} | {text}",
|
"|\n{line_no:width$} | {text}",
|
||||||
width = INDENT.len(),
|
width = INDENT.len(),
|
||||||
line_no = self.line_start + line_no,
|
line_no = self.line_start + line_no,
|
||||||
text = line,
|
text = line,
|
||||||
|
@ -392,7 +392,7 @@ impl Canonicalizer {
|
|||||||
ConsoleFunction::Assert(expression) => {
|
ConsoleFunction::Assert(expression) => {
|
||||||
ConsoleFunction::Assert(self.canonicalize_expression(expression))
|
ConsoleFunction::Assert(self.canonicalize_expression(expression))
|
||||||
}
|
}
|
||||||
ConsoleFunction::Debug(args) | ConsoleFunction::Error(args) | ConsoleFunction::Log(args) => {
|
ConsoleFunction::Error(args) | ConsoleFunction::Log(args) => {
|
||||||
let parameters = args
|
let parameters = args
|
||||||
.parameters
|
.parameters
|
||||||
.iter()
|
.iter()
|
||||||
@ -406,7 +406,6 @@ impl Canonicalizer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match &console_function_call.function {
|
match &console_function_call.function {
|
||||||
ConsoleFunction::Debug(_) => ConsoleFunction::Debug(console_args),
|
|
||||||
ConsoleFunction::Error(_) => ConsoleFunction::Error(console_args),
|
ConsoleFunction::Error(_) => ConsoleFunction::Error(console_args),
|
||||||
ConsoleFunction::Log(_) => ConsoleFunction::Log(console_args),
|
ConsoleFunction::Log(_) => ConsoleFunction::Log(console_args),
|
||||||
_ => unimplemented!(), // impossible
|
_ => unimplemented!(), // impossible
|
||||||
|
@ -390,7 +390,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
) -> Result<ConsoleStatement, ReducerError> {
|
) -> Result<ConsoleStatement, ReducerError> {
|
||||||
let function = match &console_function_call.function {
|
let function = match &console_function_call.function {
|
||||||
ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)?),
|
ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)?),
|
||||||
ConsoleFunction::Debug(args) | ConsoleFunction::Error(args) | ConsoleFunction::Log(args) => {
|
ConsoleFunction::Error(args) | ConsoleFunction::Log(args) => {
|
||||||
let mut parameters = vec![];
|
let mut parameters = vec![];
|
||||||
for parameter in args.parameters.iter() {
|
for parameter in args.parameters.iter() {
|
||||||
parameters.push(self.reduce_expression(parameter)?);
|
parameters.push(self.reduce_expression(parameter)?);
|
||||||
@ -403,7 +403,6 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match &console_function_call.function {
|
match &console_function_call.function {
|
||||||
ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted),
|
|
||||||
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
|
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
|
||||||
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
|
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
|
||||||
_ => return Err(ReducerError::impossible_console_assert_call(&args.span)),
|
_ => return Err(ReducerError::impossible_console_assert_call(&args.span)),
|
||||||
|
@ -22,7 +22,6 @@ use std::fmt;
|
|||||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
||||||
pub enum ConsoleFunction {
|
pub enum ConsoleFunction {
|
||||||
Assert(Expression),
|
Assert(Expression),
|
||||||
Debug(ConsoleArgs),
|
|
||||||
Error(ConsoleArgs),
|
Error(ConsoleArgs),
|
||||||
Log(ConsoleArgs),
|
Log(ConsoleArgs),
|
||||||
}
|
}
|
||||||
@ -31,7 +30,6 @@ impl fmt::Display for ConsoleFunction {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ConsoleFunction::Assert(assert) => write!(f, "assert({})", assert),
|
ConsoleFunction::Assert(assert) => write!(f, "assert({})", assert),
|
||||||
ConsoleFunction::Debug(debug) => write!(f, "debug({})", debug),
|
|
||||||
ConsoleFunction::Error(error) => write!(f, "error{})", error),
|
ConsoleFunction::Error(error) => write!(f, "error{})", error),
|
||||||
ConsoleFunction::Log(log) => write!(f, "log({})", log),
|
ConsoleFunction::Log(log) => write!(f, "log({})", log),
|
||||||
}
|
}
|
||||||
@ -42,18 +40,14 @@ impl Node for ConsoleFunction {
|
|||||||
fn span(&self) -> &Span {
|
fn span(&self) -> &Span {
|
||||||
match self {
|
match self {
|
||||||
ConsoleFunction::Assert(assert) => assert.span(),
|
ConsoleFunction::Assert(assert) => assert.span(),
|
||||||
ConsoleFunction::Debug(formatted) | ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => {
|
ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => &formatted.span,
|
||||||
&formatted.span
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_span(&mut self, span: Span) {
|
fn set_span(&mut self, span: Span) {
|
||||||
match self {
|
match self {
|
||||||
ConsoleFunction::Assert(assert) => assert.set_span(span),
|
ConsoleFunction::Assert(assert) => assert.set_span(span),
|
||||||
ConsoleFunction::Debug(formatted) | ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => {
|
ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => formatted.set_span(span),
|
||||||
formatted.set_span(span)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,13 +39,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
&console.span.clone().unwrap_or_default(),
|
&console.span.clone().unwrap_or_default(),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
ConsoleFunction::Debug(string) => {
|
|
||||||
let string = self.format(cs, string)?;
|
|
||||||
|
|
||||||
if get_indicator_value(indicator) {
|
|
||||||
tracing::debug!("{}", string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ConsoleFunction::Error(string) => {
|
ConsoleFunction::Error(string) => {
|
||||||
let string = self.format(cs, string)?;
|
let string = self.format(cs, string)?;
|
||||||
|
|
||||||
|
@ -597,8 +597,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
(AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => {
|
(AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => {
|
||||||
AstConsoleFunction::Assert(self.reduce_expression(&ast_expression, asg_expression.get())?)
|
AstConsoleFunction::Assert(self.reduce_expression(&ast_expression, asg_expression.get())?)
|
||||||
}
|
}
|
||||||
(AstConsoleFunction::Debug(ast_console_args), AsgConsoleFunction::Debug(asg_format))
|
(AstConsoleFunction::Error(ast_console_args), AsgConsoleFunction::Error(asg_format))
|
||||||
| (AstConsoleFunction::Error(ast_console_args), AsgConsoleFunction::Error(asg_format))
|
|
||||||
| (AstConsoleFunction::Log(ast_console_args), AsgConsoleFunction::Log(asg_format)) => {
|
| (AstConsoleFunction::Log(ast_console_args), AsgConsoleFunction::Log(asg_format)) => {
|
||||||
let mut parameters = vec![];
|
let mut parameters = vec![];
|
||||||
for (ast_parameter, asg_parameter) in
|
for (ast_parameter, asg_parameter) in
|
||||||
@ -614,7 +613,6 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match &ast.function {
|
match &ast.function {
|
||||||
AstConsoleFunction::Debug(_) => AstConsoleFunction::Debug(args),
|
|
||||||
AstConsoleFunction::Error(_) => AstConsoleFunction::Error(args),
|
AstConsoleFunction::Error(_) => AstConsoleFunction::Error(args),
|
||||||
AstConsoleFunction::Log(_) => AstConsoleFunction::Log(args),
|
AstConsoleFunction::Log(_) => AstConsoleFunction::Log(args),
|
||||||
_ => return Err(ReducerError::impossible_console_assert_call(&ast_console_args.span)),
|
_ => return Err(ReducerError::impossible_console_assert_call(&ast_console_args.span)),
|
||||||
|
@ -218,6 +218,11 @@ pub fn init_logger(_app_name: &'static str, verbosity: usize) -> Result<()> {
|
|||||||
Err(_) => return Err(anyhow::anyhow!("Error: Failed to enable ansi_support")),
|
Err(_) => return Err(anyhow::anyhow!("Error: Failed to enable ansi_support")),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||||
|
|
||||||
|
let stderr = std::io::stderr.with_max_level(tracing::Level::WARN);
|
||||||
|
let mk_writer = stderr.or_else(std::io::stdout);
|
||||||
|
|
||||||
let subscriber = FmtSubscriber::builder()
|
let subscriber = FmtSubscriber::builder()
|
||||||
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
|
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
|
||||||
// will be written to stdout.
|
// will be written to stdout.
|
||||||
@ -227,6 +232,7 @@ pub fn init_logger(_app_name: &'static str, verbosity: usize) -> Result<()> {
|
|||||||
2 => tracing::Level::DEBUG,
|
2 => tracing::Level::DEBUG,
|
||||||
_ => tracing::Level::TRACE
|
_ => tracing::Level::TRACE
|
||||||
})
|
})
|
||||||
|
.with_writer(mk_writer)
|
||||||
.without_time()
|
.without_time()
|
||||||
.with_target(false)
|
.with_target(false)
|
||||||
.event_format(Format::default())
|
.event_format(Format::default())
|
||||||
|
16
leo/main.rs
16
leo/main.rs
@ -39,6 +39,7 @@ use commands::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use colored::Colorize;
|
||||||
use std::{path::PathBuf, process::exit};
|
use std::{path::PathBuf, process::exit};
|
||||||
use structopt::{clap::AppSettings, StructOpt};
|
use structopt::{clap::AppSettings, StructOpt};
|
||||||
|
|
||||||
@ -229,7 +230,20 @@ fn handle_error<T>(res: Result<T>) -> T {
|
|||||||
match res {
|
match res {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {}", err);
|
eprintln!(
|
||||||
|
"{} {}",
|
||||||
|
"Error:".bold().red(),
|
||||||
|
err.to_string()
|
||||||
|
.lines()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, l)| if i == 0 {
|
||||||
|
l.bold().red().to_string()
|
||||||
|
} else {
|
||||||
|
l.to_string()
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n")
|
||||||
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,13 +277,12 @@ impl ParserContext {
|
|||||||
let expr = self.parse_expression()?;
|
let expr = self.parse_expression()?;
|
||||||
ConsoleFunction::Assert(expr)
|
ConsoleFunction::Assert(expr)
|
||||||
}
|
}
|
||||||
"debug" => ConsoleFunction::Debug(self.parse_console_args()?),
|
|
||||||
"error" => ConsoleFunction::Error(self.parse_console_args()?),
|
"error" => ConsoleFunction::Error(self.parse_console_args()?),
|
||||||
"log" => ConsoleFunction::Log(self.parse_console_args()?),
|
"log" => ConsoleFunction::Log(self.parse_console_args()?),
|
||||||
x => {
|
x => {
|
||||||
return Err(SyntaxError::unexpected_ident(
|
return Err(SyntaxError::unexpected_ident(
|
||||||
&x,
|
&x,
|
||||||
&["assert", "debug", "error", "log"],
|
&["assert", "error", "log"],
|
||||||
&function.span,
|
&function.span,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,11 @@ impl Namespace for ParseStatementNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_test(&self, test: Test) -> Result<Value, String> {
|
fn run_test(&self, test: Test) -> Result<Value, String> {
|
||||||
let tokenizer = tokenizer::tokenize("test", test.content.into()).map_err(|x| x.to_string())?;
|
let tokenizer = tokenizer::tokenize("test", test.content.into()).map_err(|x| {
|
||||||
|
let s = x.to_string();
|
||||||
|
println!("s is {}", s);
|
||||||
|
s
|
||||||
|
})?;
|
||||||
if tokenizer
|
if tokenizer
|
||||||
.iter()
|
.iter()
|
||||||
.all(|x| matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_)))
|
.all(|x| matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_)))
|
||||||
@ -108,7 +112,11 @@ impl Namespace for ParseStatementNamespace {
|
|||||||
}
|
}
|
||||||
let mut tokens = ParserContext::new(tokenizer);
|
let mut tokens = ParserContext::new(tokenizer);
|
||||||
|
|
||||||
let parsed = tokens.parse_statement().map_err(|x| x.to_string())?;
|
let parsed = tokens.parse_statement().map_err(|x| {
|
||||||
|
let s = x.to_string();
|
||||||
|
println!("bruh {}", s);
|
||||||
|
s
|
||||||
|
})?;
|
||||||
not_fully_consumed(&mut tokens)?;
|
not_fully_consumed(&mut tokens)?;
|
||||||
|
|
||||||
Ok(serde_yaml::to_value(&parsed).expect("serialization failed"))
|
Ok(serde_yaml::to_value(&parsed).expect("serialization failed"))
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
namespace: Compile
|
|
||||||
expectation: Pass
|
|
||||||
input_file: input/dummy.in
|
|
||||||
*/
|
|
||||||
|
|
||||||
function main(y: bool) -> bool {
|
|
||||||
console.debug("hello debug");
|
|
||||||
return y == true;
|
|
||||||
}
|
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> compiler-test:6:19\n |\n 6 | const x = a[i..10];\n | ^^^^^^^^\n |\n = array size cannot be inferred, add explicit types"
|
- " --> compiler-test:7:17\n |\n 7 | console.debug(\"{}\", x);\n | ^^^^^\n |\n = expected identifier 'assert', 'error', 'log' -- got 'debug'"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> :0:0\n |\n |\n |\n = failed to resolve import: 'core'"
|
- " --> :0:0\n |\n |\n = failed to resolve import: 'core'"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> :0:0\n |\n |\n |\n = failed to resolve import: 'core'"
|
- " --> :0:0\n |\n |\n = failed to resolve import: 'core'"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> :0:0\n |\n |\n |\n = failed to resolve import: 'core.unstable'"
|
- " --> :0:0\n |\n |\n = failed to resolve import: 'core.unstable'"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> compiler-test:6:12\n |\n 6 | return 10u32; \n | ^^^^^\n |\n = unexpected type, expected: '()', received: 'u32'"
|
- "- Circuit has no constraints, use inputs and registers in program to produce them"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> compiler-test:4:5\n |\n 4 | if true {\n 5 | ...\n 6 | }\n | ^\n |\n = function 'main' failed to validate return path: 'cannot have asymmetrical return in if statement'"
|
- " --> compiler-test:4:5\n |\n 4 | if true {\n|\n 5 | ...\n|\n 6 | }\n | ^\n |\n = function 'main' failed to validate return path: 'cannot have asymmetrical return in if statement'"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> compiler-test:3:1\n |\n 3 | function main() -> bool {\n 4 | ...\n 5 | }\n 6 | \n 7 | \n 8 | \n 9 | \n 10 | \n | ^\n |\n = function 'main' missing return for all paths"
|
- " --> compiler-test:3:1\n |\n 3 | function main() -> bool {\n|\n 4 | ...\n|\n 5 | }\n|\n 6 | \n|\n 7 | \n|\n 8 | \n|\n 9 | \n|\n 10 | \n | ^\n |\n = function 'main' missing return for all paths"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- " --> compiler-test:3:1\n |\n 3 | function main() -> bool {\n 4 | ...\n 5 | }\n | ^\n |\n = Mismatched types. Expected register output type `u8`, found type `bool`."
|
- " --> compiler-test:3:1\n |\n 3 | function main() -> bool {\n|\n 4 | ...\n|\n 5 | }\n | ^\n |\n = Mismatched types. Expected register output type `u8`, found type `bool`."
|
||||||
|
@ -80,73 +80,6 @@ outputs:
|
|||||||
col_stop: 18
|
col_stop: 18
|
||||||
path: test
|
path: test
|
||||||
content: "console.error(\"x\");"
|
content: "console.error(\"x\");"
|
||||||
- Console:
|
|
||||||
function:
|
|
||||||
Debug:
|
|
||||||
string:
|
|
||||||
- Scalar: 123
|
|
||||||
- Scalar: 125
|
|
||||||
parameters:
|
|
||||||
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"test\\\",\\\"content\\\":\\\"console.debug(\\\\\\\"{}\\\\\\\", x);\\\"}\"}"
|
|
||||||
span:
|
|
||||||
line_start: 1
|
|
||||||
line_stop: 1
|
|
||||||
col_start: 15
|
|
||||||
col_stop: 22
|
|
||||||
path: test
|
|
||||||
content: "console.debug(\"{}\", x);"
|
|
||||||
span:
|
|
||||||
line_start: 1
|
|
||||||
line_stop: 1
|
|
||||||
col_start: 1
|
|
||||||
col_stop: 22
|
|
||||||
path: test
|
|
||||||
content: "console.debug(\"{}\", x);"
|
|
||||||
- Console:
|
|
||||||
function:
|
|
||||||
Debug:
|
|
||||||
string:
|
|
||||||
- Scalar: 123
|
|
||||||
- Scalar: 125
|
|
||||||
- Scalar: 123
|
|
||||||
- Scalar: 125
|
|
||||||
parameters:
|
|
||||||
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"test\\\",\\\"content\\\":\\\"console.debug(\\\\\\\"{}{}\\\\\\\", x, y);\\\"}\"}"
|
|
||||||
- Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"test\\\",\\\"content\\\":\\\"console.debug(\\\\\\\"{}{}\\\\\\\", x, y);\\\"}\"}"
|
|
||||||
span:
|
|
||||||
line_start: 1
|
|
||||||
line_stop: 1
|
|
||||||
col_start: 15
|
|
||||||
col_stop: 27
|
|
||||||
path: test
|
|
||||||
content: "console.debug(\"{}{}\", x, y);"
|
|
||||||
span:
|
|
||||||
line_start: 1
|
|
||||||
line_stop: 1
|
|
||||||
col_start: 1
|
|
||||||
col_stop: 27
|
|
||||||
path: test
|
|
||||||
content: "console.debug(\"{}{}\", x, y);"
|
|
||||||
- Console:
|
|
||||||
function:
|
|
||||||
Debug:
|
|
||||||
string:
|
|
||||||
- Scalar: 120
|
|
||||||
parameters: []
|
|
||||||
span:
|
|
||||||
line_start: 1
|
|
||||||
line_stop: 1
|
|
||||||
col_start: 15
|
|
||||||
col_stop: 18
|
|
||||||
path: test
|
|
||||||
content: "console.debug(\"x\");"
|
|
||||||
span:
|
|
||||||
line_start: 1
|
|
||||||
line_stop: 1
|
|
||||||
col_start: 1
|
|
||||||
col_stop: 18
|
|
||||||
path: test
|
|
||||||
content: "console.debug(\"x\");"
|
|
||||||
- Console:
|
- Console:
|
||||||
function:
|
function:
|
||||||
Log:
|
Log:
|
||||||
|
@ -13,13 +13,6 @@ console.error("{}{}", x, y);
|
|||||||
console.error("x");
|
console.error("x");
|
||||||
|
|
||||||
|
|
||||||
console.debug("{}", x);
|
|
||||||
|
|
||||||
console.debug("{}{}", x, y);
|
|
||||||
|
|
||||||
console.debug("x");
|
|
||||||
|
|
||||||
|
|
||||||
console.log("{}", x);
|
console.log("{}", x);
|
||||||
|
|
||||||
console.log("{}{}", x, y);
|
console.log("{}{}", x, y);
|
||||||
|
Loading…
Reference in New Issue
Block a user