MCPcopy Index your code
hub / github.com/NICUP14/MiniLang

github.com/NICUP14/MiniLang @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
589 symbols 1,999 edges 41 files 145 documented · 25%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

MiniLang

[!WARNING] The development of the project has stopped due to memory and thread safety concers. Chain, the philosophical successor of MiniLang is here to take its place. It's been designed from scratch to offer safety guarantees comparable to Rust, while retaining safe ergonomics thanks to its revolutionary pointer semantics. Stay tuned, Chain will soon be available on github!

A type-safe C successor that compiles directly to various platforms.

Check out acwj-git, DoctorWkt's tutorial is the main (best) source of inspiration of this project's structure.

QuickStart

Design choices

  • Modern
  • Compiled
  • Procedural
  • Strongly typed
  • ~~Type and memory safe~~
  • Closely match C features
  • Bidirectionally compatible with C
  • ML must be easy to learn and use
  • ML abstractions introduce zero-overhead compared to C

Motivation

The language is designed to closely match c features along with some zero-overhead quality of life improvements that you would find in a modern language, while maintaining the ease of learning the language (in about 10 minutes or less via QUICKSTART). Moreover, the type system is stricter than c, which prevents common bugs (flaws) of the c language. ~~Memory safety is also a primary concern~~. As for c compatibility, the language is bidirectionally compatible with c (c can be used in ML, ML can be used in c).

Goodies

Online compiler

The online compiler is provided by ryugod.com. Special thanks to ryusatgat for hosting and maintaining the online compiler!

Branches

[!WARNING] The unstable branch is updated more often than the main (stable) branch and offers access to experimental features, but is more prone to breakage/bugs.

Links

To suggest features/fixes, modify IDEAS.md/BUG.md and submit a pull request or contact me via the email address in my github profile.

Syntax highlighter (VSCode)

Install the VSIX extension ./minilang-highlighter/minilang-highlighter-0.0.1.vsix.

Extensions -> Views and more actions... (top-left three dots) -> Install from VSIX...

Manage ML projects

Running samples and tests

To run a sample or test, specify its directory using the -C option in mlpx with arguments build and run.

python mlpx -C tests/test build and run

Creating projects

[!IMPORTANT] It's recommended to use the mlpx build tool as it's specifically designed for this purpose: no libary redundancy and no configuration compared to using the make build tool.

Creating a MiniLang project is easy and straight-forward using the mlpx utility, which provides two ways with differing build tools.

# Using the mlpx build tool
python mlpx init my_new_project

# Using the make build tool
python mlpx makefile-init my_new_project

Build tools

Code statistics

----------------------------------------------------------------------------------------        
File                                      blank        comment           code
----------------------------------------------------------------------------------------        
src\Parser.py                               482             92           1846
src\Def.py                                  320             74           1108
src\Gen.py                                  217            134            697
src\Lexer.py                                 43              1            351
src\backend\c\CWalker.py                     25             17            203
src\backend\ml\MLWalker.py                   18              6            179
src\backend\c\CDef.py                        50              1            155
src\GenStr.py                                16              1            129
src\Snippet.py                               38              0            106
src\Main.py                                  14              2             79
src\backend\ml\MLDef.py                      14              2             56
src\backend\Walker.py                        16              3             53
----------------------------------------------------------------------------------------        
SUM:                                       1253            333           4962
----------------------------------------------------------------------------------------

[!NOTE] Statistics were generated with cloc.

Usage

[!WARNING] The asm compiler backend is currently far outdated. The latest features exclusively require the c and ml compiler backends.

Usage: Main.py [options]

The mini language compiler, Version: 1.0.0, Source:
https://github.com/NICUP14/MiniLang.git

Options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output=OUTPUT
                        Write contents to OUTPUT; When set, no-color is        
                        enabled by default.
  -d, --debug           Dry run; Print the human-friendly AST representation.  
                        Overrides any specified backend option.
  -c, --no-color        Do not use ANSI color sequences in the output.
  -C, --no-comment      Do not include human-readable comments in the
                        generated assembly.
  -I INCLUDE, --include=INCLUDE
                        Add the directory to the include path.
  -b BACKEND, --backend=BACKEND
                        Specify which compiler backend to use. Choose between  
                        c, asm and ml.

Samples

[!NOTE] All MiniLang samples (example projects) are located within the samples directory. All samples are written entirely in ML.

Hello World

# From samples/helloworld/src/main.ml:
import stdlib.io.print

fun main: int32
    print "Hello World!"
    ret 0
end

String (UFCS)

# From samples/str-ufcs/src/main.ml:
import stdlib.io.print
import stdlib.string

fun main: int32
    # Is equivalent to:
    # print(concat(str("Hello "), str("World!")))
    (str("Hello ").
        concat(str("World!")).
        print)
end

FizzBuzz

# From samples/fizzbuzz/src/main.ml:
import stdlib.io.print

fun fizz_buzz(num: int64): void
    let idx = 1

    while idx <= num
        if idx % 15 == 0
            println(idx, ": FizzBuzz")
        elif idx % 3 == 0
            println(idx, ": Fizzz")
        elif idx % 5 == 0
            println(idx, ": Buzz")
        end

        idx = idx + 1
    end
end

fun main(): int64
    fizz_buzz(15)
    ret 0
end

License

Copyright © 2023-2024 Nicolae Petri

Licensed under the MIT License.

Core symbols most depended-on inside this repo

print_error
called by 162
src/Def.py
color_str
called by 76
src/Def.py
add_arg
called by 68
src/Snippet.py
print_stdout
called by 54
src/Def.py
rev_type_of
called by 54
src/Def.py
curr_token
called by 51
src/Parser.py
copy_of
called by 47
src/Snippet.py
asm
called by 45
src/Snippet.py

Shape

Function 418
Method 94
Class 77

Languages

C49%
Python44%
C++7%

Modules by API surface

src/Def.py98 symbols
src/Parser.py72 symbols
tests/aoc-2022/day-2/include/sds.c50 symbols
tests/aoc-2022/day-1/include/sds.c50 symbols
skel/include/sds.c50 symbols
tests/aoc-2022/day-2/include/gc.c41 symbols
tests/aoc-2022/day-1/include/gc.c41 symbols
skel/include/gc.c41 symbols
src/Gen.py29 symbols
src/Lexer.py19 symbols
tests/aoc-2022/day-2/include/sds.h11 symbols
tests/aoc-2022/day-1/include/sds.h11 symbols

For agents

$ claude mcp add MiniLang \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact