955049bffde43785730b872a88366e8cf54238c1
[tpg/acess2.git] / Usermode / Libraries / libspiderscript.so_src / bytecode_gen.h
1 /*
2  * SpiderScript Library
3  * - By John Hodge (thePowersGang)
4  *
5  * bytecode_gen.h
6  * - Bytecode Generation header
7  */
8 #ifndef _BYTECODE_GEN_H_
9 #define _BYTECODE_GEN_H_
10
11 #include "common.h"
12 #include "ast.h"
13 #include "bytecode.h"
14
15 typedef struct sStringList      tStringList;
16 typedef struct sString  tString;
17
18 struct sString
19 {
20         tString *Next;
21          int    Length;
22          int    RefCount;
23         char    Data[];
24 };
25
26 struct sStringList
27 {
28         tString *Head;
29         tString *Tail;
30          int    Count;
31 };
32
33
34 extern int      Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile);
35 extern tBC_Function     *Bytecode_ConvertFunction(tScript_Function *Fcn);
36 extern tBC_Function     *Bytecode_NewBlankFunction(void);
37 extern void     Bytecode_DeleteFunction(tBC_Function *Fcn);
38
39 extern char *Bytecode_SerialiseFunction(const tBC_Function *Function, int *Length, tStringList *Strings);
40 extern int      StringList_GetString(tStringList *List, const char *String, int Length);
41 extern tBC_Function     *Bytecode_CreateFunction(tScript_Function *Fcn);
42
43 extern int      Bytecode_AllocateLabel(tBC_Function *Handle);
44 extern void     Bytecode_SetLabel(tBC_Function *Handle, int Label);
45 // Bytecode adding
46 // - Flow Control
47 extern void     Bytecode_AppendJump(tBC_Function *Handle, int Label);
48 extern void     Bytecode_AppendCondJump(tBC_Function *Handle, int Label);
49 extern void      Bytecode_AppendCondJumpNot(tBC_Function *Handle, int Label);
50 extern void     Bytecode_AppendReturn(tBC_Function *Handle);
51 // - Operation Stack
52 //  > Load/Store
53 extern void     Bytecode_AppendLoadVar(tBC_Function *Handle, const char *Name);
54 extern void     Bytecode_AppendSaveVar(tBC_Function *Handle, const char *Name); // (Obj->)?var = 
55 extern void     Bytecode_AppendConstInt(tBC_Function *Handle, uint64_t Value);
56 extern void     Bytecode_AppendConstReal(tBC_Function *Handle, double Value);
57 extern void     Bytecode_AppendConstString(tBC_Function *Handle, const void *Data, size_t Length);
58 //  > Scoping
59 extern void     Bytecode_AppendElement(tBC_Function *Handle, const char *Name); // Obj->SubObj
60 extern void     Bytecode_AppendIndex(tBC_Function *Handle);     // Index into an array
61 //  > Function Calls
62 extern void     Bytecode_AppendCreateObj(tBC_Function *Handle, const char *Name, int ArgumentCount);
63 extern void     Bytecode_AppendMethodCall(tBC_Function *Handle, const char *Name, int ArgumentCount);
64 extern void     Bytecode_AppendFunctionCall(tBC_Function *Handle, const char *Name, int ArgumentCount);
65 //  > Manipulation
66 extern void     Bytecode_AppendBinOp(tBC_Function *Handle, int Operation);
67 extern void     Bytecode_AppendUniOp(tBC_Function *Handle, int Operation);
68 extern void     Bytecode_AppendCast(tBC_Function *Handlde, int Type);
69 extern void     Bytecode_AppendDuplicate(tBC_Function *Handlde);
70 // - Context
71 //   TODO: Are contexts needed? Should variables be allocated like labels?
72 extern void     Bytecode_AppendEnterContext(tBC_Function *Handle);
73 extern void     Bytecode_AppendLeaveContext(tBC_Function *Handle);
74 //extern void   Bytecode_AppendImportNamespace(tBC_Function *Handle, const char *Name);
75 extern void     Bytecode_AppendDefineVar(tBC_Function *Handle, const char *Name, int Type);
76
77 #endif
78

UCC git Repository :: git.ucc.asn.au