{"id":21736385,"url":"https://github.com/kyza/universal-hello-world-compiler","last_synced_at":"2025-04-13T01:56:10.507Z","repository":{"id":241477566,"uuid":"616582346","full_name":"Kyza/universal-hello-world-compiler","owner":"Kyza","description":"Compile any language's Hello World program!","archived":false,"fork":false,"pushed_at":"2023-03-20T17:14:09.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-04-13T01:56:04.459Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kyza.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":"2023-03-20T17:06:53.000Z","updated_at":"2023-03-27T03:36:51.000Z","dependencies_parsed_at":"2024-06-28T12:03:32.905Z","dependency_job_id":null,"html_url":"https://github.com/Kyza/universal-hello-world-compiler","commit_stats":null,"previous_names":["kyza/universal-hello-world-compiler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Funiversal-hello-world-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Funiversal-hello-world-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Funiversal-hello-world-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Funiversal-hello-world-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kyza","download_url":"https://codeload.github.com/Kyza/universal-hello-world-compiler/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654050,"owners_count":21140235,"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":[],"created_at":"2024-11-26T05:18:32.911Z","updated_at":"2025-04-13T01:56:10.486Z","avatar_url":"https://github.com/Kyza.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Universal Hello World Compiler\r\n\r\nUHWC is able to analyze *any* Hello World program and compile it for a multitude of targets.\r\n\r\n## Features\r\n\r\n- [x] Blazingly fast compilation speed.\r\n- [x] Blazingly fast executable speed.\r\n- [x] Memory safety guarueantead.\r\n- [x] Many compilation targets.\r\n- [x] Automatic bug correction.\r\n- [x] Rust.\r\n\r\n## Usage\r\n\r\nYou will need Node, PNPM, and Rust installed.\r\n\r\n```bash\r\n# Install dependencies.\r\npnpm i\r\n\r\n# Build your code!\r\npnpm run build -- ./your_code TARGET\r\n```\r\n\r\nThe first argument is the path to yuor code, and the second is the target. UHWC can compile to any target Rust can, so the target format matches Rust's.\r\n\r\nThe following command compiles `hello_world.c` For Windows.\r\n\r\n```bash\r\npnpm run build -- ./hello_world.c x86_64-pc-windows-msvc\r\n```\r\n\r\n## Examples\r\n\r\n### JavaScript/TypeScript\r\n\r\n```js\r\nconsole.log(\"Hello, world!\");\r\n```\r\n\r\n```bash\r\nHello, world!\r\n```\r\n\r\n### New Languages\r\n\r\nIt even works with new languages!\r\n\r\nFor example, here's a concept language I made just now.\r\n\r\n```dslhn\r\nvdfjnskahfljdskahfdjklsahfjds\r\n```\r\n\r\n```bash\r\nHello, world!\r\n```\r\n\r\nIt correctly compiles even though the compiler has never seen it before!\r\n\r\n### Bug Correction\r\n\r\nUHWC is also able to detect and correct bugs for you!\r\n\r\nHere's an example of this in Rust.\r\n\r\n```rust\r\n/// Copyright (c) 2016 Florent Fayolle\r\n/// \r\n/// Permission is hereby granted, free of charge, to any person obtaining\r\n/// a copy of this software and associated documentation files (the\r\n/// \"Software\"), to deal in the Software without restriction, including\r\n/// without limitation the rights to use, copy, modify, merge, publish,\r\n/// distribute, sublicense, and/or sell copies of the Software, and to\r\n/// permit persons to whom the Software is furnished to do so, subject to\r\n/// the following conditions:\r\n/// \r\n/// The above copyright notice and this permission notice shall be\r\n/// included in all copies or substantial portions of the Software.\r\n/// \r\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\n/// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\n/// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\n/// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r\n/// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r\n/// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r\n/// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n\r\nuse std::io::{self, Write};\r\n\r\nenum Operator {\r\n  Addition,\r\n  Substraction,\r\n  Multiplication,\r\n  Division,\r\n  Modulo\r\n}\r\n\r\nenum OperationElt {\r\n  Operator(Operator),\r\n  Operand(f32)\r\n}\r\n\r\nfn tokenizer(expr: \u0026str) -\u003e Result\u003cVec\u003cOperationElt\u003e, String\u003e {\r\n  expr.split_whitespace()\r\n    .map(|el| {\r\n      match el {\r\n        \"+\" =\u003e Ok(OperationElt::Operator(Operator::Addition)),\r\n        \"-\" =\u003e Ok(OperationElt::Operator(Operator::Substraction)),\r\n        \"*\" =\u003e Ok(OperationElt::Operator(Operator::Multiplication)),\r\n        \"/\" =\u003e Ok(OperationElt::Operator(Operator::Division)),\r\n        \"%\" =\u003e Ok(OperationElt::Operator(Operator::Modulo)),\r\n        operand =\u003e match operand.parse::\u003cf32\u003e() {\r\n          Ok(val) =\u003e Ok(OperationElt::Operand(val)),\r\n          Err(_) =\u003e Err(format!(\"Cannot parse operand \\\"{}\\\"\", operand))\r\n        }\r\n      }\r\n    })\r\n    .into_iter()\r\n    .collect()\r\n}\r\n\r\n/// Evaluates an RPL expression.\r\n///\r\n/// # Examples\r\n/// ````\r\n/// extern crate rpn;\r\n///\r\n/// let result:f32 = rpn::evaluate(\"5 2 +\").unwrap();\r\n/// assert_eq!(result, 7.0);\r\n/// ````\r\n///\r\n/// # Errors\r\n/// This function will return an error in case of bad expression:\r\n///\r\n/// - if it includes an unrecognized operator (recognized ones are +, -, * and /\r\n/// - if it misses an operand (i.e. value)\r\n/// - if it misses an operator\r\npub fn evaluate(expr: \u0026str) -\u003e Result\u003cf32, String\u003e {\r\n  return match tokenizer(expr) {\r\n    Ok(tokens) =\u003e {\r\n      let mut stack:Vec\u003cf32\u003e = Vec::new();\r\n      for token in tokens {\r\n        match token {\r\n          OperationElt::Operator(operator) =\u003e {\r\n            if stack.len() \u003c 2 {\r\n              return Err(\"Unsufficient operands before operator\".to_string());\r\n            }\r\n            let operand2 = stack.pop().expect(\"expected f32 values in stack\");\r\n            let operand1 = stack.pop().expect(\"expected f32 values in stack\");\r\n            let result = match operator {\r\n              Operator::Addition        =\u003e operand1 + operand2,\r\n              Operator::Substraction    =\u003e operand1 - operand2,\r\n              Operator::Multiplication  =\u003e operand1 * operand2,\r\n              Operator::Division        =\u003e operand1 / operand2,\r\n              Operator::Modulo          =\u003e operand1 % operand2\r\n            };\r\n            stack.push(result);\r\n          },\r\n          OperationElt::Operand(val) =\u003e stack.push(val)\r\n        }\r\n      }\r\n      if stack.len() != 1 {\r\n        return Err(\"Remaining untreated operands. Probably missing operator.\".to_string());\r\n      }\r\n      return Ok(stack.pop().expect(\"expected a f32 value remaining in stack\"));\r\n    },\r\n    Err(err) =\u003e Err(err)\r\n  }\r\n}\r\n\r\n#[test]\r\nfn it_adds() {\r\n  let result = evaluate(\"1 2 +\");\r\n  assert_eq!(result.unwrap(), 3.0);\r\n}\r\n\r\n#[test]\r\nfn it_substracts() {\r\n  let result = evaluate(\"1 2 -\");\r\n  assert_eq!(result.unwrap(), -1.0);\r\n}\r\n\r\n#[test]\r\nfn it_multiplies() {\r\n  let result = evaluate(\"6 7 *\");\r\n  assert_eq!(result.unwrap(), 42.0);\r\n}\r\n\r\n#[test]\r\nfn it_divides() {\r\n  let result = evaluate(\"1 2 /\");\r\n  assert_eq!(result.unwrap(), 0.5);\r\n}\r\n\r\n#[test]\r\nfn it_modulos() {\r\n  let result = evaluate(\"4 2 %\");\r\n  assert_eq!(result.unwrap(), 0.0);\r\n}\r\n\r\n#[test]\r\nfn it_evaluates_complex_expressions() {\r\n  // ((1+2) * 8 / (5-1) - 4 % 3) / 2\r\n  let result = evaluate(\"1 2 + 8 * 5 1 - / 4 3 % - 2 /\");\r\n  assert_eq!(result.unwrap(), 2.5);\r\n}\r\n\r\n#[test]\r\nfn it_allows_multiple_shitespaces() {\r\n  let result = evaluate(\"1  2 +\\t3 -\");\r\n  assert_eq!(result.unwrap(), 0.0);\r\n}\r\n\r\n#[test]\r\nfn it_fails_for_unsupported_characters() {\r\n  let result = evaluate(\"1 2 t\");\r\n  assert_eq!(result.unwrap_err(), \"Cannot parse operand \\\"t\\\"\");\r\n}\r\n\r\n#[test]\r\nfn it_fails_for_unsufficient_operands() {\r\n  let result = evaluate(\"1 +\");\r\n  assert_eq!(result.unwrap_err(), \"Unsufficient operands before operator\");\r\n}\r\n\r\n#[test]\r\nfn it_fails_for_unsufficient_operators() {\r\n  let result = evaluate(\"1 2 3 +\");\r\n  assert_eq!(result.unwrap_err(),\r\n    \"Remaining untreated operands. Probably missing operator.\");\r\n}\r\n\r\nfn main() {\r\n  println!(\"Reverse Polish Notation.\");\r\n  println!(\"Type quit to exit\");\r\n\r\n  loop {\r\n    print!(\"\u003e \");\r\n    io::stdout().flush().expect(\"flushing failed\");\r\n    let mut input = String::new();\r\n\r\n    io::stdin().read_line(\u0026mut input)\r\n      .expect(\"failed to read line\");\r\n\r\n    if input.trim() == \"quit\" {\r\n      break;\r\n    }\r\n    let result = evaluate(\u0026input);\r\n    match result {\r\n      Err(err) =\u003e println!(\"Error: {}\", err),\r\n      Ok(res) =\u003e println!(\"{}\", res)\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nAs you can see this program has a syntax error, but UHWC automatically corrects it and compiles!\r\n\r\n```bash\r\nHello, world!\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyza%2Funiversal-hello-world-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyza%2Funiversal-hello-world-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyza%2Funiversal-hello-world-compiler/lists"}