-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.kalem
executable file
·214 lines (154 loc) · 3.73 KB
/
example.kalem
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// required_flag just defines file type,
// for source file it's not required.
!required_flag("source")
#import <ios>
#import <stdstr>
// Disable hash cache checker for test.kalem, etc...
!flag("hash-cache=false")
// Some of Kalem's runtime flags.
!flag("output=testikebabi")
!flag("cpp-standard=c++2a")
!flag("cpp-output=true")
!flag("cpp-sysroot=false")
// default=clang
!flag("cpp-compiler=default")
// Its type is not boolean.
!flag("cpp-flags=false")
!include_dir("./include/libs/")
!include_dir("./")
// TODO: Set STL directory default,
// add 'kalem-stl' runtime flag.
!add_source("test")
// TODO: For STL files, make it automatically.
!add_source("/usr/include/kalem/stl/variables")
!add_source("/usr/include/kalem/stl/math")
!add_source("/usr/include/kalem/stl/tools")
#import <StringTools.hpp>
// import <test.kalem>
#include <test>
// STL files
#include <variables>
#include <math>
#include <tools>
#defn LOWERCASE_A 'a'
#defn UPPERCASE_A 'A'
@my_class class {
~public
@another_my_class_function void {
@print "Hi from my_class!\n"
@print test
@print test_protected
}
~private
string test "Hi from my_class as private member!\n"
~protected
string test_protected "Hi from my_class as protected member!\n"
}
@my_namespace namespace {
@another_my_function(string test) void {
@print "Hi, "
@print test
}
}
@my_function(string name) void {
@print name
}
@my_test_function void {
@print "Test\n"
}
@main int {
string test "[Hello, Kalem!]\n"
str my_str_test "Hello str!\n"
// Kalem does not support class declaring and
// user-defined variables yet.
#my_class myclass;
#i16 int16_test = 16;
#u32 uint32_test = 32;
int _test 10
unsign _test_ 20
@print "String: "
@print test
@print "\nInteger: "
@print _test
@print "\nUnsigned Integer: "
@print _test_
@print "\n"
@my_function("Hi, from Kalem!\n")
@my_test_function
@my_test_function()
#/* You can use directly C++ & C code with # token like this too. */
@my_namespace::another_my_function("Hi, C++!\n")
@test: @print "argc: "
++_test
@print argc
@print "\nargv[argc]: "
@print argv[argc-1]
@print "\n"
if (_test == 11) {
@print "Passed [11]\n"
} elsif (_test != 12) {
@goto test
} els {
@print "Passed : "
@print _test
@print "\n"
}
int i 0
loop {
@print "Hello, world!\n"
i++
if (i == 2) {
break
}
}
// Call C++ namespace directly from Kalem.
#test = stringtools::GetBetweenString(test, "[", "]");
@print "StringTools: "
@print test
@print "\n"
@my_test
@myclass.another_my_class_function()
@print my_str_test
@print "uint32_test : "
@print uint32_test
@print "\n"
@print "int16_test : "
@print int16_test
@print "\n"
@print "factorial(7) : "
@print math::factorial(7)
@print "\n"
@print "log2(32) : "
@print math::binary_log2(32)
@print "\n"
// Base = 10 logarithm
@print "log(32) : "
@print math::log(32,10)
@print "\n"
@print "abs(-2021) : "
@print math::abs(-2021)
@print "\n"
char lowercase_a 'a'
@print "lowercase_a : a\n"
@print "to_upper(lowercase_a) : "
@lowercase_a=tools::toupper(lowercase_a)
@print lowercase_a
@print "\n"
@print "Character: "
switch (lowercase_a) {
~LOWERCASE_A {
@print "LOWERCASE_A"
break
}
~UPPERCASE_A {
@print "UPPERCASE_A"
break
}
~default {
@print "Undefined"
break
}
}
@print "\n"
@return 0
}