3 ms·
Ask HN: Writng a transpiler – What language/runtime should I target?
I'm wanting to design a language (similar to JS/Ocaml/Rust, but which fixes a lot of gripes I have about these), and write a transpiler for it. I am aiming for a transpiler because I just want to innovate in syntax and semantics, not the implementation of those on an actual machine.
*What target language and/or runtime would you recommend?*
With JS there is very little learning curve for me, but I have come to really hate that ecosystem, and I need true concurrency. Ocaml seems elegant, but the language has weird corners, and the tooling is atrocious. Rust seems too unnecessarily dense and lacking cohesion and focus. Other options are wasm, erlang, .net.
BTW, below are some features I am designing for:
- Mostly but not purely functional: Everything is an expression; Pattern matching; Immutability; Result sum type instead of exceptions, etc.
- Functions and types are first class, just like values. No type inference, other than to assume that the type of literal values are themselves as a unit type. For example, x = 2 means just that; there is no assumption that x is a number, or x is a positive integer, etc. So if a function is defined that returns 2, then the return type of the function is not a number, but the unit type [2]. Such unit types can be determined to satisfy or inhabit/satisfy one or more other types.
- Reactivity is built-in at the language level. All mutable state (variables, etc) can be observed and reacted to automatically by the rest of the app.
- Support for use of JSX to express composable function calls built-in (no dependency on React). This is naturally relevant to front-end UIs, but useful for other things as well.
- Syntax can be expressed in any parser-less format: JSX, JSON, XML, Yaml, Toml, and more traditional statement formats that have a simple transformation to/from these formats, with automatic translation between these formats provided by binary and/or language server.
- Avoidance of code coloring problems.
- Localizable keywords, with automatic traslation provided by binary and/or language server.
- Two kinds of files: _Modules_ (Exports only pure/impure functions, constants, and types; No side effects at the module level; Can only import from other modules), and _Activities_ (For doing stuff; May contain invocations, functions, constants, types, etc, but does not export anything).
- Packages are modules shared on the cloud repository. All packages are namespaced. Automatic async lazy imports supported, with pure dependency injection
- pgen 3y agoC?
- prmph 3y agoWhy C in particular?
- deleted 3y ago[deleted]
- sargstuff 3y agoUsing C would tie the run-time/compiled implimentation to specific set of platforms/hardware. aka each hardware platform would have it's own specific compiled C quirks/issues to deal with. aka big endian / little endian; 16/32 bit; etc. A virutal machine is typically what is used when not targeting an actual machine/hardware. aka runtime environment. Transpiling the language to java or webassembly would provide for wider range of hardware/platform support without requiring specific knowlege compiled C platform quirks -- big endian/little endian machine. Although, transpiling to awk with system() & named pipes/netcat, perl, javascript, and/or creating an excell 16 bit cpu[7]/virtual pc could work too. "1st class"[0] concept implies there are no restrictions on where given language construct/concept can be used. for example: which side of the assignment operator a programming language concept/construct can be used. "type inference"[1] is typically an interpreted/virtual machine language feature. aka C++ run time type inference (rtti) is done via instance of a virtual machine. namespace / scoping is important aspect of modularity / avoiding code coloring issues / automatic translation between formats / 'reactivity'[2] XL[3], oils/ysh[4], unicorn[5]/unicorn.js[6], awkgo[8], pawk[9] might be of interest. Would suggest using ' JS/Ocaml/Rust' implimented/running under python (and/or bindings to ocaml/rust). A related example/demo of this approach would be awk running under go[8] or python[9]. This approach would make it bit easier to experiement with doing modifications/customizations/extensions to 'js/ocaml/rust'. Permits leveraging things that have already been written. aka editors/debuggers/graphics libraries etc. Instead of going the 'super' environment, gawk extentions/additions to awk take the extend the 'sub-environment' direction[10] via extensions support for c/c++ ---- [0] : https://medium.com/ryanjang-devnotes/who-is-first-class-citizen-in-programming-world-b92c67b32635 https://medium.com/ryanjang-devnotes/who-is-first-class-citi... [1] : https://en.wikipedia.org/wiki/Type_inference https://en.wikipedia.org/wiki/Type_inference [2] : https://www.linkedin.com/pulse/reactive-programming-principles-explained-luis-soares-m-sc- https://www.linkedin.com/pulse/reactive-programming-principl... [3] : https://xlr.sourceforge.io/ https://xlr.sourceforge.io/ [4] : https://www.oilshell.org/ https://www.oilshell.org/ [5] : http://www.unicon.org/ http://www.unicon.org/ [6] : https://alexaltea.github.io/unicorn.js/ https://alexaltea.github.io/unicorn.js/ [7] : https://github.com/InkboxSoftware/excelCPU https://github.com/InkboxSoftware/excelCPU [8] : https://benhoyt.com/writings/goawk/ https://benhoyt.com/writings/goawk/ [9] : https://github.com/alecthomas/pawk https://github.com/alecthomas/pawk [10] : https://www.gnu.org/software/gawk/manual/html_node/Dynamic-Extensions.html https://www.gnu.org/software/gawk/manual/html_node/Dynamic-E...
- sargstuff 3y agoAlternate interpretation of topic: On the strictly theory side, changing c source code to fortran source code in an automated/direct 1:1 transform would involve using bnf/ebnf definition of c language and defining how that corresponds to the equivalent enbf/ebnf definition of fortran or parser combinator[3]. Fortran language bindings to be able to use C inside of a fortran program bit easier to manage. BFNC can generate a compiler from bnf/ebnf definition.[1] So, mess around with c as subset of python till get bnf/ebnf grammar that corresponds to bnf/enbf fortran. Convert the aforementioned C subset to fortran program into ebnf/bnf format. use bnfc[1][2] to create a compilter that will transform c source code into fortran source code. ---- compiling vs. transpiling: https://crystallize.com/answers/tech-dev/compiling-vs-transpiling https://crystallize.com/answers/tech-dev/compiling-vs-transp... [1] : https://bnfc.digitalgrammars.com/ https://bnfc.digitalgrammars.com/ [2] : https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=171c79e76f9056675496a69f622917bd0c623983 https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&d... [3] : https://en.wikipedia.org/wiki/Parser_combinator https://en.wikipedia.org/wiki/Parser_combinator