-
Notifications
You must be signed in to change notification settings - Fork 1
/
pogl_rpn.xs
1970 lines (1763 loc) · 42 KB
/
pogl_rpn.xs
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
215
216
217
218
219
220
221
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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
328
329
330
331
332
333
334
335
336
337
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
367
368
369
370
371
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
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
524
525
526
527
528
529
530
531
532
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
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Last saved: Sun 06 Sep 2009 02:10:28 PM */
/* Copyright (c) 1998 Kenneth Albanowski. All rights reserved.
* Copyright (c) 2007 Bob Free. All rights reserved.
* Copyright (c) 2009 Chris Marshall. All rights reserved.
* Copyright (c) 2015 Bob Free. All rights reserved.
* This program is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
*/
/* OpenGL::Array */
#define IN_POGL_ARRAY_XS
/* OpenGL::Matrix */
#define IN_POGL_MATRIX_XS
/* OpenGL RPN code */
#define IN_POGL_RPN_XS
#include <stdio.h>
#include "pgopogl.h"
#ifdef HAVE_GL
#include "gl_util.h"
#endif
#ifdef HAVE_GLX
#include "glx_util.h"
#endif
#ifdef HAVE_GLU
#include "glu_util.h"
#endif
#ifdef IN_POGL_RPN_XS
#ifndef M_PI
#ifdef PI
#define M_PI PI
#else
#define M_PI 3.1415926535897932384626433832795
#endif
#endif
#endif /* End IN_POGL_RPN_XS */
/* Note: this is caching procs once for all contexts */
/* !!! This should instead cache per context */
#ifdef HAVE_GL
#if defined(_WIN32) || (defined(__CYGWIN__) && defined(HAVE_W32API))
#define loadProc(proc,name) \
{ \
if (!proc) \
{ \
proc = (void *)wglGetProcAddress(name); \
if (!proc) croak(name " is not supported by this renderer"); \
} \
}
#define testProc(proc,name) ((proc) ? 1 : !!(proc = (void *)wglGetProcAddress(name)))
#else
#define loadProc(proc,name)
#define testProc(proc,name) 1
#endif
#endif
#ifdef IN_POGL_RPN_XS
/********************/
/* RPN Processor */
/********************/
/* RPN Ops */
enum
{
RPN_NOP = 0,
RPN_PSH,
RPN_POP,
RPN_CNT,
RPN_IDX,
RPN_CLS,
RPN_COL,
RPN_RWS,
RPN_ROW,
RPN_SET,
RPN_GET,
RPN_STO,
RPN_LOD,
RPN_TST,
RPN_NOT,
RPN_EQU,
RPN_GRE,
RPN_LES,
RPN_END,
RPN_EIF,
RPN_ERW,
RPN_ERI,
RPN_RET,
RPN_RIF,
RPN_RRW,
RPN_RRI,
RPN_SUM,
RPN_AVG,
RPN_RND,
RPN_DUP,
RPN_SWP,
RPN_ABS,
RPN_NEG,
RPN_INC,
RPN_DEC,
RPN_ADD, // Also OR
RPN_MUL, // ALSO AND
RPN_DIV,
RPN_POW,
RPN_MOD,
RPN_MIN,
RPN_MAX,
RPN_SIN,
RPN_COS,
RPN_TAN,
RPN_AT2,
RPN_DMP,
RPN_FLR,
RPN_CGT,
RPN_CST,
RPN_RGT,
RPN_RST
};
/* RPN breaks */
enum
{
RPNF_CONTINUE = 0,
RPNF_END,
RPNF_ENDROW,
RPNF_RETURN,
RPNF_RETURNROW
};
/* RPN OP link-list */
struct tag_rpn_op
{
int op;
GLfloat value;
struct tag_rpn_op * next;
};
typedef struct tag_rpn_op rpn_op;
/* RPN OP stack for a given column */
struct tag_rpn_stack
{
int count;
int max_count;
GLfloat * data;
rpn_op * ops;
};
typedef struct tag_rpn_stack rpn_stack;
/* RPN Object */
struct tag_rpn_context
{
int rows;
int cols;
int oga_count;
oga_struct ** oga_list;
GLfloat * store;
rpn_stack ** stacks;
};
typedef struct tag_rpn_context rpn_context;
/* RPN Parser */
rpn_stack * rpn_parse(int size,char * string)
{
rpn_stack * stack = malloc(sizeof(rpn_stack));
rpn_op * op = NULL;
rpn_op * last = NULL;
char * data = NULL;
/* Will destroy string, so make a copy */
memset(stack,0,sizeof(rpn_stack));
if (string && *string)
{
/* Assumes ASCII */
data = malloc(strlen(string)+1);
strcpy(data,string);
string = data;
}
/* OPs are comma-separated */
while (string && *string)
{
rpn_op * cur = NULL;
char * pos = string;
char * end = strchr(pos,',');
int len;
/* Grab op */
if (end)
{
*end = 0;
string = end+1;
len = end - pos;
}
else
{
len = strlen(string);
string += len;
}
/* Empty op is a NOP */
if (!len) continue;
/* Update linklist */
cur = malloc(sizeof(rpn_op));
memset(cur,0,sizeof(rpn_op));
if (last)
{
last->next = cur;
}
else
{
op = cur;
}
last = cur;
/* Check for primitive OPs */
if (len == 1)
{
switch (*pos)
{
case '!':
{
cur->op = RPN_NOT;
continue;
}
case '-':
{
cur->op = RPN_NEG;
continue;
}
case '+':
{
cur->op = RPN_ADD;
continue;
}
case '*':
{
cur->op = RPN_MUL;
continue;
}
case '/':
{
cur->op = RPN_DIV;
continue;
}
case '%':
{
cur->op = RPN_MOD;
continue;
}
case '=':
{
cur->op = RPN_EQU;
size++;
continue;
}
case '>':
{
cur->op = RPN_GRE;
size++;
continue;
}
case '<':
{
cur->op = RPN_LES;
size++;
continue;
}
case '?':
{
cur->op = RPN_TST;
continue;
}
}
}
/* Check for textual OPs */
if (!strcmp(pos,"pop"))
{
cur->op = RPN_POP;
}
else if (!strcmp(pos,"rand"))
{
cur->op = RPN_RND;
size++;
}
else if (!strcmp(pos,"dup"))
{
cur->op = RPN_DUP;
size++;
}
else if (!strcmp(pos,"swap"))
{
cur->op = RPN_SWP;
}
else if (!strcmp(pos,"set"))
{
cur->op = RPN_SET;
}
else if (!strcmp(pos,"get"))
{
cur->op = RPN_GET;
size++;
}
else if (!strcmp(pos,"store"))
{
cur->op = RPN_STO;
}
else if (!strcmp(pos,"load"))
{
cur->op = RPN_LOD;
}
else if (!strcmp(pos,"end"))
{
cur->op = RPN_END;
}
else if (!strcmp(pos,"endif"))
{
cur->op = RPN_EIF;
}
else if (!strcmp(pos,"endrow"))
{
cur->op = RPN_ERW;
}
else if (!strcmp(pos,"endrowif"))
{
cur->op = RPN_ERI;
}
else if (!strcmp(pos,"return"))
{
cur->op = RPN_RET;
}
else if (!strcmp(pos,"returnif"))
{
cur->op = RPN_RIF;
}
else if (!strcmp(pos,"returnrow"))
{
cur->op = RPN_RRW;
}
else if (!strcmp(pos,"returnrowif"))
{
cur->op = RPN_RRI;
}
else if (!strcmp(pos,"if"))
{
cur->op = RPN_TST;
}
else if (!strcmp(pos,"or"))
{
cur->op = RPN_ADD;
}
else if (!strcmp(pos,"and"))
{
cur->op = RPN_MUL;
}
else if (!strcmp(pos,"inc"))
{
cur->op = RPN_INC;
}
else if (!strcmp(pos,"dec"))
{
cur->op = RPN_DEC;
}
else if (!strcmp(pos,"sum"))
{
cur->op = RPN_SUM;
}
else if (!strcmp(pos,"avg"))
{
cur->op = RPN_AVG;
}
else if (!strcmp(pos,"abs"))
{
cur->op = RPN_ABS;
}
else if (!strcmp(pos,"power"))
{
cur->op = RPN_POW;
}
else if (!strcmp(pos,"min"))
{
cur->op = RPN_MIN;
}
else if (!strcmp(pos,"max"))
{
cur->op = RPN_MAX;
}
else if (!strcmp(pos,"sin"))
{
cur->op = RPN_SIN;
}
else if (!strcmp(pos,"cos"))
{
cur->op = RPN_COS;
}
else if (!strcmp(pos,"tan"))
{
cur->op = RPN_TAN;
}
else if (!strcmp(pos,"atan2"))
{
cur->op = RPN_AT2;
}
else if (!strcmp(pos,"count"))
{
cur->op = RPN_CNT;
size++;
}
else if (!strcmp(pos,"index"))
{
cur->op = RPN_IDX;
size++;
}
else if (!strcmp(pos,"columns"))
{
cur->op = RPN_CLS;
size++;
}
else if (!strcmp(pos,"column"))
{
cur->op = RPN_COL;
size++;
}
else if (!strcmp(pos,"rows"))
{
cur->op = RPN_RWS;
size++;
}
else if (!strcmp(pos,"row"))
{
cur->op = RPN_ROW;
size++;
}
else if (!strcmp(pos,"pi"))
{
cur->op = RPN_PSH;
cur->value = (float)M_PI;
size++;
}
else if (!strcmp(pos,"dump"))
{
cur->op = RPN_DMP;
}
else if (!strcmp(pos,"floor"))
{
cur->op = RPN_FLR;
}
else if (!strcmp(pos,"colget"))
{
cur->op = RPN_CGT;
}
else if (!strcmp(pos,"colset"))
{
cur->op = RPN_CST;
}
else if (!strcmp(pos,"rowget"))
{
cur->op = RPN_RGT;
}
else if (!strcmp(pos,"rowset"))
{
cur->op = RPN_RST;
}
/* Default to a numeric push */
else
{
cur->op = RPN_PSH;
cur->value = (float)atof(pos);
size++;
}
}
/* release string copy */
if (data) free(data);
stack->data = malloc(sizeof(GLfloat)*size);
stack->max_count = size;
stack->ops = op;
return(stack);
}
/* Instantiate an RPN Object */
rpn_context * rpn_init(int oga_count,oga_struct ** oga_list,int col_count,char ** col_ops)
{
rpn_context * ctx = NULL;
int elements = 0;
int i,j;
if (!oga_count) croak("Missing OGA count");
if (!oga_list) croak("Missing OGA list");
if (!col_count) croak("Missing column count");
/* Validate OGAs */
for (i=0; i<oga_count; i++)
{
if (!oga_list[i]) croak("Missing OGA %d",i);
if (!oga_list[i]->item_count) croak("Empty OGA %d",i);
/* Check that all OGAs have the same dimension */
if (!i)
{
elements = oga_list[i]->item_count;
if (elements % col_count) croak("Invalid OGA size for %d columns",col_count);
}
else if (elements != oga_list[i]->item_count)
{
croak("Invalid length in OGA %d",i);
}
/* Only supporting GLfloat for now */
for (j=0; j<oga_list[i]->type_count; j++)
{
if (oga_list[i]->types[j] != GL_FLOAT)
croak("Unsupported type in OGA %d",i);
}
}
/* Alloc Object data */
ctx = malloc(sizeof(rpn_context));
if (!ctx) croak("Unable to alloc rpn context");
/* Alloc current row store */
ctx->store = malloc(sizeof(GLfloat) * col_count);
if (!ctx->store) croak("Unable to alloc rpn store");
/* Alloc column stack array */
ctx->stacks = malloc(sizeof(rpn_stack *) * col_count);
if (!ctx->stacks) croak("Unable to alloc rpn stacks");
ctx->cols =col_count;
ctx->rows = elements / col_count;
ctx->oga_count = oga_count;
ctx->oga_list = oga_list;
/* Parse and populate column stacks */
for (i=0; i<col_count; i++)
ctx->stacks[i] = rpn_parse(oga_count,col_ops[i]);
return(ctx);
}
/* Release OP link-list */
void rpn_delete_ops(rpn_op * ops)
{
if (!ops) return;
rpn_delete_ops(ops->next);
free(ops);
}
/* Release OPS stack */
void rpn_delete_stack(rpn_stack * stack)
{
if (!stack) return;
rpn_delete_ops(stack->ops);
free(stack->data);
free(stack);
}
/* Release RPN Object */
void rpn_term(rpn_context * ctx)
{
if (ctx)
{
int i;
for (i=0; i<ctx->cols; i++)
rpn_delete_stack(ctx->stacks[i]);
free(ctx->stacks);
free(ctx->store);
free(ctx);
}
}
/* Push an RPN value on the stack */
void rpn_push(rpn_stack * stack, GLfloat value)
{
if (stack){
if(stack->count == stack->max_count)
croak("Trying to push past allocated rpn stack size: %d", stack->count);
stack->data[stack->count++] = value;
}
}
/* Pop an RPN value from the stack */
GLfloat rpn_pop(rpn_stack * stack)
{
GLfloat value = 0.0;
if (stack && stack->count)
{
value = stack->data[--stack->count];
if (!stack->count) rpn_push(stack,0.0);
}
return(value);
}
/* Dump out the current stack */
void rpn_dump(rpn_stack * stack, int row, int col, float reg)
{
if (stack && stack->count)
{
int i;
warn("-----------------(row: %d, col: %d)----\n", row, col);
warn("Register: %.7f\n", reg);
for (i = stack->count - 1; i >= 0 ; i--)
warn("Stack %2d: %.7f\n", i, stack->data[stack->count - i - 1]);
}
else {
warn("Empty Stack\n");
}
}
/* Execute RPN OPs stack */
void rpn_exec(rpn_context * ctx)
{
int elements = ctx->rows * ctx->cols;
int i,j,k,r = 0;
GLfloat v1,v2;
for (i=0;i<ctx->rows;i++)
{
for (j=0;j<ctx->cols;j++)
{
rpn_stack * stack = ctx->stacks[j];
int flow = RPNF_CONTINUE; /* or 0 */
rpn_op * ops;
/* Skip for NOP columns */
if (!stack || !stack->ops) continue;
stack->count = 0;
/* Push oga data on stack - reverse order */
for (k=ctx->oga_count-1;k>=0;k--)
rpn_push(stack,((GLfloat *)ctx->oga_list[k]->data)[r+j]);
/* Process RPN ops */
ops = stack->ops;
while (ops)
{
int pos = stack->count - 1;
switch(ops->op)
{
case RPN_PSH:
{
//printf("RPN_PSH: %f\n",ops->value);
rpn_push(stack,ops->value);
break;
}
case RPN_POP:
{
//printf("RPN_POP\n");
rpn_pop(stack);
break;
}
case RPN_CNT:
{
//printf("RPN_CNT: %f\n",elements);
rpn_push(stack,(float)elements);
break;
}
case RPN_IDX:
{
//printf("RPN_IDX: %f\n",r+j);
rpn_push(stack,(float)r+j);
break;
}
case RPN_CLS:
{
//printf("RPN_CLS: %f\n",ctx->cols);
rpn_push(stack,(float)ctx->cols);
break;
}
case RPN_COL:
{
//printf("RPN_COL: %f\n",j);
rpn_push(stack,(float)j);
break;
}
case RPN_RWS:
{
//printf("RPN_RWS: %f\n",ctx->rows);
rpn_push(stack,(float)ctx->rows);
break;
}
case RPN_ROW:
{
//printf("RPN_ROW: %f\n",i);
rpn_push(stack,(float)i);
break;
}
case RPN_SET:
{
//printf("RPN_SET %d: %f\n",j,stack->data[pos]);
ctx->store[j] = stack->data[pos];
break;
}
case RPN_GET:
{
//printf("RPN_Get %d: %f\n",j,ctx->store[j]);
rpn_push(stack,ctx->store[j]);
break;
}
case RPN_STO:
{
//printf("RPN_STO row %d\n",r);
v1 = rpn_pop(stack);
k = ((int)v1) % ctx->oga_count;
if (k < 0) k += ctx->oga_count;
memcpy(ctx->store,&((GLfloat *)ctx->oga_list[k]->data)[r],
ctx->cols*sizeof(GLfloat));
break;
}
case RPN_CGT:
{
//printf("RPN_CGT row %d\n",r);
int _col = (int)rpn_pop(stack);
if (_col < 0) _col = 0;
if (_col > ctx->cols-1) _col = ctx->cols-1;
rpn_push(stack,(float)((GLfloat *)ctx->oga_list[0]->data)[r+_col]);
break;
}
case RPN_CST:
{
//printf("RPN_CST row %d\n",r);
int _col = (int)rpn_pop(stack);
if (_col < 0) _col = 0;
if (_col > ctx->cols-1) _col = ctx->cols-1;
((GLfloat *)ctx->oga_list[0]->data)[r+_col] = stack->data[pos > 0 ? pos-1 : 0];
break;
}
case RPN_RGT:
{
//printf("RPN_RGT row %d\n",r);
int _col = (int)rpn_pop(stack);
int _row = (int)rpn_pop(stack);
if (_row < 0) _row = 0;
if (_row > ctx->rows-1) _row = ctx->rows-1;
if (_col < 0) _col = 0;
if (_col > ctx->cols-1) _col = ctx->cols-1;
rpn_push(stack,(float)((GLfloat *)ctx->oga_list[0]->data)[_row*ctx->cols+_col]);
break;
}
case RPN_RST:
{
//printf("RPN_RST row %d\n",r);
int _col = (int)rpn_pop(stack);
int _row = (int)rpn_pop(stack);
if (_row < 0) _row = 0;
if (_row > ctx->rows-1) _row = ctx->rows-1;
if (_col < 0) _col = 0;
if (_col > ctx->cols-1) _col = ctx->cols-1;
((GLfloat *)ctx->oga_list[0]->data)[_row*ctx->cols+_col] = stack->data[pos > 1 ? pos-2 : 0];
break;
}
case RPN_FLR:
{
//printf("RPN_FLR %d: %f\n",j,ctx->store[j]);
int flr = (int)stack->data[pos];
stack->data[pos] = (float)flr;
break;
}
case RPN_LOD:
{
//printf("RPN_LOD rwo %d\n",r);
v1 = rpn_pop(stack);
k = ((int)v1) % ctx->oga_count;
if (k < 0) k += ctx->oga_count;
memcpy(&((GLfloat *)ctx->oga_list[k]->data)[r],ctx->store,
ctx->cols*sizeof(GLfloat));
break;
}
case RPN_TST:
{
//printf("RPN_TST\n");
v1 = rpn_pop(stack);
if (v1 != 0.0)
{
rpn_pop(stack);
}
else
{
v1 = rpn_pop(stack);
rpn_pop(stack);
rpn_push(stack,v1);
}
break;
}
case RPN_NOT:
{
//printf("RPN_NOT\n");
if (!stack->count)
{
rpn_push(stack,1.0);
}
else if (stack->data[pos] == 0.0)
{
stack->data[pos] = 1.0;
}
else
{
stack->data[pos] = 0.0;
}
break;
}
case RPN_EQU:
{
//printf("RPN_EQU\n");
v1 = (stack->count) ? rpn_pop(stack) : (float)0.0;
v2 = (stack->count) ? rpn_pop(stack) : (float)0.0;
rpn_push(stack,(float)((v1 == v2) ? 1.0 : 0.0));
break;
}
case RPN_GRE:
{
//printf("RPN_GRE\n");
v1 = (stack->count) ? rpn_pop(stack) : (float)0.0;
v2 = (stack->count) ? rpn_pop(stack) : (float)0.0;
rpn_push(stack,(float)((v1 > v2) ? 1.0 : 0.0));
break;
}
case RPN_LES:
{
//printf("RPN_LES\n");
v1 = (stack->count) ? rpn_pop(stack) : (float)0.0;
v2 = (stack->count) ? rpn_pop(stack) : (float)0.0;
rpn_push(stack,(float)((v1 < v2) ? 1.0 : 0.0));
break;
}
case RPN_END:
{
//printf("RPN_END\n");
flow = RPNF_END;
ops = 0;
continue;
}
case RPN_EIF:
{
//printf("RPN_EIF\n");
v1 = rpn_pop(stack);
if (v1 != 0.0)
{
flow = RPNF_END;
ops = 0;
continue;
}
break;
}
case RPN_ERW:
{
//printf("RPN_ERW\n");
flow = RPNF_ENDROW;
ops = 0;
continue;
}
case RPN_ERI:
{
//printf("RPN_ERI\n");
v1 = rpn_pop(stack);
if (v1 != 0.0)
{
flow = RPNF_ENDROW;
ops = 0;
continue;
}
break;
}
case RPN_RET:
{
//printf("RPN_RET\n");
flow = RPNF_RETURN;
ops = 0;
continue;
}
case RPN_RIF:
{
//printf("RPN_RIF\n");
v1 = rpn_pop(stack);
if (v1 != 0.0)
{
flow = RPNF_RETURN;
ops = 0;
continue;
}
break;
}
case RPN_RRW:
{
//printf("RPN_RRW\n");
flow = RPNF_RETURNROW;
ops = 0;
continue;
}
case RPN_RRI:
{
//printf("RPN_RRI\n");
v1 = rpn_pop(stack);
if (v1 != 0.0)
{
flow = RPNF_RETURNROW;
ops = 0;
continue;
}
break;
}
case RPN_RND:
{
//printf("RPN_RND\n");
rpn_push(stack,(float)(1.0*rand()/RAND_MAX));
break;
}
case RPN_DUP:
{
//printf("RPN_DUP\n");
rpn_push(stack,stack->data[pos]);
break;
}
case RPN_SWP:
{
//printf("RPN_SWP\n");
if (pos >= 1)
{
v1 = stack->data[pos-1];
stack->data[pos-1] = stack->data[pos];
stack->data[pos] = v1;
}
break;
}
case RPN_ABS:
{
//printf("RPN_ABS\n");
stack->data[pos] = (float)fabs(stack->data[pos]);
break;
}
case RPN_NEG:
{
//printf("RPN_NEG\n");
stack->data[pos] *= (float)-1.0;
break;
}
case RPN_INC:
{
//printf("RPN_INC\n");
stack->data[pos] += (float)1.0;
break;
}
case RPN_DEC:
{
//printf("RPN_DEC\n");
stack->data[pos] -= (float)1.0;
break;
}
case RPN_AVG:
case RPN_SUM:
{
//printf("RPN_SUM/AVG\n");
v1 = 0;
for(pos=0; pos<stack->count; pos++)
v1 += stack->data[pos];
if (ops->op == RPN_AVG) v1 /= stack->count;
stack->data[0] = v1;
stack->count = 1;
break;
}
case RPN_ADD: