lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Soft Types System [STS]  Proposal
STS is system of types which implements in the same time both
dynamical and static approach.

(Step 1) Syntax of some constructs should be changed in the following way:

* 'local' declaration:

'local' typename namelist [init]

* 'function' declaration:

function ::= 'function' funcbody
funcbody ::= '(' [parlist1] ')' block 'end'
parlist1 ::=  [typename] Name {',' [typename] Name} [',' '...'] | '...'

(Step 2) API should be widened with function

lua_newstype(lua_State*, const char *typename, lua_STypeInfo *i)

(Step 3) core and API should be widened to support

Semantic of the previous step is following:

in compile time lua code can be optimised by using softtype info, if
compiler have it, otherwise code will be generated in the old-fashioned
way(but some softtype info will be added to compiled chunk to make
it's execution faster). Also some static checks can be done.

For example now the following code
    local a = smth();
compiles into sequence of calls(into smth similar)
    get_local a;
    if isuserdata(top) {
       call __index(top, "getB");
       call top(top-1);                                               (*)
       if isuserdata(top) call __index(top, "getC");
       call top(top-1);                                               (*)
       if isuserdata(top) call __index(top, "print");
       call top(top-1,"Bla-Bla");                                    (*)
And this code can raise error in points (*).
But with softtyping this code may be enhanced in two ways:

* strictly errors checking --- function signature and fields/methods
of userdata are known in compilation time

* faster execution --- code and pseudo will look like
  local TSmthA a = smth();           -- where smth, getB, getC have
  a:getB():getC():print("Bla-Bla"); -- appropriate signature or STS
                                    -- will be disabled

  get_global a;
  call TSmthA::getB(top)
  call TSmthB::getC(top)
  call TSmthC::print(top, "Bla-Bla")

  Where *::* are only indexes in big table.
Any comments?

PS. of course there are some sides of STS to think about, because now
it is based much more on dynamical 'trust-relation' side then on
static checks.

 Antero Vipunen