[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Soft Types System Proposal
- From: "Bilyk, Alex" <ABilyk@...>
- Date: Tue, 26 Oct 2004 17:46:36 -0700
How would this addess the following.
Say I have a hierarchy of tables linked via __index : A:B:C:D.
Each table has a function such that X:X() is defined for A,B,C,D.
Now I want to write a function alne the lines of
function F(a:A) -- taking one parameter 'a' of type 'A'
a:A()
a:B()
a:C()
a:D()
a:E() -- compile error(1)
end
1. Do you envision your type system handling this case?
2. What would be the syntax to ensure A becomes recognized as a new type with operations A,B,C,D defined for it?
Alex
-----Original Message-----
From: Antero Vipunen [mailto:antero@nsk.ru]
Sent: Saturday, October 23, 2004 8:10 PM
To: Lua list
Subject: Soft Types System Proposal
--------------------------------------------------------------------------------
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
soft-function-signatures.
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();
a:getB():getC():print("Bla-Bla");
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