Skip to content

Commit 0943768

Browse files
committed
added thesis\container and improved many tests
added run files for 3 tests
1 parent cfaad3a commit 0943768

File tree

13 files changed

+255
-49
lines changed

13 files changed

+255
-49
lines changed

frontend/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool OldFileFilter( string s ) => s.EndsWith( Path.DirectorySeparatorChar + Exec
239239
process2.Start();
240240
process2.WaitForExit();
241241

242-
Console.WriteLine("Executable finished with exit code {0}", process2.ExitCode);
242+
Console.WriteLine("Executable finished with exit code {0} 0x{0:X8}", process2.ExitCode);
243243

244244
return process2.ExitCode;
245245
}

frontend/frontend.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<WarningsAsErrors>;NU1605;Nullable</WarningsAsErrors>
2424
</PropertyGroup>
2525

26+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
27+
<WarningsAsErrors>;NU1605;Nullable</WarningsAsErrors>
28+
</PropertyGroup>
29+
2630
<ItemGroup>
2731
<ProjectReference Include="..\backend\backend.csproj" />
2832
</ItemGroup>
@@ -67,6 +71,9 @@
6771
<Content Include="tests\mixed\stack_big*.myll">
6872
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6973
</Content>
74+
<Content Include="tests\thesis\container.myll">
75+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76+
</Content>
7077
<Content Include="tests\thesis\main.myll">
7178
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7279
</Content>

frontend/frontend.csproj.DotSettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tests_005Cmixed/@EntryIndexedValue">True</s:Boolean>
3-
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tests_005Cmixed_005Cvalidation/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
3+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tests_005Cmixed_005Cvalidation/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

frontend/tests/mixed/enum.myll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module my_enum; // enum is a keyword ;)...
44

5+
import std_iostream;
6+
57
// prevents unnecessary nesting
68
namespace MyLang;
79

frontend/tests/mixed/main.myll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main( int argc, const char*[] argv ) -> int
2424

2525
while( !message.isEmpty() )
2626
{
27-
cout << (move) message.top();
27+
cout << message.top();
2828
message.pop();
2929
}
3030
cout.flush();

frontend/tests/mixed/stack.myll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Stack<T> {
1717
[priv]:
1818
field {
1919
// only these new array pointers would allow arithmetic and therefore indexing
20-
T[]* _values;
20+
T[*] _values;
2121
int _size, _last;
2222
}
2323
// the compiler could feed some info backwards here,
@@ -29,10 +29,10 @@ class Stack<T> {
2929

3030
[throw] // not supported yet, would make the method not noexcept, currently no method is noexcept but all but [throw] should be
3131
method increase() {
32-
var T[]* t = new T[_size * 2];
32+
var T[*] t = new T[_size * 2];
3333
// same as: for (int i = 0; i < _size; ++i)
3434
do _size times i
35-
t[i] = _values[i] = (9**8);
35+
t[i] = _values[i];
3636
_size *= 2;
3737
// this could drop the [] once we know that _values is an array from analyze step
3838
delete[] _values;

frontend/tests/mixed/testcase.myll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func hans (int a) -> bool => a == 42;
4545
func hansX(int a) -> bool* => new bool();
4646

4747
// TODO: find a way to select which main is gonna be build by module
48-
func main()->int { return test(); }
48+
// HACK: running this will result in a crash with 0xC0000409
49+
func mainX()->int { return test(); }
4950
/*
5051
operator "|" (MyEnum lhs, MyEnum rhs) -> MyEnum
5152
{
@@ -57,7 +58,7 @@ operator "|" (MyEnum lhs, MyEnum rhs) -> MyEnum
5758
*/
5859
namespace MyNS
5960
{
60-
class MyClass
61+
class MyClassX
6162
{
6263
[pub]:
6364
[operators(bitwise),flags]
@@ -115,7 +116,7 @@ namespace MyNamespace
115116
field T::X x_with_typename; // needs typename in C++
116117
field int[5] ary;
117118
// will just be generated as a common ptr in C++
118-
field int[]* ptr_to_ary = &ary;
119+
field int[*] ptr_to_ary = &ary;
119120
// this is a non-arithmetic pointer and will not allow ++, --, +, -, []
120121
field int* ptr_to_int = &ary;
121122
field std::vector<int> vec;

frontend/tests/thesis/container.myll

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Thesis page 19
2+
3+
module MyContainers;
4+
//module main;
5+
6+
import std_iostream;
7+
8+
func main( int argc, char*[] argv ) -> int {
9+
using std, JanSordid::Container;
10+
11+
var MyStack<i8> stack = MyStack<i8>(4);
12+
stack.push( 42 ).push( 23 ).push( 16 ).push( 15 ).push( 8 ).push( 4 );
13+
14+
do 30 times stack.push( 1 );
15+
do 30 times i stack.push( i );
16+
17+
while( !stack.isEmpty() ) {
18+
cout << (int)stack.top() << endl;
19+
stack.pop();
20+
}
21+
return 0;
22+
}
23+
24+
namespace JanSordid::Container;
25+
26+
[rule_of_n=0] // not yet validated
27+
class MyStack<T> {
28+
const usize _default_reserved = 8;
29+
field usize _reserved = _default_reserved;
30+
field usize _size = 0;
31+
field T[]! _data = new T[_reserved]!;
32+
33+
[pub]:
34+
//ctor() : ctor_(_default_reserved) {} // forwarding to other ctor does not work yet
35+
ctor( usize reserved ) {
36+
_reserved = reserved;
37+
_data = new T[_reserved]!;
38+
}
39+
40+
[pure] {
41+
method isEmpty() -> bool => _size == 0;
42+
43+
//[precond(!isEmpty())]
44+
method top() -> T => _data[_size-1];
45+
}
46+
47+
[chain] // when this works, then the return type "-> MyStack&" and return statement "return self;" can be omitted
48+
method push( T val ) -> MyStack& {
49+
if( _size >= _reserved )
50+
grow();
51+
_data[_size] = val;
52+
++_size;
53+
return self;
54+
}
55+
56+
//[precond(!isEmpty())]
57+
method pop() {
58+
--_size;
59+
}
60+
61+
[priv]:
62+
method grow() {
63+
[debug] //
64+
std::cout << "grow\n";
65+
const usize new_reserved = _reserved * 2;
66+
var T[]! new_data = new T[new_reserved]!;
67+
68+
do _size times i {
69+
new_data[i] = _data[i];
70+
}
71+
_reserved = new_reserved;
72+
_data = (move)new_data;
73+
}
74+
}

frontend/tests/thesis/main.myll

Lines changed: 97 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,131 @@ import std_iostream, c_stdlib, std_chrono, std_vector;
33
//#line 68 "../main.myll"
44

55
func stuff() -> int[]! {
6+
var int*[4][8] myArray1; // declare myArray1 as pointer to array 4 of int
7+
var int[8][4]* myArray2; // declare myArray2 as array 4 of pointer to int
8+
var int**! myArray3;
69
var int*[] @[] * asd;
710
var int*! iup2, jup2;
8-
var int@[] a;
9-
}
10-
11-
func main() -> int
12-
{
13-
problem_3311(); // clang++ error: use of undeclared identifier 'problem_3311'
11+
var int@[] a;
1412

15-
return 42;
13+
//return {}; // unsupported still, should be relatively easy
14+
//return int[]!(); // does not work either, grammar change (is this func style cast?)
15+
return std::unique_ptr<int[]>();
1616
}
1717

18-
func problem_3311() {}
18+
namespace problem_3311 {
19+
func main() {
20+
a(); // clang++ error: use of undeclared identifier 'a'
21+
}
22+
func a() {}
23+
}
1924

20-
class problem_3312 {
21-
field int*[4][8] myArray1; // declare myArray1 as pointer to array 4 of int
22-
field int[8][4]* myArray2; // declare myArray2 as array 4 of pointer to int
23-
field int**! myArray3; // declare myArray2 as array 4 of pointer to int
24-
field int myField1;
25-
field int myField2;
26-
field int myField3 = 3;
27-
[static] field int myStatic = 1;
28-
public:
29-
ctor() {
30-
myField1 = 1;
31-
myField2 = 2;
25+
namespace problem_3312 {
26+
class MyClass {
27+
field int myField1;
28+
field int myField2;
29+
field int myField3 = 3;
30+
[static] field int myStatic = 1;
31+
[pub]:
32+
ctor() {
33+
myField1 = 1;
34+
myField2 = 2;
35+
}
36+
method myMethod1() -> int => 1;
37+
[inline] method myMethod2() -> int => 2;
38+
[inline,const] method myMethod3() -> int => 3;
39+
[virtual] method myVirtual() -> int => 4;
3240
}
33-
method myMethod1() -> int => 1;
34-
[inline] method myMethod2() -> int => 2;
35-
[inline,const] method myMethod3() -> int => 3;
36-
[virtual] method myVirtual() -> int => 4;
3741
}
3842

39-
func problem_3313_1<T>() -> int => 0;
40-
func problem_3313_2() -> int => 0;
43+
namespace problem_3313 {
44+
func with_template<T>() -> int => 0;
45+
func without_template() -> int => 0;
46+
}
4147

4248
namespace problem_3321 {
4349
alias a = int;
4450
alias c = int;
45-
func problem_3321() {
51+
func problem() {
4652
var a * b;
4753
const a * b1;
4854
var int a2, b2;
4955
a2 * b2; // clang++ warning: expression result unused [-Wunused-value]
5056
var c d;
51-
var c e1 = c();
57+
var c e1 = c(); // different notation than in thesis
5258
}
5359
// TODO: problem_3321::c should just be c
54-
func e2() -> problem_3321::c {}
60+
func e2() -> problem_3321::c { return 0; }
5561
}
5662

57-
func problem_3322() {
58-
var int i, j;
59-
var int* ip = &i, jp = &j;
60-
var int& ir = i, jr = j;
61-
var int[4] ia, ja;
63+
namespace problem_3322 {
64+
func problem_3322() {
65+
var int i, j;
66+
var int* ip = &i, jp = &j;
67+
var std::unique_ptr<int> iu1, ju1;
68+
var int*! iu2, ju2;
69+
var int& ir = i, jr = j;
70+
var int[10] ia, ja;
71+
}
6272
}
6373

64-
func problem_3323() {
65-
var int[4]* ptr_to_ary_of_4;
66-
var int*[4] ary_of_4_ptrs;
74+
namespace problem_3323 {
75+
func problem_3323() {
76+
var int[4]* ptr_to_ary_of_4;
77+
var int*[4] ary_of_4_ptrs;
78+
}
6779
}
6880

6981
namespace problem_3324 {
70-
func f( int a, int b ) -> void {}
82+
func f( int a, int b )-> void {}
7183
func ff( func*(int,int)->int f) -> void {}
7284
func func_ptr_fun() {
73-
var func(int,int)->void fp = f;
74-
var func*(func*(int,int)->int)->void ffp = ff;
85+
var func*(int,int)->void fp = f;
86+
var func*(func*(int,int)->int)->void ffp = ff;
87+
var int[4]* c; // no func ptr
88+
}
89+
// all func need to be above all var to make this work without 'func_ptr_fun'
90+
// solution, change for out-of-struct but keep like this in-struct?
91+
}
92+
93+
namespace problem_3331 {
94+
class C {
95+
[implicit]
96+
ctor(int i) {}
97+
ctor(float f) {}
98+
//[implicit, disable] // does not work either
99+
//ctor(float f);
100+
[pub]:
101+
//[pub] // does not work yet
102+
[static]
103+
method test() {
104+
var C c1 = C(1); // OK
105+
var C c2 = 2; // OK, man wollte explizit die implizierte Konvertierung von int erlauben
106+
var C c3 = C(3.0f); // OK
107+
var C c4 = 4.0f; // Error, man bekommt standardmäßig nur den float Konstruktor
108+
// NO Error? WTF C++
109+
// 4.0f is converted to int and uses the implicit ctor(int) :facepalm:
110+
}
111+
}
112+
}
113+
114+
namespace problem_3332 {
115+
class C {}
116+
class D1 : C {}
117+
//class D2 : private C {} // private is not a keyword anymore, use attrib?
118+
//class D2 : [priv] C {}
119+
}
120+
121+
namespace problem_3333 {
122+
func test() {
123+
75124
}
76125
}
126+
127+
/*
128+
func main() -> int
129+
{
130+
problem_3331::C::test();
131+
return 42;
132+
}
133+
*/

myll.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ Global
2222
{4D2A02BF-364B-44B4-A375-8AD037BD3239}.Release|Any CPU.ActiveCfg = Release|Any CPU
2323
{4D2A02BF-364B-44B4-A375-8AD037BD3239}.Release|Any CPU.Build.0 = Release|Any CPU
2424
EndGlobalSection
25+
GlobalSection(RiderSharedRunConfigurations) = postSolution
26+
File = run\Thesis.run.xml
27+
File = run\Game of Life.run.xml
28+
File = run\Mixed.run.xml
29+
EndGlobalSection
2530
EndGlobal

run/Game of Life.run.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Game of Life" type="DotNetProject" factoryName=".NET Project">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/frontend/bin/Debug/net5.0/myll.exe" />
4+
<option name="PROGRAM_PARAMETERS" value="-i tests/gol/*.myll -o tests/gol/generated -cr" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/frontend/bin/Debug/net5.0" />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="USE_EXTERNAL_CONSOLE" value="0" />
8+
<option name="USE_MONO" value="0" />
9+
<option name="RUNTIME_ARGUMENTS" value="" />
10+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/frontend/frontend.csproj" />
11+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
12+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
13+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
14+
<option name="PROJECT_KIND" value="DotNetCore" />
15+
<option name="PROJECT_TFM" value="net5.0" />
16+
<method v="2">
17+
<option name="Build" />
18+
</method>
19+
</configuration>
20+
</component>

0 commit comments

Comments
 (0)