Skip to content

Execution Mode Semantic

Alexey Kutepov edited this page Sep 26, 2016 · 7 revisions

Morganey Module

Morganey Module is a file that consists of only bindings or loadings. No free terms.

Example:

// numbers.morganey

load math.arithmetic

six := (succ 5)
ten := ((plus 5) 5)

Entry Point

Entry Point is a special binding inside of a Morganey module that has a special name (let it be main). This special name should be bound to an expression that represents the program.

Example:

// main.morganey

load math.arithmetic

main := <lambda-term>

Input Stream

Input Stream, it's a lazy evaluating Church pair encoded list of Church encoded numbers. This Stream represents the Standard Input of the program. The Morganey interpreter is responsible for constructing this list on the fly. The Morganey program can access this Stream only via global input binding which is injected into the scope of the program by the interpreter.

Program Execution

Load Graph

When the Morganey Interpreter is given a file with a program to execute, it starts with building a Load Graph beginning from the file. A Load Graph is graph where vertices are Morganey Modules and the edges are load relations between the modules.

Term Compilation and Execution

The interpreter traverses the Load Graph and collects all of the available bindings from it. Then it compiles the following term

((\binding-var1 .
((\binding-var2 .
((\binding-var3 .
<...>
((\input .          // <-- Input Binding
<...>               // <-- Entry Point 
) 
<input-stream>)
<...>)
binding-value3))
binding-value2))
binding-value1)

and reduces it. The result of reduction is interpreted as the one of the Church encoded structures and printed on the standard output accordingly.

Usage

  • File: input.txt
a
  • File: main.morganey
load prelude

main := plus input 2
  • Execute with
$ sbt "run exe main.morganey"
string: c
$