{"id":15398445,"url":"https://github.com/jubnzv/moonsmith","last_synced_at":"2025-04-16T01:20:07.787Z","repository":{"id":94900198,"uuid":"396756623","full_name":"jubnzv/moonsmith","owner":"jubnzv","description":"A random generator of Lua programs","archived":false,"fork":false,"pushed_at":"2021-11-01T03:51:50.000Z","size":315,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T11:05:51.763Z","etag":null,"topics":["lua","ocaml","program-generator"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jubnzv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-16T11:09:37.000Z","updated_at":"2023-09-19T15:24:45.000Z","dependencies_parsed_at":"2023-04-06T16:46:57.310Z","dependency_job_id":null,"html_url":"https://github.com/jubnzv/moonsmith","commit_stats":{"total_commits":69,"total_committers":1,"mean_commits":69.0,"dds":0.0,"last_synced_commit":"1bc64fd9f01b84b2c943e6edc28c590bba01184c"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jubnzv%2Fmoonsmith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jubnzv%2Fmoonsmith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jubnzv%2Fmoonsmith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jubnzv%2Fmoonsmith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jubnzv","download_url":"https://codeload.github.com/jubnzv/moonsmith/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249179059,"owners_count":21225482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","ocaml","program-generator"],"created_at":"2024-10-01T15:43:52.425Z","updated_at":"2025-04-16T01:20:07.770Z","avatar_url":"https://github.com/jubnzv.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# moonsmith\n\n![](https://github.com/jubnzv/moonsmith/workflows/Build/badge.svg)\n\nmoonsmith is a generator of random Lua 5.3 programs.\n\nThis tool can be used to evaluate tooling that works with Lua: parsers, transpilers, code analyzers, etc.\n\n## Description\n\nmoonsmith generates a syntactically and semantically correct Lua program, which always successfully terminates in a short time.\n\nThe core idea behind the algorithm of generated programs is to generate some global data and a few functions and methods, which mutate it. At the end of top-level a generated program calls all functions and combines results to a single integer. Then it prints this integer to the stdout.\n\nHere is an example of randomly generated program:\n\n\u003cdetails\u003e\n  \u003csummary\u003eout.lua\u003c/summary\u003e\n\n```lua\n--------------------------------------------------------\n-- This code was automatically generated by moonsmith --\n-- https://github.com/jubnzv/moonsmith                --\n--                                                    --\n-- Seed:                   42                         --\n--------------------------------------------------------\n\n--------------------------------------------------------\n-- Utility functions.                                 --\n--------------------------------------------------------\nms = {}\n\n-- Generates a random integer for an arbitrary table.\n-- @param t table\nfunction ms.table_to_int(t)\n  acc = 0\n  for i, v in ipairs(t) do\n    if type(v) == \"number\" then\n      acc = acc + v\n    else\n      acc = acc \u0026 i\n    end\n  end\n  return acc + #t\nend\n\n--------------------------------------------------------\n-- Global datums definitions (  5 statements)         --\n--------------------------------------------------------\ndatum0 = {}\ndatum1 = {}\nlocal datum2 = {}\ndatum3 = {}\ndatum4 = 33\n\n--------------------------------------------------------\n-- Function definitions (  5 functions)               --\n--------------------------------------------------------\n-- @return float\nfunction datum2:m5()\n  local v22, v24, v26 = [[et\nullamco\nlaborum]], 62.085799, 26\n  local v28, v30, v32 = \"laborum in\", -48.609145, \"tempor quis\"\n  v24 = 5.729946 - math.pi - -(math.pi)\n  v22 = \"anim\"\n  local cond35 = 9\n  repeat\n      v24 = math.cos(v24) - 56.973951 - -(math.pi)\n      v24 = math.abs(v24) - 73.589347 - -(math.abs(v24))\n      cond35 = cond35 + 3\n  until cond35 \u003c= 45\n  v22 = \"minim culpa eiusmod\"\n  local cond37 = 5\n  repeat\n      v22 = math.type(85)\n      v22 = math.type(53)\n      cond37 = cond37 + 0x3\n  until cond37 \u003c= 41\n  return math.pi - -(math.cos(v24))\nend\n\n-- @param a0 float\n-- @param a1 boolean\n-- @param a2 string\n-- @param a3 int\n-- @param a4 string\n-- @return nil\nfunction func6(a0, a1, a2, a3, a4)\n  v39, v41 = -97.502688, \"2\"\n  local v43, v45, v47, v49 = \"nisi\", -77, a2, a1\n  v51, v53 = datum4, a1\n  for _, v in ipairs(datum3) do\n      a2 = a4\n      v39 = math.pi - -(72.747706)\n  end\n  v43 = math.type(-78)\n  for i, _ in ipairs(datum1) do\n      v41 = \"1\"\n  end\n  if a3 ~= 44 then\n      a3 = -50 + ~ -78\n      a0 = 80.030963 - 2.273377 - -(math.abs(9))\n      a3 = 94 + ~ string.len([[nulla]])\n  else\n      a3 = -61 - ~ #(a2)\n      a4 = math.type(a3)\n  end\n  return false ~= a1 == \"adipiscing nostrud\" == a2 ~= math.ult(a3, 4) ~= [[et\nnisi\ndolore]] ~= a4 == true == \"nostrud exercitation cillum\" == v41 == not \"in do reprehenderit pariatur\" ~= v43\nend\n\n-- @param a0 string\n-- @return string\nlocal func12 = function (a0)\n  v62, v64, v66 = false, \"1\", [[2]]\n  v68, v70, v72, v74 = a0, datum4, v62, \"veniam dolore\"\n  v76, v78, v80 = \"nostrud qui consequat\", [[proident\naliquip\nUt]], \"9\"\n  if v64 ~= \"3\" then\n      v62 = math.ult(-98, -6) == not true ~= false\n      a0 = v64\n      a0 = tostring(-73)\n  else\n      v64 = \"5\"\n      v64 = tostring(-60)\n  end\n  v66 = \"1\"\n  a0 = v64\n  if a0 ~= \"4\" then\n      v62 = false ~= \"quis nisi nisi\" == a0 ~= not math.ult(-11, 12)\n      v62 = false ~= not \"ut\" ~= \"esse proident in\"\n      v62 = false == false == not false == v62\n  else\n      v62 = true ~= true == false == not \"adipiscing consequat\" == a0\n      v66 = a0\n      a0 = \"8\"\n  end\n  if v62 == true then\n      a0 = \"2\"\n  else\n      v64 = v66\n      v62 = math.ult(-4, 11) == \"proident in fugiat laborum\" == v64 ~= not math.ult(-37, 0x5)\n  end\n  return a0\nend\n\n-- @param a0 string\n-- @param a1 string\n-- @param a2 boolean\n-- @param a3 boolean\n-- @return float\nlocal func14 = function (a0, a1, a2, a3)\n  local v82, v84 = -93.709911, 78.054212\n  local v86, v88, v90 = [[9]], \"8\", true\n  if datum3 == {} then\n      v84 = 49.225268 + -(math.abs(113.449562))\n      a2 = true == a3 == not true == true\n      v82 = 7.013714 + math.pi - -(math.pi)\n  else\n      v82 = 6.035996 + math.sin(v84) - -(math.pi)\n      a2 = false == a3 ~= not false ~= true\n  end\n  v82 = math.sin(v84) + math.pi + -(math.abs(0.302638))\n  for _, v in ipairs(datum1) do\n      a1 = \"8\"\n  end\n  local cond94 = false\n  repeat\n      a0 = math.type(0x21)\n      a0 = \"consequat in elit\"\n      cond94 = true\n  until cond94 ~= false\n  return math.pi + 63.696019 - 13.263112 + 0x1.9b9000b262431p+2 - math.abs(v82) + -(math.sin(v84))\nend\n\n-- @param a0 float\n-- @param a1 string\n-- @return nil\nlocal func19 = function (a0, a1)\n  v96, v98, v100, v102 = -39.158628, -15, \"4\", a0\n  v104, v106, v108, v110 = \"4\", \"qui proident\", \"9\", \"7\"\n  v96 = math.tan(v96) + math.pi + -(17.112416)\n  if a0 == -29.895999 then\n      a1 = \"nulla quis\"\n      v98 = math.floor(v96) \u0026 ~ -17\n  else\n      v96 = math.pi + -(35.132890)\n  end\n  v98 = math.floor(a0) ~ -54 + ~ 55\n  v96 = math.pi - -(math.pi)\n  for i=0,0xe,2 do\n      v96 = math.tan(v96) + -(math.tan(51.779741))\n      v98 = -38 ~ -(string.len(\"cillum\"))\n  end\n  return false ~= \"aute fugiat veniam nostrud\" ~= a1 == false == not math.ult(v98, 0xd)\nend\n\n--------------------------------------------------------\n-- Calling functions                                  --\n--------------------------------------------------------\nlocal r_m5_0 = datum2:m5()\nlocal func6_a0 = 41.181777\nlocal func6_a1 = true\nlocal func6_a2 = \"sed in in\"\nlocal func6_a3 = -31\nlocal func6_a4 = \"voluptate sed laborum ea\"\nlocal r_func6_0 = func6(func6_a0, func6_a1, func6_a2, func6_a3, func6_a4)\nlocal func12_a0 = \"9\"\nlocal r_func12_0 = func12(func12_a0)\nlocal func14_a0 = \"officia dolor\"\nlocal func14_a1 = [[1]]\nlocal func14_a2 = true\nlocal func14_a3 = true\nlocal r_func14_0 = func14(func14_a0, func14_a1, func14_a2, func14_a3)\nlocal func19_a0 = 95.503889\nlocal func19_a1 = [[eu\nconsequat\nesse]]\nlocal r_func19_0 = func19(func19_a0, func19_a1)\n\n--------------------------------------------------------\n-- Combining and printing result                      --\n--------------------------------------------------------\nlocal res_datum0 = ms.table_to_int(datum0)\nlocal res_datum1 = #(datum1)\nlocal res_datum2 = ms.table_to_int(datum2)\nlocal res_datum3 = #(datum3)\nlocal res_datum4 = datum4\nlocal res_r_m5_0 = math.floor(r_m5_0)\nlocal res_r_func6_0 = 1\nlocal res_r_func12_0 = math.floor(r_func12_0 + 1)\nlocal res_r_func14_0 = math.floor(r_func14_0)\nlocal res_r_func19_0 = 1\nRESULT = res_r_func19_0 + res_r_func14_0 - res_r_func12_0 + res_r_func6_0 + res_r_m5_0 - res_datum4 + res_datum3 - res_datum2 - res_datum1 + res_datum0\nprint(math.floor(RESULT))\n```\n\n\u003c/details\u003e\n\n## Installation\n\nThe simplest way to install the tool is to download it from the [releases page](https://github.com/jubnzv/moonsmith/releases).\n\nOtherwise you should build it from sources.\n\nInstall the latest OCaml compiler and opam. Consider installation instructions at [ocaml.org](https://ocaml.org/docs/install.html) and [opam.ocaml.org](https://opam.ocaml.org/doc/Install.html).\n\nThen clone the repository and install required dependencies:\n\n```bash\ngit clone https://github.com/jubnzv/moonsmith.git\ncd moonsmith\nopam install --deps-only .    # first time only\n```\n\nThen build and install `moonsmith` binary:\n\n```bash\ndune build --profile release\ndune install --prefix output\n```\n\nYou'll get a statically linked binary at `output/bin/moonsmith`.\n\n## Usage\n\nYou can simply call binary to get randomly-generated Lua program at `out.lua`:\n\n```bash\noutput/bin/moonsmith\n```\n\nThe complete set of command-line options is available through `--help` option.\n\nTo perform evaluation of your tool that works with Lua, it may be convenient to write a script that generates a random program and runs your tool over it to check output or return code. You can check an example of such script in the test suite: [run-test.py](./test/run-test.py).\n\nYou can also provide some subtle configuration using a configuration file. By default, moonsmith looks it at `moonsmith.yml`, but you can set the specific file using `-c` command-line option. Using this file you can disable some Lua constructions which your tooling doesn't support yet. See the default config at [moonsmith.yml](./moonsmith.yml).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjubnzv%2Fmoonsmith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjubnzv%2Fmoonsmith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjubnzv%2Fmoonsmith/lists"}