 |
Gorgon Game Engine
|
Go to the documentation of this file.
5 #include "../../Containers/Collection.h"
7 #include "../Instruction.h"
10 namespace Gorgon {
namespace Scripting {
namespace Compilers {
117 ASTCompiler(std::vector<Instruction> &list,
Base &parser) : parser(parser), list(&list) { }
127 bool IsReady()
const {
return waitingcount==0; }
131 throw FlowException(scope::keywordnames[scopes.back().type]+
" scope is not closed.");
137 void release(
int start,
int except=-1);
138 void release(
int start,
Value except);
151 static const std::string keywordnames[];
153 scope(scopetype type,
int index) : type(type) { indices.push_back(index); }
155 scope(scopetype type) : type(type) { }
157 scope(scopetype type,
const Data &data) : type(type), data(data) { }
161 std::vector<int> indices;
162 std::vector<int> indices2;
168 std::vector<scope> scopes;
169 std::vector<std::vector<Instruction>*> redirects;
173 int waitingcount = 0;
174 std::vector<Instruction> *list;
184 void ASTToSVG(
const std::string &line, ASTNode &tree,
const std::vector<std::string> &compiled={},
bool show=
false);
void ASTToSVG(const std::string &line, ASTNode &tree, const std::vector< std::string > &compiled={}, bool show=false)
Converts given AST to an SVG file.
Definition: AST.cpp:88
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
constexpr Type Data
Data resource.
Definition: GID.h:164
@ FunctionCall
Marks instruction as a regular function call.
void Register(const Data &data)
Registers a new object of reference counting, this will set reference count to one.
Definition: Runtime.h:24
std::string Replace(std::string str, const std::string &find, const std::string &replace)
String replace that does not use regex.
Definition: String.h:349
std::string Text
Textual data held by this node.
Definition: AST.h:97
@ Operator
This node represents an operator. All operators in GorgonScript are left associative and binary.
Definition: AST.h:46
bool Open(const std::string &file)
Opens the given file with the related application.
Definition: Linux.cpp:268
void SetStringLiteral(const std::string &value)
Definition: Instruction.h:105
int Start
Starting character of the node. Used for error locating.
Definition: AST.h:91
ReferenceCounter References
This system allows objects of automatic lifetime.
Definition: VirtualMachine.h:222
void PrintAST(ASTNode &tree)
Recursively prints an AST.
Definition: AST.cpp:120
@ Identifier
This node is an identifier.
Definition: AST.h:40
bool Reference
Definition: Instruction.h:170
Data describes a piece of data.
Definition: Data.h:22
std::string ToString() const
Definition: Data.cpp:90
@ Literal
This node represents a literal. Literal member of ASTNode should be set.
Definition: AST.h:25
bool Start(const std::string &name, const std::vector< std::string > &args=std::vector< std::string >())
Starts the given application.
Definition: Linux.cpp:116
unsigned Compile(ASTNode *tree)
This function compiles given abstract syntax tree, returns the number of instructions generated.
Definition: AST.cpp:355
Value RHS
The value that will be assigned to the variable.
Definition: Instruction.h:165
Value Name
Name of the function or variable.
Definition: Instruction.h:162
The base class for compilers.
Definition: Compilers.h:21
@ Assignment
Marks instruction as an assignment.
static VirtualMachine & Get()
Returns the current VM for this thread.
Definition: VirtualMachine.h:109
@ Keyword
This node is a keyword call.
Definition: AST.h:57
@ FunctionCall
This node represents a function call.
Definition: AST.h:30
bool IsReady() const
If this function returns true, it is ok to use instructions from the list.
Definition: AST.h:127
void Finalize()
Definition: AST.h:129
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
const Type & GetType() const
Returns the type of the data.
Definition: Data.h:173
Represents a node in abstract syntax tree.
Definition: AST.h:19
~ASTNode()
Destroying a node destroys its children.
Definition: AST.h:83
int Line
Starting line of this ASTNode.
Definition: AST.h:94
ASTNode(NodeType type)
Constructor requires the node type.
Definition: AST.h:70
This class stores information about types.
Definition: Reflection.h:1165
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
ASTNode * Duplicate()
Duplicates this node.
Definition: AST.h:73
std::string Name
Used for variables and constants.
Definition: Instruction.h:84
@ Variable
This node represents a variable identifier.
Definition: AST.h:43
@ MethodCall
Same as function call, this just calls method variant if it exists, if not it will print out return v...
Definition: AST.h:34
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
ASTCompiler stores states for AST compiler.
Definition: AST.h:112
static Data Invalid()
Constructs an invalid data object.
Definition: Data.h:27
Collection is a container for reference typed objects.
Definition: Collection.h:21
Data Literal
Used for literal values.
Definition: Instruction.h:87
std::string ToLower(std::string str)
Converts the given string to lowercase.
Definition: String.h:416
Containers::Collection< ASTNode > Leaves
Leaves of this node.
Definition: AST.h:103
@ Member
This node represents a membership. Membership should be parsed as left associative.
Definition: AST.h:37
InstructionType Type
Type of the instruction.
Definition: Instruction.h:159
Data LiteralValue
If node type is literal, this value will be used.
Definition: AST.h:100
This class contains a parsed value.
Definition: Instruction.h:82
@ Assignment
This node is an assignment. This node should be top level.
Definition: AST.h:60
Byte Result
Used for temporary results.
Definition: Instruction.h:93
NodeType Type
Type of the node.
Definition: AST.h:88
std::string dottree(ASTNode &tree, int &ind)
Definition: AST.cpp:15
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
@ MethodCall
Marks this instruction as a method call.
@ Index
This node represents an indexing operation.
Definition: AST.h:50
ASTCompiler(std::vector< Instruction > &list, Base &parser)
AST compiler requires a vector of instructions.
Definition: AST.h:117
@ Literal
This is a literal value.
@ Empty
This node is empty, possibly a placeholder for an identifier.
Definition: AST.h:63
@ List
List of expressions to be compiled.
Definition: AST.h:66
This class allows embedded types to become scripting types that are passed around as references.
Definition: Embedding.h:1406
@ Identifier
Marks this value as an identifier, either a constant or a variable.
@ Unknown
This value is not valid.
Value compilevalue(ASTNode &tree, std::vector< Instruction > *list, Byte &tempind, bool generateoutput=true)
Definition: AST.cpp:157
@ Variable
This is a variable.
Byte Store
Whether to store the result of the function.
Definition: Instruction.h:174
ValueType Type
Type of this value.
Definition: Instruction.h:90
@ Construct
This node is a constructor node.
Definition: AST.h:54
@ Jump
Unconditionally jumps by the given offset. Offset should be in JumpOffset field.
std::vector< Value > Parameters
Parameters of the function.
Definition: Instruction.h:168
MappedReferenceType< std::vector< Instruction >, &ToEmptyString > instructionlisttype("#instructionlist", "")
A single instruction.
Definition: Instruction.h:150
NodeType
Node type.
Definition: AST.h:23
std::string ToEmptyString(const T_ &)
Definition: Embedding.h:30
std::string GetName() const
Returns the name of this member.
Definition: Reflection.h:325