Commit Graph

244 Commits

Author SHA1 Message Date
dimgigov b3af1208e8 feat(lsp): add LSP server with completion, definition, hover, diagnostics 2026-06-07 18:20:35 +03:00
dimgigov 0d7a30835f feat: borrow expr, parser fix, borrow tests, borrow example 2026-06-07 18:09:40 +03:00
dimgigov adca52b269 docs: update README v0.4.0, update stdlib docs to 23 modules
- README: bump version to v0.4.0, add selfhost loop & borrow/shared
- Stdlib.md: update sections 1-4, add String_Chars, FromBool, Fmt, Iter
- BuildAndTest.md: add make selfhost-loop and make test-golden targets
- Standard library list updated to all 23 modules
2026-06-07 18:08:34 +03:00
dimgigov 04be9eb400 feat(stdlib): add String_Chars, String_FromBool, fix Fmt and Net
- String.bux: add String_Chars(s, index) for char-at-index access
- String.bux: add String_FromBool(b) conversion
- Fmt.bux: rewrite with correct stdlib imports (was using non-existent names)
- Net.bux: fix String_Len -> bux_strlen (String_Len not imported)
- All lib modules compile successfully
2026-06-07 18:05:04 +03:00
dimgigov bfe87a8acb feat: add borrow test example, fix borrow &mut parsing order
- examples/borrow.bux: working borrow expression example
- tests/borrow_test.nim: add 4 new tests for borrow & @[Shared]
- parser.nim: fix borrow parsing order (& before mut)
- Build verified: example compiles and runs
2026-06-07 17:50:27 +03:00
dimgigov 46814b2abc feat: selfhost-loop determinism, golden tests, sema diagnostics 2026-06-07 17:37:22 +03:00
dimgigov 9758b17b1a fix(parser): add stray } workaround in parserParseFuncDecl, enable selfhost build
This workaround consumes a stray } that parserParseBlock sometimes leaves
behind, which was causing the module handler to exit early. With this fix,
the selfhost compiler (buxc2) can now compile the entire src/ project.

- buxc2 project build: 491 user + 310 stdlib = 801 decls, no sema errors
- make selfhost-loop: builds and runs both passes
- C compilation succeeds, resulting binary works
2026-06-07 17:33:17 +03:00
dimgigov 8347599d23 fix(parser): save/restore + depth counter for reliable } consumption 2026-06-07 17:25:30 +03:00
dimgigov 4794335673 chore: clean up experimental changes, keep core parser improvements 2026-06-07 17:11:45 +03:00
dimgigov 134e8e877d fix(parser): depth counter in module handler, stray } cleanup, token count debug 2026-06-07 17:06:36 +03:00
dimgigov 88af8b09d4 fix(parser): improve parserParseBlock infinite-loop safeguard for stuck at } 2026-06-07 17:01:15 +03:00
dimgigov e41a8d31df fix(parser): use parserExpect for module closing brace 2026-06-07 16:43:14 +03:00
dimgigov a11071ab95 fix(parser): skip newlines before checking decl kind 2026-06-07 16:38:42 +03:00
dimgigov 093e08a2b9 chore(cli): remove diagnostic scan, keep FIFO merge and per-file counts 2026-06-07 16:25:23 +03:00
dimgigov 1500575982 fix(parser): replace destructive skip with single-token skip 2026-06-07 16:24:51 +03:00
dimgigov fe048eb4aa feat(cli): diagnostic scan for missing function defs, FIFO merge order, per-file counts 2026-06-07 16:20:22 +03:00
dimgigov 9dd964dc48 test: add fibonacci golden test, expand GOLDEN_TESTS 2026-06-07 16:10:05 +03:00
dimgigov e1038059c2 fix(cli): change user merge from LIFO to FIFO order, add per-file decl counts
- Cli_BuildProject now appends declarations (preserving original file order)
  instead of prepending (which reversed order)
- Added per-file declaration count debug output
- This makes merge order match Nim bootstrap behavior
2026-06-07 16:08:51 +03:00
dimgigov 1f0baefa5a feat: add selfhost-loop determinism check, golden tests, improve sema diagnostics
- Makefile: new targets `test-golden` and `selfhost-loop`
  - selfhost-loop verifies C codegen determinism (2-pass bootstrap)
  - test-golden compares C output against expected.c golden files
  - Updated clean-all to clean new build dirs
- tests/golden/hello/: first golden test (hello world)
- src/sema.bux:
  - Fix: import stubs only registered if symbol doesn't already exist
  - Improve: error message now includes identifier name
2026-06-07 15:47:48 +03:00
dimgigov 3b4456f01f selfhost: expand Decl to 256 fields, fix unary precedence, add discard/var parsing, fix diag buffer overflow
- ast.bux: Decl expanded with field0..field255, variant0..7, param0..8
- parser.bux: add parserParseUnary for correct unary precedence; handle tkDiscard statements; allow var without initializer (matching bootstrap); add diagCount bounds check in parserEmitDiag
- hir.bux: HirParam changed to pointers
- hir_lower.bux: full field chains for struct lowering
- c_backend.bux: hardened -> vs . field access; null checks in CBE_GetExprTypeName
- cli.bux: add -lcrypto to linker
2026-06-07 14:58:23 +03:00
dimgigov 0bdef58182 selfhost: fix pointer field access, algebraic enums, string literal escaping
- hir_lower: use per-function scope instead of global scope for params
  fixes p->error emission for pointer parameters
- parser: assign variant4..variant7 in enum decls (was only 0..3)
- c_backend: escape quotes, backslash, newline, tab, cr in string literals
- runtime: bux_write_file now writes raw bytes (was un-escaping sequences)
- c_backend: emit algebraic enums as tagged unions (tag enum + data union + struct)
- hir_lower: add hBreak/hContinue lowering
- sema: skip empty variant names when collecting enum globals
2026-06-06 23:54:09 +03:00
dimgigov 3ae8c60ebb fix(bootstrap): resolve lir lower crashes and struct-copy bugs
- Fix lirValToC crash on lvkInt in hStore raw C emission
- Add hAlloca handling to lowerExpr (returns &name, avoids unhandled fallback)
- Fix nested comment syntax in unhandled expr fallback
- Rewrite buildLval to handle hIndexPtr and nested hFieldPtr/hArrowField
  so assignments like arr[i].field = val emit direct C lvalues
- Make &&/|| temporaries unique (__and_tmp_N/__or_tmp_N) to avoid
  duplicate declarations in the same function
- Selfhost null-deref fix in sema.bux (unchained nested conditions)
2026-06-06 21:46:25 +03:00
dimgigov 9416c486b2 docs: update PLAN.md — Phase 11 roadmap, 26 examples, M10 completed 2026-06-06 19:53:24 +03:00
dimgigov ba0a55f467 docs: update README — 26 examples passing, selfhost working 2026-06-06 19:49:52 +03:00
dimgigov 797ca7c80c fix(lir): resolve all LIR backend regressions — 26/26 examples + selfhost passing
- hir_lower: add isScope=true to lowerBlock; fix resolveExprType for ekIndex,
  ekField on monomorphized structs, and ekTry/ekUnwrap tmpVar typing
- lir_lower: add loop label stack for break/continue; pass null arg to
  bux_task_spawn when spawn has no arguments
- lir_c_backend: multi-pass type inference for temps; include params in
  varTypes; handle lvkTemp in lirLoad; use inferred type in lirAlloca
2026-06-06 19:49:24 +03:00
dimgigov 4f7653a410 docs: update project status — buxc2 is now a working compiler, not a PoC 2026-06-06 19:02:54 +03:00
dimgigov 62a9c8b84a feat: LIR backend replaces direct HIR→C emission (v0.3.0)
- 42 LIR instructions in bootstrap/lir.nim

- HIR→LIR lowering in bootstrap/lir_lower.nim

- LIR→C emission with full struct/enum/vtable support

- All 22 examples + 5 Nim unit tests passing

- Updated README status and backend description
2026-06-06 18:55:59 +03:00
dimgigov aff03ffb5a fix(selfhost): resolve all sema errors — 0 undeclared identifiers
- Add forward declarations for mutually-recursive parser functions
  (parserParseExpr, parserParseStmt, parserParseBlock,
   parserParsePrimary, parserParsePostfixExpr, parserParseBinaryPrec)
- Fix HIR lowering: skip forward decls (refBody==null) to avoid
  duplicate function entries and array overflow
- Bump funcs/externFuncs array size 256→512 to handle large modules
- Update PLAN.md with progress

Sema: 0 errors (was 7, then 2, now 0)
Remaining: C backend struct ordering (pre-existing, Iter/StringBuilder)
2026-06-06 05:34:19 +03:00
dimgigov a8b909726b v0.4.0: selfhost loop progress
- Fix stdlib merge: merge ALL lib/*.bux via bux_list_dir (was 0)
- Fix Cli_FindStdlibDir: search for lib/ not stdlib/
- Fix stdlib path: remove Std/ subdir (now flat in lib/)
- Fix runtime paths: add ../../ fallback for build/selfhost depth
- Remove hardcoded /home/ziko paths from src/cli.bux
- Fix Json.bux: avoid var-in-if-block scoping bug (5 errors)
- Add improved sema error messages (reverted due to crash)
- Remaining: 2 parserParsePostfix sema forward-ref errors
- Update PLAN.md with v0.3.0-v1.0.0 roadmap
2026-06-06 05:15:04 +03:00
dimgigov 2698ca92b7 fix(selfhost): stdlib path + merge all modules, not just imports
- Fix Cli_FindStdlibDir: search for lib/ instead of stdlib/
- Fix Cli_CollectStdlibImports → merge ALL lib/*.bux via bux_list_dir
- Fix Cli_CollectStdlibImports path: remove Std/ subdir (now flat)
- Add ../../ fallback for rt/ paths (build/selfhost depth)
- Update PLAN.md with v0.3.0 structure + v1.0.0 roadmap
- Remaining: 7 sema cross-module resolution bugs (pre-existing)
2026-06-06 05:02:48 +03:00
dimgigov ac969b37c1 v0.3.0: restructure directories
- src/        ← compiler/selfhost/  (canonical Bux compiler)
- bootstrap/  ← compiler/bootstrap/ (Nim bootstrap)
- lib/        ← library/std/        (standard library)
- rt/         ← library/runtime/    (C runtime)
- tests/      ← compiler/tests/     (unit tests)
- Remove _selfhost/ (built into build/selfhost/ now)
- Update all path references (Makefile, cli.nim, cli.bux, docs)
- Bump version to 0.3.0
2026-06-06 04:53:39 +03:00
dimgigov 0dade151d2 refactor: remove QBE backend, improve bootstrap compiler and stdlib
Bootstrap compiler improvements:
- Extract findStdlibDir() to remove hardcoded path and deduplicate
- Extract prepareProject()/mergeProject() to share code between cmdCheck/cmdBuild
- Fix C backend to emit warning on unknown types instead of silent 'int'
- Clean up all unused imports across 7 modules
- Makefile: add strip, debug target, clean-all, selfhost strip

QBE removal:
- Remove vendor/qbe/ (74K lines)
- Remove compiler/selfhost/qbe_backend.bux, nim_backend.bux

Stdlib improvements:
- Add Result.bux + Option.bux modules
- Fix Json.bux memory leak (removed double String_Copy)
- Add missing imports in Crypto.bux (Alloc/Free) and Test.bux (PrintLine/PrintInt)
- Clean stale buxc_debug binary
2026-06-06 00:51:11 +03:00
dimgigov 7b32cad3e9 fix(hir_lower): generic monomorphization for cross-module generic calls
The old findGenericCalls second-pass only looked in non-generic functions
and generated unresolved instances like Array_Get_T when generic funcs
called other generic funcs. Removed it entirely.

lowerExpr for ekCall now invokes generateMethodInstance directly for
both explicit (ekGenericCall) and inferred generic calls. This ensures
concrete instantiations are generated on-demand with correct typeSubst.

Also added guard in resolveTypeExpr/substituteType to skip emitting C
struct definitions for unresolved type parameters (e.g. Array<T> inside
a generic function body before monomorphization).

feat(std): add Std::Iter module
- Array_Iter, Iter_Next, Iter_HasNext, Iter_Peek, Iter_Reset
- Iter_Pos, Iter_Len, Iter_Count, Iter_Skip, Iter_Take

docs: document Std::Iter in Stdlib.md
examples: add iter.bux example
tests: add _test_array regression test
2026-06-05 23:39:41 +03:00
dimgigov 846c29c6dd examples: add testing example for bux test 2026-06-05 23:06:53 +03:00
dimgigov f02b354e9a feat: bux test command + Std::Test module
- Add 'bux test' CLI command: discovers .bux files in tests/, compiles
  each into a temp package, runs them, reports pass/fail
- Add Std::Test module with Assert, AssertEqInt, AssertTrue,
  AssertFalse, Fail
- Add bux_exit and bux_assert C runtime primitives
- Update README.md and docs/BuildAndTest.md
2026-06-05 22:58:02 +03:00
dimgigov 2a19734c72 docs: update README status to reflect actual project focus
Self-hosted compiler (buxc2) is deprioritized; bootstrap compiler
(buxc, Nim) is the actively maintained and used compiler.
2026-06-05 22:49:27 +03:00
dimgigov 1f64f4707e fix: algebraic enum C backend and sema field type resolution
- Fix sema.nim: use objType.name instead of obj.name for algebraic enum
  tag/data field types (was generating _Tag instead of EnumName_Tag)
- Fix c_backend.nim: emit enum definitions before struct definitions
  to allow structs to reference algebraic enum types
2026-06-05 22:47:37 +03:00
dimgigov 154579b30d feat: String_ToFloat + Json escape sequence support
- Add bux_str_to_float() C runtime wrapper (strtod)
- Add String_ToFloat() in library/std/String.bux
- Update JsonParser_ParseNumber to use String_ToFloat (decimals now work)
- Update JsonParser_ParseString to decode escape sequences (\n, \t, \r, \", \\, \b, \f)
- Fix use-after-free in JsonParser_ParseString: String_Copy before StringBuilder_Free
2026-06-05 22:35:50 +03:00
dimgigov d0de9c2abf feat: Std::Sync — Mutex and RwLock primitives
- Add bux_mutex_* and bux_rwlock_* C runtime functions
- Add library/std/Sync.bux with Mutex and RwLock wrappers
- Add examples/sync.bux — threaded counter with Mutex
- Update docs/Stdlib.md with Sync section and example
- Update README.md feature table
2026-06-05 22:30:44 +03:00
dimgigov 809785711c docs: add missing stdlib modules and update language reference
Stdlib.md:
- Add Std::Task (thread spawn/join/sleep)
- Add Std::Channel (generic channels + wrappers)
- Add Std::Net (TCP sockets)
- Add Std::Json (parser/serializer)
- Add Std::Crypto (SHA-256, HMAC, Base64, random)
- Add Std::Fmt (formatting wrappers)
- Add Std::Math (Sqrt, Pow, Abs, Min, Max)
- Add String_FromFloat to String docs
- Update Future Modules list

LanguageRef.md:
- Add Concurrency section (threads + channels)
- Update Ownership with move semantics and own T

BuildAndTest.md:
- Add libssl-dev/openssl prerequisite note
- Mention -lcrypto auto-linking
2026-06-05 22:19:46 +03:00
dimgigov 96aada2a4e fix: Channel_RecvInt init + add channel example to README
- Initialize result to 0 in Channel_RecvInt/RecvFloat64 to handle closed channel
- Add producer/consumer channel example in examples/channel.bux
- Update README.md with Channels syntax preview
2026-06-05 22:15:56 +03:00
dimgigov a7f96c8e0d Remove temporary _test_borrow2 directory 2026-06-05 21:56:54 +03:00
dimgigov 636c49e9df feat: improve borrow checker — reinitialization, assignment move, return move
- Add isOwn field to Symbol for tracking own T declarations
- Reinitialization after move: assigning to a moved variable removes it from movedVars
- Move tracking in let/var initialization: var b: own Box = a moves a
- Move tracking in assignment: x = y moves y if y is own T
- Move tracking in return: return x moves x if x is own T
- Expand borrow_test.nim to 10 tests (all passing)
2026-06-05 21:56:47 +03:00
dimgigov ce3b4c99f0 Remove temporary _test_crypto directory 2026-06-05 21:34:43 +03:00
dimgigov fe31ddbc4b feat: add Std::Crypto — SHA-256, HMAC-SHA256, Base64, random bytes
- C runtime (OpenSSL): bux_sha256, bux_hmac_sha256, bux_random_bytes,
  bux_base64_encode, bux_base64_decode, bux_bytes_to_hex
- library/std/Crypto.bux: Crypto_Sha256, Crypto_HmacSha256,
  Crypto_HmacSha256Raw, Crypto_RandomBytes, Crypto_Base64Encode,
  Crypto_Base64Decode
- examples/jwt.bux: full JWT creation with HS256 signature
- Link with -lcrypto in C backend
2026-06-05 21:34:37 +03:00
dimgigov fd9abb12be Remove temporary test directories 2026-06-05 21:26:57 +03:00
dimgigov 49264b5d06 feat: add Std::Json — JSON parser and serializer
- JsonValue struct supporting null, bool, number, string, array, object
- Json_Parse(s: String) -> JsonValue: recursive descent parser
- Json_Stringify(v: JsonValue) -> String: recursive serializer
- Access helpers: Json_ObjectGet, Json_ObjectSet, Json_ObjectHas,
  Json_ArrayGet, Json_ArrayPush, Json_ArrayLen, Json_ObjectLen
- Constructors: Json_Null, Json_Bool, Json_Number, Json_String,
  Json_Array, Json_Object
- Type accessors: Json_IsNull, Json_AsBool, Json_AsNumber, Json_AsString
- examples/json.bux: demonstrates parse, access, build programmatically
- Add os_time, process, json to test-examples suite
2026-06-05 21:26:51 +03:00
dimgigov 459e4fb6db Remove temporary _test_fmt directories 2026-06-05 21:05:05 +03:00
dimgigov db9025f3a3 feat: add Std::Fmt — string formatting module
- C runtime: bux_float_to_string() for float64 → String conversion
- String.bux: add String_FromFloat, extern decl for bux_float_to_string
- library/std/Fmt.bux: Fmt_Fmt1, Fmt_Fmt2, Fmt_Fmt3, Fmt_FmtInt, Fmt_FmtInt2,
  Fmt_FmtFloat, Fmt_FmtBool — positional {0}, {1}, {2} placeholders
- Refactor examples to use Fmt:
  factorial.bux, fibonacci.bux, process.bux, os_time.bux
2026-06-05 21:05:00 +03:00
dimgigov 6d4543ead9 Remove temporary _test_net directory 2026-06-05 20:32:27 +03:00