Repository navigation
Add raylib bindings and fix generic import rewriting - #2
Merged
Merged
Conversation
- add std/gfx/raylib bindings and a spinning cube example - fix where-clause rewriting to avoid looping over the clause
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new std/gfx/raylib.ag FFI binding module for raylib, adds a raylib-based graphics example, and fixes a looping bug in the import-alias rewriter when processing generic where clauses.
Changes:
- Add a comprehensive raylib binding module (
std/gfx/raylib.ag) with structs/enums/constants and manyextern "C"declarations. - Add a raylib example (
examples/gfx_raylib.ag) intended to demonstrate rendering a spinning cube. - Fix
ImportAliasRewriter::rewrite_genericsto avoid an infinite loop by rewriting an existingwhere_clauseonce.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| std/gfx/raylib.ag | Adds raylib FFI types/constants/functions for use from Silver code. |
| examples/gfx_raylib.ag | Adds a raylib-based demo program (currently re-declares FFI locally). |
| agc/src/parser/import_hook.rs | Fixes generic where-clause alias rewriting to avoid looping. |
Comments suppressed due to low confidence (3)
examples/gfx_raylib.ag:23
InitWindowis declared with only(width, height), but raylib’s C API takes a thirdconst char* titleparameter. With the current extern declaration, the call inmain()will use the wrong ABI/stack layout and can crash immediately. Update the extern signature (and the call site) to include the window title, or import and use thestd/gfx/raylib.agbinding which already declares the correct signature.
#[link(raylib)]
extern "C" void InitWindow(i32 width, i32 height);
extern "C" void SetTargetFPS(i32 fps);
extern "C" bool WindowShouldClose();
extern "C" f64 GetTime();
examples/gfx_raylib.ag:29
- The extern declarations use
u32forClearBackground/DrawRectangle/DrawLine/DrawTrianglecolor parameters, but raylib expects aColorstruct passed by value. Declaring these parameters asu32is an ABI mismatch and may lead to incorrect argument passing on some platforms. Prefer using theColordefinition fromstd/gfx/raylib.ag(and its function declarations) instead of re-declaring these APIs with a different type.
extern "C" void BeginDrawing();
extern "C" void ClearBackground(u32 color);
extern "C" void DrawRectangle(i32 posX, i32 posY, i32 width, i32 height, u32 color);
extern "C" void DrawLine(i32 startPosX, i32 startPosY, i32 endPosX, i32 endPosY, u32 color);
extern "C" void DrawTriangle(Vec2 v1, Vec2 v2, Vec2 v3, u32 color);
extern "C" void EndDrawing();
examples/gfx_raylib.ag:68
fill_quaddraws each triangle twice by submitting the same vertices in both winding orders (a,b,ccandcc,b,a, thena,cc,dandd,cc,a). For raylib’s 2DDrawTriangle(filled) this is redundant work and can noticeably increase overdraw in more complex scenes. If backface concerns aren’t relevant here, draw the quad using only two triangles (or use a dedicated quad helper if available).
DrawTriangle(a, b, cc, color);
DrawTriangle(cc, b, a, color);
DrawTriangle(a, cc, d, color);
DrawTriangle(d, cc, a, color);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
416
to
420
| fn rewrite_generics(&mut self, generics: &mut ast::Generics) { | ||
| while let Some(clause) = &mut generics.where_clause { | ||
| if let Some(clause) = &mut generics.where_clause { | ||
| for predicate in &mut clause.predicates { | ||
| match predicate { | ||
| ast::WherePredicate::Type { |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Owner
|
@copilot std/gfx/raylib current uses multiple extern statements. these can wrapped inside a single extern block for better readability. See std/io.ag for example |
CierCier
added a commit
that referenced
this pull request
Aug 1, 2026
Add raylib bindings and fix generic import rewriting
CierCier
added a commit
that referenced
this pull request
Aug 16, 2026
The compiler already knows every function's source span, so the backtrace
symbol table now carries {addr, name, file, line} instead of {addr, name}:
- emit_function_body records (llvm name -> basename, declaration line) from
the lexer source registry + span (works without -g).
- emit_backtrace_table emits the 4-field records with per-function file/line
string globals.
- std/rt/backtrace.ag prints '#N <name> at <file>:<line> (0x...)'.
- AGM magic bumped to v6: stale .agm library objects carry the old 2-field
records and would misparse.
Frames now read like:
#0 __silver_assert_failed at memory.ag:399 (0x000000000020e92d)
#1 level3 at btprobe.ag:3 (0x00000000002124da)
#2 level2 at btprobe.ag:8 (0x0000000000212505)
Verified: cargo 328/328, run_tests 132/132 (backtrace_test now greps for
'<name> at <file>:' positions), clippy at the single pre-existing warning.
CierCier
added a commit
that referenced
this pull request
Aug 16, 2026
The runtime now prints the exact source line of each frame and the values
of spilled arguments — no assembly diving needed to check whether a param
is garbled:
assertion failed at /tmp/btprobe.ag:4: level3 guard
backtrace:
#0 __silver_assert_failed at memory.ag:425 (0x...)
args: file=2099240 line=4 msg=2099256
#1 level3 at btprobe.ag:4 (0x...)
args: x=42
#2 level2 at btprobe.ag:9 (0x...)
args: x=42
...
DWARF sections are not allocated into the running binary, so the compiler
parses its own emitted object and folds the data into alloc'd,
link-time-resolved tables (agc/src/codegen/dwarf_bt.rs):
- ELF reader (section headers, symtab, RELA relocations — sh_info is the
target section, addends are raw 64-bit two's complement).
- .debug_line v4/v5 decoder: peeked dir/file tables (name, dir idx, mtime,
size order), line_base as a signed byte, standard opcodes applied
(advance_pc/advance_line/set_file/copy/const_add_pc), special-opcode
address advance divided by line_range, relocated set_address values.
- .debug_info formal parameters: abbrev tables, strp with R_X86_64_32
relocations applied, exprloc DW_OP_fbreg (frame base is rbp) / DW_OP_reg.
- emit_bt_debug_tables: __silver_bt_lines ({fn, offset, line, file}) and
__silver_bt_args ({fn, count, {name, fbreg, size}}) globals, linkonce_odr,
always emitted (empty when no DWARF). The object is re-emitted with the
tables; the parsed offsets stay valid because the debug sections are
unchanged.
Unit test compiles a probe with -g and asserts line + param extraction
against the real object. backtrace_test now greps for args: x=.
Verified: cargo 329/329, run_tests 132/132, clippy at the single
pre-existing warning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
std/gfx/raylib.agbinding module covering raylib constants, structs, enums, and a broad set of C FFI declarations.examples/gfx_raylib.agto demonstrate drawing a spinning cube with raylib.Testing
agc/src/parser/import_hook.rs