fix variables as well as replace build script with rust version for cross-platform compatibility (thanks LoganDark)
This commit is contained in:
parent
c0ffee6d5f
commit
9f5c78ca64
5 changed files with 297 additions and 32 deletions
267
Cargo.lock
generated
267
Cargo.lock
generated
|
@ -2,6 +2,273 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "built"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f346b6890a0dfa7266974910e7df2d5088120dd54721b9b0e5aae1ae5e05715"
|
||||
dependencies = [
|
||||
"cargo-lock",
|
||||
"git2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cargo-lock"
|
||||
version = "7.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fb04b88bd5b2036e30704f95c6ee16f3b5ca3b4ca307da2889d9006648e5c88"
|
||||
dependencies = [
|
||||
"semver",
|
||||
"serde",
|
||||
"toml",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git2"
|
||||
version = "0.13.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
"libgit2-sys",
|
||||
"log",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.116"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
|
||||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
version = "0.12.26+1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"libz-sys",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lintc"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"built",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.136"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.136"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
[package]
|
||||
name = "lintc"
|
||||
version = "0.1.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
built = { version = "0.5", features = ["git2"] }
|
||||
|
||||
[dependencies]
|
||||
|
|
4
build.rs
Normal file
4
build.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
eprintln!("Building lintc...");
|
||||
built::write_built_file().expect("Failed to acquire build-time information")
|
||||
}
|
20
build.sh
20
build.sh
|
@ -1,20 +0,0 @@
|
|||
#!/bin/sh
|
||||
export debug="false"
|
||||
export version="0.2"
|
||||
if [ $debug = "true" ]; then
|
||||
echo "NOTE: This is going to be a development build. Please make sure you downloaded the point version from the 'about' tab if you wanted a stabler version."
|
||||
sed -i "s/VERZON/$version-$(git rev-parse HEAD)/g" src/main.rs
|
||||
cargo build
|
||||
sed -i "s/$version-$(git rev-parse HEAD)/VERZON/g" src/main.rs
|
||||
mv target/debug/lintc .
|
||||
echo "Built. Binary stored at lintc in current directory."
|
||||
fi
|
||||
|
||||
if [ $debug = "false" ]; then
|
||||
echo "Building point version."
|
||||
sed -i "s/VERZON/$version/g" src/main.rs
|
||||
cargo build --release
|
||||
sed -i "s/$version/VERZON/g" src/main.rs
|
||||
mv target/release/lintc .
|
||||
echo "Built. Binary stored at lintc in current directory."
|
||||
fi
|
32
src/main.rs
32
src/main.rs
|
@ -3,6 +3,15 @@ use std::fs::File;
|
|||
use std::env;
|
||||
use std::process;
|
||||
|
||||
pub mod built_info {
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
}
|
||||
|
||||
fn builtinf() {
|
||||
println!("This is version {}, built for {}", built_info::PKG_VERSION, built_info::TARGET);
|
||||
if let (Some(v), Some(hash)) = (built_info::GIT_VERSION, built_info::GIT_COMMIT_HASH,) { println!("It is tagged {}, commit {}",v, hash); }
|
||||
}
|
||||
|
||||
fn load_macro(set: String, mac: String, inputs: String, vars: Vec<String>) -> String {
|
||||
let mut file = File::open(format!("macros/{}/{}", set, mac)).expect("Unable to open macro");
|
||||
let mut contents = String::new();
|
||||
|
@ -21,7 +30,7 @@ fn load_macro(set: String, mac: String, inputs: String, vars: Vec<String>) -> St
|
|||
let mut locofjeff = 1;
|
||||
while end != 1 {
|
||||
if jeff[locofjeff].contains("![[hex]]") {
|
||||
contents = contents.replace("[0]", &format!("#{}",jeff[1]));
|
||||
contents = contents.replace(&format!("[{}]",cvar.to_string()), &format!("#{}",jeff[locofjeff]));
|
||||
contents = contents.replace("![[hex]]", "");
|
||||
} else if jeff[locofjeff].contains("var!") {
|
||||
let jazz: Vec<&str> = jeff[locofjeff].split("var!").collect();
|
||||
|
@ -39,20 +48,20 @@ fn load_macro(set: String, mac: String, inputs: String, vars: Vec<String>) -> St
|
|||
println!("ERROR: Reference to variable {} not assigned.", jazz[1]);
|
||||
process::exit(1);
|
||||
}
|
||||
contents = contents.replace(&format!("[{}]", cvar), &format!(".{} LDZ",i.to_string()));
|
||||
contents = contents.replace(&format!("[{}]", cvar.to_string()), &format!(".{} LDZ",i.to_string()));
|
||||
contents = contents.replace("var!","");
|
||||
} else {
|
||||
let mut zard: Vec<String> = [].to_vec();
|
||||
for n in jeff[locofjeff].chars() {
|
||||
let chard = str_to_hex(n);
|
||||
zard.push(contents.replace(&format!("[{}]", cvar), &format!("#{}",chard)));
|
||||
zard.push(contents.replace(&format!("[{}]", cvar.to_string()), &format!("#{}",chard)));
|
||||
}
|
||||
for charl in zard {
|
||||
keg.push_str(&format!("{}",&charl));
|
||||
}
|
||||
contents = keg.to_string();
|
||||
}
|
||||
if contents.contains(&format!("[{}]", cvar + 1)) {
|
||||
if contents.contains(&format!("[{}]", (cvar + 1).to_string())) {
|
||||
cvar = cvar + 1;
|
||||
locofjeff = locofjeff + 2;
|
||||
} else {
|
||||
|
@ -77,11 +86,11 @@ fn load_macro(set: String, mac: String, inputs: String, vars: Vec<String>) -> St
|
|||
|
||||
fn determine_device(line: String) -> String {
|
||||
let mut device = "";
|
||||
if line.contains("console") { device = "|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]"; }
|
||||
else if line.contains("system") { device = "|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]"; }
|
||||
else if line.contains("screen") { device = "|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]"; }
|
||||
else if line.contains("controller") { device = "|80 @Controller [ &vector $2 &button $1 &key $1 ]"; }
|
||||
else if line.contains("mouse") { device = "|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 ]"; }
|
||||
if line.contains("console") { device = "|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]\n"; }
|
||||
else if line.contains("system") { device = "|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]\n"; }
|
||||
else if line.contains("screen") { device = "|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]\n"; }
|
||||
else if line.contains("controller") { device = "|80 @Controller [ &vector $2 &button $1 &key $1 ]\n"; }
|
||||
else if line.contains("mouse") { device = "|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 ]\n"; }
|
||||
return device.to_string();
|
||||
}
|
||||
|
||||
|
@ -116,7 +125,7 @@ fn parse(code: String) -> String {
|
|||
} else if line.contains("var.") {
|
||||
let name: Vec<&str> = line.split("var.").collect();
|
||||
let value: Vec<&str> = name[1].split("=").collect();
|
||||
if vars.contains(&value[0].to_string()) {
|
||||
if !vars.contains(&value[0].to_string()) {
|
||||
blocks[2].push_str(&format!("@{}\n",counter.to_string()));
|
||||
vars.push(format!("{}",value[0]));
|
||||
blocks[3].push_str(&format!("LIT {} .{} STZ\n", value[1], counter.to_string()));
|
||||
|
@ -149,10 +158,11 @@ fn parse(code: String) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
return format!("(generated by lintc {})\n{}\n{}\n|0000\n{}\n|0100\n{}", version, blocks[0], blocks[1], blocks[2], blocks[3]).to_string();
|
||||
return format!("{}\n{}\n|0000\n{}\n|0100\n{}", blocks[0], blocks[1], blocks[2], blocks[3]).to_string();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
builtinf();
|
||||
let args: Vec<String> = env::args().collect();
|
||||
println!("Reading file {}", &args[1]);
|
||||
let code = load_source(args[1].to_string());
|
||||
|
|
Reference in a new issue