Browse Source

wip: if stack bug

master
Inderjit Gill 1 month ago
parent
commit
5efa05dcde
21 changed files with 607 additions and 111 deletions
  1. +1
    -1
      README.md
  2. +1
    -1
      client/src/lib.rs
  3. +1
    -2
      core/src/colour.rs
  4. +0
    -2
      core/src/compiler.rs
  5. +1
    -1
      core/src/geometry/mod.rs
  6. +49
    -7
      core/src/geometry/ring.rs
  7. +48
    -29
      core/src/interp.rs
  8. +1
    -1
      core/src/keywords.rs
  9. +2
    -2
      core/src/lib.rs
  10. +8
    -9
      core/src/native.rs
  11. +57
    -14
      core/src/path.rs
  12. +21
    -6
      core/src/prng.rs
  13. +1
    -1
      core/src/render_list.rs
  14. +2
    -0
      core/src/render_packet.rs
  15. +45
    -22
      core/src/repeat.rs
  16. +91
    -13
      core/src/vm.rs
  17. +8
    -0
      server/seni/sketch/1938-testing.seni
  18. +44
    -0
      server/seni/sketch/1941-bug.seni
  19. +12
    -0
      server/seni/sketch/1941-bug2.seni
  20. +11
    -0
      server/seni/sketch/1941-bug3.seni
  21. +203
    -0
      server/seni/sketch/1941-vhs.seni

+ 1
- 1
README.md View File

@@ -1,7 +1,7 @@
Seni
====

### Note: Development happens at [git.indy.io/indy/seni](https://git.indy.io/indy/seni)
### Note: The canonical home page for this project is [git.indy.io/indy/seni](https://git.indy.io/indy/seni)

## Overview


+ 1
- 1
client/src/lib.rs View File

@@ -249,7 +249,7 @@ impl Bridge {
if let Some(program) = &self.program {
match run_program_with_preamble(&mut self.vm, &mut self.context, &program) {
Ok(_) => {
self.vm.debug_str_clear();
self.vm.probe_clear();
self.context.render_list.remove_useless_render_packets();
self.context.render_list.get_num_render_packets()
}

+ 1
- 2
core/src/colour.rs View File

@@ -1306,7 +1306,7 @@ mod tests {

#[test]
fn test_colour_pack() {
let mut res: String = "".to_string();
let mut res: String = "".into();
let col = Colour::new(ColourFormat::Rgb, 1.1, 2.2, 3.3, 4.4);
col.pack(&mut res).unwrap();
assert_eq!("RGB 1.1 2.2 3.3 4.4", res);
@@ -1348,5 +1348,4 @@ mod tests {
assert_equal_f64(-0.1, fmod(-6.1, 6.0));
assert_equal_f64(-1.0, fmod(-7.0, 6.0));
}

}

+ 0
- 2
core/src/compiler.rs View File

@@ -1339,7 +1339,6 @@ impl Compiler {

// todo: some version of compile_user_defined_name that
// also looks at the string_to_keyword hash

}
}
} else if let Some(native) = self.name_to_native.get(&iname) {
@@ -3327,5 +3326,4 @@ mod tests {
expected_bytecode
);
}

}

+ 1
- 1
core/src/geometry/mod.rs View File

@@ -19,7 +19,7 @@ pub mod circle;
pub mod circle_slice;
pub mod line;
pub mod poly;
pub mod ring;
pub mod quadratic;
pub mod rect;
pub mod ring;
pub mod stroked_bezier;

+ 49
- 7
core/src/geometry/ring.rs View File

@@ -31,10 +31,19 @@ pub fn render(
tessellation: usize,
uvm: &UvMapping,
) -> Result<()> {
ring_segment(render_list, matrix, position, inner_radius, outer_radius, inner_colour, outer_colour, tessellation, uvm)
ring_segment(
render_list,
matrix,
position,
inner_radius,
outer_radius,
inner_colour,
outer_colour,
tessellation,
uvm,
)
}


fn ring_segment(
render_list: &mut RenderList,
matrix: &Matrix,
@@ -48,7 +57,12 @@ fn ring_segment(
) -> Result<()> {
let unit_angle = TAU / tessellation as f32;

render_list.prepare_to_add_triangle_strip(matrix, (tessellation * 2) + 2, position.0, position.1 + inner_radius)?;
render_list.prepare_to_add_triangle_strip(
matrix,
(tessellation * 2) + 2,
position.0,
position.1 + inner_radius,
)?;

let rp = render_list
.render_packets
@@ -64,8 +78,22 @@ fn ring_segment(
let outervx = (angle.sin() * outer_radius) + position.0;
let outervy = (angle.cos() * outer_radius) + position.1;

rpg.add_vertex(matrix, innervx, innervy, inner_colour, uvm.map[4], uvm.map[5]);
rpg.add_vertex(matrix, outervx, outervy, outer_colour, uvm.map[4], uvm.map[5]);
rpg.add_vertex(
matrix,
innervx,
innervy,
inner_colour,
uvm.map[4],
uvm.map[5],
);
rpg.add_vertex(
matrix,
outervx,
outervy,
outer_colour,
uvm.map[4],
uvm.map[5],
);
}

let angle: f32 = TAU;
@@ -75,8 +103,22 @@ fn ring_segment(
let outervx = (angle.sin() * outer_radius) + position.0;
let outervy = (angle.cos() * outer_radius) + position.1;

rpg.add_vertex(matrix, innervx, innervy, inner_colour, uvm.map[4], uvm.map[5]);
rpg.add_vertex(matrix, outervx, outervy, outer_colour, uvm.map[4], uvm.map[5]);
rpg.add_vertex(
matrix,
innervx,
innervy,
inner_colour,
uvm.map[4],
uvm.map[5],
);
rpg.add_vertex(
matrix,
outervx,
outervy,
outer_colour,
uvm.map[4],
uvm.map[5],
);

Ok(())
}

+ 48
- 29
core/src/interp.rs View File

@@ -152,86 +152,105 @@ mod tests {

#[test]
fn test_interp_cos() {
is_debug_str(
probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/cos t: (/ x 5))))",
"1 0.9800666 0.921061 0.8253356 0.6967067 0.5403023",
[1.0, 0.9800666, 0.921061, 0.8253356, 0.6967067, 0.5403023].to_vec(),
);
is_debug_str(

probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/cos t: (/ x 5))))",
[1.0, 0.9800666, 0.921061, 0.8253356, 0.6967067, 0.5403023].to_vec(),
);
probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/cos amplitude: 3 t: (/ x 5))))",
"3 2.9401999 2.7631829 2.476007 2.09012 1.6209068",
[3.0, 2.9401999, 2.7631829, 2.476007, 2.09012, 1.6209068].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/cos frequency: 7 t: (/ x 5))))",
"1 0.16996716 -0.9422223 -0.49026057 0.7755658 0.75390226",
[
1.0,
0.16996716,
-0.9422223,
-0.49026057,
0.7755658,
0.75390226,
]
.to_vec(),
);
}

#[test]
fn test_interp_sin() {
is_debug_str(
probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/sin t: (/ x 5))))",
"0 0.19866933 0.38941833 0.5646425 0.7173561 0.84147096",
[
0.0, 0.19866933, 0.38941833, 0.5646425, 0.7173561, 0.84147096,
]
.to_vec(),
);
is_debug_str(
probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/sin amplitude: 3 t: (/ x 5))))",
"0 0.596008 1.168255 1.6939275 2.1520681 2.5244129",
[0.0, 0.596008, 1.168255, 1.6939275, 2.1520681, 2.5244129].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(loop (x upto: 5)
(probe scalar: (interp/sin frequency: 7 t: (/ x 5))))",
"0 0.98544973 0.3349882 -0.8715759 -0.6312667 0.6569866",
[
0.0, 0.98544973, 0.3349882, -0.8715759, -0.6312667, 0.6569866,
]
.to_vec(),
);
}

#[test]
fn test_interp_build() {
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [0 1] to: [0 100]))
(probe scalar: (interp/value from: i t: 0.5))",
"50",
[50.0].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [10 20] to: [50 200]))
(probe scalar: (interp/value from: i t: 10.0))",
"50",
[50.0].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [10 20] to: [50 200]))
(probe scalar: (interp/value from: i t: 20.0))",
"200",
[200.0].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [50 10] to: [100 1000]))
(probe scalar: (interp/value from: i t: 50.0))",
"100",
[100.0].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [50 10] to: [100 1000]))
(probe scalar: (interp/value from: i t: 10.0))",
"1000",
[1000.0].to_vec(),
);

// clamping
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [0 1] to: [0 100] clamping: false))
(probe scalar: (interp/value from: i t: 2.0))",
"200",
[200.0].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [0 1] to: [0 100] clamping: true))
(probe scalar: (interp/value from: i t: 2.0))",
"100",
[100.0].to_vec(),
);
is_debug_str(
probe_has_scalars(
"(define i (interp/build from: [0 1] to: [0 100] clamping: true))
(probe scalar: (interp/value from: i t: -2.0))",
"0",
[0.0].to_vec(),
);
}

}

+ 1
- 1
core/src/keywords.rs View File

@@ -469,7 +469,7 @@ mod tests {

#[test]
fn test_keyword_pack() {
let mut res: String = "".to_string();
let mut res: String = "".into();
Keyword::Volatility.pack(&mut res).unwrap();
assert_eq!("volatility", res);
}

+ 2
- 2
core/src/lib.rs View File

@@ -73,7 +73,7 @@ pub use crate::gene::{next_generation, Genotype};
pub use crate::packable::Packable;
pub use crate::parser::{parse, WordLut};
pub use crate::program::Program;
pub use crate::render_list::{RenderList, RPCommand};
pub use crate::render_list::{RPCommand, RenderList};
pub use crate::render_packet::{
RenderPacket, RenderPacketGeometry, RenderPacketImage, RenderPacketMask,
};
@@ -174,7 +174,7 @@ pub mod tests {

assert_eq!(1, context.render_list.get_num_render_packets() as i32);

let geo = context.get_render_packet_geometry(0).unwrap();
let geo = context.get_rp_geometry(0).unwrap();
let num_floats = geo.get_geo_len();
let floats_per_vert = 8;
assert_eq!(expected_num_verts, num_floats / floats_per_vert);

+ 8
- 9
core/src/native.rs View File

@@ -773,19 +773,19 @@ fn probe_execute(vm: &mut Vm, context: &mut Context) -> Result<Option<Var>> {

if is_arg_given(default_mask, 1) {
let scalar: f32 = vm.stack_peek(1)?;
vm.debug_str_append(&format!("{}", scalar));
vm.probe_scalar(scalar);
}

if is_arg_given(default_mask, 2) {
let (x, y): (f32, f32) = vm.stack_peek(2)?;
vm.debug_str_append(&format!("({},{})", x, y));
vm.probe_scalar_v2(x, y)
}

if is_arg_given(default_mask, 3) {
let (x, y): (f32, f32) = vm.stack_peek(3)?;
if let Some(matrix) = context.matrix_stack.peek() {
let (nx, ny) = matrix.transform_vec2(x, y);
vm.debug_str_append(&format!("({},{})", nx, ny));
vm.probe_scalar_v2(nx, ny)
}
}

@@ -3678,10 +3678,10 @@ mod tests {

#[test]
fn test_probe() {
is_debug_str("(probe scalar: 0.4)", "0.4");
is_debug_str(
probe_has_scalars("(probe scalar: 0.4)", [0.4].to_vec());
probe_has_scalars(
"(probe scalar: 0.4) (probe scalar: 0.7) (probe scalar: 0.9)",
"0.4 0.7 0.9",
[0.4, 0.7, 0.9].to_vec(),
);
}

@@ -3709,10 +3709,10 @@ mod tests {

#[test]
pub fn bug_nth() {
is_debug_str(
probe_has_scalars(
"(define vs [5 6 7])
(probe scalar: (nth from: vs n: 0))",
"5",
[5.0].to_vec(),
);
}

@@ -3750,5 +3750,4 @@ mod tests {
is_float("(math/clamp from: 1 min: 2 max: 5)", 2.0);
is_float("(math/clamp from: 8 min: 2 max: 5)", 5.0);
}

}

+ 57
- 14
core/src/path.rs View File

@@ -162,7 +162,7 @@ mod tests {

#[test]
fn test_invocations() {
is_debug_str(
probe_has_scalars(
"(fn (point position: [500 500]
n: 1
t: 0.2)
@@ -171,13 +171,13 @@ mod tests {
to: [50 50]
fn: (address-of point)
steps: 5)",
"0 1 2 3 4",
[0.0, 1.0, 2.0, 3.0, 4.0].to_vec(),
);
}

#[test]
fn test_linear() {
is_debug_str(
probe_has_scalars(
"(fn (point position: [500 500]
n: 1
t: 0.2)
@@ -186,10 +186,10 @@ mod tests {
to: [50 50]
fn: (address-of point)
steps: 5)",
"0 0.25 0.5 0.75 1",
[0.0, 0.25, 0.5, 0.75, 1.0].to_vec(),
);

is_debug_str(
probe_has_scalars(
"(fn (point position: [500 500]
n: 1
t: 0.2)
@@ -199,10 +199,10 @@ mod tests {
fn: (address-of point)
mapping: ease/quick
steps: 5)",
"0 0.15625 0.5 0.84375 1",
[0.0, 0.15625, 0.5, 0.84375, 1.0].to_vec(),
);

is_debug_str(
probe_has_scalars_v2(
"(fn (point position: [500 500]
n: 1
t: 0.2)
@@ -211,13 +211,21 @@ mod tests {
to: [50 50]
fn: (address-of point)
steps: 5)",
"(10,10) (20,20) (30,30) (40,40) (50,50)",
[
(10.0, 10.0),
(20.0, 20.0),
(30.0, 30.0),
(40.0, 40.0),
(50.0, 50.0),
]
.to_vec(),
);
}

#[test]
fn test_circular() {
is_debug_str("(fn (point position: [500 500]
probe_has_scalars_v2(
"(fn (point position: [500 500]
n: 1
t: 0.2)
(probe vector: position))
@@ -225,30 +233,65 @@ mod tests {
radius: 100
fn: (address-of point)
steps: 8)",
"(0,100) (70.71068,70.71068) (100,-0.000004371139) (70.71068,-70.71068) (-0.000008742278,-100) (-70.710686,-70.71066) (-100,0.0000011924881) (-70.710655,70.7107)");
[
(0.0, 100.0),
(70.71068, 70.71068),
(100.0, -0.000004371139),
(70.71068, -70.71068),
(-0.000008742278, -100.0),
(-70.710686, -70.71066),
(-100.0, 0.0000011924881),
(-70.710655, 70.7107),
]
.to_vec(),
);
}

#[test]
fn test_spline() {
is_debug_str("(fn (point position: [500 500]
probe_has_scalars_v2(
"(fn (point position: [500 500]
n: 1
t: 0.2)
(probe vector: position))
(path/spline coords: [[100 500] [300 500] [500 500]]
fn: (address-of point)
steps: 8)",
"(100,500) (157.14285,500) (214.28572,500) (271.4286,500) (328.57144,500) (385.7143,500) (442.85718,500) (500,500)");
[
(100.0, 500.0),
(157.14285, 500.0),
(214.28572, 500.0),
(271.4286, 500.0),
(328.57144, 500.0),
(385.7143, 500.0),
(442.85718, 500.0),
(500.0, 500.0),
]
.to_vec(),
);
}

#[test]
fn test_bezier() {
is_debug_str("(fn (point position: [500 500]
probe_has_scalars_v2(
"(fn (point position: [500 500]
n: 1
t: 0.2)
(probe vector: position))
(path/bezier coords: [[100 500] [300 300] [500 800] [700 500]]
fn: (address-of point)
steps: 8)",
"(100,500) (185.71431,452.76974) (271.42862,465.01465) (357.14288,510.49567) (442.85718,562.97375) (528.5714,596.2099) (614.28577,583.965) (700,500)");
[
(100.0, 500.0),
(185.71431, 452.76974),
(271.42862, 465.01465),
(357.14288, 510.49567),
(442.85718, 562.97375),
(528.5714, 596.2099),
(614.28577, 583.965),
(700.0, 500.0),
]
.to_vec(),
);
}
}

+ 21
- 6
core/src/prng.rs View File

@@ -234,7 +234,7 @@ pub mod tests {

#[test]
pub fn test_prng_value() {
is_debug_str(
probe_has_scalars(
"(define p (prng/build seed: 5 min: 0 max: 1))
(probe scalar: (prng/value from: p))
(probe scalar: (prng/value from: p))
@@ -245,13 +245,24 @@ pub mod tests {
(probe scalar: (prng/value from: p))
(probe scalar: (prng/value from: p))
(probe scalar: (prng/value from: p))",
"0.16439326 0.58795106 0.12325332 0.039127756 0.9678266 0.8247009 0.787962 0.13722154 0.94319534",
[
0.16439326,
0.58795106,
0.12325332,
0.039127756,
0.9678266,
0.8247009,
0.787962,
0.13722154,
0.94319534,
]
.to_vec(),
);
}

#[test]
pub fn test_prng_value2() {
is_debug_str(
probe_has_scalars(
"(define p (prng/build seed: 5938 min: 3 max: 9))
(probe scalar: (prng/value from: p))
(probe scalar: (prng/value from: p))
@@ -262,19 +273,23 @@ pub mod tests {
(probe scalar: (prng/value from: p))
(probe scalar: (prng/value from: p))
(probe scalar: (prng/value from: p))",
"7.696081 6.462363 6.579473 4.650559 5.4763083 4.6319327 8.11852 6.7570615 5.3803825",
[
7.696081, 6.462363, 6.579473, 4.650559, 5.4763083, 4.6319327, 8.11852, 6.7570615,
5.3803825,
]
.to_vec(),
);
}

#[test]
pub fn test_prng_values() {
is_debug_str(
probe_has_scalars(
"(define p (prng/build seed: 5 min: 0 max: 1))
(define vs (prng/values from: p num: 3))
(probe scalar: (nth from: vs n: 0))
(probe scalar: (nth from: vs n: 1))
(probe scalar: (nth from: vs n: 2))",
"0.16439326 0.58795106 0.12325332",
[0.16439326, 0.58795106, 0.12325332].to_vec(),
);
}


+ 1
- 1
core/src/render_list.rs View File

@@ -160,7 +160,7 @@ impl RenderList {
_ => {
self.render_packets
.push(RenderPacket::Geometry(RenderPacketGeometry::new()));
return Ok(());
Ok(())
}
}
}

+ 2
- 0
core/src/render_packet.rs View File

@@ -22,10 +22,12 @@ pub const RENDER_PACKET_FLOAT_PER_VERTEX: usize = 8;
// 262144 * 4 == 1MB per render packet
// 262144 / 8 == 32768 vertices per render packet

#[derive(Default)]
pub struct RenderPacketGeometry {
pub geo: Vec<f32>,
}

#[derive(Default)]
pub struct RenderPacketMask {
pub filename: String,
pub invert: bool,

+ 45
- 22
core/src/repeat.rs View File

@@ -198,88 +198,111 @@ mod tests {

#[test]
fn test_symmetry_vertical() {
is_debug_str(
probe_has_scalars_v2(
"(fn (f) (probe worldspace: [20 20]))
(repeat/symmetry-vertical fn: (address-of f))",
"(20,20) (-20,20)",
[(20.0, 20.0), (-20.0, 20.0)].to_vec(),
);
}

#[test]
fn test_symmetry_horizontal() {
is_debug_str(
probe_has_scalars_v2(
"(fn (f) (probe worldspace: [20 20]))
(repeat/symmetry-horizontal fn: (address-of f))",
"(20,20) (20,-20)",
[(20.0, 20.0), (20.0, -20.0)].to_vec(),
);
}

#[test]
fn test_symmetry_4() {
is_debug_str(
probe_has_scalars_v2(
"(fn (f) (probe worldspace: [10 20]))
(repeat/symmetry-4 fn: (address-of f))",
"(10,20) (-10,20) (10,-20) (-10,-20)",
[(10.0, 20.0), (-10.0, 20.0), (10.0, -20.0), (-10.0, -20.0)].to_vec(),
);
}

#[test]
fn test_symmetry_8() {
is_debug_str(
probe_has_scalars_v2(
"(fn (f) (probe worldspace: [10 20]))
(repeat/symmetry-8 fn: (address-of f))",
"(10,20) (-10,20) (10,-20) (-10,-20) (-20,9.999999) (-20,-10.000001) (20,10.000001) (20,-9.999999)",
[
(10.0, 20.0),
(-10.0, 20.0),
(10.0, -20.0),
(-10.0, -20.0),
(-20.0, 9.999999),
(-20.0, -10.000001),
(20.0, 10.000001),
(20.0, -9.999999),
]
.to_vec(),
);
}

#[test]
fn shabba_test_rotate() {
is_debug_str(
probe_has_scalars(
"(fn (f angle: 0 copy: 0) (probe scalar: angle))
(repeat/rotate fn: (address-of f) copies: 3)",
"0 120 240",
[0.0, 120.0, 240.0].to_vec(),
);
}

#[test]
fn test_rotate() {
is_debug_str(
probe_has_scalars(
"(fn (f angle: 0 copy: 0) (probe scalar: angle))
(repeat/rotate fn: (address-of f) copies: 3)",
"0 120 240",
[0.0, 120.0, 240.0].to_vec(),
);

is_debug_str(
probe_has_scalars(
"(fn (f angle: 0 copy: 0) (probe scalar: copy))
(repeat/rotate fn: (address-of f) copies: 3)",
"0 1 2",
[0.0, 1.0, 2.0].to_vec(),
);

is_debug_str(
probe_has_scalars_v2(
"(fn (f) (probe worldspace: [0 1]))
(repeat/rotate fn: (address-of f) copies: 3)",
"(0,1) (-0.8660254,-0.50000006) (0.86602545,-0.4999999)",
[
(0.0, 1.0),
(-0.8660254, -0.50000006),
(0.86602545, -0.4999999),
]
.to_vec(),
);
}

#[test]
fn test_rotate_mirrored() {
is_debug_str(
probe_has_scalars(
"(fn (f angle: 0 copy: 0) (probe scalar: angle))
(repeat/rotate-mirrored fn: (address-of f) copies: 3)",
"0 120 240 0 -120 -240",
[0.0, 120.0, 240.0, 0.0, -120.0, -240.0].to_vec(),
);

is_debug_str(
probe_has_scalars(
"(fn (f angle: 0 copy: 0) (probe scalar: copy))
(repeat/rotate-mirrored fn: (address-of f) copies: 3)",
"0 1 2 3 4 5",
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0].to_vec(),
);

is_debug_str(
probe_has_scalars_v2(
"(fn (f) (probe worldspace: [0 1]))
(repeat/rotate-mirrored fn: (address-of f) copies: 3)",
"(0,1) (-0.8660254,-0.50000006) (0.86602545,-0.4999999) (0,1) (0.8660254,-0.50000006) (-0.86602545,-0.4999999)",
[
(0.0, 1.0),
(-0.8660254, -0.50000006),
(0.86602545, -0.4999999),
(0.0, 1.0),
(0.8660254, -0.50000006),
(-0.86602545, -0.4999999),
]
.to_vec(),
);
}
}

+ 91
- 13
core/src/vm.rs View File

@@ -203,6 +203,50 @@ impl Var {
}
}

pub struct ProbeSample {
/// frame pointer
pub fp: usize,
/// stack pointer (points to the next free stack index)
pub sp: usize,
/// instruction pointer
pub ip: usize,

pub scalar: Option<f32>,
pub scalar_v2: Option<(f32, f32)>,
}

impl ProbeSample {
pub fn new(vm: &Vm) -> ProbeSample {
ProbeSample {
fp: vm.fp,
sp: vm.sp,
ip: vm.ip,
scalar: None,
scalar_v2: None,
}
}

pub fn new_scalar(vm: &Vm, scalar: f32) -> ProbeSample {
ProbeSample {
fp: vm.fp,
sp: vm.sp,
ip: vm.ip,
scalar: Some(scalar),
scalar_v2: None,
}
}

pub fn new_scalar_v2(vm: &Vm, scalar_v2: (f32, f32)) -> ProbeSample {
ProbeSample {
fp: vm.fp,
sp: vm.sp,
ip: vm.ip,
scalar: None,
scalar_v2: Some(scalar_v2),
}
}
}

pub struct Vm {
/// only used when evaluating bracket bindings
pub prng_state: PrngStateStruct,
@@ -228,7 +272,8 @@ pub struct Vm {
pub building_with_trait_within_vector: bool,
pub trait_within_vector_index: usize,

pub debug_str: String,
/// used during testing
pub probe_samples: Vec<ProbeSample>,
}

impl Default for Vm {
@@ -276,7 +321,7 @@ impl Default for Vm {
building_with_trait_within_vector: false,
trait_within_vector_index: 0,

debug_str: "".to_string(),
probe_samples: vec![],
}
}
}
@@ -301,15 +346,18 @@ fn bytecode_arg_to_var(bytecode_arg: &BytecodeArg) -> Result<Var> {
}

impl Vm {
pub fn debug_str_clear(&mut self) {
self.debug_str = "".to_string();
pub fn probe_clear(&mut self) {
self.probe_samples = vec![];
}

pub fn debug_str_append(&mut self, text: &str) {
if !self.debug_str.is_empty() {
self.debug_str += &" ".to_string();
}
self.debug_str += &text.to_string();
pub fn probe_scalar(&mut self, scalar: f32) {
let sample = ProbeSample::new_scalar(self, scalar);
self.probe_samples.push(sample);
}

pub fn probe_scalar_v2(&mut self, x: f32, y: f32) {
let sample = ProbeSample::new_scalar_v2(self, (x, y));
self.probe_samples.push(sample);
}

pub fn set_prng_state(&mut self, prng: PrngStateStruct) {
@@ -606,7 +654,6 @@ impl Vm {
// dbg!(i);
// dbg!(&self.stack[i]);
// }

}

fn opcode_native(
@@ -1533,12 +1580,43 @@ pub mod tests {
}
}

pub fn is_debug_str(s: &str, val: &str) {
pub fn probe_has_scalars(s: &str, expected_scalars: Vec<f32>) {
let mut vm: Vm = Default::default();
let mut context: Context = Default::default();

vm_exec(&mut vm, &mut context, s);

for (i, sample) in vm.probe_samples.iter().enumerate() {
if let Some(scalar) = sample.scalar {
assert_eq!(scalar, expected_scalars[i], "mismatch at index {}", i);
} else {
assert!(false, "expected a scalar in the sample");
}
}
}

pub fn probe_has_scalars_v2(s: &str, expected_scalars_v2: Vec<(f32, f32)>) {
let mut vm: Vm = Default::default();
let mut context: Context = Default::default();

vm_exec(&mut vm, &mut context, s);
assert_eq!(vm.debug_str, val);

for (i, sample) in vm.probe_samples.iter().enumerate() {
if let Some(scalar_v2) = sample.scalar_v2 {
assert_eq!(
scalar_v2.0, expected_scalars_v2[i].0,
"mismatch for 0 element at index {}",
i
);
assert_eq!(
scalar_v2.1, expected_scalars_v2[i].1,
"mismatch for 1 element at index {}",
i
);
} else {
assert!(false, "expected a scalar in the sample");
}
}
}

#[test]
@@ -1984,7 +2062,7 @@ pub mod tests {
}

fn pack_compare(var: Var, expected: &str) {
let mut res: String = "".to_string();
let mut res: String = "".into();
var.pack(&mut res).unwrap();
assert_eq!(expected, res);
}

+ 8
- 0
server/seni/sketch/1938-testing.seni View File

@@ -0,0 +1,8 @@

(mask/set from: "mask/skull-c.png")
;(mask/set from: "mask/horizontal-linear.png")

(rect position: [(/ canvas/width 2) (/ canvas/height 2)]
width: (* canvas/width 0.9)
height: (* canvas/height 0.9)
colour: red)

+ 44
- 0
server/seni/sketch/1941-bug.seni View File

@@ -0,0 +1,44 @@

;; false if statement, effects on stack?


(define
col-fn-1 (col/build-procedural a: [0.977 0.416 0.171] ~ (gen/scalar)
b: [0.846 0.460 0.596] ~ (gen/scalar)
c: [0.667 0.176 0.706] ~ (gen/scalar)
d: [0.148 0.675 0.572] ~ (gen/scalar)
alpha: 0.08)
)

(fn (dummy-bg position: [500 500]
colour: red
seed: 343
radius: 300)
(rect position: position
width: radius
height: radius
colour: colour))

(fn (bg3)
(define
focalpoint (focal/build-point position: [430 ~ (gen/int max: canvas/width)
533 ~ (gen/int max: canvas/height)]
distance: 651 ~ (gen/int min: (/ canvas/width 2) max: canvas/width)))
(loop (i from: 1 to: 400)
(define ; has to be here
theta (/ (* i math/TAU) 0.1)
; replacing focalpoint stuff with a constant also fucks up, but differently
c1 (col-fn-1.col/value t: (focalpoint.focal/value position: [10 10]))
)

(if (> -22 -10) ;; has to be false
(dummy-bg position: [0 0]
radius: 1
colour: red
seed: i)
)
(probe overlap: 1.0)
)
)

(bg3)

+ 12
- 0
server/seni/sketch/1941-bug2.seni View File

@@ -0,0 +1,12 @@
;; client.js:460 Mem::Local (hopback): fp is not Var::Int?
;; client.js:460 seni core: VM

(fn (dummy-bg radius: 300)
(+ 1 1))

(loop (i from: 1 to: 10)
(if (> -22 -10) ;; has to be false
(dummy-bg radius: 1)
)
(probe overlap: 1.0)
)

+ 11
- 0
server/seni/sketch/1941-bug3.seni View File

@@ -0,0 +1,11 @@

(fn (dummy-bg radius: 300)
(+ 1 1))

(fn (bg3)
(loop (i from: 1 to: 400)
(if (> -22 -10) ;; has to be false
(dummy-bg radius: 1))
(probe overlap: 1.0)))

(bg3)

+ 203
- 0
server/seni/sketch/1941-vhs.seni View File

@@ -0,0 +1,203 @@
(image linear-colour-space: 1)

(define
initial-seed (prng/range seed: 384 ~ (gen/int max: 1000))
coords1 [[304.553 -275.573] [-71.354 -384.054] [196.137 -37.219] [-158.737 279.845]] ~ (gen/2d min: -500 max: 500)
coords2 [[-188.668 -221.156] [133.438 7.501] [-389.312 47.671] [-251.040 -450.217]] ~ (gen/2d min: -500 max: 500)
coords3 [[104.872 -115.458] [-201.240 401.424] [57.271 293.906] [-140.606 -252.564]] ~ (gen/2d min: -500 max: 500)
col-fn-1 (col/build-procedural a: [0.977 0.416 0.171] ~ (gen/scalar)
b: [0.846 0.460 0.596] ~ (gen/scalar)
c: [0.667 0.176 0.706] ~ (gen/scalar)
d: [0.148 0.675 0.572] ~ (gen/scalar)
alpha: 0.08)
col-fn-2 (col/build-procedural a: [0.945 0.574 0.681] ~ (gen/scalar)
b: [0.565 0.806 0.712] ~ (gen/scalar)
c: [0.260 0.205 0.216] ~ (gen/scalar)
d: [0.940 0.123 0.942] ~ (gen/scalar)
alpha: 0.08))

(fn (wash vol: 200
line-width: 70
line-segments: 5
colour: (col/rgb r: 0.627 g: 0.627 b: 0.627 alpha: 0.4)
seed: 272)
(define
w/3 (/ canvas/width 3)
h/3 (/ canvas/height 3))
(loop (d from: -20 to: 1020 inc: 20)
(bezier tessellation: line-segments
line-width: line-width
coords: [[0 (wash-n x: 0 d: d seed: seed vol: vol)]
[w/3 (wash-n x: w/3 d: d seed: seed vol: vol)]
[(* w/3 2) (wash-n x: (* w/3 2) d: d seed: seed vol: vol)]
[canvas/width (wash-n x: canvas/width d: d seed: seed vol: vol)]]
colour: colour)

(bezier tessellation: line-segments
line-width: line-width
coords: [[(wash-n x: 0 d: d seed: seed vol: vol) 0]
[(wash-n x: h/3 d: d seed: seed vol: vol) h/3]
[(wash-n x: (* h/3 2) d: d seed: seed vol: vol) (* h/3 2)]
[(wash-n x: canvas/height d: d seed: seed vol: vol) canvas/height]]
colour: colour)))

(fn (wash-n x: 0 d: 0 seed: 0 vol: 1)
(+ d (* vol (prng/perlin x: x y: d z: seed))))


(fn (interesting-circle position: [500 500]
colour: red
seed: 343
radius: 300)
(define
rng (prng/build seed: seed)
outer-exterior (prng/build seed: (rng.prng/value) min: 170 max: 210)
outer-interior (prng/build seed: (rng.prng/value) min: 80 max: 170)
inner-exterior (prng/build seed: (rng.prng/value) min: 100 max: 150)
inner-interior (prng/build seed: (rng.prng/value) min: 0 max: 100)
srng (prng/build min: -1 max: 1 seed: seed))

(on-matrix-stack
(translate vector: position)
(scale scalar: (/ radius 210))
(loop (i to: 8)
(on-matrix-stack
(rotate angle: (* 360 (rng.prng/value)))
;; outer ring
(circle-slice tessellation: 30
position: [0 0]
colour: (col/lighten from: colour
value: (* 85 ~ (gen/int min: 20 max: 600) (srng.prng/value)))
angle-start: 0
angle-end: 320
width: (outer-exterior.prng/value)
inner-width: (outer-interior.prng/value)
height: (outer-exterior.prng/value)
inner-height: (outer-interior.prng/value))
;; inner ring
(circle-slice tessellation: 10
position: [0 0]
colour: (col/lighten from: colour
value: (* 54 ~ (gen/int min: 10 max: 400) (srng.prng/value)))
angle-start: 0
angle-end: 320
width: (inner-exterior.prng/value)
inner-width: (inner-interior.prng/value)
height: (inner-exterior.prng/value)
inner-height: (inner-interior.prng/value))))
;; centre fill
(circle-slice tessellation: 10
position: [0 0]
colour: (col/lighten from: colour
value: (* 66 ~ (gen/int min: 5 max: 200) (srng.prng/value)))
angle-start: 0
angle-end: 360
radius: 30)))

(fn (flowery)
(loop (t from: 0 upto: 1 steps: 200)
(poly coords: [(interp/bezier t: t coords: coords1)
(interp/bezier t: t coords: coords2)
(interp/bezier t: t coords: coords3)]
colours: [(col-fn-1.col/value t: t)
(col-fn-2.col/value t: (- 1 t))
(col-fn-1.col/value t: t)])))

(fn (fg1)
(on-matrix-stack
(translate vector: [(/ canvas/width 2) 0])
(scale scalar: 1.587 ~ (gen/scalar min: 1.2 max: 1.7))
(rotate angle: 190 ~ (gen/int max: 360))
(repeat/rotate-mirrored fn: (address-of flowery)
copies: 8 ~ (gen/int min: 1 max: 10))))


(fn (bg2)
(define
seed-radius 7.055 ~ (gen/scalar min: 6 max: 8)
scale-factor 4
phi 0.1;(/ (sqrt 5.428 ~ (gen/scalar min: 4 max: 6)) 8.036 ~ (gen/scalar min: 8 max: 10))
seeds 200
focalpoint (focal/build-point ~ (gen/select from: ['focal/build-point 'focal/build-hline 'focal/build-vline])
position: [430 ~ (gen/int max: canvas/width)
533 ~ (gen/int max: canvas/height)]
distance: 651 ~ (gen/int min: (/ canvas/width 2) max: canvas/width)))
(on-matrix-stack
(translate vector: [500 0])
(scale scalar: 20)
(loop (i from: seeds to: 0)
(define
theta (/ (* i math/TAU) phi)
r (* scale-factor ;(sqrt i)
)
position [(* r (math/cos from: theta))
(* r (math/sin from: theta))]
colour (col/set-alpha from: (col-fn-1.col/value t: (focalpoint position: position))
value: 0.4))
;; don't render some of the offscreen circles
(if (> (position.get-y)
;(vector/get from: position nth: 1)
-10)
(interesting-circle position: position
radius: seed-radius
colour: colour
seed: i)))))

(fn (bg3)
(define
seed-radius 7.055 ~ (gen/scalar min: 6 max: 8)
scale-factor 4
;phi (/ 2.3298 8.036)
phi (/ (sqrt 5.428 ~ (gen/scalar min: 4 max: 6)) 8.036 ~ (gen/scalar min: 8 max: 10))
seeds 200
focalpoint (focal/build-point ~ (gen/select from: ['focal/build-point 'focal/build-hline 'focal/build-vline])
position: [430 ~ (gen/int max: canvas/width)
533 ~ (gen/int max: canvas/height)]
distance: 651 ~ (gen/int min: (/ canvas/width 2) max: canvas/width)))


(on-matrix-stack
(translate vector: [500 0])
(scale scalar: 20)

(loop (i from: 1 to: seeds)
(define
theta (/ (* i math/TAU) phi)
r (* scale-factor (sqrt i)
)
position [(* r (math/cos from: theta))
(* r (math/sin from: theta))]
c1 (col-fn-1.col/value t: (focalpoint.focal/value position: position))
colour (col/set-alpha from: c1
value: 0.1)
)

;; don't render some of the offscreen circles
(if (> (position.get-y) -10)

(rect position: position
width: seed-radius
height: seed-radius
colour: colour)

; (interesting-circle position: position
; radius: seed-radius
; colour: colour
; seed: i)
)
))
)

;(wash colour: (col-fn-1.col/value t: 0.1))
(bg3)
(fg1)

;; (rect position: [500 500]
;; width: 300
;; height: 300
;; colour: green)

;; (interesting-circle position: [300 300]
;; colour: blue
;; seed: 654
;; radius: 300)

Loading…
Cancel
Save