Compiler stub.

This commit is contained in:
chriseth
2023-01-23 15:39:24 +01:00
parent f59882c7e4
commit 54a7900a39
4 changed files with 51 additions and 12 deletions

5
src/bin/compiler.rs Normal file
View File

@@ -0,0 +1,5 @@
use std::env;
fn main() {
powdr::compiler::compile(&env::args().nth(1).unwrap());
}

View File

@@ -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
View 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) {}
}

View File

@@ -1 +1,2 @@
pub mod compiler;
pub mod parser;