]> ocean-lang.org Git - ocean-D/blob - Ocean-types
updates
[ocean-D] / Ocean-types
1
2 Types have a per-module namespace.
3 This is pre-populated with
4   int i8 i16 uint u8 u64 etc
5   num float f64 f128
6   Bool
7   byte
8   char string
9
10 Types can be added with:
11
12   struct name: content
13   record name: content
14   enum name: content
15   class name: content
16
17  name is optional, and can list (parameters) and /attributes
18
19 Types can be constructed with
20
21    name(args)   parameterized type
22    name^        reference type
23    name[size]   array type
24    (args:: args)  procedure type
25    (args:: type)    function type
26
27
28 The content of struct and record are a list of:
29    fieldname: type
30  or
31    fieldname/attribute: type
32
33  'attribute' can:
34       indicate endianness - bigendian littleendian hostendian
35       'const' ??
36       identify a refcount,
37       protected by a given lock??
38
39  For enum, content is list of
40    name = value
41  where "= value" is optional
42
43 Pointers:
44   to assign a pointer, use foo = stuff
45   to update what the pointer points to, use foo^ = stuff
46   to get a reference to store in a pointer....
47      references are either borrowed or owned.
48      a name defined "type^" is a borrowed reference, a name defined
49      "type@" is owned.
50      borrowed references may be taken of anything, but only remain defined
51      as long as the owner remains defined.
52      owned references can only be taken of ownable objects, and
53      remain indefinitely.
54
55    There are various ways to own an object:
56     - refcount or lock
57     - ownership of a containing object.
58     - ownership provided by class method
59
60 non-type names (vars, constants) can be introduced with
61
62 const prefix: name = value; ...
63 func: name(args::type): statements
64 proc: name(args::result): statements
65
66 main: statements
67 init:
68 exit:
69
70
71 enum name: values
72
73
74 Plan:
75   decide on data structure
76   different types can't really be handled by a big switch now,
77     I probably need and object with function pointers.
78         free_value(), vtype_compat(), val_init(),
79         dup_value(), value_cmp(), print_value(), parse_value()
80
81         parse_value only needed for args - str and num
82         val_init...
83         print_value - only needed for print and code-dump
84         dup_value - needed until pointers can make sense
85         vtype_compat - needed for various things
86         value_cmp - needed until we have object behaviours
87
88   pre-defined
89      Bool
90      int - sizes
91      char
92      string
93   array
94      I think I need to disassociate the type from the storage.
95      So a 'value' is a parsed constant, but something new is needed for
96      the content of a variable.
97   const
98   struct
99
100 ----------
101
102  I currently have an enum of types that is used to test compatability
103  and for propagation.
104  This needs to change .... I guess I need a struct type* What goes in it?
105   - name
106   - scalar/record/struct/array/pointer/func/enum
107   - other details.
108
109  Do I need forward declarations?  Maybe I can just be lazy and
110  require everything to be declared eventually.
111  That isn't sufficient for:
112   - mutually recursive functions
113   - mutually recursive structures
114
115  What about unions ???
116    blend with enum: a tag with fields?
117    struct name:
118      x:int; y:int
119
120      .Bool.true = a:char; b:char
121      .Bool.false = ......
122
123  Are enums just a fancy way of doing 'const'?
124  I could have
125    const: a=1; b=2; c; d
126  which defines module-wide consts.
127  And separately have
128    enum foo: a, b, c
129  which defines consts foo.a foo.b foo.c
130  But I don't really like foo entering the val namespace.
131  If bar:foo, then bar.a could be true/false depending on value of bar.
132  bar.a! could set it??  bar.a=true?
133    var = .foo.a
134
135  How do we allocate new objects?
136    new(type) ???
137    ptrname = new ??
138    new(ptrname)
139    ptrname := new(type)
140
141  Maybe ^= assigns a borrowed reference, and @= assigns an owned reference.
142
143  allocating isn't really a top priority, so I should just focus on
144  non-allocated types.