Skip to content

Commit

Permalink
new intl
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Mar 2, 2025
1 parent 60df21a commit 94ef78c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
9 changes: 5 additions & 4 deletions interpreter/src/ipreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ pub(crate) unsafe fn tok_parse<'a>(
heap
.remove(var)
.expect("Cannot find variable")
.expect("Cannot find variable"),
.expect("Cannot find variable")
.into(),
);

None
Expand Down Expand Up @@ -211,7 +212,7 @@ pub(crate) unsafe fn tok_parse<'a>(
let runt = opt.rem_r_runtime();

if val_type && opt.r_val.is_some() {
let _ = heap.set(Cow::Borrowed(to_set), opt.r_val.unwrap());
let _ = heap.set(Cow::Borrowed(to_set), opt.r_val());
} else if val_type && runt.is_some() {
let _ = set_runtime_val(
heap,
Expand All @@ -230,7 +231,7 @@ pub(crate) unsafe fn tok_parse<'a>(
let runt = opt.rem_r_runtime();

if val_type && opt.r_val.is_some() {
let _ = heap.set(Cow::Borrowed(to_set), opt.r_val.unwrap());
let _ = heap.set(Cow::Borrowed(to_set), opt.r_val());
} else if val_type && runt.is_some() {
let _ = set_runtime_val(
heap,
Expand Down Expand Up @@ -264,7 +265,7 @@ pub(crate) unsafe fn tok_parse<'a>(
let runt = opt.rem_r_runtime();

if val_type && opt.r_val.is_some() {
let _ = heap.set(Cow::Borrowed(to_set), opt.r_val.unwrap());
let _ = heap.set(Cow::Borrowed(to_set), opt.r_val());
} else if val_type && runt.is_some() {
let _ = set_runtime_val(
heap,
Expand Down
2 changes: 1 addition & 1 deletion interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use tokio::*;

pub use lealang_chalk_rs::Chalk;

pub static VERSION_INT: u16 = 4;
pub static VERSION_INT: u16 = 5;

pub trait Package {
fn name(&self) -> &'static [u8];
Expand Down
40 changes: 34 additions & 6 deletions interpreter/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ use tokio::{runtime::Handle, sync::mpsc::UnboundedReceiver, task::JoinHandle};

use crate::runtime::RuntimeValue;

pub enum RetBufValue {
Future(Pin<Box<dyn Future<Output = BufValue> + Send>>),
Heap(BufValue)
}

impl From<BufValue> for RetBufValue {
fn from(item: BufValue) -> Self {
Self::Heap(item)
}
}

pub struct Options {
pub pre: *const str,
pub r_val: Option<BufValue>,
pub r_val: Option<RetBufValue>,
pub runtime: *const Handle,
r_runtime: Option<RuntimeValue>,
}

impl Debug for Options {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("Options {{ r_val: {:?} }}", &self.r_val))
f.write_fmt(format_args!("Options {{ <inner> }}"))
}
}

Expand All @@ -44,15 +55,32 @@ impl Options {
}
}

pub fn spawn<F: Future<Output = BufValue> + Send + 'static>(&self, future: F) -> JoinHandle<BufValue> {
unsafe { &*self.runtime }.spawn(future)
fn spawn(&self) -> &Handle {
unsafe { &*self.runtime }
}

pub fn set_return_future(&mut self, val: Pin<Box<dyn Future<Output = BufValue> + Send>>) {
self.r_val = Some(RetBufValue::Future(val));
}

pub fn set_return_val(&mut self, val: BufValue) {
self.r_val = Some(val);
self.r_val = Some(RetBufValue::Heap(val));
}

pub(crate) fn r_val(self) -> BufValue {
let rt = self.spawn();
let rt = rt.clone();
let val = self.r_val;

match val.expect("Error") {
RetBufValue::Future(x) => {
rt.block_on(x)
},
RetBufValue::Heap(x) => x
}
}

pub fn rem_r_runtime(&mut self) -> Option<RuntimeValue> {
pub(crate) fn rem_r_runtime(&mut self) -> Option<RuntimeValue> {
let mut rt = self.r_runtime.take()?;

rt.r#type = format!("{}/{}", unsafe { &*self.pre }, rt.r#type);
Expand Down

0 comments on commit 94ef78c

Please # to comment.