The Towel Programming Language
W4115 PLT, Fall 2015
Zihang Chen (zc2324) Baochan Zheng (bc2269) Guanlin Chen (gc2666) December 21, 2015
Columbia University
The Towel Programming Language W4115 PLT, Fall 2015 Zihang Chen - - PowerPoint PPT Presentation
The Towel Programming Language W4115 PLT, Fall 2015 Zihang Chen (zc2324) Baochan Zheng (bc2269) Guanlin Chen (gc2666) December 21, 2015 Columbia University Introduction What is Towel anyway? It is ... Stack-based and postfjx-syntaxed
Zihang Chen (zc2324) Baochan Zheng (bc2269) Guanlin Chen (gc2666) December 21, 2015
Columbia University
What is Towel anyway? It is ...
42 !println
2
What does it look like? import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println)
3
Let me do some syntax-highlighting here. import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println)
bind-then forms, import form, export form
4
Let me do some syntax-highlighting here. import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println) Tail recursive function call
bind-then forms, import form, export form
5
Let me do some syntax-highlighting here. import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println) Partial function application
bind-then forms, import form, export form
6
Let me do some syntax-highlighting here. import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println)
supported
7
Let me do some syntax-highlighting here. import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println)
8
Let me do some syntax-highlighting here. import 'std' @ bind Fold-left ,\ Acc Xs Fun, (Xs ?# ift Acc, (Acc Xs #hd Fun Xs #tl Fun` Fold-left@)) also Sum (0 (+` Fold-left /flip)) then ([1 10 11 20] Sum !println)
The above three are what we call words in Towel. A program in Towel is essentially a sentence of words.
9
Towel supports the following type:
→ A constant with a name (see also Erlang atoms)
→ String (one of the Enumerable types)
→ Linked list (one of the Enumerable types)
→ Fixed, random accessible enumerable data type
→ Passing around a piece of code
10
In module Std, you will fjnd ...
!!pop, !!dup, etc.
11
How weave compiles a piece of towel: it ...
tokenizes the source code using a scanner
parses the tokens with a parser
traverses and transforms AST to IR AST (along with some scope analysis that will detect unbound names)
compiles IR AST into bytecode representation Bytecode is runnable via the Towel Virtual Machine!
12
The Towel Virtual Machine is a piece of software that ...
decompiles bytecode to IR AST
interprets the IR AST (essentially an array of instructions) one by
You can use the Extension mechanism to call OCaml functions from within the Towel Virtual Machine! See manual for more detail.
13
feature of Towel.
general-purpose.
A stack-based language is very dynamic due to its unclearness of the data (i.e. type) fmow. A static-typed Towel could be made by analyzing each function’s stack-efgect.
14
15