#include "ast.h"
// === PROTOTYPES ===
-void Object_Dereference(tSpiderObject *Object);
-void Object_Reference(tSpiderObject *Object);
-tSpiderObject *Object_CreateInteger(uint64_t Value);
-tSpiderObject *Object_CreateReal(double Value);
-tSpiderObject *Object_CreateString(int Length, const char *Data);
-tSpiderObject *Object_CastTo(int Type, tSpiderObject *Source);
- int Object_IsTrue(tSpiderObject *Value);
+void Object_Dereference(tSpiderValue *Object);
+void Object_Reference(tSpiderValue *Object);
+tSpiderValue *Object_CreateInteger(uint64_t Value);
+tSpiderValue *Object_CreateReal(double Value);
+tSpiderValue *Object_CreateString(int Length, const char *Data);
+tSpiderValue *Object_CastTo(int Type, tSpiderValue *Source);
+ int Object_IsTrue(tSpiderValue *Value);
-tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node);
+tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node);
tAST_Variable *Variable_Define(tAST_BlockState *Block, int Type, const char *Name);
-void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderObject *Value);
-tSpiderObject *Variable_GetValue(tAST_BlockState *Block, const char *Name);
+void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value);
+tSpiderValue *Variable_GetValue(tAST_BlockState *Block, const char *Name);
void Variable_Destroy(tAST_Variable *Variable);
// === CODE ===
/**
* \brief Dereference a created object
*/
-void Object_Dereference(tSpiderObject *Object)
+void Object_Dereference(tSpiderValue *Object)
{
if(!Object) return ;
Object->ReferenceCount --;
if( Object->ReferenceCount == 0 ) free(Object);
}
-void Object_Reference(tSpiderObject *Object)
+void Object_Reference(tSpiderValue *Object)
{
if(!Object) return ;
Object->ReferenceCount ++;
/**
* \brief Create an integer object
*/
-tSpiderObject *Object_CreateInteger(uint64_t Value)
+tSpiderValue *Object_CreateInteger(uint64_t Value)
{
- tSpiderObject *ret = malloc( sizeof(tSpiderObject) );
+ tSpiderValue *ret = malloc( sizeof(tSpiderValue) );
ret->Type = SS_DATATYPE_INTEGER;
ret->ReferenceCount = 1;
ret->Integer = Value;
/**
* \brief Create an real number object
*/
-tSpiderObject *Object_CreateReal(double Value)
+tSpiderValue *Object_CreateReal(double Value)
{
- tSpiderObject *ret = malloc( sizeof(tSpiderObject) );
+ tSpiderValue *ret = malloc( sizeof(tSpiderValue) );
ret->Type = SS_DATATYPE_REAL;
ret->ReferenceCount = 1;
ret->Real = Value;
/**
* \brief Create an string object
*/
-tSpiderObject *Object_CreateString(int Length, const char *Data)
+tSpiderValue *Object_CreateString(int Length, const char *Data)
{
- tSpiderObject *ret = malloc( sizeof(tSpiderObject) + Length + 1 );
+ tSpiderValue *ret = malloc( sizeof(tSpiderValue) + Length + 1 );
ret->Type = SS_DATATYPE_STRING;
ret->ReferenceCount = 1;
ret->String.Length = Length;
/**
* \brief Concatenate two strings
*/
-tSpiderObject *Object_StringConcat(tSpiderObject *Str1, tSpiderObject *Str2)
+tSpiderValue *Object_StringConcat(tSpiderValue *Str1, tSpiderValue *Str2)
{
int newLen = 0;
- tSpiderObject *ret;
+ tSpiderValue *ret;
if(Str1) newLen += Str1->String.Length;
if(Str2) newLen += Str2->String.Length;
- ret = malloc( sizeof(tSpiderObject) + newLen + 1 );
+ ret = malloc( sizeof(tSpiderValue) + newLen + 1 );
ret->Type = SS_DATATYPE_STRING;
ret->ReferenceCount = 1;
ret->String.Length = newLen;
/**
* \brief Cast one object to another
*/
-tSpiderObject *Object_CastTo(int Type, tSpiderObject *Source)
+tSpiderValue *Object_CastTo(int Type, tSpiderValue *Source)
{
- tSpiderObject *ret = ERRPTR;
+ tSpiderValue *ret = ERRPTR;
// Check if anything needs to be done
if( Source->Type == Type ) {
Object_Reference(Source);
return ERRPTR;
case SS_DATATYPE_INTEGER:
- ret = malloc(sizeof(tSpiderObject));
+ ret = malloc(sizeof(tSpiderValue));
ret->Type = SS_DATATYPE_INTEGER;
ret->ReferenceCount = 1;
switch(Source->Type)
/**
* \brief Condenses a value down to a boolean
*/
-int Object_IsTrue(tSpiderObject *Value)
+int Object_IsTrue(tSpiderValue *Value)
{
switch(Value->Type)
{
/**
* \brief Execute an AST node and return its value
*/
-tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node)
+tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node)
{
tAST_Node *node;
- tSpiderObject *ret, *tmpobj;
- tSpiderObject *op1, *op2; // Binary operations
+ tSpiderValue *ret, *tmpobj;
+ tSpiderValue *op1, *op2; // Binary operations
int cmp; // Used in comparisons
switch(Node->Type)
}
// Logical block (used to allocate `params`)
{
- tSpiderObject *params[nParams];
+ tSpiderValue *params[nParams];
int i=0;
for(node = Node->FunctionCall.FirstArg; node; node = node->NextSibling) {
params[i] = AST_ExecuteNode(Block, node);
/**
* \brief Set the value of a variable
*/
-void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderObject *Value)
+void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value)
{
tAST_Variable *var;
tAST_BlockState *bs;
/**
* \brief Get the value of a variable
*/
-tSpiderObject *Variable_GetValue(tAST_BlockState *Block, const char *Name)
+tSpiderValue *Variable_GetValue(tAST_BlockState *Block, const char *Name)
{
tAST_Variable *var;
tAST_BlockState *bs;