{"id":13846349,"url":"https://github.com/AlexCeleste/Pyrite","last_synced_at":"2025-07-12T07:32:26.593Z","repository":{"id":7372301,"uuid":"8698571","full_name":"AlexCeleste/Pyrite","owner":"AlexCeleste","description":"BASIC-style \"compiler\" as C syntax library","archived":false,"fork":false,"pushed_at":"2013-03-11T07:33:38.000Z","size":116,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-10T01:08:43.883Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexCeleste.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-11T07:32:12.000Z","updated_at":"2023-11-07T10:48:10.000Z","dependencies_parsed_at":"2022-09-22T13:02:38.807Z","dependency_job_id":null,"html_url":"https://github.com/AlexCeleste/Pyrite","commit_stats":null,"previous_names":["leushenko/pyrite"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexCeleste%2FPyrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexCeleste%2FPyrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexCeleste%2FPyrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexCeleste%2FPyrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexCeleste","download_url":"https://codeload.github.com/AlexCeleste/Pyrite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225807248,"owners_count":17527216,"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-08-04T18:00:30.727Z","updated_at":"2024-11-21T21:30:24.348Z","avatar_url":"https://github.com/AlexCeleste.png","language":"C","funding_links":[],"categories":["C language extensions"],"sub_categories":[],"readme":"\n Pyrite:\n A BASIC \"compiler\" implemented entirely using the C macro system\n \n This project is entirely public domain\n (I will not be held responsible for this madness.)\n\nPyrite uses a largish number of C preprocessor macros to build a BASIC-style\nsyntax layer on top of C. It requires a C99-compliant preprocessor (for the\nvariadic macros), and for various reasons will not work with C++ due to the\nnature of the output code. Heavy-duty use of macros means that a powerful\npreprocessor like GCC's will probably give best results.\n\nFeatures:\n  - BASIC-like syntax forms\n  - garbage collection\n  - exceptions\n  - user-defined objects\n  - arrays\n  - string and collection methods (not yet included)\n\nThe project consists of the following files:\n  README : this document\n  pyrite.h : the main include to use, defines BASIC syntax forms\n  pyrite-lib.h : declares the Pyrite runtime functions and other things\n                 (included by pyrite.h)\n  pyrite-lib.c : implements the runtime features declared in pyrite-lib.h;\n                 link against this when compiling\n  cmacros.h : generic metaprogramming library (not directly related to Pyrite)\n  pyrite-project.c : a C \"wrapper\" project file to allow writing whole programs\n                     using only Pyrite source code\n  pyrite-undefs.h : #undef directives for the Pyrite macros most likely to mess\n                    up C code: necessary for writing C after a Pyrite block\n  test.c : an example program that tests actually very little\n  test.pyr : a minimal Pyrite program to demonstrate the project system\n\nYou can compile the test file with:\n  gcc -std=c99 pyrite-lib.c test.c -o test\n\npyrite-project.c is a stub application intended to hide most of the necessary C\nboilerplate so that a program may be presented as though written entirely in\nBASIC. It sets up the GC, puts the command line arguments into a data structure,\nand passes them to a function called MAIN expected to be found in Pyrite code.\nPass the name of your source file to GCC with -DPYRITE_PROJECT=\\\"myFile.pyr\\\"\nand it will include it in the right place. The only concession to the syntax of\nC is that the Pyrite code must still be wrapped in a BASIC() form.\n\nPyrite code may be included in a C file in much the same way: #include the\nsyntax definitions in pyrite.h, enclose Pyrite code in a BASIC() block, and\n#undef the syntax when done using pyrite-undefs.h, as it will otherwise\ninterfere with the ability to write in normal C.\n\n\n Pyrite syntax:\n================\n\nPyrite introduces a number of syntax forms, as follows. Short examples of all\nforms may also be found at the bottom of pyrite.h.\n\nFunction definition:\n\nfunction NAME as (arg0 as TYPE, arg1 as TYPE) of RETTYPE do\n\t// ...\nend\n\nThis form declares a function named NAME, with arguments arg0 and arg1 of type\n'TYPE', returning a value of type RETTYPE. A nullary function takes 'none' as\nits argument list; a void function may have 'void' as its return type.\nThere are also allowances for the initial declaration to more closely resemble\na C function name, but that doesn't play well with the GC.\n\nForward declaration:\n\ndeclare(f6 as (IntF, int) of void,\n\t\tf7 as (Vector3) of int)\n\nForward declarations are required in the same way as in C, if a function is to\nbe used before its point of definition.\nNullary functions must be declared with an empty argument list here.\n\nType declaration:\n\nfunctype(IntF, ((int), void) )\nfunctype(Op, ((float, float), float))\narraytype(IntF)\n\ntype MyType\n\tfield x as int, y as int\n\tfield f as IntF\nendtype\n\nSince variable declaration only works with named types, these forms must be used\nto declare types that can then be attached to variables.\n\n'functype' declares a typedef for a function pointer type: in the above example\nit creates the types 'IntF', for functions that take one int and return void;\nand 'Op', for those that take two floats and return one float.\n\n'arraytype' declares the a type for arrays containing the passed type. So the\nabove example declares a new type named 'IntFArray' that can store IntF values.\n'arraytype' is called automatically by 'type' and 'functype', and is not\ngenerally needed in user code.\n\n'type' declares a record with the given fields. Records are always reference\nobjects and, like strings and arrays, are garbage-collected. Record variables\nmay be null; new values must be created with new(TypeName).\n\nArrays and strings:\n\na = array(int, 10)\nelem(a, 0) = foo\nbar = elem(a, 1)\ns = str(\"foobar\")\n\nArrays are created with the 'array' command, taking a type and a size. Their\nelements are accessed via the 'elem' operation, which is essentially the same as\nC's [] indexing. Strings literals are created using the str() form around a\nconst char, or by using other string functions.\n\nLoops:\n\nwhile condition do\n\t//...\nend\n\nfor x in 0 upto 10 do\n\t//...\nend\n\nfor x in 10 downto 0 do\n\t//...\nend\n\nfor x in 0 to 9 do\n\t//...\nend\n\nfor x in 0 to 10 step 2 do\n\t//...\nend\n\nfor e in list do\n\t//...\nend\n\nrepeat\n\t//...\nforever\n\nrepeat\n\t//...\nuntil (condition)\n\nThere are a number of looping forms available. While loops are similar to their\nC counterparts. Repeat/forever is an infinite loop; repeat/until is similar to\nC's do/while except with a negative condition check. The argument to until must\nbe parenthesized.\n\nThere are several 'for' variants available. The first three all iterate over\nintegers; the upto and downto forms stop short of their target, while 'to'\nwill try to finish *on* the target. The 'to' form may also take an optional\n'step' value (the step is implicitly 1 or -1 when using upto and downto). It\nis also possible to iterate over elements of a collection; for this to work, the\nindex variable must be of the right type, and the collection must support the\n'getIterator', 'hasNext' and 'next' functions (currently this functionality is\nnot complete and Iterator is not defined).\n\nSelection:\n\nif a then b else c\n\nif a do\n\tb()\nelseif c do\n\td()\nelsedo\n\te()\nend\n\nselect x in\n\tcase a, b do\n\t\tprint(a)\n\tcase c, d do\n\t\tprint(d)\n\tdefault\n\t\tprint(0)\nend\n\nThe \"inline\" if form at the top is limited in the same way as a braceless 'if'\nin C: it is not possible for its branches to contain multiple statements. Doing\nso will lead to program errors. Notice that the block-if form requires the use\nof 'elsedo' rather than 'else'. 'select' may be used to select an integer from\na list of options: each is tried in sequence and the case values may be function\ncalls, side-effectful, etc.\n\nExceptions:\n\ntry\n\tsomething()\ncatch(Vector3)\n\thandle((Vector3)exception)\ncatch(string)\n\thandle2((string)exception)\nend\n\nAny record object or array may be \"thrown\" as an exception value. Catch blocks\nselect the appropriate branch by the runtime type of the thrown object. The\nobject is retrieved from the read-only value 'exception' and should be cast to\nthe right type. Exceptions are raised with the 'throw' command. If none of the\ncatch blocks match, the exception will be re-raised (this may cause a program\ncrash if the exception propagates past the outermost level of handlers!).\n\nVariable declaration:\n\nlet\n\ti as int equal 10, j as int equal 20\nend\n\nvar(a as int, b as float)\n\nwith a as int, s as string do\n\twrite(s, a)\nend\n\nApart from function parameters, variables may be declared in three main ways.\n'let' blocks declare variables, assign values (not optional), and add any non-\nprimitive type variables to be tracked by the GC (don't use 'let' within a loop,\nit will cause chaos as well as being slow).\n\n'var' statements simply declare an uninitialised variable slot. These do not\nhook into the GC system and must be added manually with 'gc_trackvar'. These are\nthe main way to declare globals.\n\n'with' blocks create a nested scope level. The variables are added to the GC\nsystem, and will go out of scope at the end of the block, freeing their values\nfor collection if necessary. Note that it is *not* safe to jump out of a 'with'\nblock using break or continue; use return or exceptions.\n\nReturning values:\n\nreturn expr end\n\n'return' works much the same as in plain C, except that its expression must be\nterminated with an explicit 'end'.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexCeleste%2FPyrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAlexCeleste%2FPyrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexCeleste%2FPyrite/lists"}