Skip to content

Commit a73f7ce

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # Documentation/design_doc_cpp_myll_1.cpp
2 parents 54afa06 + f54dec1 commit a73f7ce

File tree

3 files changed

+108
-20
lines changed

3 files changed

+108
-20
lines changed

Documentation/design_doc_cpp_myll_1.cpp

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ data_type{index_type} m;
1616

1717
//////////////////////////// BESSER:
1818
MyLang -> C++
19-
int[16] -> array<int,16>
20-
int[*] -> int * // pointer that can hold an array
2119
int* -> int * // pointer to a single element
20+
int[*] -> int * // pointer that can hold an array
21+
int[16] -> array<int,16>
2222
int[] -> vector<int>
2323
int[](16) -> vector<int>(16)
2424
int[](16,99) -> vector<int>(16,99)
2525
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)
26+
int[reserve:16] -> vector<int>; v.reserve(16)
27+
int[>16] -> vector<int>; v.reserve(16)
28+
int[16+] -> vector<int>; v.reserve(16)
29+
30+
// TODO: find a way to make arrays that can only be indexed by specified enums
2931

3032
// compatibility, this from C/C++ is possible
3133
int@[] -> int[];
@@ -47,6 +49,15 @@ string{}(16) -> unordered_set<string>(16)
4749
string{<} -> set<string>
4850
string{>} -> set<string,greater>
4951

52+
string[set] -> unordered_set<string>
53+
string[set,16] -> unordered_set<string> // reserve 16 if possible
54+
string[set,<] -> set<string>
55+
string[set,>] -> set<string,greater>
56+
string[<set] -> set<string>
57+
string[>set] -> set<string,greater>
58+
string[<+set] -> set<string>
59+
string[>set] -> set<string,greater>
60+
5061
string[deque] -> deque<string>
5162
string[heap] -> priority_queue<string>
5263
string[list] -> list<string>
@@ -106,14 +117,40 @@ class X {
106117
[conversion(auto,default,implicit,explicit)]
107118
ctor( OTHER other) {...}
108119

109-
// rule file myll::magic
110-
[
120+
string[int] -> unordered_map<int,string>
121+
string[int,hasher](16) -> unordered_map<int,string,hasher<int>>(16)
122+
string[int,<] -> map<int,string,less<int>>
123+
string[int,>] -> map<int,string,greater<int>>
124+
string[int,+](16) -> unordered_multimap<int,string>(16)
125+
string[int,<+](16) -> multimap<int,string>(16)
126+
127+
string{} -> unordered_set<string>
128+
string{}(16) -> unordered_set<string>(16)
129+
string{<} -> set<string>
130+
string{>} -> set<string,greater>
131+
132+
string[set] -> unordered_set<string>
133+
string[set,16] -> unordered_set<string> // reserve 16 is possible
134+
string[set,<] -> set<string>
135+
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>
140+
141+
string[deque] -> deque<string>
142+
string[heap] -> priority_queue<string>
143+
string[list] -> list<string>
144+
string[stack] -> stack<string>
145+
146+
[ // rule file myll::magic
111147
magic_return_val=[ret,result],
112148
magic_param_val=other,
113149
magic_param_ref=other,
114150
magic_param_ptr=that,
115151
magic_uscore=true,
116152
magic_autoindex=true,
153+
117154
convert_decl=true,
118155
default_on_semicolon=true,
119156
support_nullptr=warning,
@@ -122,18 +159,33 @@ struct_default=[pub,pod],
122159
method_default=[instance],
123160
func_default=[global,pure],
124161
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,
162+
163+
unique_pointer=std::unique_ptr<T>,
164+
shared_pointer=std::shared_ptr<T>,
165+
weak_pointer=std::weak_ptr<T>,
166+
167+
// static_array: T@[16], dynamic_array: T@[],
168+
static_array=std::array<T,S>,
169+
dynamic_array=std::vector<T>,
170+
ordered_dict=std::map<K,V>, // sorted_dict
171+
unordered_dict=std::unordered_map<K,V>,
172+
ordered_set=std::set<T>,
173+
unordered_set=std::unordered_set<T>,
174+
ordered_multidict=std::multimap<K,V>,
175+
unordered_multidict=std::unordered_multimap<K,V>,
176+
ordered_multiset=std::multiset<T>,
177+
unordered_multiset=std::unordered_multiset<T>,
178+
179+
static_cast=static_cast<T>,
180+
dynamic_cast=dynamic_cast<T>,
181+
const_cast=const_cast<T>,
182+
reinterpret_cast=reinterpret_cast<T>,
183+
bit_cast=std::bit_cast<T>,
131184
narrowing_conversion=false, // also set related C++ compiler warnings as errors to be sure
132185
]
133186
class rule::myll::magic {}
134187

135-
// rule file myll::retro
136-
[
188+
[ // rule file myll::retro
137189
magic_return_val=[],
138190
magic_param_val=[],
139191
magic_param_ref=[],
@@ -148,13 +200,32 @@ struct_default=[pub],
148200
method_default=[],
149201
func_default=[],
150202
proc_default=[],
151-
unique_pointer=std::unique_ptr,
152-
shared_pointer=std::shared_ptr,
153-
weak_pointer=std::weak_ptr,
203+
unique_pointer=std::unique_ptr<T>,
204+
shared_pointer=std::shared_ptr<T>,
205+
weak_pointer=std::weak_ptr<T>,
206+
static_array=false,
207+
dynamic_array=false,
208+
static_cast=static_cast<T>,
209+
dynamic_cast=dynamic_cast<T>,
210+
const_cast=const_cast<T>,
211+
reinterpret_cast=reinterpret_cast<T>,
212+
bit_cast=std::bit_cast<T>,
154213
narrowing_conversion=true,
155214
]
156215
class rule::myll::retro {}
157216

217+
[ // rule file myll::madness
218+
unique_pointer=T*,
219+
shared_pointer=T*,
220+
weak_pointer=T*,
221+
static_cast=((T)E),
222+
dynamic_cast=((T)E),
223+
const_cast=((T)E),
224+
reinterpret_cast=((T)E),
225+
bit_cast=((T)E),
226+
]
227+
class rule::myll::madness {}
228+
158229

159230
[virtual=encouraged]
160231
class Test

backend/Grammar/MyllParser.g4

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,13 @@ threeWay : (relOP | equalOP) COLON expr;
279279
capture : LBRACK args? RBRACK;
280280

281281
// Tier 3
282-
//cast: nothing = static, ? = dynamic, ! = const & reinterpret
282+
//cast: nothing = static_cast
283+
// ? = dynamic_cast
284+
// - = const_cast
285+
// -const = const_cast removing outer const
286+
// -volatile = const_cast removing outer volatile
287+
// ! = std::bit_cast
288+
// !! = reinterpret_cast
283289
// TODO REMOVE THEM ALL, IN CODE TOO
284290
// xxx
285291
//preOpExpr : preOP;
@@ -301,7 +307,10 @@ expr : (idTplArgs SCOPE)+ idTplArgs # ScopedExpr
301307
( COPY // cast that forces a copy?
302308
| MOVE
303309
| FORWARD
304-
| (QM|EM)? typespec ) RPAREN
310+
| MINUS CONST
311+
| MINUS VOLATILE
312+
| (QM|MINUS|EM|EM EM)? typespec
313+
) RPAREN
305314
| SIZEOF
306315
| DELETE ( ary='['']' )?
307316
| preOP

frontend/tests/gol/game_of_life.myll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class GameOfLife
2121
{
2222
var Map2D & dstMap = doubleBufferedMap[currentIndex];
2323

24+
// Exploration: Two nested loops like this?
25+
//do sizeY, sizeX times y, x {}
26+
//do [sizeY, sizeX] times [y, x] {}
27+
//do sizeY times y, sizeX times x {}
28+
//do sizeY times y do sizeX times x {} // should work already
29+
//do( y: sizeY ) times {}
30+
//do( y: sizeY, x: sizeX ) times {}
31+
//do times( y: sizeY, x: sizeX ) {}
2432
do sizeY times y
2533
{
2634
do sizeX times x

0 commit comments

Comments
 (0)