A safe & fast low-level language.
Dependencies: Make, GCC (can also work with other compilers like Clang or TCC)
Contact: Emmanouil (Manios) Krasanakis
License: Apache 2.0
Here's what smoλ programs look like. Syntax is indentation-based.
deffunctions are inlined and could fail. Results are treated as both tuples and types.servicefunctions safely deallocate resources on internal failure (e.g., of called def or other services). Result errors can be checked or -if not- cascade into more failures.newreferences types by name for safety (aka nominal typing).@onautomatically add as first argument (even before currying).@mut, if prepended to the first declaration of a variable, indicates values that may change..is element access, or passes the left-hand-side as the first argument into functions ("currying"). Currying into a loop passes the value into first call in the condition; in this casenext(@mut chunks, @mut str)is called to progress the iteration.
@include std.core
@include std.mem
@include std.file
def Stats(
new, // new type (prevents structural matching)
u64 lines,
u64 chars
)
return @args // return all inputs
def print(file_stats stats)
// @all to reduce the expression with printin (print without \n ending)
// no commas in this syntax makes it our string interpolation
printin(@all stats.lines" lines, "stats.chars" bytes\n")
def file_reader(String path, @mut Memory memory) // for all String variations
@mut stat_lines = 0
@mut stat_chars = 0
@mut file = ReadFile.open(path) // pass the ReadFile type as first argument
endl = "\n".str().first
@on memory.allocate(1.KB()).arena()
file
.while next_line(@mut str line)
stat_lines = stat_lines + 1
stat_chars = stat_chars + line:len
printin("| ")
print(line)
return new.Stats(stat_lines, stat_chars)
service main()
@mut memory = Stack.allocate(1.MB()).arena()
stats = file_reader("README.md", memory)
print(stats)Different parts of this codebase are governed by different licenses:
- std/: CC0
- Prism.js: MIT License (see
vendor/prism/LICENSE) - Everything else: Apache2.0
