示例#1
0
/**
 * CTRWalkerAssignment
 *
 * Processes an assignment operation.
 */
ctr_object* ctr_cwlk_assignment(ctr_tnode* node) {
	char wasReturn = 0;
	ctr_tlistitem* assignmentItems = node->nodes;
	ctr_tnode* assignee = assignmentItems->node;
	ctr_tlistitem* valueListItem = assignmentItems->next;
	ctr_tnode* value = valueListItem->node;
	ctr_object* x;
	ctr_object* result;
	if (ctr_flag_sandbox && ++ctr_sandbox_steps>CTR_MAX_STEPS_LIMIT) exit(1);
	if (CtrStdFlow == NULL) {
		ctr_callstack[ctr_callstack_index++] = assignee;
	}
	x = ctr_cwlk_expr(value, &wasReturn);
	if (assignee->modifier == 1) {
		result = ctr_assign_value_to_my(ctr_build_string(assignee->value, assignee->vlen), x);
	} else if (assignee->modifier == 2) {
		result = ctr_assign_value_to_local(ctr_build_string(assignee->value, assignee->vlen), x);
	} else {
		result = ctr_assign_value(ctr_build_string(assignee->value, assignee->vlen), x);
	}
	if (CtrStdFlow == NULL) {
		ctr_callstack_index--;
	}
	return result;
}	
示例#2
0
文件: walker.c 项目: probonopd/citron
/**
 * CTRWalkerAssignment
 *
 * Processes an assignment operation.
 */
ctr_object *
ctr_cwlk_assignment (ctr_tnode * node)
{
  char wasReturn = 0;
  ctr_tlistitem *assignmentItems = node->nodes;
  ctr_tnode *assignee = assignmentItems->node;
  ctr_tlistitem *valueListItem = assignmentItems->next;
  ctr_tnode *value = valueListItem->node;
  ctr_object *x;
  ctr_object *result;
  char ret;
  if (CtrStdFlow == NULL)
    {
      ctr_callstack[ctr_callstack_index++] = assignee;
    }
  x = ctr_cwlk_expr (value, &wasReturn);
  if (!x)
    {
      CtrStdFlow = ctr_build_string_from_cstring ("NULL expression");
      return NULL;
    }
  if (assignee->type == CTR_AST_NODE_REFERENCE)
    {
      if (assignee->modifier == 1)
	{
	  result = ctr_assign_value_to_my (ctr_build_string (assignee->value, assignee->vlen), x);
	}
      else if (assignee->modifier == 2)
	{
	  result = ctr_assign_value_to_local (ctr_build_string (assignee->value, assignee->vlen), x);
	}
      else if (assignee->modifier == 3)
	{
	  result = ctr_assign_value (ctr_build_string (assignee->value, assignee->vlen), x);	//Handle lexical scoping
	}
      else
	{
	  result = ctr_assign_value (ctr_build_string (assignee->value, assignee->vlen), x);
	}
    }
  else
    {
      int old_replace = ctr_cwlk_replace_refs;
      ctr_cwlk_replace_refs = 1;
      ctr_cwlk_last_msg_level = ctr_cwlk_msg_level;
      ctr_object *y = ctr_cwlk_expr (assignee, &ret);
      ctr_cwlk_replace_refs = old_replace;	//set back in case we didn't reset
      result = ctr_send_message_variadic (x, "unpack:", 7, 1, y);
      ctr_object *old_result = NULL;
      while (old_result != result && result->info.type == CTR_OBJECT_TYPE_OTBLOCK)
	result = ctr_block_run_here (result, NULL, (old_result = result));
    }
  if (CtrStdFlow == NULL)
    {
      ctr_callstack_index--;
    }
  return result;
}
示例#3
0
文件: base.c 项目: Drooids/citrine
/**
 * 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;
}