Skip to content

Commit

Permalink
Merge the array
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksharmaongraph committed Apr 23, 2024
1 parent 78b84e5 commit 9e591d1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
14 changes: 13 additions & 1 deletion framec/src/frame_c/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::cell::RefCell;
use std::fs;
use std::io;
use std::io::Read;
use std::panic::{self, AssertUnwindSafe};
use std::path::{Path, PathBuf};
use std::rc::Rc;

Expand Down Expand Up @@ -166,7 +167,15 @@ impl Exe {
// NOTE: This block is to remove references to symbol_table and comments
{
let mut syntactic_parser = Parser::new(&tokens, &mut comments, true, arcanum);
syntactic_parser.parse();

panic::set_hook(Box::new(|_info| {
// prevent std output from panics.
}));
// catch and suppress panics
let _result = panic::catch_unwind(AssertUnwindSafe(|| {
syntactic_parser.parse();
}));

if syntactic_parser.had_error() {
let mut errors = "Terminating with errors.\n".to_string();
errors.push_str(&syntactic_parser.get_errors());
Expand All @@ -178,6 +187,9 @@ impl Exe {

let mut comments2 = comments.clone();
let mut semantic_parser = Parser::new(&tokens, &mut comments2, false, arcanum);

// TODO: this doesn't capture any panics like syntactic_parser above.
// Need to figure how to implement.
let system_node = semantic_parser.parse();
if semantic_parser.had_error() {
let mut errors = "Terminating with errors.\n".to_string();
Expand Down
38 changes: 33 additions & 5 deletions framec/src/frame_c/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ impl<'a> Parser<'a> {
Err(_parse_error) => None,
};

if let Some(ref function_vec) = functions_opt {
// If there is a function, there can be only one and it must be named 'main'.
if function_vec.len() > 1 {
self.error_at_current("Frame can have at most one function which must be 'main'.");
} else if function_vec.len() == 1 {
let function_opt = function_vec.get(0);
let function_node = function_opt.unwrap().borrow();
if function_node.name != "main" {
self.error_at_current(
"Frame can have at most one function which must be 'main'.",
);
}
}
}

// #[system_attribute]
let system_attributes_opt = match self.entity_attributes() {
Ok(attributes_opt) => attributes_opt,
Expand All @@ -209,15 +224,28 @@ impl<'a> Parser<'a> {
if self.match_token(&[TokenType::System]) {
self.system(module_elements_opt, system_attributes_opt, functions_opt)
} else {
// TODO: For now we always need to have one (and only one) system.
// TODO: This path is taken when there isn't a declared system.
// For now, the rule is there must be a function and/or a system declared.

// The semantics for any existing functions are validated above.
// If we don't have a system then we must have a main so none is an error here.
if functions_opt.is_none() {
self.error_at_current("Frame modules must have a 'main' function or a system.");
}

let module = match module_elements_opt {
Some(module_elements) => Module { module_elements },
None => Module {
module_elements: vec![],
},
};

let line = self.previous().line;
// Hack to prevent referencing -1 index in previous().
let line = if self.current == 0 {
1
} else {
self.previous().line
};

SystemNode::new(
String::new(),
Expand Down Expand Up @@ -5994,9 +6022,9 @@ impl<'a> Parser<'a> {
}

// '@' '^'
if self.match_token(&[TokenType::Caret]) {
return Ok(Some(FrameEventPart::Return { is_reference }));
}
// if self.match_token(&[TokenType::Caret]) {
// return Ok(Some(FrameEventPart::Return { is_reference }));
// }

// @
Ok(Some(FrameEventPart::Event { is_reference }))
Expand Down
2 changes: 2 additions & 0 deletions framec/src/frame_c/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,11 @@ impl Scanner {
// Unterminated string.
if self.is_at_end() {
self.error(self.line, "Unterminated string.");
return;
}

self.advance();

self.add_string_token_literal(TokenType::String, TokenLiteral::None);
}

Expand Down
2 changes: 0 additions & 2 deletions framec/src/frame_c/visitors/python_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1982,8 +1982,6 @@ impl AstVisitor for PythonVisitor {
self.add_code("self._message = message");
self.newline();
self.add_code("self._parameters = parameters");
self.newline();
self.add_code("self._return = None");
self.outdent();
self.outdent();
self.newline();
Expand Down

0 comments on commit 9e591d1

Please sign in to comment.