paul@167 | 1 | #include <stdlib.h> /* calloc, exit */ |
paul@161 | 2 | #include "types.h" |
paul@161 | 3 | #include "exceptions.h" |
paul@161 | 4 | #include "ops.h" |
paul@161 | 5 | #include "progconsts.h" |
paul@161 | 6 | #include "progops.h" |
paul@161 | 7 | #include "progtypes.h" |
paul@161 | 8 | #include "main.h" |
paul@161 | 9 | |
paul@167 | 10 | /* Native functions. */ |
paul@167 | 11 | |
paul@167 | 12 | __attr __fn_native__exit(__attr __args[]) |
paul@167 | 13 | { |
paul@167 | 14 | #define status (__args[1]) |
paul@167 | 15 | |
paul@167 | 16 | exit(__load_via_object(status.value, __pos___data__).intvalue); |
paul@167 | 17 | return __builtins___none_None; |
paul@167 | 18 | #undef status |
paul@167 | 19 | } |
paul@167 | 20 | |
paul@161 | 21 | __attr __fn_native__is(__attr __args[]) |
paul@161 | 22 | { |
paul@161 | 23 | #define x (__args[1]) |
paul@161 | 24 | #define y (__args[2]) |
paul@161 | 25 | |
paul@161 | 26 | return x.value == y.value ? __builtins___boolean_True : __builtins___boolean_False; |
paul@161 | 27 | #undef x |
paul@161 | 28 | #undef y |
paul@161 | 29 | } |
paul@161 | 30 | |
paul@161 | 31 | __attr __fn_native__is_not(__attr __args[]) |
paul@161 | 32 | { |
paul@161 | 33 | #define x (__args[1]) |
paul@161 | 34 | #define y (__args[2]) |
paul@161 | 35 | |
paul@161 | 36 | return x.value != y.value ? __builtins___boolean_True : __builtins___boolean_False; |
paul@161 | 37 | #undef x |
paul@161 | 38 | #undef y |
paul@161 | 39 | } |
paul@161 | 40 | |
paul@161 | 41 | __attr __fn_native__int_add(__attr __args[]) |
paul@161 | 42 | { |
paul@161 | 43 | #define self (__args[1]) |
paul@161 | 44 | #define other (__args[2]) |
paul@161 | 45 | |
paul@161 | 46 | /* NOTE: To be written. */ |
paul@161 | 47 | return __builtins___none_None; |
paul@161 | 48 | #undef self |
paul@161 | 49 | #undef other |
paul@161 | 50 | } |
paul@161 | 51 | |
paul@161 | 52 | __attr __fn_native__int_sub(__attr __args[]) |
paul@161 | 53 | { |
paul@161 | 54 | #define self (__args[1]) |
paul@161 | 55 | #define other (__args[2]) |
paul@161 | 56 | |
paul@161 | 57 | /* NOTE: To be written. */ |
paul@161 | 58 | return __builtins___none_None; |
paul@161 | 59 | #undef self |
paul@161 | 60 | #undef other |
paul@161 | 61 | } |
paul@161 | 62 | |
paul@161 | 63 | __attr __fn_native__int_mul(__attr __args[]) |
paul@161 | 64 | { |
paul@161 | 65 | #define self (__args[1]) |
paul@161 | 66 | #define other (__args[2]) |
paul@161 | 67 | |
paul@161 | 68 | /* NOTE: To be written. */ |
paul@161 | 69 | return __builtins___none_None; |
paul@161 | 70 | #undef self |
paul@161 | 71 | #undef other |
paul@161 | 72 | } |
paul@161 | 73 | |
paul@161 | 74 | __attr __fn_native__int_div(__attr __args[]) |
paul@161 | 75 | { |
paul@161 | 76 | #define self (__args[1]) |
paul@161 | 77 | #define other (__args[2]) |
paul@161 | 78 | |
paul@161 | 79 | /* NOTE: To be written. */ |
paul@161 | 80 | return __builtins___none_None; |
paul@161 | 81 | #undef self |
paul@161 | 82 | #undef other |
paul@161 | 83 | } |
paul@161 | 84 | |
paul@161 | 85 | __attr __fn_native__int_mod(__attr __args[]) |
paul@161 | 86 | { |
paul@161 | 87 | #define self (__args[1]) |
paul@161 | 88 | #define other (__args[2]) |
paul@161 | 89 | |
paul@161 | 90 | /* NOTE: To be written. */ |
paul@161 | 91 | return __builtins___none_None; |
paul@161 | 92 | #undef self |
paul@161 | 93 | #undef other |
paul@161 | 94 | } |
paul@161 | 95 | |
paul@161 | 96 | __attr __fn_native__int_pow(__attr __args[]) |
paul@161 | 97 | { |
paul@161 | 98 | #define self (__args[1]) |
paul@161 | 99 | #define other (__args[2]) |
paul@161 | 100 | |
paul@161 | 101 | /* NOTE: To be written. */ |
paul@161 | 102 | return __builtins___none_None; |
paul@161 | 103 | #undef self |
paul@161 | 104 | #undef other |
paul@161 | 105 | } |
paul@161 | 106 | |
paul@161 | 107 | __attr __fn_native__int_and(__attr __args[]) |
paul@161 | 108 | { |
paul@161 | 109 | #define self (__args[1]) |
paul@161 | 110 | #define other (__args[2]) |
paul@161 | 111 | |
paul@161 | 112 | /* NOTE: To be written. */ |
paul@161 | 113 | return __builtins___none_None; |
paul@161 | 114 | #undef self |
paul@161 | 115 | #undef other |
paul@161 | 116 | } |
paul@161 | 117 | |
paul@161 | 118 | __attr __fn_native__int_or(__attr __args[]) |
paul@161 | 119 | { |
paul@161 | 120 | #define self (__args[1]) |
paul@161 | 121 | #define other (__args[2]) |
paul@161 | 122 | |
paul@161 | 123 | /* NOTE: To be written. */ |
paul@161 | 124 | return __builtins___none_None; |
paul@161 | 125 | #undef self |
paul@161 | 126 | #undef other |
paul@161 | 127 | } |
paul@161 | 128 | |
paul@161 | 129 | __attr __fn_native__int_xor(__attr __args[]) |
paul@161 | 130 | { |
paul@161 | 131 | #define self (__args[1]) |
paul@161 | 132 | #define other (__args[2]) |
paul@161 | 133 | |
paul@161 | 134 | /* NOTE: To be written. */ |
paul@161 | 135 | return __builtins___none_None; |
paul@161 | 136 | #undef self |
paul@161 | 137 | #undef other |
paul@161 | 138 | } |
paul@161 | 139 | |
paul@161 | 140 | __attr __fn_native__int_rsub(__attr __args[]) |
paul@161 | 141 | { |
paul@161 | 142 | #define self (__args[1]) |
paul@161 | 143 | #define other (__args[2]) |
paul@161 | 144 | |
paul@161 | 145 | /* NOTE: To be written. */ |
paul@161 | 146 | return __builtins___none_None; |
paul@161 | 147 | #undef self |
paul@161 | 148 | #undef other |
paul@161 | 149 | } |
paul@161 | 150 | |
paul@161 | 151 | __attr __fn_native__int_rdiv(__attr __args[]) |
paul@161 | 152 | { |
paul@161 | 153 | #define self (__args[1]) |
paul@161 | 154 | #define other (__args[2]) |
paul@161 | 155 | |
paul@161 | 156 | /* NOTE: To be written. */ |
paul@161 | 157 | return __builtins___none_None; |
paul@161 | 158 | #undef self |
paul@161 | 159 | #undef other |
paul@161 | 160 | } |
paul@161 | 161 | |
paul@161 | 162 | __attr __fn_native__int_rmod(__attr __args[]) |
paul@161 | 163 | { |
paul@161 | 164 | #define self (__args[1]) |
paul@161 | 165 | #define other (__args[2]) |
paul@161 | 166 | |
paul@161 | 167 | /* NOTE: To be written. */ |
paul@161 | 168 | return __builtins___none_None; |
paul@161 | 169 | #undef self |
paul@161 | 170 | #undef other |
paul@161 | 171 | } |
paul@161 | 172 | |
paul@161 | 173 | __attr __fn_native__int_rpow(__attr __args[]) |
paul@161 | 174 | { |
paul@161 | 175 | #define self (__args[1]) |
paul@161 | 176 | #define other (__args[2]) |
paul@161 | 177 | |
paul@161 | 178 | /* NOTE: To be written. */ |
paul@161 | 179 | return __builtins___none_None; |
paul@161 | 180 | #undef self |
paul@161 | 181 | #undef other |
paul@161 | 182 | } |
paul@161 | 183 | |
paul@161 | 184 | __attr __fn_native__int_lt(__attr __args[]) |
paul@161 | 185 | { |
paul@161 | 186 | #define self (__args[1]) |
paul@161 | 187 | #define other (__args[2]) |
paul@161 | 188 | |
paul@161 | 189 | /* NOTE: To be written. */ |
paul@161 | 190 | return __builtins___none_None; |
paul@161 | 191 | #undef self |
paul@161 | 192 | #undef other |
paul@161 | 193 | } |
paul@161 | 194 | |
paul@161 | 195 | __attr __fn_native__int_gt(__attr __args[]) |
paul@161 | 196 | { |
paul@161 | 197 | #define self (__args[1]) |
paul@161 | 198 | #define other (__args[2]) |
paul@161 | 199 | |
paul@161 | 200 | /* NOTE: To be written. */ |
paul@161 | 201 | return __builtins___none_None; |
paul@161 | 202 | #undef self |
paul@161 | 203 | #undef other |
paul@161 | 204 | } |
paul@161 | 205 | |
paul@161 | 206 | __attr __fn_native__int_eq(__attr __args[]) |
paul@161 | 207 | { |
paul@161 | 208 | #define self (__args[1]) |
paul@161 | 209 | #define other (__args[2]) |
paul@161 | 210 | |
paul@161 | 211 | /* NOTE: To be written. */ |
paul@161 | 212 | return __builtins___none_None; |
paul@161 | 213 | #undef self |
paul@161 | 214 | #undef other |
paul@161 | 215 | } |
paul@161 | 216 | |
paul@161 | 217 | __attr __fn_native__str_add(__attr __args[]) |
paul@161 | 218 | { |
paul@161 | 219 | #define self (__args[1]) |
paul@161 | 220 | #define other (__args[2]) |
paul@161 | 221 | |
paul@161 | 222 | /* NOTE: To be written. */ |
paul@161 | 223 | return __builtins___none_None; |
paul@161 | 224 | #undef self |
paul@161 | 225 | #undef other |
paul@161 | 226 | } |
paul@161 | 227 | |
paul@161 | 228 | __attr __fn_native__str_lt(__attr __args[]) |
paul@161 | 229 | { |
paul@161 | 230 | #define self (__args[1]) |
paul@161 | 231 | #define other (__args[2]) |
paul@161 | 232 | |
paul@161 | 233 | /* NOTE: To be written. */ |
paul@161 | 234 | return __builtins___none_None; |
paul@161 | 235 | #undef self |
paul@161 | 236 | #undef other |
paul@161 | 237 | } |
paul@161 | 238 | |
paul@161 | 239 | __attr __fn_native__str_gt(__attr __args[]) |
paul@161 | 240 | { |
paul@161 | 241 | #define self (__args[1]) |
paul@161 | 242 | #define other (__args[2]) |
paul@161 | 243 | |
paul@161 | 244 | /* NOTE: To be written. */ |
paul@161 | 245 | return __builtins___none_None; |
paul@161 | 246 | #undef self |
paul@161 | 247 | #undef other |
paul@161 | 248 | } |
paul@161 | 249 | |
paul@161 | 250 | __attr __fn_native__str_eq(__attr __args[]) |
paul@161 | 251 | { |
paul@161 | 252 | #define self (__args[1]) |
paul@161 | 253 | #define other (__args[2]) |
paul@161 | 254 | |
paul@161 | 255 | /* NOTE: To be written. */ |
paul@161 | 256 | return __builtins___none_None; |
paul@161 | 257 | #undef self |
paul@161 | 258 | #undef other |
paul@161 | 259 | } |
paul@161 | 260 | |
paul@161 | 261 | __attr __fn_native__str_len(__attr __args[]) |
paul@161 | 262 | { |
paul@161 | 263 | #define self (__args[1]) |
paul@161 | 264 | |
paul@161 | 265 | /* NOTE: To be written. */ |
paul@161 | 266 | return __builtins___none_None; |
paul@161 | 267 | #undef self |
paul@161 | 268 | } |
paul@161 | 269 | |
paul@161 | 270 | __attr __fn_native__str_nonempty(__attr __args[]) |
paul@161 | 271 | { |
paul@161 | 272 | #define self (__args[1]) |
paul@161 | 273 | |
paul@161 | 274 | /* NOTE: To be written. */ |
paul@161 | 275 | return __builtins___none_None; |
paul@161 | 276 | #undef self |
paul@161 | 277 | } |
paul@161 | 278 | |
paul@161 | 279 | __attr __fn_native__list_init(__attr __args[]) |
paul@161 | 280 | { |
paul@161 | 281 | #define size (__args[1]) |
paul@161 | 282 | /* size.__data__ interpreted as int */ |
paul@161 | 283 | __fragment *data = calloc(__load_via_object(size.value, __pos___data__).intvalue, sizeof(__attr)); |
paul@161 | 284 | __attr attr = {0, .data=data}; |
paul@161 | 285 | |
paul@161 | 286 | return attr; |
paul@161 | 287 | #undef size |
paul@161 | 288 | } |
paul@161 | 289 | |
paul@161 | 290 | __attr __fn_native__list_len(__attr __args[]) |
paul@161 | 291 | { |
paul@161 | 292 | #define self (__args[1]) |
paul@161 | 293 | |
paul@161 | 294 | /* NOTE: To be written. */ |
paul@161 | 295 | return __builtins___none_None; |
paul@161 | 296 | #undef self |
paul@161 | 297 | } |
paul@161 | 298 | |
paul@161 | 299 | __attr __fn_native__list_nonempty(__attr __args[]) |
paul@161 | 300 | { |
paul@161 | 301 | #define self (__args[1]) |
paul@161 | 302 | |
paul@164 | 303 | return __load_via_object(self.value, __pos___data__).data->size ? __builtins___boolean_True : __builtins___boolean_False; |
paul@161 | 304 | #undef self |
paul@161 | 305 | } |
paul@161 | 306 | |
paul@161 | 307 | __attr __fn_native__list_element(__attr __args[]) |
paul@161 | 308 | { |
paul@161 | 309 | #define self (__args[1]) |
paul@161 | 310 | #define index (__args[2]) |
paul@161 | 311 | |
paul@161 | 312 | /* NOTE: To be written. */ |
paul@161 | 313 | return __builtins___none_None; |
paul@161 | 314 | #undef self |
paul@161 | 315 | #undef index |
paul@161 | 316 | } |
paul@161 | 317 | |
paul@161 | 318 | __attr __fn_native__list_to_tuple(__attr __args[]) |
paul@161 | 319 | { |
paul@161 | 320 | #define l (__args[1]) |
paul@161 | 321 | |
paul@161 | 322 | /* NOTE: To be written. */ |
paul@161 | 323 | return __builtins___none_None; |
paul@161 | 324 | #undef l |
paul@161 | 325 | } |
paul@161 | 326 | |
paul@161 | 327 | __attr __fn_native__tuple_init(__attr __args[]) |
paul@161 | 328 | { |
paul@161 | 329 | #define size (__args[1]) |
paul@161 | 330 | /* size.__data__ interpreted as int */ |
paul@161 | 331 | __fragment *data = calloc(__load_via_object(size.value, __pos___data__).intvalue, sizeof(__attr)); |
paul@161 | 332 | __attr attr = {0, .data=data}; |
paul@161 | 333 | |
paul@161 | 334 | return attr; |
paul@161 | 335 | #undef size |
paul@161 | 336 | } |
paul@161 | 337 | |
paul@161 | 338 | __attr __fn_native__tuple_len(__attr __args[]) |
paul@161 | 339 | { |
paul@161 | 340 | #define self (__args[1]) |
paul@161 | 341 | |
paul@161 | 342 | /* NOTE: To be written. */ |
paul@161 | 343 | return __builtins___none_None; |
paul@161 | 344 | #undef self |
paul@161 | 345 | } |
paul@161 | 346 | |
paul@161 | 347 | __attr __fn_native__tuple_element(__attr __args[]) |
paul@161 | 348 | { |
paul@161 | 349 | #define self (__args[1]) |
paul@161 | 350 | #define index (__args[2]) |
paul@161 | 351 | |
paul@161 | 352 | /* NOTE: To be written. */ |
paul@161 | 353 | return __builtins___none_None; |
paul@161 | 354 | #undef self |
paul@161 | 355 | #undef index |
paul@161 | 356 | } |
paul@161 | 357 | |
paul@161 | 358 | __attr __fn_native__isinstance(__attr __args[]) |
paul@161 | 359 | { |
paul@161 | 360 | #define obj (__args[1]) |
paul@161 | 361 | #define cls (__args[2]) |
paul@161 | 362 | |
paul@161 | 363 | if (__HASATTR(obj.value, __TYPEPOS(cls.value), __TYPECODE(cls.value))) |
paul@161 | 364 | return obj; |
paul@161 | 365 | else |
paul@161 | 366 | return __builtins___none_None; |
paul@161 | 367 | #undef obj |
paul@161 | 368 | #undef cls |
paul@161 | 369 | } |
paul@161 | 370 | |
paul@161 | 371 | void __main_native() |
paul@161 | 372 | { |
paul@161 | 373 | } |