Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 26 additions & 10 deletions grey_compiler/crates/grey_lang/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,32 @@ impl<'a> Parser<'a> {
// === Utility Methods ===

fn consume_identifier(&mut self, message: &str) -> Result<String, Box<dyn Diagnostic>> {
if let Token::Identifier(name) = &self.peek().token {
let name = name.clone();
self.advance();
Ok(name)
} else {
Err(Box::new(DiagnosticError::general(
message,
crate::diagnostics::SourceLocation::dummy(),
)))
}
// Handle keywords that can be used as identifiers in certain contexts
let name = match &self.peek().token {
Token::Identifier(name) => name.clone(),
Token::Event => "event".to_string(), // Allow "event" as identifier
Token::Const => "const".to_string(), // Allow "const" as identifier
Token::Fn => "fn".to_string(), // Allow "fn" as identifier
Token::Let => "let".to_string(), // Allow "let" as identifier
Token::If => "if".to_string(), // Allow "if" as identifier
Token::Else => "else".to_string(), // Allow "else" as identifier
Token::While => "while".to_string(), // Allow "while" as identifier
Token::For => "for".to_string(), // Allow "for" as identifier
Token::Return => "return".to_string(), // Allow "return" as identifier
Token::Process => "process".to_string(), // Allow "process" as identifier
Token::Module => "module".to_string(), // Allow "module" as identifier
Token::Boolean(true) => "true".to_string(),
Token::Boolean(false) => "false".to_string(),
_ => {
return Err(Box::new(DiagnosticError::general(
message,
crate::diagnostics::SourceLocation::dummy(),
)));
}
};

self.advance();
Ok(name)
}

fn consume(&mut self, expected: &Token, message: &str) -> Result<(), Box<dyn Diagnostic>> {
Expand Down
25 changes: 25 additions & 0 deletions grey_compiler/simple_test.grey
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Test the original failing case: keyword as parameter name
module SimpleTest {
event Infection {
strain: Int,
severity: Int,
}

process Person {
infected: Bool,
recovered: Bool,
infection_count: Int,

method handle_infection(event: Infection) {
// This was failing with "Expected parameter name" at (0,0)
this.infected = true;
this.infection_count = this.infection_count + 1;
}

method handle_recovery(event: Infection) {
// This was also failing
this.infected = false;
this.recovered = true;
}
}
}
193 changes: 193 additions & 0 deletions grey_compiler/sir_demo_betti.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
//! Auto-generated Betti RDL executable for sir_demo
//! This file was generated by the Grey compiler backend.

use betti_rdl::Kernel;
use std::collections::HashMap;

pub struct sir_demoExecutable {
kernel: Kernel,
process_coords: HashMap<String, (i32, i32, i32)>,
}

impl sir_demoExecutable {
pub fn new() -> Self {
let mut executable = Self {
kernel: Kernel::new(),
process_coords: HashMap::new(),
};

// Initialize process coordinates
executable.process_coords.insert("p0".to_string(), (0, 0, 0));
executable.process_coords.insert("p1".to_string(), (1, 0, 0));
executable.process_coords.insert("p10".to_string(), (2, 1, 0));
executable.process_coords.insert("p11".to_string(), (3, 1, 0));
executable.process_coords.insert("p12".to_string(), (4, 1, 0));
executable.process_coords.insert("p13".to_string(), (5, 1, 0));
executable.process_coords.insert("p14".to_string(), (6, 1, 0));
executable.process_coords.insert("p15".to_string(), (7, 1, 0));
executable.process_coords.insert("p16".to_string(), (0, 2, 0));
executable.process_coords.insert("p17".to_string(), (1, 2, 0));
executable.process_coords.insert("p18".to_string(), (2, 2, 0));
executable.process_coords.insert("p19".to_string(), (3, 2, 0));
executable.process_coords.insert("p2".to_string(), (2, 0, 0));
executable.process_coords.insert("p20".to_string(), (4, 2, 0));
executable.process_coords.insert("p21".to_string(), (5, 2, 0));
executable.process_coords.insert("p22".to_string(), (6, 2, 0));
executable.process_coords.insert("p23".to_string(), (7, 2, 0));
executable.process_coords.insert("p24".to_string(), (0, 3, 0));
executable.process_coords.insert("p25".to_string(), (1, 3, 0));
executable.process_coords.insert("p26".to_string(), (2, 3, 0));
executable.process_coords.insert("p27".to_string(), (3, 3, 0));
executable.process_coords.insert("p28".to_string(), (4, 3, 0));
executable.process_coords.insert("p29".to_string(), (5, 3, 0));
executable.process_coords.insert("p3".to_string(), (3, 0, 0));
executable.process_coords.insert("p30".to_string(), (6, 3, 0));
executable.process_coords.insert("p31".to_string(), (7, 3, 0));
executable.process_coords.insert("p32".to_string(), (0, 4, 0));
executable.process_coords.insert("p33".to_string(), (1, 4, 0));
executable.process_coords.insert("p34".to_string(), (2, 4, 0));
executable.process_coords.insert("p35".to_string(), (3, 4, 0));
executable.process_coords.insert("p36".to_string(), (4, 4, 0));
executable.process_coords.insert("p37".to_string(), (5, 4, 0));
executable.process_coords.insert("p38".to_string(), (6, 4, 0));
executable.process_coords.insert("p39".to_string(), (7, 4, 0));
executable.process_coords.insert("p4".to_string(), (4, 0, 0));
executable.process_coords.insert("p40".to_string(), (0, 5, 0));
executable.process_coords.insert("p41".to_string(), (1, 5, 0));
executable.process_coords.insert("p42".to_string(), (2, 5, 0));
executable.process_coords.insert("p43".to_string(), (3, 5, 0));
executable.process_coords.insert("p44".to_string(), (4, 5, 0));
executable.process_coords.insert("p45".to_string(), (5, 5, 0));
executable.process_coords.insert("p46".to_string(), (6, 5, 0));
executable.process_coords.insert("p47".to_string(), (7, 5, 0));
executable.process_coords.insert("p48".to_string(), (0, 6, 0));
executable.process_coords.insert("p49".to_string(), (1, 6, 0));
executable.process_coords.insert("p5".to_string(), (5, 0, 0));
executable.process_coords.insert("p50".to_string(), (2, 6, 0));
executable.process_coords.insert("p51".to_string(), (3, 6, 0));
executable.process_coords.insert("p52".to_string(), (4, 6, 0));
executable.process_coords.insert("p53".to_string(), (5, 6, 0));
executable.process_coords.insert("p54".to_string(), (6, 6, 0));
executable.process_coords.insert("p55".to_string(), (7, 6, 0));
executable.process_coords.insert("p56".to_string(), (0, 7, 0));
executable.process_coords.insert("p57".to_string(), (1, 7, 0));
executable.process_coords.insert("p58".to_string(), (2, 7, 0));
executable.process_coords.insert("p59".to_string(), (3, 7, 0));
executable.process_coords.insert("p6".to_string(), (6, 0, 0));
executable.process_coords.insert("p60".to_string(), (4, 7, 0));
executable.process_coords.insert("p61".to_string(), (5, 7, 0));
executable.process_coords.insert("p62".to_string(), (6, 7, 0));
executable.process_coords.insert("p63".to_string(), (7, 7, 0));
executable.process_coords.insert("p7".to_string(), (7, 0, 0));
executable.process_coords.insert("p8".to_string(), (0, 1, 0));
executable.process_coords.insert("p9".to_string(), (1, 1, 0));
executable
}

pub fn spawn_processes(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.kernel.spawn_process(0, 0, 0); // p0
self.kernel.spawn_process(1, 0, 0); // p1
self.kernel.spawn_process(2, 1, 0); // p10
self.kernel.spawn_process(3, 1, 0); // p11
self.kernel.spawn_process(4, 1, 0); // p12
self.kernel.spawn_process(5, 1, 0); // p13
self.kernel.spawn_process(6, 1, 0); // p14
self.kernel.spawn_process(7, 1, 0); // p15
self.kernel.spawn_process(0, 2, 0); // p16
self.kernel.spawn_process(1, 2, 0); // p17
self.kernel.spawn_process(2, 2, 0); // p18
self.kernel.spawn_process(3, 2, 0); // p19
self.kernel.spawn_process(2, 0, 0); // p2
self.kernel.spawn_process(4, 2, 0); // p20
self.kernel.spawn_process(5, 2, 0); // p21
self.kernel.spawn_process(6, 2, 0); // p22
self.kernel.spawn_process(7, 2, 0); // p23
self.kernel.spawn_process(0, 3, 0); // p24
self.kernel.spawn_process(1, 3, 0); // p25
self.kernel.spawn_process(2, 3, 0); // p26
self.kernel.spawn_process(3, 3, 0); // p27
self.kernel.spawn_process(4, 3, 0); // p28
self.kernel.spawn_process(5, 3, 0); // p29
self.kernel.spawn_process(3, 0, 0); // p3
self.kernel.spawn_process(6, 3, 0); // p30
self.kernel.spawn_process(7, 3, 0); // p31
self.kernel.spawn_process(0, 4, 0); // p32
self.kernel.spawn_process(1, 4, 0); // p33
self.kernel.spawn_process(2, 4, 0); // p34
self.kernel.spawn_process(3, 4, 0); // p35
self.kernel.spawn_process(4, 4, 0); // p36
self.kernel.spawn_process(5, 4, 0); // p37
self.kernel.spawn_process(6, 4, 0); // p38
self.kernel.spawn_process(7, 4, 0); // p39
self.kernel.spawn_process(4, 0, 0); // p4
self.kernel.spawn_process(0, 5, 0); // p40
self.kernel.spawn_process(1, 5, 0); // p41
self.kernel.spawn_process(2, 5, 0); // p42
self.kernel.spawn_process(3, 5, 0); // p43
self.kernel.spawn_process(4, 5, 0); // p44
self.kernel.spawn_process(5, 5, 0); // p45
self.kernel.spawn_process(6, 5, 0); // p46
self.kernel.spawn_process(7, 5, 0); // p47
self.kernel.spawn_process(0, 6, 0); // p48
self.kernel.spawn_process(1, 6, 0); // p49
self.kernel.spawn_process(5, 0, 0); // p5
self.kernel.spawn_process(2, 6, 0); // p50
self.kernel.spawn_process(3, 6, 0); // p51
self.kernel.spawn_process(4, 6, 0); // p52
self.kernel.spawn_process(5, 6, 0); // p53
self.kernel.spawn_process(6, 6, 0); // p54
self.kernel.spawn_process(7, 6, 0); // p55
self.kernel.spawn_process(0, 7, 0); // p56
self.kernel.spawn_process(1, 7, 0); // p57
self.kernel.spawn_process(2, 7, 0); // p58
self.kernel.spawn_process(3, 7, 0); // p59
self.kernel.spawn_process(6, 0, 0); // p6
self.kernel.spawn_process(4, 7, 0); // p60
self.kernel.spawn_process(5, 7, 0); // p61
self.kernel.spawn_process(6, 7, 0); // p62
self.kernel.spawn_process(7, 7, 0); // p63
self.kernel.spawn_process(7, 0, 0); // p7
self.kernel.spawn_process(0, 1, 0); // p8
self.kernel.spawn_process(1, 1, 0); // p9
Ok(())
}

pub fn inject_events(&mut self) -> Result<(), Box<dyn std::error::Error>> {
// Inject initial events to first process
if let Some((x, y, z)) = self.process_coords.get("p0") {
// Inject seed events to trigger process execution
self.kernel.inject_event(*x, *y, *z, 1);
}
Ok(())
}

pub fn run(&mut self, max_events: i32) -> Result<HashMap<String, u64>, Box<dyn std::error::Error>> {
let events_in_run = self.kernel.run(max_events);

let mut results = HashMap::new();
results.insert("events_in_run".to_string(), events_in_run as u64);
results.insert("events_processed".to_string(), self.kernel.events_processed());
results.insert("current_time".to_string(), self.kernel.current_time());
results.insert("process_count".to_string(), self.kernel.process_count() as u64);
Ok(results)
}

}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_sir_demo_execution() {
let mut executable = sir_demoExecutable::new();
executable.spawn_processes().unwrap();
executable.inject_events().unwrap();

let results = executable.run(100).unwrap();

assert!(results.contains_key("events_processed"));
assert_eq!(results["process_count"], 64 as u64);
}
}
2 changes: 1 addition & 1 deletion grey_compiler/target/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"rustc_fingerprint":5499565177865739684,"outputs":{"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/engine/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.92.0 (ded5c06cf 2025-12-08)\nbinary: rustc\ncommit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234\ncommit-date: 2025-12-08\nhost: x86_64-unknown-linux-gnu\nrelease: 1.92.0\nLLVM version: 21.1.3\n","stderr":""}},"successes":{}}
{"rustc_fingerprint":1667727843378204266,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.92.0 (ded5c06cf 2025-12-08)\nbinary: rustc\ncommit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234\ncommit-date: 2025-12-08\nhost: x86_64-unknown-linux-gnu\nrelease: 1.92.0\nLLVM version: 21.1.3\n","stderr":""},"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/engine/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified grey_compiler/target/debug/deps/grey_harness-987c39918135c785
Binary file not shown.
Binary file modified grey_compiler/target/debug/deps/greyc-0129acffd92aff3d
Binary file not shown.
Binary file modified grey_compiler/target/debug/deps/libbetti_rdl.rlib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified grey_compiler/target/debug/deps/libgrey_ir-3db6d0d1164cb215.rlib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified grey_compiler/target/debug/greyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading