From 18f981007039869661e4a3316e06d00f5cbda62b Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 21 May 2020 19:09:48 -0400 Subject: [PATCH] Move compile::visit mod to crate root Signed-off-by: Alek Ratzloff --- src/compile/block.rs | 3 ++- src/compile/mod.rs | 45 +++++++++++++++++++++++++++++++++++++- src/compile/name.rs | 3 ++- src/main.rs | 1 + src/{compile => }/visit.rs | 6 ++--- 5 files changed, 52 insertions(+), 6 deletions(-) rename src/{compile => }/visit.rs (92%) diff --git a/src/compile/block.rs b/src/compile/block.rs index f63807a..672cc92 100644 --- a/src/compile/block.rs +++ b/src/compile/block.rs @@ -1,6 +1,7 @@ use crate::{ - compile::{ctx::Ctx, error::*, ir, visit::*}, + compile::{ctx::Ctx, error::*, ir}, syn::{ast::*, op::BinOp, span::*}, + visit::*, }; // basic block diff --git a/src/compile/mod.rs b/src/compile/mod.rs index 93c4c39..7dda1f6 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -1,5 +1,4 @@ #[macro_use] -pub mod visit; pub mod attrs; pub mod block; pub mod ctx; @@ -7,3 +6,47 @@ pub mod error; pub mod ir; pub mod name; pub mod sym; + +// question: +// where to insert root/builtin names +// +// Brainstorming: +// * Want to avoid initializing a GC during compile-time +// * Shared resources between compiler and VM: +// - tracked pointers (gc'd or otherwise) +// - a "constant" pointer API might be a good avenue to explore - e.g. relaxing +// constraints on Attrs to accept pointers as a source of data (maybe +// Attrs::new_unchecked) +// - I think there needs to be a new way to make an Attrs instance without GC involved +// - Main problem is how to get the "this" pointer for Attrs obj? +// - Maybe make a "ConstGc" or something like that, which never releases its +// references and is used for the core? +// - registered symbols (mutable) +// * Separate object pointers from GC pointers +// - GC pointer itself gets marked, and then marks all attributes? +// - Maybe use a visitor pattern for marking built-in objects? +// - TODO - try this +// +// impl Visit for Gc { +// type Out = (); +// fn visit(&mut self, acceptor: &A) -> Self::Out { +// +// } +// } +// +// other idea: eliminate IR and compile straight from AST to vm::Op +// IR pros and cons +// +// Disposition: keep IR since it's already there and helps with semantic translation +// +// PRO +// = +// * Compact representation +// * Easier to translate to VM ops +// * Can add IR layer at a later time +// +// CON +// = +// * Requires lots of complex resource sharing (GC, symbols, etc) for creating constants +// * Probably better in the long term for modification using IR mid-level +// * More natural LHS expression compilation with IR diff --git a/src/compile/name.rs b/src/compile/name.rs index db5b67d..b7fbc02 100644 --- a/src/compile/name.rs +++ b/src/compile/name.rs @@ -1,7 +1,8 @@ use crate::{ - compile::{ctx::Ctx, visit::*}, + compile::ctx::Ctx, obj::prelude::*, syn::{ast::prelude::*, span::*}, + visit::*, }; use std::collections::HashMap; diff --git a/src/main.rs b/src/main.rs index 64c5c3e..fb42689 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![allow(dead_code)] #![feature(unsize, coerce_unsized, new_uninit)] +#[macro_use] mod visit; mod compile; mod mem; mod obj; diff --git a/src/compile/visit.rs b/src/visit.rs similarity index 92% rename from src/compile/visit.rs rename to src/visit.rs index 9ca78e9..a25fe51 100644 --- a/src/compile/visit.rs +++ b/src/visit.rs @@ -18,7 +18,7 @@ pub trait DefaultAccept>: Accept + Sized { #[macro_export] macro_rules! default_visitor { ($default:ident for $visitor:ty where Out = $out:ty) => { - impl crate::compile::visit::Visit<$default> for $visitor { + impl crate::visit::Visit<$default> for $visitor { type Out = $out; fn visit(&mut self, acceptor: &$default) -> Self::Out { acceptor.default_accept(self) @@ -30,7 +30,7 @@ macro_rules! default_visitor { #[macro_export] macro_rules! empty_visitor { ($default:ident for $visitor:ty) => { - impl crate::compile::visit::Visit<$default> for $visitor { + impl crate::visit::Visit<$default> for $visitor { type Out = (); fn visit(&mut self, _: &$default) -> Self::Out {} } @@ -39,7 +39,7 @@ macro_rules! empty_visitor { macro_rules! impl_accept { ($what:ident) => { - impl crate::compile::visit::Accept for $what { + impl crate::visit::Accept for $what { fn accept>(&self, visitor: &mut V) -> V::Out { visitor.visit(self) }