コード例 #1
0
ファイル: OpCodes.cs プロジェクト: CMertens/StrikeVM
        internal static void SetNear(VirtualMachine vm, Instruction i)
        {
            Value vName = vm.Stack.Shift();
            Value vValue = vm.Stack.Shift();
            if (vName.Type != ValueTypes.STRING || vName.String_Value == null || vName.String_Value == "") {
                vm.RaiseError("Tried to use a non-string value for a variable name");
                return;
            }

            if (vm.Exists(vName.String_Value) == false) {
                if (vm.CurrentEnvironment.Parent == null || vm.CurrentEnvironment.Parent.Exists(vName.String_Value) == false) {
                    vm.RaiseError("Tried to access non-existent value name " + vName.String_Value);
                    return;
                }
                if (i.Type == OpCodeTypes.TYPESET) {
                    if (vm.CurrentEnvironment.Parent.Get(vName.String_Value).Type != vValue.Type) {
                        vm.RaiseError("Tried to redefine type for variable " + vName.String_Value + ": value is " + vm.Get(vName.String_Value).Type + ", new value is " + vValue.Type);
                        return;
                    }
                }
                vm.CurrentEnvironment.Parent.Set(vName.String_Value, vValue);
                vm.Stack.Push(vName);
                return;
            } else {
                if (i.Type == OpCodeTypes.TYPESET) {
                    if (vm.Get(vName.String_Value).Type != vValue.Type) {
                        vm.RaiseError("Tried to redefine type for variable " + vName.String_Value + ": value is " + vm.Get(vName.String_Value).Type + ", new value is " + vValue.Type);
                        return;
                    }
                }
                vm.Set(vName.String_Value, vValue);
                vm.Stack.Push(vName);
            }
        }