mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-01-10 22:08:44 -05:00
Compiler stub.
This commit is contained in:
5
src/bin/compiler.rs
Normal file
5
src/bin/compiler.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
powdr::compiler::compile(&env::args().nth(1).unwrap());
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
|
||||
use powdr::parser;
|
||||
|
||||
fn main() {
|
||||
let input = fs::read_to_string(env::args().nth(1).unwrap()).unwrap();
|
||||
match parser::parse(&input) {
|
||||
Ok(result) => println!("{result:?}"),
|
||||
Err(err) => println!("Parse error: {err}"),
|
||||
}
|
||||
}
|
||||
45
src/compiler/mod.rs
Normal file
45
src/compiler/mod.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
use crate::parser::ast::*;
|
||||
use crate::parser::{self, ast::PILFile};
|
||||
|
||||
pub fn compile(path: &str) {
|
||||
let input = fs::read_to_string(path).unwrap();
|
||||
match parser::parse(&input) {
|
||||
Ok(pil_file) => {
|
||||
let mut ctx = Context::default();
|
||||
ctx.process(&pil_file);
|
||||
}
|
||||
Err(err) => println!("Parse error: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Context {
|
||||
namespace: String,
|
||||
included_files: HashSet<String>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn process(&mut self, file: &PILFile) {
|
||||
for statement in &file.0 {
|
||||
match statement {
|
||||
Statement::Include(include) => self.handle_include(include),
|
||||
Statement::Namespace(name, degree) => self.handle_namespace(name, degree),
|
||||
Statement::PolynomialDefinition(_, _) => todo!(),
|
||||
Statement::PolynomialConstantDeclaration(_) => todo!(),
|
||||
Statement::PolynomialCommitDeclaration(_) => todo!(),
|
||||
Statement::PolynomialIdentity(_) => todo!(),
|
||||
Statement::PlookupIdentity(_, _) => todo!(),
|
||||
Statement::ConstantDefinition(_, _) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_include(&mut self, path: &str) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn handle_namespace(&mut self, name: &str, degree: &Expression) {}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod compiler;
|
||||
pub mod parser;
|
||||
|
||||
Reference in New Issue
Block a user