mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 15:05:33 +00:00
add compile flag
This commit is contained in:
@ -14,4 +14,7 @@ pub struct Args {
|
|||||||
|
|
||||||
#[clap(short, long, takes_value = false)]
|
#[clap(short, long, takes_value = false)]
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
|
|
||||||
|
#[clap(short, long, takes_value = false)]
|
||||||
|
pub compile: bool,
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs,
|
fs::{self, File},
|
||||||
io::{BufRead, BufReader, Write},
|
io::{BufRead, BufReader, Read, Write},
|
||||||
net::TcpStream,
|
net::TcpStream,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
args::Args,
|
args::Args,
|
||||||
config::Config,
|
config::{Config, ConfigFile},
|
||||||
elliptic_curve::encryption::Encryption,
|
elliptic_curve::encryption::Encryption,
|
||||||
gpsl::{
|
gpsl::{
|
||||||
self,
|
self,
|
||||||
@ -21,18 +23,49 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn start_client(args: Args) {
|
pub fn start_client(args: Args) {
|
||||||
let mut source =
|
let file = args.file.clone().unwrap();
|
||||||
Source::new(fs::read_to_string(&(args.file.unwrap())).expect("Cannot read file."));
|
let file_name = {
|
||||||
|
let file_name = file.file_name();
|
||||||
let mut tokenizer = Tokenizer::new();
|
file_name.unwrap().to_string_lossy()
|
||||||
tokenizer.tokenize(&mut source).unwrap();
|
|
||||||
|
|
||||||
let mut parser = gpsl::parser::Parser {
|
|
||||||
tokenizer,
|
|
||||||
local_vars: HashMap::new(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let functions = parser.functions().unwrap();
|
let functions = {
|
||||||
|
if file_name.ends_with(".o") {
|
||||||
|
let mut file = fs::File::open(args.file.clone().unwrap()).unwrap();
|
||||||
|
let mut contents = Vec::new();
|
||||||
|
file.read_to_end(&mut contents).unwrap();
|
||||||
|
let mut d = ZlibDecoder::new(&contents[..]);
|
||||||
|
let mut s = String::new();
|
||||||
|
d.read_to_string(&mut s).unwrap();
|
||||||
|
|
||||||
|
serde_json::from_str(&s).unwrap()
|
||||||
|
} else {
|
||||||
|
let mut source = Source::new(
|
||||||
|
fs::read_to_string(&(args.file.clone().unwrap())).expect("Cannot read file."),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut tokenizer = Tokenizer::new();
|
||||||
|
tokenizer.tokenize(&mut source).unwrap();
|
||||||
|
|
||||||
|
let mut parser = gpsl::parser::Parser {
|
||||||
|
tokenizer,
|
||||||
|
local_vars: HashMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
parser.functions().unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if args.compile {
|
||||||
|
let functions = serde_json::to_string(&functions).unwrap();
|
||||||
|
|
||||||
|
let mut file = File::create(format!("{}.o", file_name)).unwrap();
|
||||||
|
let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
|
||||||
|
e.write_all(functions.as_bytes()).unwrap();
|
||||||
|
file.write_all(&e.finish().unwrap()).unwrap();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut server_functions: HashMap<String, HashMap<String, Box<Node>>> = HashMap::new();
|
let mut server_functions: HashMap<String, HashMap<String, Box<Node>>> = HashMap::new();
|
||||||
for function in functions.clone() {
|
for function in functions.clone() {
|
||||||
@ -105,7 +138,6 @@ pub fn start_client(args: Args) {
|
|||||||
let config = Config::read_or_create();
|
let config = Config::read_or_create();
|
||||||
|
|
||||||
let mut gpsl = GPSL::new(
|
let mut gpsl = GPSL::new(
|
||||||
source,
|
|
||||||
Some(functions),
|
Some(functions),
|
||||||
Some(server_functions),
|
Some(server_functions),
|
||||||
Some(servers),
|
Some(servers),
|
||||||
|
@ -6,7 +6,6 @@ use crate::gpsl::external_function::{
|
|||||||
use crate::gpsl::gpsl_type::GPSLType;
|
use crate::gpsl::gpsl_type::GPSLType;
|
||||||
use crate::gpsl::node::*;
|
use crate::gpsl::node::*;
|
||||||
use crate::gpsl::permission::Permission;
|
use crate::gpsl::permission::Permission;
|
||||||
use crate::gpsl::source::Source;
|
|
||||||
use crate::gpsl::variable::*;
|
use crate::gpsl::variable::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
use primitive_types::U512;
|
use primitive_types::U512;
|
||||||
@ -34,7 +33,6 @@ pub struct GPSL {
|
|||||||
pub private_key: Option<U512>,
|
pub private_key: Option<U512>,
|
||||||
pub public_key: Option<EllipticCurvePoint>,
|
pub public_key: Option<EllipticCurvePoint>,
|
||||||
pub global_variables: Vec<Variable>,
|
pub global_variables: Vec<Variable>,
|
||||||
pub source: Source,
|
|
||||||
pub blocks: VecDeque<Block>,
|
pub blocks: VecDeque<Block>,
|
||||||
pub external_func: Vec<
|
pub external_func: Vec<
|
||||||
fn(
|
fn(
|
||||||
@ -73,7 +71,6 @@ impl VariableStatus {
|
|||||||
|
|
||||||
impl GPSL {
|
impl GPSL {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
source: Source,
|
|
||||||
functions: Option<HashMap<String, Box<Node>>>,
|
functions: Option<HashMap<String, Box<Node>>>,
|
||||||
server_functions: Option<HashMap<String, HashMap<String, Box<Node>>>>,
|
server_functions: Option<HashMap<String, HashMap<String, Box<Node>>>>,
|
||||||
servers: Option<HashMap<String, Arc<Mutex<TcpStream>>>>,
|
servers: Option<HashMap<String, Arc<Mutex<TcpStream>>>>,
|
||||||
@ -91,7 +88,6 @@ impl GPSL {
|
|||||||
>,
|
>,
|
||||||
) -> GPSL {
|
) -> GPSL {
|
||||||
GPSL {
|
GPSL {
|
||||||
source,
|
|
||||||
functions,
|
functions,
|
||||||
server_functions,
|
server_functions,
|
||||||
servers,
|
servers,
|
||||||
|
@ -8,7 +8,6 @@ use crate::args::Args;
|
|||||||
use crate::elliptic_curve::encryption::Encryption;
|
use crate::elliptic_curve::encryption::Encryption;
|
||||||
use crate::gpsl::external_function::{ExternalFuncReturn, ExternalFuncStatus, STD_FUNC};
|
use crate::gpsl::external_function::{ExternalFuncReturn, ExternalFuncStatus, STD_FUNC};
|
||||||
use crate::gpsl::node::Node;
|
use crate::gpsl::node::Node;
|
||||||
use crate::gpsl::source::Source;
|
|
||||||
use crate::gpsl::vm::gpsl::{ServerFunctionCall, GPSL};
|
use crate::gpsl::vm::gpsl::{ServerFunctionCall, GPSL};
|
||||||
|
|
||||||
fn listen_tcp_server(port: u16) -> TcpStream {
|
fn listen_tcp_server(port: u16) -> TcpStream {
|
||||||
@ -41,7 +40,6 @@ pub fn start_server(args: Args) {
|
|||||||
debug!("Received: {:?}", functions);
|
debug!("Received: {:?}", functions);
|
||||||
|
|
||||||
let mut gpsl = GPSL::new(
|
let mut gpsl = GPSL::new(
|
||||||
Source::new(String::default()),
|
|
||||||
Some(functions),
|
Some(functions),
|
||||||
Some(HashMap::new()),
|
Some(HashMap::new()),
|
||||||
Some(HashMap::new()),
|
Some(HashMap::new()),
|
||||||
|
Reference in New Issue
Block a user