Loading...
Searching...
No Matches
BytebeatCodegen.hpp
1#pragma once
2#include <string>
3#include <string_view>
4
5#include <score_plugin_jit_export.h>
6
7namespace Jit::Bytebeat
8{
9// How the formula is evaluated.
10// JavaScript: what the web players (dollchan, greggman) run: every value is a
11// double, bitwise operators go through ToInt32, Math is available without prefix.
12// C: viznut's original `int t; putchar(EXPR)`: 32-bit integers, wrapping.
13enum class Language : int
14{
15 JavaScript = 0,
16 C = 1
17};
18
19// How the value returned by the formula becomes a sample.
20enum class OutputMode : int
21{
22 Bytebeat = 0, // (v & 255) is an unsigned 8-bit sample
23 SignedBytebeat = 1, // (v & 255) is a signed 8-bit sample
24 Floatbeat = 2 // v is a sample in [-1, 1]
25};
26
27// Entry point of the compiled program.
28// Fills `frames` samples of `left` and `right`, evaluating the formula once per
29// distinct value in `t`. `state` is a zero-initialized buffer of the size the
30// function returns when called with a null state; it holds the variables of the
31// formula, which persist from one sample to the next as in the JS players.
32using Function = int(
33 void* state, double* left, double* right, const double* t, int frames, int mode);
34inline constexpr const char* function_name = "score_bytebeat";
35
37{
38 std::string code;
39 std::string error;
40 int error_line{-1};
41 int formulas{};
42};
43
44// One formula per line: several lines are mixed together.
45// A line continues the previous formula when its brackets are not balanced, or
46// when it starts or the previous one ends with a binary operator.
47SCORE_PLUGIN_JIT_EXPORT
48Generated generate(std::string_view source, Language lang);
49}
Definition BytebeatCodegen.hpp:37