public MessageHolder(string name, string defmsg)
 {
     //mAssignedMessage = null;
     mDefaultMessage = defmsg;
     mName           = name;
     Tjs.RegisterMessageMap(mName, this);
 }
Exemple #2
0
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public RandomGeneratorClass() : base(CLASS_NAME)
 {
     ClassID = Tjs.FindNativeClassId(CLASS_NAME);
     // constructor
     RegisterNCM(CLASS_NAME, new _NativeClassConstructor_24(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("finalize", new _NativeClassMethod_37(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("randomize", new _NativeClassMethod_44(), CLASS_NAME, Interface.nitMethod
                 , 0);
     // インスタンス所得
     RegisterNCM("random", new _NativeClassMethod_54(), CLASS_NAME, Interface.nitMethod
                 , 0);
     // インスタンス所得
     // returns 53-bit precision random value x, x is in 0 <= x < 1
     RegisterNCM("random32", new _NativeClassMethod_69(), CLASS_NAME, Interface.nitMethod
                 , 0);
     // インスタンス所得
     // returns 32-bit precision integer value x, x is in 0 <= x <= 4294967295
     RegisterNCM("random63", new _NativeClassMethod_84(), CLASS_NAME, Interface.nitMethod
                 , 0);
     // インスタンス所得
     // returns 63-bit precision integer value x, x is in 0 <= x <= 9223372036854775807
     RegisterNCM("random64", new _NativeClassMethod_99(), CLASS_NAME, Interface.nitMethod
                 , 0);
     // インスタンス所得
     // returns 64-bit precision integer value x, x is in
     // -9223372036854775808 <= x <= 9223372036854775807
     // Java 实装では、int は32 bitまで
     RegisterNCM("serialize", new _NativeClassMethod_116(), CLASS_NAME, Interface.nitMethod
                 , 0);
 }
Exemple #3
0
 static Variant Execute(TjsByteCodeLoader loader, Tjs engine, string path)
 {
     using (var fs = new FileStream(path, FileMode.Open))
     {
         TjsBinaryStream stream = new TjsBinaryStream(fs);
         try
         {
             var       ret = new Variant();
             Dispatch2 dsp = engine.GetGlobal();
             engine.LoadByteCode(ret, dsp, Path.GetFileNameWithoutExtension(path), stream);
             //dsp.PropGet(0, "FrameView", ret, dsp);
             //var obj = ret.AsObject();
             //var r = obj.FuncCall(0, null, ret, null, obj);
             //r = obj.FuncCall(0, "FrameView", ret, null, obj);
             return(ret);
         }
         catch (TjsScriptError ex)
         {
             Console.WriteLine(ex);
         }
         catch (Exception e)
         {
             Console.WriteLine($"Execute {path} failed.");
             _count--;
         }
     }
     return(null);
 }
Exemple #4
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        private static Dispatch2 GetResultArray(bool matched, RegExpNI _this, Matcher m)
        {
            Dispatch2 array = Tjs.CreateArrayObject();

            if (matched)
            {
                if (_this.RegEx == null)
                {
                    Variant val = new Variant(string.Empty);
                    array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, 0, val, array);
                }
                else
                {
                    if (m != null)
                    {
                        bool    isMatch = m.Matches();
                        Variant val;
                        if (isMatch)
                        {
                            val = new Variant(m.Group(0));
                            array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, 0, val, array);
                        }
                        int size = m.GroupCount();
                        for (int i = 0; i < size; i++)
                        {
                            val = new Variant(m.Group(i + 1));
                            array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, i + 1, val, array
                                               );
                        }
                    }
                }
            }
            return(array);
        }
Exemple #5
0
 /// <exception cref="TjsException"></exception>
 protected internal override int Process(Variant result, Variant[] param, Dispatch2
                                         objthis)
 {
     if (param.Length < 1)
     {
         return(Error.E_BADPARAMCOUNT);
     }
     if (param.Length == 1)
     {
         Tjs.OutputToConsole(param[0].AsString());
         //Console.WriteLine( param[0].AsString() );
     }
     else
     {
         // display the arguments separated with ", "
         StringBuilder builder = new StringBuilder(512);
         for (int i = 0; i < param.Length; i++)
         {
             if (i != 0)
             {
                 builder.Append(", ");
             }
             builder.Append(param[i].AsString());
         }
         //Console.WriteLine(builder.ToString());
         Tjs.OutputToConsole(builder.ToString());
     }
     return(Error.S_OK);
 }
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public ExceptionClass() : base(CLASS_NAME)
 {
     ClassID = Tjs.FindNativeClassId(CLASS_NAME);
     // constructor
     RegisterNCM(CLASS_NAME, new _NativeClassConstructor_15(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("finalize", new _NativeClassMethod_38(), CLASS_NAME, Interface.nitMethod
                 , 0);
 }
Exemple #7
0
 public static void ReportExceptionSource(string msg, InterCodeObject context, int
                                          codepos)
 {
     if (Tjs.EnableDebugMode)
     {
         Tjs.OutputExceptionToConsole(msg + " at " + context.GetPositionDescriptionString(
                                          codepos));
     }
 }
 public virtual void ReShare()
 {
     // search shared string map using mapGlobalStringMap,
     // and ahsre the name string ( if it can )
     if (mName != null)
     {
         mName = Tjs.MapGlobalStringMap(mName);
     }
 }
Exemple #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Krkr# Tjs2 Executor by Ulysses");
            if (args.Length <= 0)
            {
                //args = new[] {"frameview.tjs"};
                args = new[] { Directory.GetCurrentDirectory() };
            }

            Tjs.mStorage = null;
            Tjs.Initialize();
            Tjs scriptEngine = new Tjs();

            Tjs.SetConsoleOutput(ConsoleOutput);

            Dispatch2         dsp    = scriptEngine.GetGlobal();
            TjsByteCodeLoader loader = new TjsByteCodeLoader();

            foreach (string s in args)
            {
                if (Directory.Exists(s)) //disasm dir
                {
                    var list       = Directory.EnumerateFiles(s, "*.tjs").Where(ss => ss.ToLowerInvariant().EndsWith(".tjs")).ToList();
                    var initScript = list.FirstOrDefault(n => n.Contains("startup.tjs"));
                    if (!string.IsNullOrWhiteSpace(initScript))
                    {
                        Execute(loader, scriptEngine, initScript);
                        list.Remove(initScript);
                    }

                    initScript = list.FirstOrDefault(n => n.Contains("initialize.tjs"));
                    if (!string.IsNullOrWhiteSpace(initScript))
                    {
                        Execute(loader, scriptEngine, initScript);
                        list.Remove(initScript);
                    }

                    foreach (var scripts in list)
                    {
                        var ret = Execute(loader, scriptEngine, scripts);
                        Console.WriteLine($"ret: {ret}");
                    }
                }
                else if (File.Exists(s) && s.ToLowerInvariant().EndsWith(".tjs"))
                {
                    var ret = Execute(loader, scriptEngine, s);
                    Console.WriteLine($"ret: {ret}");
                }
            }

            Console.WriteLine($"All Done! {_count} files processed.");
            Console.ReadLine();
            scriptEngine.Shutdown();
            Tjs.FinalizeApplication();
        }
        /// <exception cref="VariantException"></exception>
        protected internal static void DisplayExceptionGeneratedCode(int codepos, Variant
                                                                     [] ra, int ra_offset)
        {
            StringBuilder builder = new StringBuilder(128);

            builder.Append("==== An exception occured");
            builder.Append(", VM ip = ");
            builder.Append(codepos);
            builder.Append(" ====");
            Tjs.OutputToConsole(builder.ToString());
        }
Exemple #11
0
 public NativeClass(string name) : base()
 {
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name), "Must provide a class name.");
     }
     mCallFinalize = false;
     ClassName     = Tjs.MapGlobalStringMap(name);
     ClassId       = Tjs.RegisterNativeClass(name);
     mWorkParam    = new Variant();
 }
Exemple #12
0
        private void OutputFunc(string msg, string comment, int addr, int codestart, int
                                size, ScriptBlock data)
        {
            string buf = string.Format("%08d %s", addr, msg);

            if (comment != null)
            {
                buf += "\t// " + comment;
            }
            Tjs.OutputToConsole(buf);
        }
Exemple #13
0
 public ScriptBlock(Tjs owner, string name, int lineoffset, string script, ScriptLineData
                    linedata)
 {
     // a class for managing the script block
     // 以下の4つは实行时にいるかな、名前以外はエラー発生时に必要になるだけだろうけど。
     mOwner      = owner;
     mName       = name;
     mLineOffset = lineoffset;
     mScript     = script;
     mLineData   = linedata;
     mOwner.AddScriptBlock(this);
 }
Exemple #14
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public DebugClass() : base(CLASS_NAME)
        {
            ClassID = Tjs.FindNativeClassId(CLASS_NAME);
            // constructor
            RegisterNCM(CLASS_NAME, new ReturnOKConstructor(), CLASS_NAME, Interface.nitMethod
                        , 0);
            RegisterNCM("finalize", new ReturnOKMethod(), CLASS_NAME, Interface.nitMethod,
                        0);

            RegisterNCM("message", new DebugMessageMethod(), CLASS_NAME, Interface.nitMethod,
                        0);
        }
Exemple #15
0
        private void OutputFuncSrc(string msg, string name, int line, ScriptBlock data)
        {
            string buf;

            if (line >= 0)
            {
                buf = string.Format("#%s(%d) %s", name, line + 1, msg);
            }
            else
            {
                buf = string.Format("#%s %s", name, msg);
            }
            Tjs.OutputToConsole(buf);
        }
 public MessageHolder(string name, string defmsg, bool regist)
 {
     //mAssignedMessage = null;
     mDefaultMessage = defmsg;
     if (regist)
     {
         mName = name;
         Tjs.RegisterMessageMap(mName, this);
     }
     else
     {
         mName = null;
     }
 }
Exemple #17
0
        public void TestCompileTjs()
        {
            var path = "..\\..\\Res\\Initialize.tjs";

            Tjs.mStorage = null;
            Tjs.Initialize();
            Tjs      scriptEngine = new Tjs();
            Compiler c            = new Compiler(scriptEngine);

            using (var fs = File.Create("out.tjsbin"))
            {
                BinaryStream bs = new TjsBinaryStream(fs);
                c.Compile(File.ReadAllText(path), false, false, bs);
            }
        }
Exemple #18
0
 public ScriptBlock(Tjs owner)
 {
     mOwner = owner;
     // Java で初期值となる初期化は省略
     //mScript = null;
     //mName = null;
     //mInterCodeContext = null;
     //mTopLevelContext = null;
     //mLexicalAnalyzer = null;
     //mUsingPreProcessor = false;
     //mLineOffset = 0;
     //mCompileErrorCount = 0;
     //mNode = null;
     mOwner.AddScriptBlock(this);
 }
Exemple #19
0
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public RegExpClass() : base(CLASS_NAME)
 {
     ClassID = Tjs.FindNativeClassId(CLASS_NAME);
     // constructor
     RegisterNCM(CLASS_NAME, new _NativeClassConstructor_132(), CLASS_NAME, Interface.
                 nitMethod, 0);
     RegisterNCM("finalize", new _NativeClassMethod_147(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("compile", new _NativeClassMethod_154(), CLASS_NAME, Interface.nitMethod
                 , 0);
     // compiles given regular expression and flags.
     RegisterNCM("_compile", new _NativeClassMethod_166(), CLASS_NAME, Interface.nitMethod
                 , 0);
     //_this->RegEx.assign(exprstart, (wregex::flag_type));
     RegisterNCM("test", new _NativeClassMethod_206(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("match", new _NativeClassMethod_230(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("exec", new _NativeClassMethod_254(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("replace", new _NativeClassMethod_279(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("split", new _NativeClassMethod_350(), CLASS_NAME, Interface.nitMethod
                 , 0);
     RegisterNCM("matches", new _NativeClassProperty_385(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("start", new _NativeClassProperty_398(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("index", new _NativeClassProperty_414(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("lastIndex", new _NativeClassProperty_427(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("input", new _NativeClassProperty_440(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("lastMatch", new _NativeClassProperty_453(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("lastParen", new _NativeClassProperty_464(), CLASS_NAME, Interface.nitProperty
                 , 0);
     RegisterNCM("leftContext", new _NativeClassProperty_475(), CLASS_NAME, Interface.
                 nitProperty, 0);
     RegisterNCM("rightContext", new _NativeClassProperty_486(), CLASS_NAME, Interface
                 .nitProperty, 0);
     RegisterNCM("last", new _NativeClassProperty_498(), CLASS_NAME, Interface.nitProperty
                 , Interface.STATICMEMBER);
 }
Exemple #20
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public virtual void RegisterNCM(string name, Dispatch2 dsp, string className, int
                                        type, int flags)
        {
            string tname = Tjs.MapGlobalStringMap(name);

            // add to this
            //Variant val = new Variant(dsp);
            //propSet( (Interface.MEMBERENSURE | Interface.IGNOREPROP) | flags, tname, val, this);
            mWorkParam.Set(dsp);
            try
            {
                PropSet((Interface.MEMBERENSURE | Interface.IGNOREPROP) | flags, tname, mWorkParam
                        , this);
            }
            finally
            {
                mWorkParam.Clear();
            }
        }
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public virtual Dispatch2 Serialize()
        {
            // create dictionary object which has reconstructible information
            // which can be passed into constructor or randomize method.
            if (mGenerator == null)
            {
                return(null);
            }
            Dispatch2 dic = null;
            Variant   val = new Variant();
            // retrive tTJSMersenneTwisterData
            MersenneTwisterData data = mGenerator.GetData();
            // create 'state' string
            string        state;
            StringBuilder p = new StringBuilder(MT_N * 8);

            for (int i = 0; i < MT_N; i++)
            {
                string hex = "0123456789abcdef";
                p.Append(hex[(int)((data.state.Get(i) >> 28) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 24) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 20) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 16) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 12) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 8) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 4) & unchecked ((int)(0x000f)))]);
                p.Append(hex[(int)((data.state.Get(i) >> 0) & unchecked ((int)(0x000f)))]);
            }
            state = p.ToString();
            // create dictionary and store information
            dic = Tjs.CreateDictionaryObject();
            val.Set(state);
            dic.PropSet(Interface.MEMBERENSURE, "state", val, dic);
            val.Set(data.left);
            dic.PropSet(Interface.MEMBERENSURE, "left", val, dic);
            val.Set(data.next);
            dic.PropSet(Interface.MEMBERENSURE, "next", val, dic);
            return(dic);
        }
Exemple #22
0
        /// <summary>TJSGetExceptionObject : retrieves TJS 'Exception' object</summary>
        /// <exception cref="TjsException">TJSException</exception>
        /// <exception cref="VariantException">VariantException</exception>
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public static void GetExceptionObject(Tjs tjs, Variant res, Variant msg, Variant
                                              trace)
        {
            if (res == null)
            {
                return;
            }
            // not prcess
            // retrieve class "Exception" from global
            Dispatch2 global = tjs.GetGlobal();
            Variant   val    = new Variant();
            int       hr     = global.PropGet(0, EXCEPTION_NAME, val, global);

            if (hr < 0)
            {
                throw new TjsException(ExceptionNotFound);
            }
            // create an Exception object
            Holder <Dispatch2> excpobj = new Holder <Dispatch2>(null);
            VariantClosure     clo     = val.AsObjectClosure();

            Variant[] pmsg = new Variant[1];
            pmsg[0] = msg;
            hr      = clo.CreateNew(0, null, excpobj, pmsg, clo.mObjThis);
            if (hr < 0)
            {
                throw new TjsException(ExceptionNotFound);
            }
            Dispatch2 disp = excpobj.mValue;

            if (trace != null)
            {
                string trace_name = "trace";
                disp.PropSet(Interface.MEMBERENSURE, trace_name, trace, disp);
            }
            res.Set(disp, disp);
            excpobj = null;
        }
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public DictionaryClass() : base(CLASS_NAME)
 {
     ClassID = Tjs.FindNativeClassId(CLASS_NAME);
     // constructor
     RegisterNCM(CLASS_NAME, new _NativeClassConstructor_24(), CLASS_NAME, Interface.nitMethod
                 , Interface.STATICMEMBER);
     RegisterNCM("load", new _NativeClassMethod_36(), CLASS_NAME, Interface.nitMethod,
                 Interface.STATICMEMBER);
     // OribinalTODO: implement Dictionary.load()
     RegisterNCM("save", new _NativeClassMethod_47(), CLASS_NAME, Interface.nitMethod,
                 Interface.STATICMEMBER);
     // OribinalTODO: implement Dictionary.save()
     RegisterNCM("saveStruct", new _NativeClassMethod_58(), CLASS_NAME, Interface.nitMethod
                 , Interface.STATICMEMBER);
     // Structured output for flie;
     // the content can be interpret as an expression to re-construct the object.
     RegisterNCM("assign", new _NativeClassMethod_85(), CLASS_NAME, Interface.nitMethod
                 , Interface.STATICMEMBER);
     RegisterNCM("assignStruct", new _NativeClassMethod_106(), CLASS_NAME, Interface.nitMethod
                 , Interface.STATICMEMBER);
     RegisterNCM("clear", new _NativeClassMethod_125(), CLASS_NAME, Interface.nitMethod
                 , Interface.STATICMEMBER);
 }
Exemple #24
0
        static void Dump(TjsByteCodeLoader loader, Tjs engine, string path)
        {
            _count++;
            var fileOutput = new FileLogOutput(path + "asm");

            Tjs.SetConsoleOutput(fileOutput);
            using (var fs = new FileStream(path, FileMode.Open))
            {
                TjsBinaryStream stream = new TjsBinaryStream(fs);
                try
                {
                    var scriptBlock = loader.ReadByteCode(engine, Path.GetFileNameWithoutExtension(path), stream);
                    scriptBlock.Dump();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Loading {path} failed.");
                    _count--;
                }
            }
            Tjs.SetConsoleOutput(ConsoleOutput);
            fileOutput.Dispose();
        }
Exemple #25
0
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public virtual void Split(Holder <Dispatch2> array, string target, bool purgeempty
                           )
 {
     if (array.mValue == null)
     {
         array.mValue = Tjs.CreateArrayObject();
     }
     if (RegEx != null)
     {
         int limit = 0;
         if (purgeempty == false)
         {
             limit = -1;
         }
         string[] strs  = RegEx.Split(target, limit);
         int      count = strs.Length;
         for (int i = 0; i < count; i++)
         {
             Variant val = new Variant(strs[i]);
             array.mValue.PropSetByNum(Interface.MEMBERENSURE, i, val, array.mValue);
         }
     }
 }
        /// <summary>
        /// 引数があるコンストラクタには未对应
        /// TODO エラー时エラー表示するようにした方がいいかも
        /// </summary>
        protected internal override NativeInstance CreateNativeInstance()
        {
            object obj;

            try
            {
                obj = Activator.CreateInstance(mJavaClass);
            }
            catch (InstantiationException e)
            {
                Tjs.OutputExceptionToConsole(e.ToString());
                return(null);
            }
            catch (MemberAccessException e)
            {
                Tjs.OutputExceptionToConsole(e.ToString());
                return(null);
            }
            if (obj != null)
            {
                return(new NativeJavaInstance(obj));
            }
            return(null);
        }
 public NativeConvertedClassBase(Tjs owner)
 {
     mOwner = new WeakReference <Tjs>(owner);
 }
Exemple #28
0
 public NativeConvertedClassProperty(Tjs owner) : base(owner)
 {
 }
Exemple #29
0
 public static void ConsoleOutput(string msg, ScriptBlock blk)
 {
     Tjs.OutputToConsole(msg);
 }
 public PreprocessorExpressionParser(Tjs tjs, string script) : base(script)
 {
     //	private int mResult;
     mIDs = new AList <string>();
     mTJS = tjs;
 }