start looking into memory layout

This commit is contained in:
Scott Richmond 2024-11-21 18:50:13 -05:00
parent 0cd170bd83
commit e4954678f0
4 changed files with 12 additions and 23 deletions

View File

@ -9,4 +9,5 @@ edition = "2021"
ariadne = { git = "https://github.com/zesterer/ariadne" } ariadne = { git = "https://github.com/zesterer/ariadne" }
chumsky = { git = "https://github.com/zesterer/chumsky", features = ["label"] } chumsky = { git = "https://github.com/zesterer/chumsky", features = ["label"] }
imbl = "3.0.0" imbl = "3.0.0"
struct_scalpel = "0.1.1"
tailcall = "1.0.1" tailcall = "1.0.1"

View File

@ -57,18 +57,12 @@ use crate::base::*;
pub fn main() { pub fn main() {
let src = " let src = "
let foo = false true
loop (foo) with {
(:foo) -> :done
(x as :boolean) -> recur (:bar)
(x as :number) -> recur (:foo)
(x as :keyword) -> recur (:foo)
}
"; ";
let (tokens, lex_errs) = lexer().parse(src).into_output_errors(); let (tokens, lex_errs) = lexer().parse(src).into_output_errors();
if lex_errs.len() > 0 { if !lex_errs.is_empty() {
println!("{:?}", lex_errs); println!("{:?}", lex_errs);
return (); return;
} }
let tokens = tokens.unwrap(); let tokens = tokens.unwrap();
let to_parse = tokens.clone(); let to_parse = tokens.clone();
@ -85,4 +79,8 @@ loop (foo) with {
let result = eval(&ast, &mut ctx).unwrap(); let result = eval(&ast, &mut ctx).unwrap();
println!("{}", result); println!("{}", result);
// struct_scalpel::print_dissection_info::<value::Value>()
// struct_scalpel::print_dissection_info::<parser::Ast>();
// println!("{}", std::mem::size_of::<parser::Ast>())
} }

View File

@ -2,6 +2,7 @@ use crate::lexer::*;
use crate::spans::*; use crate::spans::*;
use chumsky::{input::ValueInput, prelude::*, recursive::Recursive}; use chumsky::{input::ValueInput, prelude::*, recursive::Recursive};
use std::fmt; use std::fmt;
use struct_scalpel::Dissectible;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct WhenClause<'src> { pub struct WhenClause<'src> {
@ -32,19 +33,7 @@ impl<'src> fmt::Display for MatchClause<'src> {
} }
} }
// #[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq, Dissectible)]
// pub struct Pair<'src> {
// pub key: &'src str,
// pub value: Spanned<Ast<'src>>,
// }
// 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)]
pub enum Ast<'src> { pub enum Ast<'src> {
Error, Error,
Placeholder, Placeholder,

View File

@ -4,6 +4,7 @@ use imbl::*;
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::rc::Rc; use std::rc::Rc;
use struct_scalpel::Dissectible;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Fn<'src> { pub struct Fn<'src> {
@ -11,7 +12,7 @@ pub struct Fn<'src> {
pub body: &'src Vec<MatchClause<'src>>, pub body: &'src Vec<MatchClause<'src>>,
} }
#[derive(Debug)] #[derive(Debug, Dissectible)]
pub enum Value<'src> { pub enum Value<'src> {
Nil, Nil,
Placeholder, Placeholder,