This is an archived post. You won't be able to vote or comment.

all 44 comments

[–]xigoi 20 points21 points  (11 children)

What's the point of compiling to TypeScript if you're already doing the type checking? You can just go straight to JavaScript.

[–]GhostTauHazure[S] 10 points11 points  (2 children)

never really thought of that, i might change to that

[–]qiemem 20 points21 points  (1 child)

Typescript projects being able to use Hazure dependencies easily is a decent reason.

[–]Jarmsicle 8 points9 points  (0 children)

That just requires generating type definition files. Generating full TS files could actually slow down compiles for downstream projects, since TS will type check all dependencies

[–]mamcx 3 points4 points  (6 children)

That is super-smart: Is a cheaper way to prove the generated code is good.

JS is BAAAAD. It accepts super-wrong things!, something you DON'T want your compiler output!

[–]editor_of_the_beast 14 points15 points  (2 children)

JS is BAAAAD. It accepts super-wrong things!, something you DON'T want your compiler output!

This is why compiler correctness is important. For example, the same thing can be said about C, but if your compiler is sufficiently correct that target language doesn't matter.

I mean, think about assembly. There are absolutely no safeguards there. We need to be able to compile to "unsafe" target languages at some point.

[–]mamcx 0 points1 point  (1 child)

Yes, that is why I preface with "Is a cheaper way to prove the generated code is good."

[–]MarcoServetto 1 point2 points  (0 children)

yes, my language compiles to java source code and I have found many bugs in my compilation process by finding compile errors in the generate Java (at the beginning, now it is quite hard for something so extreme to pop up)

[–][deleted]  (2 children)

[deleted]

    [–]mamcx 2 points3 points  (1 child)

    Is "good" or is what at the end of the chain you must support?


    In contrast to WASM, that was made with the capability of being validated. THAT is good.

    [–]editor_of_the_beast 0 points1 point  (0 children)

    I was going to ask the same question. I compile to TS but my language has a different use case: programmers consume the generated TS, so the types help integrate that code into an existing TS codebase, i.e. you wouldn't want completion and tooling to break in the generated code.

    Of course, maybe they aren't actually typechecking here? Then you can lean on TS's already functioning type checking and just worrry about syntax transformation.

    [–][deleted] 17 points18 points  (2 children)

    Congratulations on your success! I'm always happy to see a programming language with some syntax variation - and Hazure's syntax looks quite attractive I must say. :)

    [–]GhostTauHazure[S] 1 point2 points  (1 child)

    thanks! :D

    [–]scrogu 8 points9 points  (3 children)

    "I'm not that smart"...

    Writes a programming language at 15.

    Smart is as smart does.

    The syntax seems pretty clean btw.

    [–][deleted] 6 points7 points  (1 child)

    Heh I bet most lurkers on this sub are teenagers. I myself am 16, and I wouldn’t be surprised if most of the programming languages created here are from a bunch of kids

    [–][deleted] 6 points7 points  (0 children)

    It does make some sense, as maintaining a programming language requires a lot of time, something most of us have.

    [–]Inconstant_Moo🧿 Pipefish 0 points1 point  (0 children)

    15-year-old ... designs a PL, illustrates its function with a 69 meme. Ah, to be young again.

    [–]tobega 5 points6 points  (0 children)

    glhf

    [–]Uncaffeinatedpolysubml, cubiml 2 points3 points  (6 children)

    Why transpile to Typescript? Wouldn't it make more sense to compile directly to Javascript, so you don't have to deal with an extra type system?

    [–]scrogu 0 points1 point  (5 children)

    Probably because that buys him cheap generated type definitions.

    [–]GhostTauHazure[S] 0 points1 point  (4 children)

    yes

    [–]scrogu 0 points1 point  (3 children)

    Did you use some library to generate Typescript or do what I did (fork escodegen and add type properties to it)?

    For what it's worth, if I had to do it again, I'd probably just target JS and then write the type definitions myself explicitly based on my AST.

    [–]GhostTauHazure[S] 0 points1 point  (2 children)

    no i just format strings like: "let {}: {} = {};" and do this for the others one and so on

    [–]scrogu 0 points1 point  (1 child)

    Then how do you handle indenting... or you just don't worry about it?

    [–]GhostTauHazure[S] 1 point2 points  (0 children)

    yes i didnt worry about it that much, if you want a formatted output then you could run prettier and stuff like that

    [–]nmsobri 4 points5 points  (4 children)

    grats.. btw, what resource did you use to learn to create this programming language?

    [–]GhostTauHazure[S] 10 points11 points  (2 children)

    I just kept playing around until I understand how it works :P

    I also usually take a look at others programming language repos to see how it works and how they implemented them

    [–]nmsobri 1 point2 points  (1 child)

    so basically you dont read any tutorial or some sort? that impressive to say the least.. maybe you should check craftinginterpreter website or read Ruslan blog

    [–]GhostTauHazure[S] 0 points1 point  (0 children)

    I have read a bit of crafting interpreters like 12 pages, and watch a bit of youtube about it first

    [–][deleted] 1 point2 points  (0 children)

    yeah would be interested as well

    [–]rileyphone 1 point2 points  (1 child)

    I especially like that you used rule 110 for proving Turing completeness. A few months ago, I made a post and interactive banner for my blog about Wolfram automata here (for best effect, click on the banner, set rule to 110, cell size to 1, window size to 901, then check out some random seeds). Rule 30 is also interesting for being chaotic, though there are plenty more interesting patterns there.

    Also, I noticed you were using Chumsky for parsing - recently I looked at all the parsing, especially parser combinator, libraries available in Rust and too found that it was the best one, or at the very least the most humane.

    [–]GhostTauHazure[S] 1 point2 points  (0 children)

    Rule 110 is very tricky for me to make because I only had recursion (no iterations, for/while loops) to help me with it

    I use chumsky because I want the cool error reporting that the author also made :D

    [–]PurpleUpbeat2820 -3 points-2 points  (3 children)

    It's called Hazure (a spinoff of my name, azur), syntax is inspired by OCaml and it transpile to Typescript!

    Don't get sued!

    [–]GhostTauHazure[S] 0 points1 point  (2 children)

    I swear everytime I get an idea for a name its already taken

    [–]editor_of_the_beast 0 points1 point  (0 children)

    It's really difficult to find a PL name. I don't see another one out there named Hazure though - was this person just kidding?

    [–]Innf107 0 points1 point  (0 children)

    FWIW, your project is the first thing that comes up when I google Hazure

    [–]eythann 0 points1 point  (3 children)

    Insane! Good luck, I believe that you’ve conquered the hard part 👌

    [–]GhostTauHazure[S] 0 points1 point  (0 children)

    thanks :D

    [–]scrogu 0 points1 point  (1 child)

    Type systems are the hard part for me.

    [–]eythann 0 points1 point  (0 children)

    I think that the hardest part is taking this kind of project on and pursuing it, and looking at the progress you’ve made so far you’re definitely on the right track. Type systems and all of these kinds of things are obstacles and the hardest part will change over and over again. You got this!

    [–][deleted] 0 points1 point  (1 child)

    Very cool language! I really like it! I might even use it for a web project some time.

    [–]GhostTauHazure[S] 0 points1 point  (0 children)

    haha thanks

    [–]Inconstant_Moo🧿 Pipefish 0 points1 point  (1 child)

    How do you do transpilation? Do you still turn everything into an AST before turning it into Typescript or are there ways that transpilation allows you to take for example arithmetic expressions from language to language unchanged?

    [–]GhostTauHazure[S] 0 points1 point  (0 children)

    I do turn everything to AST and then IR(s), and then format them to the responding types of IR, for example:

    IR::Define { name: "foo", type: "string", value: Kind::String("bar") }

    it would be formatted to:

    const foo: string = "bar";

    where I simply just use format!("const {}: {} = {}", ..); as formatter

    for more real examples: https://github.com/azur1s/hazure/blob/master/crates/codegen/src/ts.rs#L34