@@ -15,13 +15,17 @@ std::unordered_map<index_type,data_type> m;
15
15
data_type{index_type} m;
16
16
17
17
// ////////////////////////// BESSER:
18
- MyLang -> C++
19
- int [16 ] -> array<int ,16 >
20
- int [*] -> int * // pointer that can hold an array
21
- int * -> int * // pointer to a single element
22
- int [] -> vector<int >
23
- int [](16 ) -> vector<int >(16 )
24
- int [init:16 ]-> vector<int >(16 )
18
+ MyLang -> C++
19
+ int [16 ] -> array<int ,16 >
20
+ int [*] -> int * // pointer that can hold an array
21
+ int * -> int * // pointer to a single element
22
+ int [] -> vector<int >
23
+ int [](16 ) -> vector<int >(16 )
24
+ int [](16 ,99 ) -> vector<int >(16 ,99 )
25
+ int [init:16 ] -> vector<int >(16 )
26
+ int [reserve:16 ] -> vector<int > then reserve (16 )
27
+ int[>16] -> vector<int> then reserve(16 )
28
+ int[16+] -> vector<int> then reserve(16 )
25
29
26
30
// compatibility, this from C/C++ is possible
27
31
int@[] -> int[];
@@ -90,8 +94,8 @@ unique_ptr<BigOne> blah()
90
94
// attributes
91
95
92
96
linkage = reachability (not accessability)
93
- [extern ,external,global? ] var int i; // extern int i;
94
- [intern,internal,local?] var int j; // static int j;
97
+ [global, extern ,external] var int i; // extern int i;
98
+ [hidden, intern,internal] var int j; // static int j;
95
99
96
100
[virtual (forbidden,discouraged,encouraged,enforced), pod == (virtual =forbidden)]
97
101
class X {
@@ -102,3 +106,232 @@ class X {
102
106
[conversion(auto ,default ,implicit,explicit )]
103
107
ctor ( OTHER other) {...}
104
108
109
+ // rule file myll::magic
110
+ [
111
+ magic_return_val=[ret,result],
112
+ magic_param_val=other,
113
+ magic_param_ref=other,
114
+ magic_param_ptr=that,
115
+ magic_uscore=true ,
116
+ magic_autoindex=true ,
117
+ convert_decl=true ,
118
+ default_on_semicolon=true ,
119
+ support_nullptr=warning,
120
+ class_default=[priv,rule_of_n],
121
+ struct_default=[pub,pod],
122
+ method_default=[instance],
123
+ func_default=[global,pure],
124
+ proc_default=[global],
125
+ unique_pointer=std::unique_ptr,
126
+ shared_pointer=std::shared_ptr,
127
+ weak_pointer=std::weak_ptr,
128
+ // static_array: type@[16], dynamic_array@[],
129
+ static_array=std::array,
130
+ dynamic_array=std::vector,
131
+ ]
132
+ class rule ::myll::magic {}
133
+
134
+ // rule file myll::retro
135
+ [
136
+ magic_return_val=[],
137
+ magic_param_val=[],
138
+ magic_param_ref=[],
139
+ magic_param_ptr=[],
140
+ magic_uscore=false ,
141
+ magic_autoindex=false ,
142
+ convert_decl=false ,
143
+ default_on_semicolon=false ,
144
+ support_nullptr=true ,
145
+ class_default=[priv],
146
+ struct_default=[pub],
147
+ method_default=[],
148
+ func_default=[],
149
+ proc_default=[],
150
+ unique_pointer=std::unique_ptr,
151
+ shared_pointer=std::shared_ptr,
152
+ weak_pointer=std::weak_ptr,
153
+ ]
154
+ class rule ::myll::retro {}
155
+
156
+
157
+ [virtual =encouraged]
158
+ class Test
159
+ {
160
+ field int [*] data;
161
+ field int size, capacity;
162
+
163
+ [dispatch=static , nonvirtual]
164
+ func
165
+ {
166
+ [dispatch=dynamic, virtual ]
167
+ top () => data[size ? size-1 : 0 ];
168
+
169
+ pop () => size && --size;
170
+ }
171
+
172
+ func push ( int val )
173
+ {
174
+ // if(size+1 < capacity)
175
+ data[size] = val;
176
+ ++size;
177
+ }
178
+
179
+ [virtual =inherit]
180
+ class Sub {}
181
+ }
182
+
183
+ top
184
+ [dispatch=dynamic, virtual ] // sets to virtual
185
+ [dispatch=static , nonvirtual] // applies afterwards, notices overlap and discards
186
+ [virtual =encouraged] // applies afterwards, notices overlap and does not disagree
187
+
188
+ pop
189
+ [dispatch=static , nonvirtual] // sets to nonvirtual
190
+ [virtual =encouraged] // applies afterwards, notices overlap and does not disagree
191
+
192
+ push
193
+ [virtual =encouraged] // notices no direct setting, applies virtual
194
+
195
+ different idea
196
+ top
197
+ [virtual =encouraged] on class saves that child funcs by default should be virtual
198
+ [dispatch=static , nonvirtual] on func, receives attr from class // applies afterwards, notices overlap and discards
199
+ [dispatch=dynamic, virtual ] // sets to virtual
200
+
201
+
202
+ shortcut table
203
+ [final ] class => [dispatch=disallow] if no virtual base class
204
+ || [dispatch=final ] if virtual base class
205
+ [pod] class => [dispatch=disallow] => applies [dispatch=static ] func, among other things
206
+ [interface] class => [dispatch=interface]=> applies [dispatch=abstract] func
207
+ [nonvirtual]class => [dispatch=forbid]
208
+ [virtual ] class => [dispatch=basic] => applies [virtual ] dtor
209
+ [static ] class => [storage=onlystatic]
210
+ [instance] class => [storage=onlyinstance]
211
+
212
+ [nonvirtual]func => [dispatch=nonvirtual]
213
+ [abstract] func => [dispatch=virtual , impl=abstract]
214
+ [virtual ] func => [dispatch=virtual ]
215
+ [override ] func => [dispatch=override ]
216
+ [final ] func => [dispatch=final ]
217
+
218
+ [manual] enum => [startcount=nil,counting=manual]
219
+ [] enum => [startcount=0 , counting=increment]
220
+ [enum ] enum => [startcount=0 , counting=increment]
221
+ [flags] enum => [startcount=1 , counting=doubling]
222
+ [enum ] enumval => [startcount=???,counting=increment]
223
+ [flags] enumval => [startcount=???,counting=doubling]
224
+
225
+ [global] var => [storage=static ]
226
+
227
+ Dr K sprach grad über seinen Guru, der sowas ist wie ein Coach...
228
+ und dann dachte ich mir ich mache sowas bei unseren neuen Codern,
229
+ vielleicht sollte ich das auch freiberufich machen.
230
+
231
+ Error ausgeben wenn eine nicht virtuelle klasse implizit zur basisklasse gecastet wird
232
+
233
+
234
+ // h
235
+ extern int j; // visibility external,
236
+ const int k; // visibility internal
237
+ extern const int ek; // visibility external, neet to be extern in h and cpp
238
+ extern const int j; // visibility external,
239
+ class Blah {
240
+ static int i; // storage duration from start to end of program
241
+ int f () { // this member function is dispatched statically
242
+ static int i; // storage duration from first call to end of program
243
+ int j = i; // statically checked that the types are assign-compatible
244
+ }
245
+ };
246
+ // cpp
247
+ static int i; // visibility internal, other TU can not see this, maybe not in header?
248
+ int j;
249
+ int Blah::i = 0 ;
250
+
251
+ // var in global or NS need to specify one of [module], [global,extenal], [hidden,internal]
252
+ // DO NOT rely on linkage internal/hidden, since merged cpp building might copy multiple files together
253
+ // so a cpp file might have two [internal] var int x; and then fail to compile
254
+ // module linkage can fix this, so rather only use [global] and [module]
255
+ [linkage=module] var int mv; // visibility internal, but since we have merged module builds...
256
+ [linkage=module] const int mc; // visibility internal, ... (fusion of all cpp) this might work
257
+ [hidden,intern(al),NOT static ] var int hv; // visibility internal, other TU can not see this
258
+ [hidden,intern(al),NOT static ] const int hc; // visibility internal, other TU can not see this
259
+ [global,extern (al),visible] var int gv; // visibility external / global
260
+ [global,extern (al),visible] const int gc; // visibility external / global
261
+ // NOTE: same for functions
262
+ // unnamed NS provide internal linkage
263
+ class Blah {
264
+ [static ,shared,persist(ant)]
265
+ var int i = 0 ; // storage duration from start to end of program
266
+ func f -> int { // this member function is dispatched statically
267
+ [keep,once,static ,persistant,prevail,retain]
268
+ var int i; // storage duration from first call to end of program
269
+ }
270
+ };
271
+ int Blah::i = 0 ;
272
+
273
+ 4 is not the same as +4
274
+ +4 could be of some type like offset-int , allowing ctors to make a different
275
+ overload based on this .
276
+ e.g. Vec<int >(+4 ) allocates 4 slots more than the default .
277
+ +-4 could be the same for negative numbers (-4 could already be, if the ctor
278
+ handles it differently, but still the original type)
279
+
280
+ how to do explicit template instantiation?
281
+
282
+ Removed in Myll compared to C and C++ (functionality which was only renamed, is not considered removed)
283
+ - preprocessor (instead use attributes, constexpr )
284
+ - the split between implementation and header files (.cpp/.h/.hpp/...)
285
+ - operator ","
286
+ - operator prefix "+" ???
287
+ - typedef (use using instead)
288
+ - non-class enums (use class enum instead)
289
+ - directly declare an object of a newly declared type (struct B {} b;)
290
+ - local classes, structs, enums, and functions inside functions. (lambdas can replace local functions)
291
+ - forward declarations (import what you need from other modules)
292
+ - assignment in expressions
293
+ - throw in expressions
294
+ - goto
295
+ - unsigned long long and a lot of similar names are gone
296
+ - using {} for initialization everywhere (it solves a problem in C++ which Myll does not have)
297
+
298
+
299
+
300
+ struct B {
301
+ float x,y,z;
302
+ };
303
+
304
+ void compute_with_B ( B * b ) {
305
+ ...
306
+ }
307
+
308
+ B b;
309
+ compute_with_B (b);
310
+
311
+ // top solution is exactly the same as bottom
312
+ // you can only use do_with_B with a object B
313
+ // same as with the solution below
314
+
315
+ class B {
316
+ float x,y,z;
317
+ void compute () {
318
+ ...
319
+ }
320
+ };
321
+
322
+ B b;
323
+ b.compute();
324
+
325
+ // Why do I like namespaces and object bound functions?
326
+ SDL_Renderer render;
327
+ SDL_RenderDrawLine (render, ...);
328
+
329
+ // If I analyzed that I have no collision with the name Renderer then I could
330
+ // globally add "using Renderer = SDL::Renderer;"
331
+ // or if I'm crazy even "using namespace SDL;"
332
+ SDL::Renderer render;
333
+ render.DrawLine(...); // working autocompletion and 10 significant chars less to write each line
334
+
335
+ // The code has the same performance as it produces the same binary,
336
+ // assuming that you did not intentionally sabotage DrawLine by making it unnecesarily virtual.
337
+ // This is not about polymorphism.
0 commit comments