Sea (a compiled language)
fuzzyastrocat (663)

Hello everyone! This is my first post, so if it's boring I apologize :D

Just wanted to share a little compiled language I made called Sea. It's called Sea because, well, Sea shares many things in common with C. I chose C to mimic because this was my first compiled language — given that C is so low-level, I figured I wouldn't have to do too much work translating to x86.

A quick overview of the language

In case any of you want to try it out, here's a quick overview of the syntax/semantics.

To start, we'll take the simple "hello, world" program:

    import "stdlib.sea";
    int function main {
            println("Hello, world!");
            0;
    }

Here we immediately see a few differences between C and Sea:

  • Import is not a preprocessor routine, it's a keyword
  • Functions are defined as <type> function <name>
  • Functions automatically return their last expression — to suppress this, the last expression can be void;
  • Arguments in functions are declared differently — instead of putting arguments between parentheses, they are written as null declarations on the following line:
    int function my_function
            int my_arg_1;
            int my_arg_2;
    {
            // some code
     }

Control flow (if, else, while) is implemented as a "postfix operator":

    1 == 2
            :then {
                    println("Whoa, math broke"); // And no, this won't get printed :D
            }

A for-loop can be emulated with a block scope and a while:

    {int i = 0; i < 5
            :while {
                    printf("%d", i);
                    i++;
            }}

These control flow constructs can be extended — an excerpt taken from the stdlib:

    int::isZero {
        $int
            :else {
                $();
            }
    }

$int represents the int in question, and $() represents execution of the block given to the control statement. We could "call" this like so:

    0
         :isZero {
                 println("Hey math works again!");
         }

Sea has support for ints, chars, pointers, strings (char*), and moderate support for floats. If you want to see more about the language, peruse stdlib.sea and the tests (and oldtests, though some of those are outdated) folders in the repl.

EDIT: stdlib.sea uses what might be a confusing doc notation, so let me explain that here.

Comments

Sea comments behave just like C comments:

    // This
    /* will
        not
        be
    */ // Evaluated

However, there is a doc notation (used by SeaLib to generate simple HTML docs for a file). It is the following:

    [[[header]]]
    The header must be the first line of the file (outside of line or block comments).  It gives  a description of the file to follow. // This line is the file info

    [[your_function]] // Descriptor doc — gives info about a function
    A cool function I just wrote for demo purposes

    void function your_function {
            println("Hello, world!");
    }

    // Add more functions with their descriptor docs

SeaLib translates that to the following:

And yes, that file would actually run (aside from saying "entry point main is not defined"). Doc headers are ignored (along with the line after) just like normal comments.

Future

"That's neat — but why are you posting it here right now?"

Unfortunately, I'm going to abandon Sea (in favor of a newer language, Curta). Why? Two things:

  • As the language became more complex, I noticed a few things I had done not-quite-nicely in the compiler were becoming difficult to manage. I was faced with either using bad tools or buying (re-coding) new tools.
  • I was actually wrong about translating from a C-like language to x86 being easy. While the actual conversions themselves are not difficult, finding the proper x86 commands can be very difficult! For instance, there is no power function for the SSE floating point system — and all the tools I needed to make a power function were either nonexistent or difficult to implement.

So Sea will probably remain in its current state [for the rest of time].

In the aforementioned newer language (Curta), I am learning from my mistakes — it will compile to C++, with the added benefit that it will work on some embedded systems (most notably the Arduino). Stay tuned!

EDIT: Curta is now here: https://repl.it/talk/challenge/Curta-Lets-make-hard-things-easy/51820

You are viewing a single comment. View All
Highwayman (1358)

This is sick! I was trying to make a Lang, but I got a bit confused the minute I hit parsing which is embarrassing, ngl.
Anyways.
Cant wait for Curta!

fuzzyastrocat (663)

@Highwayman Thanks! I'm considering making a "HOWTO: compiled languages" tutorial (no guarantees though).
Also thanks! I'm progressing much faster with it since C++ is an easier intermediate representation — so it should be done [relatively] soon!

Highwayman (1358)

Oo noice, is Curta like an entirely new language, syntax and everything, or is it like Sea2.0? @fuzzyastrocat

fuzzyastrocat (663)

@Highwayman Mostly new. I'm pulling the ideas I liked from Sea into the new language though, so it won't be 100% different.

Highwayman (1358)

Cool.. I bet the doc format you had is going in..? :P @fuzzyastrocat

fuzzyastrocat (663)

@Highwayman Yep!
That isn't the only thing though — but I'll leave it a secret until Curta is done :D

Highwayman (1358)

Makes sense, it looks somewhat convenient. Reminds me of D. Someone posted a tutorial about it and it has a sort of thing like Sealib where you can just insert you docs into the code. Pretty cool stuff there XP.
What went wrong with the Sea compiler? @fuzzyastrocat

fuzzyastrocat (663)

@Highwayman Nice! Yeah, I think more languages need a system for easy documentation embedded in the code.
Well, the way it was constructed I was using many variables to keep track of compiler state (rather than using immutable types and keeping state locally via function calls). It's a bit difficult to explain, but it started to hinder me a bit. Additionally, the parser error system was not well-constructed, so sometimes errors would be very misleading.
So nothing went objectively wrong, it's just that I'm going to do things a bit differently the second time around.

Highwayman (1358)

Ahh I think I kinda get what your saying.. so like it was just a bit disorganized it sounds....? Huh. @fuzzyastrocat

fuzzyastrocat (663)

@Highwayman Hindsight is 20/20 :D Looking back, yes it was not the most "clean" approach. Though that was certainly the less-impactful of the two problems (the x86 translation part was what initially motivated the abandonment of Sea).

Highwayman (1358)

Definitely lol. I really enjoy redoing old projects cause of that ye.
Ah yeah how you were saying that the stuff was hard to find oh yeah.
@fuzzyastrocat

fuzzyastrocat (663)

@Highwayman Hey! Since you were interested in Curta, here's the link: https://repl.it/talk/challenge/Curta-Lets-make-hard-things-easy/51820
It's still in development but I've gotten it to a state where it can be used for actual purposes.