git @ Cat's Eye Technologies Tamsin / master mains / micro-tamsin.tamsin
master

Tree @master (Download .tar.gz)

micro-tamsin.tamsin @masterraw · history · blame

# Interpreter for "Micro-Tamsin", written in Tamsin.
# (see doc/Micro-Tamsin.markdown.)
# Distributed under a BSD-style license; see LICENSE.

# REQUIRES lib/tamsin_scanner.tamsin
# REQUIRES lib/tamsin_parser.tamsin

main = tamsin_parser:parse → AST & tamsin_scanner:skippable & "/" &
       interpret(AST, AST).

interpret(P, program(L)) =
    tamsin_parser:find_production_global('main', 'main', P) → Main &
    interpret(P, Main).

interpret(P, production(N, list(prodbranch(Fs, Ls, E), nil))) = interpret(P, E).

interpret(P, call(prodref('$', 'return'), list(atom(X), nil))) = return X.
interpret(P, call(prodref('$', 'expect'), list(atom(X), nil))) = «X».
interpret(P, call(prodref('$', 'print'), list(atom(X), nil))) = print X.
interpret(P, call(prodref('', N), A)) =
    interpret(P, call(prodref('main', N), A)).
interpret(P, call(prodref(M, N), A)) =
    tamsin_parser:find_production_global(M, N, P) → Prod &
    interpret(P, Prod).

interpret(P, or(L, R)) = interpret(P, L) | interpret(P, R).
interpret(P, and(L, R)) = interpret(P, L) & interpret(P, R).
interpret(P, not(X)) = !interpret(P, X).
interpret(P, while(X)) = {interpret(P, X)}.