Skip to content

Commit ae3c719

Browse files
committed
working Decl overhaul
progress on Attributes (global attrs, parent attrs, effective attrs)
1 parent e07514e commit ae3c719

23 files changed

+9547
-5985
lines changed

Documentation/almost_never_auto.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,5 @@ Contrary to C++, the initialization with the = sign can now communicate its type
145145
The new can not deduce ...??
146146

147147

148-
[magic-return-val=ret]
149-
[magic-param-val=other]
150-
[magic-param-ref=other]
151-
[magic-param-ptr=that]
148+
{
149+
"class", "MyClass", ["dispatch=basic"]

Documentation/design_doc_cpp_myll_1.cpp

Lines changed: 242 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ std::unordered_map<index_type,data_type> m;
1515
data_type{index_type} m;
1616

1717
//////////////////////////// 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)
2529

2630
// compatibility, this from C/C++ is possible
2731
int@[] -> int[];
@@ -90,8 +94,8 @@ unique_ptr<BigOne> blah()
9094
// attributes
9195

9296
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;
9599

96100
[virtual(forbidden,discouraged,encouraged,enforced), pod == (virtual=forbidden)]
97101
class X {
@@ -102,3 +106,232 @@ class X {
102106
[conversion(auto,default,implicit,explicit)]
103107
ctor( OTHER other) {...}
104108

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.

backend/Core/Attribute.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
namespace Myll.Core
2+
{
3+
public class Attribute
4+
{
5+
/*
6+
public enum Attribute
7+
{
8+
Auto_Begin,
9+
Auto,
10+
AutoOn,
11+
AutoOff,
12+
AutoExplicit, // if explicitly set to auto
13+
Auto_End,
14+
15+
Preselection_Begin, // for surrounding areas, ranging from never to always
16+
Disallow,
17+
Discourage,
18+
Manual, // Needs to be manually set for every applicable child
19+
Basic, // Basic Support, for dispatch this means adding a virtual dtor
20+
BasicAuto, // Basic Support with auto deduction for overridden methods
21+
Encourage,
22+
Enforce,
23+
Preselection_End,
24+
25+
Yes_Begin,
26+
Yes,
27+
Pure,
28+
Throw,
29+
Virtual,
30+
Override,
31+
Final,
32+
Yes_End,
33+
34+
No_Begin,
35+
No,
36+
ImPure,
37+
NoThrow,
38+
NonVirtual,
39+
No_End,
40+
41+
MultiState_Begin,
42+
Private,
43+
Protected,
44+
Public,
45+
MultiState_End,
46+
}
47+
*/
48+
49+
// TODO merge all of them into one enum?
50+
// or split the category parts off?
51+
public enum Dispatch : byte {
52+
Auto,
53+
54+
Category_Begin,
55+
Forbid, // all child func NonVirtual (unchangable)
56+
Discourage, // all child func NonVirtual
57+
Manual, // all children need explicit specification
58+
Encourage, // all child func Virtual
59+
Enforce, // all child func Virtual (unchangable)
60+
Interface, // all child func Abstract
61+
Basic, // dtor Virtual
62+
Abstract, // dtor PureVirtual but implemented (wtf)
63+
Category_End,
64+
65+
NonVirtual, // Static dispatch, as opposed to Dynamic (Virtual)
66+
67+
Dynamic_Begin,
68+
//Abstract,
69+
Virtual,
70+
Override,
71+
Final,
72+
Dynamic_End,
73+
}
74+
75+
public enum Implementation : byte {
76+
Auto,
77+
Provided, // {...}
78+
Abstract, // = 0
79+
Default, // = default
80+
Forbid, // = delete OR Disable
81+
}
82+
83+
// static storage duration and internal linkage
84+
public enum Storage : byte {
85+
Auto,
86+
87+
Category_Begin,
88+
AllowBoth,
89+
OnlyStatic,
90+
OnlyStatelessStatic,
91+
OnlyInstance,
92+
Category_End,
93+
94+
Static, // Shared, Persistent, Permanent, Always, Continous
95+
Dynamic, // same as Instance?
96+
Instance, // for func, var
97+
Thread, // thread(+static) = internal, thread+extern = external
98+
}
99+
100+
public enum Linkage : byte {
101+
Auto,
102+
None, // visible only in its scope
103+
Internal, // hides between different TU, Hidden, (Static), prefer Module
104+
External, // visible everywhere, Visible, Global
105+
Module, // visible inside the same module, same as Internal for merged compilation
106+
}
107+
108+
public enum Purity : byte {
109+
Auto,
110+
Impure,
111+
Const, // const this
112+
Pure, // const this and global
113+
Constexpr, // same as Pure?
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)