-
Notifications
You must be signed in to change notification settings - Fork 62
Phantom language possible attributes implementation
Attributes are compile-time properties of variable, value or method/argument.
Some attributes are specifically treated by system, others are user-defined.
const | – | It is checked that corresponding value is constant. It will not be permitted to use such value in situations where it can be changed. Calls to const methods are subject to common sub-expression elimination. |
volatile | – | Any kind of optimizations (for example, common sub-expression elimination) will be forbidden for this value/method. |
synchronized | – | Each access will be locked on class-global semaphore. |
class-local | – | can’t be passed/used outside of class (like private) |
package-local | – | Compiler will generate error if you try to pass such thing to other package’s method somehow. |
user-local | – | Compiler will generate code for runtime checks for passing this data to another user. (User is operating system defined thing.) |
thread-local | – | Compiler will generate code for runtime checks (or do static checks where possible) for passing this data to another thread. |
phantom-public | – | In phantom OS environment this class will be globally accessible. Other classes will be available in package only. |
System attributes are always declared and are global. No attribute can use name of system attribute. User attributes are corresponding to some package.
Class can have attributes too. All methods and objects of that class will have corresponding attributes.
var name : <type-def-expression></type-def-expression> attribute attr_name, const;
Defines variable with attributes “attr_name” and “const”.
var name : <type-def-expression></type-def-expression> @ attr_name, const;
Shortcut for “attribute” keyword is @.
var name : <type-def-expression></type-def-expression> attribute attr_name!;
Exclamation sign marks attribute as required – it means that variable can be passed to method which has corresponding attribute mark.
var name : <type-def-expression></type-def-expression> attribute ~attr_name;
This variable is explicitly not compatible with methods, marked with this attribute.
<method-definition></method-definition> ::=
<type-name></type-name> <method-name></method-name> (<args></args>) [[<integer></integer>]] <attribute-list></attribute-list>
{ <method-body></method-body> }
<args></args> ::= [<arg></arg>]
<arg></arg> ::= … <attribute-list></attribute-list>
<attribute-list></attribute-list> ::= [<attribute></attribute>]
<attribute></attribute> ::= attribute [~]<identifier></identifier>[!]
Example:
string toString( string format attribute const ) attribute const;
Method attribute list is compared against ‘this’ attribute list. Method argument attribute list is compared against passed parameter or expression attribute list. Destination of assignment operator is compared against assigned expression attribute list.
Rules are:
Passed value | ||||
Argument | No attribute | Has attribute | Has attribute! | Has !attribute |
No attribute | Ok | Ok | Forbidden | Ok |
Has attribute | Ok | Ok | Ok | Forbidden |
Has attribute! | Forbidden | Ok | Ok | Forbidden |
Has !attribute | Ok | Forbidden | Forbidden | Ok |
In general, ~attribute means “I don’t have this attribute and counterpart must not have it too”, attribute! means “I have this attribute and counterpart must have it too” and attribute means “I have this attribute but don’t require my counterpart to have it”.
Attribute can (must?) be defined:
attribute .const !-> ;
attribute .volatile + ->! ;
attribute .secure ! * ;
attribute .ru.dz.deprecated *;
Marking attribute with + means that result of any operation will have attribute if any of operands has it. Marking with * means that all operands must have attribute for result to have it too. If attribute is defined with !, all uses of it will define it as required (as if it was given with “!” mark). It is an error to mix attribute! and ~attribute operands in one expression. Attribute with !-> mark will be treated as ! in variable definitions, and ->! – as required in arguments.
By default attributes are multiplicative (‘*’ type) and non-requiring.
It is not possible to find at run time, has some value given attribute, or not.
Examples:
attribute .const !-> * ;
const int i = 10;
class { void index( int arg ); } object;
object.index( i ); // Error! i has required attribute
int j = 15;
class { void index( const int arg ); } cobject;
cobject.index( j ); // Ok
// Ok – because of * value of i+j is not const anymore.
object.index( i+j );
attribute .volatile !-> +;
volatile string vs;
string nvs, result;
// Error! Due to ‘+’ in attribute definition
// result of op is volatile, and requires destination
// to be volatile too because of ‘!->’.
result = nvs+vs;
attribute .secure ->! *;
int a;
class { void use( secure int arg ); } sobject;
subject.use(a); // Error!
secure int a = (@secure) 10; // cast
:: Home :: RoadMap :: History :: ChangeLog :: ScreenShots :: Phantom Developer's Guide