Type declaration, may occur at top level or inside functions: type NameOfType = DefinitionOfType Builtin elementary types see syntax.txt Enum types enum ( E1=v1 E2 E3 ) enum (E1=v1,E2,E3 ...) values are optional. The first value defaults to 0, the following default to previous+1 Should enums allow a none value also? enum ( none=-1 E1 E2 ) Require the "none" value to come first or last? Should enums have a base type? (defaulting to e.g. int) enum byte ( E1 E2 ) Disjoint/error types ref X or enum Y # allowed if enum Y has only small values ( -127..128 ?) # should "none" values be allowed? T or enum Z # allowed if T is unsigned (or a "neither signed/unsigned type") AND enum Z has no non-negative values # should "none" values be allowed? which syntax to use to check if it is an enum value (usually an error) or a reference/integer? (multiple alternatives possible... also, this may be used for optional types also!) alternative 1: rwref File f # no var on variable -> works like "final" in Java if f = open("blabla") { # i.e. = on a disjoint type returns true if it was assigned } else { # ... but how do we access the error code? } alternative 2: # overloaded switch syntax switch open("blabla") { case enum any as error_code { } case File f as file { } } alternative 3: rwref File f = open("blabla") else error_code { } alternative 4: try { rwref File f = open("blabla") } error { # ... but how do we access the error code AND source of error? } alternative 5: try { rwref File f = open("blabla") throw open error_code } catch open, read { # multi catch can be supported # error is available in error_code } alternative 6: rwref File or enum Error f = open("blabla") if f is enum Error { } Struct types struct ( T1 i1 T2 i2 ... ) struct (T1 i1, T2 i2) Class struct types (tagged union) class struct ( SUBCLASS1 ( T1 i1 T1 i2 ... ) SUBCLASS2 ( T1 i1 ... ) ... ) Array type [LEN]T LEN may be a constant expression, or an immutable variable Optional type QUALIFIER? Only applicable on refrences. Maybe on enums also? Reference type ref mergedref ownref (takeown, alloc, etc?) Should we have rwref, woref etc as separate keywords? Type reference enum I struct I QUALIFIER I Qualifiers are things like "ref" etc. If I is a type parameter, then it must follow the rules for generic types. Generic type reference QUALIFIERS I Qualifiers are things like "ref" etc. Parametricized types cannot be stack-allocated or merged - Should we allow enums? E.g. I - Should we have syntax handling for function pointers? E.g. I -- This is needed because data-pointers and function pointers may have different size. -- Generic function types could happen, but is probably not that common. Function types (if we should have function pointers?) - Should pointers be implicit or explicit(and required)? func(T1 arg1...) returns T2 func(T1 arg1...) noreturn Any type (should we have this?) any Only meaningful in pointers (perhaps mainly as "addr any"). Should not accept function pointers, unless written as follows, in which case it only allows function pointers: any func Type qualifiers: var - variable may be modified by us writeonly - we may write but not read from this variable aliased - access in the same thread may occur threaded - other threads may access this variable When should qualifiers affect nested references? Should we have separate keywords for reads and writes for aliased/threaded keywords? This is only needed for "var" data, otherwise it is obvious. And it should mainly be needed when passing a aliased/threaded variable to a function that has less access (either read-only or write-only) - Skip this distinction? And loose some performance, but hopefully not much. Type states, definition: type [STATE1,STATE2...] T = private A type with type states will always be in exactly one of the given type states. Type states, accepted type states for parameter/variable/struct member/etc: T [STATE1,STATE2...] t T [not STATE1,STATE2...] t # leaving a space inbetween (and enforcing it in the compiler) # gives a visual distinction between type states and arrays Type states, required type states to access struct member: MEMBERTYPE STRUCTMEMBER when [STATE1,STATE2...] MEMBERTYPE STRUCTMEMBER when [not STATE1,STATE2...] If the struct type is not in an accepted type state, then the struct member may not be accessed. This can be used for: - uninitialized data - invalidated data - data that may only be accessed when a lock is held(?) (how to validate this? perhaps we can return a new type to access the locked data?) How to distinguish between uninitialized/invalidated data that needs initialization, and unlocked data which just needs to be locked? shared when [Unlocked] int i # access always allowed, and exclusive access when locked int i locked when [Locked] # access only allowed when locked. keeps state between typestate changes Type states, change (expression) EXPR typestate STATE Can we restrict where this should be allowed? Type states, change (function) alternative 1: func work(ref var A[closed->open] a) return xxx alternative 2: func work(ref var A a) return xxx typestate a [STATE1,STATE2...] -> [STATE3] when return == 1 # or something like that...