ossia / score

ossia score, an interactive sequencer for the intermedia arts
https://ossia.io
Other
1.52k stars 104 forks source link

Dividing / modulo by zero in bytebeat crashes #1344

Open jcelerier opened 2 years ago

jcelerier commented 2 years ago

Idea: having a struc instead of t which reimplements the operators and replaces division by zero by zero

dtee1 commented 2 years ago

I'm interested

jcelerier commented 2 years ago

hi and welcome @dtee1 ! My recommendation for this would be to try to make a self-contained header-only library which is able to execute bytebeat expressions correctly.

Here are some test cases: (one per line)

(((t & t>>8)-(t>>13&t))&((t & t>>8)-(t>>13)))^(t>>8&t) 

t<<((t>>8&t)|(t>>14&t))

t/(t%(t>>8|t>>16)) 

(t<<(t/(t>>8&t))) 

t<<((t>>1|t>>8)^(t>>13)) 

t<<((t>>1|t>>8)*(t>>13&t>>12)) 

t<<(t>>8&(t/(t>>10&t))) 

(t>>8&t>>16)*t>>4 

(t & (t>>15+(t>>8&t)))*t

the idea would be that t instead of being int, would be some struct type with all the operators reimplemented so that dividing by 0 or calling % 0 does not fail like it does currently.

A "fun" alternative would be to try and reimplement a bytebeat interpreter with boost.metaparse ? this would allow to copy-paste JS functions directly, e.g. Math.sin instead of std::sin.