{"id":25885037,"url":"https://github.com/sauldoescode/m","last_synced_at":"2026-03-07T01:02:00.917Z","repository":{"id":279919445,"uuid":"940439591","full_name":"SaulDoesCode/m","owner":"SaulDoesCode","description":"m script does things.. in a way","archived":false,"fork":false,"pushed_at":"2025-02-28T08:18:26.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T14:24:21.006Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"V","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SaulDoesCode.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":"2025-02-28T07:13:49.000Z","updated_at":"2025-02-28T08:18:30.000Z","dependencies_parsed_at":"2025-02-28T14:24:34.232Z","dependency_job_id":"2cc61fc5-1f92-4b4f-9187-f09aef8f951d","html_url":"https://github.com/SaulDoesCode/m","commit_stats":null,"previous_names":["sauldoescode/m"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SaulDoesCode/m","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Fm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Fm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Fm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Fm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SaulDoesCode","download_url":"https://codeload.github.com/SaulDoesCode/m/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Fm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30204452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-03-02T17:20:07.359Z","updated_at":"2026-03-07T01:02:00.886Z","avatar_url":"https://github.com/SaulDoesCode.png","language":"V","funding_links":[],"categories":[],"sub_categories":[],"readme":"M script interpreter implemented in the V programming language. Allows for basic scripting operations, including variable manipulation, file system interactions, arithmetic calculations, conditional logic, and script definitions. The interpreter is designed to be lightweight and extensible, providing a foundation for automating tasks and creating simple command-line tools.\n\n## Features\n\n  * **Variable Assignment:**\n      * String variables: Assign string values to named variables.\n      * Numeric variables: Assign numerical values to named variables, supporting basic arithmetic operations.\n  * **File System Operations:**\n      * **Write File (`i`):** Create or overwrite files with specified content.\n      * **Append to File (`+i`):** Add content to the end of an existing file.\n      * **Move/Rename File (`m`):** Rename or move files.\n      * **Read File to Variable (`o`):** Read the content of a file into a string variable.\n  * **Output to Console (`\u003e`):** Print strings or variable values to the standard output.\n  * **Arithmetic Operations:**\n      * **Addition (`+`):** Add two numbers (either numeric variables or literals).\n      * **Subtraction (`-`):** Subtract two numbers.\n      * **Multiplication (`*`):** Multiply two numbers.\n      * **Division (`/`):** Divide two numbers.\n      * **Exponentiation (`**`):** Raise a number to the power of another.\n      * **Store Result (`#`):** Store the result of the last arithmetic operation (stored in a temporary `=` variable) into a named numeric variable.\n  * **Script Definition and Execution (`~` and `.`):**\n      * Define reusable scripts (macros) using the `~` operator, storing them under a given name.\n      * Execute defined scripts using the `.` operator.\n  * **Conditional Logic (`%`, `=`, `!=`, `;`, `?`, `!`):**\n      * **Toggle `otherwise` Flag (`%`):** Invert the boolean `otherwise` flag.\n      * **Equality Check (`=`):** Set the `otherwise` flag based on the equality of two values.\n      * **Inequality Check (`!=`):** Set the `otherwise` flag based on the inequality of two values.\n      * **Conditional AND (`;`):** Perform a logical AND with the current `otherwise` flag.\n      * **Conditional Execution - If True (`?`):** Execute a script block only if the `otherwise` flag is true.\n      * **Conditional Execution - If False (`!`):** Execute a script block only if the `otherwise` flag is false.\n  * **Looping (Repetition) (`r`):**\n      * Repeat a script a specified number of times.\n  * **Shell Command Execution (`\u003c`):**\n      * Execute shell commands and capture the standard output into the `r` state variable.\n  * **Quoting (`'...'`):**\n      * Use single quotes to treat enclosed text as a single string argument, useful for including spaces and special characters.\n  * **Variable Substitution (`~variable_name`):**\n      * Embed the value of string or numeric variables directly into commands and strings using the `~` prefix.\n\n## Getting Started\n\n### Prerequisites\n\n  * **V Programming Language:** Ensure you have the V programming language installed on your system. You can find installation instructions at [https://vlang.io/](https://www.google.com/url?sa=E\u0026source=gmail\u0026q=https://vlang.io/).\n\n### Compilation and Execution\n\n1.  **Clone the repository (if applicable) or save the code:** Save the provided V code (both `main.m` and the script code) into files, for example, `interpreter.v` and `my_script.m`.\n\n2.  **Compile the interpreter:** Open a terminal in the directory where you saved `interpreter.v` and compile it using the V compiler:\n\n    ```bash\n    v -prod m.v\n    ```\n\n    This will create an executable file named `m` (or `m.exe` on Windows).\n\n3.  **Run the interpreter with a script:** Execute the interpreter, providing the path to your script file (`my_script.m` or similar) using the `-src` flag:\n\n    ```bash\n    ./m -src my_script.m\n    ```\n\n    If you omit the `-src` flag, it defaults to looking for a script named `main.m` in the current directory.\n\n### Studying the Implementation\n\nThe core logic of the interpreter is contained within the `SR` struct and its associated methods in the `interpreter.v` file.\n\n  * **`SR` Struct:**  Represents the interpreter's state, holding variables, scripts, operations, and parsing buffers.\n  * **`munch(src string)`:** The main function responsible for processing the input script string, character by character.\n  * **`interpret(t u8)`:** Handles the interpretation of individual characters, managing quoting, variable substitution, and command parsing.\n  * **`chwok()`:** Processes a \"word\" (separated by spaces or newlines) to identify operations, arguments, or variable declarations.\n  * **`routine(moniker string, f FN, bounds u8)`:**  Registers built-in operations (like `i`, `+`, `\u003e`, etc.) with the interpreter, defining their function (`f`) and expected number of arguments (`bounds`).\n\nThe `main.v` file's `main()` function sets up the interpreter, defines all the standard operations, and then loads and executes the script specified by the `-src` command-line argument.  Reviewing the `main()` function and the `routine` calls is crucial to understanding the available commands and their syntax.\n\n## Language Syntax and Operations\n\nThe script language is word-based and uses a combination of keywords, operators, and variable names.\n\n### Basic Syntax Elements\n\n  * **Words:** Separated by spaces or newlines. Words can be operations, arguments, variable names, or string literals.\n  * **Operations/Keywords:**  Predefined commands like `i`, `+i`, `m`, `o`, `\u003e`, `n`, `+`, `-`, `*`, `/`, `**`, `#`, `~`, `.`, `%`, `=`, `!=`, `;`, `?`, `!`, `r`, `\u003c`.\n  * **String Literals:** Enclosed in single quotes `` `...` ``.  Use `^` to escape a single quote within a quoted string ( `^` becomes `` ` `` inside quotes).\n  * **Numeric Literals:** Numbers (integers and floating-point) without any special delimiters.\n  * **String Variables:** Declared implicitly by assigning a string value. Referenced using `~variable_name` for substitution.\n  * **Numeric Variables:** Declared using `#variable_name` followed by a numeric value on the preceding line. Also referenced using `~variable_name` for substitution.\n  * **Comments:**  There are no explicit comment markers. Text that doesn't conform to operations or variable declarations will be treated as arguments or potentially ignored depending on context.\n\n### Operations and their Syntax\n\nHere's a breakdown of each operation and its syntax:\n\n| Operation     | Syntax                                   | Description                                                                 |\n|---------------|--------------------------------------------|-----------------------------------------------------------------------------|\n| **Write File**  | `i \u003cfilename\u003e \u003ccontent\u003e`                  | Writes `\u003ccontent\u003e` to `\u003cfilename\u003e`, overwriting if the file exists.         |\n| **Append File** | `+i \u003cfilename\u003e \u003ccontent\u003e`                 | Appends `\u003ccontent\u003e` to the end of `\u003cfilename\u003e`.                             |\n| **Move File**   | `m \u003csource_filename\u003e \u003cdestination_filename\u003e` | Moves or renames `\u003csource_filename\u003e` to `\u003cdestination_filename\u003e`.       |\n| **Read File**   | `o \u003cfilename\u003e \u003cvariable_name\u003e`            | Reads the content of `\u003cfilename\u003e` into the string `\u003cvariable_name\u003e`.      |\n| **Print**       | `\u003e \u003cmessage\u003e`                             | Prints `\u003cmessage\u003e` to the console.                                        |\n| **Number Var**  | `\u003cvalue\u003e #\u003cvariable_name\u003e`                | Declares a numeric variable `\u003cvariable_name\u003e` with value `\u003cvalue\u003e`.         |\n| **Addition**    | `+ \u003coperand1\u003e \u003coperand2\u003e`                 | Adds `\u003coperand1\u003e` and `\u003coperand2\u003e`, result in `=` temporary variable.        |\n| **Subtraction** | `- \u003coperand1\u003e \u003coperand2\u003e`                 | Subtracts `\u003coperand2\u003e` from `\u003coperand1\u003e`, result in `=` temporary variable. |\n| **Multiplication**| `* \u003coperand1\u003e \u003coperand2\u003e`                 | Multiplies `\u003coperand1\u003e` and `\u003coperand2\u003e`, result in `=` temporary variable.   |\n| **Division**    | `/ \u003coperand1\u003e \u003coperand2\u003e`                 | Divides `\u003coperand1\u003e` by `\u003coperand2\u003e`, result in `=` temporary variable.      |\n| **Exponent**    | `** \u003cbase\u003e \u003cexponent\u003e`                   | Raises `\u003cbase\u003e` to the power of `\u003cexponent\u003e`, result in `=` temporary variable.|\n| **Store Result**| `# \u003cvariable_name\u003e`                        | Stores the value of the `=` temporary variable into `\u003cvariable_name\u003e`.      |\n| **Define Script**| `~ \u003cscript_name\u003e \u003cscript_content\u003e`        | Defines a script named `\u003cscript_name\u003e` with the content `\u003cscript_content\u003e`. Use `__` for backtick `` ` `` and `##` for underscore `_` in script content definition.|\n| **Run Script**  | `. \u003cscript_name\u003e`                         | Executes the script named `\u003cscript_name\u003e`.                                 |\n| **Toggle %**    | `%`                                        | Toggles the `otherwise` flag.                                            |\n| **Equals**      | `= \u003cvalue1\u003e \u003cvalue2\u003e`                      | Sets `otherwise` flag if `\u003cvalue1\u003e` is equal to `\u003cvalue2\u003e`.                |\n| **Not Equals**  | `!= \u003cvalue1\u003e \u003cvalue2\u003e`                     | Sets `otherwise` flag if `\u003cvalue1\u003e` is not equal to `\u003cvalue2\u003e`.             |\n| **Conditional AND**| `; \u003cvalue1\u003e \u003cvalue2\u003e`                     | Performs conditional AND with `otherwise` flag.                            |\n| **If True**     | `? \u003cscript_block\u003e`                        | Executes `\u003cscript_block\u003e` only if `otherwise` is true.                    |\n| **If False**    | `! \u003cscript_block\u003e`                        | Executes `\u003cscript_block\u003e` only if `otherwise` is false.                   |\n| **Repeat**      | `r \u003crepetitions\u003e \u003cscript_name\u003e`          | Repeats execution of `\u003cscript_name\u003e` `\u003crepetitions\u003e` times.               |\n| **Shell Exec**  | `\u003c \u003ccommand\u003e`                             | Executes `\u003ccommand\u003e` in the shell, output in `r` state variable.             |\n\n\n+l my_tasks `Task A`\n+l my_tasks `Task B`\n+l my_tasks `Task C`\n\nl- my_tasks  // Pop the last task (Task C)\n\u003e `Popped task: ~$` // Print the popped task\n\nl- my_tasks  // Pop again (Task B)\n\u003e `Popped task: ~$`\n\n**Note on Variable Substitution:** Variable substitution using `~variable_name` works within quoted strings and as arguments to operations.\n\n## Examples\n\nThe `main.m` file provides a good example script demonstrating various features:\n\n```m\n50.5 #a\n50.5 #b\n+ a b\n# c\n\n\u003e `~a + ~b = ~c`\n\n2.10 #a\n10.2 #b\n a b\n# c\n\n\u003e `~a ** ~b = ~c`\n\n\u003e `okay`\n\n`yes` moo\n`flowrs can be eaten and are sometimes tasty` yum\n\u003e `there is moo? ~moo`\n\n`hoaw wurl and uuuuu ~moo, also ~yum` s\n`yep` msg\n\n`\u003e ^~s^\n^yep^ moo` rep\n\n\n~ hi `~rep`\n\nr 2 hi\n\n\u003e `there is moo? ~moo`\n\n`rainbow` gravity\n\n\u003c `echo hi`\n\u003e `~r`\n```\n\n**Explanation of `main.m` Example:**\n\n1.  **Numeric Variable Declarations and Addition:**\n\n      * `50.5 #a` and `50.5 #b`: Declare numeric variables `a` and `b` with the value 50.5.\n      * `+ a b`: Adds `a` and `b`, storing the result in the `=` temporary variable.\n      * `# c`: Stores the value from `=` into numeric variable `c`.\n      * `\u003e '~a + ~b = ~c'`: Prints a string showing the calculation and substituted variable values.\n\n2.  **Numeric Variable Declarations and Exponentiation:**\n\n      * Similar to step 1, but performs exponentiation (`**`) instead of addition.\n\n3.  **String Variable Declarations and Output:**\n\n      * `` `yes` moo `` and `` `flowrs can be eaten and are sometimes tasty` yum ``: Declare string variables `moo` and `yum` with the given string values.\n      * `\u003e 'there is moo? ~moo'`: Prints a string, substituting the value of the `moo` variable.\n\n4.  **String Variable Concatenation and Output:**\n\n      * `` `hoaw wurl and uuuuu ~moo, also ~yum` s ``: Declares string variable `s` with a string that includes substitutions for `moo` and `yum`.\n      * `` `yep` msg ``: Declares string variable `msg`.\n      * `` `\u003e ^~s^ ^yep^ moo` rep ``: Declares string variable `rep` holding a string with variable substitutions, using `^` to escape backticks within the quoted string for later correct interpretation.\n\n5.  **Script Definition and Repetition:**\n\n      * `~ hi 'rep'`: Defines a script named `hi` with the content of the `rep` variable (which contains the formatted string from the previous step).\n      * `r 2 hi`: Repeats the execution of the `hi` script 2 times. This will print the string defined in `rep` twice.\n\n6.  **Shell Command Execution:**\n\n      * `` `rainbow` gravity ``: Declares string variable `gravity`. (Unused in this example, likely for demonstration).\n      * `\u003c 'echo hi'`: Executes the shell command `echo hi` and stores the output in the `r` state variable.\n      * `\u003e '~r'`: Prints the content of the `r` state variable, which will be the output of the `echo hi` command (i.e., \"hi\" followed by a newline).\n\n## Limitations and Future Enhancements\n\n  * **Basic Error Handling:** Error handling is minimal. Invalid operations or incorrect syntax may lead to program crashes or unexpected behavior.\n  * **Limited Data Types:**  Primarily supports string and numeric data types. Lists or more complex data structures are not natively supported.\n  * **Simple Control Flow:** Control flow is limited to conditional execution and basic looping. More advanced control structures (like `for` loops or `while` loops) are not implemented.\n  * **No User-Defined Functions (beyond scripts):** Users can define scripts (macros), but not functions with more complex parameter handling or return values.\n  * **Security Considerations:** Executing arbitrary shell commands (`\u003c`) can introduce security risks if the script interpreter is used with untrusted input.\n\n**Potential Future Enhancements:**\n\n  * **Improved Error Handling:** Implement more robust error reporting and handling.\n  * **Expanded Data Types:** Add support for lists, dictionaries, or other data structures.\n  * **More Control Flow Structures:** Implement `for`, `while`, or `if-else` control flow statements.\n  * **User-Defined Functions:** Allow users to define functions with parameters and return values for better code organization and reusability.\n  * **String Manipulation Functions:** Add built-in functions for common string operations (substring, split, join, etc.).\n  * **Input from User:** Implement a mechanism for taking input from the user during script execution.\n\n## Author\n\nSaul van der walt \nsaulvdw@kurshok.space\n\nFeel free to contribute to this project or suggest improvements\\!\n\n## License\n\nCopyleft GNU3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsauldoescode%2Fm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsauldoescode%2Fm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsauldoescode%2Fm/lists"}