https://github.com/akalenuk/milasm Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} akalenuk / milasm Public * Notifications * Fork 1 * Star 10 Macros system for CLR IL assembly 10 stars 1 fork Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights akalenuk/milasm This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/a] Use Git or checkout with SVN using the web URL. [gh repo clone akalen] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @akalenuk akalenuk Update README.md ... 86863c0 Apr 4, 2023 Update README.md 86863c0 Git stats * 24 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time README.md Update README.md April 4, 2023 21:53 branching.min Introducing blocks: {{ }} May 2, 2014 16:05 build.cmd Create build.cmd April 19, 2014 18:44 console_input_output.min Introducing blocks: {{ }} May 2, 2014 16:05 hello.il Introducing blocks: {{ }} May 2, 2014 16:05 hello.mil Little cleanup August 20, 2014 21:00 instructions.min Introducing blocks: {{ }} May 2, 2014 16:05 milasm.py Little cleanup August 20, 2014 21:00 View code MILAsm TL&DR An example: hello.il How it works? README.md MILAsm TL&DR This is a readable Assembly dialect made of prolog-like pattern matching macros for CLR ILAsm. Write this: ((write: "Hello, world!")) Instead of that: ldstr "Hello, world!" call void [mscorlib]System.Console::Write (string) The macrosystem is just a proof of concept, but it works: you can build the code, write your own macros, write your own CLR applications. An example: hello.il <> <> <> .assembly extern mscorlib {} .assembly hello { .ver 1:0:1:0 } .module hello.exe .method static void main() cil managed { .maxstack 2 .entrypoint .locals init (int32 a, int32 b) ((write: "Input positive x: ")) ((read line)) ((parse it as int32)) ((store it as local a)) ((check if ((local a)) > ((int32 0)) )) ((if so {{ ((write: "It is positive!\n")) ((load int32 2)) ((store it as local b)) ((write: "x * 2 = ")) ((load local a)) ((load local b)) ((multiply them)) ((write int32)) ((write line: "")) }}else{{ ((write: "It isn't positive.\n")) }} )) ((read line)) ((return)) } This piece of code is a valid ILAsm code with MILAsm macros. Not a mock-up. It reads a number from the console, checks if it's positive, and if it is, returns the double of this number. What's important, you can read the intention from the code yourself even if you don't know any of CLR assembly. The langauge is meant to be both low-level and readable. How it works? Macros are defined in free-form syntax using double square brackets, like this: [[write $type -> call void [mscorlib]System.Console::Write ($type) ]] The macro expansion works like this: the part before the -> is a pattern, and the part after the arrow is the substitution. $type is a macro argument. All the words starting from $ are macro arguments. When a pattern occurs in the code, it's being replaced recursively until no recursive patterns are left. ldstr "Hello!" ((write string)) Becomes: ldstr "Hello!" call void [mscorlib]System.Console::Write (string) Of course, you can multiline the body of a macro like this: [[write: $text -> ldstr $text call void [mscorlib]System.Console::Write (string) ]] And you can make recursive macros: [[write: $text -> ldstr $text ((write string)) ]] And with this new macro, you can turn this: ldstr "Hello!" call void [mscorlib]System.Console::Write (string) To that: ((write: "Hello!")) When you want to write a macro with the block of other macros or some ILAsm code as a macros variable, use double curly brackets: {{ }}. You can make macros for if or for with that. Note that apart from the parenthesis, the syntax of all the macros is non-restricted. Macroexpansion uses primitive Prolog-style pattern-matching with atoms being always separated by space, so you can use almost any symbols in your macro definition. Just remember that all identifiers starting with $ are supposed to be macro variables. And there is one special macro variable: $#. It is a macro expansion for the instance ID. it is intended for branching, so you can make labels like HERE_$#: automatically expanding like HERE_$5: or HERE_$16: or HERE_$192: anew every time the macro expansion is happening. Another feature is file inclusion dedicated to macros only. You can write your macros definitions in the same file your code is, but you can store them elsewhere and then include them with double corner braces like this: <> I didn't want to mess with all CLR infrastructure, so this is not the usual C-style inline. it deliberately works with macros definitions only ignoring all the other text: test code or comments. I'd recommend keeping an extension for these files .min (for "macros include") to avoid mixing them with other code files but this is not an inherent restriction. About Macros system for CLR IL assembly Resources Readme Stars 10 stars Watchers 2 watching Forks 1 fork Releases No releases published Packages 0 No packages published Languages * Python 98.9% * Batchfile 1.1% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.