-
Notifications
You must be signed in to change notification settings - Fork 15
/
basics.tbl
1040 lines (1010 loc) · 34.7 KB
/
basics.tbl
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
// *****************************************************************************
// basics.tbl XL project
// *****************************************************************************
//
// File description:
#
#
#
#
#
#
#
#
// *****************************************************************************
// This software is licensed under the GNU General Public License v3
// (C) 2012, Baptiste Soulisse <baptiste.soulisse@taodyne.com>
// (C) 2010-2011, Catherine Burvelle <catherine@taodyne.com>
// (C) 2009-2015,2019, Christophe de Dinechin <christophe@dinechin.org>
// (C) 2010-2013, Jérôme Forissier <jerome@taodyne.com>
// (C) 2010, Lionel Schaffhauser <lionel@taodyne.com>
// *****************************************************************************
// This file is part of XL
//
// XL is free software: you can r redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XL is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with XL, in a file named COPYING.
// If not, see <https://www.gnu.org/licenses/>.
// *****************************************************************************
// Types must come first for type info to be initialized correctly
NAME(nil);
NAME(empty);
NAME(true);
NAME(false);
TYPE(boolean);
TYPE(integer);
TYPE(real);
TYPE(text);
TYPE(character);
TYPE(tree);
TYPE(source);
TYPE(code);
TYPE(lazy);
TYPE(reference);
TYPE(value);
TYPE(symbol);
TYPE(name);
TYPE(operator);
TYPE(infix);
TYPE(prefix);
TYPE(postfix);
TYPE(block);
TYPE(integer8);
TYPE(integer16);
TYPE(integer32);
TYPE(integer64);
TYPE(unsigned);
TYPE(unsigned8);
TYPE(unsigned16);
TYPE(unsigned32);
TYPE(unsigned64);
TYPE(real32);
TYPE(real64);
// Basic units
INFIX(DefineRewrite, tree, source, "->", source,
return xl_define(context, self, &l, &r),
GROUP(basics)
SYNOPSIS("Declare a tree rewrite"))
INFIX(SequenceNewLine, tree, source, "\n", source,
return xl_evaluate_sequence(context, &l, &r),
GROUP(basics)
SYNOPSIS("Sequence of statements separated by line separators"))
INFIX(SequenceSemicolon, tree, source, ";", source,
return xl_evaluate_sequence(context, &l, &r),
GROUP(basics)
SYNOPSIS("Sequence of statements separated by semicolons"))
PREFIX(DataDefinition, tree, "data",
PARM(form, source, "Source code for the data form"),
return xl_define(context, self, &form, NULL),
GROUP(basics)
SYNOPSIS("Declare a data form"))
PREFIX(CodeClosure, tree, "<code>",
PARM(input, source, "Source code"),
return xl_evaluate_code(context, self, &input),
GROUP(basics:closure)
SYNOPSIS("Code closure, evaluated repeatedly in original code context"))
PREFIX(LazyClosure, tree, "<lazy>",
PARM(input, source, "Source code"),
return xl_evaluate_lazy(context, self, &input),
GROUP(basics:closure)
SYNOPSIS("Lazy evaluation closure, evaluated once in original context"))
PREFIX(EvaluatedClosure, tree, "<value>",
PARM(input, source, "Stored value"),
return &input,
GROUP(basics:closure)
SYNOPSIS("Result of a previous lazy evaluation"))
PREFIX(AnyLookup, tree, "any",
PARM(expr, source, "Expression to evaluate"),
return xl_evaluate_any(context, &expr),
GROUP(basics:lookup)
SYNOPSIS("Evaluate the value along the call stack"))
PREFIX(Properties, tree, "properties",
PARM(body, source, "Property storage")
PARM(declarations, source, "Property declarations"),
return xl_enter_properties(context, self, &body, &declarations),
GROUP(basics:properties)
SYNOPSIS("Declare properties"))
PREFIX(Constraint, tree, "constraint",
PARM(declarations, source, "Constraint declarations"),
return xl_enter_constraints(context, self, &declarations),
GROUP(basics:properties)
SYNOPSIS("Declare constraints on properties or variables"))
PREFIX(Solve, tree, "solve",
PARM(n, name, "Name of variable to solve for")
PARM(eq, source, "Equation to solve"),
return Constraint(&eq).SolveFor(&n),
GROUP(basics:properties)
SYNOPSIS("Test for the property solver"))
// Array indexing and assignment. Assignment must be before other assignments
INFIX(Assign, tree, reference, ":=", tree,
return xl_assign(context, &l, &r), )
INFIX(Index, tree, tree, ".", tree, return xl_index(context, &l, &r), )
PREFIX(Good, name, "good", PARM(V, tree, ""),
XL_RBOOL(xl_evaluate(context, &V) != xl_false), )
// Integer arithmetic and comparisons
INFIX(AddInt,integer, integer,"+",integer, XL_RINT(XL_INT(l) + XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(SubInt,integer, integer,"-",integer, XL_RINT(XL_INT(l) - XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(MulInt,integer, integer,"*",integer, XL_RINT(XL_INT(l) * XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(DivInt,integer, integer,"/",integer,
if (XL_INT(r) == 0) { Ooops("$1 divides by $2", self, &r); XL_RINT(0LL); }
XL_RINT(XL_INT(l) / XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(RemInt,integer, integer,"rem",integer,
if (XL_INT(r) == 0) { Ooops("$1 divides by $2", self, &r); XL_RINT(0LL); }
XL_RINT(XL_INT(l) % XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(ModInt,integer, integer,"mod",integer,
if (XL_INT(r) == 0) { Ooops("$1 divides by $2", self, &r); XL_RINT(0LL); }
XL_RINT(xl_mod(l, r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(PowerInt, integer, integer, "^", integer, XL_RINT(xl_pow(l,r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(LShift, integer, integer,"shl",integer, XL_RINT(XL_INT(l) << XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(RShift, integer, integer,"shr",integer, XL_RINT(XL_INT(l) >> XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(And, integer, integer, "and", integer, XL_RINT(XL_INT(l) & XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(Or, integer, integer, "or", integer, XL_RINT(XL_INT(l) | XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(Xor, integer, integer, "xor", integer, XL_RINT(XL_INT(l) ^ XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer,""))
INFIX(LTInt, boolean, integer, "<", integer, XL_RBOOL(XL_INT(l) < XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(GTInt, boolean, integer, ">", integer, XL_RBOOL(XL_INT(l) > XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(LEInt, boolean, integer, "<=", integer, XL_RBOOL(XL_INT(l) <= XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(GEInt, boolean, integer, ">=", integer, XL_RBOOL(XL_INT(l) >= XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEInt, boolean, integer, "<>", integer, XL_RBOOL(XL_INT(l) != XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEInt2, boolean, integer, "!=", integer, XL_RBOOL(XL_INT(l) != XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(EQInt, boolean, integer, "=", integer, XL_RBOOL(XL_INT(l) == XL_INT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
PREFIX(NegateInt, integer, "-", PARM(x, integer, ""), XL_RINT(-x),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(BitwiseNotInt, integer, "not", PARM(x, integer, ""), XL_RINT(~x),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
// Percents
POSTFIX(PercentInt, real, PARM(x, integer, ""), "%", XL_RREAL(x / 100.0),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
POSTFIX(PercentReal, real, PARM(x, real, ""), "%", XL_RREAL(x / 100.0),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
// Real arithmetic and comparisons
INFIX(AddReal, real, real, "+", real, XL_RREAL(XL_REAL(l) + XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(SubReal, real, real, "-", real, XL_RREAL(XL_REAL(l) - XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(MulReal, real, real, "*", real, XL_RREAL(XL_REAL(l) * XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(DivReal, real, real, "/", real,
if (XL_REAL(r) == 0) { Ooops("$1 divides by $2", self, &r); XL_RREAL(0.0); }
XL_RREAL(XL_REAL(l) / XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(RemReal, real, real, "rem", real,
if (XL_REAL(r) == 0) { Ooops("$1 divides by $2", self, &r); XL_RREAL(0.0); }
XL_RREAL(fmod(XL_REAL(l), XL_REAL(r))),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(ModReal, real, real, "mod", real,
if (XL_REAL(r) == 0) { Ooops("$1 divides by $2", self, &r); XL_RREAL(0.0); }
XL_RREAL(xl_modf(l,r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(PowRealInt, real, real, "^", integer, XL_RREAL(xl_powf(l,r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(PowReal, real, real, "^", real, XL_RREAL(pow(XL_REAL(l), XL_REAL(r))),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( real, ""))
INFIX(LTReal, boolean, real, "<", real, XL_RBOOL(XL_REAL(l) < XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(GTReal, boolean, real, ">", real, XL_RBOOL(XL_REAL(l) > XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(LEReal, boolean, real, "<=", real, XL_RBOOL(XL_REAL(l) <= XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(GEReal, boolean, real, ">=", real, XL_RBOOL(XL_REAL(l) >= XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEReal2, boolean, real, "<>", real, XL_RBOOL(XL_REAL(l) != XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEReal, boolean, real, "!=", real, XL_RBOOL(XL_REAL(l) != XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(EQReal, boolean, real, "=", real, XL_RBOOL(XL_REAL(l) == XL_REAL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
PREFIX(Negate, real, "-", PARM(r, real, ""), XL_RREAL(-r),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Abs, real, "abs", PARM(x, real, ""), XL_RREAL(fabs(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Sign, real, "sign", PARM(x, real, ""),
XL_RREAL(XL_REAL(x) < 0 ? -1 : XL_REAL(x) > 0 ? 1 : 0),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Floor, real, "floor", PARM(x, real, ""), XL_RREAL(floor(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Ceil, real, "ceil", PARM(x, real, ""), XL_RREAL(ceil(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Sqrt, real, "sqrt", PARM(x, real, ""), XL_RREAL(sqrt(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Sin, real, "sin", PARM(x, real, ""), XL_RREAL(sin(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Cos, real, "cos", PARM(x, real, ""), XL_RREAL(cos(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Tan, real, "tan", PARM(x, real, ""), XL_RREAL(tan(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(ArcSin, real, "asin", PARM(x, real, ""), XL_RREAL(asin(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(ArcCos, real, "acos", PARM(x, real, ""), XL_RREAL(acos(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(ArcTan2, real, "atan", PARM(y, real, "") PARM(x, real, ""), XL_RREAL(atan2(y,x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(ArcTan, real, "atan", PARM(x, real, ""), XL_RREAL(atan(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Exp, real, "exp", PARM(x, real, ""), XL_RREAL(exp(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(ExpMinus1, real, "expm1", PARM(x, real, ""), XL_RREAL(expm1(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Log, real, "log", PARM(x, real, ""), XL_RREAL(log(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Log2, real, "log2", PARM(x, real, ""), XL_RREAL(log2(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(Log10, real, "log10", PARM(x, real, ""), XL_RREAL(log10(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(LogPlus1, real, "log1p", PARM(x, real, ""), XL_RREAL(log1p(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(PiConstant, real, "pi", , XL_RREAL(M_PI),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
// Boolean operations
INFIX(AndBool, boolean, boolean, "and", boolean, XL_RBOOL(XL_BOOL(l) & XL_BOOL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(OrBool, boolean, boolean, "or", boolean, XL_RBOOL(XL_BOOL(l) | XL_BOOL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(XorBool, boolean, boolean, "xor", boolean, XL_RBOOL(XL_BOOL(l) ^ XL_BOOL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
PREFIX(NotBool, boolean, "not", PARM(x, boolean, ""), XL_RBOOL(!XL_BOOL(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS( boolean, ""))
INFIX(NEBool, boolean, boolean, "<>", boolean, XL_RBOOL(XL_BOOL(l) != XL_BOOL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEBool2, boolean, boolean, "!=", boolean, XL_RBOOL(XL_BOOL(l) != XL_BOOL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(EQBool, boolean, boolean, "=", boolean, XL_RBOOL(XL_BOOL(l) == XL_BOOL(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
// Text operations
INFIX(TextConcatenate, text, text, "&", text,
XL_RTEXT(XL_TEXT(l) + XL_TEXT(r)),
GROUP(basics) SYNOPSIS("") DESCRIPTION("") RETURNS(text, ""))
INFIX(TextConcatenateRightNumber, text, text, "&", real,
XL_RTEXT(XL_TEXT(l) + xl_real2text(r)),
GROUP(basics) SYNOPSIS("") DESCRIPTION("") RETURNS(text, ""))
INFIX(TextConcatenateLeftNumber, text, real, "&", text,
XL_RTEXT(xl_real2text(l) + XL_TEXT(r)),
GROUP(basics) SYNOPSIS("") DESCRIPTION("") RETURNS(text, ""))
INFIX(LTText, boolean, text, "<", text, XL_RBOOL(XL_TEXT(l) < XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(GTText, boolean, text, ">", text, XL_RBOOL(XL_TEXT(l) > XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(LEText, boolean, text, "<=", text, XL_RBOOL(XL_TEXT(l) <= XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(GEText, boolean, text, ">=", text, XL_RBOOL(XL_TEXT(l) >= XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEText, boolean, text, "<>", text, XL_RBOOL(XL_TEXT(l) != XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(NEText2, boolean, text, "!=", text, XL_RBOOL(XL_TEXT(l) != XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(EQText, boolean, text, "=", text, XL_RBOOL(XL_TEXT(l) == XL_TEXT(r)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
INFIX(TextAt, text, text, "at", integer,
text t = l; longlong i = r;
XL_RTEXT((i >= 1 && i <= (longlong) t.length()) ?
text(t[i-1],1) : text("")),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(text, ""))
INFIX(ListIndex, tree, tree, "at", tree,
return xl_array_index(context, &l, &r), )
// Some other text primitives
PREFIX(TextLength, integer, "text_length",
PARM(t,text, "Input text"),
XL_RINT(t.value.length()),
GROUP(text)
SYNOPSIS("Compute the length of input text"))
PREFIX(TextRange, text, "text_range",
PARM(txt, text, "Input text")
PARM(pos, integer, "Start position")
PARM(sz, integer, "Length of the text to extract"),
text t = txt; size_t p = pos; size_t s = sz;
XL_RTEXT(t.substr(p, s)),
GROUP(text)
SYNOPSIS("Extract a range of text"))
PREFIX(TextFind, integer, "text_find",
PARM(txt, text, "Input text to find into")
PARM(fnd, text, "Text to find in the input text"),
text t = txt;
text f = fnd;
XL_RINT(t.find(f)),
GROUP(text)
SYNOPSIS("Find a text into another larger text"))
PREFIX(TextReplace, text, "text_replace",
PARM(txt, text, "Input text to find into")
PARM(before, text, "The string to be replaced")
PARM(after, text, "The replacement string"),
XL_RTEXT(xl_text_replace(txt, before, after)),
GROUP(text)
SYNOPSIS("Replace every occurrence of a string")
DESCRIPTION("Replace every occurence of before with after in txt."))
INFIX(TextContains, boolean, text, "contains", text,
text t = l;
text f = r;
XL_RBOOL(t.find(f) != t.npos),
GROUP(text)
SYNOPSIS("Find a text into another larger text"))
// Conversions
PREFIX(IntToReal, real, "real",
PARM(x, integer, ""),
XL_RREAL((real_t) x),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(TextToReal, real, "real", PARM(x, text, ""), XL_RREAL(xl_text2real(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(RealToInt, integer, "integer", PARM(x, real, ""), XL_RINT((integer_t) x),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TextToInt, integer, "integer", PARM(x, text, ""), XL_RINT(xl_text2int(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(IntToText, text, "text", PARM(x, integer, ""), XL_RTEXT(xl_int2text(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(text, ""))
PREFIX(RealToText, text, "text", PARM(x, real, ""), XL_RTEXT(xl_real2text(x)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(text, ""))
// Time computations
#ifndef LIBXLR
/* Currently if LIBXLR is defined it means we're building Tao.
Tao redefines the following primitives, and we must not define
them twice to avoid a clash */
PREFIX(TimeHours, integer, "hours", PARM(t, integer, ""), XL_RTIME(tm.tm_hour),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeMinutes, integer, "minutes", PARM(t, integer, ""), XL_RTIME(tm.tm_min),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeSeconds, integer, "seconds", PARM(t, integer, ""), XL_RTIME(tm.tm_sec),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeYear, integer, "year", PARM(t, integer, ""), XL_RTIME(tm.tm_year + 1900),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeMonth, integer, "month", PARM(t, integer, ""), XL_RTIME(tm.tm_mon),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeMonthDay, integer, "day", PARM(t, integer, ""), XL_RTIME(tm.tm_mday),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeWeekDay, integer, "week_day", PARM(t, integer, ""), XL_RTIME(tm.tm_wday),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(TimeYearDay, integer, "year_day", PARM(t, integer, ""), XL_RTIME(tm.tm_yday),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
// Return hour, minutes, seconds for the current time
PREFIX(SystemTime, integer, "system_time",, XL_RINT(xl_time(1)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemHours, integer, "hours",, XL_RCTIME(tm.tm_hour, 10),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemMinutes, integer, "minutes",, XL_RCTIME(tm.tm_min, 2),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemSeconds, integer, "seconds",, XL_RCTIME(tm.tm_sec, 0.5),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemYear, integer, "year",, XL_RCTIME(tm.tm_year + 1900, 10),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemMonth, integer, "month",, XL_RCTIME(tm.tm_mon, 10),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemMonthDay, integer, "day",, XL_RCTIME(tm.tm_mday, 10),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemWeekDay, integer, "week_day",, XL_RCTIME(tm.tm_wday, 10),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(SystemYearDay, integer, "year_day",, XL_RCTIME(tm.tm_yday, 10),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
#endif
// Random number generator
PREFIX(RandomNumber2i, integer, "random", PARM(low,integer, "") PARM(high,integer, ""),
XL_RINT(xl_random(XL_INT(low), XL_INT(high))),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(integer, ""))
PREFIX(RandomNumber2, real, "random", PARM(low, real, "") PARM(high, real, ""),
XL_RREAL(xl_random(XL_REAL(low), XL_REAL(high))),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(RandomNumber, real, "random", , XL_RREAL(xl_random(0.0, 1.0)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(real, ""))
PREFIX(RandomSeedNumber2i, boolean, "random_seed",
PARM(seed,integer, ""),
XL_RBOOL(xl_random_seed(XL_INT(seed))),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("Initialize random generator with seed number")
RETURNS(integer, ""))
// Executing some code
PREFIX(Identity, tree, "identity",
PARM(input, tree, "Input ode"),
return &input,
GROUP(basics)
SYNOPSIS("No operation")
DESCRIPTION("")
RETURNS(tree, "The input tree, not evaluated"))
PREFIX(DoCode, tree, "do",
PARM(input, tree, "Input tree to evaluate"),
Symbols *symbols = self->Symbols();
if (!input.Symbols())
input.SetSymbols(symbols);
Tree *tree = xl_evaluate(context, &input);
if (!tree->Symbols())
tree->SetSymbols(symbols);
return xl_evaluate(context, tree),
GROUP(basics)
SYNOPSIS("Evaluate the input immediately"))
PREFIX(ParseText, tree, "parse",
PARM(input, text, "Input text to turn into a tree"),
Tree *tree = xl_parse_text(input);
if (!tree)
tree = xl_false;
return tree,
GROUP(basics)
SYNOPSIS("Parse a tree from text"))
PREFIX(InCaller, tree, "in_caller",
PARM(input, source, "Input tree to evaluate"),
return xl_evaluate_in_caller(context, &input),
GROUP(basics)
SYNOPSIS("Evaluate the input in caller's context"))
PREFIX(ParseTree, tree, "parse_tree",
PARM(src, source, "Source tree to return"),
return xl_parse_tree(context, &src),
GROUP(source)
SYNOPSIS("Return the source tree unevaluated"))
PREFIX(BoundForm, tree, "bound",
PARM(test, source, "Value to test"),
return xl_bound(context, &test),
GROUP(source)
SYNOPSIS("Test if a given name or form is bound in the current context"))
PREFIX(GetAttribute, tree, "form_attribute",
PARM(name, text, "Name of the attribute, e.g. 'property'")
PARM(form, tree, "Form to test for in the current context"),
return xl_attribute(context, name, &form),
GROUP(source)
SYNOPSIS("Find the attribute associated to a given form"))
PREFIX(LoadCSVBody, tree, "load_csv",
PARM(f, text, "")
PARM(p, text, "")
PARM(body, tree, ""),
return xl_load_data(context, self, f, p, ",;", "\n\f\r", &body),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(LoadCSV, tree, "load_csv",
PARM(f, text, "")
PARM(p, text, ""),
return xl_load_data(context, self, f, p, ",;", "\n\f\r"),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(LoadTSVBody, tree, "load_tsv",
PARM(f, text, "File name")
PARM(p, text, "Prefix to apply")
PARM(body, text, "Prefix to apply"),
return xl_load_data(context, self, f, p, "\t", "\n\f\r", &body),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(LoadTSV, tree, "load_tsv",
PARM(f, text, "File name")
PARM(p, text, "Prefix to apply"),
return xl_load_data(context, self, f, p, "\t", "\n\f\r"),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(LoadDataBody, tree, "load_data",
PARM(f, text, "File name")
PARM(p, text, "Prefix to apply")
PARM(fs, text, "Field separator")
PARM(rs, text, "Row separator")
PARM(body, tree, "Body"),
return xl_load_data(context, self, f, p, fs, rs, &body),
GROUP(basics) SYNOPSIS("") DESCRIPTION("") RETURNS(tree, ""))
PREFIX(LoadData, tree, "load_data",
PARM(f, text, "File name")
PARM(p, text, "Prefix to apply")
PARM(fs, text, "Field separator")
PARM(rs, text, "Row separator"),
return xl_load_data(context, self, f, p, fs, rs),
GROUP(basics) SYNOPSIS("") DESCRIPTION("") RETURNS(tree, ""))
PREFIX(AddSearchPath, tree, "add_search_path", PARM(prefix, text, "") PARM(dir, text, ""),
return xl_add_search_path(context, prefix, dir),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("Add dir to the search path for prefix for the current context")
RETURNS(tree, ""))
PREFIX(FindInSearchPath, text, "find_in_search_path", PARM(prefix, text, "") PARM(path, text, ""),
return xl_find_in_search_path(context, prefix, path),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("Look for file using search path for prefix")
RETURNS(text, "The path to the file, if the file was found"))
INFIX(Apply, tree, tree, "with", tree,
return xl_apply(context, &l, &r),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
INFIX(Range, tree, integer, "..", integer, return xl_range(l, r),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(Length, integer, "length",
PARM(l, tree, ""),
return xl_size(context, &l),
GROUP(basics))
PREFIX(Size, integer, "size",
PARM(l, tree, ""),
return xl_size(context, &l),
GROUP(basics))
PREFIX(Springify, real, "springify",
PARM(v, real, "") PARM(tgt, real, "") PARM(t, real, "")
PARM(d, real, "") PARM(k, real, "")
PARM(lt, real, "") PARM(ls, real, ""),
return xl_springify(v, tgt, t, d, k, lt, ls),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
#ifndef LIBXLR
PREFIX(ListFiles, tree, "files", PARM(pat, tree, ""),
return xl_list_files(context, &pat),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
#endif
PREFIX(FileExists, boolean, "file_exists",
PARM(f, text, "filename"),
XL_RBOOL(xl_file_exists(context, self, f)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(boolean, ""))
// Debugging code
PREFIX(DebugTree, tree, "debug", PARM(toDebug, tree, ""),
std::cerr << "DEBUG: " << (Tree *) &toDebug << "\n";
return xl_true,
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(EvaluationError, tree, "evaluation_error",
PARM(expr, source, "Expression that caused an evaluation error"),
return xl_form_error(context, &expr),
GROUP(basics)
SYNOPSIS("Function called when no form matches a given expression"))
PREFIX(ErrorMsg3, tree, "error",
PARM(m, text, "") PARM(a,tree, "") PARM(b,tree, "") PARM(c, tree, ""),
return xl_error(self, m, &a, &b, &c),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(ErrorMsg2, tree, "error",
PARM(m, text, "") PARM(a,tree, "") PARM(b,tree, ""),
return xl_error(self, m, &a, &b),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(ErrorMsg1, tree, "error", PARM(m, text, "") PARM(a,tree, ""),
return xl_error(self, m, &a),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(ErrorMsg0, tree, "error", PARM(m, text, ""),
return xl_error(self, m),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(ExitProgram, boolean, "exit",
PARM(exitCode, integer, "Exit code to return to calling shell"),
exit(XL_INT(exitCode)); return xl_false,
GROUP(basics)
SYNOPSIS("Terminate the program with the given exit code"))
PREFIX(WriteInteger, tree, "write", PARM(toWrite, integer, ""),
XL_RBOOL(xl_write_integer(toWrite.value)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(WriteReal, tree, "write", PARM(toWrite, real, ""),
XL_RBOOL(xl_write_real(toWrite.value)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(WriteText, tree, "write", PARM(toWrite, text, ""),
XL_RBOOL(xl_write_text(toWrite.value.c_str())),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(WriteOther, tree, "write", PARM(toWrite, tree, ""),
if (!toWrite.Symbols())
toWrite.SetSymbols(self->Symbols());
Tree *value = context->Evaluate(&toWrite);
XL_RBOOL(xl_write_tree(value)),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(WriteLn, tree, "writeln", ,
XL_RBOOL(xl_write_cr()),
GROUP(basics)
SYNOPSIS("")
DESCRIPTION("")
RETURNS(tree, ""))
PREFIX(Env, text, "env", PARM(name, text, ""),
char *val = getenv(name.value.c_str());
return new XL::Text(val ? val : ""),
GROUP(basics)
SYNOPSIS("Get the value of an environment variable")
DESCRIPTION("Returns the current value of the environment variable "
"'name' or an empty string if the variable is not set.")
RETURNS(text, ""))
// Loops
FORM(IntegerForLoop, tree,
"for Var in Low:integer..High:integer loop Body",
PARM(Var, tree, "")
PARM(Low, integer, "")
PARM(High, integer, "")
PARM(Body, source, ""),
return xl_integer_for_loop(context,self, &Var, Low, High, 1, &Body), )
FORM(IntegerForLoopStep, tree,
"for Var in Low:integer..High:integer by Step:integer loop Body",
PARM(Var, tree, "")
PARM(Low, integer, "")
PARM(High, integer, "")
PARM(Step, integer, "")
PARM(Body, source, ""),
return xl_integer_for_loop(context,self, &Var, Low,High,Step, &Body), )
FORM(RealForLoop, tree,
"for Var in Low:real..High:real loop Body",
PARM(Var, tree, "")
PARM(Low, real, "")
PARM(High, real, "")