Previous Up Next

Chapter 13  Migration Guide

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.

13.1  Migration from 2.3 to 2.4

Builtins

Since version 2.4, builtin sorts (int, long, String, etc.) are no longer implicit. The corresponding %include { ... } must be done explicitly.

Gom, Vas, and ApiGen

Since version 2.4, ApiGen and Vas are obsolete. Gom should be used instead.

13.2  Migration from 2.2 to 2.3

Mapping definition and term notation

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() {
    ...
  }
  


Static functions

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.

From Vas to Gom

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:

13.3  Migration from 2.1 to 2.2

Mapping definition

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: 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) }
  }
  


Disjunction of patterns

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] ).

Variable

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.

Vas

Since version 2.2, ApiGen and Vas have been updated:

Strategy library

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)).

13.4  Migration from 2.0 to 2.1

Tom library

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

Command line options

13.5  Migration from 1.5 to 2.0

New backquote usage

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:

Command line options

Predefined mapping

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).
Previous Up Next