compiled steel engine
This commit is contained in:
@@ -1,4 +1,49 @@
|
||||
// src/steel/server/execution.rs
|
||||
use std::fmt;
|
||||
use std::collections::HashMap;
|
||||
use sqlx::{PgPool, Row};
|
||||
use steel::steel_vm::engine::Engine;
|
||||
use steel::rvals::SteelVal;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ExecutionError {
|
||||
#[error("Script execution failed: {0}")]
|
||||
RuntimeError(String),
|
||||
#[error("Type conversion error: {0}")]
|
||||
TypeConversionError(String),
|
||||
#[error("Unsupported target type: {0}")]
|
||||
UnsupportedType(String),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Value {
|
||||
String(String),
|
||||
}
|
||||
|
||||
// TODO LEAKING MEMORY NEEDS IMIDATE FIX BEFORE PROD
|
||||
pub fn execute_script(
|
||||
script: &str,
|
||||
target_type: &str,
|
||||
) -> Result<Value, ExecutionError> {
|
||||
let mut vm = Engine::new();
|
||||
|
||||
// Convert to Box<str> then leak to get 'static lifetime
|
||||
let static_script: &'static str = Box::leak(script.to_string().into_boxed_str());
|
||||
|
||||
let results = vm.compile_and_run_raw_program(static_script)
|
||||
.map_err(|e| ExecutionError::RuntimeError(e.to_string()))?;
|
||||
|
||||
let last_result = results.last()
|
||||
.ok_or_else(|| ExecutionError::TypeConversionError("Script returned no values".to_string()))?;
|
||||
|
||||
match target_type {
|
||||
"STRING" => {
|
||||
if let SteelVal::StringV(s) = last_result {
|
||||
Ok(Value::String(s.to_string()))
|
||||
} else {
|
||||
Err(ExecutionError::TypeConversionError(
|
||||
format!("Expected string, got {:?}", last_result)
|
||||
))
|
||||
}
|
||||
}
|
||||
_ => Err(ExecutionError::UnsupportedType(target_type.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// src/steel/server/mod.rs
|
||||
// pub mod execution;
|
||||
pub mod execution;
|
||||
|
||||
// pub use execution::*;
|
||||
pub use execution::*;
|
||||
|
||||
Reference in New Issue
Block a user