Skip to content

Commit

Permalink
feat: compiler integration into api
Browse files Browse the repository at this point in the history
  • Loading branch information
rootCircle committed Dec 2, 2023
1 parent bc438cd commit a56edfa
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 12 deletions.
74 changes: 74 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lettre = { version = "0.10.4", features = ["tokio1", "tokio1-native-tls"] }
serde = "1.0.189"
tower-http = { version = "0.4.4", features = ["full"] }
http = "0.2.9"
zen = {git = "https://github.com/zenlang-rs/zen-lang.git", branch = "main"}
zen = {git = "https://github.com/zenlang-rs/zen-lang.git", branch = "main", version = "^0.2.0"}
jsonwebtoken = "9.1.0"
once_cell = "1.18.0"
shuttle-persist = "0.34.1"
Expand Down
25 changes: 16 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,41 @@ use axum::{
routing::{get, post},
Json, Router,
};
mod config;
mod email;

mod login_signup;
use dotenv::dotenv;
// use http::{Method, header::ACCESS_CONTROL_ALLOW_ORIGIN};
use login_signup::{auth_routes, UserData};
use serde::{Deserialize, Serialize};
use shuttle_persist::PersistInstance;
use tower_http::cors::CorsLayer;
use zen::{compile, get_version};
use zen::run_program;

mod config;
mod email;

mod login_signup;

async fn hello_zen() -> &'static str {
format!(
"Zen is High Dear!\nCompiler Version: {version}",
version = get_version().unwrap_or("v0.0".to_owned())
)
"Zen is High Dear!\nCompiler Version: v0.2.0")
.leak()
}

async fn compile_code(
extract::Json(user): extract::Json<CodeCompileRequest>,
) -> Json<CodeOutputResponse> {
Json(CodeOutputResponse {
output: compile(user.code),
output: runnable_code(user.code, ""),
})
}

fn runnable_code(code: String, input: &str) -> Result<String, String> {
let runnable = run_program(code, input);
match runnable {
Ok(output) => Ok(output),
Err(err) => Err(format!("[ERROR]\n{}\n{}", err.msg, err.error_type)),
}
}

#[shuttle_runtime::main]
async fn axum(#[shuttle_persist::Persist] persist: PersistInstance) -> shuttle_axum::ShuttleAxum {
// let origins: [axum::http::HeaderValue; 3] = [
Expand Down

0 comments on commit a56edfa

Please sign in to comment.