#![allow(dead_code)]
#![feature(unsize, coerce_unsized, new_uninit)]
mod compile;
mod syn;
mod obj;
mod mem;
mod vm;
use std::{
convert::TryFrom,
fs,
path::PathBuf,
};
use structopt::StructOpt;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[derive(StructOpt, Debug)]
struct Options {
/// The input file to work with.
///
/// By default, the file will be executed. If -c is passed, it will not run and only compile.
/// Supplying - for the path will read from STDIN.
#[structopt(name = "FILE", parse(from_os_str))]
input: PathBuf,
/*
/// Disassemble object that would be passed to VM and exit before running it.
#[structopt(short = "d", long)]
disassemble: bool,
*/
}
fn main() -> Result<()> {
use syn::{
parser::Parser,
let opt = Options::from_args();
let text = fs::read_to_string(&opt.input)?;
let mut parser = Parser::try_from(text.as_str())?;
let ast = parser.next_body()?;
//println!("{:#?}", ast);
let mut ctx = compile::ctx::Ctx::new();
compile::name::CollectSyms::new(&mut ctx, text.as_str()).collect(&ast);
println!("{:#?}", ctx.syms());
ctx.name_stack_mut().push_default();
{
let mut collect_names = compile::name::CollectNames::new(&mut ctx, text.as_str());
collect_names.collect(&ast);
let names = ctx.name_stack_mut().pop().unwrap();
//println!("{:#?}", names);
Ok(())