Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
// 'test/spec/wcc/module/module.spec.ts',
// 'test/spec/wcc/wxs/wxs.spec.ts',
// 'test/spec/wcsc/raw/raw.spec.ts',
// 'test/spec/wcc/empty/version.spec.ts'
],
// spec: "test/spec/wcc/wxs/wxs.spec.ts",
timeout: 20000,
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
🚀Features
- 架构:添加龙芯支持
- 编译器:跟进v2.01.2510250版本
- 编译器:添加 `--runtime-globals` 选项,移除 `--gdc` 选项

## 🌈 v0.1.5 / 2025-05-02

Expand Down
2 changes: 1 addition & 1 deletion src/include/define.h

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions src/include/wxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,19 +717,31 @@ namespace WXML

} // namespace EXPRLib

namespace GlassEaselWxs {
const std::string sWrapper = "function e(nv_require,nv_exports,nv_module){\u000a%s\u000a}const n={nv_exports:{}};e((function(e){return e.startsWith(\u0022p_\u0022)&&(e=\u0022/\u0022+e.slice(2)),e.endsWith(\u0022.wxs\u0022)&&(e=e.slice(0,e.length-4)),()=>gdc(require(e)(),\u0022nv_\u0022,2)}),n.nv_exports,n),Object.assign(module,gdc(n,void 0,2));";
const std::string sGenFuncDeepCopy = "var gdc=function(){var e=function(){return void 0!==this?this:\"undefined\"!=typeof globalThis?globalThis:\"undefine"
"d\"!=typeof self?self:\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:{}}();return function("
"n,t,o,i=e){if(null==n)return n;if(\"undefined\"!=typeof __wxCodeSpace__&&\"function\"==typeof __wxCodeSpace__.isWxsS"
"tateObject&&__wxCodeSpace__.isWxsStateObject(n))return n;if(\"string\"==typeof n||\"boolean\"==typeof n||\"number\"="
"=typeof n)return n;if(Array.isArray(n)){const e=[];for(let i=0;i<n.length;i++)e.push(gdc(n[i],t,o,n));return e}if(n "
"instanceof Date){const e=new Date;return e.setTime(n.getTime()),e}if(n instanceof RegExp){let e=\"\";return n.global"
"&&(e+=\"g\"),n.ignoreCase&&(e+=\"i\"),n.multiline&&(e+=\"m\"),new RegExp(n.source,e)}if(\"object\"==typeof n){const "
"e={};for(let i in n)Object.prototype.hasOwnProperty.call(n,i)&&(void 0===t?e[i.substring(3)]=gdc(n[i],t,o,n):e[t+i]="
"gdc(n[i],t,o,n));return e}return\"function\"==typeof n?1===o?null:function(...e){const o=gdc(e,void 0===t?\"nv_\":vo"
"id 0),r=n.apply(i,o);return gdc(r,t)}:null}}();";
const std::string sWxsEnvInit = aUndefinedTypeo;
namespace GlassEasel{
const std::string sRuntimeGlobals = "var X=function(n){return null==n?Object.create(null):n},Y=function(n){return null==n?\"\":String(n)},Z=function(n,t)"
"{return!0===n||(n?n[t]:void 0)},P=function(n){return function(...t){if(\"function\"==typeof n)try{return gdc(n.apply"
"(null,gdc(t,\"nv_\")))}catch(n){return console.error(\"WXS Error:\"),void console.error(n)}}},Q={a:function(n){for(v"
"ar t=0;t<n.length;t++)if(n[t])return n},b:function(n){for(var t=Object.values(n),r=0;r<t.length;r++)if(t[r])return t"
"},A:function(n){return n},B:function(n){return n}},D=function(){const n={},t=t=>{const o=n[t];if(void 0===o)throw ne"
"w Error(`no such WXS module: ${t}`);if(!o.t){const n={exports:{}};let e;o.o=n.exports,o.t=!0;try{e=o.u(r(t),n.export"
"s,n)}catch(n){throw o.t=!1,n}o.o=void 0!==n.exports?n.exports:e}return o.o},r=n=>function(r){if(\"string\"!=typeof r"
")throw new Error(\"WXS require args must be a string\");if(r.startsWith(\"p_\")&&r.endsWith(\".wxs\")){const n=r.sli"
"ce(2,-4);return()=>gdc(t(n),\"nv_\",2)}{const o=((n,t)=>{let r;r=\"/\"!==n[0]?t.split(\"/\").slice(0,-1).concat(n.sp"
"lit(\"/\")):n.split(\"/\");const o=[];for(let n=0;n<r.length;n+=1){const t=r[n];\"\"!==t&&\".\"!==t&&(\"..\"!==t?o.p"
"ush(t):o.pop())}return o.join(\"/\")})(r,n);return()=>t(o)}};return(r,o)=>(((t,r)=>{void 0===n[t]&&(n[t]={t:!1,u:r,o"
":null})})(r,o),()=>t(r))}(),gdc=function(n,t,r){if(null==n)return n;if(\"string\"==typeof n||\"boolean\"==typeof n||"
"\"number\"==typeof n)return n;if(Array.isArray(n)){const o=[];for(let e=0;e<n.length;e++)o.push(gdc(n[e],t,r));retur"
"n o}if(n instanceof Date){const t=new Date;return t.setTime(n.getTime()),t}if(n instanceof RegExp){let t=\"\";return"
" n.global&&(t+=\"g\"),n.ignoreCase&&(t+=\"i\"),n.multiline&&(t+=\"m\"),new RegExp(n.source,t)}if(\"function\"==typeo"
"f n)return 1==r?gdc(n(),void 0,2):2==r?n:null;if(\"object\"==typeof n){const o={};for(let e in n)Object.prototype.ha"
"sOwnProperty.call(n,e)&&(void 0===t?o[e.substring(3)]=gdc(n[e],t,r):o[t+e]=gdc(n[e],t,r));return o}return null};";
const std::string sGitHash = "";
namespace WXS {
const std::string sWrapper = "function e(nv_require,nv_exports,nv_module){\u000a%s\u000a}const n={nv_exports:{}};e((function(e){return e.startsWith(\u0022p_\u0022)&&(e=\u0022/\u0022+e.slice(2)),e.endsWith(\u0022.wxs\u0022)&&(e=e.slice(0,e.length-4)),()=>gdc(require(e)(),\u0022nv_\u0022,2)}),n.nv_exports,n),Object.assign(module,gdc(n,void 0,2));";

const std::string sEnvInit = aUndefinedTypeo;
const std::string sGitHash = "e8f2c53f408bfdf50d9acfef2cfe46b9358589d6";
};
};
}
#endif
4 changes: 2 additions & 2 deletions src/module/wcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ Napi::Value compile(Napi::Env &env, WCCOptions &options) {
{
throw Napi::Error::New(env, "Error: " + v146 + "\n");
}
auto v31 = snprintf(0, 0, WXML::GlassEaselWxs::sWrapper.c_str(),
auto v31 = snprintf(0, 0, WXML::GlassEasel::WXS::sWrapper.c_str(),
v146.c_str()) + 1; char *v32 = (char *)operator new[](v31);
snprintf(v32, v31, WXML::GlassEaselWxs::sWrapper.c_str(),
snprintf(v32, v31, WXML::GlassEasel::WXS::sWrapper.c_str(),
v146.c_str()); wxsMap[v152] = v32; delete[] v32;
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/wcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ int main(int argc, const char **argv)
bool isLLA = false;
bool hasLL = false;
bool isWxs = false;
bool isGDC = false;
bool isWxsEnv = false;
bool isRuntimeGlobals = false;
string xc_Or_completeCode_Param;
string outputFileName;
vector<string> fileList;
Expand Down Expand Up @@ -270,14 +270,14 @@ int main(int argc, const char **argv)
{
isWxs = true;
}
else if (!param.compare("--gdc"))
{
isGDC = true;
}
else if (!param.compare("--wxs-env"))
{
isWxsEnv = true;
}
else if (!param.compare("--runtime-globals"))
{
isRuntimeGlobals = true;
}

}
}
Expand Down Expand Up @@ -330,9 +330,9 @@ int main(int argc, const char **argv)
fprintf(stderr, "Error in file %s: %s\n", v152.c_str(), v146.c_str());
return -2;
}
auto v31 = snprintf(0, 0, WXML::GlassEaselWxs::sWrapper.c_str(), v146.c_str()) + 1;
auto v31 = snprintf(0, 0, WXML::GlassEasel::WXS::sWrapper.c_str(), v146.c_str()) + 1;
char *v32 = (char *)operator new[](v31);
snprintf(v32, v31, WXML::GlassEaselWxs::sWrapper.c_str(), v146.c_str());
snprintf(v32, v31, WXML::GlassEasel::WXS::sWrapper.c_str(), v146.c_str());
cfg[v152] = v32;
delete[] v32;
}
Expand All @@ -345,9 +345,9 @@ int main(int argc, const char **argv)
return fclose(f);
return 0;
}
if (isGDC)
if (isWxsEnv)
{
std::string v136 = WXML::GlassEaselWxs::sGenFuncDeepCopy.c_str();
std::string v136 = WXML::GlassEasel::WXS::sEnvInit.c_str();
FILE *f = stdout;
if (!outputFileName.empty())
f = fopen(outputFileName.c_str(), "w");
Expand All @@ -356,9 +356,9 @@ int main(int argc, const char **argv)
return fclose(f);
return 0;
}
if (isWxsEnv)
if (isRuntimeGlobals)
{
std::string v136 = WXML::GlassEaselWxs::sWxsEnvInit.c_str();
std::string v136 = WXML::GlassEasel::sRuntimeGlobals.c_str();
FILE *f = stdout;
if (!outputFileName.empty())
f = fopen(outputFileName.c_str(), "w");
Expand Down
54 changes: 54 additions & 0 deletions test/spec/wcc/empty/version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,60 @@ describe("wcc - empty", function () {
fs.mkdirSync(storagePath, { recursive: true });
} catch (error) {}

fs.writeFileSync(`${storagePath}/wine-output.js`, w);
fs.writeFileSync(`${storagePath}/node-output.js`, n);
assert.equal(n, w, `wine: ${w}\n\nlinux: ${n}`);
});
it("wxs-env", async function () {
const projectPath = __dirname;
const args: string[] = [
"--wxs-env"
];
let w = ""
try
{
w = (await windows.wcc(args, projectPath)).replace(/\r\n/g, '\n')
}
catch(err: any){
console.error('error:', err)
w = err.stdout.replace(/\r\n/g, '\n')
}
const n = await linux.wcc(args, projectPath);
const storagePath = path.resolve(
__dirname,
`wxs-env/${this.test?.title}`
);
try {
fs.mkdirSync(storagePath, { recursive: true });
} catch (error) {}

fs.writeFileSync(`${storagePath}/wine-output.js`, w);
fs.writeFileSync(`${storagePath}/node-output.js`, n);
assert.equal(n, w, `wine: ${w}\n\nlinux: ${n}`);
});
it("runtime-globals", async function () {
const projectPath = __dirname;
const args: string[] = [
"--runtime-globals"
];
let w = ""
try
{
w = (await windows.wcc(args, projectPath)).replace(/\r\n/g, '\n')
}
catch(err: any){
console.error('error:', err)
w = err.stdout.replace(/\r\n/g, '\n')
}
const n = await linux.wcc(args, projectPath);
const storagePath = path.resolve(
__dirname,
`runtime-globals/${this.test?.title}`
);
try {
fs.mkdirSync(storagePath, { recursive: true });
} catch (error) {}

fs.writeFileSync(`${storagePath}/wine-output.js`, w);
fs.writeFileSync(`${storagePath}/node-output.js`, n);
assert.equal(n, w, `wine: ${w}\n\nlinux: ${n}`);
Expand Down
10 changes: 5 additions & 5 deletions test/wcc.disassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195705,7 +195705,7 @@ int __cdecl main(int argc, const char **argv, const char **envp)
else
{
v12 = *(_DWORD *)v103;
if ( *(_BYTE *)(*(_DWORD *)v103 + 1) == 99 && *(_BYTE *)(v12 + 2) == 98 )
if ( *(_BYTE *)(*(_DWORD *)v103 + 1) == 99/*c*/ && *(_BYTE *)(v12 + 2) == 98 /*b*/)
{
++v5;
LOBYTE(v170[0]) = 0;
Expand Down Expand Up @@ -195733,7 +195733,7 @@ int __cdecl main(int argc, const char **argv, const char **envp)
std::string::_M_dispose((void **)&String);
++v5;
}
else if ( v89 == 108 && *(_BYTE *)(v12 + 2) == 108 )
else if ( v89 == 108/*l*/ && *(_BYTE *)(v12 + 2) == 108/*l*/ )
{
v16 = *(_BYTE *)(v12 + 3);
if ( v16 != 119 )
Expand Down Expand Up @@ -195811,15 +195811,15 @@ int __cdecl main(int argc, const char **argv, const char **envp)
fclose(v24);
std::string::_M_dispose((void **)&v168);
}
if ( !v88 )
if ( !v88 ) // wxs
{
if ( v87 )
if ( v87 ) // isRuntimeGlobals
{
v39 = (const char **)&WXML::GlassEasel::sRuntimeGlobals;
LABEL_112:
main::{lambda(std::string const&)#1}::operator()((const char **)&FileName, v39);
v111 = 0;
goto LABEL_192;
goto LABEL_192; // return
}
v39 = (const char **)&WXML::GlassEasel::WXS::sEnvInit;
if ( v93 )
Expand Down
Loading