swizl / tinycc_zh

GNU Lesser General Public License v2.1
4 stars 4 forks source link

你好,我有几个问题想请教你 #1

Open qwas982 opened 7 years ago

qwas982 commented 7 years ago

你好,我有几个问题想请教你 1,请问相对于原始tcc,你改动了哪些文件,哪些地方? 2,我能否按照你改动的方法和过程将tcc全部文件和代码修改为汉语,包括缩写(阿拉伯数字和数学符号就不改了)? 3,我能否将全部修改后的代码用你的【小习编译器Bate】编译为新的汉化tcc编译器?如果技术上不行,我该怎么做? 4,tcc怎么没有汇编器?它是直接编译为二进制吗?我没看到汇编代码。

qwas982 commented 7 years ago

@swizl

swizl commented 7 years ago

@qwas982 1.这个工程改动就多了,所有的关键字都替换成中文了。另外一个工程tinycc_cn里,就几个文件,你可以在commits里看到。 2.可以的,这工程已经将关键字都换了。本来打算将变量和函数名也换的,但是工作量比较大,意义已经没有关键字自举那么大了,自己就懒起来了,没干。你愿意做的话,我先谢一下你。 3 可行的,路线的话在readme 里写了。这里大概对你的需求再写一下,先用gcc编译小习alpha,并安装;再用小习alpha编译小习bate,并安装。你在对小习bate的代码进行修改,然后再的编译安装,进行自举。 有一点要主要一下,下载代码后,所以源文件的编码要统一一下。utf8的其实也可以,我试过,但最好还是转成ascii的。 4.tcc好像是根据cpu和os直接编译成bin的,这个我也没细看。你有精力的话可以细看一下,好好学习一下。

swizl commented 7 years ago

@qwas982 有什么问题可以继续讨论。 再说一点,在代码里可以搜一下 “main”,这个是主函数的名字,其实可以改成中文的,但我没做。改了之后要多自举一次,所以麻烦了一点,其实逻辑可以改一下,“main”和“主函数”都认,都有时“主函数”优先。

qwas982 commented 7 years ago

@swizl 你回答的几点我仔细看了,多谢解答。 工作量大不要紧,我愿意试一试。

第二个,你是说我可以在Beta的基础上将函数名 变量名 参数名等,还有缩写都可以改成中文了吗?然后再用beta版本编译也可以通过?

swizl commented 7 years ago

@qwas982 其实alpha版和beta版本质是一样的,只是beta版在alpha的基础上将本身的关键字替换成中文了。而中文的函数名、变量名、参数名都只是符号而已,在alpha就已经可以用了。如果你在beta版上做更好,那就可接近100%中文了。里面和windows相关的几个头文件,我觉得没有必要汉化。

qwas982 commented 7 years ago

@swizl 原来是这样,我明白了。

不过关于关键字的汉化,我有如下想法 【关于对现阶段模仿的出发点, 我觉得判断语句; 可以用 【if=若 else=反之 elif=反之若 switch=岔路 case=状况】 循环语句; 可以用 【while=圆 do=当 for=环。】】

const=常量,你翻译为【不变】。我觉得有违阅读惯性。如果码界有了一定程度的共识,我觉得顺应趋势会更方便推广使用,当然,这只是我个人的看法。

swizl commented 7 years ago

@qwas982 while=园,for=环,这两个我不喜欢,其他的都还行。

const 可以翻译成 常数,不变的。我用“不变”,主要是还有个volatile,意思是“易变的”。 当然,还是还是那句话,随你喜欢,fork之后,自己随便改嘛。

qwas982 commented 7 years ago

@swizl
while=园,for=环,我是取【形】的“意”。把这种循环想象成一个形状。并且 还有动词的意思,假如你觉得不行,那你认为用什么命名比较好? 用“重复”,你觉得如何?while=重复,for=循环。不过这样就是两个字了

另外,关于编码的问题,是文本编码还是其它什么的编码? 为啥必须要用ASCII?用unicode码编译的时候会出现兼容问题吗? 如果是,在哪个位置可以修改?

qwas982 commented 7 years ago

@swizl 你好,我在编译的时候遇到问题了。

我在Windows下的mingw64下编译,在CMD中执行./configure提示找不到文件或目录,我把tcc整个目录都移动到mingw64的目录下,还是一样,cmd提示 . 不是命令。然后我又在windows下安装msys2,在它提供的模拟bash shell下执行./configure 也是一样找不到目录,执行make也不行。是不是windows下不能编译?

请问你是在windows下编译的吗?还是,你是在linux下编译的?

swizl commented 7 years ago

@qwas982 我是在mingw32下编译的,mingw64应该也可有。应该先编译tinycc_cn,并安装。然后再编译tinycc_zh。 ./configure 最好带安装路径的参数。不然的话,会安装到c盘去。 tinycc_cn 编译: ./configure --prefix=/local/tcc make & make install tinycc_zh 编译 ./configure --prefix=/local/tcc --cc=/local/tcc/tcc.exe make & make install

qwas982 commented 7 years ago

C:>./configure --prefix=/local/tcc '.' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

@swizl 我执行后就是这样的,我把tinycc_cn的源代码整个目录都放在mingw64目录下,但还是这样的提示,这是为什么?是不是没有加入系统变量?

swizl commented 7 years ago

@qwas982 看样子你还没有进入posix环境。建议你用原版mingw或者msys2。之前用的是mingw,刚才试了一下msys2也可以。

swizl commented 7 years ago

@qwas982 还有,你cd到了代码的路径下了吗?

qwas982 commented 7 years ago

@swizl 我又重新安装了32位的cygwin,执行./configure后 有如下提示。 $ ./configure --prefix=/local/tcc configure: error: 'gcc' failed to compile conftest.c. ./configure:行332: ./conftest.exe: No such file or directory Binary directory /local/tcc TinyCC directory /local/tcc Library directory /local/tcc/lib Include directory /local/tcc/include Manual directory /local/tcc/man Info directory /local/tcc/info Doc directory /local/tcc/doc Source path . C compiler gcc (0.0) Target OS CYGWIN_NT-6.1-WOW CPU i386 Config WIN32 Creating config.mak and config.h

swizl commented 7 years ago

@qwas982 确定你是在编译tinycc_cn,对吧? tinycc_zh 只能用tinycc_cn编译,不能用gcc编译。

如果是在编译tinycc_cn,可能是cygwin 32位的 gcc的库里少了一个crtfastmath.o的文件。

qwas982 commented 7 years ago

@swizl 是的 我确定在编译tinycc_cn的源码,在windows平台上在cygwin或msys2里用命令行编译,并且安装了mingw 32位 64位。每个版本都试了,都不行。

经过一些研究,我发现是环境变量找不到已经安装好的gcc程序。打入命令后,显示如下 $ gcc bash: gcc: 未找到命令

根据这里的提示;http://blog.csdn.net/fightforprogrammer/article/details/41960707 我输入以下命令后发现了这一原因; $ whereis gcc gcc:

于是打算在bash里安装gcc。 $ wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.0/gcc-4.8.0.tar.gz --2017-09-12 10:55:29-- http://ftp.gnu.org/gnu/gcc/gcc-4.8.0/gcc-4.8.0.tar.gz 正在解析主机 ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b 正在连接 ftp.gnu.org|208.118.235.20|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:111219539 (106M) [application/x-gzip] 正在保存至: “gcc-4.8.0.tar.gz”

gcc-4.8.0.tar.gz 7%[> ] 8.41M 382KB/s 剩余 4m 53s

qwas982 commented 7 years ago

@swizl 【zhangboyang】说,0.9.27版有很多子版本,如果是最近的都没有解决utf8的问题。可能tinycc_cn需要更新他的补丁才行,我不知道怎么更新,请问怎么更新这个补丁,他说叫宽字符补丁。

swizl commented 7 years ago

@qwas982 msys2的话直接 pacman -S gcc 就行了 mingw的话安装的时候,所有模块都选上。

swizl commented 7 years ago

@qwas982 你先把自己编译过吧,之后再下个diff,加上就行了

qwas982 commented 7 years ago

@swizl 刚刚下载完压缩包后,发现tar命令又找不到....郁闷,是不是windows不适合用命令行开发?看起来又要安装tar依赖环境,索性放弃这条思路,于是把已经下载好的mingw64文件全部复制到msys2的mingw64目录下。然后启动64位msys2,敲入 gcc -v 终于显示出了版本。如下; $ gcc -v Using built-in specs. COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe COLLECT_LTO_WRAPPER=C:/msys64/mingw64/libexec/gcc/x86_64-w64-mingw32/7.1.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-7.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw710/x86_64-710-posix-seh-rt_v5-rev1/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw710/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw710/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw710/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw710/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev1, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev1/mingw64/opt/include -I/c/mingw710/prerequisites/x86_64-zlib-static/include -I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev1/mingw64/opt/include -I/c/mingw710/prerequisites/x86_64-zlib-static/include -I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev1/mingw64/opt/include -I/c/mingw710/prerequisites/x86_64-zlib-static/include -I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw710/x86_64-710-posix-seh-rt_v5-rev1/mingw64/opt/lib -L/c/mingw710/prerequisites/x86_64-zlib-static/lib -L/c/mingw710/prerequisites/x86_64-w64-mingw32-static/lib ' Thread model: posix gcc version 7.1.0 (x86_64-posix-seh-rev1, Built by MinGW-W64 project)

启动32位的msys2 键入 gcc 也显示没有这个命令,看来版本一定要对的上才行。

现在尝试编译tinycc_cn的源码

qwas982 commented 7 years ago

@swizl

出现编译失败的提示,请问是哪里出问题了?

$ ./configure --prefix=/local/tcc

Binary directory /local/tcc TinyCC directory /local/tcc Library directory /local/tcc/lib Include directory /local/tcc/include Manual directory /local/tcc/man Info directory /local/tcc/info Doc directory /local/tcc/doc Source path . C compiler gcc (7.1) Target OS MINGW64_NT-6.1 CPU x86_64 Config WIN32 Creating config.mak and config.h

Administrator@android- MINGW64 /mingw64/tcc/tinycc_cn-tinycc-cn $ make

gcc -o tcc.o -c tcc.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o libtcc.o -c libtcc.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o tccpp.o -c tccpp.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o tccgen.o -c tccgen.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o tccelf.o -c tccelf.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o tccasm.o -c tccasm.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o tccrun.o -c tccrun.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o x86_64-gen.o -c x86_64-gen.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o x86_64-link.o -c x86_64-link.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o i386-asm.o -c i386-asm.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -o tccpe.o -c tccpe.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I. gcc -shared -o libtcc.dll libtcc.o tccpp.o tccgen.o tccelf.o tccasm.o tccrun.o x86_64-gen.o x86_64-link.o i386-asm.o tccpe.o -static gcc -o tcc.exe tcc.o libtcc.dll -static make[1]: Entering directory 'C:/msys64/mingw64/tcc/tinycc_cn-tinycc-cn/lib' make[1]: '../libtcc1.a' is up to date. make[1]: Leaving directory 'C:/msys64/mingw64/tcc/tinycc_cn-tinycc-cn/lib' ./tcc.exe -impdef libtcc.dll -o libtcc.def makeinfo --no-split --html --number-sections -o tcc-doc.html tcc-doc.texi Makefile:240: recipe for target 'tcc-doc.html' failed process_begin: CreateProcess(NULL, makeinfo --no-split --html --number-sections -o tcc-doc.html tcc-doc.texi, ...) failed. make (e=2): ϵͳ▒Ҳ▒▒▒ָ▒▒▒▒▒ļ▒▒▒ make: [tcc-doc.html] Error 2 (ignored) makeinfo tcc-doc.texi Makefile:247: recipe for target 'tcc-doc.info' failed process_begin: CreateProcess(NULL, makeinfo tcc-doc.texi, ...) failed. make (e=2): ϵͳ▒Ҳ▒▒▒ָ▒▒▒▒▒ļ▒▒▒ make: [tcc-doc.info] Error 2 (ignored)

swizl commented 7 years ago

@qwas982 可能没安装 texinfo,所以makeinfo用不了。不过我建议你重新安装msys2,用pacman安装gcc,git,texinfo等。你的环境可能已经被你搞乱了。

qwas982 commented 7 years ago

@swizl 噢~ 原来如此,看来编译环境、依赖关系彼此严密。 请问,如果是手动组建环境的话,除了gcc,git,texinfo以外,还需要哪些组件?

qwas982 commented 7 years ago

@swizl 已经顺利编译完成阿尔法α版,不过我发现还有更方便的编译工具,它甚至是图形界面的.... http://blog.csdn.net/xuguangsoft/article/details/8162757

那么现在就是用阿尔法版生成的编译器编译beta版源代码是吗? 还有就是目录,我怎么将编译后的文件设置在c盘根目录下?

swizl commented 7 years ago

@qwas982 编译并安装alpha版,再用alpha版编译beta版。 configure 时--prefix=/local/tcc 设置的就是安装路径,你可以设置成其他路径,在configure beta版时 --cc=/local/tcc/tcc.exe 对应就行。

qwas982 commented 7 years ago

@swizl configure beta版时 --cc=/local/tcc/tcc.exe中这个路径tcc.exe我放在其他路径,这个路径--cc=/local/tcc/tcc.exe是不是也可以自定义修改?

另外,我发现msys2无法执行tcc.exe 用windows的cmd又可以执行。这是怎么回事? 我在msys2的终端中是cd到编译好的alpha版tcc的目录下的。

qwas982 commented 7 years ago

@swizl 朋友,你有即时聊天软件账号吗?邮箱也行,你经常用的。github在我这里访问不是很稳定,我不能及时看到回复。通过其他方式交流或许更高效点,然后把交流的重点po到这里来,那样,大家都看得到了。

qwas982 commented 7 years ago

@swizl 收到。

我发现了新的问题。 从你的git库里下载回来的所有源代码用的是GB18030编码,通过gcc可以编译,用编译后的tinycc-cn编译器编译带有中文关键字的源代码也可以编译通过。 例如;

包含

整 main(){ 整 a=1; 整 b=2; printf("%d\n",a+b);
}

用tinycc-cn beta版本的编译器编译后(正常编译通过),不管在msys2里还是windows cmd里都可以正常执行出结果3.



但是如果把代码改成这样;

包含

整 main(){ 整 a=1; 整 b=2; 字 z=你好; printf("%d\n",a+b); printf("%c\n",z); }

在msys2用tinycc-cn beta版本的编译器编译是会出现以下提示; Administrator@android- MINGW32 /tcc $ tcccn3 hanzi.c zifu.exe hanzi.c:6: error: '▒▒ã▒▒▒▒▒' undeclared

我用notepad2把编码从GB18030改成utf-8后保存再编译,后会出现以下提示; Administrator@android- MINGW32 /tcc $ tcccn3 hanzi.c zifu.exe hanzi.c:1: warning: Ignoring unknown preprocessing directive #包含 hanzi.c:3: error: ';' expected (got "main")

qwas982 commented 7 years ago

@swizl 这是什么问题?也就是说还是要打@zhangboyang 的那个diff补丁?

swizl commented 7 years ago

@qwas982

  1. 字* z="你好"; //这是c 最基本语法呀
  2. 你编译的源文件的编码和tinycc_cn的源代码 的编码必须一致。
qwas982 commented 7 years ago

@swizl

字符要打双引号....才疏学浅,实在不懂,抱歉。但是字* 是指向字符串的指针?有必要用指针吗?

我用Beyond Compare 4打开对比查看,发现用utf8显示 中文部分是一偏乱码。也就是说,你修改了tcc的源码后,保存的方式并不是用utf8保存的?

qwas982 commented 7 years ago

@swizl
你好,我怎么获得tcc的最新源代码?

swizl commented 7 years ago

@qwas982 网址 http://repo.or.cz/w/tinycc.git 2天前,新的更新tar.gz或zip格式