Added support for destructors! This is done by making a void, parameterless member method called destruct which is called when a stack object falls out of scope, if it exists. This is implemented by the generator, in this case CGenerator.
This commit is contained in:
1
tests/destructorTest.expected_results
Normal file
1
tests/destructorTest.expected_results
Normal file
@@ -0,0 +1 @@
|
||||
Hello Destructors!
|
||||
28
tests/destructorTest.krak
Normal file
28
tests/destructorTest.krak
Normal file
@@ -0,0 +1,28 @@
|
||||
import io;
|
||||
|
||||
typedef DestructorPrint {
|
||||
char* myStr;
|
||||
DestructorPrint* construct(char* str) {
|
||||
myStr = str;
|
||||
return this;
|
||||
}
|
||||
void destruct() {
|
||||
println(myStr);
|
||||
}
|
||||
};
|
||||
|
||||
typedef NoDistruction {
|
||||
int a;
|
||||
void dummyFunc() {}
|
||||
};
|
||||
|
||||
void indirPrint() {
|
||||
DestructorPrint testObj.construct("Hello Destructors!");
|
||||
NoDistruction dummy;
|
||||
}
|
||||
|
||||
int main() {
|
||||
indirPrint();
|
||||
return 0;
|
||||
}
|
||||
|
||||
1
tests/emptyBracesFunction.expected_results
Normal file
1
tests/emptyBracesFunction.expected_results
Normal file
@@ -0,0 +1 @@
|
||||
It was nothing
|
||||
9
tests/emptyBracesFunction.krak
Normal file
9
tests/emptyBracesFunction.krak
Normal file
@@ -0,0 +1,9 @@
|
||||
import io;
|
||||
|
||||
void nothing() {}
|
||||
|
||||
int main() {
|
||||
nothing();
|
||||
println("It was nothing");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user