Add Y-lang prime number calculator: parser <=, assignment coercion, stdlib/primes#3
Draft
Add Y-lang prime number calculator: parser <=, assignment coercion, stdlib/primes#3
Conversation
Co-authored-by: andrewjc <444861+andrewjc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add console program for calculating 1000 prime numbers
Add Y-lang prime number calculator: parser <=, assignment coercion, stdlib/primes
Feb 24, 2026
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.
Implements a Y-lang program that computes and prints the first 1000 prime numbers to stdout, compiled to a native Linux binary and verified against a Go-computed reference. Three blocking issues required fixes before the program could compile and run correctly.
Compiler / Parser Fixes
parser/parser.go:<=(TokenTypeLessThanEqual) was lexed and codegen-handled but never registered as an infix operator — added to precedence table (LESSGREATER) and infix dispatch. Without this,while (i * i <= n)failed to parse.compiler/generator/assignment.go: Stores to typed pointer targets (e.g.i8*from mmap) now truncate or sign-extend the RHS to match the element type before emittingstore. Enables byte-buffer writes:New stdlib Module
lib/stdlib/primes/primes.y: Pure Y-lang stdlib module using Linux x86-64 syscalls only (no C runtime):isPrime(n)— trial division; modulo emulated asn - (n/i)*iprint_digit(d)— single digit via mmap scratch buffer +SYS_write+ munmapprint_int(n)— recursive decimal printerprint_primes(count)— iterates candidates, prints firstcountprimesIntegration Test
primes_test.go: Lexes → parses → compiles to LLVM IR →clang→ runs binary → verifies all 1000 output lines againstfirstNPrimes(1000)computed in Go (first:2, 1000th:7919).🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.