-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinstructions.h
executable file
·5246 lines (4169 loc) · 147 KB
/
instructions.h
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
/*
* Tamgu (탐구)
*
* Copyright 2019-present NAVER Corp.
* under BSD 3-clause
*/
/* --- CONTENTS ---
Project : Tamgu (탐구)
Version : See tamgu.cxx for the version number
filename : instructions.h
Date : 2017/09/01
Purpose :
Programmer : Claude ROUX (claude.roux@naverlabs.com)
Reviewer :
*/
#ifndef instructions_h
#define instructions_h
#include "tamgushort.h"
#include "tamguint.h"
#include "tamgudecimal.h"
#include "tamgufloat.h"
#include "tamgulong.h"
class Tamgudecimal;
class Tamgutamgu;
#define DIVIDEDBYZERO -101
//--------------------------------------------------------------------
class TamguDeclarationLocal : public TamguTracked {
public:
BVECTE<short, Tamgu*> declarations;
VECTE<Tamgu*> toclean;
short idx;
short idthread;
bool pushed;
bool used;
TamguDeclarationLocal(short ix) : idx(ix), used(false), pushed(false), idthread(-1), TamguTracked(NULL) {
investigate = is_declaration;
}
bool FindAndClean(Tamgu* a) {
return !declarations.check(a);
}
bool hasDeclaration() {
return true;
}
bool isEmpty() {
return (!declarations.last);
}
bool isDeclared(short id) {
return (declarations.check(id));
}
void Replacedeclaration(short idthread, short id, Tamgu* a) {
globalTamgu->Replacevariable(idthread, id, a);
declarations.replace(id, a);
}
char Declarelocal(short idthread, short n, Tamgu* a) {
if (isDeclared(n))
return a_declaration;
Declare(n, a);
return true;
}
void Variables(vector<short>& vars) {
for (short i = 0; i < declarations.last; i++)
vars.push_back(declarations.index[i]);
}
void Declare(short id, Tamgu* a) {
declarations.push_back(id, a);
toclean.push_back(a);
}
inline void Declaring(short id, Tamgu* a) {
declarations.push_back(id, a);
toclean.push_back(a);
}
inline void Declaringmin(short id, Tamgu* a) {
declarations.push_back(id, a);
}
Tamgu* Declaration(short idname) {
return declarations.find(idname);
}
void Cleaning() {
short i;
for (i = 0; i < declarations.last; i++)
globalTamgu->Removingvariable(idthread, declarations.index[i]);
for (i = 0; i < toclean.last; i++)
toclean.vecteur[i]->Resetreference();
declarations.last = 0;
toclean.last = 0;
}
void Release() {
short i;
for (i = 0; i < declarations.last; i++)
globalTamgu->Removingvariable(idthread, declarations.index[i]);
for (i = 0; i < toclean.last; i++)
toclean.vecteur[i]->Resetreference();
if (pushed)
globalTamgu->Popstack(idthread);
if (used) {
declarations.last = 0;
toclean.last = 0;
used = false;
idthread = -1;
pushed = false;
globalTamgu->declempties.push_back(idx);
}
else
delete this;
}
inline void Releasing() {
short i;
for (i = 0; i < declarations.last; i++)
globalTamgu->Removingvariable(idthread, declarations.index[i]);
for (i = 0; i < toclean.last; i++)
toclean.vecteur[i]->Resetreference();
if (used) {
declarations.last = 0;
toclean.last = 0;
used = false;
idthread = -1;
pushed = false;
globalTamgu->declempties.push_back(idx);
}
else
delete this;
}
void Info(Tamgu* ins, short idt, bool p) {
idthread = idt;
if (p) {
globalTamgu->Pushstack(this, idthread);
pushed = p;
}
if (globalTamgu->debugmode && ins->isTracked()) {
idinfo = ins->Currentinfo();
}
}
};
class TamguLocalEvaluation : public TamguTracked {
public:
Tamgu* declarations;
VECTE<Tamgu*> instructions;
TamguLocalEvaluation(Tamgu* d) : TamguTracked(NULL) {
declarations = d;
}
void AddInstruction(Tamgu* a) {
instructions.push_back(a);
}
bool isLocalEvaluation() {
return true;
}
bool isMainFrame() {
return declarations->isMainFrame();
}
bool FindAndClean(Tamgu* a) {
return declarations->FindAndClean(a);
}
bool hasDeclaration() {
return true;
}
bool isEmpty() {
return declarations->isEmpty();
}
bool isDeclared(short id) {
return declarations->isDeclared(id);
}
void Replacedeclaration(short idthread, short id, Tamgu* a) {
declarations->Replacedeclaration(idthread, id, a);
}
char Declarelocal(short idthread, short n, Tamgu* a) {
return declarations->Declarelocal(idthread, n, a);
}
void Variables(vector<short>& vars) {
return declarations->Variables(vars);
}
void Declare(short id, Tamgu* a) {
declarations->Declare(id, a);
}
Tamgu* Declaration(short idname) {
return declarations->Declaration(idname);
}
};
//--------------------------------------------------------------------
//This function call is used to call methods associated to objects such as i.log()
class TamguCallMethod : public TamguCallClean {
public:
bool Checkarity();
TamguCallMethod(short m, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallClean(m, a_callmethod, global, parent) {}
Exporting Tamgu* Eval(Tamgu* context, Tamgu* object, short idthread);
Exporting Tamgu* Put(Tamgu* context, Tamgu* object, short idthread);
short Typeinfered() {
if (function != NULL)
return function->Typevariable();
if (!globalTamgu->returntypes.check(name))
return a_none;
return globalTamgu->returntypes[name];
}
};
class TamguCallFromCall : public TamguCallMethod {
public:
TamguCallFromCall(short m, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallMethod(m, global, parent) {}
Exporting Tamgu* Eval(Tamgu* context, Tamgu* object, short idthread);
Exporting Tamgu* Put(Tamgu* context, Tamgu* object, short idthread);
};
class TamguCallCommonMethod : public TamguCallFromCall {
public:
bool Checkarity();
TamguCallCommonMethod(short m, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFromCall(m, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* object, short idthread);
Tamgu* Execute(Tamgu* environment, Tamgu* value, short idthread) {
return TamguCallFromCall::Eval(environment, value, idthread);
}
};
class TamguCallAlias : public TamguCall {
public:
TamguAlias* body;
bool stop;
TamguCallAlias(TamguAlias* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : body(b), TamguCall(a_callfunction, global, parent) {
addarg = false;
stop = true;
name = b->Name();
}
Exporting virtual Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
short Name() {
return name;
}
Tamgu* Body(short idthread) {
return body->Body(idthread);
}
bool Checkarity() {
return (body->Size() == arguments.size());
}
bool isAssignable() {
return (function != NULL && body->isAssignable() && body->parameters.size() == function->Size());
}
bool isAlias() {
return true;
}
Tamgu* Function() {
return function;
}
bool Setstopindex() {
stop = (function == NULL || function->Function() == NULL);
if (!stop)
function->Setstopindex();
return true;
}
bool isDirectIndex() {
return (function != NULL && function->isIndex() && !function->Function());
}
};
//This function call is used to call user declared functions
class TamguCallFunction : public TamguCall {
public:
Tamgu* body;
bool nonlimited;
Exporting bool Checkarity();
TamguCallFunction(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : body(b), TamguCall(a_callfunction, global, parent) {
nonlimited = false;
if (b != NULL)
name = b->Name();
}
TamguCallFunction(TamguCallFunction& c) : TamguCall(a_callfunction) {
body=c.body;
nonlimited=c.nonlimited;
name=c.name;
arguments=c.arguments;
}
Tamgu* Eval_Arguments(TamguDeclarationLocal* context, Tamgu* value, short idthread);
Exporting virtual Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
short Name() {
return name;
}
Tamgu* Body(short idthread) {
return body->Body(idthread);
}
short Typeinfered() {
if (body != NULL)
return body->Typeinfered();
return a_none;
}
};
class TamguCallLispFunction : public TamguCall {
public:
Tamgu* body;
bool Checkarity() {
if (body->Size() != arguments.size())
return false;
return true;
}
TamguCallLispFunction(Tamgu* b, TamguGlobal* global, Tamgu* parent) : body(b), TamguCall(a_calllisp, global, parent) {
name = b->Name();
}
TamguCallLispFunction(Tamgu* b) : body(b), TamguCall(a_calllisp) {
name = b->Name();
}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
short Name() {
return name;
}
Tamgu* Body(short idthread) {
return body->Body(idthread);
}
};
class TamguCallFunction0 : public TamguCallFunction {
public:
TamguCallFunction0(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguCallFunction1 : public TamguCallFunction {
public:
TamguCallFunction1(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguCallFunction2 : public TamguCallFunction {
public:
TamguCallFunction2(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguCallFunction3 : public TamguCallFunction {
public:
TamguCallFunction3(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguCallFunction4 : public TamguCallFunction {
public:
TamguCallFunction4(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguCallFunction5 : public TamguCallFunction {
public:
TamguCallFunction5(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguCallFromPredicateRule : public TamguCallFunction {
public:
TamguCallFromPredicateRule(Tamgu* b, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallFunction(b, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
};
class TamguFunctionDeclarationCall : public TamguCallFunction {
public:
TamguFunctionDeclarationCall(short n, TamguGlobal* global, Tamgu* parent) : TamguCallFunction(NULL, global, parent) { name = n; }
Tamgu* Eval(Tamgu* context, Tamgu* callfunction, short idthread) {
body = globalTamgu->Getdeclaration(name, idthread);
body = body->Body(idthread);
if (body == NULL)
return globalTamgu->Returnerror(e_cannot_execute_this02, idthread);
return TamguCallFunction::Eval(context, callfunction, idthread);
}
};
class TamguCallThread : public TamguCall {
public:
Tamgu* body;
Tamgu* recipient;
bool nonlimited;
bool predicate_rule;
bool Checkarity();
TamguCallThread(Tamgu* b, bool pred_rule = false, TamguGlobal* global = NULL, Tamgu* parent = NULL) :
nonlimited(false),recipient(NULL), body(b), predicate_rule(pred_rule), TamguCall(a_callthread, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
short Name() {
return body->Name();
}
Tamgu* Body(short idthread) {
return body->Body(idthread);
}
bool isThread() {
return true;
}
Tamgu* Push(Tamgu* v) {
recipient = v;
recipient->Setreference();
return aTRUE;
}
};
//This function call is used to call user declared functions
class TamguThreadCall : public TamguCallFunction {
public:
std::atomic<bool> joined;
std::atomic<bool> to_be_deleted;
threadhandle tid;
TamguGlobal* global;
Tamgu* domain;
Tamgu* recipient;
std::thread* thid;
long idomain;
short parentid;
short idthread;
bool cleandom;
bool exclusive;
TamguThreadCall(Tamgu* b, Tamgu* r, Tamgu* d, bool c, bool e, short idt, short pid) : TamguCallFunction(b) {
to_be_deleted = false;
global = globalTamgu;
recipient = r;
parentid = pid;
joined = false;
idtype = a_callthread;
domain = d;
idthread = idt;
cleandom = c;
exclusive = e;
idomain = -1;
if (cleandom)
idomain = d->Setprotect();
}
~TamguThreadCall() {
if (to_be_deleted) {
thid->join();
delete thid;
}
}
virtual Tamgu* Eval(Tamgu* domain, Tamgu* value, short idthread);
short Name() {
return body->Name();
}
};
//This function call is used to call user declared functions
class TamguThreadCallFromPredicate : public TamguThreadCall {
public:
TamguThreadCallFromPredicate(Tamgu* b, Tamgu* r, Tamgu* d, bool c, bool e, short idt, short pid) : TamguThreadCall(b,r,d,c,e,idt,pid) {
joined = true;
((TamguThread*)b)->joined = true;
}
Tamgu* Eval(Tamgu* domain, Tamgu* value, short idthread);
};
//This function call is used to call user declared functions
class TamguCallFrameFunction : public TamguCallClean {
public:
TamguFrame* frame;
bool Checkarity();
TamguCallFrameFunction(TamguFrame* f, short n, TamguGlobal* global = NULL, Tamgu* parent = NULL) :
frame(f), TamguCallClean(n, a_callfunction, global, parent) {}
TamguCallFrameFunction(short n) : frame(NULL), TamguCallClean(n, a_callfunction) {}
virtual Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
virtual Tamgu* Put(Tamgu* context, Tamgu* domain, short idthread);
Tamgu* Frame() {
return frame;
}
short Typeinfered() {
if (function != NULL)
return function->Typeinfered();
if (frame != NULL)
return frame->Declaration(name)->Typeinfered();
return globalTamgu->returntypes[name];
}
};
//This function call is used to call user declared functions
class TamguCallTopFrameFunction : public TamguCallFrameFunction {
public:
TamguCallTopFrameFunction(TamguFrame* f, short n, TamguGlobal* global = NULL, Tamgu* parent = NULL) :
TamguCallFrameFunction(f,n, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* domain, short idthread);
Tamgu* Put(Tamgu* context, Tamgu* domain, short idthread);
Tamgu* Frame() {
return frame;
}
};
//This function call is used to call procedures such as print, println etc...
class TamguCallProcedure : public TamguCallClean {
public:
bool Checkarity();
TamguCallProcedure(short m, TamguGlobal* global = NULL, Tamgu* parent = NULL) : TamguCallClean(m, a_callprocedure, global, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
bool isUnified(TamguDeclaration* dom) {
return false;
}
short Typeinfered() {
if (globalTamgu->returntypes.check(name))
return globalTamgu->returntypes[name];
return a_none;
}
};
class TamguCallReturn : public TamguTracked {
public:
Tamgu* argument;
bool tail;
TamguCallReturn(TamguGlobal* global = NULL, Tamgu* parent = NULL) : argument(aNOELEMENT), TamguTracked(a_return, global, parent) {
investigate = is_return;
tail = false;
}
Tamgu* DirectEval(Tamgu* context, Tamgu* v, short idthread) {
globalTamgu->threads[idthread].returnvalue = argument->Eval(context, aNULL, idthread);
return this;
}
virtual Tamgu* Eval(Tamgu* context, Tamgu* v, short idthread) {
globalTamgu->threads[idthread].returnvalue = tail?aNOELEMENT:argument->Eval(context, aNULL, idthread);
return this;
}
virtual Tamgu* Put(Tamgu* index, Tamgu* v, short idthread) {
globalTamgu->threads[idthread].returnvalue = v;
return aTRUE;
}
bool isTail() {
return tail;
}
bool isCall() {
return true;
}
bool isCallFunction() {
return true;
}
long Size() {
if (argument == NULL)
return 0;
return 1;
}
Tamgu* Argument(size_t i) {
if (argument == aNOELEMENT)
return NULL;
return argument;
}
Tamgu* Returned(short idthread) {
return globalTamgu->threads[idthread].returnvalue;
}
virtual void AddInstruction(Tamgu* a) {
if (argument != aNOELEMENT)
return;
argument = a;
}
};
//To handle aBREAKTRUE et aBREAKFALSE
class TamguCallBreak : public TamguCallReturn {
public:
TamguCallBreak(Tamgu* a, TamguGlobal* global) : TamguCallReturn(global) {
argument = a;
}
Tamgu* Eval(Tamgu* context, Tamgu* v, short idthread) {
globalTamgu->threads[idthread].returnvalue = argument;
return this;
}
Tamgu* DirectEval(Tamgu* context, Tamgu* v, short idthread) {
globalTamgu->threads[idthread].returnvalue = argument;
return this;
}
Tamgu* Put(Tamgu* index, Tamgu* v, short idthread) {
return aTRUE;
}
void AddInstruction() {}
};
//----------------------------------------------------------------------
//Variables are declarations, which are executed through a Put
class TamguVariableDeclaration : public TamguTracked {
public:
Tamgu* initialization;
Tamgu* function;
short name;
short typevariable;
bool isprivate;
bool choice;
bool isframe;
bool isconstant;
TamguVariableDeclaration(TamguGlobal* g, short n, short t, bool p, bool c, Tamgu* parent);
TamguVariableDeclaration(TamguGlobal* g, short n, short t, Tamgu* parent = NULL);
//When we call this function, we actually will create an element of type value
virtual Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
virtual Tamgu* Put(Tamgu* index, Tamgu* value, short idthread);
virtual bool Setarguments(TamguDeclarationLocal* index, Tamgu* value, short idthread, bool strict = false);
string String() {
string s = "[";
s = globalTamgu->Getsymbol(typevariable);
s += " ";
s += globalTamgu->Getsymbol(name);
if (initialization != NULL) {
s += " = ";
s += initialization->String();
}
s += "]";
return s;
}
string displayString() {
return String();
}
bool Checkarity();
bool isFrame() {
return isframe;
}
bool isConstant() {
return isconstant;
}
void Copiing(TamguVariableDeclaration* a) {
initialization = a->initialization;
function = a->function;
Getinfo(a);
}
void ScanVariables(vector<short>& vars) {
vars.push_back(name);
if (initialization!=NULL)
initialization->ScanVariables(vars);
}
bool isFunction() {
//We can check whether it is a TamguFunctionCall object, then it can be a function
if (typevariable == a_call)
return true;
return false;
}
Tamgu* Initialisation() {
return initialization;
}
virtual void AddInstruction(Tamgu* a) {
if (!choice)
initialization = a;
else
function = a;
}
bool Private() {
return isprivate;
}
short Typevariable() {
return typevariable;
}
short Typeinfered() {
return typevariable;
}
Tamgu* Frame() {
if (globalTamgu->newInstance.check(typevariable))
return globalTamgu->newInstance[typevariable]->Frame();
return NULL;
}
Tamgu* Function() {
return function;
}
bool Setstopindex() {
if (function !=NULL)
function->Setstopindex();
return false;
}
bool isDirectIndex() {
return (function != NULL && function->isIndex() && !function->Function());
}
short Name() {
return name;
}
};
class TamguAtomicVariableDeclaration : public TamguVariableDeclaration {
public:
Tamgu* constant;
Tamgu* reference;
char directcall;
TamguAtomicVariableDeclaration(TamguGlobal* g, short n, short t, bool p, bool c, Tamgu* parent) : TamguVariableDeclaration(g,n,t,p,c,parent) {
reference = globalTamgu->newInstance.get(typevariable);
constant = aNULL;
switch (typevariable) {
case a_boolean:
constant = aTRUE;
break;
case a_string:
constant = aEMPTYSTRING;
break;
case a_ustring:
constant = aEMPTYUSTRING;
break;
case a_decimal:
case a_float:
constant = aZEROPOINTZERO;
break;
case a_int:
case a_long:
case a_short:
constant = aZERO;
break;
}
directcall=false;
}
TamguAtomicVariableDeclaration(TamguGlobal* g, short n, short t, Tamgu* parent = NULL) : TamguVariableDeclaration(g,n,t,parent) {
reference = globalTamgu->newInstance.get(typevariable);
directcall=false;
}
bool Setarguments(TamguDeclarationLocal* index, Tamgu* value, short idthread, bool strict = false);
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
Tamgu* Put(Tamgu* index, Tamgu* value, short idthread);
void AddInstruction(Tamgu* a) {
if (!choice) {
initialization = a;
directcall = true;
if (initialization->isConst())
directcall = 2;
}
else
function = a;
}
};
class TamguTaskellVariableDeclaration : public TamguVariableDeclaration {
public:
char directcall;
TamguTaskellVariableDeclaration(TamguGlobal* g, short n, short t, bool p, bool c, Tamgu* parent) : directcall(1),TamguVariableDeclaration(g, n, t, p, c, parent) {}
TamguTaskellVariableDeclaration(TamguGlobal* g, short n, short t, Tamgu* parent = NULL) : directcall(1),TamguVariableDeclaration(g, n, t, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
};
class TamguTaskellSelfVariableDeclaration : public TamguVariableDeclaration {
public:
char directcall;
TamguTaskellSelfVariableDeclaration(TamguGlobal* g, short n, short tid = a_self, Tamgu* parent = NULL) : directcall(1),TamguVariableDeclaration(g, n, tid, false, false, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
Tamgu* Put(Tamgu* index, Tamgu* value, short idthread);
bool Computevariablecheck(short idthread) {
if (initialization == NULL)
return true;
return initialization->Computevariablecheck(idthread);
}
};
class TamguFrameVariableDeclaration : public TamguVariableDeclaration {
public:
bool common;
TamguFrameVariableDeclaration(TamguGlobal* g, short n, short t, bool p, bool c, Tamgu* parent) : common(c), TamguVariableDeclaration(g, n, t, p, false, parent) {
if (g != NULL)
g->framevariables[n] = this;
}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
};
class TamguFrameAtomicVariableDeclaration : public TamguAtomicVariableDeclaration {
public:
bool common;
TamguFrameAtomicVariableDeclaration(TamguGlobal* g, short n, short t, bool p, bool c, Tamgu* parent) : common(c), TamguAtomicVariableDeclaration(g, n, t, p, false, parent) {
if (g != NULL)
g->framevariables[n] = this;
}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
};
class TamguGlobalVariableDeclaration : public TamguVariableDeclaration {
public:
bool alreadydeclared;
TamguGlobalVariableDeclaration(TamguGlobal* g, short n, short t, bool p, bool c, Tamgu* parent) : alreadydeclared(false), TamguVariableDeclaration(g, n, t, p, c, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
bool isGlobalVariable() {
return true;
}
};
class TamguThroughVariableDeclaration : public TamguVariableDeclaration {
public:
string sname;
string tname;
TamguThroughVariableDeclaration(short n, short t, string sn, string tn, Tamgu* parent) : sname(sn), tname(tn), TamguVariableDeclaration(NULL, n, t, parent) {}
Tamgu* Eval(Tamgu* context, Tamgu* value, short idthread);
void Resetreference(short i = 1) {}
bool Candelete() {
return false;
}
};
class TamguSystemVariable : public TamguVariableDeclaration {
public:
Tamgu* value;
Exporting TamguSystemVariable(TamguGlobal* g, Tamgu* v, short n, short t);
Tamgu* Atom(bool forced = false) {
return value->Newvalue(value, 0);
}
Tamgu* plus(Tamgu* a, bool itself) {
return value->plus(a, false);
}
Tamgu* minus(Tamgu* a, bool itself) {
return value->minus(a, false);
}
Tamgu* multiply(Tamgu* a, bool itself) {
return value->multiply(a, true);
}
Tamgu* divide(Tamgu* a, bool itself) {
return value->divide(a, true);
}
Tamgu* divideinteger(Tamgu* a, bool itself) {
return value->divideinteger(a, true);
}
Tamgu* power(Tamgu* a, bool itself) {
return value->power(a, true);
}
Tamgu* shiftleft(Tamgu* a, bool itself) {
return value->shiftleft(a, true);
}
Tamgu* shiftright(Tamgu* a, bool itself) {
return value->shiftright(a, true);