see also
- compile time meta programming http://tratt.net/laurie/research/publications/html/tratt__domain_specific_language_implementation_via_compile_time_meta_programming/
Notes feb18
- do we need language and/xor byte code
- exceptions with resume?
- extensions
- compiling or currying (compiletime features)
- oo
- environment? 4 d-Registers: callFrame, obj, class, sys
- multiprocessing ... / operating system
- wie funktionieren interrupts: Exceptions? spontaneous calls? messages?
Differences to AsmL, Lit.Lit#Gur00
- strictly sequential, no parallel updateset
- less typing: function do not have an arity, they just take 0-n arguments
- code is contained in the universe - do we need better syntax for (nested) preprocessor capabilities?
Notation
- S* for a Set S: the set of finite sequences from S. We often will use [], the sequence of length 0
the starting Point
- a set C of constants C ⊇ {true, false, value, key, size, undef, noexpr, nobool, 0, 1, ...} including a sufficiently large prefix of the naturals (for the tupels in the program)
- a set V ⊇ (C ∪ {cf}) the Vocabulary including the Constants and (time dependent) function cf for the current frame
- E the expressions over V - i.e. all the programms using the Vocabulary V
- I the object Identifiers a set big enough for any program, disjoint from any other set used here
- U ⊇ (C ∪ I ∪ E) the Universe (i.e. the base set of the model)
- a Model is an interpretation of the Elements of the Vocabulary as partial functions U* → U. The special value undef is thrown if the program accesses an undefined location
- M: (cf → I) ∪ (I → U* → U): The time dependet (Memory) State of a computation: the current frame is an object and each object is a partial Map from U* to U
Abstract syntax of AWL
Variant with 3 - clarified
A program is simply an expression. E ist the set of all expressions. Given a Vocabulary V, E are the expressions, formed by a finite many application of the following recursive definition of an expression e ∈ E
syntactical definitions | |
---|---|
e | designates an expression |
u | an element from the universe |
v | an element from the vocabulary |
loc = e [ e ] | an location in a map for access or update |
abstract syntax of e | e is any of the following |
v | v( e* ) | evaluation of a function from the vocabulary |
u | a constant (for internal use in the compiler) |
new | creation of a new, empty map |
loc | access to the value at a location of an objectMap, throw undef if not defined |
loc := e | update (or add) the value at a location of an objectMap and return new value for |
loc :- | remove the location from the map return old value or throw undefined |
for loc in e do e | process each defined location in the range of a map, by assigning each key to cf[e] |
e ; e | sequential composition |
while e do e | loop in sequential composition |
if e then e else e | if statement: choose one |
fun e | function definition for later execution |
e ( ( e := e )* ) | call of the function in the first expression with a new frame with the given mappings |
return e | return from a call |
throw e | throw an exception |
try e catch loc handle e | catch exceptions |
concrete syntax
- expression begin
- string, number ==> constant values in u
- name ==> v if defined else ==> cf.name
- .? ==> cf[?]
- vocabulary und call syntax gleich ==> implementierung ohne code change
- zurzeit vocabluary nur unbenannte args, call nur benannte!
Variant with 2 - clarified
A program is simply an expression. E ist the set of all expressions. Given a Vocabulary V, E are the expressions, formed by a finite many application of the following recursive definition of an expression e ∈ E
syntactical definitions | |
---|---|
e | designates an expression |
al = e := e (, e := e)* | assignment list |
u | an element from the universe |
v | an element from the vocabulary |
abstract syntax of e | e is any of the following |
v | v() | v( e (, e)* ) | evaluation of a function from the vocabulary |
const u | a constant (for internal use in the compiler) |
new | creation of a new, empty map |
e [ e ] | access to the value at a location of an objectMap, throw undef if not defined |
e [ al ] | update (or add) the value at a location of an objectMap and return new value |
e [ e :- ] | remove a location from an objectMap and return old value, throw undef if not defined |
for e (=> e)? in e do e | process each defined location in the range of a map, by assigning each key to cf[e] |
e ; e | sequential composition |
while e do e | loop in sequential composition |
if e then e else e | if statement: choose one |
fun e | function definition for later execution |
det e | evaluate e at declaration time: evaluate e and assign the result to a const, if the det nesting level reaches the fun nesting level |
exe e | evalute the expression if it yields an expression execute it, otherwise throw noCode |
e ( al ) | call of the function in the first expression with a new frame with the given mappings |
return e | return from a call |
throw e | throw an exception |
try e catch e handle e | catch exceptions |
Variant with 1-dimensinal maps and as few iterations as possible
A program is simply an expression. E ist the set of all expressions. Given a Vocabulary V, E are the expressions, formed by a finite many application of the following recursive definition of an expression e ∈ E
syntactical definitions | |
---|---|
e | designates an expression |
l = e [ e ] | (update) location: point in the range of an objectMap |
u | an element from the universe |
v | an element from the vocabulary |
abstract syntax of e | e is any of the following |
v | v() | v( e (, e)* ) | evaluation of a function from the vocabulary |
const u | a constant (for internal use in the compiler) |
new | creation of a new, empty map |
l | access to the value at a location of an objectMap, throw undef if not defined |
l := e | update (or add) the value at a location of an objectMap and return new value |
remove l | remove a location from an objectMap and return old value, throw undef if not defined |
all l in e do e | process each defined location in the range a map, by assigning each key to l |
e ; e | sequential composition |
while e do e | loop in sequential composition |
if e then e else e | if statement: choose one |
fun e | function definition for later execution |
call e with e | call of the function in the first expression with the frame in the second |
return e | return from a call |
exe e | evaluate e and assign the result to a const, if the exe nesting level reaches call nesting level |
throw e | throw an exception |
try e catch l by e | catch exceptions |
- ass = e [ a1? (, a1?)* ]
- a1 = e (:- | :-- | ( ( := | :== | :=+) e)?
Variant with mulitdimensional maps and iterations
A program is simple an expression. E ist the set of all expressions. Given a Vocabulary V, E are the expressions, formed by a finite many application of the following recursive definition of an expression e ∈ E
syntactical definitions | |
---|---|
e | designates an expression |
e = e* | designates a finite sequence of expressions, possibly of length 0 |
r = e | point in the range of an objectMap |
l = e[ r ] | (update) location: point in the range of an objectMap |
if = if e then e (elif e then e)* else e | if statement |
abstract syntax of e | e is any of the following |
v(e) | evaluation of a function from the vocabulary |
new (r := e)* | creation of a new object with initialisation |
l | access to the value at a location of an objectMap, throw undef if not defined |
l := e | update (or add) the value at a location of an objectMap and return new value |
remove l | remove a location from an objectMap and return old value, throw undef if not defined |
all e in e do e | process each defined location in the range an object, by updating the fields value, (key, size), (key, 1) ... in the object of the first expression for the evaluation of the last expression |
e ; e | sequential composition |
while e do e | loop in sequential composition |
if | if statement: choose one |
fun e | function definition for later execution |
call e (r := e)* | call of a function |
return e | return from a call |
throw e | throw an exception |
try e catch l if | catch exceptions |
Operational Semantics
The evalution of an expression updates the current state and returns a value, thus we model it by a function S
- S: M × E → M × {normal, return, throw} × U
The middle element say, whether the result has been generated by normal program flow, a return or a throw. We define S recursively.
helper functions
- FN((m1, f1, u1), ..., (mn, fn, un)) := (mk, fk, uk)
- with k ∈ {1..n} and (k = n or fk <> normal) and ∀ j<k: fj = normal
- FE(m, e) = FN(
- (m0, f0) = (m, normal)
- , (mi, fi, u1, ..., ui) with (mi, fi, ui)= S(mi-1, ei) for n >= i > 0
- ) with n = length(e)
- FE(m0, e1, ..., eh) (mk', k″, fk', k″, u1, 1, ..., uk', k″)
- multiple ei are iterated anlogously
- FF(m, k, e1, ... ei) = FF'(m, 1, e1, ... ei) with FF'(m, k, e1, ... ei)
- = if f' <> normal then (m', f', u')
- elif u' = true then (m', f', k)
- elif u' <> false then (m', throw, nobool)
- elif i=1 then (m', f', k+1)
- else FF'(m', k+1, e2, ... ei)
- with (m', f', u') = S(m, e1)
- S(m, v(e)) = if f' <> normal then (m', f', uk) elif v(u1, ... un) is defined then (m″, normal, v(u1, ... un)) else (m', throw, undef) with
- (m', f', u1, ..., uk) = FE(m, e)
- S(m, e'[e]) = if fk <> normal then (mk, fk, uk) elif mn(u', u1, ... un) is defined then (mn, normal,mn(, u', u1, ... un)) else (mn, throw, undef) with
- (m', f', u') = S(m, e')
- (n, k, mk, fk, u1, ..., uk) = if f' <> normal then (length(e), 0, m', f', u') else FE(m', e)
- S(m, e'[e] := e″) = if f″ <> normal then (m″, f″, u″) else (m'″, normal, u″) with
- (n, k, mk, fk, u1, ..., uk) as above
- (m″, f″, u″) = if fk <> normal then (mk, fk, uk) else S(mn, e″)
- m″' = m″ except m'″(e', u1, ..., un) = u″
- S(m, call e e′1 = e1, ..., e′k = ek) = FN(
- (m1, f1, u1) = S(m, e)
- , if u1 ∉ E then (m1, throw, noexpr)
- , (m2, f2, u2) = S(m1, new e′1 = e1, ..., e′k = ek)
- , (m3, f2, u2) with m3 = m2 except m3(cf) = u2
- , (m4, f4, u4) with (m4, g4, u4) = S(m3, u1) and f4 = if g4 = return then normal else g4
- , (m5, f4, u4) with m5 = m4 except m5(cf) = m(cf)
- )
- S(m, all e' in e″ do e) = FN(
- (m', f', u') = S(m, e')
- , (m0, f0, u0) = S(m', e″)
- , ...
- , (mi-1, fi-1, ui-1)
- , (m'i, fi-1, ui-1) with m'i = mi-1 except m'i(u', key, size) = size(ti), m'i(u', key, k) = ti,k for k=1..size(ti) and m'i(u', value) = mi-1(u0, ti) for a tuple ti ∈ U*
- , (mi, fi, ui) = S(m'i, e)
- , ...
- , (mj, fj, uj)
- ) such that all the ti are different and ∩(range(e″ in mi)) ⊆ {t1, ..., tj} ⊆ ∪(range(e″ in mi))
- S(m, try e catch e'[e″] if e1 then e'1 elif e2 then e'2 ... else e'i)
- = if f1 <> throw then (m1, f1, u1) = S(m, e)
- elif f2 <> normal then (m2, f2, u2) = S(m1, e'[e″] := u1)
- elif f3 <> normal then (m3, f3, j) = FF(m2, e1, ..., ei-1)
- elif e'j is missing in syntax then (m3, f1, u1)
- else S(m3, e'j)