Facilis - A Low Level Functional Language
h
CSharpIsGud (639)

Facilis is a strongly typed functional language that aims to be low level. Facilis uses a hand-written recursive descent parser made with love.

Factorial Example

impure foreign putchar(c of u8) -> void
impure foreign tostr(num of void*) -> string

impure write(str of string, start of i32) -> void {
	putchar(str[start])

	if start != str.length() {
		write(str, start + 1)
	}
}

pure fact(i of i32) -> i32 {
	if i == 1 {
		return i
	}

	return i * fact(i - 1)
}

impure main() -> i32 {
    write(tostr(fact(6)), 0)
}

Demo: https://repl.it/@Facilislang/FacilisDemo#README.md
^ Has a user/password login program loaded by default. Read the README!

Source: https://repl.it/@Facilislang/Facilis
^ 2072 lines of C++!

@CSharpIsGud @Subarashi @xxpertHacker

You are viewing a single comment. View All
DynamicSquid (4350)

why are we using all caps in an enum with a non-capitalized enum name?

I like that question xD

xxpertHacker (477)

@DynamicSquid Wait what, you aren't supposed to actually check the source code! Lol, no one else at Repl.it does at least. Good luck understanding that stuff.

DynamicSquid (4350)

@xxpertHacker lol. I just find it really interesting since it's in C++ and I could something. And it's not that messy

DynamicSquid (4350)

@xxpertHacker quick question, so when you compiled your language, you translated your language's syntax into C++ code in the out.cpp file, and compiled that with bash?

xxpertHacker (477)

@DynamicSquid We actually accept command line arguments, we just passed "out.cpp" as the output file, but yeah, we used a bit of Bash, we could've changed it to pure C++, but it's not easy to query the system and execute other code in a portable simple fashion. In a way we just took the easy way out, also, you can hand tune the output or check it for bugs yourself, since our implementation is still pretty buggy.

DynamicSquid (4350)

@xxpertHacker oh okay. I'v never done any compiled language stuff before so all this is really interesting. so basically a compiled language turns your language's syntax into lower level code?

xxpertHacker (477)

@DynamicSquid It's not an actual compiler, it's merely a transpiler, but if we win and are asked to update it for the next 3 months, we might end up using LLVM, or just fixing all of the bugs and making it more real.

It could very well become its own language independent from C/C++, once we create a proper module system, a foreign function interface (FFI), scope checking, types, type checking, new operations, etc.

But for the time being, it's actually just a transpiler.

DynamicSquid (4350)

@xxpertHacker I see... but I heard that a compiler translates source code to a lower level, so in this case, would it have to translate to Assembly for it to be an actual compiler?

fuzzyastrocat (1210)

@DynamicSquid That is the general consensus, yes. Some people consider compiling to C (or a C-like language such as C++, C--) a "true" compiler as well, but others don't. (I do, since if you compile to C the C just compiles to x86, so you're basically compiling to x86 with two steps. If you don't consider this a true compiler, then Haskell is not compiled.)

DynamicSquid (4350)

@fuzzyastrocat wait did you just say C minus minus?????? oh okay. for your language "Sea", you compiled to Assembly?

DynamicSquid (4350)

@fuzzyastrocat so you had to learn assembly?

fuzzyastrocat (1210)

@DynamicSquid :D

It takes dedication, but it's not impossible.

DynamicSquid (4350)

@fuzzyastrocat yuck. how do you run it? the file extension is .s, right?

fuzzyastrocat (1210)

@DynamicSquid Running it depends on the assembly "flavor". There are two main flavors of assembly:

  • Intel: This is the most common one. It is the thing you'll see a bunch on StackOverflow. (For some examples of what it looks like, so that I don't have to explain it, look here).
  • AT&T: This one is far less common, but I like it better. It's also used by the gcc C compiler by default. Some examples of what AT&T looks like
    can be found here.

To run AT&T, use gcc [filename].s -o ./out. That will make an executable, ./out, which can be run through the shell by simply typing ./out.

To run Intel, you have to get something like nasm. I won't go over that here, you can probably find it online by a google search (I'm not super experienced with nasm either so google will probably explain it better).

fuzzyastrocat (1210)

@DynamicSquid I may also stand corrected — I'm attempting to run Intel with gcc right now, so I'll get back to you if it's possible.

fuzzyastrocat (1210)

@DynamicSquid I can't seem to find a way to do it but it may be possible in different environments. (The internet claims that adding the -masm=intel option to GCC works, but it didn't in my test.) So for all intents and purposes
Intel does require something like nasm, and also uses the file extension .asm.

For more about the differences, Wikipedia has a good comparison. There's also this which gives a shorter overview.

fuzzyastrocat (1210)

@DynamicSquid One last thing: In my opinion a compiler might not be the best way to learn assembly — first it might be best to learn some basics (using an external tutorial), then try making the compiler. The thing about assembly is that it's not super hard to learn the syntax (so learning the basics should be easy), but finding the right commands (and semantics) can be hard (the command set is fairly large and documentation can be hard to find for some commands).

DynamicSquid (4350)

@fuzzyastrocat yeah, that was what I was planning to do, but I think for now I'm going to stick to transpiled languages first

fuzzyastrocat (1210)

@DynamicSquid Transpiling is a great way to learn the how of a compiler without the nitty-gritty what. So yeah, if you do a transpiler and then learn assembly it should all kinda "come together"*.

* "coming together" not guaranteed. You know what they say about theory and practice... :D
fuzzyastrocat (1210)

@DynamicSquid The only true way to lol and have a smiley is to lol with smileys :D

    :D         :D :D :D   :D
    :D         :D    :D   :D
    :D :D :D   :D :D :D   :D :D :D
xxpertHacker (477)

@DynamicSquid Often times directly to binary. Either way, it just has to compiled from every high-level, abstract language, into instructions that show how the machine works, oftentimes those instructions should be executable.
Ideally, Facilis is without external dependencies, unlike what we have done here, compilation should be one single step from the user's point of view, but I guess we can just document that somewhere.