summaryrefslogtreecommitdiff
path: root/src/macro_processor/macro_processor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/macro_processor/macro_processor.rs')
-rw-r--r--src/macro_processor/macro_processor.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index 306c8da..52fc581 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -1,10 +1,12 @@
#[cfg(feature = "guile")]
-use crate::guile::guile::Guile;
+use crate::guile::guile::{scm_undefined, Guile};
#[cfg(feature = "deadlinks")]
use crate::macro_processor::deadlinks::smp_builtin_wodl;
use crate::macro_processor::error::SMPError;
use std::collections::HashMap;
use std::fs;
+#[cfg(feature = "guile")]
+use std::os::raw::c_void;
use std::process::Command;
// print only with debug_assertions
@@ -537,6 +539,9 @@ fn smp_builtin_html_from_markdown(
}
fn macro_is_whitespace_deleting(s: &str) -> bool {
+ if s.len() == 0 {
+ return false;
+ }
s.chars().nth(s.len() - 1) == Some('_')
}
@@ -623,7 +628,7 @@ impl MacroProcessorWarning {
/// Defines a MacroProcessor object, with it's associated state
/// the state mostly includes the defined macros
-#[derive(Clone)]
+#[derive(Debug, Clone)]
pub struct MacroProcessor {
/// All currently defined macros in this MacroProcessor
pub macros: HashMap<String, MacroType>,
@@ -632,9 +637,11 @@ pub struct MacroProcessor {
/// Emitted warnings
pub warnings: Vec<MacroProcessorWarning>,
#[cfg(feature = "guile")]
- pub guile: Guile,
+ pub guile: std::rc::Rc<Guile>,
}
+pub static mut GLOBS: Option<&MacroProcessor> = None;
+
impl MacroProcessor {
pub fn new() -> Self {
let mut smp = Self {
@@ -642,12 +649,21 @@ impl MacroProcessor {
macro_invocations: Vec::new(),
warnings: Vec::new(),
#[cfg(feature = "guile")]
- guile: Guile::new(),
+ guile: std::rc::Rc::new(Guile::new()),
};
smp.define_builtins();
smp
}
+ pub fn defself(&mut self) {
+ // Find a better way to do this Rc-stuff
+ let guile = std::rc::Rc::as_ptr(&self.guile);
+ unsafe {
+ let data_ptr: *mut c_void = self as *mut _ as *mut c_void;
+ (*guile).define("smp_state_ptr", data_ptr);
+ }
+ }
+
/// Bootstrapping-function for defining all builtins,
/// the same way all other macros might be defined
fn define_builtins(&mut self) {
@@ -747,13 +763,6 @@ impl MacroProcessor {
/// * `name` - The name of the new macro
/// * `macro_expansion` - The MacroType struct to use.
pub fn define_macro(&mut self, name: String, macro_expansion: MacroType) {
- #[cfg(feature = "guile")]
- {
- match &macro_expansion {
- MacroType::String(s) => self.guile.define_string(&(name.clone()), s),
- _ => (),
- }
- }
self.macros.insert(name, macro_expansion);
}
@@ -916,6 +925,7 @@ impl MacroProcessor {
#[cfg(feature = "guile")]
ParserState::InGuile => match c {
')' if peek == Some(&'%') => {
+ self.defself();
let r = self
.guile
.evaluate_expression(&guile_expr)