From f29eaac1d0eea26adb6bd6babf6e9416b9f2f6af Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Tue, 26 Sep 2023 14:00:11 -0500 Subject: [PATCH] :white_check_mark: test: measure size of my Value compared to PUC Lua (mine's bigger sadly, like 40 bytes) --- src/tests.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index b053adf..9be3e9b 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -191,3 +191,33 @@ fn is_93 () { assert_eq! (actual, expected); } } + +#[test] +fn value_size () { + // Per https://www.lua.org/doc/jucs05.pdf, + // "The Implementation of Lua 5.0", + // + // Lua's tagged union values are 12-16 bytes on a 32-bit system + // with 64-bit floats + // + // It is very nice if LunarWaveVM is the same or better. + // There is some exploratory things in this test, too + + use std::{ + mem::size_of, + rc::Rc, + }; + + assert! (size_of::> () <= 8); + assert! (size_of::> () <= 8); + + pub enum Value { + Nil, + Boolean (bool), + Float (f64), + String (Rc ), + } + + assert_eq! (size_of:: (), 16); + assert_eq! (size_of:: (), 16); +}