Hacker Lang
Interpretowany język programowania dla HackerOS.
Własna składnia operatorowa · Bytecode + Cranelift · Manager pakietów bit · Gen 2
Czym jest Hacker Lang?
Hacker Lang (HL) to interpretowany język programowania napisany w Rust, natywny język skryptowy HackerOS. Pliki źródłowe mają rozszerzenie .hl, skompilowany bytecode — .bc.
%: typ, arytmetyka $(), pipe do zmiennej |>, for-in @ item in, while ?~, switch ? switch, HackerOS API ||, goroutines z nazwą :* nazwa def, manager pakietów bit z progress barem.
Dostępność
hl i manager bit są częścią systemu.hl version bit
Szybki start
#!/usr/bin/env hl /// Mój pierwszy skrypt using <gen 2> // curl # <main/colors> % name: str = HackerOS % count: int = 42 $( @count * 2 ) -> @doubled ~> Witaj w @name! count=@count doubled=@doubled > uname -r |> @kernel ~> Kernel: @kernel @ tool in curl git python3 ::which @tool ? ok ::green ✓ @tool done done
hl hello.hl # uruchom hl compile hello.hl # → hello.bc (bytecode) hl compile hello.bc # → binarka ELF ./hello.bc # uruchom .bc bezpośrednio hl repl # REPL interaktywny
Shebang
#!/usr/bin/env hl # .hl — zalecana forma #!/usr/bin/hl # bezpośrednia ścieżka #!/usr/bin/env -S /usr/bin/hl run # .bc — auto-dodawany
System Genów
Geny to odpowiednik Rust editions. Gen 2 jest domyślny — pliki bez using dostają gen 2.
using <gen 2> # domyślny using <gen 1> # kompatybilność wsteczna
| Gen | Status | Co zawiera |
|---|---|---|
| gen 1 | aktywny | & *> _N << :* :** *-- — podstawowa składnia |
| gen 2 | domyślny | %: typ $() |> @ in ?~ ? switch || — typowanie, pętle, switch, HackerOS API |
| gen 3 | plan | Domknięcia (planowane) |
Print — ~>
> echo tekst generuje błąd. Użyj ~> tekst.~> Zwykły tekst ~> Zmienna: @name ~> Wynik: @count doubled=@doubled
Quick-funkcje — ::
Komendy — > ^> ->
Zwykłe wykonanie.
Sudo.
Izolacja namespace.
Sudo + izolacja.
Z interpolacją zmiennych.
Interpolacja + sudo.
Tło — &
& python3 -m http.server 8080 & redis-server --port 6379 ~> Serwer PID: @_bg_pid ;; Równoległy download & wget -q https://example.com/a.zip & wget -q https://example.com/b.zip
Hsh — *>
Operator *> uruchamia komendę przez hsh -c — autorską powłokę HackerOS. echo jest dozwolone wewnątrz *>.
*> uname -a *> notify-send "Gotowe" ;; Brak interpolacji @zmiennych — użyj >> dla zmiennych
Pętla _N
_10 > hacker update _5 ~> powtorzenie! _3 ::green OK
Goroutines — :*
:** wyniki ;; zadeklaruj kanał :* scanner def ;; goroutine z nazwą (gen 2) >> nmap -sn 192.168.1.0/24 *-- wyniki done :* ;; anonimowa (gen 1) > jakies_zadanie done *-- wyniki ;; odbierz z kanału
Import pliku — <<
<< utils.hl << config.hl | produkcja ;; detal → @_import_detail
Typowane zmienne — %: typ (gen 2)
% count: int = 42 % score: float = 3.14 % label: str = hello world % active: bool = true % x: int = $( @count * 2 ) ;; arytmetyka jako wartość % name = bez_typu ;; gen 1 — nadal działa
Arytmetyka — $( ) (gen 2)
$( 2 + 2 ) -> @res $( 10 * @count ) -> @mul $( @a + @b ) -> @sum $( (2 + 3) * 4 ) -> @paren $( 100 / @cores ) -> @per_core % threads: int = $( @cores * 2 )
sh -c 'echo $(( expr ))'. Obsługuje wszystkie operatory shell: + - * / % ** << >>.Pipe do zmiennej — |> (gen 2)
> hostname |> @host > uname -r |> @kernel > date +%Y-%m-%d |> @today > id -un |> @user > nproc |> @cores ^> id -u |> @uid ;; sudo pipe ~> Host: @host | Kernel: @kernel
For-in — @ item in (gen 2)
@ tool in curl git python3 ::which @tool ? ok ::green ✓ @tool done done ;; Ze zmiennej (ważne: ścieżki z / muszą być w zmiennej) % dirs = "/tmp /etc /usr" @ d in @dirs ~> @d done
/ należy umieszczać w zmiennej (% dirs = "/tmp /etc"), a nie bezpośrednio w @ item in.While — ?~ (gen 2)
% i: int = 0 ?~ @i < 10 $( @i + 1 ) -> @i ~> iteracja: @i done ;; Operatory: == != < > <= >= ?~ @status == running ~> działa... done
Switch — ? switch (gen 2)
? switch @os | linux ::green Linux! | windows ::yellow Windows! | * ~> Nieznany: @os done ;; Z dynamiczną wartością > uname -s |> @detected ? switch @detected | Linux ::green Linux! | * ~> @detected done
HackerOS API — || (gen 2)
Operator || wywołuje natywne narzędzia HackerOS bezpośrednio.
|| hacker update || hpkg install nmap || lpm list || hsh -c "ls /tmp" || H# --version || Blue-Environment start || hackeros-steam launch
Dostępne: H# hco hacker hsh hpkg Blue-Environment hnm hpm hedit ngt eiq getit hdev anvil a hbuild lpm chker isolator hackeros-steam ulb gameframe hup hackeros-builder
Zmienne — % i @
| Zmienna | Wartość |
|---|---|
| @HL_VERSION | gen 2 |
| @HL_OS | HackerOS/Debian |
| @HL_GEN | 2 |
| @HL_SCRIPT | ścieżka do bieżącego skryptu |
| @_bg_pid | PID ostatniego procesu w tle (&) |
| @_import_detail | detal z << plik.hl | detal |
| @argc, @arg0… | argumenty skryptu |
Export — =>
=> EDITOR = nvim => GOPATH = /home/hacker/go => PATH [ | /usr/local/bin | /usr/bin | /usr/lib/HackerOS ]
Funkcje — : i --
: audit def ~> Skanowanie @target... >> nmap -sV @target ? ok ::green Skan OK. done done -- audit
Warunki — ? ok / ? err
> ping -c 1 192.168.1.1 ? ok ::green Online ✓ done ? err ::red Offline ✗ done
Zależności — //
// nmap // curl // git
Biblioteki — #
# <main/net> ;; NET_LOCALHOST, NET_MYIP, porty... # <main/fs> ;; FS_HOME, FS_TMP... # <main/sys> ;; SYS_ARCH, SYS_KERNEL, SYS_OS... # <main/str> ;; STR_* stałe + funkcje str_* # <main/crypto> ;; sha256, md5, base64 # <main/colors> ;; COLOR_RED, COLOR_GREEN... # <main/cli> ;; CLI_ARGC, CLI_ARG0... # <main/progress-bar> ;; pb_draw, pb_done, pb_label # <main/json> ;; json_get, json_validate... # <main/hk-parser> ;; parser .hk (HackerOS Config) # <main/hacker> ;; parser .hacker v1/v2/v3 # <bit/hashlib> ;; bit — .so # <github/user/repo> ;; GitHub ;; Kompatybilność wsteczna (automatycznie normalizowane): ;; # <std/net> → main/net # <virus/x> → bit/x # <community/u/r> → github/u/r
Biblioteki main/ to pliki .hl w /usr/lib/HackerOS/Hacker-Lang/main-libs/ — nie wbudowane w binkarkę.
Manager pakietów — bit
bit # auto: uruchom/skompiluj projekt bit install hashlib # zainstaluj pakiet bit remove hashlib # usuń pakiet bit list # lista dostępnych bit update # zaktualizuj listę bit info hashlib # info o pakiecie bit help # pomoc
[->.................] [1%] [---->..............] [10%] [---------->........] [50%] [-------------------->] [100%]
Projekt mode — bit
bit → uruchamia interpretowalnie przez hl run run.hl
bit → kompiluje do bc/elf/so wg BIT_BUILD_TARGET
bit → kompiluje cały katalog (rust-like)
using <gen 2> % BIT_BUILD_TARGET = elf ;; bc | elf | so % BIT_BUILD_INPUT = main.hl
.cache/ tworzony automatycznie i usuwany po zakończeniu — izolowane środowisko.CLI — hl
hl plik.hl # uruchom skrypt hl run plik.hl # jawna forma hl run plik.bc # uruchom bytecode hl compile plik.hl # → plik.bc hl compile plik.bc # → binarka ELF hl compile --shared plik.bc # → .so hl check plik.hl # linter + składnia hl check --meta plik.hl # + gen + shebang hl ast plik.hl # AST jako JSON hl repl # REPL interaktywny hl shell # HL jako powłoka hl exec nazwa # skrypt systemowy hl search fraza # szukaj skryptów hl gen-info plik.hl # gen + shebang hl docs # dokumentacja TUI hl version # wersja hl -c "~> Hej!" # kod inline
Kompilacja — .hl → .bc → ELF
Parsuj, serializuj AST do JSON bytecode. Plik .bc ma shebang i jest wykonywalny.
Wczytaj .bc, lower → Cranelift → C runtime → binarka ELF x86_64.
hl compile skrypt.hl # → skrypt.bc (bytecode) ./skrypt.bc # uruchom bezpośrednio hl compile skrypt.bc # → skrypt (ELF) ./skrypt # uruchom binkarkę
hl exec i hl search
hl search all # wszystkie skrypty hl search update # szukaj hl exec update-system # uruchom
Powłoka
using <gen 2> => EDITOR = nvim => PATH [ | /usr/local/bin | /usr/bin | /usr/lib/HackerOS ] : ll def > ls -la done
Diagnostyka i linter
error: `echo` jest zabronione w blokach komend HL --> skrypt.hl:5:1 5 │ > echo hello ^^^^^^^^^^^ help: zamień na: `~> hello` warning: `> sudo cmd` — użyj `^>` --> skrypt.hl:8:1 help: zamień na: `^> cmd`
Przykłady — Gen 1 podstawy
#!/usr/bin/env hl /// Aktualizacja systemu HackerOS : aktualizuj def ::hr 50 ::bold APT — Aktualizacja ^> apt-get update -y ? ok ^> apt-get upgrade -y ::green APT zaktualizowany ✓ done done & snap refresh ;; snap w tle -- aktualizuj *> notify-send "Zaktualizowano"
Przykłady — Gen 2
#!/usr/bin/env hl /// Demo wszystkich funkcji gen 2 using <gen 2> # <main/colors> ;; Typowane zmienne % cores: int = 1 > nproc |> @cores $( @cores * 2 ) -> @threads ~> Rdzenie: @cores | Wątki: @threads ;; For-in @ tool in curl git nmap ::which @tool ? ok ~> @COLOR_GREEN✓@COLOR_RESET @tool done done ;; Switch > uname -s |> @os ? switch @os | Linux ::green Linux ✓ | * ~> OS: @os done ;; While % i: int = 0 ?~ @i < 3 $( @i + 1 ) -> @i ~> iter: @i done ;; HackerOS API || hacker --version
Przykłady — Async
/// Równoległy skan sieci using <gen 2> // nmap :** wyniki :* nmap_scan def >> nmap -sn 192.168.1.0/24 *-- wyniki done :* ping_gw def > ping -c 3 8.8.8.8 *-- wyniki done & wget -q https://example.com/plik1.zip & wget -q https://example.com/plik2.zip *-- wyniki
Przykłady — Systemowe
/// Raport systemowy — gen 2 using <gen 2> # <main/colors> > uname -r |> @kernel > nproc |> @cores > uname -m |> @arch > id -un |> @user $( @cores * 2 ) -> @threads ::hr 50 ~> @COLOR_BOLDHackerOS System Report@COLOR_RESET ::hr 50 ~> Kernel: @kernel ~> Arch: @arch ~> Cores: @cores ~> Threads: @threads ~> User: @user ::hr 50
Komentarze