From 467a24766fb2ee39ac454fa7361e3b96d4d8a45a Mon Sep 17 00:00:00 2001 From: katajisto Date: Tue, 22 Jul 2025 14:31:41 +0300 Subject: [PATCH] Create basic linter --- first.jai | 40 ++++---------------------------- src/editor/tacoma.jai | 16 ++----------- src/load.jai | 3 ++- src/meta/ascii.jai | 49 +++++++++++++++++++++++++++++++++++++++ src/meta/lint.jai | 54 +++++++++++++++++++++++++++++++++++++++++++ src/meta/meta.jai | 2 ++ 6 files changed, 113 insertions(+), 51 deletions(-) create mode 100644 src/meta/ascii.jai create mode 100644 src/meta/lint.jai create mode 100644 src/meta/meta.jai diff --git a/first.jai b/first.jai index 32f2355..9fa35bf 100644 --- a/first.jai +++ b/first.jai @@ -1,39 +1,4 @@ -ascii_car : string = #string DONE - - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡤⢤⣶⣶⣶⣶⣶⣒⣒⣀⣺⣿⣿⠿⢶⣶⣶⣶⣦⣤⣤⣤⣄⣀⣀⣀⣀⡀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠴⠚⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠛⠒⠲⠦⢤⣉⠙⣿⣿⣿⣟⢿⣿⠿⠿⠿⢿⣿ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣶⣷⡦⠞⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡇⠀⠈⠛⢿⣿⡀⠀⠀⠀⠻ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣤⠤⢴⣿⣉⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠇⠀⠀⠀⠀⠙⣿⣄⡀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⡶⠞⠛⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠓⠒⠒⠢⠤⠤⣄⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⠀⢠⠤⠤⠤⣤⣾⠀⠙⢦⡀ - ⠀⠀⠀⠀⠀⠀⠀⠀⣠⠴⣾⣛⣩⢴⣿⠿⠶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠙⠒⠒⠒⠤⠤⢤⣤⣾⢿⣴⢏⣀⣀⣤⡼⠻⡆⠀⠈⢷ - ⠀⠀⠀⠀⠀⢀⣴⠋⠁⠀⠀⠀⠀⠙⠓⠲⠤⠬⠷⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠞⠉⠀⠀⠹⡟⠀⠀⠀⠀⠀⢱⠀⢠⣼ - ⠀⠀⠀⣀⡴⠋⠈⢙⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠛⠢⠤⢄⣀⣠⠴⠛⣋⣠⠴⠒⠉⠉⢉⣲⠶⠀⣀⡠⠤⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⢹⠀⠀⠀⠀⠀⣼⢰⣿⣿ - ⡀⣠⣼⠏⠀⠀⣰⠟⠦⢤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠓⠒⠒⠒⠋⣉⠤⠒⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⢀⣯⣼⣿⣿ - ⡟⠋⠹⢤⣠⠞⠁⠀⠀⠀⠀⠈⠉⠐⠲⠤⢄⣀⡀⠀⠀⠀⠀⣀⠤⠤⠤⠤⠤⣄⣀⣀⠀⢀⡠⠖⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⡀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⢸⣿⣿⣿⣿ - ⢻⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⢒⡶⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⣿⡝⣆⠀⠀⠀⠀⢸⠀⠀⣠⣴⠿⣻⣿⣿⠈ - ⢿⣿⣿⠶⢤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⠇⠀⠀⠀⠀⣀⣀⣤⣤⣾⣿⢿⡆⢸⣧⢹⠀⠀⣠⣴⣿⣴⠟⢋⣥⠴⢻⣿⠏⠀ - ⢸⣿⣿⡇⠀⠘⣿⣶⣦⣤⣀⡀⠀⠀⠀⠀⠀⠀⠈⠑⠲⠤⢤⣀⣀⡀⠀⠀⠀⠀⠀⠀⣀⣀⣞⣀⣠⣤⣾⣿⣿⣿⣿⣿⣿⢻⢸⣿⣾⣿⣾⣤⣾⣿⠿⢋⡡⠞⠉⠉⠉⠉⠀⠀⠀ - ⣼⡟⣿⡇⠀⠀⢹⣄⠈⠙⠒⠯⣽⣶⢶⣤⣤⣄⣀⣀⠀⠀⠀⠀⠈⠙⠻⠿⠿⠿⠿⠿⠿⠛⠛⠛⢉⣉⣽⠶⣿⠟⣿⣿⣧⣿⣾⣿⣿⡇⢹⡿⠋⣡⠖⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⣇⠳⣼⣧⠴⠛⠉⠉⠉⠒⣦⣤⣀⡀⠀⠀⠉⠙⢦⠀⠉⠉⢙⣷⣶⠒⠒⠒⠶⡶⠶⠶⢶⣤⠖⠚⠉⠁⠀⣰⣷⠾⣿⢿⢥⣼⣾⣿⣿⠃⣸⣠⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠈⠳⣌⣿⢦⣄⠀⢀⣴⣿⣿⣷⣿⡯⣗⠲⠤⣀⡈⣇⠀⠀⠻⡄⠈⣷⠀⠀⠀⡿⠒⠶⠾⢿⠀⠀⠀⢠⣾⡏⠁⣸⡇⢸⡸⢠⡌⢡⣿⠴⠿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠈⠙⠳⢿⣙⠺⢽⣿⣮⣿⣿⠗⠋⠀⠀⠀⠉⡿⠀⠀⣀⣹⣿⣯⣤⣶⣚⣛⣒⣛⣓⣿⠀⠀⠀⢽⣿⣶⣶⡏⢧⣼⣷⡿⢁⣾⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠈⠙⠢⢬⣙⠛⠧⢤⣀⣀⠀⢀⣴⠃⠀⢀⣹⢦⣤⣉⣉⣯⣍⣹⣿⣿⣿⡃⣀⡤⠴⠛⠋⠁⠀⡇⠘⣜⣏⣠⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠓⠦⢤⣈⡉⠉⠙⠛⠛⠛⠲⠤⠤⠤⠴⣶⣶⣿⣿⢿⡿⣯⠀⠀⠀⠀⠀⢀⣠⡟⠤⠿⠟⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠒⠲⠤⢤⣄⣀⣀⣀⣤⣈⣤⣤⠤⣴⣿⣥⠤⠴⠒⠚⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - - - - ░██████████░█████████ ░██ ░██ ░██████████ ░███ ░██ ░██████ - ░██ ░██ ░██ ░██ ░██ ░██ ░████ ░██ ░██ ░██ - ░██ ░██ ░██ ░██ ░██ ░██ ░██░██ ░██ ░██ ░██ - ░██ ░█████████ ░██ ░██ ░█████████ ░██ ░██ ░██ ░██ ░██ - ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██░██ ░██ ░██ - ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░████ ░██ ░██ - ░██ ░██ ░██ ░██████ ░██████████ ░██ ░███ ░██████ - - -DONE - +#load "./src/meta/meta.jai"; Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); #run { @@ -184,9 +149,12 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); iprof_plugin.add_source(iprof_plugin); add_build_file("src/platform_specific/main_native.jai", w); + lint_ok := true; while true { message := compiler_wait_for_message(); iprof_plugin.message(iprof_plugin, message); + if !lint_checks(message) then lint_ok = false; + if message.kind == .COMPLETE then break; } compiler_end_intercept(w); diff --git a/src/editor/tacoma.jai b/src/editor/tacoma.jai index da2e62e..e5c860e 100644 --- a/src/editor/tacoma.jai +++ b/src/editor/tacoma.jai @@ -1,18 +1,6 @@ #run { - tacomaString : string = #string DONE - ___ ___ ___ ___ ___ ___ - /\ \ /\ \ /\ \ /\ \ /\__\ /\ \ - \:\ \ /::\ \ /::\ \ /::\ \ /::| | /::\ \ - \:\ \ /:/\:\ \ /:/\:\ \ /:/\:\ \ /:|:| | /:/\:\ \ - /::\ \ /::\~\:\ \ /:/ \:\ \ /:/ \:\ \ /:/|:|__|__ /::\~\:\ \ - /:/\:\__\ /:/\:\ \:\__\ /:/__/ \:\__\ /:/__/ \:\__\ /:/ |::::\__\ /:/\:\ \:\__\ - /:/ \/__/ \/__\:\/:/ / \:\ \ \/__/ \:\ \ /:/ / \/__/~~/:/ / \/__\:\/:/ / - /:/ / \::/ / \:\ \ \:\ /:/ / /:/ / \::/ / - \/__/ /:/ / \:\ \ \:\/:/ / /:/ / /:/ / - /:/ / \:\__\ \::/ / /:/ / /:/ / - \/__/ \/__/ \/__/ \/__/ \/__/ - DONE - print("%\n", tacomaString); + #load "../../meta/ascii.jai"; + print("%\n", ascii_tacoma); } Tacoma :: #import "Tacoma"; diff --git a/src/load.jai b/src/load.jai index ddaadad..34e3389 100644 --- a/src/load.jai +++ b/src/load.jai @@ -9,6 +9,7 @@ mandatory_loads_done :: () -> bool { } init_font_loads :: () { + mandatory_loads_left += 1; sfetch_send(*(sfetch_request_t.{ path = "./resources/DroidSerif-Regular.ttf".data, callback = fontcb, @@ -23,5 +24,5 @@ fontcb :: (res: *sfetch_response_t) #c_call { push_context,defer_pop default_context; state.font_default.fons_font = fonsAddFontMem(state.fons, "sans", res.data.ptr, xx res.data.size, 0); ui_init_font_fields(*state.font_default); - mandatory_done = true; + mandatory_loads_left -= 1; } diff --git a/src/meta/ascii.jai b/src/meta/ascii.jai new file mode 100644 index 0000000..a2d2afe --- /dev/null +++ b/src/meta/ascii.jai @@ -0,0 +1,49 @@ +ascii_car : string : #string DONE + + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡤⢤⣶⣶⣶⣶⣶⣒⣒⣀⣺⣿⣿⠿⢶⣶⣶⣶⣦⣤⣤⣤⣄⣀⣀⣀⣀⡀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠴⠚⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠛⠒⠲⠦⢤⣉⠙⣿⣿⣿⣟⢿⣿⠿⠿⠿⢿⣿ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣶⣷⡦⠞⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡇⠀⠈⠛⢿⣿⡀⠀⠀⠀⠻ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣤⠤⢴⣿⣉⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠇⠀⠀⠀⠀⠙⣿⣄⡀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⡶⠞⠛⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠓⠒⠒⠢⠤⠤⣄⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⠀⢠⠤⠤⠤⣤⣾⠀⠙⢦⡀ + ⠀⠀⠀⠀⠀⠀⠀⠀⣠⠴⣾⣛⣩⢴⣿⠿⠶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠙⠒⠒⠒⠤⠤⢤⣤⣾⢿⣴⢏⣀⣀⣤⡼⠻⡆⠀⠈⢷ + ⠀⠀⠀⠀⠀⢀⣴⠋⠁⠀⠀⠀⠀⠙⠓⠲⠤⠬⠷⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠞⠉⠀⠀⠹⡟⠀⠀⠀⠀⠀⢱⠀⢠⣼ + ⠀⠀⠀⣀⡴⠋⠈⢙⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠛⠢⠤⢄⣀⣠⠴⠛⣋⣠⠴⠒⠉⠉⢉⣲⠶⠀⣀⡠⠤⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⢹⠀⠀⠀⠀⠀⣼⢰⣿⣿ + ⡀⣠⣼⠏⠀⠀⣰⠟⠦⢤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠓⠒⠒⠒⠋⣉⠤⠒⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⢀⣯⣼⣿⣿ + ⡟⠋⠹⢤⣠⠞⠁⠀⠀⠀⠀⠈⠉⠐⠲⠤⢄⣀⡀⠀⠀⠀⠀⣀⠤⠤⠤⠤⠤⣄⣀⣀⠀⢀⡠⠖⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⡀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⢸⣿⣿⣿⣿ + ⢻⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⢒⡶⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⣿⡝⣆⠀⠀⠀⠀⢸⠀⠀⣠⣴⠿⣻⣿⣿⠈ + ⢿⣿⣿⠶⢤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⠇⠀⠀⠀⠀⣀⣀⣤⣤⣾⣿⢿⡆⢸⣧⢹⠀⠀⣠⣴⣿⣴⠟⢋⣥⠴⢻⣿⠏⠀ + ⢸⣿⣿⡇⠀⠘⣿⣶⣦⣤⣀⡀⠀⠀⠀⠀⠀⠀⠈⠑⠲⠤⢤⣀⣀⡀⠀⠀⠀⠀⠀⠀⣀⣀⣞⣀⣠⣤⣾⣿⣿⣿⣿⣿⣿⢻⢸⣿⣾⣿⣾⣤⣾⣿⠿⢋⡡⠞⠉⠉⠉⠉⠀⠀⠀ + ⣼⡟⣿⡇⠀⠀⢹⣄⠈⠙⠒⠯⣽⣶⢶⣤⣤⣄⣀⣀⠀⠀⠀⠀⠈⠙⠻⠿⠿⠿⠿⠿⠿⠛⠛⠛⢉⣉⣽⠶⣿⠟⣿⣿⣧⣿⣾⣿⣿⡇⢹⡿⠋⣡⠖⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⣇⠳⣼⣧⠴⠛⠉⠉⠉⠒⣦⣤⣀⡀⠀⠀⠉⠙⢦⠀⠉⠉⢙⣷⣶⠒⠒⠒⠶⡶⠶⠶⢶⣤⠖⠚⠉⠁⠀⣰⣷⠾⣿⢿⢥⣼⣾⣿⣿⠃⣸⣠⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠈⠳⣌⣿⢦⣄⠀⢀⣴⣿⣿⣷⣿⡯⣗⠲⠤⣀⡈⣇⠀⠀⠻⡄⠈⣷⠀⠀⠀⡿⠒⠶⠾⢿⠀⠀⠀⢠⣾⡏⠁⣸⡇⢸⡸⢠⡌⢡⣿⠴⠿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠈⠙⠳⢿⣙⠺⢽⣿⣮⣿⣿⠗⠋⠀⠀⠀⠉⡿⠀⠀⣀⣹⣿⣯⣤⣶⣚⣛⣒⣛⣓⣿⠀⠀⠀⢽⣿⣶⣶⡏⢧⣼⣷⡿⢁⣾⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠈⠙⠢⢬⣙⠛⠧⢤⣀⣀⠀⢀⣴⠃⠀⢀⣹⢦⣤⣉⣉⣯⣍⣹⣿⣿⣿⡃⣀⡤⠴⠛⠋⠁⠀⡇⠘⣜⣏⣠⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠓⠦⢤⣈⡉⠉⠙⠛⠛⠛⠲⠤⠤⠤⠴⣶⣶⣿⣿⢿⡿⣯⠀⠀⠀⠀⠀⢀⣠⡟⠤⠿⠟⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠒⠲⠤⢤⣄⣀⣀⣀⣤⣈⣤⣤⠤⣴⣿⣥⠤⠴⠒⠚⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + + + + ░██████████░█████████ ░██ ░██ ░██████████ ░███ ░██ ░██████ + ░██ ░██ ░██ ░██ ░██ ░██ ░████ ░██ ░██ ░██ + ░██ ░██ ░██ ░██ ░██ ░██ ░██░██ ░██ ░██ ░██ + ░██ ░█████████ ░██ ░██ ░█████████ ░██ ░██ ░██ ░██ ░██ + ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██░██ ░██ ░██ + ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░████ ░██ ░██ + ░██ ░██ ░██ ░██████ ░██████████ ░██ ░███ ░██████ + + +DONE + +ascii_tacoma : string : #string DONE + ___ ___ ___ ___ ___ ___ + /\ \ /\ \ /\ \ /\ \ /\__\ /\ \ + \:\ \ /::\ \ /::\ \ /::\ \ /::| | /::\ \ + \:\ \ /:/\:\ \ /:/\:\ \ /:/\:\ \ /:|:| | /:/\:\ \ + /::\ \ /::\~\:\ \ /:/ \:\ \ /:/ \:\ \ /:/|:|__|__ /::\~\:\ \ + /:/\:\__\ /:/\:\ \:\__\ /:/__/ \:\__\ /:/__/ \:\__\ /:/ |::::\__\ /:/\:\ \:\__\ +/:/ \/__/ \/__\:\/:/ / \:\ \ \/__/ \:\ \ /:/ / \/__/~~/:/ / \/__\:\/:/ / +/:/ / \::/ / \:\ \ \:\ /:/ / /:/ / \::/ / +\/__/ /:/ / \:\ \ \:\/:/ / /:/ / /:/ / + /:/ / \:\__\ \::/ / /:/ / /:/ / + \/__/ \/__/ \/__/ \/__/ \/__/ +DONE diff --git a/src/meta/lint.jai b/src/meta/lint.jai new file mode 100644 index 0000000..5f205e7 --- /dev/null +++ b/src/meta/lint.jai @@ -0,0 +1,54 @@ +/* + Custom linting rules to maintain some style things in the + engine, just so I don't forget to follow the style I want to follow, + mostly with function names and variable names. +*/ + +lint_errors_found := 0; + +lint_checks :: (message: *Message) -> bool { + // We are only interested declarations being typechecked, and we'll look at + // them after typechecking. + if message.kind != .TYPECHECKED then return true; + code := cast(*Message_Typechecked) message; + + lint_ok := true; + + + for code.declarations { + import := it.expression.enclosing_load.enclosing_import; + if import.module_type != .MAIN_PROGRAM then return true; + if !lint_declaration(it.expression) { + lint_ok = false; + } + } + return lint_ok; +} + +lint_declaration :: (expression: Code_Declaration) -> bool { + if expression.expression && expression.expression.kind == .PROCEDURE_HEADER { + return lint_procedure_name(expression.name, expression.expression); + } + return true; +} + +lint_procedure_name :: (name: string, node: Code_Node) -> bool { + name_ok := true; + wrong_char : u8; + for name { + if it >= #char "a" && it <= #char "z" then continue; + if it == #char "_" then continue; + if it >= #char "0" && it <= #char "9" then continue; + name_ok = false; + wrong_char = it; + break; + } + if !name_ok { + error := sprint("Linter: Name % contains illegal char % for procedure names\n", name, wrong_char); + compiler_report(error, make_location(*node), .ERROR); + lint_errors_found += 1; + return false; + } else { + return true; + } +} diff --git a/src/meta/meta.jai b/src/meta/meta.jai new file mode 100644 index 0000000..1b7e5b4 --- /dev/null +++ b/src/meta/meta.jai @@ -0,0 +1,2 @@ +#load "ascii.jai"; +#load "lint.jai";