Skip to content

Commit f1f7a5b

Browse files
committed
Stmt grammar and visitor overhaul working
Block -> MultiStmt new const_casts, bit_cast
1 parent a73f7ce commit f1f7a5b

20 files changed

+2018
-3420
lines changed

Documentation/design_doc_cpp_myll_1.cpp

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,33 @@ string[set] -> unordered_set<string>
133133
string[set,16] -> unordered_set<string> // reserve 16 is possible
134134
string[set,<] -> set<string>
135135
string[set,>] -> set<string,greater>
136-
string[<set] -> set<string>
137-
string[>set] -> set<string,greater>
138-
string[<+set] -> set<string>
139-
string[>set] -> set<string,greater>
136+
string[set<] -> set<string>
137+
string[set>] -> set<string,greater>
138+
string[set<+] -> multiset<string>
139+
string[set+>] -> multiset<string,greater>
140140

141141
string[deque] -> deque<string>
142142
string[heap] -> priority_queue<string>
143143
string[list] -> list<string>
144144
string[stack] -> stack<string>
145145

146146
[ // rule file myll::magic
147+
default_defines=[debug,release,assert],
148+
149+
magic_this_ref=[self], // hardcoded right now
150+
magic_this_class=[This,Self],
151+
magic_base_ctor=[base,super],
152+
magic_base_class=[Base,Super],
153+
magic_base_on_multi_inherit=true, // will be the first inherited base
147154
magic_return_val=[ret,result],
148155
magic_param_val=other,
149156
magic_param_ref=other,
150157
magic_param_ptr=that,
151-
magic_uscore=true,
158+
magic_uscore=true, // write_only?
152159
magic_autoindex=true,
160+
magic_flagsenum_zeroval=[None],
153161

162+
narrowing_conversion=false, // also set related C++ compiler warnings as errors to be sure
154163
convert_decl=true,
155164
default_on_semicolon=true,
156165
support_nullptr=warning,
@@ -181,17 +190,22 @@ dynamic_cast=dynamic_cast<T>,
181190
const_cast=const_cast<T>,
182191
reinterpret_cast=reinterpret_cast<T>,
183192
bit_cast=std::bit_cast<T>,
184-
narrowing_conversion=false, // also set related C++ compiler warnings as errors to be sure
185193
]
186194
class rule::myll::magic {}
187195

196+
188197
[ // rule file myll::retro
198+
default_defines=[debug,release,assert],
199+
189200
magic_return_val=[],
190201
magic_param_val=[],
191202
magic_param_ref=[],
192203
magic_param_ptr=[],
193204
magic_uscore=false,
194205
magic_autoindex=false,
206+
magic_flagsenum_zeroval=[None],
207+
208+
narrowing_conversion=true,
195209
convert_decl=false,
196210
default_on_semicolon=false,
197211
support_nullptr=true,
@@ -200,20 +214,22 @@ struct_default=[pub],
200214
method_default=[],
201215
func_default=[],
202216
proc_default=[],
217+
203218
unique_pointer=std::unique_ptr<T>,
204219
shared_pointer=std::shared_ptr<T>,
205220
weak_pointer=std::weak_ptr<T>,
221+
206222
static_array=false,
207223
dynamic_array=false,
208224
static_cast=static_cast<T>,
209225
dynamic_cast=dynamic_cast<T>,
210226
const_cast=const_cast<T>,
211227
reinterpret_cast=reinterpret_cast<T>,
212228
bit_cast=std::bit_cast<T>,
213-
narrowing_conversion=true,
214229
]
215230
class rule::myll::retro {}
216231

232+
217233
[ // rule file myll::madness
218234
unique_pointer=T*,
219235
shared_pointer=T*,
@@ -224,7 +240,7 @@ const_cast=((T)E),
224240
reinterpret_cast=((T)E),
225241
bit_cast=((T)E),
226242
]
227-
class rule::myll::madness {}
243+
class rule::myll::madness : rule::myll::retro {}
228244

229245

230246
[virtual=encouraged]
@@ -273,8 +289,8 @@ top
273289

274290

275291
shortcut table
276-
[final] class => [dispatch=disallow] if no virtual base class
277-
|| [dispatch=final] if virtual base class
292+
[final] class => [dispatch=final] if base class dispatch=virtual
293+
|| [dispatch=disallow] else
278294
[pod] class => [dispatch=disallow] => applies [dispatch=static] func, among other things
279295
[interface] class => [dispatch=interface]=> applies [dispatch=abstract] func
280296
[nonvirtual]class => [dispatch=forbid]
@@ -288,15 +304,27 @@ shortcut table
288304
[override] func => [dispatch=override]
289305
[final] func => [dispatch=final]
290306

291-
[manual] enum => [startcount=nil,counting=manual]
292-
[] enum => [startcount=0, counting=increment]
307+
[manual] enum => [init=nil, iteration=manual]
308+
[] enum => [initval=0, progress=increment]
293309
[enum] enum => [startcount=0, counting=increment]
294-
[flags] enum => [startcount=1, counting=doubling]
295-
[enum] enumval => [startcount=???,counting=increment]
296-
[flags] enumval => [startcount=???,counting=doubling]
310+
[flags] enum => [startval=1, counting=doubling, zeroval=@magic_flagsenum_zeroval]
311+
[enum] enumval => [ counting=increment]
312+
[flags] enumval => [ counting=shift,shifting,leftshift]
297313

298314
[global] var => [storage=static]
299315

316+
[noblock, something_else]
317+
{
318+
// if you want the containing things to apply attribute "something_else",
319+
// but not introduce a block/scope
320+
}
321+
322+
// flags also gets a None=0 by default
323+
[flags]
324+
enum Access { Read, Write, Exec }
325+
// None = 0, Read = 1, Write = 2, Exec = 4
326+
// Maybe also provide a named mask by or'ing all flags
327+
300328
Dr K sprach grad über seinen Guru, der sowas ist wie ein Coach...
301329
und dann dachte ich mir ich mache sowas bei unseren neuen Codern,
302330
vielleicht sollte ich das auch freiberufich machen.
@@ -325,6 +353,7 @@ int Blah::i = 0;
325353
// DO NOT rely on linkage internal/hidden, since merged cpp building might copy multiple files together
326354
// so a cpp file might have two [internal] var int x; and then fail to compile
327355
// module linkage can fix this, so rather only use [global] and [module]
356+
[linkage=module] should be the default
328357
[linkage=module] var int mv; // visibility internal, but since we have merged module builds...
329358
[linkage=module] const int mc; // visibility internal, ... (fusion of all cpp) this might work
330359
[hidden,intern(al),NOT static] var int hv; // visibility internal, other TU can not see this
@@ -359,10 +388,10 @@ Removed in Myll compared to C and C++
359388
- operator ","
360389
- operator prefix "+" ???
361390
- typedef (use "using" instead)
362-
- non-class enums (use "class enum" instead)
363-
- directly declare an object of a newly declared type (struct B{} b;)
391+
- unscoped enums (use "class enum" instead)
392+
- directly declare an object of a newly declared type (e.g. struct B{} b;)
364393
- local classes, structs, enums, and functions inside functions. (lambdas can replace local functions)
365-
- forward declarations (import what you need from other modules)
394+
- forward declarations (order irrelevant, import what you need from other modules)
366395
- assignment in expressions
367396
- throw in expressions
368397
- goto
@@ -420,3 +449,17 @@ render.DrawLine(...); // working autocompletion and 10 significant chars less to
420449
// assuming that you did not intentionally sabotage DrawLine by making it unnecesarily virtual.
421450
// This is not about polymorphism.
422451

452+
453+
var int *? weakPtrToInt;
454+
if(weakPtrToInt)
455+
{
456+
weakPtrToInt->doThings();
457+
}
458+
459+
// myll -> C++
460+
461+
std::weak_ptr<int> weakPtrToInt;
462+
if(std::shared_ptr<int> weakPtrToIntLocked = weakPtrToInt.lock())
463+
{
464+
weakPtrToIntLocked->doThings();
465+
}

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
![image](https://user-images.githubusercontent.com/634372/146655353-6066d0ac-cf61-4445-abd3-0b3d0e311900.png)
22

33
# Myll
4-
IPA: /mʏl/, free from »MyLang«. A saner Programming Language that compiles to C++.
4+
IPA: /mʏl/, free from »MyLang«. A saner Programming Language that compiles to **C++**.
55

66
Created by Jan Reitz. Licence undecided (apparently its open source).
77

8-
## Goals
9-
Give newcomers an easy onboarding with less bad surprises.
10-
11-
Give professionals the comfort of known semantics with less repetition and fewer accidents.
8+
## Goals of this Programming Language
9+
* Provide newcomers an easy onboarding and fewer bad surprises.
10+
* Provide professionals the comfort of known semantics with less repetition and fewer accidents.
1211

1312
## Principles
1413
1. Don't ask the user to repeat themselves

0 commit comments

Comments
 (0)