Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

吾思虑再三,若备一转换之工具,甚美呓。吾之工程,尽为文言呓! #47

Open
bd233 opened this issue Dec 18, 2019 · 11 comments
Labels
related-project Idea/showcase for derived projects

Comments

@bd233
Copy link

bd233 commented Dec 18, 2019

No description provided.

@LingDong-
Copy link
Member

That would be really nice, but would also need a huge amount of work to implement. Think about all the various nuances and tricky details of other languages, and the fact that other languages (especially JavaScript) are constantly evolving themselves. I imagine it could be quite a pain to keep up. Perhaps one day there would be a large enough community of wenyan developers to support this kind of project. I look forward to that day :)

@jeffli678
Copy link

LLVM might be helpful. There is emscripten (https://github.com/emscripten-core/emscripten) which can compile C/C++ to js. Given the simiarlirties between Wenyan and js, it would be possible to translate js to Wenyan.

@yorkie
Copy link

yorkie commented Dec 18, 2019

Given the simiarlirties between Wenyan and js, it would be possible to translate js to Wenyan.

This might be impossible, it's hard to convert the JavaScript to LLVM IR, however the reverse is done.

Thus the LLVM IR to wenyan is meaningful a use case that C/C++ into wenyan, but that won't work for converting JS to wenyan.

@jeffli678
Copy link

jeffli678 commented Dec 18, 2019

@yorkie Let me rephrase: we can convert c/c++ to LLVM IR. And we also know that we can convert LLVM IR to js (using emscripten). Since js shares some similarities with Wenyan, it is possible to modify emscripten and generate Wenyan, instread of js.

I should not have used the word translate js to Wenyan

@yorkie
Copy link

yorkie commented Dec 18, 2019

it would be possible to translate js to Wenyan.

You actually said it as it's possible, aha but never mind :)

And yes, we can output "wenyan" from LLVM IR, IMHO I'm a little bit -1 on this idea, the "wenyan"'s good part is to represent a program in Classical Chinese, that means what a programmer now think about the solution to problems in Classical Chinese language model, I'm very inspired on this part :)

@jeffli678
Copy link

Yep, your idea definitely worths checking out.

I, and the person who starts this thread, wish to compile existing programs to Wenyan. For example, we can have OpenSSL in Wenyan. Then people from 1000 years ago can securely communicate with us. I would say this idea to trans-compile, as well as the Wenyan itself, is more for recreational and research purposes rather than actual usage.

@kaiyuan01
Copy link
Contributor

How about developing a tool to take a JS/Java source code, and explain it in Wen Yan. That will make programming or learning how to programming fun. Users can also learn JS/Java etc at the same time improve their Wenyan.

@hiiwave
Copy link

hiiwave commented Dec 21, 2019

How about developing a tool to take a JS/Java source code, and explain it in Wen Yan. That will make programming or learning how to programming fun. Users can also learn JS/Java etc at the same time improve their Wenyan.

Isn't it exactly what this title suggests?

@zxch3n
Copy link
Contributor

zxch3n commented Dec 23, 2019

@LingDong- I'm working on one. https://github.com/zxch3n/wenyanizer

You can play it online http://zxch3n.github.io/wenyanizer

There are still some basic js grammars that are not parsed correctly. But I'm optimistic 😄. (it has passed all the example tests, where it should compile back the compiled wenyan examples, and has the same output as them)

When making it, I met some obstacles resulting from the current syntax. I hope the incoming specifications will include the following two things.

  1. typeof keyword. For example, a[b] = 3 is hard to implement since in Wenyan Lang index starts from 1. If b is a number, we should index a by b + 1; however, when b is of string type, we should index a by b. Though it can be polyfilled by using data, it will look bad.
  2. this keyword. I really need this one to make things better. But I guess it's a hard problem due to the weird behavior of JS' this.

PS: I guess we need not keep up with the development of JS specifications. We might only need es5, and use babel to compile all the new things down.

@LingDong- LingDong- added the related-project Idea/showcase for derived projects label Dec 24, 2019
@zxch3n
Copy link
Contributor

zxch3n commented Dec 24, 2019

It turns out I can actually use 「this」 directly right now. Though weird, but it works.

Currently, I'm using the following way to make new working.

function A(arg){
    this.arg = arg;
}

const a = new A(123);

=>

吾有一術。名之曰「A」
欲行是術。必先得一物。曰「arg」。
乃行是術曰。
    昔之「this」之「「arg」」者。今「arg」是矣。
是謂「A」之術也。

吾有一術。名之曰「造物」
欲行是術。必先得一物。曰「蓝图」。
乃行是術曰。
    乃得  new 蓝图(...Array.prototype.slice.call(arguments, 1))
是謂「造物」之術也。

施「造物」於「A」。於一百二十三。
名之曰「a」。

@LingDong-
Copy link
Member

@zxch3n . Nice tricks! Glad you figured it out. I think you can also use 今有一數 to generate this.. Hopefully the language will evolve soon enough that we wouldn't need hacks anymore :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
related-project Idea/showcase for derived projects
Projects
None yet
Development

No branches or pull requests

7 participants