compiler with dist

This commit is contained in:
Nilton Constantino 2026-01-21 06:50:57 +00:00
parent 1410a8ff19
commit b7425e5a20
No known key found for this signature in database
25 changed files with 370 additions and 316 deletions

2
.gitignore vendored
View File

@ -54,3 +54,5 @@ sdcard/**
dist-staging
dist-staging/**
temp
temp/**

264
Cargo.lock generated
View File

@ -86,7 +86,7 @@ dependencies = [
"ndk-context",
"ndk-sys 0.6.0+11769913",
"num_enum",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -187,12 +187,6 @@ dependencies = [
"libloading 0.7.4",
]
[[package]]
name = "assert-unchecked"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7330592adf847ee2e3513587b4db2db410a0d751378654e7e993d9adcbe5c795"
[[package]]
name = "atomic-waker"
version = "1.1.2"
@ -270,9 +264,6 @@ name = "bumpalo"
version = "3.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
dependencies = [
"allocator-api2",
]
[[package]]
name = "bytemuck"
@ -297,7 +288,7 @@ dependencies = [
"polling",
"rustix 0.38.44",
"slab",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -476,9 +467,9 @@ dependencies = [
[[package]]
name = "compact_str"
version = "0.8.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32"
checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a"
dependencies = [
"castaway",
"cfg-if",
@ -642,6 +633,12 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
[[package]]
name = "dragonbox_ecma"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a5577f010d4e1bb3f3c4d6081e05718eb6992cf20119cab4d3abadff198b5ae"
[[package]]
name = "either"
version = "1.15.0"
@ -664,6 +661,12 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "find-msvc-tools"
version = "0.1.7"
@ -784,7 +787,7 @@ checksum = "6f56f6318968d03c18e1bcf4857ff88c61157e9da8e47c5f29055d60e1228884"
dependencies = [
"log",
"presser",
"thiserror",
"thiserror 1.0.69",
"winapi",
"windows 0.52.0",
]
@ -819,20 +822,14 @@ dependencies = [
"allocator-api2",
]
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"allocator-api2",
]
[[package]]
name = "hashbrown"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
dependencies = [
"allocator-api2",
]
[[package]]
name = "hassle-rs"
@ -844,7 +841,7 @@ dependencies = [
"com",
"libc",
"libloading 0.8.9",
"thiserror",
"thiserror 1.0.69",
"widestring",
"winapi",
]
@ -909,7 +906,7 @@ dependencies = [
"combine",
"jni-sys",
"log",
"thiserror",
"thiserror 1.0.69",
"walkdir",
"windows-sys 0.45.0",
]
@ -1091,7 +1088,7 @@ dependencies = [
"rustc-hash 1.1.0",
"spirv",
"termcolor",
"thiserror",
"thiserror 1.0.69",
"unicode-xid",
]
@ -1106,7 +1103,7 @@ dependencies = [
"log",
"ndk-sys 0.5.0+25.2.9519653",
"num_enum",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -1121,7 +1118,7 @@ dependencies = [
"ndk-sys 0.6.0+11769913",
"num_enum",
"raw-window-handle",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -1509,23 +1506,24 @@ checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52"
[[package]]
name = "oxc-miette"
version = "1.0.2"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e03e63fd113c068b82d07c9c614b0b146c08a3ac0a4dface3ea1d1a9d14d549e"
checksum = "60a7ba54c704edefead1f44e9ef09c43e5cfae666bdc33516b066011f0e6ebf7"
dependencies = [
"cfg-if",
"owo-colors",
"oxc-miette-derive",
"textwrap",
"thiserror",
"thiserror 2.0.18",
"unicode-segmentation",
"unicode-width 0.2.2",
]
[[package]]
name = "oxc-miette-derive"
version = "1.0.2"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e21f680e8c5f1900297d394627d495351b9e37761f7bbf90116bd5eeb6e80967"
checksum = "d4faecb54d0971f948fbc1918df69b26007e6f279a204793669542e1e8b75eb3"
dependencies = [
"proc-macro2",
"quote",
@ -1534,29 +1532,27 @@ dependencies = [
[[package]]
name = "oxc_allocator"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17374a91329f2e362bc8be31cb3e171ef226777d0ea668e17a39620443693027"
checksum = "2174c7c8f77137b1bd1c653d7a5a531ae41f3b8fec1dd0251c801689784e7a2e"
dependencies = [
"allocator-api2",
"bumpalo",
"hashbrown 0.15.5",
"hashbrown 0.16.1",
"oxc_data_structures",
"rustc-hash 2.1.1",
"simdutf8",
]
[[package]]
name = "oxc_ast"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b38cfe954ee987354af015020f5cb2723df6fed6cd688eff24388437c7eb7e"
checksum = "62f1902f97a5cac8767b76a1d8a1b3124e9db80c176ebbc98f75143dcc124a15"
dependencies = [
"bitflags 2.10.0",
"cow-utils",
"num-bigint",
"num-traits",
"oxc_allocator",
"oxc_ast_macros",
"oxc_data_structures",
"oxc_diagnostics",
"oxc_estree",
"oxc_regular_expression",
"oxc_span",
@ -1565,57 +1561,83 @@ dependencies = [
[[package]]
name = "oxc_ast_macros"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85f9e03eff90b041078edcc8aff09457eb4126fa5d62a383fdb082d3ae286274"
checksum = "c5a31bd55516a98a35b2d99fa5813a3d3a5b798bad3262c819dfe7344bc6f390"
dependencies = [
"phf",
"proc-macro2",
"quote",
"syn 2.0.114",
]
[[package]]
name = "oxc_diagnostics"
version = "0.48.2"
name = "oxc_ast_visit"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a24c41929c1910d83fb6f4c508190a8b2d1bad02e81c8cb3a9d3f474ca0ad2c1"
checksum = "e2c520a488c04ba5267223edd0bb245fb7f10e2358e8955802a5d962bb95b50a"
dependencies = [
"cow-utils",
"oxc-miette",
]
[[package]]
name = "oxc_ecmascript"
version = "0.48.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30fba86c97b571671f941b818e6831ba821aac398b9f6f3b4e3367ca264b8324"
dependencies = [
"num-bigint",
"num-traits",
"oxc_allocator",
"oxc_ast",
"oxc_span",
"oxc_syntax",
]
[[package]]
name = "oxc_estree"
version = "0.48.2"
name = "oxc_data_structures"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e587034bb5f108dd987e5419a4ad35a173550bd9439fc2b610d34e4ce41e8b23"
checksum = "a42840ce8d83a08a92823dda6189e4d97359feca24a4fa732f3256c4614bb5a4"
[[package]]
name = "oxc_diagnostics"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f7b09c1563a67ede53af131f717b31ba89a992959ebad188b5158c21d4dc0a"
dependencies = [
"cow-utils",
"oxc-miette",
"percent-encoding",
]
[[package]]
name = "oxc_ecmascript"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4813b352bd5b0b05badf0c9e6c5ec7ea58a6a7ab49bec8d18ead262624c6ef8d"
dependencies = [
"cow-utils",
"num-bigint",
"num-traits",
"oxc_allocator",
"oxc_ast",
"oxc_regular_expression",
"oxc_span",
"oxc_syntax",
]
[[package]]
name = "oxc_estree"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54fb3effe995e6538d68070bf0a450b5ffd11dd41b62f11a4d01efa1f40e278"
[[package]]
name = "oxc_index"
version = "2.0.0"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eca5d9726cd0a6e433debe003b7bc88b2ecad0bb6109f0cef7c55e692139a34"
checksum = "eb3e6120999627ec9703025eab7c9f410ebb7e95557632a8902ca48210416c2b"
dependencies = [
"nonmax",
"serde",
]
[[package]]
name = "oxc_parser"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc385aca3586877f8c918aed1141b885dedcfc1019d6ea5be4105f8e2a7965e"
checksum = "5592bf8b64743944eb46528f9eabdde2b2435c8293cd502f5c183f9dff644e16"
dependencies = [
"assert-unchecked",
"bitflags 2.10.0",
"cow-utils",
"memchr",
@ -1623,6 +1645,7 @@ dependencies = [
"num-traits",
"oxc_allocator",
"oxc_ast",
"oxc_data_structures",
"oxc_diagnostics",
"oxc_ecmascript",
"oxc_regular_expression",
@ -1634,14 +1657,14 @@ dependencies = [
[[package]]
name = "oxc_regular_expression"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8d172402f6d542ab2837d35126cc42ad6989b9c2289b06bc5c8c89dceb60c48"
checksum = "09de7f7e0fb82f54750e3a95346a828fd354b9aeac00f131719008733e66a18d"
dependencies = [
"bitflags 2.10.0",
"oxc_allocator",
"oxc_ast_macros",
"oxc_diagnostics",
"oxc_estree",
"oxc_span",
"phf",
"rustc-hash 2.1.1",
@ -1650,9 +1673,9 @@ dependencies = [
[[package]]
name = "oxc_span"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75881376dfdbb6a23f12a66794904f0d215629f208edcf7e156c0770e89e2101"
checksum = "2a42c0759b745eca0fe776890af46ce12e79e61796995e51a8eb9dcdf5516ab0"
dependencies = [
"compact_str",
"oxc-miette",
@ -1663,22 +1686,21 @@ dependencies = [
[[package]]
name = "oxc_syntax"
version = "0.48.2"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6d88037a5de07f66299ab523a65545cc48d550658cea8cadcea09b60596dd49"
checksum = "b63eac2e04a75a10c5714aeb753cdfa06b1abc66bbaa748b7994700f52c9b184"
dependencies = [
"assert-unchecked",
"bitflags 2.10.0",
"cow-utils",
"dragonbox_ecma",
"nonmax",
"oxc_allocator",
"oxc_ast_macros",
"oxc_data_structures",
"oxc_estree",
"oxc_index",
"oxc_span",
"phf",
"rustc-hash 2.1.1",
"ryu-js",
"unicode-id-start",
]
@ -1719,29 +1741,30 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "phf"
version = "0.11.3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
dependencies = [
"phf_macros",
"phf_shared",
"serde",
]
[[package]]
name = "phf_generator"
version = "0.11.3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
dependencies = [
"fastrand",
"phf_shared",
"rand",
]
[[package]]
name = "phf_macros"
version = "0.11.3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"
checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef"
dependencies = [
"phf_generator",
"phf_shared",
@ -1752,9 +1775,9 @@ dependencies = [
[[package]]
name = "phf_shared"
version = "0.11.3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266"
dependencies = [
"siphasher",
]
@ -1794,7 +1817,7 @@ dependencies = [
"bytemuck",
"pollster",
"raw-window-handle",
"thiserror",
"thiserror 1.0.69",
"ultraviolet",
"wgpu",
]
@ -1874,13 +1897,10 @@ checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773"
name = "prometeu"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"cpal",
"pixels",
"prometeu-core",
"ringbuf",
"serde_json",
"winit",
"prometeu-compiler",
"prometeu-runtime-desktop",
]
[[package]]
@ -1895,6 +1915,7 @@ dependencies = [
"clap",
"oxc_allocator",
"oxc_ast",
"oxc_ast_visit",
"oxc_parser",
"oxc_span",
"prometeu-bytecode",
@ -1948,21 +1969,6 @@ version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "range-alloc"
version = "0.1.4"
@ -2098,12 +2104,6 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"
[[package]]
name = "ryu-js"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd29631678d6fb0903b69223673e122c32e9ae559d0960a38d574695ebc0ea15"
[[package]]
name = "safe_arch"
version = "0.7.4"
@ -2202,12 +2202,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "simdutf8"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
[[package]]
name = "siphasher"
version = "1.0.1"
@ -2255,7 +2249,7 @@ dependencies = [
"log",
"memmap2",
"rustix 0.38.44",
"thiserror",
"thiserror 1.0.69",
"wayland-backend",
"wayland-client",
"wayland-csd-frame",
@ -2350,7 +2344,16 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [
"thiserror-impl 2.0.18",
]
[[package]]
@ -2364,6 +2367,17 @@ dependencies = [
"syn 2.0.114",
]
[[package]]
name = "thiserror-impl"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.114",
]
[[package]]
name = "tiny-skia"
version = "0.11.4"
@ -2754,7 +2768,7 @@ dependencies = [
"raw-window-handle",
"rustc-hash 1.1.0",
"smallvec",
"thiserror",
"thiserror 1.0.69",
"web-sys",
"wgpu-hal",
"wgpu-types",
@ -2798,7 +2812,7 @@ dependencies = [
"renderdoc-sys",
"rustc-hash 1.1.0",
"smallvec",
"thiserror",
"thiserror 1.0.69",
"wasm-bindgen",
"web-sys",
"wgpu-types",

View File

@ -15,4 +15,6 @@ repository = "https://github.com/prometeu/runtime"
# The profile that 'dist' will build with
[profile.dist]
inherits = "release"
lto = "thin"
lto = true
codegen-units = 1
strip = "symbols"

View File

@ -2,6 +2,8 @@
name = "prometeu-bytecode"
version = "0.1.0"
edition = "2021"
license.workspace = true
repository.workspace = true
[dependencies]
# No dependencies for now

View File

@ -2,15 +2,26 @@
name = "prometeu-compiler"
version = "0.1.0"
edition = "2021"
license.workspace = true
repository.workspace = true
[[bin]]
name = "prometeu-compiler"
path = "src/main.rs"
[package.metadata.dist]
dist = true
include = ["../../VERSION.txt"]
[dependencies]
prometeu-bytecode = { path = "../prometeu-bytecode" }
prometeu-core = { path = "../prometeu-core" }
oxc_parser = "0.48.0"
oxc_allocator = "0.48.0"
oxc_ast = "0.48.0"
oxc_span = "0.48.0"
clap = { version = "4.4", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
oxc_parser = "0.110.0"
oxc_allocator = "0.110.0"
oxc_ast = "0.110.0"
oxc_ast_visit = "0.110.0"
oxc_span = "0.110.0"
clap = { version = "4.5.54", features = ["derive"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
anyhow = "1.0.100"

View File

@ -32,4 +32,9 @@ pub enum Commands {
#[arg(long, default_value_t = true)]
emit_symbols: bool,
},
/// Verifies a Prometeu project
Verify {
/// Project directory
project_dir: PathBuf,
},
}

View File

@ -53,6 +53,7 @@ impl Codegen {
// Entry point: loop calling tick
self.emit_label("entry".to_string());
self.emit_op(OpCode::Call, vec![Operand::Label("tick".to_string()), Operand::U32(0)], Span::default());
self.emit_op(OpCode::Pop, vec![], Span::default());
self.emit_op(OpCode::FrameSync, vec![], Span::default());
self.emit_op(OpCode::Jmp, vec![Operand::Label("entry".to_string())], Span::default());
@ -79,6 +80,12 @@ impl Codegen {
self.compile_stmt(stmt)?;
}
}
// ABI Rule: Every function MUST leave exactly one value on the stack before RET.
// If the function doesn't have a return statement, we push Null.
// For now, we always push Null at the end if it's not a return.
// In a more complex compiler, we would check if all paths return.
self.emit_op(OpCode::PushConst, vec![Operand::U32(0)], Span::default()); // Index 0 is Null in PBC
Ok(())
}
@ -86,7 +93,7 @@ impl Codegen {
match stmt {
Statement::VariableDeclaration(var) => {
for decl in &var.declarations {
if let BindingPatternKind::BindingIdentifier(ident) = &decl.id.kind {
if let BindingPattern::BindingIdentifier(ident) = &decl.id {
let name = ident.name.to_string();
if let Some(init) = &decl.init {
self.compile_expr(init)?;
@ -95,7 +102,6 @@ impl Codegen {
}
let id = self.next_local;
self.locals.insert(name, id);
self.emit_op(OpCode::SetLocal, vec![Operand::U32(id)], decl.span);
self.next_local += 1;
}
}

View File

@ -1,6 +1,5 @@
use oxc_ast::ast::*;
use oxc_ast::visit::walk;
use oxc_ast::Visit;
use oxc_ast_visit::{Visit, walk};
use oxc_span::GetSpan;
use anyhow::{Result, anyhow};
use crate::syscall_map;

View File

@ -0,0 +1,46 @@
pub mod cli;
pub mod codegen;
pub mod compiler;
pub mod syscall_map;
use clap::Parser;
use anyhow::Result;
pub fn run() -> Result<()> {
let cli = cli::Cli::parse();
match cli.command {
cli::Commands::Build {
project_dir,
entry,
out,
emit_disasm,
emit_symbols,
} => {
let entry = entry.unwrap_or_else(|| project_dir.join("src/main.ts"));
let build_dir = project_dir.join("build");
let out = out.unwrap_or_else(|| build_dir.join("program.pbc"));
if !build_dir.exists() {
std::fs::create_dir_all(&build_dir)?;
}
println!("Building project at {:?}", project_dir);
println!("Entry: {:?}", entry);
println!("Output: {:?}", out);
let compilation_unit = compiler::compile(&entry)?;
compilation_unit.export(&out, emit_disasm, emit_symbols)?;
}
cli::Commands::Verify { project_dir } => {
let entry = project_dir.join("src/main.ts");
println!("Verifying project at {:?}", project_dir);
println!("Entry: {:?}", entry);
compiler::compile(&entry)?;
println!("Project is valid!");
}
}
Ok(())
}

View File

@ -1,38 +1,5 @@
use clap::Parser;
use anyhow::Result;
pub mod cli;
pub mod codegen;
pub mod compiler;
pub mod syscall_map;
fn main() -> Result<()> {
let cli = cli::Cli::parse();
match cli.command {
cli::Commands::Build {
project_dir,
entry,
out,
emit_disasm,
emit_symbols,
} => {
let entry = entry.unwrap_or_else(|| project_dir.join("src/main.ts"));
let build_dir = project_dir.join("build");
let out = out.unwrap_or_else(|| build_dir.join("program.pbc"));
if !build_dir.exists() {
std::fs::create_dir_all(&build_dir)?;
}
println!("Building project at {:?}", project_dir);
println!("Entry: {:?}", entry);
println!("Output: {:?}", out);
let compilation_unit = compiler::compile(&entry)?;
compilation_unit.export(&out, emit_disasm, emit_symbols)?;
}
}
Ok(())
prometeu_compiler::run()
}

View File

@ -5,6 +5,6 @@ edition = "2024"
license.workspace = true
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
prometeu-bytecode = { path = "../prometeu-bytecode" }

View File

@ -325,23 +325,9 @@ impl PrometeuOS {
Ok(100)
}
pub fn get_color(&self, index: usize, hw: &mut dyn HardwareBridge) -> Color {
if let Some(bank) = hw.gfx().banks[0].as_ref() {
bank.palettes[0][index % 16]
} else {
match index % 16 {
0 => Color::BLACK,
1 => Color::WHITE,
2 => Color::RED,
3 => Color::GREEN,
4 => Color::BLUE,
5 => Color::YELLOW,
6 => Color::CYAN,
7 => Color::INDIGO,
8 => Color::GRAY,
_ => Color::BLACK,
}
}
pub fn get_color(&self, value: i64) -> Color {
// Agora usamos o valor diretamente como RGB565.
Color::from_raw(value as u16)
}
// Helper para syscalls
@ -464,6 +450,17 @@ mod tests {
assert!(cycles_after_tick_2 > cycles_after_tick_1, "VM should have consumed more cycles because FrameSync reset the budget");
}
#[test]
fn test_get_color_logic() {
let os = PrometeuOS::new(None);
// Deve retornar a cor raw diretamente
assert_eq!(os.get_color(0x07E0), Color::GREEN);
assert_eq!(os.get_color(0xF800), Color::RED);
assert_eq!(os.get_color(0x001F), Color::BLUE);
assert_eq!(os.get_color(3), Color::from_raw(3));
}
#[test]
fn test_syscall_log_write_and_rate_limit() {
let mut os = PrometeuOS::new(None);
@ -575,70 +572,70 @@ impl NativeInterface for PrometeuOS {
// gfx.clear(color_index) -> null
Syscall::GfxClear => {
let color_idx = vm.pop_integer()? as usize;
let color = self.get_color(color_idx, hw);
let color_val = vm.pop_integer()?;
let color = self.get_color(color_val);
hw.gfx_mut().clear(color);
vm.push(Value::Null);
Ok(100)
}
// gfx.draw_rect(x, y, w, h, color_index) -> null
Syscall::GfxFillRect => {
let color_idx = vm.pop_integer()? as usize;
let color_val = vm.pop_integer()?;
let h = vm.pop_integer()? as i32;
let w = vm.pop_integer()? as i32;
let y = vm.pop_integer()? as i32;
let x = vm.pop_integer()? as i32;
let color = self.get_color(color_idx, hw);
let color = self.get_color(color_val);
hw.gfx_mut().fill_rect(x, y, w, h, color);
vm.push(Value::Null);
Ok(200)
}
// gfx.draw_line(x1, y1, x2, y2, color_index) -> null
Syscall::GfxDrawLine => {
let color_idx = vm.pop_integer()? as usize;
let color_val = vm.pop_integer()?;
let y2 = vm.pop_integer()? as i32;
let x2 = vm.pop_integer()? as i32;
let y1 = vm.pop_integer()? as i32;
let x1 = vm.pop_integer()? as i32;
let color = self.get_color(color_idx, hw);
let color = self.get_color(color_val);
hw.gfx_mut().draw_line(x1, y1, x2, y2, color);
vm.push(Value::Null);
Ok(200)
}
// gfx.draw_circle(x, y, r, color_index) -> null
Syscall::GfxDrawCircle => {
let color_idx = vm.pop_integer()? as usize;
let color_val = vm.pop_integer()?;
let r = vm.pop_integer()? as i32;
let y = vm.pop_integer()? as i32;
let x = vm.pop_integer()? as i32;
let color = self.get_color(color_idx, hw);
let color = self.get_color(color_val);
hw.gfx_mut().draw_circle(x, y, r, color);
vm.push(Value::Null);
Ok(200)
}
// gfx.draw_disc(x, y, r, border_color_idx, fill_color_idx) -> null
Syscall::GfxDrawDisc => {
let fill_color_idx = vm.pop_integer()? as usize;
let border_color_idx = vm.pop_integer()? as usize;
let fill_color_val = vm.pop_integer()?;
let border_color_val = vm.pop_integer()?;
let r = vm.pop_integer()? as i32;
let y = vm.pop_integer()? as i32;
let x = vm.pop_integer()? as i32;
let fill_color = self.get_color(fill_color_idx, hw);
let border_color = self.get_color(border_color_idx, hw);
let fill_color = self.get_color(fill_color_val);
let border_color = self.get_color(border_color_val);
hw.gfx_mut().draw_disc(x, y, r, border_color, fill_color);
vm.push(Value::Null);
Ok(300)
}
// gfx.draw_square(x, y, w, h, border_color_idx, fill_color_idx) -> null
Syscall::GfxDrawSquare => {
let fill_color_idx = vm.pop_integer()? as usize;
let border_color_idx = vm.pop_integer()? as usize;
let fill_color_val = vm.pop_integer()?;
let border_color_val = vm.pop_integer()?;
let h = vm.pop_integer()? as i32;
let w = vm.pop_integer()? as i32;
let y = vm.pop_integer()? as i32;
let x = vm.pop_integer()? as i32;
let fill_color = self.get_color(fill_color_idx, hw);
let border_color = self.get_color(border_color_idx, hw);
let fill_color = self.get_color(fill_color_val);
let border_color = self.get_color(border_color_val);
hw.gfx_mut().draw_square(x, y, w, h, border_color, fill_color);
vm.push(Value::Null);
Ok(200)

View File

@ -19,4 +19,4 @@ winit = "0.30.12"
pixels = "0.15.0"
cpal = "0.15.3"
ringbuf = "0.4.7"
serde_json = "1.0"
serde_json = "1.0.149"

View File

@ -0,0 +1,84 @@
pub mod audio;
pub mod runner;
pub mod fs_backend;
pub mod log_sink;
pub mod debugger;
pub mod stats;
pub mod input;
pub mod cap;
pub mod utilities;
use runner::HostRunner;
use cap::load_cap_config;
use winit::event_loop::EventLoop;
use prometeu_core::firmware::BootTarget;
pub fn run() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = std::env::args().collect();
let mut fs_root = None;
let mut cap_config = None;
let mut cartridge_path = None;
let mut debug_mode = false;
let mut debug_port = 7777;
let mut i = 1; // Skip the executable name
while i < args.len() {
match args[i].as_str() {
"--run" => {
if i + 1 < args.len() {
cartridge_path = Some(args[i + 1].clone());
debug_mode = false;
i += 1;
}
}
"--debug" => {
if i + 1 < args.len() {
cartridge_path = Some(args[i + 1].clone());
debug_mode = true;
i += 1;
}
}
"--port" => {
if i + 1 < args.len() {
if let Ok(port) = args[i + 1].parse::<u16>() {
debug_port = port;
}
i += 1;
}
}
"--fs-root" => {
if i + 1 < args.len() {
fs_root = Some(args[i + 1].clone());
i += 1;
}
}
"--cap" => {
if i + 1 < args.len() {
cap_config = load_cap_config(&args[i + 1]);
i += 1;
}
}
_ => {}
}
i += 1;
}
let boot_target = if let Some(path) = cartridge_path {
BootTarget::Cartridge {
path,
debug: debug_mode,
debug_port: if debug_mode { debug_port } else { 7777 },
}
} else {
BootTarget::Hub
};
let event_loop = EventLoop::new()?;
let mut runner = HostRunner::new(fs_root, cap_config);
runner.set_boot_target(boot_target);
event_loop.run_app(&mut runner)?;
Ok(())
}

View File

@ -1,84 +1,3 @@
mod audio;
mod runner;
mod fs_backend;
mod log_sink;
mod debugger;
mod stats;
mod input;
mod cap;
mod utilities;
use crate::runner::HostRunner;
use crate::cap::load_cap_config;
use winit::event_loop::EventLoop;
use prometeu_core::firmware::BootTarget;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = std::env::args().collect();
let mut fs_root = None;
let mut cap_config = None;
let mut cartridge_path = None;
let mut debug_mode = false;
let mut debug_port = 7777;
let mut i = 1; // Skip the executable name
while i < args.len() {
match args[i].as_str() {
"--run" => {
if i + 1 < args.len() {
cartridge_path = Some(args[i + 1].clone());
debug_mode = false;
i += 1;
}
}
"--debug" => {
if i + 1 < args.len() {
cartridge_path = Some(args[i + 1].clone());
debug_mode = true;
i += 1;
}
}
"--port" => {
if i + 1 < args.len() {
if let Ok(port) = args[i + 1].parse::<u16>() {
debug_port = port;
}
i += 1;
}
}
"--fs-root" => {
if i + 1 < args.len() {
fs_root = Some(args[i + 1].clone());
i += 1;
}
}
"--cap" => {
if i + 1 < args.len() {
cap_config = load_cap_config(&args[i + 1]);
i += 1;
}
}
_ => {}
}
i += 1;
}
let boot_target = if let Some(path) = cartridge_path {
BootTarget::Cartridge {
path,
debug: debug_mode,
debug_port: if debug_mode { debug_port } else { 7777 },
}
} else {
BootTarget::Hub
};
let event_loop = EventLoop::new()?;
let mut runner = HostRunner::new(fs_root, cap_config);
runner.set_boot_target(boot_target);
event_loop.run_app(&mut runner)?;
Ok(())
prometeu_runtime_desktop::run()
}

View File

@ -11,16 +11,11 @@ path = "src/main.rs"
[[bin]]
name = "prometeu-runtime"
path = "../prometeu-runtime-desktop/src/main.rs"
path = "src/bin/prometeu-runtime.rs"
# Future binaries (commented)
# [[bin]]
# name = "prometeu-compiler"
# path = "../prometeu-compiler/src/main.rs"
#
# [[bin]]
# name = "prometeup"
# path = "../prometeup/src/main.rs"
[[bin]]
name = "prometeuc"
path = "src/bin/prometeuc.rs"
[package.metadata.dist]
dist = true
@ -31,9 +26,6 @@ include = [
[dependencies]
clap = { version = "4.5", features = ["derive"] }
prometeu-core = { path = "../prometeu-core" }
winit = "0.30.12"
pixels = "0.15.0"
cpal = "0.15.3"
ringbuf = "0.4.7"
serde_json = "1.0"
prometeu-runtime-desktop = { path = "../prometeu-runtime-desktop" }
prometeu-compiler = { path = "../prometeu-compiler" }
anyhow = "1.0.100"

View File

@ -6,8 +6,10 @@ The `prometeu` binary acts as the unified front-end for the ecosystem. It does n
- `prometeu run <cart>`: Runs a cartridge using the available runtime.
- `prometeu debug <cart> [--port <p>]`: Starts execution in debug mode.
- `prometeu build <projectDir>`: (Planned) Calls the `prometeuc` compiler.
- `prometeu build <projectDir>`: Calls the `prometeuc` compiler.
- `prometeu verify c <projectDir>`: Calls the `prometeuc` compiler.
- `prometeu pack <cartDir>`: (Planned) Calls the `prometeup` packager.
- `prometeu verify p <cartDir>`: (Planned) Calls the `prometeup` packager.
## How it works

View File

@ -0,0 +1 @@
fn main() -> Result<(), Box<dyn std::error::Error>> { prometeu_runtime_desktop::run() }

View File

@ -0,0 +1 @@
fn main() -> anyhow::Result<()> { prometeu_compiler::run() }

View File

@ -86,14 +86,16 @@ fn main() {
&["--debug", &cart, "--port", &port.to_string()],
);
}
Some(Commands::Build { .. }) => {
not_implemented("build", "prometeu-compiler");
Some(Commands::Build { project_dir }) => {
dispatch(&exe_dir, "prometeuc", &["build", &project_dir]);
}
Some(Commands::Pack { .. }) => {
not_implemented("pack", "prometeup");
}
Some(Commands::Verify { target }) => match target {
VerifyCommands::C { .. } => not_implemented("verify c", "prometeu-compiler"),
VerifyCommands::C { project_dir } => {
dispatch(&exe_dir, "prometeuc", &["verify", &project_dir]);
}
VerifyCommands::P { .. } => not_implemented("verify p", "prometeup"),
},
None => {
@ -119,8 +121,8 @@ fn dispatch(exe_dir: &Path, bin_name: &str, args: &[&str]) {
eprintln!(
"prometeu: command '{}' is not yet available in this distribution on {}",
match bin_name {
"prometeu-runtime-desktop" => "run/debug",
"prometeu-compiler" => "build/verify c",
"prometeu-runtime" => "run/debug",
"prometeuc" => "build/verify c",
"prometeup" => "pack/verify p",
_ => bin_name,
}, exe_dir.display()

View File

@ -15,4 +15,4 @@ targets = ["aarch64-apple-darwin", "x86_64-apple-darwin"]
unix-archive = ".zip"
macos-universal-binaries = true
[dist.hooks]
pre-build = ["./scripts/gen-version.sh"]
pre-build = ["./scripts/pre-dist.sh"]

View File

@ -1,8 +1,8 @@
export function tick(): void {
let color = 0x07E0; // green
if (input.btnA()) color = 0xF800; // red
if (input.btnB()) color = 0x001F; // blue
if (Input.btnA()) color = 0xF800; // red
if (Input.btnB()) color = 0x001F; // blue
gfx.fillRect(60, 60, 40, 40, color);
Gfx.fillRect(60, 60, 40, 40, color);
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
# Get version from git tag or fallback to Cargo.toml version
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || grep -m 1 '^version =' crates/prometeu-runtime-desktop/Cargo.toml | cut -d '"' -f 2 || echo "0.1.0")
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || grep -m 1 '^version =' crates/prometeu/Cargo.toml | cut -d '"' -f 2 || echo "0.1.0")
echo "$VERSION" > VERSION.txt
echo "Generated VERSION.txt with version $VERSION"

View File

@ -1,5 +1,7 @@
#!/bin/bash
set -e
# Generate version
./scripts/gen-version.sh
VERSION=$(cat VERSION.txt)