diff --git a/.gitignore b/.gitignore index 54f3f1a5..7c057efa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,16 @@ elm-stuff -.cache +.parcel-cache node_modules /dist +/src/optimized.js +generated + # Ignore Yarn caches .yarn/* +!.yarn/patches !.yarn/releases !.yarn/plugins +!.yarn/sdks +!.yarn/versions .pnp.* diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6756131f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "elmLS.elmFormatPath": "elm-format-hack", + "cSpell.words": ["Glsl", "sqrts"] +} diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b63ab6f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +ELM_FILES = $(wildcard src/**/*.elm) +CODEGEN_FILES = $(wildcard codegen/*.elm) + +.PHONY: build +build: generated/Glsl/Functions/NuPlot.elm src/optimized.js Makefile + parcel build src/index.html --public-url . + +src/optimized.js: $(ELM_FILES) Makefile + yarn elm-optimize-level-2 src/elm/UI.elm --output $@ + +generated/Glsl/Functions/NuPlot.elm: codegen/functions.frag codegen/src/Generate.elm codegen/bindings/Gen/Glsl.elm Makefile + rm -rf generated + yarn elm-pages run codegen/src/Generate.elm + elm-format --yes generated + +codegen/bindings/Gen/Glsl.elm: codegen/elm.codegen.json Makefile + rm -rf codegen/bindings + yarn elm-codegen install + mkdir -p codegen/bindings + mv codegen/Gen codegen/bindings + + +.PHONY: clean +clean: Makefile + rm -rf .cache dist elm-stuff diff --git a/README.md b/README.md index d9adbb46..4b5444d6 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ It's a rewrite in Elm of "mePlot", which was a formerly J2ME, then Android appli It's pre-1.0, and there is much to do. -To test it, `pnpm install` and then `pnpm start`. +To test it, `yarn install` and then `yarn start`. diff --git a/TODO.md b/TODO.md index 5df5cdc4..4c0e96c5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # Todo +- https://samuelj.li/complex-function-plotter/#1%2Fz - solve `x² - 3pi x² + 3 pi² x - pi³ = 0` - Fuzzy test the solver - User functions diff --git a/codegen/.gitignore b/codegen/.gitignore new file mode 100644 index 00000000..a6ea7088 --- /dev/null +++ b/codegen/.gitignore @@ -0,0 +1 @@ +Gen diff --git a/codegen/.vscode/settings.json b/codegen/.vscode/settings.json new file mode 100644 index 00000000..0c8d6f19 --- /dev/null +++ b/codegen/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.words": ["Glsl"] +} diff --git a/codegen/elm.codegen.json b/codegen/elm.codegen.json new file mode 100644 index 00000000..c473e5bb --- /dev/null +++ b/codegen/elm.codegen.json @@ -0,0 +1,9 @@ +{ + "elm-codegen-version": "0.6.1", + "codegen-helpers": { + "packages": { + "elm/core": "1.0.5" + }, + "local": ["vendored/miniBill/elm-glsl/1.0.0/src"] + } +} diff --git a/codegen/elm.json b/codegen/elm.json new file mode 100644 index 00000000..2c4b49dc --- /dev/null +++ b/codegen/elm.json @@ -0,0 +1,65 @@ +{ + "type": "application", + "source-directories": [ + "src", + "bindings", + "../vendored/miniBill/elm-glsl/1.0.0/src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "dillonkearns/elm-pages": "10.2.1", + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0", + "elm/json": "1.1.3", + "elm/parser": "1.1.0", + "elm-community/list-extra": "8.7.0", + "elm-community/result-extra": "2.4.0", + "mdgriffith/elm-codegen": "5.2.0", + "mdgriffith/elm-ui": "1.1.8", + "pithub/elm-parser-bug-workaround": "1.0.0", + "wolfadex/elm-ansi": "3.0.0" + }, + "indirect": { + "Chadtech/elm-bool-extra": "2.4.2", + "avh4/elm-color": "1.0.0", + "danfishgold/base64-bytes": "1.1.0", + "danyx23/elm-mimetype": "4.0.1", + "dillonkearns/elm-bcp47-language-tag": "2.0.0", + "dillonkearns/elm-cli-options-parser": "3.2.0", + "dillonkearns/elm-date-or-date-time": "2.0.0", + "dillonkearns/elm-form": "3.0.1", + "elm/bytes": "1.0.8", + "elm/file": "1.0.5", + "elm/http": "2.0.0", + "elm/random": "1.0.0", + "elm/regex": "1.0.0", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.3", + "elm-community/basics-extra": "4.1.0", + "elm-community/maybe-extra": "5.3.0", + "fredcy/elm-parseint": "2.0.1", + "jluckyiv/elm-utc-date-strings": "1.0.0", + "justinmimbs/date": "4.1.0", + "miniBill/elm-codec": "2.2.0", + "miniBill/elm-unicode": "1.1.1", + "noahzgordon/elm-color-extra": "1.0.2", + "pithub/elm-parser-extra": "1.0.0", + "robinheghan/fnv1a": "1.0.0", + "robinheghan/murmur3": "1.0.0", + "rtfeldman/elm-css": "18.0.0", + "rtfeldman/elm-hex": "1.0.0", + "rtfeldman/elm-iso8601-date-strings": "1.1.4", + "stil4m/elm-syntax": "7.3.8", + "stil4m/structured-writer": "1.0.3", + "the-sett/elm-pretty-printer": "3.1.1", + "the-sett/elm-syntax-dsl": "6.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/codegen/functions.frag b/codegen/functions.frag new file mode 100644 index 00000000..3f28cd75 --- /dev/null +++ b/codegen/functions.frag @@ -0,0 +1,600 @@ +const int MAX_DEPTH = 30; +//const int MAX_DEPTH = 60; + +const int P31 = 2147483648; +const int P32M1 = 4294967295; +const float PIHALF = 1.5707963267948966; +const float PI = 3.141592653589793; +const float TWOPI = 6.283185307179586; + +// precision highp float; + +uniform float u_whiteLines; +uniform float u_completelyReal; +uniform float u_drawAxes; +uniform vec2 u_zoomCenter; +uniform float u_viewportWidth; +uniform float u_canvasWidth; +uniform float u_canvasHeight; +uniform float u_phi; +uniform float u_theta; + +/////////// +// Utils // +/////////// + +float log10(float x) { + return log(x) / log(10.0); +} + +float sinh(float x) { return 0.5 * (exp(x) - exp(-x)); } +float cosh(float x) { return 0.5 * (exp(x) + exp(-x)); } +float tanh(float x) { + if (abs(x) > 10.) + return sign(x); + float p = exp(x); + float m = exp(-x); + return (p - m) / (p + m); +} + +float round(float v) { return floor(v + 0.5); } +vec2 round(vec2 v) { return floor(v + 0.5); } +vec3 round(vec3 v) { return floor(v + 0.5); } +vec4 round(vec4 v) { return floor(v + 0.5); } + +float cbrt(float v) { return sign(v) * pow(abs(v), 1. / 3.); } + +bool between(float x, float low, float high) { return low <= x && x <= high; } + +vec2 dup(float x) { return vec2(x, x); } + +vec3 hl2rgb(float h, float l) { + vec3 rgb = clamp(abs(mod(h * 6. + vec3(0., 4., 2.), 6.) - 3.) - 1., 0., 1.); + return l + (rgb - .5) * (1. - abs(2. * l - 1.)); +} + +vec4 gnum(float f) { return vec4(f, 0, 0, 0); } + +float atanPlus(float y, float x) { + return mod(radians(360.) + atan(y, x), radians(360.)); +} + +vec2 iexpand(vec2 v) { + return v * (vec2(1., 1.) + sign(v) * vec2(-0.000001, 0.000001)); +} + +float thetaDelta(float theta) { + if (u_whiteLines < 1.) + return 100.; + float thetaSix = theta * u_whiteLines + .5; + float thetaNeigh = .05; + return abs(fract(thetaSix) - .5) / thetaNeigh; +} + +float axis(float coord, float otherCoord, float maxDelta) { + float across = 1.0 - abs(coord/maxDelta); + if(across < -12.0) + return 0.0; + float smallUnit = pow(10.0, ceil(log10(maxDelta))); + if(across < 0.0 && abs(otherCoord) < maxDelta * 2.0) + return 0.0; + float unit = across < -6.0 ? smallUnit * 100.0 : across < -0.1 ? smallUnit * 10.0 : smallUnit * 5.0; + float parallel = mod(abs(otherCoord), unit) < maxDelta ? 1.0 : 0.0; + return max(0.0, max(across, parallel)); +} + +// Shifts for the recursive algorithm +int left_shift(int i) { return i * 2; } +int left_shift_increment(int i) { return i * 2 + 1; } + +ivec2 increment(ivec2 i) { + return i.x == P32M1 ? ivec2(0, i.y + 1) : ivec2(i.x + 1, i.y); +} + +ivec2 left_shift(ivec2 i) { + return i.x >= P31 ? ivec2(2 * (i.x - P31), i.y * 2 + 1) : 2 * i; +} + +ivec2 left_shift_increment(ivec2 i) { return increment(left_shift(i)); } + +bool is_even(int i) { return i / 2 * 2 == i; } +bool is_odd(int i) { return i / 2 * 2 != i; } +bool is_even(ivec2 i) { return is_even(i.x); } + +ivec2 right_shift(ivec2 i) { + return is_odd(i.y) ? ivec2(i.x / 2 + P31, i.y / 2) : i / 2; +} + +int right_shift(int i) { return i / 2; } + +///////////// +// Complex // +///////////// + +// Constants +vec2 ci() { return vec2(0, 1); } + +vec2 cpi() { return vec2(radians(180.), 0); } + +vec2 ce() { return vec2(exp(1.), 0); } + +// Operations +vec2 cby(vec2 a, vec2 b) { + return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); +} + +vec2 cdiv(vec2 a, vec2 b) { + float k = 1. / dot(b, b); + float r = k * dot(a, b); + float i = k * (a.y * b.x - a.x * b.y); + return vec2(r, i); +} + +vec2 cln(vec2 z) { + if (z.y == 0. && z.x >= 0.) { + return vec2(log(z.x), 0); + } + float px = length(z); + float py = atan(z.y, z.x); + return vec2(log(px), py); +} + +vec2 cexp(vec2 z) { + if (z.y == 0.) { + return vec2(exp(z.x), 0); + } + return vec2(cos(z.y), sin(z.y)) * exp(z.x); +} + +vec2 cpow(vec2 w, vec2 z) { + if (w.x >= 0. && w.y == 0. && z.y == 0.) { + return vec2(pow(w.x, z.x), 0); + } + return cexp(cby(cln(w), z)); +} + +// Trig +vec2 csin(vec2 z) { + if (z.y == 0.0) { + return vec2(sin(z.x), 0); + } + return vec2(sin(z.x) * cosh(z.y), cos(z.x) * sinh(z.y)); +} + +vec2 ccos(vec2 z) { + if (z.y == 0.0) { + return vec2(cos(z.x), 0); + } + return vec2(cos(z.x) * cosh(z.y), sin(z.x) * sinh(z.y)); +} + +vec2 ctan(vec2 z) { + if (z.y == 0.0) { + return vec2(tan(z.x), 0); + } + return cdiv(csin(z), ccos(z)); +} + +vec2 csqrt(vec2 z) { + if (z.y == 0. && z.x >= 0.) { + return vec2(sqrt(z.x), 0); + } + float r = pow(dot(z, z), .25); + float t = atan(z.y, z.x) * .5; + return r * vec2(cos(t), sin(t)); +} + +vec2 casin(vec2 z) { + vec2 s = csqrt(vec2(1, 0) - cby(z, z)); + vec2 arg = s - cby(vec2(0, 1), z); + return cby(vec2(0, 1), cln(arg)); +} + +vec2 cacos(vec2 z) { return cpi() * .5 - casin(z); } + +vec2 catan(vec2 z) { + if (z.y == 0.) { + return vec2(atan(z.x), 0); + } + vec2 o = vec2(1, 0); + vec2 iz = cby(vec2(0, 1), z); + vec2 l = cdiv(o + iz, o - iz); + return -0.5 * cby(vec2(0, 1), cln(l)); +} + +vec2 catan2(vec2 y, vec2 x) { + vec2 z = vec2(x.x - y.y, x.y + y.x); + return vec2(atan(z.y, z.x), 0.); +} + +vec2 csinh(vec2 z) { return .5 * (cexp(z) - cexp(-z)); } +vec2 ccosh(vec2 z) { return .5 * (cexp(z) + cexp(-z)); } + +vec2 ctanh(vec2 z) { + vec2 p = cexp(z); + vec2 m = cexp(-z); + return cdiv(p - m, p + m); +} + +// Power and sign +vec2 cabs(vec2 z) { return vec2(length(z), 0.); } + +vec2 csign(vec2 z) { return vec2(sign(z.x), sign(z.y)); } + +vec2 ccbrt(vec2 z) { + if (z.y == 0.) { + return vec2(sign(z.x) * pow(z.x, 1. / 3.), 0); + } + float r = pow(dot(z, z), 1. / 6.); + float t = atan(z.y, z.x) / 3. + (z.x > 0. ? 0. : radians(120.)); + return r * vec2(cos(t), sin(t)); +} + +vec2 csquare(vec2 z) { return cby(z, z); } + +vec2 clog10(vec2 z) { return cln(z) / log(10.); } + +vec2 cre(vec2 z) { return vec2(z.x, 0); } +vec2 cim(vec2 z) { return vec2(z.y, 0); } + +float arg(vec2 v) { return atan(v.y, v.x); } +vec2 carg(vec2 v) { return vec2(atan(v.y, v.x), 0); } + +vec2 cpw(vec2 c, vec2 t, vec2 f) { return c.x > 0. ? t : f; } + +// Rounding +vec2 cceil(vec2 z) { return ceil(z); } +vec2 cfloor(vec2 z) { return floor(z); } +vec2 cround(vec2 z) { return floor(z + vec2(0.5, 0.5)); } + +// Comparison +vec2 cmin(vec2 l, vec2 r) { return l.x < r.x ? l : r; } +vec2 cmax(vec2 l, vec2 r) { return l.x > r.x ? l : r; } + +// Other +vec2 cmod(vec2 l, vec2 r) { return vec2(mod(l.x, r.x), 0); } + +vec2 cmbrot(vec2 x, vec2 y) { + vec2 c = x + vec2(-y.y, y.x); + float p = length(c - vec2(.25, 0)); + if (c.x <= p - 2.0 * p * p + .25 || length(c + vec2(1, 0)) <= .25) + return vec2(0, 0); + vec2 z = c; + for (int i = 0; i < 4000; i++) { + z = vec2(z.x * z.x - z.y * z.y, 2. * z.x * z.y) + c; + if (length(z) > 1000000.) { + float logLength = log(length(z)); + float nu = log(logLength / log(2.)) / log(2.); + float fi = float(i) - nu; + return vec2(sin(fi), cos(fi)); + } + } + return vec2(0, 0); +} + +////////////// +// Interval // +////////////// + +// Operations +vec2 ineg(vec2 v) { return vec2(-v.y, -v.x); } + +vec2 iby(vec2 l, vec2 r) { + float a = l.x * r.x; + float b = l.x * r.y; + float c = l.y * r.x; + float d = l.y * r.y; + float mn = min(min(a, b), min(c, d)); + float mx = max(max(a, b), max(c, d)); + return vec2(mn, mx); +} + +vec2 iinverse(vec2 y) { + if (y.x <= 0. && y.y >= 0.) + return vec2(-1. / 0., 1. / 0.); + if (y.y == 0.) + return vec2(-1. / 0., 1. / y.x); + if (y.x == 0.) + return vec2(1. / y.y, 1. / 0.); + return vec2(1. / y.y, 1. / y.x); +} + +vec2 idiv(vec2 l, vec2 r) { return iby(l, iinverse(r)); } + +float ipow(float b, int e) { + float fe = float(e); + if (mod(fe, 2.) == 0.) + return pow(abs(b), fe); + return b * pow(abs(b), fe - 1.); +} + +vec2 ipow(vec2 b, int e) { + if (e == 0) + return vec2(1, 1); + if (e == 1) + return b; + float xe = ipow(b.x, e); + float ye = ipow(b.y, e); + float mn = min(xe, ye); + float mx = max(xe, ye); + if (mod(float(e), 2.) == 0. && b.x <= 0. && b.y >= 0.) { + return vec2(min(0., mn), max(0., mx)); + } + return vec2(mn, mx); +} + +vec2 iln(vec2 z) { return log(z); } +vec2 iexp(vec2 z) { return exp(z); } + +vec2 ipow(vec2 b, float e) { + if (abs(e - round(e)) < .000001) + return ipow(b, int(e)); + return iexp(e * iln(b)); +} + +vec2 ipow(vec2 b, vec2 e) { + if (e.y - e.x < .000001 && abs(e.x - round(e.x)) < .000001) + return ipow(b, int(e.x)); + return iexp(iby(iln(b), e)); +} + +// Relations +vec2 ilt(vec2 l, vec2 r) { return vec2(r.x - l.y, r.y - l.x); } +vec2 ileq(vec2 l, vec2 r) { return vec2(r.x - l.y, r.y - l.x); } +vec2 ineq(vec2 l, vec2 r) { return vec2(r.x - l.y, r.y - l.x); } +vec2 ieq(vec2 l, vec2 r) { return vec2(l.x - r.y, l.y - r.x); } +vec2 igeq(vec2 l, vec2 r) { return vec2(l.x - r.y, l.y - r.x); } +vec2 igt(vec2 l, vec2 r) { return vec2(l.x - r.y, l.y - r.x); } + +vec2 iabs(vec2 z) { + if (z.x <= 0. && z.y >= 0.) + return vec2(0, max(z.y, abs(z.x))); + if (z.x <= 0.) + return vec2(-z.y, -z.x); + return z; +} + +vec2 isin(vec2 v) { + if (v.y - v.x > radians(360.)) { + return vec2(-1., 1.); + } + float from = mod(v.x, radians(360.)); // [0, 360°] + float to = from + v.y - v.x; // [0, 720°] + vec2 s = sin(vec2(from, to)); + vec2 res = vec2(min(s.x, s.y), max(s.x, s.y)); + if (between(radians(90.), from, to) || between(radians(90. + 360.), from, to)) + res.y = 1.; + if (between(radians(270.), from, to) || + between(radians(270. + 360.), from, to)) + res.x = -1.; + return res; +} + +vec2 icos(vec2 v) { + vec2 shift = radians(90.) * vec2(1, 1); + return isin(v + shift); +} + +vec2 itan(vec2 z) { return idiv(isin(z), icos(z)); } + +vec2 isinh(vec2 v) { return vec2(sinh(v.x), sinh(v.y)); } + +vec2 icosh(vec2 z) { + if (z.x <= 0. && z.y >= 0.) + return vec2(cosh(0.), max(z.y, abs(z.x))); + if (z.x <= 0.) + return vec2(cosh(-z.y), cosh(-z.x)); + return vec2(cosh(z.x), cosh(z.y)); +} + +vec2 itanh(vec2 z) { return vec2(tanh(z.x), tanh(z.y)); } + +vec2 iasin(vec2 z) { + // Don't use clamp so if z is fully outside range the result is empty + vec2 clamped = vec2(max(z.x, -1.), min(z.y, 1.)); + return asin(clamped); +} + +vec2 iacos(vec2 z) { + // Don't use clamp so if z is fully outside range the result is empty + vec2 clamped = vec2(max(z.x, -1.), min(z.y, 1.)); + return acos(clamped).yx; +} + +vec2 iatan(vec2 z) { return atan(z); } + +vec2 iatan2(vec2 y, vec2 x) { + // TODO: improve this + vec2 r = vec2(atan(y.x, x.x), atan(y.y, x.x)); + vec2 q = vec2(atan(y.x, x.y), atan(y.y, x.y)); + vec2 rs = vec2(min(r.x, r.y), max(r.x, r.y)); + vec2 qs = vec2(min(q.x, q.y), max(q.x, q.y)); + return vec2(min(rs.x, qs.x), max(rs.y, qs.y)); +} + +vec2 ire(vec2 v) { return v; } +vec2 iim(vec2 v) { return vec2(0); } + +vec2 iarg(vec2 z) { + if (z.y < 0.) + return dup(radians(180.)); + if (z.x >= 0.) + return vec2(0); + return vec2(0., radians(180.)); +} + +vec2 isign(vec2 z) { return sign(z); } + +vec2 ilog10(vec2 z) { return log(z) / log(10.); } + +vec2 ipw(vec2 c, vec2 t, vec2 f) { + if (c.y <= 0.) + return f; + if (c.x > 0.) + return t; + return vec2(min(t.x, f.x), max(t.y, f.y)); +} + +vec2 isquare(vec2 z) { + vec2 s = z * z; + float mx = max(s.x, s.y); + if (z.x <= 0. && z.y >= 0.) + return vec2(0., mx); + float mn = min(s.x, s.y); + return vec2(mn, mx); +} + +vec2 isqrt(vec2 v) { return vec2(sqrt(max(0., v.x)), sqrt(max(0., v.y))); } +vec2 icbrt(vec2 v) { return vec2(cbrt(v.x), cbrt(v.y)); } + +vec2 iceil(vec2 z) { return ceil(z); } +vec2 ifloor(vec2 z) { return floor(z); } +vec2 iround(vec2 z) { return round(z); } + +vec2 imin(vec2 l, vec2 r) { return vec2(min(l.x, r.x), min(l.y, r.y)); } +vec2 imax(vec2 l, vec2 r) { return vec2(max(l.x, r.x), max(l.y, r.y)); } +vec2 imod(vec2 x, vec2 y) { return x + ineg(iby(y, ifloor(idiv(x, y)))); } + +////////////////////////////////////////////////// +// With derivatives - used to calculate normals // +////////////////////////////////////////////////// + +// Operations +vec4 gneg(vec4 v) { return -v; } + +vec4 gby(vec4 l, vec4 r) { return vec4(l.x * r.x, l.x * r.yzw + r.x * l.yzw); } + +vec4 gdiv(vec4 l, vec4 r) { + return vec4(l.x / r.x, (r.x * l.yzw - l.x * r.yzw) / pow(r.x, 2.)); +} + +vec4 gpow(vec4 b, float e) { + return vec4(pow(b.x, e), e * pow(b.x, e - 1.) * b.yzw); +} + +vec4 gexp(vec4 z) { return vec4(exp(z.x), exp(z.x) * z.yzw); } +vec4 gln(vec4 z) { return vec4(log(z.x), z.yzw / z.x); } + +vec4 gpow(vec4 b, vec4 e) { + if (floor(e.x) == e.x && e.y == 0. && e.z == 0. && e.w == 0.) { + return gpow(b, e.x); + } + return gexp(gby(gln(b), e)); +} + +vec4 gabs(vec4 v) { return vec4(abs(v.x), sign(v.x) * v.yzw); } + +vec4 gsin(vec4 v) { return vec4(sin(v.x), cos(v.x) * v.yzw); } +vec4 gcos(vec4 v) { return vec4(cos(v.x), -sin(v.x) * v.yzw); } +vec4 gtan(vec4 z) { + float c = cos(z.x); + return vec4(tan(z.x), 1. / (c * c) * z.yzw); +} + +vec4 gsinh(vec4 v) { return vec4(sinh(v.x), cosh(v.x) * v.yzw); } +vec4 gcosh(vec4 v) { return vec4(cosh(v.x), sinh(v.x) * v.yzw); } +vec4 gtanh(vec4 z) { + float c = 1. / cosh(z.x); + return vec4(tanh(z.x), c * c * z.yzw); +} + +vec4 gasin(vec4 v) { return vec4(asin(v.x), v.yzw / sqrt(1. - v.x * v.x)); } +vec4 gacos(vec4 v) { return vec4(acos(v.x), -v.yzw / sqrt(1. - v.x * v.x)); } +vec4 gatan(vec4 v) { return vec4(atan(v.x), v.yzw / (1. + v.x * v.x)); } + +vec4 gatan2(vec4 y, vec4 x) { + return vec4(atan(y.x, x.x), y.yzw / x.yzw / (1. + y.x * y.x / x.x / x.x)); +} + +vec4 gre(vec4 v) { return v; } +vec4 gim(vec4 v) { return vec4(0, 0, 0, 1); } +vec4 garg(vec4 z) { return gnum(z.x >= 0. ? 0. : radians(180.)); } + +vec4 glog10(vec4 z) { return vec4(log(z.x), z.yzw / z.x) / log(10.); } +vec4 gpw(vec4 c, vec4 t, vec4 f) { return c.x > 0. ? t : f; } +vec4 gsquare(vec4 z) { return vec4(z.x * z.x, 2. * z.x * z.yzw); } +vec4 gsqrt(vec4 v) { return vec4(sqrt(v.x), .5 * pow(v.x, -.5) * v.yzw); } +vec4 gcbrt(vec4 v) { return vec4(cbrt(v.x), pow(v.x, -2. / 3.) / 3. * v.yzw); } + +vec4 gmin(vec4 l, vec4 r) { return l.x < r.x ? l : r; } +vec4 gmax(vec4 l, vec4 r) { return l.x > r.x ? l : r; } +vec4 gmod(vec4 l, vec4 r) { return vec4(mod(l.x, r.x), l.yzw); } + +vec4 gsign(vec4 v) { return gnum(sign(v.x)); } + +vec4 gceil(vec4 z) { return gnum(ceil(z.x)); } +vec4 gfloor(vec4 z) { return gnum(floor(z.x)); } +vec4 ground(vec4 z) { return gnum(round(z.x)); } + +////////////////////// +// Bisect, raytrace // +////////////////////// + +// bool bisect${suffix}(vec3 o, mat3 d, float max_distance, out vec3 found) { +// mat3 from = mat3(o, o, vec3(0)); +// mat3 to = from + max_distance * d; +// float ithreshold = ${threshold}; +// int depth = 0; +// int choices = 0; +// for(int it = 0; it < ${max_iterations}; it++) { +// mat3 midpoint = 0.5 * (from + to); +// vec2 front = interval${suffix}(from, midpoint); +// vec2 back = interval${suffix}(midpoint, to); +// if(depth >= ${max_depth} +// || (front.y - front.x < ithreshold && front.x <= 0.0 && front.y >= 0.0) +// || (back.y - back.x < ithreshold && back.x <= 0.0 && back.y >= 0.0) +// ) { +// found = mix(midpoint[0], midpoint[1], 0.5); +// return true; +// } +// if(front.x <= 0.0 && front.y >= 0.0) { +// to = midpoint; +// depth++; +// choices = left_shift(choices); +// } else if(back.x <= 0.0 && back.y >= 0.0) { +// from = midpoint; +// depth++; +// choices = left_shift_increment(choices); +// } else { +// // This could be possibly helped by https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightBinSearch +// for(int j = ${max_depth} - 1; j > 0; j--) { +// if(j > depth) +// continue; +// depth--; +// choices = right_shift(choices); +// if(is_even(choices)) { +// midpoint = to; +// to = to + (to - from); +// vec2 back = interval${suffix}(midpoint, to); +// if(back.x <= 0.0 && back.y >= 0.0) { +// from = midpoint; +// depth++; +// choices = left_shift_increment(choices); +// break; +// } +// } else { +// from = from - (to - from); +// } +// } +// if(depth == 0) +// return false; +// } +// } +// return false; +// } + +// bool sphere_bisect${suffix}(vec3 o, mat3 d, float max_distance, out vec3 found) { +// vec3 center = vec3(${center.x},${center.y},${center.z}); + +// vec3 to_center = o - center; +// float b = dot(to_center, 0.5 * (d[0] + d[1])); +// float c = dot(to_center, to_center) - ${radius} * ${radius}; +// float delta = b*b - c; +// if(delta < 0.0) +// return false; +// float x = -b - sqrt(delta); +// if(x < ${threshold}) +// return false; +// found = o + x * 0.5 * (d[0] + d[1]); +// return true; +// } diff --git a/codegen/src/Generate.elm b/codegen/src/Generate.elm new file mode 100644 index 00000000..ade3a8be --- /dev/null +++ b/codegen/src/Generate.elm @@ -0,0 +1,836 @@ +module Generate exposing (run) + +import Ansi.Color +import BackendTask exposing (BackendTask) +import BackendTask.File as File +import Dict exposing (Dict) +import Elm +import Elm.Annotation as Type +import FatalError exposing (FatalError) +import Gen.Glsl +import Glsl exposing (BinaryOperation(..), Declaration(..), Expr(..), Expression(..), Function, RelationOperation(..), Stat(..), Statement(..), Type(..), Uniform) +import Glsl.Parser +import Glsl.PrettyPrinter +import List.Extra +import Pages.Script as Script exposing (Script) +import Parser +import Parser.Advanced +import Result.Extra +import Set +import SortedSet exposing (SortedSet) + + +run : Script +run = + Script.withoutCliOptions task + + +task : BackendTask FatalError () +task = + File.rawFile "codegen/functions.frag" + |> BackendTask.allowFatal + |> BackendTask.andThen + (\glsl -> + case generate glsl of + Err msg -> + let + reflowedMsg : String + reflowedMsg = + msg + |> String.split "\n" + |> (::) "" + |> String.join "\n " + + coloredMsg : String + coloredMsg = + Ansi.Color.fontColor Ansi.Color.red "Error:" + ++ reflowedMsg + in + BackendTask.fail (FatalError.fromString coloredMsg) + + Ok declarations -> + let + file = + declarations + |> List.Extra.gatherEqualsBy Tuple.first + |> List.map + (\( head, tail ) -> + let + group : List Elm.Declaration + group = + List.map Tuple.second (head :: tail) + in + case Tuple.first head of + Just groupName -> + Elm.group (Elm.docs ("#" ++ groupName) :: group) + + Nothing -> + Elm.group group + ) + |> Elm.file + [ "Glsl", "Functions", "NuPlot" ] + in + Script.writeFile + { path = "generated/" ++ file.path + , body = file.contents + } + |> BackendTask.allowFatal + ) + + +generate : String -> Result String (List ( Maybe String, Elm.Declaration )) +generate glsl = + case Parser.Advanced.run Glsl.Parser.file glsl of + Err e -> + Err (parserErrorToString glsl e) + + Ok ( _, declarations ) -> + let + functions = + List.filterMap + (\declaration -> + case declaration of + FunctionDeclaration function -> + Just function + + UniformDeclaration _ -> + Nothing + + ConstDeclaration _ -> + Nothing + ) + declarations + + uniforms = + List.filterMap + (\declaration -> + case declaration of + UniformDeclaration uniform -> + Just uniform + + FunctionDeclaration _ -> + Nothing + + ConstDeclaration _ -> + Nothing + ) + declarations + + constants = + List.filterMap + (\declaration -> + case declaration of + ConstDeclaration const -> + Just const + + FunctionDeclaration _ -> + Nothing + + UniformDeclaration _ -> + Nothing + ) + declarations + + env : Env + env = + List.foldl + (\{ name, returnType, args } -> + functionHasType + name + (List.map Tuple.first args) + returnType + ) + { constantsEnv = + constants + |> List.map (\{ tipe, name } -> ( name, tipe )) + |> Dict.fromList + |> Dict.insert "P32M1" TInt + |> Dict.insert "P31" TInt + , functionsEnv = Dict.empty + , variablesEnv = + uniforms + |> List.map (\{ tipe, name } -> ( name, tipe )) + |> Dict.fromList + } + functions + + maybeDecls : Result String (List ( Maybe String, Elm.Declaration )) + maybeDecls = + Result.Extra.combineMap + (functionToDeclarations env) + functions + |> Result.map List.concat + in + case maybeDecls of + Ok decls -> + let + uniformDecls : List ( Maybe String, Elm.Declaration ) + uniformDecls = + List.map uniformToDeclaration uniforms + in + Ok (decls ++ uniformDecls) + + Err e -> + Err ("Error generating file: " ++ e) + + +uniformToDeclaration : Uniform -> ( Maybe String, Elm.Declaration ) +uniformToDeclaration { name, tipe } = + ( Just "uniforms" + , Gen.Glsl.unsafeVar name + |> Elm.withType (Gen.Glsl.annotation_.expression (typeToAnnotation tipe)) + |> Elm.declaration name + |> Elm.expose + ) + + +functionHasType : String -> List Type -> Type -> Env -> Env +functionHasType baseName argTypes returnType env = + { env | functionsEnv = Dict.insert (fullName baseName argTypes) returnType env.functionsEnv } + + +parserErrorToString : String -> List Glsl.Parser.DeadEnd -> String +parserErrorToString input err = + err + |> List.Extra.gatherEqualsBy (\{ row, col, contextStack } -> ( row, col, contextStack )) + |> List.map (errorToString input) + |> String.join "\n\n" + + +errorToString : String -> ( Glsl.Parser.DeadEnd, List Glsl.Parser.DeadEnd ) -> String +errorToString source ( error, errors ) = + let + -- How many lines of context to show + contextSize : Int + contextSize = + 4 + + lines : List String + lines = + String.split "\n" source + |> List.drop (error.row - contextSize) + |> List.take (contextSize * 2) + + errorString : String + errorString = + [ String.repeat (error.col - 1) " " + , Ansi.Color.fontColor Ansi.Color.red "^ " + , " at row " + , String.fromInt error.row + , ", col " + , String.fromInt error.col + , " " + , (error :: errors) + |> List.map (\{ problem } -> problemToString problem) + |> Set.fromList + |> Set.toList + |> String.join ", " + |> Ansi.Color.fontColor Ansi.Color.yellow + , " while " + , error.contextStack + |> List.map (\frame -> contextToString frame.context) + |> String.join ", while " + ] + |> String.concat + + before : Int + before = + min error.row contextSize + in + List.take before lines + ++ errorString + :: List.drop before lines + |> String.join "\n" + + +contextToString : Glsl.Parser.Context -> String +contextToString context = + case context of + Glsl.Parser.ParsingFile -> + "parsing a file" + + Glsl.Parser.ParsingFunction -> + "parsing a function" + + Glsl.Parser.ParsingStatement -> + "parsing a statement" + + Glsl.Parser.ParsingExpression -> + "parsing an expression" + + Glsl.Parser.ParsingForInitialization -> + "parsing a for's initialization" + + Glsl.Parser.ParsingForCondition -> + "parsing a for's condition" + + Glsl.Parser.ParsingForStep -> + "parsing a for's step" + + Glsl.Parser.ParsingForBody -> + "parsing a for's body" + + +problemToString : Parser.Problem -> String +problemToString problem = + case problem of + Parser.Expecting e -> + "Expecting " ++ e + + Parser.ExpectingInt -> + "Expecting Int" + + Parser.ExpectingHex -> + "Expecting Hex" + + Parser.ExpectingOctal -> + "Expecting Octal" + + Parser.ExpectingBinary -> + "Expecting Binary" + + Parser.ExpectingFloat -> + "Expecting Float" + + Parser.ExpectingNumber -> + "Expecting Number" + + Parser.ExpectingVariable -> + "Expecting Variable" + + Parser.ExpectingSymbol _ -> + "Expecting Symbol" + + Parser.ExpectingKeyword _ -> + "Expecting Keyword" + + Parser.ExpectingEnd -> + "Expecting End" + + Parser.UnexpectedChar -> + "Unexpected char" + + Parser.Problem p -> + p + + Parser.BadRepeat -> + "Bad repeat" + + +type alias Env = + { constantsEnv : Dict String Type + , functionsEnv : Dict String Type + , variablesEnv : Dict String Type + } + + +functionToDeclarations : Env -> Function -> Result String (List ( Maybe String, Elm.Declaration )) +functionToDeclarations env function = + let + functionName : String + functionName = + fullName function.name (List.map Tuple.first function.args) + + envWithArgs : Env + envWithArgs = + List.foldl (\( type_, name ) -> variableHasType name type_) env function.args + + maybeDeps : Result String ( Env, SortedSet String ) + maybeDeps = + findDepsStatement function.stat envWithArgs + |> Result.mapError (\e -> e ++ " while generating " ++ functionName) + in + Result.map + (\( _, deps ) -> + [ ( Nothing + , function.stat + |> Glsl.PrettyPrinter.stat 0 + |> Elm.string + |> Elm.declaration (functionName ++ "Body") + ) + , wrapFunction function.name (SortedSet.insert functionName deps) function.args function.returnType + ] + ) + maybeDeps + + +wrapFunction : String -> SortedSet String -> List ( Type, String ) -> Type -> ( Maybe String, Elm.Declaration ) +wrapFunction name deps args returnType = + let + fname = + fullName name (List.map Tuple.first args) + + argDecls : List ( String, Maybe Type.Annotation ) + argDecls = + List.map + (\( type_, argName ) -> + ( argName + , Just <| Gen.Glsl.annotation_.expression (typeToAnnotation type_) + ) + ) + args + + depsExpr : Elm.Expression + depsExpr = + deps + |> SortedSet.toList + |> List.map (\dep -> Elm.val <| dep ++ "Body") + |> Elm.list + + innerCall argValues = + case argValues of + [] -> + Gen.Glsl.call_.unsafeCall0 (Elm.string name) depsExpr + + [ arg0 ] -> + Gen.Glsl.call_.unsafeCall1 (Elm.string name) depsExpr arg0 + + [ arg0, arg1 ] -> + Gen.Glsl.call_.unsafeCall2 (Elm.string name) depsExpr arg0 arg1 + + [ arg0, arg1, arg2 ] -> + Gen.Glsl.call_.unsafeCall3 (Elm.string name) depsExpr arg0 arg1 arg2 + + [ arg0, arg1, arg2, arg3 ] -> + Gen.Glsl.call_.unsafeCall4 (Elm.string name) depsExpr arg0 arg1 arg2 arg3 + + _ :: _ :: _ -> + Elm.string "TODO" + + expr : List Elm.Expression -> Elm.Expression + expr argValues = + innerCall + argValues + |> Elm.withType (Gen.Glsl.annotation_.expression (typeToAnnotation returnType)) + in + ( if + List.member (String.left 1 name) [ "g", "i", "c" ] + && not (List.member name [ "cbrt", "increment", "cosh", "is_even", "is_odd" ]) + then + Just (String.dropLeft 1 name) + + else + Just name + , Elm.function argDecls expr + |> Elm.declaration fname + |> Elm.expose + ) + + +typeToAnnotation : Type -> Type.Annotation +typeToAnnotation type_ = + case type_ of + TBool -> + Type.bool + + TFloat -> + Type.float + + TInt -> + Type.int + + TVec2 -> + Gen.Glsl.annotation_.vec2 + + TIVec2 -> + Gen.Glsl.annotation_.iVec2 + + TBVec2 -> + Gen.Glsl.annotation_.bVec2 + + TVec3 -> + Gen.Glsl.annotation_.vec3 + + TIVec3 -> + Gen.Glsl.annotation_.iVec3 + + TBVec3 -> + Gen.Glsl.annotation_.bVec3 + + TVec4 -> + Gen.Glsl.annotation_.vec4 + + TIVec4 -> + Gen.Glsl.annotation_.iVec4 + + TBVec4 -> + Gen.Glsl.annotation_.bVec4 + + TMat3 -> + Gen.Glsl.annotation_.mat3 + + TVoid -> + Gen.Glsl.annotation_.void + + TIn tt -> + Gen.Glsl.annotation_.in_ (typeToAnnotation tt) + + TOut tt -> + Gen.Glsl.annotation_.out (typeToAnnotation tt) + + TUint -> + Type.int + + TUVec2 -> + Gen.Glsl.annotation_.uVec2 + + TUVec3 -> + Gen.Glsl.annotation_.uVec3 + + TUVec4 -> + Gen.Glsl.annotation_.uVec4 + + TDouble -> + Type.float + + TDVec2 -> + Gen.Glsl.annotation_.dVec2 + + TDVec3 -> + Gen.Glsl.annotation_.dVec3 + + TDVec4 -> + Gen.Glsl.annotation_.dVec4 + + TMat2 -> + Gen.Glsl.annotation_.mat2 + + TMat4 -> + Gen.Glsl.annotation_.mat4 + + TMat23 -> + Gen.Glsl.annotation_.mat23 + + TMat24 -> + Gen.Glsl.annotation_.mat24 + + TMat32 -> + Gen.Glsl.annotation_.mat32 + + TMat34 -> + Gen.Glsl.annotation_.mat34 + + TMat42 -> + Gen.Glsl.annotation_.mat42 + + TMat43 -> + Gen.Glsl.annotation_.mat43 + + TDMat2 -> + Gen.Glsl.annotation_.dMat2 + + TDMat3 -> + Gen.Glsl.annotation_.dMat3 + + TDMat4 -> + Gen.Glsl.annotation_.dMat4 + + TDMat23 -> + Gen.Glsl.annotation_.dMat23 + + TDMat24 -> + Gen.Glsl.annotation_.dMat24 + + TDMat32 -> + Gen.Glsl.annotation_.dMat32 + + TDMat34 -> + Gen.Glsl.annotation_.dMat34 + + TDMat42 -> + Gen.Glsl.annotation_.dMat42 + + TDMat43 -> + Gen.Glsl.annotation_.dMat43 + + +variableHasType : String -> Type -> Env -> Env +variableHasType var type_ env = + { env | variablesEnv = Dict.insert var type_ env.variablesEnv } + + +union : List (Env -> Result String ( Env, SortedSet comparable )) -> Env -> Result String ( Env, SortedSet comparable ) +union list initialEnv = + List.foldl + (\e a -> + a + |> Result.andThen + (\( env, deps ) -> + e env + |> Result.map + (Tuple.mapSecond + (\newDeps -> SortedSet.insertAll newDeps deps) + ) + ) + ) + (Ok ( initialEnv, SortedSet.empty )) + list + + +findDepsStatement : Stat -> Env -> Result String ( Env, SortedSet String ) +findDepsStatement statement = + case statement of + If cond true -> + union + [ findDepsExpression cond + , findDepsStatement true + ] + + IfElse cond true false -> + union + [ findDepsExpression cond + , findDepsStatement true + , findDepsStatement false + ] + + ExpressionStatement e -> + findDepsExpression e + + For from cond step loop -> + union + [ case from of + Just f -> + findDepsStatement f + + Nothing -> + nop + , findDepsExpression cond + , findDepsExpression step + , findDepsStatement loop + ] + + Return e -> + findDepsExpression e + + Decl type_ var maybeVal -> + \env -> + let + newEnv : Env + newEnv = + variableHasType var type_ env + in + case maybeVal of + Nothing -> + nop newEnv + + Just val -> + findDepsExpression val newEnv + + Nop -> + nop + + Break -> + nop + + Continue -> + nop + + Block l m r -> + union (List.map findDepsStatement (l :: m :: r)) + + +nop : Env -> Result String ( Env, SortedSet String ) +nop env = + Ok ( env, SortedSet.empty ) + + +findDepsExpression : Expr -> Env -> Result String ( Env, SortedSet String ) +findDepsExpression root env = + let + go : Expr -> Result String (SortedSet String) + go expr = + case expr of + Float _ -> + Ok SortedSet.empty + + Int _ -> + Ok SortedSet.empty + + Uint _ -> + Ok SortedSet.empty + + Double _ -> + Ok SortedSet.empty + + Bool _ -> + Ok SortedSet.empty + + Dot e _ -> + go e + + Variable _ -> + Ok SortedSet.empty + + Call (Variable f) args -> + args + |> Result.Extra.combineMap go + |> Result.andThen + (\argDeps -> + let + initial = + SortedSet.singleton (fullName f []) + + deps = + List.foldl SortedSet.insertAll initial argDeps + in + Ok deps + ) + + Call _ _ -> + Err "Complex calls are not supported yet" + + Ternary c t f -> + Result.map3 + (\cd td fd -> + SortedSet.insertAll cd td + |> SortedSet.insertAll fd + ) + (go c) + (go t) + (go f) + + UnaryOperation _ e -> + go e + + BinaryOperation l _ r -> + Result.map2 + (\ld rd -> + SortedSet.insertAll ld rd + ) + (go l) + (go r) + in + go root + |> Result.map (\deps -> ( env, deps )) + + +fullName : String -> List Type -> String +fullName baseName argTypes = + String.concat (baseName :: List.map typeToShort argTypes) + + +typeToShort : Type -> String +typeToShort t = + case t of + TFloat -> + "1" + + TInt -> + "i1" + + TBool -> + "b1" + + TUint -> + "u1" + + TDouble -> + "d1" + + TVec2 -> + "2" + + TIVec2 -> + "i2" + + TBVec2 -> + "b2" + + TUVec2 -> + "u2" + + TDVec2 -> + "d2" + + TVec3 -> + "3" + + TIVec3 -> + "i3" + + TBVec3 -> + "b3" + + TUVec3 -> + "u3" + + TDVec3 -> + "d3" + + TVec4 -> + "4" + + TIVec4 -> + "i4" + + TBVec4 -> + "b4" + + TUVec4 -> + "u4" + + TDVec4 -> + "d4" + + TMat2 -> + "m2" + + TDMat2 -> + "dm2" + + TMat23 -> + "m23" + + TDMat23 -> + "dm23" + + TMat24 -> + "m24" + + TDMat24 -> + "dm24" + + TMat32 -> + "m32" + + TDMat32 -> + "dm32" + + TMat42 -> + "m42" + + TDMat42 -> + "dm42" + + TMat3 -> + "m3" + + TDMat3 -> + "dm3" + + TMat34 -> + "m34" + + TDMat34 -> + "dm34" + + TMat43 -> + "m43" + + TDMat43 -> + "dm43" + + TMat4 -> + "m4" + + TDMat4 -> + "dm4" + + TVoid -> + "v" + + TIn tt -> + "n" ++ typeToShort tt + + TOut tt -> + "o" ++ typeToShort tt diff --git a/elm.json b/elm.json index 0a8e25b3..bb32cfc6 100644 --- a/elm.json +++ b/elm.json @@ -2,13 +2,15 @@ "type": "application", "source-directories": [ "src/elm", - "src/elm-extra" + "src/elm-extra", + "generated", + "vendored/miniBill/elm-glsl/1.0.0/src" ], "elm-version": "0.19.1", "dependencies": { "direct": { "avh4/elm-color": "1.0.0", - "dillonkearns/elm-markdown": "5.1.1", + "dillonkearns/elm-markdown": "7.0.1", "elm/browser": "1.0.2", "elm/bytes": "1.0.8", "elm/core": "1.0.5", @@ -18,19 +20,17 @@ "elm/json": "1.1.3", "elm/parser": "1.1.0", "elm/url": "1.0.0", - "elm-community/list-extra": "8.2.4", - "elm-community/maybe-extra": "5.2.0", - "elm-community/result-extra": "2.4.0", + "elmcraft/core-extra": "2.1.0", "lemol/ant-design-icons-elm-ui": "1.0.0", - "miniBill/elm-codec": "2.0.0", - "miniBill/elm-ui-with-context": "1.0.0", - "miniBill/elm-unicode": "1.0.2" + "miniBill/elm-codec": "2.2.0", + "miniBill/elm-ui-with-context": "2.0.0", + "miniBill/elm-unicode": "1.1.1" }, "indirect": { "elm/regex": "1.0.0", "elm/svg": "1.0.1", "elm/time": "1.0.0", - "elm/virtual-dom": "1.0.2", + "elm/virtual-dom": "1.0.3", "lemol/ant-design-icons-elm": "2.0.0", "mdgriffith/elm-ui": "1.1.8", "rtfeldman/elm-hex": "1.0.0" @@ -38,7 +38,7 @@ }, "test-dependencies": { "direct": { - "elm-explorations/test": "1.2.2" + "elm-explorations/test": "2.2.0" }, "indirect": { "elm/random": "1.0.0" diff --git a/nuplot.code-workspace b/nuplot.code-workspace new file mode 100644 index 00000000..f6d933f4 --- /dev/null +++ b/nuplot.code-workspace @@ -0,0 +1,14 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "codegen" + }, + { + "path": "review" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/package.json b/package.json index aae054d3..b4b77e78 100644 --- a/package.json +++ b/package.json @@ -15,19 +15,24 @@ ] }, "devDependencies": { - "elm-optimize-level-2": "^0.1.5", - "elm-review": "^2.10.2", - "elm-watch": "^1.1.2", - "typescript": "^4.3.5" + "elm-codegen": "^0.6.1", + "elm-format": "^0.8.7", + "elm-optimize-level-2": "^0.3.5", + "elm-pages": "3.0.22", + "elm-review": "^2.13.2", + "elm-test-rs": "^3.0.0-5", + "elm-watch": "^2.0.0-beta.6", + "typescript": "^5.8.3" }, "scripts": { - "build": "rm -rf .cache dist elm-stuff; elm-optimize-level-2 src/elm/UI.elm --output src/optimized.js && parcel build src/index.html --public-url .", - "buildForBenchmark": "rm -rf .cache elm-stuff dist; elm-optimize-level-2 src/elm/UI.elm --output src/optimized.js && parcel build --no-minify src/index.html --public-url .", - "start": "parcel src/dev.html", + "build": "make build", + "buildForBenchmark": "rm -rf .cache elm-stuff dist; elm-optimize-level-2 src/elm/UI.elm --output src/optimized.js && yarn parcel build --no-minify src/index.html --public-url .", + "start": "yarn parcel src/dev.html", "test": "elm-test" }, "name": "nuplot", "description": "A small CAS and plotter", + "license": "MIT", "pwaManifest": { "name": "NuPlot", "shortName": "NuPlot", @@ -53,6 +58,5 @@ }, "dependencies": { "localforage": "^1.9.0" - }, - "packageManager": "yarn@4.0.2" + } } diff --git a/review/elm.json b/review/elm.json index 15025902..10e4412d 100644 --- a/review/elm.json +++ b/review/elm.json @@ -6,33 +6,52 @@ "elm-version": "0.19.1", "dependencies": { "direct": { + "SiriusStarr/elm-review-pipeline-styles": "1.3.9", "elm/core": "1.0.5", "elm/json": "1.1.3", "elm/project-metadata-utils": "1.0.2", - "jfmengels/elm-review": "2.5.0", - "jfmengels/elm-review-common": "1.0.4", - "jfmengels/elm-review-unused": "1.1.15", - "sparksp/elm-review-always": "1.0.5", - "sparksp/elm-review-imports": "1.0.1", - "stil4m/elm-syntax": "7.2.6", - "truqu/elm-review-nobooleancase": "1.0.0" + "jfmengels/elm-review": "2.15.1", + "jfmengels/elm-review-code-style": "1.2.0", + "jfmengels/elm-review-common": "1.3.3", + "jfmengels/elm-review-debug": "1.0.8", + "jfmengels/elm-review-documentation": "2.0.4", + "jfmengels/elm-review-simplify": "2.1.6", + "jfmengels/elm-review-unused": "1.2.4", + "jsuder-xx/elm-review-reducible-lambdas": "2.0.1", + "lue-bird/elm-review-record-alias-constructor": "1.1.3", + "miniBill/elm-review-no-broken-elm-parser-functions": "1.0.0", + "sparksp/elm-review-always": "1.0.6", + "sparksp/elm-review-imports": "1.0.2", + "sparksp/elm-review-ports": "1.3.1", + "stil4m/elm-syntax": "7.3.8", + "truqu/elm-review-nobooleancase": "1.0.1" }, "indirect": { + "Chadtech/elm-bool-extra": "2.4.2", + "elm/bytes": "1.0.8", "elm/html": "1.0.0", "elm/parser": "1.1.0", "elm/random": "1.0.0", + "elm/regex": "1.0.0", "elm/time": "1.0.0", - "elm/virtual-dom": "1.0.2", - "elm-community/list-extra": "8.3.1", - "elm-explorations/test": "1.2.2", - "miniBill/elm-unicode": "1.0.2", + "elm/virtual-dom": "1.0.3", + "elm-community/basics-extra": "4.1.0", + "elm-community/list-extra": "8.7.0", + "elm-community/maybe-extra": "5.3.0", + "elm-explorations/test": "2.2.0", + "jsuder-xx/elm-ra": "1.1.1", + "miniBill/elm-fast-dict": "1.2.1", + "miniBill/elm-unicode": "1.1.1", + "pzp1997/assoc-list": "1.0.0", "rtfeldman/elm-hex": "1.0.0", - "stil4m/structured-writer": "1.0.3" + "stil4m/structured-writer": "1.0.3", + "the-sett/elm-pretty-printer": "3.1.1", + "the-sett/elm-syntax-dsl": "6.0.3" } }, "test-dependencies": { "direct": { - "elm-explorations/test": "1.2.2" + "elm-explorations/test": "2.2.0" }, "indirect": {} } diff --git a/review/src/ReviewConfig.elm b/review/src/ReviewConfig.elm index 4e365a64..18b060f3 100644 --- a/review/src/ReviewConfig.elm +++ b/review/src/ReviewConfig.elm @@ -1,12 +1,23 @@ module ReviewConfig exposing (config) +import Docs.ReviewAtDocs import NoAlways import NoBooleanCase +import NoBrokenParserFunctions +import NoConfusingPrefixOperator +import NoDebug.Log +import NoDebug.TodoOrToString +import NoDuplicatePorts import NoExposingEverything import NoImportingEverything import NoMissingTypeAnnotation +import NoMissingTypeAnnotationInLetIn import NoMissingTypeExpose import NoModuleOnExposedNames +import NoPrematureLetComputation +import NoRecordAliasConstructor +import NoSimpleLetBody +import NoUnsafePorts import NoUnused.CustomTypeConstructorArgs import NoUnused.CustomTypeConstructors import NoUnused.Dependencies @@ -15,24 +26,69 @@ import NoUnused.Modules import NoUnused.Parameters import NoUnused.Patterns import NoUnused.Variables -import Review.Rule exposing (Rule) +import NoUnusedPorts +import Review.Rule as Rule exposing (Rule) +import ReviewPipelineStyles +import Simplify config : List Rule config = [ NoAlways.rule + , Docs.ReviewAtDocs.rule , NoBooleanCase.rule + , NoConfusingPrefixOperator.rule + , NoDebug.Log.rule + , NoDebug.TodoOrToString.rule + |> Rule.ignoreErrorsForDirectories + [ "tests" + , "vendored/miniBill/elm-glsl" + ] + , NoDuplicatePorts.rule + + -- , NoEtaReducibleLambdas.rule + -- { lambdaReduceStrategy = NoEtaReducibleLambdas.AlwaysRemoveLambdaWhenPossible + -- , argumentNamePredicate = always True + -- } , NoExposingEverything.rule , NoImportingEverything.rule [] , NoMissingTypeAnnotation.rule + , NoMissingTypeAnnotationInLetIn.rule , NoMissingTypeExpose.rule , NoModuleOnExposedNames.rule + , NoPrematureLetComputation.rule + , NoRecordAliasConstructor.rule + , NoSimpleLetBody.rule + , NoUnsafePorts.rule NoUnsafePorts.any , NoUnused.CustomTypeConstructorArgs.rule + |> Rule.ignoreErrorsForDirectories + [ "vendored/miniBill/elm-glsl" + ] , NoUnused.CustomTypeConstructors.rule [] - , NoUnused.Dependencies.rule + |> Rule.ignoreErrorsForDirectories + [ "vendored/miniBill/elm-glsl" + ] + + -- , NoUnused.Dependencies.rule , NoUnused.Exports.rule + |> Rule.ignoreErrorsForDirectories + [ "generated" + , "vendored/miniBill/elm-glsl" + ] , NoUnused.Modules.rule + |> Rule.ignoreErrorsForDirectories + [ "vendored/miniBill/elm-glsl" + ] , NoUnused.Parameters.rule , NoUnused.Patterns.rule , NoUnused.Variables.rule + , NoUnusedPorts.rule + , Simplify.rule Simplify.defaults + , ReviewPipelineStyles.rule + [ ReviewPipelineStyles.forbid ReviewPipelineStyles.leftCompositionPipelines + |> ReviewPipelineStyles.andCallThem "forbidden << composition" + , ReviewPipelineStyles.forbid ReviewPipelineStyles.rightCompositionPipelines + |> ReviewPipelineStyles.andCallThem "forbidden >> composition" + ] + , NoBrokenParserFunctions.rule ] diff --git a/src/dev.html b/src/dev.html index 815fe08e..c4e5c272 100644 --- a/src/dev.html +++ b/src/dev.html @@ -1,42 +1,49 @@ - -
- - -