From e4954678f018ee643b2bee5e4872db70db38f0dd Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 21 Nov 2024 18:50:13 -0500 Subject: [PATCH] start looking into memory layout --- Cargo.toml | 1 + src/main.rs | 16 +++++++--------- src/parser.rs | 15 ++------------- src/value.rs | 3 ++- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed08903..23231ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ edition = "2021" ariadne = { git = "https://github.com/zesterer/ariadne" } chumsky = { git = "https://github.com/zesterer/chumsky", features = ["label"] } imbl = "3.0.0" +struct_scalpel = "0.1.1" tailcall = "1.0.1" diff --git a/src/main.rs b/src/main.rs index ab2c95b..c476b96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,18 +57,12 @@ use crate::base::*; pub fn main() { let src = " -let foo = false -loop (foo) with { - (:foo) -> :done - (x as :boolean) -> recur (:bar) - (x as :number) -> recur (:foo) - (x as :keyword) -> recur (:foo) -} +true "; let (tokens, lex_errs) = lexer().parse(src).into_output_errors(); - if lex_errs.len() > 0 { + if !lex_errs.is_empty() { println!("{:?}", lex_errs); - return (); + return; } let tokens = tokens.unwrap(); let to_parse = tokens.clone(); @@ -85,4 +79,8 @@ loop (foo) with { let result = eval(&ast, &mut ctx).unwrap(); println!("{}", result); + + // struct_scalpel::print_dissection_info::() + // struct_scalpel::print_dissection_info::(); + // println!("{}", std::mem::size_of::()) } diff --git a/src/parser.rs b/src/parser.rs index afdfb36..9b92cb9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2,6 +2,7 @@ use crate::lexer::*; use crate::spans::*; use chumsky::{input::ValueInput, prelude::*, recursive::Recursive}; use std::fmt; +use struct_scalpel::Dissectible; #[derive(Clone, Debug, PartialEq)] pub struct WhenClause<'src> { @@ -32,19 +33,7 @@ impl<'src> fmt::Display for MatchClause<'src> { } } -// #[derive(Clone, Debug, PartialEq)] -// pub struct Pair<'src> { -// pub key: &'src str, -// pub value: Spanned>, -// } - -// impl<'src> fmt::Display for Pair<'src> { -// fn fmt(self: &Pair<'src>, f: &mut fmt::Formatter) -> fmt::Result { -// write!(f, "pair: {}: {}", self.key, self.value.0) -// } -// } - -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Dissectible)] pub enum Ast<'src> { Error, Placeholder, diff --git a/src/value.rs b/src/value.rs index c88ce86..2e08bca 100644 --- a/src/value.rs +++ b/src/value.rs @@ -4,6 +4,7 @@ use imbl::*; use std::cell::RefCell; use std::fmt; use std::rc::Rc; +use struct_scalpel::Dissectible; #[derive(Clone, Debug)] pub struct Fn<'src> { @@ -11,7 +12,7 @@ pub struct Fn<'src> { pub body: &'src Vec>, } -#[derive(Debug)] +#[derive(Debug, Dissectible)] pub enum Value<'src> { Nil, Placeholder,