if(!Node) return ;
+ // Referenced counted file name
+ (*(int*)(Node->File - sizeof(int))) -= 1;
+ if( *(int*)(Node->File - sizeof(int)) == 0 )
+ free( (void*)(Node->File - sizeof(int)) );
+
switch(Node->Type)
{
// Block of code
{
tAST_Node *ret = malloc( sizeof(tAST_Node) + ExtraSize );
ret->NextSibling = NULL;
- ret->File = "<unk>";
+ ret->File = Parser->Filename; *(int*)(Parser->Filename - sizeof(int)) += 1;
ret->Line = Parser->CurLine;
ret->Type = Type;
// Not found?
if(!bFound)
{
- fprintf(stderr, "Undefined reference to function '%s'\n", Function);
+ fprintf(stderr, "Undefined reference to function '%s' (ns='%s')\n",
+ Function, Namespace->Name);
return ERRPTR;
}
{
class = NULL; // Just to allow the below code to be neat
+ //if( !Namespace )
+ // Namespace = &Script->Variant->RootNamespace;
+
// Second: Scan current namespace
if( !class && Namespace )
{
case NODETYPE_CREATEOBJECT:
// Logical block (used to allocate `params`)
{
+ tSpiderNamespace *ns = Block->CurNamespace;
tSpiderValue *params[Node->FunctionCall.NumArgs];
i = 0;
for(node = Node->FunctionCall.FirstArg; node; node = node->NextSibling)
i ++;
}
- if( !Block->CurNamespace )
- Block->CurNamespace = Block->BaseNamespace;
+ if( !ns ) ns = Block->BaseNamespace;
// Call the function
if( Node->Type == NODETYPE_CREATEOBJECT )
{
ret = SpiderScript_CreateObject(Block->Script,
- Block->CurNamespace,
+ ns,
Node->FunctionCall.Name,
Node->FunctionCall.NumArgs, params
);
else
{
ret = SpiderScript_ExecuteFunction(Block->Script,
- Block->CurNamespace, Node->FunctionCall.Name,
+ ns, Node->FunctionCall.Name,
Node->FunctionCall.NumArgs, params
);
}
// break;
}
_return:
+ // Reset namespace when no longer needed
+ if( Node->Type != NODETYPE_SCOPE )
+ Block->CurNamespace = NULL;
+
#if TRACE_NODE_RETURNS
if(ret && ret != ERRPTR) {
AST_RuntimeError(Node, "Ret type of %p %i is %i", Node, Node->Type, ret->Type);
parser.CurLine = 1;
parser.BufStart = Buffer;
parser.CurPos = Buffer;
- parser.Filename = Filename;
+ // hackery to do reference counting
+ parser.Filename = malloc(sizeof(int)+strlen(Filename)+1);
+ strcpy(parser.Filename + sizeof(int), Filename);
+ *(int*)(parser.Filename) = 0; // Set reference count
+ parser.Filename += sizeof(int); // Move filename
parser.ErrorHit = 0;
ret = AST_NewScript();
#if USE_SCOPE_CHAR
if( GetToken(Parser) == TOK_SCOPE )
{
- ret = AST_NewScopeDereference( Parser, Parse_GetIdent(Parser, bObjectCreate), name );
+ ret = AST_NewScopeDereference( Parser, name, Parse_GetIdent(Parser, bObjectCreate) );
free(name);
return ret;
}