SHARE
TWEET
Untitled
a guest
Dec 20th, 2018
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- var pas = {};
- var rtl = {
- version: 10301,
- quiet: false,
- debug_load_units: false,
- debug_rtti: false,
- debug: function () {
- if (rtl.quiet || !console || !console.log) return;
- console.log(arguments);
- },
- error: function (s) {
- rtl.debug("Error: ", s);
- throw s;
- },
- warn: function (s) {
- rtl.debug("Warn: ", s);
- },
- checkVersion: function (v) {
- if (rtl.version != v) throw "expected rtl version " + v + ", but found " + rtl.version;
- },
- hasString: function (s) {
- return rtl.isString(s) && (s.length > 0);
- },
- isArray: function (a) {
- return Array.isArray(a);
- },
- isFunction: function (f) {
- return typeof (f) === "function";
- },
- isModule: function (m) {
- return rtl.isObject(m) && rtl.hasString(m.$name) && (pas[m.$name] === m);
- },
- isImplementation: function (m) {
- return rtl.isObject(m) && rtl.isModule(m.$module) && (m.$module.$impl === m);
- },
- isNumber: function (n) {
- return typeof (n) === "number";
- },
- isObject: function (o) {
- return (typeof (o) === "object") && (o != null);
- },
- isString: function (s) {
- return typeof (s) === "string";
- },
- getNumber: function (n) {
- return typeof (n) === "number" ? n : NaN;
- },
- getChar: function (c) {
- return ((typeof (c) === "string") && (c.length === 1)) ? c : "";
- },
- getObject: function (o) {
- return ((typeof (o) === "object") || (typeof (o) === "function")) ? o : null;
- },
- isPasClass: function (type) {
- return (rtl.isObject(type) && type.hasOwnProperty("$classname") && rtl.isObject(type.$module));
- },
- isPasClassInstance: function (type) {
- return (rtl.isObject(type) && rtl.isPasClass(type.$class));
- },
- hexStr: function (n, digits) {
- return ("000000000000000" + n.toString(16).toUpperCase()).slice(-digits);
- },
- m_loading: 0,
- m_loading_intf: 1,
- m_intf_loaded: 2,
- m_loading_impl: 3,
- m_initializing: 4,
- m_initialized: 5,
- module: function (module_name, intfuseslist, intfcode, impluseslist, implcode) {
- if (rtl.debug_load_units) rtl.debug("rtl.module name=\"" + module_name + "\" intfuses=" + intfuseslist + " impluses=" + impluseslist + " hasimplcode=" + rtl.isFunction(implcode));
- if (!rtl.hasString(module_name)) rtl.error("invalid module name \"" + module_name + "\"");
- if (!rtl.isArray(intfuseslist)) rtl.error("invalid interface useslist of \"" + module_name + "\"");
- if (!rtl.isFunction(intfcode)) rtl.error("invalid interface code of \"" + module_name + "\"");
- if (!(impluseslist == undefined) && !rtl.isArray(impluseslist)) rtl.error("invalid implementation useslist of \"" + module_name + "\"");
- if (!(implcode == undefined) && !rtl.isFunction(implcode)) rtl.error("invalid implementation code of \"" + module_name + "\"");
- if (pas[module_name])
- rtl.error("module \"" + module_name + "\" is already registered");
- var module = pas[module_name] = {
- $name: module_name,
- $intfuseslist: intfuseslist,
- $impluseslist: impluseslist,
- $state: rtl.m_loading,
- $intfcode: intfcode,
- $implcode: implcode,
- $impl: null,
- $rtti: Object.create(rtl.tSectionRTTI)
- };
- module.$rtti.$module = module;
- if (implcode) module.$impl = {
- $module: module,
- $rtti: module.$rtti
- };
- },
- exitcode: 0,
- run: function (module_name) {
- function doRun() {
- if (!rtl.hasString(module_name)) module_name = "program";
- if (rtl.debug_load_units) rtl.debug("rtl.run module=\"" + module_name + "\"");
- rtl.initRTTI();
- var module = pas[module_name];
- if (!module) rtl.error("rtl.run module \"" + module_name + "\" missing");
- rtl.loadintf(module);
- rtl.loadimpl(module);
- if (module_name == "program") {
- if (rtl.debug_load_units) rtl.debug("running $main");
- var r = pas.program.$main();
- if (rtl.isNumber(r)) rtl.exitcode = r;
- }
- }
- if (rtl.showUncaughtExceptions) {
- try {
- doRun();
- } catch (re) {
- var errMsg = re.hasOwnProperty("$class") ? re.$class.$classname : "";
- errMsg += ((errMsg) ? ": " : "") + (re.hasOwnProperty("fMessage") ? re.fMessage : re);
- alert("Uncaught Exception : " + errMsg);
- rtl.exitCode = 216;
- }
- } else {
- doRun();
- }
- return rtl.exitcode;
- },
- loadintf: function (module) {
- if (module.$state > rtl.m_loading_intf) return;
- if (rtl.debug_load_units) rtl.debug("loadintf: \"" + module.$name + "\"");
- if (module.$state === rtl.m_loading_intf)
- rtl.error("unit cycle detected \"" + module.$name + "\"");
- module.$state = rtl.m_loading_intf;
- rtl.loaduseslist(module, module.$intfuseslist, rtl.loadintf);
- if (rtl.debug_load_units) rtl.debug("loadintf: run intf of \"" + module.$name + "\"");
- module.$intfcode(module.$intfuseslist);
- module.$state = rtl.m_intf_loaded;
- },
- loaduseslist: function (module, useslist, f) {
- if (useslist == undefined) return;
- for (var i in useslist) {
- var unitname = useslist[i];
- if (rtl.debug_load_units) rtl.debug("loaduseslist of \"" + module.$name + "\" uses=\"" + unitname + "\"");
- if (pas[unitname] == undefined)
- rtl.error("module \"" + module.$name + "\" misses \"" + unitname + "\"");
- f(pas[unitname]);
- }
- },
- loadimpl: function (module) {
- if (module.$state >= rtl.m_loading_impl) return;
- if (module.$state < rtl.m_intf_loaded) rtl.error("loadimpl: interface not loaded of \"" + module.$name + "\"");
- if (rtl.debug_load_units) rtl.debug("loadimpl: load uses of \"" + module.$name + "\"");
- module.$state = rtl.m_loading_impl;
- rtl.loaduseslist(module, module.$impluseslist, rtl.loadintf);
- rtl.loaduseslist(module, module.$intfuseslist, rtl.loadimpl);
- rtl.loaduseslist(module, module.$impluseslist, rtl.loadimpl);
- if (rtl.debug_load_units) rtl.debug("loadimpl: run impl of \"" + module.$name + "\"");
- if (rtl.isFunction(module.$implcode)) module.$implcode(module.$impluseslist);
- if (rtl.debug_load_units) rtl.debug("loadimpl: run init of \"" + module.$name + "\"");
- module.$state = rtl.m_initializing;
- if (rtl.isFunction(module.$init)) module.$init();
- module.$state = rtl.m_initialized;
- },
- createCallback: function (scope, fn) {
- var cb;
- if (typeof (fn) === "string") {
- cb = function () {
- return scope[fn].apply(scope, arguments);
- };
- } else {
- cb = function () {
- return fn.apply(scope, arguments);
- };
- }
- cb.scope = scope;
- cb.fn = fn;
- return cb;
- },
- cloneCallback: function (cb) {
- return rtl.createCallback(cb.scope, cb.fn);
- },
- eqCallback: function (a, b) {
- if (a == b) {
- return true;
- } else {
- return (a != null) && (b != null) && (a.fn) && (a.scope === b.scope) && (a.fn == b.fn);
- }
- },
- initClass: function (c, parent, name, initfn) {
- parent[name] = c;
- c.$class = c;
- c.$classname = name;
- if ((parent.$module) && (parent.$module.$impl === parent)) parent = parent.$module;
- c.$parent = parent;
- c.$fullname = parent.$name + "." + name;
- if (rtl.isModule(parent)) {
- c.$module = parent;
- c.$name = name;
- } else {
- c.$module = parent.$module;
- c.$name = parent.name + "." + name;
- }
- if (rtl.debug_rtti) rtl.debug("initClass " + c.$fullname);
- var t = c.$module.$rtti.$Class(c.$name, {
- "class": c,
- module: parent
- });
- c.$rtti = t;
- if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
- if (!t.ancestor) t.ancestor = null;
- initfn.call(c);
- },
- createClass: function (parent, name, ancestor, initfn) {
- var c = null;
- if (ancestor != null) {
- c = Object.create(ancestor);
- c.$ancestor = ancestor;
- } else {
- c = {};
- c.$create = function (fnname, args) {
- if (args == undefined) args = [];
- try {
- var o = Object.create(this);
- o.$init();
- o[fnname].apply(o, args);
- o.AfterConstruction();
- } catch ($e) {
- if (o.Destroy) o.Destroy();
- o.$final();
- throw $e;
- }
- return o;
- };
- c.$destroy = function (fnname) {
- this.BeforeDestruction();
- if (this[fnname]) this[fnname]();
- this.$final();
- };
- }
- rtl.initClass(c, parent, name, initfn);
- },
- createClassExt: function (parent, name, ancestor, newinstancefnname, initfn) {
- var c = null;
- c = Object.create(ancestor);
- c.$create = function (fnname, args) {
- if (args == undefined) args = [];
- var o = null;
- if (newinstancefnname.length > 0) {
- o = this[newinstancefnname](fnname, args);
- } else {
- o = Object.create(this);
- }
- if (o.$init) o.$init();
- try {
- o[fnname].apply(o, args);
- if (o.AfterConstruction) o.AfterConstruction();
- } catch ($e) {
- if (o.Destroy) o.Destroy();
- if (o.$final) this.$final();
- throw $e;
- }
- return o;
- };
- c.$destroy = function (fnname) {
- if (this.BeforeDestruction) this.BeforeDestruction();
- if (this[fnname]) this[fnname]();
- if (this.$final) this.$final();
- };
- rtl.initClass(c, parent, name, initfn);
- },
- tObjectDestroy: "Destroy",
- free: function (obj, name) {
- if (obj[name] == null) return;
- obj[name].$destroy(rtl.tObjectDestroy);
- obj[name] = null;
- },
- freeLoc: function (obj) {
- if (obj == null) return;
- obj.$destroy(rtl.tObjectDestroy);
- return null;
- },
- is: function (instance, type) {
- return type.isPrototypeOf(instance) || (instance === type);
- },
- isExt: function (instance, type, mode) {
- if (instance == null) return false;
- if ((typeof (type) !== "object") && (typeof (type) !== "function")) return false;
- if (instance === type) {
- if (mode === 1) return false;
- if (mode === 2) return rtl.isPasClass(instance);
- return true;
- }
- if (type.isPrototypeOf && type.isPrototypeOf(instance)) {
- if (mode === 1) return rtl.isPasClassInstance(instance);
- if (mode === 2) return rtl.isPasClass(instance);
- return true;
- }
- if ((typeof type == "function") && (instance instanceof type)) return true;
- return false;
- },
- Exception: null,
- EInvalidCast: null,
- EAbstractError: null,
- ERangeError: null,
- raiseE: function (typename) {
- var t = rtl[typename];
- if (t == null) {
- var mod = pas.SysUtils;
- if (!mod) mod = pas.sysutils;
- if (mod) {
- t = mod[typename];
- if (!t) t = mod[typename.toLowerCase()];
- if (!t) t = mod["Exception"];
- if (!t) t = mod["exception"];
- }
- }
- if (t) {
- if (t.Create) {
- throw t.$create("Create");
- } else if (t.create) {
- throw t.$create("create");
- }
- }
- if (typename === "EInvalidCast") throw "invalid type cast";
- if (typename === "EAbstractError") throw "Abstract method called";
- if (typename === "ERangeError") throw "range error";
- throw typename;
- },
- as: function (instance, type) {
- if ((instance === null) || rtl.is(instance, type)) return instance;
- rtl.raiseE("EInvalidCast");
- },
- asExt: function (instance, type, mode) {
- if ((instance === null) || rtl.isExt(instance, type, mode)) return instance;
- rtl.raiseE("EInvalidCast");
- },
- createInterface: function (module, name, guid, fnnames, ancestor, initfn) {
- var i = ancestor ? Object.create(ancestor) : {};
- module[name] = i;
- i.$module = module;
- i.$name = name;
- i.$fullname = module.$name + "." + name;
- i.$guid = guid;
- i.$guidr = null;
- i.$names = fnnames ? fnnames : [];
- if (rtl.isFunction(initfn)) {
- if (rtl.debug_rtti) rtl.debug("createInterface " + i.$fullname);
- var t = i.$module.$rtti.$Interface(name, {
- "interface": i,
- module: module
- });
- i.$rtti = t;
- if (ancestor) t.ancestor = ancestor.$rtti;
- if (!t.ancestor) t.ancestor = null;
- initfn.call(i);
- }
- return i;
- },
- strToGUIDR: function (s, g) {
- var p = 0;
- function n(l) {
- var h = s.substr(p, l);
- p += l;
- return parseInt(h, 16);
- }
- p += 1;
- g.D1 = n(8);
- p += 1;
- g.D2 = n(4);
- p += 1;
- g.D3 = n(4);
- p += 1;
- if (!g.D4) g.D4 = [];
- g.D4[0] = n(2);
- g.D4[1] = n(2);
- p += 1;
- for (var i = 2; i < 8; i++) g.D4[i] = n(2);
- return g;
- },
- guidrToStr: function (g) {
- if (g.$intf) return g.$intf.$guid;
- var h = rtl.hexStr;
- var s = "{" + h(g.D1, 8) + "-" + h(g.D2, 4) + "-" + h(g.D3, 4) + "-" + h(g.D4[0], 2) + h(g.D4[1], 2) + "-";
- for (var i = 2; i < 8; i++) s += h(g.D4[i], 2);
- s += "}";
- return s;
- },
- createTGUID: function (guid) {
- var TGuid = (pas.System) ? pas.System.TGuid : pas.system.tguid;
- var g = rtl.strToGUIDR(guid, new TGuid());
- return g;
- },
- getIntfGUIDR: function (intfTypeOrVar) {
- if (!intfTypeOrVar) return null;
- if (!intfTypeOrVar.$guidr) {
- var g = rtl.createTGUID(intfTypeOrVar.$guid);
- if (!intfTypeOrVar.hasOwnProperty("$guid")) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
- g.$intf = intfTypeOrVar;
- intfTypeOrVar.$guidr = g;
- }
- return intfTypeOrVar.$guidr;
- },
- addIntf: function (aclass, intf, map) {
- function jmp(fn) {
- if (typeof (fn) === "function") {
- return function () {
- return fn.apply(this.$o, arguments);
- };
- } else {
- return function () {
- rtl.raiseE("EAbstractError");
- };
- }
- }
- if (!map) map = {};
- var t = intf;
- var item = Object.create(t);
- if (!aclass.hasOwnProperty("$intfmaps")) aclass.$intfmaps = {};
- aclass.$intfmaps[intf.$guid] = item;
- do {
- var names = t.$names;
- if (!names) break;
- for (var i = 0; i < names.length; i++) {
- var intfname = names[i];
- var fnname = map[intfname];
- if (!fnname) fnname = intfname;
- item[intfname] = jmp(aclass[fnname]);
- }
- t = Object.getPrototypeOf(t);
- } while (t != null);
- },
- getIntfG: function (obj, guid, query) {
- if (!obj) return null;
- var maps = obj.$intfmaps;
- if (!maps) return null;
- var item = maps[guid];
- if (!item) return null;
- if (typeof item === "function") return item.call(obj);
- var intf = null;
- if (obj.$interfaces) {
- intf = obj.$interfaces[guid];
- }
- if (!intf) {
- intf = Object.create(item);
- intf.$o = obj;
- if (!obj.$interfaces) obj.$interfaces = {};
- obj.$interfaces[guid] = intf;
- }
- if (typeof (query) === "object") {
- var o = null;
- if (intf.QueryInterface(rtl.getIntfGUIDR(query), {
- get: function () {
- return o;
- },
- set: function (v) {
- o = v;
- }
- }) === 0) {
- return o;
- } else {
- return null;
- }
- } else if (query === 2) {
- if (intf.$kind === "com") intf._AddRef();
- }
- return intf;
- },
- getIntfT: function (obj, intftype) {
- return rtl.getIntfG(obj, intftype.$guid);
- },
- queryIntfT: function (obj, intftype) {
- return rtl.getIntfG(obj, intftype.$guid, intftype);
- },
- queryIntfIsT: function (obj, intftype) {
- var i = rtl.queryIntfG(obj, intftype.$guid);
- if (!i) return false;
- if (i.$kind === "com") i._Release();
- return true;
- },
- asIntfT: function (obj, intftype) {
- var i = rtl.getIntfG(obj, intftype.$guid);
- if (i !== null) return i;
- rtl.raiseEInvalidCast();
- },
- intfIsClass: function (intf, classtype) {
- return (intf != null) && (rtl.is(intf.$o, classtype));
- },
- intfAsClass: function (intf, classtype) {
- if (intf == null) return null;
- return rtl.as(intf.$o, classtype);
- },
- intfToClass: function (intf, classtype) {
- if ((intf !== null) && rtl.is(intf.$o, classtype)) return intf.$o;
- return null;
- },
- intfRefs: {
- ref: function (id, intf) {
- var old = this[id];
- if (old) {
- delete this[id];
- old._Release();
- }
- this[id] = intf;
- return intf;
- },
- free: function () {
- for (var id in this) {
- if (this.hasOwnProperty(id)) {
- this[id]._Release();
- }
- }
- }
- },
- createIntfRefs: function () {
- return Object.create(rtl.intfRefs);
- },
- setIntfP: function (path, name, value, skipAddRef) {
- var old = path[name];
- if (old === value) return;
- if (old !== null) {
- path[name] = null;
- old._Release();
- }
- if (value !== null) {
- if (!skipAddRef) value._AddRef();
- path[name] = value;
- }
- },
- setIntfL: function (old, value, skipAddRef) {
- if (old !== value) {
- if (value !== null) {
- if (!skipAddRef) value._AddRef();
- }
- if (old !== null) {
- old._Release();
- }
- } else if (skipAddRef) {
- if (old !== null) {
- old._Release();
- }
- }
- return value;
- },
- _AddRef: function (intf) {
- if (intf) intf._AddRef();
- return intf;
- },
- _Release: function (intf) {
- if (intf) intf._Release();
- return intf;
- },
- checkMethodCall: function (obj, type) {
- if (rtl.isObject(obj) && rtl.is(obj, type)) return;
- rtl.raiseE("EInvalidCast");
- },
- rc: function (i, minval, maxval) {
- if ((Math.floor(i) === i) && (i >= minval) && (i <= maxval)) return i;
- rtl.raiseE("ERangeError");
- },
- rcc: function (c, minval, maxval) {
- if ((typeof (c) === "string") && (c.length === 1)) {
- var i = c.charCodeAt(0);
- if ((i >= minval) && (i <= maxval)) return c;
- }
- rtl.raiseE("ERangeError");
- },
- rcSetCharAt: function (s, index, c) {
- if ((typeof (s) !== "string") || (index < 0) || (index >= s.length)) rtl.raiseE("ERangeError");
- return rtl.setCharAt(s, index, c);
- },
- rcCharAt: function (s, index) {
- if ((typeof (s) !== "string") || (index < 0) || (index >= s.length)) rtl.raiseE("ERangeError");
- return s.charAt(index);
- },
- rcArrR: function (arr, index) {
- if (Array.isArray(arr) && (typeof (index) === "number") && (index >= 0) && (index < arr.length)) {
- if (arguments.length > 2) {
- arr = arr[index];
- for (var i = 2; i < arguments.length; i++) arr = rtl.rcArrR(arr, arguments[i]);
- return arr;
- }
- return arr[index];
- }
- rtl.raiseE("ERangeError");
- },
- rcArrW: function (arr, index, value) {
- for (var i = 3; i < arguments.length; i++) {
- arr = rtl.rcArrR(arr, index);
- index = arguments[i - 1];
- value = arguments[i];
- }
- if (Array.isArray(arr) && (typeof (index) === "number") && (index >= 0) && (index < arr.length)) {
- return arr[index] = value;
- }
- rtl.raiseE("ERangeError");
- },
- length: function (arr) {
- return (arr == null) ? 0 : arr.length;
- },
- arraySetLength: function (arr, defaultvalue, newlength) {
- if (arr == null) arr = [];
- var p = arguments;
- function setLength(a, argNo) {
- var oldlen = a.length;
- var newlen = p[argNo];
- if (oldlen !== newlength) {
- a.length = newlength;
- if (argNo === p.length - 1) {
- if (rtl.isArray(defaultvalue)) {
- for (var i = oldlen; i < newlen; i++) a[i] = [];
- } else if (rtl.isFunction(defaultvalue)) {
- for (var i = oldlen; i < newlen; i++) a[i] = new defaultvalue();
- } else if (rtl.isObject(defaultvalue)) {
- for (var i = oldlen; i < newlen; i++) a[i] = {};
- } else {
- for (var i = oldlen; i < newlen; i++) a[i] = defaultvalue;
- }
- } else {
- for (var i = oldlen; i < newlen; i++) a[i] = [];
- }
- }
- if (argNo < p.length - 1) {
- for (var i = 0; i < newlen; i++) a[i] = setLength(a[i], argNo + 1);
- }
- return a;
- }
- return setLength(arr, 2);
- },
- arrayEq: function (a, b) {
- if (a === null) return b === null;
- if (b === null) return false;
- if (a.length !== b.length) return false;
- for (var i = 0; i < a.length; i++)
- if (a[i] !== b[i]) return false;
- return true;
- },
- arrayClone: function (type, src, srcpos, endpos, dst, dstpos) {
- if (rtl.isFunction(type)) {
- for (; srcpos < endpos; srcpos++) dst[dstpos++] = new type(src[srcpos]);
- } else if (type === "refSet") {
- for (; srcpos < endpos; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]);
- } else {
- for (; srcpos < endpos; srcpos++) dst[dstpos++] = src[srcpos];
- }
- },
- arrayConcat: function (type) {
- var a = [];
- var l = 0;
- for (var i = 1; i < arguments.length; i++) {
- var src = arguments[i];
- if (src !== null) l += src.length;
- }
- a.length = l;
- l = 0;
- for (var i = 1; i < arguments.length; i++) {
- var src = arguments[i];
- if (src === null) continue;
- rtl.arrayClone(type, src, 0, src.length, a, l);
- l += src.length;
- }
- return a;
- },
- arrayConcatN: function () {
- var a = null;
- for (var i = 1; i < arguments.length; i++) {
- var src = arguments[i];
- if (src === null) continue;
- if (a === null) {
- a = src;
- } else {
- a = a.concat(src);
- }
- }
- return a;
- },
- arrayCopy: function (type, srcarray, index, count) {
- if (srcarray === null) return [];
- if (index < 0) index = 0;
- if (count === undefined) count = srcarray.length;
- var end = index + count;
- if (end > srcarray.length) end = srcarray.length;
- if (index >= end) return [];
- if (type === 0) {
- return srcarray.slice(index, end);
- } else {
- var a = [];
- a.length = end - index;
- rtl.arrayClone(type, srcarray, index, end, a, 0);
- return a;
- }
- },
- setCharAt: function (s, index, c) {
- return s.substr(0, index) + c + s.substr(index + 1);
- },
- getResStr: function (mod, name) {
- var rs = mod.$resourcestrings[name];
- return rs.current ? rs.current : rs.org;
- },
- createSet: function () {
- var s = {};
- for (var i = 0; i < arguments.length; i++) {
- if (arguments[i] != null) {
- s[arguments[i]] = true;
- } else {
- var first = arguments[i += 1];
- var last = arguments[i += 1];
- for (var j = first; j <= last; j++) s[j] = true;
- }
- }
- return s;
- },
- cloneSet: function (s) {
- var r = {};
- for (var key in s) r[key] = true;
- return r;
- },
- refSet: function (s) {
- Object.defineProperty(s, "$shared", {
- enumerable: false,
- configurable: true,
- writable: true,
- value: true
- });
- return s;
- },
- includeSet: function (s, enumvalue) {
- if (s.$shared) s = rtl.cloneSet(s);
- s[enumvalue] = true;
- return s;
- },
- excludeSet: function (s, enumvalue) {
- if (s.$shared) s = rtl.cloneSet(s);
- delete s[enumvalue];
- return s;
- },
- diffSet: function (s, t) {
- var r = {};
- for (var key in s)
- if (!t[key]) r[key] = true;
- return r;
- },
- unionSet: function (s, t) {
- var r = {};
- for (var key in s) r[key] = true;
- for (var key in t) r[key] = true;
- return r;
- },
- intersectSet: function (s, t) {
- var r = {};
- for (var key in s)
- if (t[key]) r[key] = true;
- return r;
- },
- symDiffSet: function (s, t) {
- var r = {};
- for (var key in s)
- if (!t[key]) r[key] = true;
- for (var key in t)
- if (!s[key]) r[key] = true;
- return r;
- },
- eqSet: function (s, t) {
- for (var key in s)
- if (!t[key]) return false;
- for (var key in t)
- if (!s[key]) return false;
- return true;
- },
- neSet: function (s, t) {
- return !rtl.eqSet(s, t);
- },
- leSet: function (s, t) {
- for (var key in s)
- if (!t[key]) return false;
- return true;
- },
- geSet: function (s, t) {
- for (var key in t)
- if (!s[key]) return false;
- return true;
- },
- strSetLength: function (s, newlen) {
- var oldlen = s.length;
- if (oldlen > newlen) {
- return s.substring(0, newlen);
- } else if (s.repeat) {
- return s + " ".repeat(newlen - oldlen);
- } else {
- while (oldlen < newlen) {
- s += " ";
- oldlen++;
- }
- return s;
- }
- },
- spaceLeft: function (s, width) {
- var l = s.length;
- if (l >= width) return s;
- if (s.repeat) {
- return " ".repeat(width - l) + s;
- } else {
- while (l < width) {
- s = " " + s;
- l++;
- }
- }
- },
- floatToStr: function (d, w, p) {
- if (arguments.length > 2) {
- return rtl.spaceLeft(d.toFixed(p), w);
- } else {
- var pad = "";
- var ad = Math.abs(d);
- if (ad < 1.0e+10) {
- pad = "00";
- } else if (ad < 1.0e+100) {
- pad = "0";
- }
- if (arguments.length < 2) {
- w = 9;
- } else if (w < 9) {
- w = 9;
- }
- var p = w - 8;
- var s = (d > 0 ? " " : "") + d.toExponential(p);
- s = s.replace(/e(.)/, "E$1" + pad);
- return rtl.spaceLeft(s, w);
- }
- },
- valEnum: function (s, enumType, setCodeFn) {
- s = s.toLowerCase();
- for (var key in enumType) {
- if ((typeof (key) === "string") && (key.toLowerCase() === s)) {
- setCodeFn(0);
- return enumType[key];
- }
- }
- setCodeFn(1);
- return 0;
- },
- initRTTI: function () {
- if (rtl.debug_rtti) rtl.debug("initRTTI");
- rtl.tTypeInfo = {
- name: "tTypeInfo"
- };
- function newBaseTI(name, kind, ancestor) {
- if (!ancestor) ancestor = rtl.tTypeInfo;
- if (rtl.debug_rtti) rtl.debug("initRTTI.newBaseTI \"" + name + "\" " + kind + " (\"" + ancestor.name + "\")");
- var t = Object.create(ancestor);
- t.name = name;
- t.kind = kind;
- rtl[name] = t;
- return t;
- }
- function newBaseInt(name, minvalue, maxvalue, ordtype) {
- var t = newBaseTI(name, 1, rtl.tTypeInfoInteger);
- t.minvalue = minvalue;
- t.maxvalue = maxvalue;
- t.ordtype = ordtype;
- return t;
- }
- newBaseTI("tTypeInfoInteger", 1);
- newBaseInt("shortint", -0x80, 0x7f, 0);
- newBaseInt("byte", 0, 0xff, 1);
- newBaseInt("smallint", -0x8000, 0x7fff, 2);
- newBaseInt("word", 0, 0xffff, 3);
- newBaseInt("longint", -0x80000000, 0x7fffffff, 4);
- newBaseInt("longword", 0, 0xffffffff, 5);
- newBaseInt("nativeint", -0x10000000000000, 0xfffffffffffff, 6);
- newBaseInt("nativeuint", 0, 0xfffffffffffff, 7);
- newBaseTI("char", 2);
- newBaseTI("string", 3);
- newBaseTI("tTypeInfoEnum", 4, rtl.tTypeInfoInteger);
- newBaseTI("tTypeInfoSet", 5);
- newBaseTI("double", 6);
- newBaseTI("boolean", 7);
- newBaseTI("tTypeInfoProcVar", 8);
- newBaseTI("tTypeInfoMethodVar", 9, rtl.tTypeInfoProcVar);
- newBaseTI("tTypeInfoArray", 10);
- newBaseTI("tTypeInfoDynArray", 11);
- newBaseTI("tTypeInfoPointer", 15);
- var t = newBaseTI("pointer", 15, rtl.tTypeInfoPointer);
- t.reftype = null;
- newBaseTI("jsvalue", 16);
- newBaseTI("tTypeInfoRefToProcVar", 17, rtl.tTypeInfoProcVar);
- rtl.tTypeMember = {};
- function newMember(name, kind) {
- var m = Object.create(rtl.tTypeMember);
- m.name = name;
- m.kind = kind;
- rtl[name] = m;
- }
- newMember("tTypeMemberField", 1);
- newMember("tTypeMemberMethod", 2);
- newMember("tTypeMemberProperty", 3);
- rtl.tTypeMembers = {};
- var tis = newBaseTI("tTypeInfoStruct", 0);
- tis.$addMember = function (name, ancestor, options) {
- if (rtl.debug_rtti) {
- if (!rtl.hasString(name) || (name.charAt() === "$")) throw "invalid member \"" + name + "\", this=\"" + this.name + "\"";
- if (!rtl.is(ancestor, rtl.tTypeMember)) throw "invalid ancestor \"" + ancestor + ":" + ancestor.name + "\", \"" + this.name + "." + name + "\"";
- if ((options != undefined) && (typeof (options) != "object")) throw "invalid options \"" + options + "\", \"" + this.name + "." + name + "\"";
- }
- var t = Object.create(ancestor);
- t.name = name;
- this.members[name] = t;
- this.names.push(name);
- if (rtl.isObject(options)) {
- for (var key in options)
- if (options.hasOwnProperty(key)) t[key] = options[key];
- }
- return t;
- };
- tis.addField = function (name, type, options) {
- var t = this.$addMember(name, rtl.tTypeMemberField, options);
- if (rtl.debug_rtti) {
- if (!rtl.is(type, rtl.tTypeInfo)) throw "invalid type \"" + type + "\", \"" + this.name + "." + name + "\"";
- }
- t.typeinfo = type;
- this.fields.push(name);
- return t;
- };
- tis.addFields = function () {
- var i = 0;
- while (i < arguments.length) {
- var name = arguments[i++];
- var type = arguments[i++];
- if ((i < arguments.length) && (typeof (arguments[i]) === "object")) {
- this.addField(name, type, arguments[i++]);
- } else {
- this.addField(name, type);
- }
- }
- };
- tis.addMethod = function (name, methodkind, params, result, options) {
- var t = this.$addMember(name, rtl.tTypeMemberMethod, options);
- t.methodkind = methodkind;
- t.procsig = rtl.newTIProcSig(params);
- t.procsig.resulttype = result ? result : null;
- this.methods.push(name);
- return t;
- };
- tis.addProperty = function (name, flags, result, getter, setter, options) {
- var t = this.$addMember(name, rtl.tTypeMemberProperty, options);
- t.flags = flags;
- t.typeinfo = result;
- t.getter = getter;
- t.setter = setter;
- if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
- this.properties.push(name);
- if (!rtl.isString(t.stored)) t.stored = "";
- return t;
- };
- tis.getField = function (index) {
- return this.members[this.fields[index]];
- };
- tis.getMethod = function (index) {
- return this.members[this.methods[index]];
- };
- tis.getProperty = function (index) {
- return this.members[this.properties[index]];
- };
- newBaseTI("tTypeInfoRecord", 12, rtl.tTypeInfoStruct);
- newBaseTI("tTypeInfoClass", 13, rtl.tTypeInfoStruct);
- newBaseTI("tTypeInfoClassRef", 14);
- newBaseTI("tTypeInfoInterface", 15, rtl.tTypeInfoStruct);
- },
- tSectionRTTI: {
- $module: null,
- $inherited: function (name, ancestor, o) {
- if (rtl.debug_rtti) {
- rtl.debug("tSectionRTTI.newTI \"" + (this.$module ? this.$module.$name : "(no module)") +
- "\".\"" + name + "\" (" + ancestor.name + ") " + (o ? "init" : "forward"));
- }
- var t = this[name];
- if (t) {
- if (!t.$forward) throw "duplicate type \"" + name + "\"";
- if (!ancestor.isPrototypeOf(t)) throw "typeinfo ancestor mismatch \"" + name + "\" ancestor=\"" + ancestor.name + "\" t.name=\"" + t.name + "\"";
- } else {
- t = Object.create(ancestor);
- t.name = name;
- t.$module = this.$module;
- this[name] = t;
- }
- if (o) {
- delete t.$forward;
- for (var key in o)
- if (o.hasOwnProperty(key)) t[key] = o[key];
- } else {
- t.$forward = true;
- }
- return t;
- },
- $Scope: function (name, ancestor, o) {
- var t = this.$inherited(name, ancestor, o);
- t.members = {};
- t.names = [];
- t.fields = [];
- t.methods = [];
- t.properties = [];
- return t;
- },
- $TI: function (name, kind, o) {
- var t = this.$inherited(name, rtl.tTypeInfo, o);
- t.kind = kind;
- return t;
- },
- $Int: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoInteger, o);
- },
- $Enum: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoEnum, o);
- },
- $Set: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoSet, o);
- },
- $StaticArray: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoArray, o);
- },
- $DynArray: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoDynArray, o);
- },
- $ProcVar: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoProcVar, o);
- },
- $RefToProcVar: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoRefToProcVar, o);
- },
- $MethodVar: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoMethodVar, o);
- },
- $Record: function (name, o) {
- return this.$Scope(name, rtl.tTypeInfoRecord, o);
- },
- $Class: function (name, o) {
- return this.$Scope(name, rtl.tTypeInfoClass, o);
- },
- $ClassRef: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoClassRef, o);
- },
- $Pointer: function (name, o) {
- return this.$inherited(name, rtl.tTypeInfoPointer, o);
- },
- $Interface: function (name, o) {
- return this.$Scope(name, rtl.tTypeInfoInterface, o);
- }
- },
- newTIParam: function (param) {
- var t = {
- name: param[0],
- typeinfo: param[1],
- flags: (rtl.isNumber(param[2]) ? param[2] : 0)
- };
- return t;
- },
- newTIParams: function (list) {
- var params = [];
- if (rtl.isArray(list)) {
- for (var i = 0; i < list.length; i++) params.push(rtl.newTIParam(list[i]));
- }
- return params;
- },
- newTIProcSig: function (params, result, flags) {
- var s = {
- params: rtl.newTIParams(params),
- resulttype: result,
- flags: flags
- };
- return s;
- }
- };
- rtl.module("System", [], function () {
- "use strict";
- var $mod = this;
- this.LineEnding = "\n";
- this.sLineBreak = "\n";
- this.MaxLongint = 0x7fffffff;
- this.Maxint = 2147483647;
- rtl.createClass($mod, "TObject", null, function () {
- this.$init = function () {};
- this.$final = function () {};
- this.Create = function () {};
- this.AfterConstruction = function () {};
- this.BeforeDestruction = function () {};
- });
- this.IsConsole = true;
- this.OnParamCount = null;
- this.OnParamStr = null;
- this.ParamStr = function (Index) {
- var Result = "";
- if ($mod.OnParamStr != null) {
- Result = $mod.OnParamStr(Index);
- } else if (Index === 0) {
- Result = "js";
- } else Result = "";
- return Result;
- };
- this.upcase = function (c) {
- return c.toUpperCase();
- };
- this.StringOfChar = function (c, l) {
- var Result = "";
- var i = 0;
- if ((l > 0) && c.repeat) return c.repeat(l);
- Result = "";
- for (var $l1 = 1, $end2 = l; $l1 <= $end2; $l1++) {
- i = $l1;
- Result = Result + c;
- }
- return Result;
- };
- $mod.$init = function () {
- rtl.exitcode = 0;
- };
- });
- rtl.module("Types", ["System"], function () {
- "use strict";
- var $mod = this;
- });
- rtl.module("JS", ["System", "Types"], function () {
- "use strict";
- var $mod = this;
- });
- rtl.module("NodeJS", ["System", "JS", "Types"], function () {
- "use strict";
- var $mod = this;
- this.NJS_OS = null;
- $mod.$init = function () {
- $mod.NJS_OS = rtl.getObject(require("os"));
- pas.System.LineEnding = $mod.NJS_OS.EOL;
- pas.System.sLineBreak = $mod.NJS_OS.EOL;
- };
- });
- rtl.module("SysUtils", ["System", "JS"], function () {
- "use strict";
- var $mod = this;
- this.TrimLeft = function (S) {
- return S.replace(/^[\s\uFEFF\xA0\x00-\x1f]+/, "");
- };
- this.OnGetEnvironmentVariable = null;
- this.OnGetEnvironmentString = null;
- this.OnGetEnvironmentVariableCount = null;
- rtl.createClass($mod, "TFormatSettings", pas.System.TObject, function () {});
- this.FormatSettings = null;
- $mod.$init = function () {
- $mod.FormatSettings = $mod.TFormatSettings.$create("Create");
- };
- });
- rtl.module("Classes", ["System", "Types", "SysUtils"], function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $mod.$init = function () {
- $impl.ClassList = Object.create(null);
- };
- }, ["JS"], function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.ClassList = null;
- });
- rtl.module("NodeJSApp", ["System", "NodeJS", "Classes", "SysUtils", "Types", "JS"], function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- this.ReloadEnvironmentStrings = function () {
- $impl.EnvNames = Object.getOwnPropertyNames(process.env);
- };
- $mod.$init = function () {
- pas.System.IsConsole = true;
- pas.System.OnParamCount = $impl.GetParamCount;
- pas.System.OnParamStr = $impl.GetParamStr;
- $mod.ReloadEnvironmentStrings();
- pas.SysUtils.OnGetEnvironmentVariable = $impl.MyGetEnvironmentVariable;
- pas.SysUtils.OnGetEnvironmentVariableCount = $impl.MyGetEnvironmentVariableCount;
- pas.SysUtils.OnGetEnvironmentString = $impl.MyGetEnvironmentString;
- };
- }, null, function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.EnvNames = [];
- $impl.GetParamCount = function () {
- var Result = 0;
- Result = rtl.length(process.argv) - 2;
- return Result;
- };
- $impl.GetParamStr = function (Index) {
- var Result = "";
- Result = process.argv[Index + 1];
- return Result;
- };
- $impl.MyGetEnvironmentVariable = function (EnvVar) {
- var Result = "";
- Result = "" + process.env[EnvVar];
- return Result;
- };
- $impl.MyGetEnvironmentVariableCount = function () {
- var Result = 0;
- Result = rtl.length($impl.EnvNames);
- return Result;
- };
- $impl.MyGetEnvironmentString = function (Index) {
- var Result = "";
- Result = $impl.EnvNames[Index];
- return Result;
- };
- });
- rtl.module("StrUtils", ["System", "SysUtils"], function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- this.ReverseString = function (AText) {
- var Result = "";
- var i = 0;
- var j = 0;
- Result = rtl.strSetLength(Result, AText.length);
- i = 1;
- j = AText.length;
- while (i <= j) {
- Result = rtl.setCharAt(Result, i - 1, AText.charAt(((j - i) + 1) - 1));
- i += 1;
- }
- return Result;
- };
- this.Soundex = function (AText, ALength) {
- var Result = "";
- var S = "";
- var PS = "";
- var I = 0;
- var L = 0;
- Result = "";
- PS = "\x00";
- if (AText.length > 0) {
- Result = pas.System.upcase(AText.charAt(0));
- I = 2;
- L = AText.length;
- while ((I <= L) && (Result.length < ALength)) {
- S = $impl.SScore.charAt(AText.charCodeAt(I - 1) - 1);
- if (!(S.charCodeAt() in rtl.createSet(48, 105, PS.charCodeAt()))) Result = Result + S;
- if (S !== "i") PS = S;
- I += 1;
- }
- }
- L = Result.length;
- if (L < ALength) Result = Result + pas.System.StringOfChar("0", ALength - L);
- return Result;
- };
- this.SoundexSimilar = function (AText, AOther, ALength) {
- var Result = false;
- Result = $mod.Soundex(AText, ALength) === $mod.Soundex(AOther, ALength);
- return Result;
- };
- this.SoundexSimilar$1 = function (AText, AOther) {
- var Result = false;
- Result = $mod.SoundexSimilar(AText, AOther, 4);
- return Result;
- };
- this.SoundexProc = function (AText, AOther) {
- var Result = false;
- Result = $mod.SoundexSimilar$1(AText, AOther);
- return Result;
- };
- this.AnsiResemblesProc = null;
- $mod.$init = function () {
- $mod.AnsiResemblesProc = $mod.SoundexProc;
- };
- }, ["JS"], function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.SScore = (((((((("00000000000000000000000000000000" + "00000000000000000000000000000000") + "0123012i02245501262301i2i2") + "000000") + "0123012i02245501262301i2i2") + "00000000000000000000000000000000") + "00000000000000000000000000000000") + "00000000000000000000000000000000") + "00000000000000000000000000000000") + "00000";
- });
- rtl.module("program", ["System", "NodeJS", "NodeJSApp", "SysUtils", "StrUtils"], function () {
- "use strict";
- var $mod = this;
- this.Exaggerate = function (S) {
- var Result = "";
- var C = "";
- for (var $in1 = S, $l2 = 0, $end3 = $in1.length - 1; $l2 <= $end3; $l2++) {
- C = $in1.charAt($l2);
- Result = (Result + C) + " ";
- }
- return Result;
- };
- this.I = 0;
- this.Jerk = "";
- this.Exaggerated = "";
- this.Space = "";
- $mod.$main = function () {
- $mod.Jerk = pas.System.ParamStr(1);
- if ($mod.Jerk === "") return;
- $mod.Exaggerated = $mod.Exaggerate($mod.Jerk);
- console.log($mod.Exaggerated);
- $mod.Space = pas.System.StringOfChar(" ", ($mod.Jerk.length * 2) - 3);
- for (var $l1 = 2, $end2 = $mod.Jerk.length - 1; $l1 <= $end2; $l1++) {
- $mod.I = $l1;
- console.log(($mod.Jerk.charAt($mod.I - 1) + $mod.Space) + $mod.Jerk.charAt(((($mod.Jerk.length - 1) + 2) - $mod.I) - 1));
- }
- console.log(pas.SysUtils.TrimLeft(pas.StrUtils.ReverseString($mod.Exaggerated)));
- };
- });
- rtl.run();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
