Skip to content

Commit 8226fa7

Browse files
committed
new update
1 parent b36cd80 commit 8226fa7

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

interpreter/r.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ mod ipreter {
452452
}),
453453
content,
454454
&mut app,
455-
&mut app2.heap,
455+
// SAFETY: It'll always unwrap
456+
&mut app2.heap.as_mut().unwrap(),
456457
&mut line,
457458
&mut markers,
458459
false,

interpreter/src/ipreter.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn interpret<'a>(file: &str, mut app: &mut Application<'a>) {
4646
format!("{}:{}", &file_name, line + 1),
4747
content,
4848
&mut app,
49-
&mut app2.heap,
49+
app2.heap.as_mut().unwrap(),
5050
&mut line,
5151
&mut markers,
5252
false,
@@ -199,11 +199,7 @@ pub(crate) unsafe fn tok_parse<'a>(
199199
r#async,
200200
) {
201201
None => {
202-
if &caller != &"" {
203-
error(&format!("Unexpected `{}`", &caller), &file);
204-
}
205-
206-
None
202+
error(&format!("Unexpected `{}`", &caller), &file);
207203
}
208204
Some(Output::String(v)) => {
209205
let runt = opt.rem_r_runtime();

interpreter/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(get_mut_unchecked)]
66

77
use std::{
8-
collections::HashMap, mem::zeroed, process, sync::LazyLock, time::{Duration, Instant}
8+
collections::HashMap, process, sync::LazyLock, time::{Duration, Instant}
99
};
1010

1111
pub use paste::paste;
@@ -74,7 +74,7 @@ pub struct Application<'a> {
7474
code: HashMap<String, String>,
7575
pub(crate) pkg: LanguagePackages<'a>,
7676
entry: &'a str,
77-
heap: Heap,
77+
heap: Option<Heap>,
7878

7979
// Resolve files
8080
module_resolver: Box<dyn FnMut(&str) -> Vec<u8>>,
@@ -107,10 +107,7 @@ impl<'a> Application<'a> {
107107
Self {
108108
code,
109109
pkg: LanguagePackages::new(),
110-
// SAFETY: It is Initialized before being used
111-
// Basically its me being lazy & Wanting to reduce computation time
112-
#[allow(invalid_value)]
113-
heap: unsafe { zeroed() },
110+
heap: None,
114111
entry: &file,
115112
module_resolver: Box::new(fs_resolver),
116113
pkg_resolver: Box::new(dll_resolver),
@@ -174,7 +171,7 @@ impl<'a> Application<'a> {
174171
}
175172

176173
pub fn run(mut self, time: bool) -> ! {
177-
self.heap = Heap::new(self.pkg.extends.clone());
174+
self.heap = Some(Heap::new(self.pkg.extends.clone()));
178175
let dur = self.run_non();
179176

180177
if time {

interpreter/src/types/heap.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn call_runtime_val<'a>(
5959

6060
let (ai, bi) = match ptr.get_mut(key)? {
6161
BufValue::RuntimeRaw(ai, bi) => (ai, bi),
62-
val => return handle_runtime(app, val, caller, v, a, c, o),
62+
val => return handle_runtime(unsafe { &mut *hp }, val, caller, v, a, c, o),
6363
};
6464

6565
let data = (ai, bi);
@@ -148,6 +148,14 @@ impl Heap {
148148
}
149149
}
150150

151+
pub(crate) fn get_extends(&self) -> &ExtendsInternal {
152+
&self.extends
153+
}
154+
155+
pub(crate) fn get_extends_arc(&self) -> &Arc<ExtendsInternal> {
156+
&self.def_extends
157+
}
158+
151159
pub fn clear(&mut self) {
152160
*self = Self::new(self.def_extends.clone());
153161
}

interpreter/src/types/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use heap::*;
1919
pub use heap_wrap::*;
2020
use tokio::sync::mpsc::UnboundedReceiver;
2121

22-
use crate::{runtime::RuntimeValue, Application};
22+
use crate::runtime::RuntimeValue;
2323

2424
pub struct RetBufValue(pub BufValue);
2525

@@ -128,26 +128,30 @@ macro_rules! extends {
128128
}
129129

130130
pub(crate) fn handle_runtime<'a>(
131-
app: *mut Application,
131+
heap: &mut Heap,
132132
val: &mut BufValue,
133133
caller: &'a str,
134134
v: &'a [*const str],
135135
a: HeapWrapper,
136136
c: &String,
137137
o: &'a mut Options,
138138
) -> Option<Output> {
139-
let app = unsafe { &mut *app };
140-
141-
let extends = &app.pkg.extends;
139+
let ar = heap.get_extends_arc();
140+
let ext = heap.get_extends();
142141

143142
crate::paste! {
144143
match val {
145144
$(
146145
BufValue::[<$good>](data) => {
147-
let scope = &extends.$x;
148-
149-
let Some(f) = scope.get(caller) else {
150-
return None;
146+
let scope1 = &ext.$x;
147+
let scope2 = &ar.$x;
148+
149+
let f = match scope1.get(caller) {
150+
Some(v) => v,
151+
None => match scope2.get(caller) {
152+
Some(v) => v,
153+
None => { return None }
154+
},
151155
};
152156

153157
f(data as _, v, a, c, o);

0 commit comments

Comments
 (0)