Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nooga's full-sized avatar
😎

Marcin Gasperowicz nooga

😎
View GitHub Profile

Modal

The execution in this Modal interpreter revolves around the application of substitution rules to transform the initial program into its final state. This process is iterative, applying rules as long as possible until no more substitutions can be made. The core of the execution process is handled by the rewrite function. Let's break down how execution works, focusing on the rewrite function and related components:

The Rewrite Function

The rewrite function is the heart of the execution process. It iterates over the program, attempting to apply each rule to the program text. If a rule matches and is applied, the program is updated with the substitution, and the process repeats. Here's a simplified overview of how rewrite operates:

static int
def count a = a.length
def not = RT.not;
def Success v s = {value: v, rest: s}
def Fail e s = {error: e, rest: s}
def Fail? e = e.error != ()
def Success? = not @ Fail?
def empty? s = s == () || s == ""
/*
* Parser combinator lib
*/
function is_error(x) {
return typeof x === 'string';
}
function parser(f) {
f.then = function(n, fc) {
➜ Build git:(master) cmake ..
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- The ASM compiler identification is Clang
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
(function () {
var x = (function () {
return f();
})();
function f() {
return 1;
}
return x;
}.call(this));
> Array.prototype.sort.call(x, (a,b) => { console.log(x); return a - b; })
{ '0': 2, '1': 1, '2': 0, '3': -1, '7': -2, '8': -3, length: 9 }
{ '0': 2, '1': 1, '2': 0, '3': -1, '7': -2, '8': -3, length: 9 }
{ '0': 2, '1': 1, '2': 0, '3': -1, '7': -2, '8': -3, length: 9 }
{ '0': 2, '1': 1, '2': 0, '3': -1, '7': -2, '8': -3, length: 9 }
{ '0': 2, '1': 1, '2': 0, '3': -1, '7': -2, '8': -3, length: 9 }
{ '0': -3, '1': -2, '2': -1, '3': 0, '4': 1, '5': 2, length: 9 }
> x = [2,1,0,-1,,,-2,-3]
[ 2, 1, 0, -1, <2 empty items>, -2, -3 ]

Keybase proof

I hereby claim:

  • I am nooga on github.
  • I am xnooga (https://keybase.io/xnooga) on keybase.
  • I have a public key ASCPjSXVwNWTM9qPSD9hPNy6wPkqJyeO71dZvXrZgQYvpAo

To claim this, I am signing this object:

"/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/bin/java" "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=54882:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/charsets.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/localedata.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/sunec.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Applicat
"/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/bin/java" "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=51814:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/charsets.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/localedata.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/sunec.jar:/Applications/IntelliJ IDEA CE.app/Contents/jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Applicat
serial0: serial@90000000 {
compatible = "opencores,uart16550-rtlsvn105", "ns16550a";
reg = <0x90000000 0x100>;
interrupts = <2>;
clock-frequency = <20000000>;
};