Idea of a new strong-typed language that will be familiar for JavaScript developers, but with native and crossplatform compilation (hopefully better performance and less runtime/compiler complexity) and zero dependencies if possible (that can run even on older machines). Not targeting web platform for now, but might be considered (using wasm or vanilla js, last one can be tricky). No plans for Mac or embedded for now, possible in future by adding LLVM IR target.
if I wanted to have the nicest language for me, what it would look like? Simple and readable. But runtime also matters, it should be possible to produce native executable for different platforms that will just run (without dependencies of having system library versions or any runtime - if any then make it just as simple as dump to path and config the app to use that path {with possibility to set such path per app!}). Also make it easy to add any syntax sugar, if its just simple replacement rules.
So, is it too hard problem to make such language? I will try and see
- Strong-typed. Increase the benefits of static analysis
- Simple, easy to learn (Not as complicated as rust and c++, but not too simple as go). No macros if possible
- Short and pretty syntax, wihout complication of control flow. No
public abstract static final synchronizedor things likevoid ** (*d) (int &, char **(*)(char *, char **)) - Minimal dependencies
- Mainly focused on native compilation
- Cross-platform
- Extendable language features (including syntax sugar) by extensions. Make it so simple, that every programmer can do it easily
- Multi-paradigm. Procedural, functional, OOP (same capabilities as in JS and TS, maybe with addition of pipe operator
|>)
listed only currently implemented types and features
Int32 - 32-bit integer
Bool - boolean true|false (internally 0 or 1 32-bit integer for now)
int - Int32 type alias
bool - Bool type alias
Immutable by default
int x; // variable declaration
x = 1; // initialization
x = 3; // error
int x2 = 1; // declaration with initialization
let y = 2; // type inferred as intMutable variables
mut int x = 1;
x = 3; // no error
mut y = 2; // type inferred as intBinary math (int, int -> int):
- left
+right - addition - left
-right - subtraction - left
*right - multiplication - left
/right - integer division - left
%right - integer division reminder
Binary bitwise (int, int -> int | bool, bool -> bool):
- left
&right - butwise and - left
|right - butwise or - left
^right - butwise xor (exclusive or)
Binary bitshift (int, int -> int):
- left
>>right - bit shift right - left
<<right - bit shift left
Binary comparison (int, int -> bool | bool, bool -> bool):
- left
==right - bit shift right - left
!=right - bit shift right
(int, int -> int)
- left
<right - less than - left
<=right - less or equal - left
>right - greater than - left
>=right - greater or equal
Unary:
-(int right) - unary minus (negation)+(int right) - unary plus~(int right) - birwise not!(bool right) - boolean not
Assignment binary operators (int, int -> int):
- var
+=right - var
-=right - var
*=right - var
/=right - var
%=right - var
<<=right - var
>>=right
(int, int -> int | bool, bool -> bool)
- var
&=right - var
|=right - var
^=right
Assignment unary operators (int -> int):
- var
++ - var
-- ++var--var
if (x < 0) {
// ...
} else if (x == 0) {
// ...
} else {
// ...
}mut int x = 1;
while (x <= 10) {
x++;
io.print(x);
}for (mut int i in 1..=10) { // including 10
// ...
}
for (mut int i in 1..10) { // excluding 10
// ...
}type i32 = int;
i32 x = 1; // int variable
type Index = i32;
Index x = 3; // also int variable- Math operations with precedence and grouping
- Variables (mutable/immutable)
- Branching and loops (
for,while) - Sinlge line, multi-line comments
- Variables check initialized before use (with consideration of branching)
- Immutable variables check no reassignment, initialized only once (with consideration of branching)
- Type checking (need testing)
- Type inference (need testing)
- Type aliases (need testing)
- Transforming AST and tokens stream by compiler extensions (built-in and custom)
- Dead code removing (uncovered edgecases)
- Compile time const expression evaluation (uncovered edgecases)
- Support for generic types in tokenizer (
<,>,>>tokens not to be confused with operators. tracking if identifier is a declared type name). to better support extensions that consume/transform a stream of tokens
- Update grammar.txt (it's outdated)
- Other primitive types (currently only
intandbool) - Nested multi-line comments (
/* /* ... */ */) - Implement generator for linux fasm and test it
- Type casting (explicit)
- String interpolation
`x = ${x}` -
useoperator for scopes - Modules (imports/exports)
- Number literals syntax (
0xFF,0b0101,1_250_000) - Strings, arrays, objects (structs and/or classes, need research)
- Functions,
Fn<>types, lambdas - Tuple types (as stack or register allocations)
- Generic types support
- Option/Nullable type (
Opt<T>) - Iterators (
Enumerable<T>) - Custom operator definitions
- Refs {probably}
- Built-ins like
Map<K,T>,Set<T>
Built-in:
-
ExtCheckTypesAndVariables
-
ExtEvaluateConstExpressions
-
ExtRemoveDeadCode
Making custom extension:
... todo readme
- Win x86 64-bit (fasm)
- Linux x86 64-bit (fasm)
- Win x86 64-bit (nasm) {probably}
- Linux x86 64-bit (nasm) {probably}
- LLVM IR {probably}
Plugin: https://github.com/NesCafe62/Krypton-intellij-plugin
Alternatively TextMate bundle available (but it will not add file type):
https://github.com/NesCafe62/Krypton-intellij-plugin/tree/main/src/main/resources/bundles/krypton
Requirements:
-
php 7.2 or higher (php used as a temporary language)
-
flat assembly (fasm) util to compile .asm to binary
- Clone the repo
$ cd project-path
$ git clone https://github.com/NesCafe62/Krypton-lang.git .
- Add
phpto system path (optional)
Only windows for now
Set executable and target in Makefile to desired values:
EXECUTABLE = test4
TARGET = fasm-win-x86-64
Compile .kr file to .asm:
$ make compileCompile .asm file to .exe:
$ make compile-exeCompile .kr file to .exe:
$ make buildCompile .kr file to .exe and run it:
$ make allCompile .kr file to .ast:
$ make dump-astClean all compilation files (asm, exe, ast)
$ make cleancompile .kr file to .asm (target = fasm-win-x86-64)
$ php src/index.php test.kr -t fasm-win-x86-64 > test.asmor
$ php src/index.php test.kr --target=fasm-win-x86-64 > test.asmtargets:
- ast
- llvm
- fasm-linux-x86-64
- fasm-win-x86-64
- avr-atmega328
- avr-atmega328-hex
compile .kr file and dump AST with -ast flag
$ php src/index.php test.kr -ast > test.astcompile .kr file and compile to binary using fasm (command for windows)
$ php src/index.php test.kr -t fasm-win-x86-64 > test.asm && fasm.exe test.asm