Created
February 24, 2025 16:47
-
-
Save VictorTaelin/12579a0fd04f3b5da0e251a0a8cb6a87 to your computer and use it in GitHub Desktop.
prompt to generate _test_.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the current dir has the following files: | |
bench_cnots.hvml | |
bench_count.hs | |
bench_count.hvml | |
bench_sum_range.hs | |
bench_sum_range.hvml | |
bench_sum_range.js | |
bug_tmp | |
docs | |
enum_bin.hvml | |
enum_coc_smart.hvml | |
enum_lam_naive_blc.hs | |
enum_lam_naive_blc.hvml | |
enum_lam_smart.hvml | |
enum_nat.hvml | |
enum_primes.hs | |
enum_primes.hvml | |
feat_affine_ctx.hvml | |
feat_cmul.hvml | |
feat_hoas.hvml | |
feat_mut_ref.hvml | |
fuse_inc.hvm1 | |
fuse_inc.hvml | |
fuse_mul.hvml | |
fuse_rot.hvml | |
main.hvml | |
the hvml files can be evaluated with hvml, as follows: | |
to run on interpreted mode: | |
$ cabal run -v0 hvml --project-dir=/Users/v/vic/dev/HVM3 -- run file_name.hvml -C -s | |
to run on compiled mode: | |
$ hvml run file_name.hvml -c -C -s | |
the output of running a hvml file is formatted like: | |
``` | |
λa λb a | |
WORK: 117440614 interactions | |
TIME: 1.0978210 seconds | |
SIZE: 335544641 nodes | |
PERF: 106.976 MIPS | |
``` | |
that is, the first line is the result, and then we have some stats. | |
our goal is to create a _test_.js script that will test the hvml implementation | |
by running these files. to do so, we must extract the result (first line) and | |
the "time" from the output. to have a better time measure, we will run each | |
command 4 times, discard the first result, and average the other 3. we will | |
compare the result agains the expected result. if the result is wrong, we will | |
console.log an error message. if the time decreased by >5%, we will also log an | |
error message. the timings of the last run are saved on _perf_.json (create if | |
it doesn't exist). finally, note that, before running a command, we must | |
*adjust* the file, by replacing its '@main' line (i.e., a line starting with | |
the "@main" string) by a given line, and then saving it as _test_.hvml (i.e., | |
do not overwrite the original file). the line we'll replace it with is given | |
in the table below, which also includes the expected result ("norm"). | |
bench_cnots: | |
- intr: | |
- main: @main = (@P20 @not @true) | |
- norm: λa λb a | |
- comp: | |
- main: @main = (@P24 @not @true) | |
- norm: λa λb a | |
bench_count: | |
- intr: | |
- main: @main = @count(2_000_000 0) | |
- norm: 4000000 | |
- comp: | |
- main: @main = @count(2_000_000_000 0) | |
- norm: 4000000000 | |
bench_sum_range: | |
- intr: | |
- main: @main = @sum(@range(1_000_000 #Nil) 0) | |
- norm: 3992170112 | |
- comp: | |
- main: @main = @sum(@range(300_000_000 #Nil) 0) | |
- norm: 1783293664 | |
enum_coc_smart: | |
- intr: | |
- norm: "λλ(0 λλ((1 3) 2))" | |
- comp: | |
- norm: "λλ(0 λλ((1 3) 2))" | |
enum_lam_naive_blc: | |
- comp: | |
- norm: "λλ(1 λλ((2 0) 1))" | |
enum_lam_smart: | |
- intr: | |
- norm: "λ(0 λλλ((0 1) 2))" | |
- comp: | |
- norm: "λ(0 λλλ((0 1) 2))" | |
enum_nat: | |
- intr: | |
- main: @main = @if(@eq(@mul(@X @nat(20)) @nat(12000)) @u32(@X) *) | |
- norm: 600 | |
- comp: | |
- main: @main = @if(@eq(@mul(@X @nat(20)) @nat(20000)) @u32(@X) *) | |
- norm: 1000 | |
enum_primes: | |
- intr: | |
- main: @main = @if(@eq(@mul(@X_B @Y_B) @P_B) λt(t @u32(@X_B) @u32(@Y_B)) *) | |
- norm: λa ((a 25997) 27299) | |
- comp: | |
- main: @main = @if(@eq(@mul(@X_C @Y_C) @P_C) λt(t @u32(@X_C) @u32(@Y_C)) *) | |
- norm: λa ((a 25997) 27299) | |
feat_affine_ctx: | |
- intr: | |
- norm: 1 | |
- comp: | |
- norm: 1 | |
feat_cmul: | |
- intr: | |
- norm: λa λb (a (a (a (a b)))) | |
- comp: | |
- norm: λa λb (a (a (a (a b)))) | |
feat_hoas: | |
- intr: | |
- norm: "λx λy (x (x (x (x y))))" | |
- comp: | |
- norm: "λx λy (x (x (x (x y))))" | |
feat_mut_ref: | |
- intr: | |
- norm: 2 | |
- comp: | |
- norm: 2 | |
fuse_inc: | |
- intr: | |
- norm: 1234567 | |
- comp: | |
- norm: 1234567 | |
fuse_mul: | |
- intr: | |
- main: @main = @mul(12345 12345) | |
- norm: 152399025 | |
- comp: | |
- main: @main = @mul(23232 32323) | |
- norm: 750927936 | |
fuse_rot: | |
- intr: | |
- main: @main = (@read(@S) @sqr(12345 (@add(@S) @KA) @KB)) | |
- norm: 209865 | |
- comp: | |
- main: @main = (@read(@S) @sqr(54321 (@add(@S) @KA) @KB)) | |
- norm: 923457 | |
note that the table above has two versions: intr and comp. this refers to | |
interpreted and compiled mode, respectively. each file is tested separately | |
for each mode. so, for example, on fuse_rot, we'll first replace main by | |
@main = (@read(@S) @sqr(12345 (@add(@S) @KA) @KB)) | |
then, save to _test_.hvml, and run it with interpreted mode. we'll then check if | |
the result (i.e., the first line) is exactly 209865 (on the first run). if it | |
isn't, we'll show a red error on the screen. then, we'll run 3 more times, to | |
average the time. if the perf drops by >5%, we'll show a yellow warning on the | |
screen. note that, if the total run time is < 0.05s, we'll skip perf warnings | |
(as this is considered a non-benchmark-relevant test). then, we will do this | |
again, but now using the compiled mode. we'll do this for each test case on the | |
table above. note that some cases don't have a 'main' function. that means you | |
don't need to replace main by anything, just copy to _test_.hvml. note that | |
some programs don't have a mode (like intr) in the table above. when that's the | |
case, you shouldn't run that mode on that program. | |
note that some normal forms include the quote (") character. that's because | |
these programs return strings. you must include them in your check. | |
create now the _test_.js file, which will be responsible for running these | |
tests, reporting errors and saving _perf_.json. keep it simple and well | |
documented, with rich comments documenting the purpose of the file, capturing | |
and explaining all the instructions given in this prompt. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
generated output by Grok3: