Skip to content

Commit feafe3d

Browse files
author
db
committed
对tsc.js手动应用src/tsc.patch和控制台直接输出编译后源码的补丁microsoft/TypeScript#1226 (comment);
用F:\i686-4.9.2-release-win32-dwarf-rt_v4-rev4\mingw32\bin编译出可正常执行的tsc.exe, F:\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\bin编译的不行
1 parent 52ea886 commit feafe3d

File tree

5 files changed

+181
-7
lines changed

5 files changed

+181
-7
lines changed

.vscode/c_cpp_properties.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [
9+
"_DEBUG",
10+
"UNICODE",
11+
"_UNICODE"
12+
],
13+
"windowsSdkVersion": "10.0.19041.0",
14+
"compilerPath": "F:/i686-4.9.2-release-win32-dwarf-rt_v4-rev4/mingw32/bin/gcc.exe",
15+
"cStandard": "c11",
16+
"cppStandard": "c++17",
17+
"intelliSenseMode": "windows-gcc-x86"
18+
}
19+
],
20+
"version": 4
21+
}

BUILD.BAT

-3
This file was deleted.

BUILD_TSC.BAT

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.\qjsc -flto -S 2097152 tsc.js
2+
make tsc.exe
3+
strip tsc.exe

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ $(OBJDIR):
189189
qjs$(EXE): $(QJS_OBJS)
190190
$(CC) $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS)
191191

192-
tsc$(EXE): $(OBJDIR)/out1440.o $(QJS_LIB_OBJS)
192+
tsc$(EXE): $(OBJDIR)/out23088.o $(QJS_LIB_OBJS)
193193
$(CC) $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS)
194194

195195
qjs-debug$(EXE): $(patsubst %.o, %.debug.o, $(QJS_OBJS))
@@ -301,6 +301,8 @@ clean:
301301
rm -f examples/*.so tests/*.so
302302
rm -rf $(OBJDIR)/ *.dSYM/ qjs-debug
303303
rm -rf run-test262-debug run-test262-32
304+
rm -f out*.c
305+
rm tsc.exe
304306

305307
install: all
306308
mkdir -p "$(DESTDIR)$(prefix)/bin"

tsc.js

+154-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
1212
See the Apache Version 2.0 License for specific language governing permissions
1313
and limitations under the License.
1414
***************************************************************************** */
15+
import * as os from "os";
16+
import * as std from "std";
1517

16-
17-
"use strict";
1818
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
1919
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
2020
to[j] = from[i];
@@ -4901,6 +4901,11 @@ var ts;
49014901
}
49024902
var fd;
49034903
try {
4904+
// If `-` is provided as the fileName, output to stdout
4905+
if (fileName === '-') {
4906+
process.stdout.write(data, "gbk");
4907+
return;
4908+
}
49044909
fd = _fs.openSync(fileName, "w");
49054910
_fs.writeSync(fd, data, undefined, "utf8");
49064911
}
@@ -5025,8 +5030,154 @@ var ts;
50255030
return hash.digest("hex");
50265031
}
50275032
}
5033+
function getQuickJSSystem() {
5034+
var executable_path = scriptArgs[0];
5035+
var args = scriptArgs.slice(1);
5036+
var useCaseSensitiveFileNames;
5037+
var newLine;
5038+
var realpath = function(path) {
5039+
var [res, err] = os.realpath(path);
5040+
return res;
5041+
};
5042+
if (os.platform === "win32") {
5043+
newLine = "\r\n";
5044+
useCaseSensitiveFileNames = false;
5045+
} else {
5046+
newLine = "\n";
5047+
useCaseSensitiveFileNames = true;
5048+
}
5049+
function getAccessibleFileSystemEntries(path) {
5050+
var entries, err, st;
5051+
[entries, err] = os.readdir(path || ".");
5052+
if (err != 0)
5053+
return ts.emptyFileSystemEntries;
5054+
entries = entries.sort();
5055+
var files = [];
5056+
var directories = [];
5057+
for (var i = 0; i < entries.length; i++) {
5058+
var entry = entries[i];
5059+
if (entry === "." || entry === "..") {
5060+
continue;
5061+
}
5062+
var name = ts.combinePaths(path, entry);
5063+
[st, err] = os.stat(name);
5064+
if (err != 0)
5065+
continue;
5066+
if ((st.mode & os.S_IFMT) == os.S_IFREG) {
5067+
files.push(entry);
5068+
} else if ((st.mode & os.S_IFMT) == os.S_IFDIR) {
5069+
directories.push(entry);
5070+
}
5071+
}
5072+
return { files: files, directories: directories };
5073+
}
5074+
function getDirectories(path) {
5075+
var entries, err, st;
5076+
var [entries, err] = os.readdir(path);
5077+
if (err != 0)
5078+
return [];
5079+
var directories = [];
5080+
for (var i = 0; i < entries.length; i++) {
5081+
var entry = entries[i];
5082+
var name = ts.combinePaths(path, entry);
5083+
[st, err] = os.stat(name);
5084+
if (err != 0)
5085+
continue;
5086+
if ((st.mode & os.S_IFMT) == os.S_IFDIR) {
5087+
directories.push(entry);
5088+
}
5089+
}
5090+
return directories;
5091+
}
5092+
5093+
return {
5094+
newLine: newLine,
5095+
args: args,
5096+
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
5097+
write: function(s) {
5098+
std.out.puts(s);
5099+
},
5100+
readFile: function (path, _encoding) {
5101+
var f, ret;
5102+
try {
5103+
f = std.open(path, "r");
5104+
ret = f.readAsString();
5105+
f.close();
5106+
} catch(e) {
5107+
ret = undefined;
5108+
}
5109+
return ret;
5110+
},
5111+
writeFile: function (path, data, writeByteOrderMark) {
5112+
var f;
5113+
try {
5114+
// If `-` is provided as the fileName, output to stdout
5115+
if (path === '-') {
5116+
std.out.puts(data);
5117+
return;
5118+
}
5119+
f = std.open(path, "w");
5120+
f.puts(data);
5121+
f.close();
5122+
} catch(e) {
5123+
}
5124+
},
5125+
resolvePath: function (s) { return s; },
5126+
fileExists: function(path) {
5127+
let [st, err] = os.stat(path);
5128+
if (err != 0)
5129+
return false;
5130+
return (st.mode & os.S_IFMT) == os.S_IFREG;
5131+
},
5132+
deleteFile: function(path) {
5133+
os.remove(path);
5134+
},
5135+
getModifiedTime: function(path) {
5136+
let [st, err] = os.stat(path);
5137+
if (err != 0)
5138+
throw std.Error(err);
5139+
return st.mtime; /* ms */
5140+
},
5141+
setModifiedTime: function(path, time) {
5142+
os.utimes(path, time, time);
5143+
},
5144+
directoryExists: function(path) {
5145+
let [st, err] = os.stat(path);
5146+
if (err != 0)
5147+
return false;
5148+
return (st.mode & os.S_IFMT) == os.S_IFDIR;
5149+
},
5150+
createDirectory: function(path) {
5151+
var ret;
5152+
ret = os.mkdir(path);
5153+
if (ret == -std.EEXIST)
5154+
throw new std.Error(-ret);
5155+
},
5156+
getExecutingFilePath: function () {
5157+
return executable_path;
5158+
},
5159+
getCurrentDirectory: function () {
5160+
var [cwd, err] = os.getcwd();
5161+
return cwd;
5162+
},
5163+
getDirectories: getDirectories,
5164+
getEnvironmentVariable: function(name) {
5165+
return std.getenv(name) || "";
5166+
},
5167+
readDirectory: function (path, extensions, excludes, includes, depth) {
5168+
let [cwd, err] = os.getcwd();
5169+
return ts.matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, cwd, depth, getAccessibleFileSystemEntries, realpath);
5170+
},
5171+
exit: function (exitCode) {
5172+
std.exit(exitCode);
5173+
},
5174+
realpath: realpath,
5175+
};
5176+
}
50285177
var sys;
5029-
if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
5178+
if (typeof os !== "undefined") {
5179+
sys = getQuickJSSystem();
5180+
} else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
50305181
sys = getNodeSystem();
50315182
}
50325183
if (sys) {

0 commit comments

Comments
 (0)