/** * [File] run * * Includes the file as a piece of executable code. */ ctr_object* ctr_file_include_ast(ctr_object* myself, ctr_argument* argumentList) { ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string("path",4), 0); ctr_tnode* parsedCode; ctr_size vlen; char* pathString; if (path == NULL) return myself; vlen = path->value.svalue->vlen; pathString = malloc(vlen + 1); memcpy(pathString, path->value.svalue->value, vlen); memcpy(pathString+vlen,"\0",1); parsedCode = ctr_serializer_unserialize(pathString); ctr_cwlk_run(parsedCode); return myself; }
/** * BlockRun * * Runs a block of code. */ ctr_object* ctr_block_run(ctr_object* myself, ctr_argument* argList, ctr_object* my) { ctr_object* result; ctr_tnode* node = myself->value.block; ctr_tlistitem* codeBlockParts = node->nodes; ctr_tnode* codeBlockPart1 = codeBlockParts->node; ctr_tnode* codeBlockPart2 = codeBlockParts->next->node; ctr_tlistitem* parameterList = codeBlockPart1->nodes; ctr_tnode* parameter; ctr_object* a; ctr_open_context(); if (parameterList && parameterList->node) { parameter = parameterList->node; while(1) { if (parameter && argList->object) { a = argList->object; ctr_assign_value_to_local(ctr_build_string(parameter->value, parameter->vlen), a); } if (!argList->next) break; argList = argList->next; if (!parameterList->next) break; parameterList = parameterList->next; parameter = parameterList->node; } } ctr_assign_value_to_local(ctr_build_string("me",2), my); ctr_assign_value_to_local(ctr_build_string("thisBlock",9), myself); /* otherwise running block may get gc'ed. */ result = ctr_cwlk_run(codeBlockPart2); if (result == NULL) result = my; ctr_close_context(); if (CtrStdError != NULL && CtrStdError != CtrStdNil) { ctr_object* catchBlock = malloc(sizeof(ctr_object)); catchBlock = ctr_internal_object_find_property(myself, ctr_build_string("catch",5), 0); if (catchBlock != NULL) { ctr_argument* a = CTR_CREATE_ARGUMENT(); a->object = CtrStdError; CtrStdError = NULL; ctr_block_run(catchBlock, a, my); result = myself; } } return result; }
/** * [File] include * * Includes the file as a piece of executable code. */ ctr_object* ctr_file_include(ctr_object* myself, ctr_argument* argumentList) { ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0); ctr_tnode* parsedCode; ctr_size vlen; char* pathString; char* prg; uint64_t program_size = 0; if (path == NULL) return myself; vlen = path->value.svalue->vlen; pathString = ctr_heap_allocate_tracked(sizeof(char)*(vlen+1)); //needed until end, pathString appears in stracktrace memcpy(pathString, path->value.svalue->value, vlen); memcpy(pathString+vlen,"\0",1); prg = ctr_internal_readf(pathString, &program_size); parsedCode = ctr_cparse_parse(prg, pathString); ctr_heap_free( prg ); ctr_cwlk_subprogram++; ctr_cwlk_run(parsedCode); ctr_cwlk_subprogram--; return myself; }