-
Notifications
You must be signed in to change notification settings - Fork 0
/
coop_readme.txt
95 lines (90 loc) · 2.76 KB
/
coop_readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Specifications:
All class members should be isolated into a struct
Constructors should be replaced with methods returning the struct
Methods should be replaced with methods taking the struct as a parameter
All references to class members inside the class should be prepended by "this." unless already the case
Object declarations should be replaced by struct declarations
Instance method calls (including constructions) should be replaced by calls to the appropriate function.
Dot-operator prefixes of function calls should be shunted inside as the first argument.
Hence,
---------------------------------------------------------------
class Rectangle(int width, int height, int area) {
Rectangle(int w, int h) {
this.width = w;
this.height = h;
area = width * height;
}
Rectangle halve(int axis) {
if (axis) {
return Rectangle(width, height/2);
} else {
return Rectangle(width/2, height);
}
}
char *string() {
char *string = malloc(100);
sprintf(string, "%i*%i", width, height);
return string;
}
}
int main() {
Rectangle r = Rectangle(10, 20);
Rectangle s = r.halve(1);
printf("%s: %i", s.string(), s.area);
return 0;
}
---------------------------------------------------------------
should become:
---------------------------------------------------------------
struct Rectangle {
int width;
int height;
int area;
}
struct Rectangle Rectangle(int w, int h) {
struct Rectangle this;
this.width = w;
this.height = h;
this.area = this.width * this.height;
return this;
}
struct Rectangle halve(struct Rectangle this, int axis) {
if (axis) {
return Rectangle(this.width, this.height/2);
} else {
return Rectangle(this.width/2, this.height);
}
}
char *string(struct Rectangle this) {
char *string = malloc(100);
sprintf(string, "%i*%i", this.width, this.height);
return string;
}
int main() {
struct Rectangle r = Rectangle(10, 20);
struct Rectangle s = halve(r, 1);
printf("%s: %i", string(s), s.area);
return 0;
}
---------------------------------------------------------------
Notes:
Keywords (should not be used elsewhere): class, this
main() should not be declared inside a class.
Class and object names cannot conflict with any other names or keywords
Nested classes are currently not supported
Classes must be declared before use
Possible future features:
Nested & function-internal classes
Usage before declaration
Unmarked (no "this.") calls to class methods inside other class methods
Better namespacing {
Class names cannot conflict with existing struct or function definitions
Likewise, object names cannot conflict with existing struct instances or variable names
}
Cross-file class usage
Bootstrapped compiler
Error handling
Efficiency notes:
Is reading the entire file ahead of time necessary?
Use buffered/optimized reader?
Faster way to pattern match?