dll alpha_01
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
use std::{
|
|
||||||
fs::File,
|
|
||||||
io::{BufReader, Read},
|
|
||||||
};
|
|
||||||
|
|
||||||
use zip::{read::ZipFile, ZipArchive};
|
|
||||||
|
|
||||||
use crate::variable::Variables;
|
|
||||||
|
|
||||||
pub fn read_dll(dll_path: String) -> Variables {
|
|
||||||
let mut vars = Variables::new();
|
|
||||||
let dll_file = File::open(dll_path).expect("err_dll_read");
|
|
||||||
let dll_reader = BufReader::new(dll_file);
|
|
||||||
let mut dll_zip = ZipArchive::new(dll_reader).expect("err_archive");
|
|
||||||
for i in 0..dll_zip.len() {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
let mut file = dll_zip.by_index(i).expect("err_dll_idx");
|
|
||||||
let filename = file.name();
|
|
||||||
if filename == "map.json" && file.is_file() {
|
|
||||||
file.read_to_end(&mut buf).expect("err_read_zip_file");
|
|
||||||
println!(
|
|
||||||
"Filename: {}\nFileContents: {}",
|
|
||||||
file.name(),
|
|
||||||
String::from_utf8_lossy(&buf)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vars
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use crate::{dll_reader::read_dll, transpiler::Transpiler, variable::Variables};
|
use crate::{dllmgr::read_dll, transpiler::Transpiler, variable::Variables};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
|
|||||||
+5
-2
@@ -1,7 +1,8 @@
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use serde::Serialize;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy, Serialize)]
|
||||||
pub struct LexerState {
|
pub struct LexerState {
|
||||||
pub line: usize,
|
pub line: usize,
|
||||||
pub column: usize,
|
pub column: usize,
|
||||||
@@ -88,7 +89,9 @@ const SYNTAX: [Node; 16] = [
|
|||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Keyword1,
|
token_type: TokenType::Keyword1,
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^(impl|namespace|if|for|while|else *if)\b").unwrap()),
|
token_regex: Lazy::new(|| {
|
||||||
|
Regex::new(r"^(impl|namespace|if|for|while|else *if)\b").unwrap()
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Keyword2,
|
token_type: TokenType::Keyword2,
|
||||||
|
|||||||
+47
-26
@@ -1,5 +1,5 @@
|
|||||||
mod compile;
|
mod compile;
|
||||||
mod dll_reader;
|
mod dllmgr;
|
||||||
mod file_writer;
|
mod file_writer;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
mod lsp;
|
mod lsp;
|
||||||
@@ -10,19 +10,21 @@ mod variable;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::{fs, path::Path};
|
use std::{fs, path::Path};
|
||||||
use transpiler::Transpiler;
|
use transpiler::Transpiler;
|
||||||
use variable::Variables;
|
use variable::{Variable, Variables};
|
||||||
|
|
||||||
use crate::lsp::run_lsp_server;
|
use crate::lsp::run_lsp_server;
|
||||||
|
|
||||||
// Arguments for Wyst (short and long version)
|
// Arguments for Wyst (short and long version)
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[clap(short, long)]
|
//#[clap(short, long)]
|
||||||
rust: Option<String>,
|
//rust: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
compile: Option<String>,
|
compile: Option<String>,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
dll: Option<String>,
|
||||||
|
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
stdio: bool,
|
stdio: bool,
|
||||||
}
|
}
|
||||||
@@ -34,6 +36,8 @@ fn main() {
|
|||||||
run_lsp_server();
|
run_lsp_server();
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
|
match args.compile {
|
||||||
|
Some(ref exe_name) => {
|
||||||
let file_content = fs::read_to_string("main.wt").expect("Error reading file");
|
let file_content = fs::read_to_string("main.wt").expect("Error reading file");
|
||||||
if Path::new("build").exists() {
|
if Path::new("build").exists() {
|
||||||
fs::remove_dir_all("build").expect("err rm build");
|
fs::remove_dir_all("build").expect("err rm build");
|
||||||
@@ -49,29 +53,8 @@ fn main() {
|
|||||||
for problem in trsp.problems {
|
for problem in trsp.problems {
|
||||||
println!("{}", problem.problem_msg)
|
println!("{}", problem.problem_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
trsp.writer.write();
|
trsp.writer.write();
|
||||||
|
|
||||||
match args.rust {
|
|
||||||
Some(ref rust_file_name) => {
|
|
||||||
// Write transpiled code to Rust file
|
|
||||||
compile::write_to_rust_file(
|
|
||||||
&transpiled_code,
|
|
||||||
("build/".to_string() + "main.rs").as_str(),
|
|
||||||
)
|
|
||||||
.expect("Error writing to Rust file");
|
|
||||||
println!("Transpiled code written to {}", rust_file_name);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// No Rust file specified, print transpiled code
|
|
||||||
if !args.compile.is_some() {
|
|
||||||
println!("{}", transpiled_code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match args.compile {
|
|
||||||
Some(ref exe_name) => {
|
|
||||||
compile::write_to_rust_file(&transpiled_code, "build/main.rs")
|
compile::write_to_rust_file(&transpiled_code, "build/main.rs")
|
||||||
.expect("Error writing to temporary Rust file");
|
.expect("Error writing to temporary Rust file");
|
||||||
std::env::set_current_dir("build").expect("setDir err: ");
|
std::env::set_current_dir("build").expect("setDir err: ");
|
||||||
@@ -84,6 +67,44 @@ fn main() {
|
|||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
match args.dll {
|
||||||
|
Some(ref dll_path) => {
|
||||||
|
let file_content = fs::read_to_string("lib.wt").expect("Error reading file");
|
||||||
|
if Path::new("build").exists() {
|
||||||
|
fs::remove_dir_all("build").expect("err rm build");
|
||||||
|
}
|
||||||
|
fs::create_dir("build").expect("error making build");
|
||||||
|
let mut trsp = Transpiler::default();
|
||||||
|
let mut vars = Variables::new();
|
||||||
|
let transpiled_code = trsp.transpile(file_content, 0, &mut vars);
|
||||||
|
for problem in trsp.problems {
|
||||||
|
println!("{}", problem.problem_msg)
|
||||||
|
}
|
||||||
|
trsp.writer.write();
|
||||||
|
let mut dll_main = String::from("fn call_fn(params: Vec<Param>){");
|
||||||
|
for (name, var) in vars.vars.clone() {
|
||||||
|
let mut dparams = String::new();
|
||||||
|
for i in 0..var.params.vars.len() {
|
||||||
|
dparams += format!("params.get({}).expect(\"Err_prms\"),", i).as_str();
|
||||||
|
}
|
||||||
|
dll_main += format!(
|
||||||
|
"\"{}\" => {}return {}({dparams});{}",
|
||||||
|
name, "{", var.rname, "}"
|
||||||
|
)
|
||||||
|
.as_str();
|
||||||
|
}
|
||||||
|
dll_main += "}";
|
||||||
|
compile::write_to_rust_file(&transpiled_code, "build/wslib.rs")
|
||||||
|
.expect("Error writing to temporary Rust file");
|
||||||
|
compile::write_to_rust_file(&dll_main, "build/main.rs")
|
||||||
|
.expect("Error writing to main dll");
|
||||||
|
std::env::set_current_dir("build").expect("setDir err: ");
|
||||||
|
compile::compile_to_executable("run").expect("Error compiling to executable");
|
||||||
|
dllmgr::write_dll(vars, "run".to_string(), dll_path.to_string());
|
||||||
|
// fs::remove_dir_all("build").expect("err rm build");
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
lexer::LexerState,
|
lexer::LexerState,
|
||||||
@@ -8,7 +9,7 @@ use crate::{
|
|||||||
transpiler::Transpiler,
|
transpiler::Transpiler,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug, Serialize)]
|
||||||
pub enum VariableType {
|
pub enum VariableType {
|
||||||
Var,
|
Var,
|
||||||
Func,
|
Func,
|
||||||
@@ -17,7 +18,7 @@ pub enum VariableType {
|
|||||||
Namespace,
|
Namespace,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct Variable {
|
pub struct Variable {
|
||||||
pub vtype: VariableType,
|
pub vtype: VariableType,
|
||||||
pub desc: String,
|
pub desc: String,
|
||||||
@@ -26,7 +27,7 @@ pub struct Variable {
|
|||||||
pub rname: String,
|
pub rname: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct Variables {
|
pub struct Variables {
|
||||||
pub vars: HashMap<String, Variable>,
|
pub vars: HashMap<String, Variable>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user