From da4180962e98b8b560a59ee7bcbe6d4630464e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabrielle=20Guimar=C3=A3es=20de=20Oliveira?= Date: Sun, 10 Mar 2024 14:23:01 -0300 Subject: [PATCH] refactor: remove sol-js --- sol-js/Cargo.toml | 20 ---------- sol-js/src/lib.rs | 91 ------------------------------------------- sol-js/src/runtime.js | 3 -- 3 files changed, 114 deletions(-) delete mode 100644 sol-js/Cargo.toml delete mode 100644 sol-js/src/lib.rs delete mode 100644 sol-js/src/runtime.js diff --git a/sol-js/Cargo.toml b/sol-js/Cargo.toml deleted file mode 100644 index 0da2fe2..0000000 --- a/sol-js/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "sol-js" -edition.workspace = true -authors.workspace = true -documentation.workspace = true -version.workspace = true - -[dependencies] -sol-diagnostic.workspace = true -sol-hir.workspace = true -sol-syntax.workspace = true -sol-vfs.workspace = true -sol-eyre.workspace = true -salsa-2022.workspace = true -im.workspace = true -axum.workspace = true -deno_core.workspace = true -resast.workspace = true -resw.workspace = true -eyre.workspace = true diff --git a/sol-js/src/lib.rs b/sol-js/src/lib.rs deleted file mode 100644 index f6d0ca9..0000000 --- a/sol-js/src/lib.rs +++ /dev/null @@ -1,91 +0,0 @@ -use std::{path::Path, rc::Rc}; - -use deno_core::{error::AnyError, FastString}; -use resast::prelude as js; -use sol_eyre::bail; -use sol_hir::source::declaration::Declaration; -use sol_hir::source::top_level::TopLevel; -use sol_hir::{ - solver::Definition, - source::{expr::Expr, HirSource}, - HirDb, -}; - -pub async fn run_js(file_path: &str) -> Result<(), AnyError> { - let main_module = deno_core::resolve_path(file_path, Path::new("."))?; - let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { - module_loader: Some(Rc::new(deno_core::FsModuleLoader)), - ..Default::default() - }); - js_runtime.execute_script( - "[sol:runtime.js]", - FastString::Static(include_str!("runtime.js")), - )?; - let mod_id = js_runtime.load_main_module(&main_module, None).await?; - let result = js_runtime.mod_evaluate(mod_id); - js_runtime.run_event_loop(false).await?; - result.await? -} - -pub fn definition_mangle_name(db: &dyn HirDb, definition: Definition) -> String { - let mut name = String::new(); - for segment in definition.name(db).segments(db) { - name.push_str(&segment.contents(db)); - name.push_str("__"); - } - name -} - -pub fn walk_on_expr<'a>(db: &dyn HirDb, expr: Expr) -> js::Expr<'a> { - match expr { - Expr::Empty => todo!(), - Expr::Error(_) => todo!(), - Expr::Path(reference) => { - let definition = reference.definition(db); - let mangled_name = definition_mangle_name(db, definition); - js::Expr::Ident(js::Ident::new(mangled_name)) - } - Expr::Meta(_) => todo!(), - Expr::Literal(_) => todo!(), - Expr::Call(_) => todo!(), - Expr::Ann(_) => todo!(), - Expr::Abs(_) => todo!(), - Expr::Match(_) => todo!(), - Expr::Upgrade(_) => todo!(), - } -} - -pub fn transform_top_level( - db: &dyn HirDb, - top_level: TopLevel, -) -> sol_eyre::Result { - match top_level { - TopLevel::Error(_) => bail!("errors are not supported"), - TopLevel::Using(_) => bail!("using are not supported"), - TopLevel::Command(_) => bail!("commands are not supported"), - TopLevel::BindingGroup(group) => Ok(js::ProgramPart::decl(js::Decl::Func(js::Func { - id: Some(js::Ident::new(group.name(db).to_string(db))), - params: vec![], - body: js::FuncBody(vec![]), - generator: false, - is_async: false, - }))), - TopLevel::Inductive(_) => bail!("data declarations are not supported"), - } -} - -pub fn dump_into_string( - db: &dyn HirDb, - source: HirSource, - w: W, -) -> sol_eyre::Result<()> { - let mut writer = resw::Writer::new(w); - for top_level in source.contents(db) { - let Ok(program_part) = transform_top_level(db, *top_level) else { - continue; - }; - - writer.write_part(&program_part)?; - } - Ok(()) -} diff --git a/sol-js/src/runtime.js b/sol-js/src/runtime.js deleted file mode 100644 index 07b3a2d..0000000 --- a/sol-js/src/runtime.js +++ /dev/null @@ -1,3 +0,0 @@ -((globalThis) => { - -})(globalThis)