prim.c 17.1 KB
Newer Older
1
#include <string.h>
2
#include <stdlib.h>
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
3
#include <stdio.h>
4
5
6

#include "prim.h"
#include "desc.h"
7
#include "thunk.h"
8
9
#include "mem.h"

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
10
11
#define arg(idx) stack_a[stack_top_a - idx]

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
12
void __addI(int dst_idx) {
13
    Thunk* target = get_dst(dst_idx);
14
15
    target->desc = (Desc*) __INT__;
    target->_int = readI(arg(2)) + readI(arg(1));
16
17
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
18
void __subI(int dst_idx) {
19
    Thunk* target = get_dst(dst_idx);
20
21
    target->desc = (Desc*) __INT__;
    target->_int = readI(arg(2)) - readI(arg(1));
22
23
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
24
void __multI(int dst_idx) {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
25
26
27
28
29
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __INT__;
    target->_int = readI(arg(2)) * readI(arg(1));
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
30
void __divI(int dst_idx) {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
31
32
33
34
35
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __INT__;
    target->_int = readI(arg(2)) / readI(arg(1));
}

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
void __addR(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = readR(arg(2)) + readR(arg(1));
}

void __subR(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = readR(arg(2)) - readR(arg(1));
}

void __multR(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = readR(arg(2)) * readR(arg(1));
}

void __divR(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = readR(arg(2)) / readR(arg(1));
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
60
void __gtI(int dst_idx) {
61
    Thunk* target = get_dst(dst_idx);
62
    target->desc = (Desc*) __BOOL__;
63
    target->_int = readI(arg(2)) > readI(arg(1));
64
65
}

66
67
68
void __geI(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __BOOL__;
69
    target->_int = readI(arg(2)) >= readI(arg(1));
70
71
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
72
void __ltI(int dst_idx) {
73
    Thunk* target = get_dst(dst_idx);
74
    target->desc = (Desc*) __BOOL__;
75
    target->_int = readI(arg(2)) < readI(arg(1));
76
77
}

Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
78
79
80
void __geC(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __BOOL__;
81
    target->_int = readC(arg(2)) >= readC(arg(1));
Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
82
83
}

84
85
86
87
88
89
void __ltC(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __BOOL__;
    target->_int = readC(arg(2)) < readC(arg(1));
}

90
91
void __eqI(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
92
    target->desc = (Desc*) __BOOL__;
93
    target->_int = readI(arg(2)) == readI(arg(1));
94
95
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
96
97
98
void __neqI(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __BOOL__;
99
    target->_int = readI(arg(2)) != readI(arg(1));
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
100
101
}

102
103
void __eqB(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
104
    target->desc = (Desc*) __BOOL__;
105
    target->_int = readB(arg(2)) == readB(arg(1));
106
107
}

Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
108
109
void __eqC(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
110
    target->desc = (Desc*) __BOOL__;
111
    target->_int = readC(arg(2)) == readC(arg(1));
Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
112
113
}

114
115
void __not(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
116
    target->desc = (Desc*) __BOOL__;
117
    target->_int = !readB(arg(1));
118
119
}

Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
120
121
122
void __and(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __BOOL__;
123
    target->_int = readB(arg(2)) && readB(arg(1));
Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
124
125
126
127
128
}

void __or(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __BOOL__;
129
    target->_int = readB(arg(2)) || readB(arg(1));
Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
130
131
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
132
133
134
135
136
137
void __mod(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __INT__;
    target->_int = readB(arg(2)) % readB(arg(1));
}

Laszlo Domoszlai's avatar
add gc    
Laszlo Domoszlai committed
138
139
140
141
142
143
void __C2I(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __INT__;
    target->_int = readC(arg(1));
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
144
145
146
147
148
149
void __I2C(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __CHAR__;
    target->_int = (char) readI(arg(1));
}

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
215
216
217
218
219
220
221
void __I2R(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = readI(arg(1));
}

void __R2R(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = readR(arg(1));
}

void __R2I(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __INT__;
    target->_int = (int) readR(arg(1));
}

void __S2R(int dst_idx) {
    Thunk* str = arg(1);
    
    int length;
    char* chars;
    
    if(str->desc == (Desc*) __STRING_PTR__)
    {
        chars = str->_string_ptr->chars;
        length = str->_string_ptr->length;
    }
    else
    {
        chars = str->_array._chars;
        length = str->_array.length;
    }

    char buff[1080];
    if(length > 1079) length = 1079;
    memcpy(buff, chars, length);
    buff[length] = '\0';
    
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __REAL__;
    target->_real = strtod(buff, NULL);
}

void __S2I(int dst_idx) {
    Thunk* str = arg(1);
    
    int length;
    char* chars;
    
    if(str->desc == (Desc*) __STRING_PTR__)
    {
        chars = str->_string_ptr->chars;
        length = str->_string_ptr->length;
    }
    else
    {
        chars = str->_array._chars;
        length = str->_array.length;
    }

    char buff[20];
    if(length > 19) length = 19;
    memcpy(buff, chars, length);
    buff[length] = '\0';
    
    Thunk* target = get_dst(dst_idx);
    target->desc = (Desc*) __INT__;
    target->_int = strtol(buff, NULL, 10);
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
void __string_size(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* arg = arg(1);
    
    int length;
    
    if(arg->desc == (Desc*) __STRING_PTR__)
    {
        length = arg->_string_ptr->length;
    }
    else
    {
        length = arg->_array.length;
    }
    
    target->desc = (Desc*) __INT__;
    target->_int = length;
}

void __string_select(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* str = arg(2);
    Thunk* pos = arg(1);
    
    char* chars;
    
    if(str->desc == (Desc*) __STRING_PTR__)
    {
        chars = str->_string_ptr->chars;
    }
    else
    {
        chars = str->_array._chars;
    }
    
    target->desc = (Desc*) __CHAR__;
260
    target->_int = (char) chars[pos->_int];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
261
262
}

263
Thunk* array_create(Thunk* target, int elementsize, int len, ArrayElementType type)
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
264
{
265
    int newsize = sizeof (Desc) + sizeof (Array) + len * elementsize;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    
    if(target == NULL)
    {
        target = (Thunk*) alloc_heap(newsize);
    }
    else if(target->desc->thunk_size < newsize)
    {
        Thunk* tmp = (Thunk*) alloc_heap(newsize);
        target->desc = (Desc*) __FORWARD_PTR__;
        target->_forward_ptr = tmp;
        target = tmp;
    }

    target->desc = (Desc*) __ARRAY__;
280
281
282
    target->_array.type = type;
    target->_array.is_boxed = type != AET_OTHER;
    target->_array.bytes_per_elem = elementsize;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
283
284
285
286
287
    target->_array.length = len;
    
    return target;
}

288
289
290
291
292
Thunk* string_create(Thunk* target, int len)
{
    return array_create(target, 1, len, AET_CHAR);
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
293
294
295
296
297
298
299
void __string_create1(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* len = arg(1);
    set_return(dst_idx, string_create(target, len->_int));   
}

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
void __array_create1(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* len = arg(1);
    set_return(dst_idx, array_create(target, sizeof(void*), len->_int, AET_OTHER));   
}

void __array_create1_b_i(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* len = arg(1);
    set_return(dst_idx, array_create(target, sizeof(int), len->_int, AET_INT));   
}

void __array_create1_b_b(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* len = arg(1);
    set_return(dst_idx, array_create(target, sizeof(char), len->_int, AET_BOOL));   
}

void __array_create1_b_r(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* len = arg(1);
    set_return(dst_idx, array_create(target, sizeof(double), len->_int, AET_REAL));   
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
328
329
330
331
332
333
334
335
336
void __string_create2(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* len = arg(2);
    Thunk* ch = arg(1);
    
    target = string_create(target, len->_int);
    for(int i=0; i<len->_int; i++)
    {
337
        target->_array._chars[i] = (char) ch->_int;    
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
    }
    
    set_return(dst_idx, target);   
}

void __string_update(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* str = arg(3);
    Thunk* idx = arg(2);
    Thunk* ch = arg(1);
        
    int length;
    char* chars;
    
    if(str->desc == (Desc*) __STRING_PTR__)
    {
        chars = str->_string_ptr->chars;
        length = str->_string_ptr->length;
    }
    else
    {
        chars = str->_array._chars;
        length = str->_array.length;
    }
    
    target = string_create(target, length);
    memcpy(target->_array._chars, chars, length);

367
    target->_array._chars[idx->_int] = (char) ch->_int;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
368
369
370
371
    
    set_return(dst_idx, target);   
}

372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
void __array_update(int dst_idx)
{
    Thunk* arr = arg(3);
    Thunk* idx = arg(2);
    Thunk* elem = arg(1);
            
    arr->_array._elems[idx->_int] = elem;
    
    set_return(dst_idx, arr);   
}

void __array_update_b_i(int dst_idx)
{
    Thunk* arr = arg(3);
    Thunk* idx = arg(2);
    Thunk* elem = arg(1);
            
    arr->_array._ints[idx->_int] = elem->_int;
    
    set_return(dst_idx, arr);   
}

void __array_update_b_b(int dst_idx)
{
    Thunk* arr = arg(3);
    Thunk* idx = arg(2);
    Thunk* elem = arg(1);
            
    arr->_array._bools[idx->_int] = (unsigned char) elem->_int;
    
    set_return(dst_idx, arr);   
}

void __array_update_b_r(int dst_idx)
{
    Thunk* arr = arg(3);
    Thunk* idx = arg(2);
    Thunk* elem = arg(1);
            
    arr->_array._reals[idx->_int] = elem->_real;
    
    set_return(dst_idx, arr);   
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
416
417
418
419
420
421
422
423
void __string_slice(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* str = arg(3);
    Thunk* idx1 = arg(2);
    Thunk* idx2 = arg(1);
        
    char* chars;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
424
    int full_length;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
425
426
427
428
    
    if(str->desc == (Desc*) __STRING_PTR__)
    {
        chars = str->_string_ptr->chars;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
429
        full_length = str->_string_ptr->length;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
430
431
432
433
    }
    else
    {
        chars = str->_array._chars;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
434
        full_length = str->_array.length;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
435
436
    }

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
437
438
    int length = idx2->_int - idx1->_int + 1;
    if(idx1->_int  + length > full_length) length = full_length - idx1->_int;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
    
    target = string_create(target, length);
    memcpy(target->_array._chars, chars + idx1->_int, length);
    
    set_return(dst_idx, target);       
}

void __string_append(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* str1 = arg(2);
    Thunk* str2 = arg(1);
        
    int length1;
    char* chars1;
    
    if(str1->desc == (Desc*) __STRING_PTR__)
    {
        chars1 = str1->_string_ptr->chars;
        length1 = str1->_string_ptr->length;
    }
    else
    {
        chars1 = str1->_array._chars;
        length1 = str1->_array.length;
    }

    int length2;
    char* chars2;
    
    if(str2->desc == (Desc*) __STRING_PTR__)
    {
        chars2 = str2->_string_ptr->chars;
        length2 = str2->_string_ptr->length;
    }
    else
    {
        chars2 = str2->_array._chars;
        length2 = str2->_array.length;
    }
            
    target = string_create(target, length1 + length2);
    
    memcpy(target->_array._chars, chars1, length1);
    memcpy(target->_array._chars + length1, chars2, length2);
    
    set_return(dst_idx, target);       
}

void __eqS(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* str1 = arg(2);
    Thunk* str2 = arg(1);
        
    int length1;
    char* chars1;
    
    if(str1->desc == (Desc*) __STRING_PTR__)
    {
        chars1 = str1->_string_ptr->chars;
        length1 = str1->_string_ptr->length;
    }
    else
    {
        chars1 = str1->_array._chars;
        length1 = str1->_array.length;
    }

    int length2;
    char* chars2;
    
    if(str2->desc == (Desc*) __STRING_PTR__)
    {
        chars2 = str2->_string_ptr->chars;
        length2 = str2->_string_ptr->length;
    }
    else
    {
        chars2 = str2->_array._chars;
        length2 = str2->_array.length;
    }
          
    int eq = length1 == length2;
    
524
525
    int i = 0;
    while(i<length1 && eq)
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
526
    {
527
528
        eq = chars1[i] == chars2[i];
        i++;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
529
530
531
    }

    target->desc = (Desc*) __BOOL__;
532
    target->_int = eq;    
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
533
534
}

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
void __ltS(int dst_idx)
{
    Thunk* target = get_dst(dst_idx);
    Thunk* str1 = arg(2);
    Thunk* str2 = arg(1);
        
    int length1;
    char* chars1;
    
    if(str1->desc == (Desc*) __STRING_PTR__)
    {
        chars1 = str1->_string_ptr->chars;
        length1 = str1->_string_ptr->length;
    }
    else
    {
        chars1 = str1->_array._chars;
        length1 = str1->_array.length;
    }

    int length2;
    char* chars2;
    
    if(str2->desc == (Desc*) __STRING_PTR__)
    {
        chars2 = str2->_string_ptr->chars;
        length2 = str2->_string_ptr->length;
    }
    else
    {
        chars2 = str2->_array._chars;
        length2 = str2->_array.length;
    }
     
    int result = length1 == 0;
    
    if(length1 > 0 && length2 > 0)
    {
        result = length1 < length2;
        
        int i = 0;
        while(i<length1)
        {
            if(chars1[i] != chars2[i])
            {
                result = chars1[i] < chars2[i];
                break;
            }
            
            i++;
        }
    }
    
    target->desc = (Desc*) __BOOL__;
    target->_int = result;    
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
void __C2S(int dst_idx) {
    Thunk* target = get_dst(dst_idx);
    Thunk* ch = arg(1);

    target = string_create(target, 1);
    target->_array._chars[0] = (char) ch->_int;    
    set_return(dst_idx, target);
}

void __trace(int dst_idx)
{
    Thunk* str = arg(1);

    int length;
    char* chars;
    
    if(str->desc == (Desc*) __STRING_PTR__)
    {
        chars = str->_string_ptr->chars;
        length = str->_string_ptr->length;
    }
    else
    {
        chars = str->_array._chars;
        length = str->_array.length;
    }

    for(int i=0; i<length; i++)
    {
        printf("%c", chars[i]);
    }
}

625
626
627
628
629
630
void __abort(int dst_idx)
{
    __trace(dst_idx);
    exit(-1);
}

Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
631
void add_prim(int arity, int boxingMap, int unboxableReturn,  char* name, void (*exec)(int)) {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
632
633
634
635
636
637
    int nameLength = strlen(name);

    // before the PrimEntry there are "arity" number of SliceEntries
    SliceEntry* entry_base = (SliceEntry*) alloc_desc(sizeof (SliceEntry) * arity + sizeof (PrimEntry) + nameLength + 1);

    PrimEntry* entry = (PrimEntry*) (entry_base + arity);
638
    entry->base.type = FT_PRIM;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
639
    entry->base.arity = arity;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
640
641
    entry->base.thunk_size = thunk_size_f(arity);    
    entry->base.hnf = false;
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
642
    entry->base.unboxable_return = unboxableReturn;
643
    entry->boxingMap = boxingMap;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
644
645
646
647
648
649
650
651
652
653
    entry->exec = exec;

    // TODO: should it be copied at all?
    memcpy(entry->name, name, nameLength);
    entry->name[nameLength] = '\0';

    // generate slices. avoid function call if arity is zero
    if (arity > 0) gen_slices(entry_base, (Desc*) entry, arity);

    add_desc(entry->name, (Desc*) entry);
654
655
}

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
656
void init_prim() {
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
657
658
659
660
661
662
663
664
665
    add_prim(2, 0b011, 1, "addI", &__addI);
    add_prim(2, 0b011, 1, "subI", &__subI);
    add_prim(2, 0b011, 1, "multI", &__multI);
    add_prim(2, 0b011, 1, "divI", &__divI);
    add_prim(2, 0b011, 1, "gtI", &__gtI);
    add_prim(2, 0b011, 1, "geI", &__geI);
    add_prim(2, 0b011, 1, "ltI", &__ltI);
    add_prim(2, 0b011, 1, "eqI", &__eqI);
    add_prim(2, 0b011, 1, "neqI", &__neqI);
666
667
668
    
    add_prim(2, 0b011, 1, "geC", &__geC);    
    add_prim(2, 0b011, 1, "ltC", &__ltC);
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
669
    add_prim(2, 0b011, 1, "eqC", &__eqC);
670
671
672
673
674
675
676

    add_prim(2, 0b011, 1, "addR", &__addR);
    add_prim(2, 0b011, 1, "subR", &__subR);
    add_prim(2, 0b011, 1, "multR", &__multR);
    add_prim(2, 0b011, 1, "divR", &__divR);    
    
    add_prim(2, 0b011, 1, "eqB", &__eqB);
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
677
678
679
680
    add_prim(1, 0b001, 1, "not", &__not);
    add_prim(2, 0b011, 1, "and", &__and); 
    add_prim(2, 0b011, 1, "or", &__or); 
    add_prim(2, 0b011, 1, "mod", &__mod);
681
    
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
682
    add_prim(1, 0b001, 1, "C2I", &__C2I);
683
684
    add_prim(1, 0b001, 1, "R2I", &__R2I);
    add_prim(1, 0b001, 1, "S2I", &__S2I);
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
685
    add_prim(1, 0b001, 1, "I2C", &__I2C);
686
687
688
689
690
    add_prim(1, 0b001, 1, "I2R", &__I2R);
    add_prim(1, 0b001, 1, "R2R", &__R2R);
    add_prim(1, 0b000, 0, "S2R", &__S2R);
    add_prim(1, 0b001, 0, "C2S", &__C2S);
            
691
692
693
694
695
696
697
698
699
700
701
702
    add_prim(1, 0b001, 0, "array_create1", &__array_create1);
    add_prim(1, 0b001, 0, "array_create1_lazy", &__array_create1);
    add_prim(1, 0b001, 0, "array_create1_B_I", &__array_create1_b_i);
    add_prim(1, 0b001, 0, "array_create1_B_B", &__array_create1_b_b);
    add_prim(1, 0b001, 0, "array_create1_B_R", &__array_create1_b_r);

    add_prim(3, 0b010, 0, "array_update", &__array_update);
    add_prim(3, 0b010, 0, "array_update_lazy", &__array_update);
    add_prim(3, 0b110, 0, "array_update_B_I", &__array_update_b_i);
    add_prim(3, 0b110, 0, "array_update_B_B", &__array_update_b_b);
    add_prim(3, 0b110, 0, "array_update_B_R", &__array_update_b_r);
    
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
703
704
705
706
707
708
709
710
    add_prim(1, 0b000, 1, "string_size", &__string_size);
    add_prim(2, 0b010, 1, "string_select", &__string_select);
    add_prim(1, 0b001, 0, "string_create1", &__string_create1);
    add_prim(2, 0b011, 0, "string_create2", &__string_create2);    
    add_prim(3, 0b110, 0, "string_update", &__string_update);
    add_prim(3, 0b110, 0, "string_slice", &__string_slice);
    add_prim(2, 0b000, 0, "string_append", &__string_append);
    add_prim(2, 0b000, 1, "eqS", &__eqS);
711
    add_prim(2, 0b000, 1, "ltS", &__ltS);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
712
    
Laszlo Domoszlai's avatar
fix bug    
Laszlo Domoszlai committed
713
    add_prim(1, 0b000, 0, "_trace", &__trace);
714
    add_prim(1, 0b000, 0, "abort", &__abort);
715
}