-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.spice
84 lines (67 loc) · 1.58 KB
/
test.spice
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
type Speak interface {
p sayHello(string);
}
type MakeSound interface {
p makeSound();
}
type Human struct : MakeSound, Speak {
string firstName
string lastName
unsigned int age
}
p Human.ctor(string firstName, string lastName, unsigned int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
p Human.makeSound() {
printf("Sigh...\n");
}
p Human.sayHello(string name) {
printf("Hi, %s!\n", name);
}
type Car struct : MakeSound {
string brand
string model
unsigned int seats
}
p Car.ctor(string brand, string model, unsigned int seats) {
this.brand = brand;
this.model = model;
this.seats = seats;
}
p Car.makeSound() {
printf("Wroom, wroom!\n");
}
type Parrot struct : MakeSound, Speak {
string name
unsigned int age
}
p Parrot.ctor(string name, unsigned int age) {
this.name = name;
this.age = age;
}
p Parrot.makeSound() {
printf("Sqawk!\n");
}
p Parrot.sayHello(string name) {
printf("Hello %s, squawk!\n", name);
}
f<int> main() {
Human human = Human("John", "Doe", 25);
Car car = Car("Toyota", "Corolla", 5);
Parrot parrot = Parrot("Polly", 3);
human.makeSound();
car.makeSound();
parrot.makeSound();
human.sayHello("Jane");
parrot.sayHello("Jane");
return 0;
}
/*import "bootstrap/util/block-allocator";
import "bootstrap/util/memory";
f<int> main() {
DefaultMemoryManager defaultMemoryManager;
IMemoryManager* memoryManager = &defaultMemoryManager;
BlockAllocator<int> allocator = BlockAllocator<int>(memoryManager, 10l);
}*/