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

Transpiler? #3

Open
drom opened this issue Jan 1, 2020 · 6 comments
Open

Transpiler? #3

drom opened this issue Jan 1, 2020 · 6 comments

Comments

@drom
Copy link

drom commented Jan 1, 2020

Would it be difficult to emit equivalent JavaScript after parsing TCL?

@cyanogilvie
Copy link
Owner

cyanogilvie commented Jan 2, 2020 via email

@drom
Copy link
Author

drom commented Jan 3, 2020

I understand, that there will be corner cases, but I was thinking about something like this: https://github.com/drom/tcl/blob/master/examples.md

@cyanogilvie
Copy link
Owner

cyanogilvie commented Jan 3, 2020 via email

@drom
Copy link
Author

drom commented Jan 3, 2020

What you would get would look nothing like that, and couldn't - since Tcl requires that some things block and JavaScript forbids it. So the execution engine used in Tcl.js used a continuation passing trampoline approach.

Could elaborate on it? Give some example?

The result would be as alien to read in JavaScript as the machine code is that is generated by a modern compiler from c is.

Generated JavaScript does not need to be too pretty from the start. We can work later to prettify some safe cases.

It would be possible to "translate" some toy subset of Tcl to meaningful JavaScript code, but only by giving up any pretense of actually being proper Tcl.

The code needs to behave as proper TCL.

The approach used by some of the JavaScript implementations of Tcl of converting Tcl expressions to equivalent JavaScript ones runs into many incompatible behaviors for instance. Think about exceptions, numeric range considerations, the fact that JavaScript doesn't actually have integers, Tclish coercion of certain strings to Boolean values, and many others.

For numbers, JS has no problem with INT32, UINT32, F64, F32 if properly annotated. http://asmjs.org/spec/latest/#annotations

For exceptions. We can construct source map from TCL to JS, catch JS exception and report it in TCL style.

For coercion, what if we replace TCL operators with JS function calls?

@cyanogilvie
Copy link
Owner

You'll need to work through the way the execution engine works to understand why this is a bad fit. You could just use the parser and then attempt to transpile some subset of the language, but working with the output of the parser is a bit nasty (it's optimised for speed rather ease of use). Take a look at demos/parser.html for an example of how to interact with the parser, and to view a marked-up version of the parser output for a given script.

@rbucker
Copy link

rbucker commented Aug 22, 2020

what would be the point of transpiling? The implementation offers a number procs that depend down on tcl and js code... see registered(). Then the transpiled code shims the functions back and forth and like he said it's a mess. There is no upside. However, if your issue is speed... maybe testing with webassembly.

This is a great project idea. I have been working on something similar with golang and Picol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants