Ejemplo n.º 1
0
		public override ExecuteResult Execute(Space space) {
			if (!IsSuccess(_expression.Execute(space))) {
				ErrorLogger.LogRuntimeError(ErrorRuntimeCode.Foreach, "The expression execute failed!");
				return ExecuteResult.Failed;
			}
			if (!ValueTool.IsArray(_expression.value)) {
				ErrorLogger.LogRuntimeError(ErrorRuntimeCode.Foreach, "The expression isn't a array!");
				return ExecuteResult.Failed;
			}
			var arr = (_expression.value as ValueArray).value;
			if (arr.Count == 0) {
				return ExecuteResult.Successed;
			}

			var tempSpace = new Space(SpaceType.Loop, space);
			var itemVariable = new Variable(_name, VariableAttribute.None);
			if (!tempSpace.AddVariable(itemVariable)) {
				ErrorLogger.LogRuntimeError(_name);
				ErrorLogger.LogRuntimeError(ErrorRuntimeCode.Foreach, "The variable \"" + _name + "\" execute failed!");
				return ExecuteResult.Failed;
			}
			var contentSpace = new Space(SpaceType.Loop, tempSpace);
			foreach (var item in arr) {
				itemVariable.SetValue(item.value);
				contentSpace.Clear();
				var ret = _sentence.Execute(contentSpace);
				if (!IsSuccess(ret)) {
					ErrorLogger.LogRuntimeError(ErrorRuntimeCode.Foreach, "The sentence execute failed!");
					return ExecuteResult.Failed;
				}
				if (ret == ExecuteResult.Break) {
					break;
				}
				if (ret == ExecuteResult.Return) {
					SetReturnValue((_sentence as SentenceReturn).returnValue);
					tempSpace.Clear();
					return ExecuteResult.Return;
				}
			}

			tempSpace.Clear();
			return ExecuteResult.Successed;
		}
Ejemplo n.º 2
0
		public override ExecuteResult Execute(Space space) {
			var valueObject = new ValueObject();
			var variable = new Variable(_name, VariableAttribute.Const, valueObject);
			if (!space.AddVariable(variable)) {
				ErrorLogger.LogRuntimeError(_name);
				ErrorLogger.LogRuntimeError(ErrorRuntimeCode.EnumDefine, "The enum name \"" + _name + "\" is exist!");
				return ExecuteResult.Failed;
			}
			var valueSpace = valueObject.space;
			foreach (var pair in _valueList) {
				var valueVariable = new Variable(pair.Key, VariableAttribute.Const, pair.Value);
				if (!valueSpace.AddVariable(valueVariable)) {
					ErrorLogger.LogRuntimeError(pair.Key);
					ErrorLogger.LogRuntimeError(_name);
					ErrorLogger.LogRuntimeError(ErrorRuntimeCode.EnumDefine, "The item name \"" + _name + "\" is exist!");
					return ExecuteResult.Failed;
				}
			}
			return ExecuteResult.Successed;
		}