obfucated names and updated stdio printf
This commit is contained in:
@@ -16,3 +16,4 @@ dirs = "5.0.1"
|
|||||||
pest = "2"
|
pest = "2"
|
||||||
pest_derive = "2.1"
|
pest_derive = "2.1"
|
||||||
clap = "3"
|
clap = "3"
|
||||||
|
hex = "0.4"
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Wyst stdlib
|
||||||
|
|
||||||
|
## > [!NOTE]
|
||||||
|
> any changes made here should be documented before pushed to master
|
||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! printf {
|
|
||||||
|
macro_rules! _0x7072696e7466 {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
println!($($arg)*);
|
print!($($arg)*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+15
-4
@@ -1,5 +1,5 @@
|
|||||||
use std::{fs, path::Path, process::Command};
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::{fs, path::Path, process::Command};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
transpiler::{State, Transpiler},
|
transpiler::{State, Transpiler},
|
||||||
@@ -16,7 +16,10 @@ pub fn transpile_file(input_file: String, output_file: String, is_main: bool) ->
|
|||||||
let mut output_code = String::new();
|
let mut output_code = String::new();
|
||||||
match trsp.transpile_code(file_contents, 0) {
|
match trsp.transpile_code(file_contents, 0) {
|
||||||
Ok(rcode) => output_code += rcode.as_str(),
|
Ok(rcode) => output_code += rcode.as_str(),
|
||||||
Err(e) => {ecode=1;println!("{e}")}
|
Err(e) => {
|
||||||
|
ecode = 1;
|
||||||
|
println!("{e}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if is_main {
|
if is_main {
|
||||||
for module in trsp.clone().mod_manager.modules {
|
for module in trsp.clone().mod_manager.modules {
|
||||||
@@ -25,7 +28,12 @@ pub fn transpile_file(input_file: String, output_file: String, is_main: bool) ->
|
|||||||
module_code += ";\n";
|
module_code += ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output_code = format!("{module_code}\n{output_code}");
|
output_code = format!(
|
||||||
|
"{module_code}\n{output_code}\nfn main() {}{}{}",
|
||||||
|
"{_0x",
|
||||||
|
hex::encode("main"),
|
||||||
|
"();}"
|
||||||
|
);
|
||||||
if let Ok(_) = fs::write(Path::new("build").join(output_file), output_code) {
|
if let Ok(_) = fs::write(Path::new("build").join(output_file), output_code) {
|
||||||
trsp.problems.append(&mut trsp.mod_manager.write());
|
trsp.problems.append(&mut trsp.mod_manager.write());
|
||||||
}
|
}
|
||||||
@@ -74,6 +82,9 @@ pub fn compile_rust(exe_file: String) {
|
|||||||
if &output.stderr.len() == &0 {
|
if &output.stderr.len() == &0 {
|
||||||
println!("Compiled successfully: \x1b[34;4m{}", exe_file.clone());
|
println!("Compiled successfully: \x1b[34;4m{}", exe_file.clone());
|
||||||
} else {
|
} else {
|
||||||
println!("{}", str::from_utf8(&output.stderr).expect("Error encoding stderr"));
|
println!(
|
||||||
|
"{}",
|
||||||
|
str::from_utf8(&output.stderr).expect("Error encoding stderr")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-22
@@ -1,9 +1,9 @@
|
|||||||
use pest::iterators::{Pair, Pairs};
|
|
||||||
use crate::utils::{ModManager, ProblemCap};
|
use crate::utils::{ModManager, ProblemCap};
|
||||||
|
use pest::iterators::{Pair, Pairs};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// The Parser
|
// The Parser
|
||||||
use pest::{Parser, error::Error};
|
use pest::{error::Error, Parser};
|
||||||
use pest_derive::Parser;
|
use pest_derive::Parser;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[grammar = "wyst.pest"]
|
#[grammar = "wyst.pest"]
|
||||||
@@ -61,9 +61,10 @@ impl Default for Transpiler {
|
|||||||
|
|
||||||
pub fn to_indexable(pairs: Pairs<Rule>) -> Vec<Pair<Rule>> {
|
pub fn to_indexable(pairs: Pairs<Rule>) -> Vec<Pair<Rule>> {
|
||||||
let mut arr: Vec<Pair<Rule>> = Vec::new();
|
let mut arr: Vec<Pair<Rule>> = Vec::new();
|
||||||
for pair in pairs {arr.push(pair)}
|
for pair in pairs {
|
||||||
|
arr.push(pair)
|
||||||
|
}
|
||||||
arr
|
arr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transpiler {
|
impl Transpiler {
|
||||||
@@ -79,11 +80,15 @@ impl Transpiler {
|
|||||||
let tokens = to_indexable(pair.clone().into_inner());
|
let tokens = to_indexable(pair.clone().into_inner());
|
||||||
match pair.as_rule() {
|
match pair.as_rule() {
|
||||||
Rule::func_def => {
|
Rule::func_def => {
|
||||||
res += format!("pub fn {}({}) -> {} {}\n", self.transpile(tokens[1].clone()),
|
res += format!(
|
||||||
self.transpile_pairs(tokens[2].clone().into_inner()).as_str(),
|
"pub fn {}({}) -> {} {}\n",
|
||||||
|
self.transpile(tokens[1].clone()),
|
||||||
|
self.transpile_pairs(tokens[2].clone().into_inner())
|
||||||
|
.as_str(),
|
||||||
self.transpile(tokens[0].clone()),
|
self.transpile(tokens[0].clone()),
|
||||||
self.transpile(tokens[3].clone())
|
self.transpile(tokens[3].clone())
|
||||||
).as_str();
|
)
|
||||||
|
.as_str();
|
||||||
}
|
}
|
||||||
Rule::var_def => {
|
Rule::var_def => {
|
||||||
res += format!("let mut {}: {}", tokens[1].as_str(), tokens[0].as_str()).as_str();
|
res += format!("let mut {}: {}", tokens[1].as_str(), tokens[0].as_str()).as_str();
|
||||||
@@ -99,36 +104,35 @@ impl Transpiler {
|
|||||||
|
|
||||||
Rule::include_global => {
|
Rule::include_global => {
|
||||||
res += "#[allow(unused_imports)]\nuse ";
|
res += "#[allow(unused_imports)]\nuse ";
|
||||||
res += self.mod_manager.add(tokens[0].as_str().to_string(), true).as_str();
|
res += self
|
||||||
|
.mod_manager
|
||||||
|
.add(tokens[0].as_str().to_string(), true)
|
||||||
|
.as_str();
|
||||||
res += "::*;\n";
|
res += "::*;\n";
|
||||||
}
|
}
|
||||||
Rule::include => {
|
Rule::include => {
|
||||||
res += "#[allow(unused_imports)]\nuse ";
|
res += "#[allow(unused_imports)]\nuse ";
|
||||||
res += self.mod_manager.add(tokens[0].as_str().to_string(), false).as_str();
|
res += self
|
||||||
|
.mod_manager
|
||||||
|
.add(tokens[0].as_str().to_string(), false)
|
||||||
|
.as_str();
|
||||||
res += "::*;\n";
|
res += "::*;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule::identifier => {
|
Rule::identifier | Rule::def_identifier => {
|
||||||
let ident = pair.as_str().trim();
|
let ident = pair.as_str().trim();
|
||||||
if self.mod_manager.macros.contains(&ident.to_string()) {
|
let ident_rs = format!("_0x{}", hex::encode(ident.as_bytes()));
|
||||||
res+=ident;
|
if self.mod_manager.macros.contains(&ident_rs) {
|
||||||
|
res += ident_rs.as_str();
|
||||||
res += "!";
|
res += "!";
|
||||||
} else {
|
} else {
|
||||||
res += match ident {
|
res += match ident {
|
||||||
"void" => {"()"}
|
"void" => "()",
|
||||||
_ => {ident}
|
_ => ident_rs.as_str(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule::def_identifier => {
|
|
||||||
let ident = pair.as_str().trim();
|
|
||||||
res+=match ident {
|
|
||||||
"void" => {"()"}
|
|
||||||
_ => {ident}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::call => {
|
Rule::call => {
|
||||||
res += " ";
|
res += " ";
|
||||||
res += self.transpile(tokens[0].clone()).as_str();
|
res += self.transpile(tokens[0].clone()).as_str();
|
||||||
|
|||||||
Reference in New Issue
Block a user