Kiwi Engine
VM for interpreter
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
KEInstruction.h
Go to the documentation of this file.
1 
8 #ifndef KEINSTRUCTION_H
9 #define KEINSTRUCTION_H
10 
11 #include <Coconut/Coconut.h>
12 #include "KEValue.h"
13 #include "KERegister.h"
14 
16 typedef enum {
17  KENopOpcode,
18  KEFunctionOpcode,
19  KECompoundOpcode,
20  KEMovLOpcode,
21  KEMovPOpcode,
22  KEMovHOpcode,
23  KEMovROpcode,
24  KESetBoolOpcode,
25  KESetSignedIntOpcode,
26  KESetUnsignedIntOpcode,
27  KESetFloatOpcode,
28  KESetStringOpcode,
29  KELogicalNotOpcode,
30  KELogicalAndOpcode,
31  KELogicalOrOpcode,
32  KELogicalXorOpcode,
33  KEBitNotOpcode,
34  KEBitAndOpcode,
35  KEBitOrOpcode,
36  KEBitXorOpcode,
37  KEEqualBoolOpcode,
38  KEEqualSignedIntOpcode,
39  KEEqualUnsignedIntOpcode,
40  KEEqualFloatOpcode,
41  KEEqualStringOpcode,
42  KENotEqualBoolOpcode,
43  KENotEqualSignedIntOpcode,
44  KENotEqualUnsignedIntOpcode,
45  KENotEqualFloatOpcode,
46  KENotEqualStringOpcode,
47  KELessThanSignedIntOpcode,
48  KELessThanUnsignedIntOpcode,
49  KELessThanFloatOpcode,
50  KELessThanStringOpcode,
51  KELessEqualSignedIntOpcode,
52  KELessEqualUnsignedIntOpcode,
53  KELessEqualFloatOpcode,
54  KELessEqualStringOpcode,
55  KEGreaterThanSignedIntOpcode,
56  KEGreaterThanUnsignedIntOpcode,
57  KEGreaterThanFloatOpcode,
58  KEGreaterThanStringOpcode,
59  KEGreateEqualSignedIntOpcode,
60  KEGreateEqualUnsignedIntOpcode,
61  KEGreateEqualFloatOpcode,
62  KEGreateEqualStringOpcode,
63  KENegSignedIntOpcode,
64  KENegFloatOpcode,
65  KEAddSignedIntOpcode,
66  KEAddUnsignedIntOpcode,
67  KEAddFloatOpcode,
68  KEAddStringOpcode,
69  KESubSignedIntOpcode,
70  KESubUnsignedIntOpcode,
71  KESubFloatOpcode,
72  KEMulSignedIntOpcode,
73  KEMulUnsignedIntOpcode,
74  KEMulFloatOpcode,
75  KEDivSignedIntOpcode,
76  KEDivUnsignedIntOpcode,
77  KEDivFloatOpcode,
78  KEModSignedIntOpcode,
79  KEModUnsignedIntOpcode,
80  KECastItoUOpcode,
81  KECastItoFOpcode,
82  KECastUtoIOpcode,
83  KECastUtoFOpcode,
84  KECastFtoIOpcode,
85  KECastFtoUOpcode,
86  KECreateFuncOpcode,
87  KECallFuncOpcode,
88  KECallBuiltinOpcode,
89  KERootFrameOpcode,
90  KECreateFrameOpcode,
91  KESetFrameOpcode,
92  KEGetFrameOpcode,
93  KECreateArrayOpcode,
94  KESetArrayOpcode,
95  KEGetArrayOpcode,
96  KECreateDictionaryOpcode,
97  KESetDictionaryOpcode,
98  KEGetDictionaryOpcode,
99  KEIfThenOpcode,
100  KEIfElseOpcode,
101  KESwitchOpcode,
102  KECaseOpcode,
103  KEWhileOpcode,
104  KEForeachArrayOpcode,
105  KEForeachDictOpcode,
106  KEReturnOpcode,
107  KENextOpcode,
108  KELastOpcode,
109  KEExitOpcode
110 } KEOpcode ;
111 
117  struct CNObject superClass ;
121  union {
123  struct {
130  struct {
132  struct CNObjectList instructionList ;
135  struct {
140  } moveInstruction ;
142  struct {
147  } setInstruction ;
149  struct {
154  } unaryInstruction ;
156  struct {
165  struct {
169  struct KEPath * path ;
174  struct KEValue * pathValue ;
180  struct CNObjectList hiddenRegisters ;
182  struct {
186  struct CNObjectList returnRegisters ;
188  struct CNObjectList parameterRegisters ;
189  } callFunctionInstruction ;
190  struct {
192  struct KEPath * path ;
197  struct KEValue * pathValue ;
199  struct CNObjectList returnRegisters ;
201  struct CNObjectList parameterRegisters ;
202  } callBuiltinInstruction ;
203  struct {
207  struct KEFrame * rootFrame ;
208  } rootFrameInstruction ;
209  struct {
212  } createFrameInstruction ;
213  struct {
220  } setFrameInstruction ;
221  struct {
227  struct KEPath * sourcePath ;
228  } getFrameInstruction ;
229  struct {
232  } createArrayInstruction ;
233  struct {
240  } setArrayInstruction ;
241  struct {
248  } getArrayInstruction ;
249  struct {
252  } createDictionaryInstruction ;
253  struct {
260  } setDictionaryInstruction ;
261  struct {
268  } getDictionaryInstruction ;
269  struct {
279  } ifInstruction ;
280  struct {
284  struct CNObjectList caseInstructionList ;
287  } switchInstruction ;
288  struct {
290  CNBoolean isDefaultCondition ;
295  int64_t caseValue ;
298  } caseInstruction ;
299  struct {
304  } whileInstruction ;
305  struct {
311  struct KEInstruction * bodyInstruction ;
312  } foreachArrayInstruction ;
313  struct {
319  struct KEInstruction * bodyInstruction ;
320  } foreachDictionaryInstruction ;
322  struct {
323  KERegisterId codeId ;
324  } exitInstruction ;
325  } ; /* No name union */
326 
328  struct KELineInfo * lineInfo ;
329 } ;
330 
339 struct KEInstruction *
341  struct KELineInfo * linfo,
342  struct CNResource * resource) ;
343 
350 struct KEInstruction *
351 KEAllocateNopInstruction(struct KELineInfo * linfo, struct CNResource * resource) ;
352 
359 struct KEInstruction *
360 KEAllocateCompoundInstruction(struct KELineInfo * linfo, struct CNResource * resource) ;
361 
371 struct KEInstruction *
373  KERegisterId dstid,
374  KERegisterId srcid,
375  struct KELineInfo * linfo,
376  struct CNResource * resource) ;
377 
386 struct KEInstruction *
388  CNBoolean val,
389  struct KELineInfo * linfo,
390  struct CNResource * resource) ;
391 
400 struct KEInstruction *
402  int64_t val,
403  struct KELineInfo * linfo,
404  struct CNResource * resource) ;
405 
414 struct KEInstruction *
416  uint64_t val,
417  struct KELineInfo * linfo,
418  struct CNResource * resource) ;
419 
428 struct KEInstruction *
430  double val,
431  struct KELineInfo * linfo,
432  struct CNResource * resource) ;
433 
442 struct KEInstruction *
444  struct CNString * val,
445  struct KELineInfo * linfo,
446  struct CNResource * resource) ;
447 
457 struct KEInstruction *
459  KERegisterId dstid,
460  KERegisterId srcid,
461  struct KELineInfo * linfo,
462  struct CNResource * resource) ;
463 
474 struct KEInstruction *
476  KERegisterId dstid,
477  KERegisterId leftid,
478  KERegisterId rightid,
479  struct KELineInfo * linfo,
480  struct CNResource * resource) ;
481 
491 struct KEInstruction *
493  struct KEPath * funcpath,
494  struct CNObjectList * hiddenregs,
495  struct KELineInfo * linfo,
496  struct CNResource * resource) ;
497 
507 struct KEInstruction *
509  struct CNObjectList * retregs,
510  struct CNObjectList * paramregs,
511  struct KELineInfo * linfo,
512  struct CNResource * resource) ;
513 
523 struct KEInstruction *
525  struct CNObjectList * retregs,
526  struct CNObjectList * paramregs,
527  struct KELineInfo * linfo,
528  struct CNResource * resource) ;
529 
537 struct KEInstruction *
539  struct KELineInfo * linfo,
540  struct CNResource * resource) ;
541 
549 struct KEInstruction *
551  struct KELineInfo * linfo,
552  struct CNResource * resource) ;
553 
563 struct KEInstruction *
565  struct KEPath * dstpath,
566  KERegisterId srcid,
567  struct KELineInfo * linfo,
568  struct CNResource * resource) ;
569 
579 struct KEInstruction *
581  KERegisterId srcid,
582  struct KEPath * srcpath,
583  struct KELineInfo * linfo,
584  struct CNResource * resource) ;
585 
593 struct KEInstruction *
595  struct KELineInfo * linfo,
596  struct CNResource * resource) ;
597 
607 struct KEInstruction *
609  KERegisterId dstindex,
610  KERegisterId srcid,
611  struct KELineInfo * linfo,
612  struct CNResource * resource) ;
613 
623 struct KEInstruction *
625  KERegisterId srcid,
626  KERegisterId srcindex,
627  struct KELineInfo * linfo,
628  struct CNResource * resource) ;
629 
637 struct KEInstruction *
639  struct KELineInfo * linfo,
640  struct CNResource * resource) ;
641 
651 struct KEInstruction *
653  KERegisterId dstkey,
654  KERegisterId srcid,
655  struct KELineInfo * linfo,
656  struct CNResource * resource) ;
657 
667 struct KEInstruction *
669  KERegisterId srcid,
670  KERegisterId srckey,
671  struct KELineInfo * linfo,
672  struct CNResource * resource) ;
673 
683 struct KEInstruction *
685  struct KEInstruction * theninst,
686  struct KEInstruction * elseinst,
687  struct KELineInfo * linfo,
688  struct CNResource * resource) ;
689 
698 struct KEInstruction *
700  struct CNObjectList * caseinsts,
701  struct KELineInfo * linfo,
702  struct CNResource * resource) ;
703 
713 struct KEInstruction *
714 KEAllocateCaseInstruction(CNBoolean isdef,
715  uint64_t caseval,
716  struct KEInstruction * bodyinst,
717  struct KELineInfo * linfo,
718  struct CNResource * resource) ;
719 
728 struct KEInstruction *
730  struct KEInstruction * bodyinst,
731  struct KELineInfo * linfo,
732  struct CNResource * resource) ;
733 
743 struct KEInstruction *
745  KERegisterId arrayid,
746  struct KEInstruction * bodyinst,
747  struct KELineInfo * linfo,
748  struct CNResource * resource) ;
749 
759 struct KEInstruction *
761  KERegisterId dictid,
762  struct KEInstruction * bodyinst,
763  struct KELineInfo * linfo,
764  struct CNResource * resource) ;
765 
772 struct KEInstruction *
773 KEAllocateReturnInstruction(struct KELineInfo * linfo, struct CNResource * resource) ;
774 
781 struct KEInstruction *
782 KEAllocateNextInstruction(struct KELineInfo * linfo, struct CNResource * resource) ;
783 
790 struct KEInstruction *
791 KEAllocateLastInstruction(struct KELineInfo * linfo, struct CNResource * resource) ;
792 
800 struct KEInstruction *
801 KEAllocateExitInstruction(KERegisterId codeid, struct KELineInfo * linfo, struct CNResource * resource) ;
802 
808 static inline struct CNResource *
809 KEResourceOfInstruction(struct KEInstruction * src)
810 {
811  return CNResourceOfObject(&(src->superClass)) ;
812 }
813 
818 static inline void
819 KERetainInstruction(struct KEInstruction * dst)
820 {
821  CNRetainObject(&(dst->superClass)) ;
822 }
823 
828 static inline void
829 KEReleaseInstruction(struct KEInstruction * dst)
830 {
831  CNReleaseObject(&(dst->superClass)) ;
832 }
833 
839 static inline KEOpcode
840 KEOpcodeOfInstruction(const struct KEInstruction * src)
841 {
842  return src->opCode ;
843 }
844 
850 static inline struct KELineInfo *
851 KELineInfoOfInstruction(const struct KEInstruction * src)
852 {
853  return src->lineInfo ;
854 }
855 
861 const char *
863 
869 static inline void
870 KEAddInstructionToCompoundInstruction(struct KEInstruction * dst, struct KEInstruction * src)
871 {
872  CNAppendObjectToList(&((dst->compoundInstruction).instructionList), &(src->superClass)) ;
873 }
874 
875 #endif /* KEINSTRUCTION_H */
struct KEInstruction * KEAllocateNextInstruction(struct KELineInfo *linfo, struct CNResource *resource)
Allocate next instruction.
KEProgram class.
Definition: KELineInfo.h:19
struct KEInstruction * KEAllocateCaseInstruction(CNBoolean isdef, uint64_t caseval, struct KEInstruction *bodyinst, struct KELineInfo *linfo, struct CNResource *resource)
Allocate case instruction.
struct CNObjectList hiddenRegisters
Definition: KEInstruction.h:180
struct KEInstruction * KEAllocateIfInstruction(KERegisterId condid, struct KEInstruction *theninst, struct KEInstruction *elseinst, struct KELineInfo *linfo, struct CNResource *resource)
Allocate if instruction.
struct CNObjectList parameterRegisters
Definition: KEInstruction.h:188
KERegisterId elementId
Definition: KEInstruction.h:307
struct KEInstruction * KEAllocateReturnInstruction(struct KELineInfo *linfo, struct CNResource *resource)
Allocate return instruction.
KERegisterId rightId
Definition: KEInstruction.h:162
KERegisterId sourceIndex
Definition: KEInstruction.h:247
struct KEPath * sourcePath
Definition: KEInstruction.h:227
int64_t caseValue
Definition: KEInstruction.h:295
struct KEInstruction * KEAllocateGetFrameInstruction(KERegisterId dstid, KERegisterId srcid, struct KEPath *srcpath, struct KELineInfo *linfo, struct CNResource *resource)
Allocate get-frame instruction.
struct KEInstruction * KEAllocateForeachDictionaryInstruction(KERegisterId elmid, KERegisterId dictid, struct KEInstruction *bodyinst, struct KELineInfo *linfo, struct CNResource *resource)
Allocate foreach-dictionary instruction.
struct KEPath * path
Definition: KEInstruction.h:169
KERegisterId arrayId
Definition: KEInstruction.h:309
struct KEInstruction * thenInstruction
Definition: KEInstruction.h:273
struct KELineInfo * lineInfo
Definition: KEInstruction.h:328
KERegisterId sourceKey
Definition: KEInstruction.h:267
struct KEInstruction * elseInstruction
Definition: KEInstruction.h:278
struct KEInstruction::@16::@22 unaryInstruction
Define KEValue data structure.
Definition: KEFrame.h:16
KERegisterId destinationKey
Definition: KEInstruction.h:257
struct KEInstruction * KEAllocateSetUnsignedIntInstruction(KERegisterId dstid, uint64_t val, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-unsigned-int instruction.
struct CNObjectList caseInstructionList
Definition: KEInstruction.h:284
struct KEInstruction::@16::@21 setInstruction
struct KEInstruction * defaultInstruction
Definition: KEInstruction.h:286
struct KEInstruction * KEAllocateRootFrameInstruction(KERegisterId dstid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate root-frame instruction.
struct KEInstruction * KEAllocateSetFrameInstruction(KERegisterId dstid, struct KEPath *dstpath, KERegisterId srcid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-frame instruction.
struct KEInstruction * KEAllocateCreateDictionaryInstruction(KERegisterId dstid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate create-dictionary instruction.
KERegisterId functionId
Definition: KEInstruction.h:184
struct KEInstruction * KEAllocateSetBoolInstruction(KERegisterId dstid, CNBoolean val, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-bool instruction.
struct KEInstruction * KEAllocateCreateFrameInstruction(KERegisterId dstid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate create-frame instruction.
struct KEInstruction * KEAllocateSetStringInstruction(KERegisterId dstid, struct CNString *val, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-string instruction.
struct KEInstruction::@16::@20 moveInstruction
struct KEInstruction::@16::@23 binaryInstruction
struct KEInstruction * KEAllocateExitInstruction(KERegisterId codeid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate exit instruction.
struct KEInstruction * compoundInstruction
Definition: KEInstruction.h:125
struct KEInstruction * KEAllocateCreateArrayInstruction(KERegisterId dstid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate create-array instruction.
struct KEInstruction * KEAllocateGetArrayInstruction(KERegisterId dstid, KERegisterId srcid, KERegisterId srcindex, struct KELineInfo *linfo, struct CNResource *resource)
Allocate get-array instruction.
struct CNObjectList instructionList
Definition: KEInstruction.h:132
KEOpcode opCode
Definition: KEInstruction.h:119
CNBoolean isDefaultCondition
Definition: KEInstruction.h:290
Definition: KEInstruction.h:115
KERegisterId destinationId
Definition: KEInstruction.h:137
struct KEInstruction * KEAllocateSwitchInstruction(KERegisterId condid, struct CNObjectList *caseinsts, struct KELineInfo *linfo, struct CNResource *resource)
Allocate switch instruction.
struct KEInstruction * KEAllocateCreateFunctionInstruction(KERegisterId dstid, struct KEPath *funcpath, struct CNObjectList *hiddenregs, struct KELineInfo *linfo, struct CNResource *resource)
Allocate create-function instruction.
struct KEInstruction * KEAllocateSetSignedIntInstruction(KERegisterId dstid, int64_t val, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-signed-int instruction.
Define register information.
struct KEValue * pathValue
Definition: KEInstruction.h:174
struct KEInstruction * KEAllocateWhileInstruction(KERegisterId condid, struct KEInstruction *bodyinst, struct KELineInfo *linfo, struct CNResource *resource)
Allocate while instruction.
struct KEInstruction * bodyInstruction
Definition: KEInstruction.h:303
struct KEInstruction * KEAllocateCallFunctionInstruction(KERegisterId funcid, struct CNObjectList *retregs, struct CNObjectList *paramregs, struct KELineInfo *linfo, struct CNResource *resource)
Allocate call-function instruction.
Definition: KEValue.h:40
struct KEInstruction * KEAllocateSetFloatInstruction(KERegisterId dstid, double val, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-float instruction.
struct KEFrame * rootFrame
Definition: KEInstruction.h:207
struct KEInstruction * KEAllocateFunctionInstruction(struct KEInstruction *body, struct KELineInfo *linfo, struct CNResource *resource)
Allocate function instruction object.
struct KEInstruction::@16::@24 createFunctionInstruction
KERegisterId sourceId
Definition: KEInstruction.h:139
struct KEInstruction * KEAllocateNopInstruction(struct KELineInfo *linfo, struct CNResource *resource)
Allocate nop instruction.
KERegisterId dictionaryId
Definition: KEInstruction.h:317
struct KEInstruction::@16::@43 exitInstruction
KERegisterId conditionId
Definition: KEInstruction.h:271
struct CNObject superClass
Definition: KEInstruction.h:117
struct KEInstruction * KEAllocateMovInstruction(KEOpcode opcode, KERegisterId dstid, KERegisterId srcid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate move instruction.
KERegisterId leftId
Definition: KEInstruction.h:160
struct KEInstruction * KEAllocateSetArrayInstruction(KERegisterId dstid, KERegisterId dstindex, KERegisterId srcid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-array instruction.
struct KEInstruction::@16::@18 functionInstruction
struct KEInstruction * KEAllocateLastInstruction(struct KELineInfo *linfo, struct CNResource *resource)
Allocate last instruction.
struct KEInstruction * KEAllocateSetDictionaryInstruction(KERegisterId dstid, KERegisterId dstkey, KERegisterId srcid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate set-dictionary instruction.
struct KEInstruction * caseInstruction
Definition: KEInstruction.h:297
struct KEInstruction * KEAllocateCallBuiltinInstruction(struct KEPath *path, struct CNObjectList *retregs, struct CNObjectList *paramregs, struct KELineInfo *linfo, struct CNResource *resource)
Allocate call-builtin instruction.
struct KEInstruction * KEAllocateUnaryInstruction(KEOpcode opcode, KERegisterId dstid, KERegisterId srcid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate unary instruction.
struct KEValue constantValue
Definition: KEInstruction.h:146
Definition: KEPath.h:16
const char * KEOpcodeString(KEOpcode src)
Get string to present the opcode.
struct KEInstruction * KEAllocateForeachArrayInstruction(KERegisterId elmid, KERegisterId arrayid, struct KEInstruction *bodyinst, struct KELineInfo *linfo, struct CNResource *resource)
Allocate foreach-array instruction.
KERegisterId destinationIndex
Definition: KEInstruction.h:237
struct CNObjectList returnRegisters
Definition: KEInstruction.h:186
struct KEInstruction * KEAllocateGetDictionaryInstruction(KERegisterId dstid, KERegisterId srcid, KERegisterId srckey, struct KELineInfo *linfo, struct CNResource *resource)
Allocate get-dictionary instruction.
struct KEPath * destinationPath
Definition: KEInstruction.h:217
struct KEInstruction * KEAllocateBinaryInstruction(KEOpcode opcode, KERegisterId dstid, KERegisterId leftid, KERegisterId rightid, struct KELineInfo *linfo, struct CNResource *resource)
Allocate binary instruction.
uint16_t KERegisterId
Definition: KERegister.h:14
struct KEInstruction * KEAllocateCompoundInstruction(struct KELineInfo *linfo, struct CNResource *resource)
Allocate compound instruction.
KEOpcode
Definition: KEInstruction.h:16
KERegisterId maxLocalRegisterId
Definition: KEInstruction.h:127