Example #1
0
 public ScriptSceneObject(ScriptSceneObject SSO, Scene ParentScene) : base(SSO, ParentScene)
 {
     this._Enabled    = true;
     this._Script     = SSO._Script;
     this._ScriptType = SSO.ScriptType;
     this.Type        = SceneObjectType.ScriptSceneObject;
 }
Example #2
0
            public static bool Prefix(
                ScriptCompiler __instance,
                ITokenStream akTokenStream, out ScriptObjectType akParsedObj)
            {
                var apTokenStream = akTokenStream;
#endif
                __instance._logger.LogTrace("Parsing {0}...", __instance._targetScript.Id);

                var parser = new PapyrusParser(apTokenStream);

                // TODO: Currently suppressing parser errors so that the compiler will continue with type resolution and disambiguation.
                // AttachParserInternalErrorEventHandler(parser, __instance);

                var parserDynamic = parser.AsDynamic();
                parserDynamic.KnownUserFlags = __instance.GetFlagsDictionary();

                parser.script();

#if FALLOUT4
                apParsedObj = parser.ParsedObject;

                arpParentName = parser.ParentObjName;
                apImports     = parser.pImportedItems;
#elif SKYRIM
                akParsedObj = parser.ParsedObject;
#endif

                return(false);
            }
        public static CommonTree GetAst(this ScriptObjectType objectType)
        {
#if FALLOUT4
            return(objectType.pObjAST);
#elif SKYRIM
            return(objectType.kAST);
#endif
        }
        public static ITokenStream GetTokenStream(this ScriptObjectType objectType)
        {
#if FALLOUT4
            return(objectType.pObjTokenStream);
#elif SKYRIM
            return(objectType.kTokenStream);
#endif
        }
Example #5
0
        public TypeWalker(ScriptFile targetScript, ScriptObjectType type, ILogger logger) : base(new Stream(type))
        {
            _targetScript = targetScript;
            _input        = (Stream)input;
            _logger       = logger;

            TreeAdaptor = new Adaptor();
        }
Example #6
0
 public DiagnosticResult Bind(ScriptObjectType type, ScriptNode node)
 {
     return(DiagnosticResult.TryWithDiagnostics((diagnostics) =>
     {
         var visitor = new ScopeBindingVisitor(diagnostics, type);
         visitor.Visit(node);
     }));
 }
Example #7
0
        public ScriptObjectType Load(Dictionary <string, ScriptComplexType> knownTypes)
        {
#if SKYRIM
            lock (_targetScript.Program.ScriptFiles)
            {
                _thisDynamic.kObjectToPath = _targetScript.Program.ScriptFiles.Select(kv => new KeyValuePair <string, string>(kv.Key.ToString().ToLower(), kv.Value.FilePath)).ToDictionary();
            }
#endif

            lock (knownTypes)
            {
                if (knownTypes.ContainsKey(_targetScript.Id))
                {
                    knownTypes.Remove(_targetScript.Id);
                }
            }

            ScriptObjectType result = null;

            try
            {
                result = (ScriptObjectType)_thisDynamic.LoadObject(_targetScript.Id.ToString(), knownTypes);
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, $"Error in LoadObject for {_targetScript.Id}");
            }

            if (result == null)
            {
                return(null);
            }

#if FALLOUT4
            if (result.pImportedTypes == null)
            {
                result.pImportedTypes = new Dictionary <string, ScriptObjectType>();
            }

            if (result.pImportedNamespaces == null)
            {
                result.pImportedNamespaces = new HashSet <string>();
            }
#endif

            return(result);
        }
Example #8
0
        public static int SizeOf(ScriptObjectType type)
        {
            switch (type)
            {
            case ScriptObjectType.Void:
                return(0);

            case ScriptObjectType.Bool:
                return(1);

            case ScriptObjectType.Int:
                return(4);

            case ScriptObjectType.LongInt:
                return(4);

            case ScriptObjectType.Float:
                return(4);

            case ScriptObjectType.Color:
                return(4);

            case ScriptObjectType.Int2:
                return(8);

            case ScriptObjectType.Int3:
                return(12);

            case ScriptObjectType.Int4:
                return(16);

            case ScriptObjectType.Float2:
                return(8);

            case ScriptObjectType.Float3:
                return(12);

            case ScriptObjectType.Float4:
                return(16);

            case ScriptObjectType.String:
            default:
                throw new NotSupportedException();
            }
        }
Example #9
0
            public static bool Prefix(
                ScriptCompiler __instance, ref ScriptObjectType __result,
                string asObjectName, Dictionary <string, ScriptComplexType> akKnownTypes, Stack <string> akChildren, bool abErrorOnNoObject, ScriptObjectType akImmediateChild)
            {
                var apKnownTypes = akKnownTypes;
#endif
                lock (apKnownTypes)
                {
                    if (apKnownTypes.ContainsKey(asObjectName))
                    {
                        __result = apKnownTypes[asObjectName] as ScriptObjectType;
                        return(false);
                    }
                }

                var objectIdentifier = ObjectIdentifier.Parse(asObjectName);

                if (objectIdentifier == __instance._targetScript.Id || apKnownTypes.ContainsKey(asObjectName))
                {
                    return(true);
                }

                if (__instance._targetScript.Program.ScriptFiles.ContainsKey(objectIdentifier))
                {
                    var externalType = __instance._targetScript.Program.ScriptFiles[objectIdentifier].CompilerType;
                    if (externalType != null)
                    {
                        lock (apKnownTypes)
                        {
                            if (!apKnownTypes.ContainsKey(asObjectName))
                            {
                                apKnownTypes.Add(asObjectName, externalType);
                            }
                        }

                        __result = externalType;
                        return(false);
                    }
                }

                return(true);
            }
Example #10
0
            private void BuildBriefFunctionTable()
            {
                briefFunctionTable.Clear();
                foreach (Function item in functionTable)
                {
                    ScriptObjectType[] rt = new ScriptObjectType[item.ReturnTypes.Count];
                    ScriptObjectType[] pt = new ScriptObjectType[item.Parameters.Count];

                    for (int i = 0; i < rt.Length; i++)
                    {
                        rt[i] = item.ReturnTypes[i];
                    }
                    for (int i = 0; i < pt.Length; i++)
                    {
                        pt[i] = item.Parameters[i].Type;
                    }

                    briefFunctionTable.Add(new Script.Function(item.Name, labelAddresses[item.BeginLabel], 0, rt, pt));
                }
                briefFunctionTable.Sort((a, b) => { return(string.Compare(a.Name, b.Name)); });
            }
Example #11
0
 public static bool Prefix(
     ScriptCompiler __instance, ref ScriptObjectType __result,
     string asObjectName, Dictionary <string, ScriptComplexType> apKnownTypes, Stack <string> apChildren, bool abErrorOnNoObject, ScriptObjectType apImmediateChild)
 {
Example #12
0
 // Skyrim's LoadObject method calls TypeCheck internally, which mutates the AST and prevents a subsequent type check from succeeding.
 // So, this patch is just to replace it with a no-op.
 public static bool Prefix(ScriptCompiler __instance, ScriptObjectType akObj, Dictionary <string, ScriptObjectType> akKnownTypes, Stack <string> akChildren)
 {
     return(false);
 }
Example #13
0
 public CompilerObjectLoadResults(ScriptObjectType type, IReadOnlyDictionary <IToken, ScriptComplexType> tokenTypes, IReadOnlyDictionary <IToken, HashSet <ScriptScope> > tokenScopes)
 {
     Type        = type;
     TokenTypes  = tokenTypes;
     TokenScopes = tokenScopes;
 }
Example #14
0
 public string DisambiguateType(string asRawType, IToken apErrorToken, ScriptObjectType apContainingType, Dictionary <string, ScriptComplexType> apKnownTypes)
 {
     return((string)_disambiguateTypeMethod.Invoke(this, new object[] { asRawType, apErrorToken, apContainingType, apKnownTypes }));
 }
Example #15
0
 public ScriptSceneObject(string Name) : base(Name)
 {
     this._Enabled   = true;
     this.ScriptType = ScriptObjectType.CSScript;
     this.Type       = SceneObjectType.ScriptSceneObject;
 }
Example #16
0
        /// <summary>
        /// Adds the type of the object.
        /// </summary>
        /// <param name="name">Name of the object.</param>
        /// <param name="type">Type of the object.</param>
        /// <param name="parseMethod">Parse method for string to object conversion.</param>
        /// <param name="defaultValue">Default value for this object.</param>
        public static void AddObjectType(string name, Type type, TryParseTo parseMethod, object defaultValue = null)
        {
            var objType = new ScriptObjectType(name, type, parseMethod, defaultValue);

            CODE_INFO.AddPossible(objType);
        }
Example #17
0
 public Stream(ScriptObjectType type) : base(type.GetAst())
 {
     TokenStream = type.GetTokenStream();
 }
Example #18
0
 public DeclareVariable(string name, ScriptObjectType type)
 {
     Name = name;
     Type = type;
 }
Example #19
0
 public ScopeBindingVisitor(List <Diagnostic> diagnostics, ScriptObjectType scriptType)
 {
     _diagnostics = diagnostics;
     _scriptType  = scriptType;
 }
Example #20
0
 public ScriptNativeFunctionParameterAttribute(ScriptObjectType type, string name)
 {
     Type = type;
     Name = name ?? string.Empty;
 }
        /// <summary>
        /// This routine loads a script (if it has not already been loaded),
        /// and sets up globals for the script.  The script needs to be safe to
        /// have its entrypoint called from OBJECT_INVALID for this function to
        /// work properly.
        /// </summary>
        /// <param name="ScriptName">Supplies the name of the script to load.</param>
        /// <param name="ForceLoadScript">If true, forcibly attempt to load
        /// the script.</param>
        /// <param name="CallerScript">Supplies the script object owned by the
        /// caller.</param>
        /// <returns>The script object for the newly loaded script.  On failure
        /// an exception is raised.</returns>
        public static IGeneratedScriptProgram LoadScript(string ScriptName, bool ForceLoadScript, CLRScriptBase CallerScript)
        {
            string   AssemblyName = String.Format("NWScriptAsm_{0}, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ScriptName);
            string   TypeName     = String.Format("NWScript.JITCode.{0}.ScriptProgram", ScriptName);
            Assembly ScriptAssembly;
            IGeneratedScriptProgram ScriptObject;
            Type       ScriptObjectType;
            MethodInfo NWScriptInitGlobals;

            //
            // Check if the script is already loaded.  If so, use the existing
            // script assembly.
            //

            ScriptAssembly = (from LoadedAsm in AppDomain.CurrentDomain.GetAssemblies()
                              where LoadedAsm.FullName == AssemblyName
                              select LoadedAsm).FirstOrDefault();

            if (ScriptAssembly == null && ForceLoadScript)
            {
                //
                // The assembly is not yet loaded.  Force it to be loaded via
                // a dummy ExecuteScript call.
                //

                CallerScript.ExecuteScript(ScriptName, CLRScriptBase.OBJECT_INVALID);

                ScriptAssembly = (from LoadedAsm in AppDomain.CurrentDomain.GetAssemblies()
                                  where LoadedAsm.FullName == AssemblyName
                                  select LoadedAsm).FirstOrDefault();
            }

            if (ScriptAssembly == null)
            {
                throw new ApplicationException("Could not load script " + ScriptName);
            }

            //
            // Now that the script assembly is loaded, we can create a script
            // object out of the script for our own use.  The script object
            // encapsulates a private set of global variables for the target
            // script.
            //

            ScriptObject = (IGeneratedScriptProgram)ScriptAssembly.CreateInstance(
                TypeName,
                false,
                BindingFlags.CreateInstance,
                null,
                new object[] { CallerScript.ScriptHost.Intrinsics, CallerScript.ScriptHost.Host },
                null,
                null);

            ScriptObjectType = ScriptObject.GetType();

            //
            // If the script had global variables, call the global variable
            // initializer on the script now.  This will set the script object
            // up into a state as though we created all the global variables,
            // but stopped just before main() or StartingConditional().
            //

            NWScriptInitGlobals = ScriptObjectType.GetMethod("NWScriptInitGlobals");

            if (NWScriptInitGlobals != null)
            {
                NWScriptInitGlobals.Invoke(ScriptObject, null);
            }

            //
            // The private script object is ready to use.  Return the instance
            // of the script that we had created.
            //

            return(ScriptObject);
        }
Example #22
0
 public ScriptSceneObject() : base()
 {
     this._Enabled   = true;
     this.ScriptType = ScriptObjectType.CSScript;
     this.Type       = SceneObjectType.ScriptSceneObject;
 }
Example #23
0
 public void AddObjectType(ScriptObjectType objectType)
 {
     ObjectTypes.Add(objectType);
 }
Example #24
0
 public static bool Prefix(
     ScriptCompiler __instance,
     ITokenStream apTokenStream, out ScriptObjectType apParsedObj, out IToken arpParentName, out Dictionary <string, IToken> apImports)
 {
Example #25
0
        /// <summary>
        /// Initialize this instance and make then to add the first Object reference to the code,the null type.
        /// </summary>
        public static void Initialize()
        {
            ScriptObjectType nullV = new ScriptObjectType("null", typeof(object), TryParseNull);

            CODE_INFO.AddPossible(nullV);
        }
Example #26
0
 public ScriptNativeFunctionReturnAttribute(ScriptObjectType type)
 {
     Type = type;
 }