This chapter documents important changes in the Tom language that impact running code. We explain how to modify your programs in order to be able to use the last version of Tom.
Representation of lists (FL). The default behaviour of lists is FL. The semantics has changed in case of associative symbol under an other associative symbol.
Gom syntax. The syntax compatibility with Vas is now not available.
The %rule
has been removed. It can be replaced by rules
hooks in
Gom, described in Section 11.2. The syntax for rules is
unchanged, except that ‘where’ clauses are no more supported.
Since rules are integrated into the code generated by Gom, it is no more
possible to short-circuit rule application by calling Java functions
instead of ‘‘’ to built terms.
%include { mustrategy.tom }
should be replace by %include { sl.tom }
Any reference to jjtraveler
or tom.library.strategy.mutraveler
should be replaced by a reference to tom.library.sl
:
import tom.library.strategy.mutraveler.*;
by import tom.library.sl.*;
import jjtraveler.*;
by import tom.library.sl.*;
jjtraveler.Visitable
by tom.library.sl.Visitable
jjtraveler.VisitFailure
by tom.library.sl.VisitFailure
jjtraveler.Visitor
by tom.library.sl.Strategy
jjtraveler.reflective.VisitableVisitor
by tom.library.sl.Strategy
MuStrategy
by Strategy
getPosition()
should be replaced by getEnvironment().getPosition()
apply(...)
should be replaced by visit(...)
or visitLight(...)
, enclosed by a try ... catch(VisitFailure e) ...
Call to MuTraveler.init
should be removed
The backquote for the default strategy in %strategy
could be removed.
Since version 2.4, builtin sorts (int, long, String, etc.) are no longer implicit. The corresponding %include { ... } must be done explicitly.
Since version 2.4, ApiGen and Vas are obsolete. Gom should be used instead.
To avoid ambiguities, since version 2.3, constants should be written using explicit parentheses: a(), nil(), for example. To be coherent, the parentheses have also to be used in the mapping definition:
%op T a() { ... }
Since version 2.3, Tom generate static functions in Java, instead of object methods. This allows to use Tom constructs in the main() function, this improves the efficiency of the generated code, and this makes safer the use of strategies.
To be compatible with the previous version, the –noStatic flag can be used.
In the future, Gom will replace Vas. To make the migration easier, the Gom compiler accepts the Vas syntax. However, there are some minor changes:
Since version 2.2, the mapping definition formalism has been simplified. Therefore, we are no longer able to be fully compatible with the old syntax. Some small and simple modifications have to be performed:
%op T f(T,T) has to be replaced by %op T f(arg1:T,arg2:T), where arg1 and arg2 are slot-names.
The definition of get_slot can be defined by using the previously defined construct get_subterm (the first slot corresponds to the 0−th subterm, second slot to the 1−st subterm, etc.). Thus, for the previous example, we can have:
%op T f(arg1:T, arg2:T) { get_slot(arg1,t) { get_subterm(t,0) } get_slot(arg2,t) { get_subterm(t,1) } }
%op T f(arg1:T, arg2:T) { is_fsym(t) { cmp_fun_sym(get_fun_sym(t), body of the old fsym construct) } get_slot(arg1,t) { get_subterm(t,0) } get_slot(arg2,t) { get_subterm(t,1) } }
As an example, let us consider the following “old” mapping definition:
%typeterm TomTerm { implement { ATermAppl } cmp_fun_sym(t1,t2) { t1 == t2 } get_fun_sym(t) { t.getName() } get_subterm(t, n) { t.getArgument(n) } equals(t1, t2) { t1 == t2 } } %typelist TomList { implement { ATermList } get_fun_sym(t) { ((t instanceof ATermList)?"conc":null) } cmp_fun_sym(t1,t2) { t1 == t2 } equals(l1,l2) { l1 == l2 } get_head(l) { (ATermAppl)l.getFirst() } get_tail(l) { l.getNext() } is_empty(l) { l.isEmpty() } } %op TomTerm a { fsym { "a" } make() { factory.makeAppl(factory.makeAFun("a", 0, false)) } } %op TomTerm f(TomTerm) { fsym { "f" } make(t1) { factory.makeAppl(factory.makeAFun("f", 1, false),t1) } } %oplist TomList conc( TomTerm* ) { fsym { "conc" } make_empty() { factory.makeList() } make_insert(e,l) { l.insert(e) } }
The two first type definitions have to be replaced by:
%typeterm TomTerm { implement { ATermAppl } equals(t1, t2) { t1 == t2 } } %typeterm TomList { implement { ATermList } equals(l1,l2) { l1 == l2 } }
The operator definition can be replaced by the following code:
%op TomTerm a { is_fsym(t) { t.getName() == "a" } make() { factory.makeAppl(factory.makeAFun("a", 0, false)) } } %op TomTerm f(arg:TomTerm) { is_fsym(t) { t.getName() == "f" } get_slot(arg,t) { (TomTerm) t.getArgument(t,0) } make(t1) { factory.makeAppl(factory.makeAFun("f", 1, false),t1) } } %oplist TomList conc( TomTerm* ) { is_fsym(t) { t instanceof ATermList } get_head(l) { (ATermAppl)l.getFirst() } get_tail(l) { l.getNext() } is_empty(l) { l.isEmpty() } make_empty() { factory.makeList() } make_insert(e,l) { l.insert(e) } }
Since version 2.2, the disjunction of patterns construct has become deprecated. It can still be used, but we recommend to use the disjunction of symbols instead. This last construct allows to share patterns which have similar subterms but different head-symbols. Therefore, the construct g(g(a)) ∣ g(h(a)) can be replaced by g( (g ∣ h)(a) ). Since version 2.2, this construct has been extended to support disjunction of symbols which do not have identical signature: only involved slots have to be compatible.
Considering %op T f(arg1:T, arg2:T) and %op T g(arg1:T), it is now possible to write g( (g ∣ f)[arg1=a] ).
To prepare a future extension where variables have to be distinguished from constructors of arity 0, we have turned into error all ambiguities between variables and constructors. As a consequence, a variable cannot any longer have the same name as a constant.
Since version 2.2, ApiGen and Vas have been updated:
The TravelerFactory class has been removed and replaced by a Tom mapping: mutraveler.tom. Therefore, backquote notation has to be used: travelerFactory.Repeat(travelerFactory.OnceBottomUp(rule)) is replaced by ‘Repeat(OnceBottomUp(rule)).
Since version 2.1, the runtime library has been reorganized. Java importations have to be updated according to the following hierarchy:
tom |--- library | |--- adt (datatype definitions) | |--- mapping (predefined mapping) | |--- adt (generated mapping) | |--- plugin (platform tools) | |--- set (to handle sets) | |--- strategy | |--- concurrent (to support parallel strategy) | |--- traversal (generic traversal) | |--- xml (xml tools) | |--- platform (the Tom Plugin Platform, known as Tom server) |--- adt
Since version 2.0, Tom integrates an optimizer which removes unused variable assignments and performs inlining optimizations. In order to make these optimizations correct, the Tom compiler needs to know whether a Tom variable (instantiated by pattern matching) is used or not.
In previous versions of Tom, it was possible to use or re-assign a Tom variable without any particular requirement. Since version 2.0, it is recommended (and needed if you want to use the optimizer) to use the backquote mechanism to retrieve the value of a Tom variable. The syntax of a backquote construct has been modified in the following way:
Since version 2.0, Tom does no longer support predefined builtin sorts, via %typeint, %typestring or %typedouble. Tom comes now with a library of predefined mappings. Among them, int.tom, string.tom and double.tom. In order to use these mappings, the %include construct should be used (i.e. %include{ int.tom } to import the predefined int mapping).