Skip to content

Commit

Permalink
🚧 WIP broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Philogy committed Nov 5, 2024
1 parent 48076ab commit 9d42203
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
13 changes: 11 additions & 2 deletions crates/analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,14 @@ impl<'a, 'src, 'ast: 'src, E: FnMut(AnalysisError<'ast, 'src>)> MacroAnalysis<'a
}
}
Invoke::BuiltinCodeSize(code_ref) | Invoke::BuiltinCodeOffset(code_ref) => {
let mut no_error = true;
if !global_exists!(self.global_defs, code_ref.ident(), Definition::Macro(_)) {
self.emit(AnalysisError::DefinitionNotFound {
scope: self.m,
def_type: "macro",
not_found: code_ref,
})
});
no_error = false;
}
if self
.global_defs
Expand All @@ -240,7 +242,14 @@ impl<'a, 'src, 'ast: 'src, E: FnMut(AnalysisError<'ast, 'src>)> MacroAnalysis<'a
self.emit(AnalysisError::NotYetSupported {
intent: "code introspection for macros with arguments".to_owned(),
span: ((), code_ref.1),
})
});
no_error = false;
}
let mut inner_errors = Vec::new();
if no_error {
analyze_entry_point(self.global_defs, code_ref.ident(), |err| {
inner_errors.push(err)
});
}
}
Invoke::BuiltinFuncSig(func_or_error_ref)
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

let mut mtracker = MarkTracker::default();
let config = CompileGlobals::new(cli.evm_version.allows_push0(), unique_defs);
let mut config = CompileGlobals::new(cli.evm_version.allows_push0(), unique_defs);

let asm = match generate_for_entrypoint(&config, entry_point_macro.unwrap(), &mut mtracker) {
let asm = match generate_for_entrypoint(&mut config, entry_point_macro.unwrap(), &mut mtracker)
{
Ok(asm) => asm,
Err(reason) => {
eprintln!("{}: {}", "Error".fg(Color::Red), reason);
Expand Down
17 changes: 13 additions & 4 deletions crates/compilation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use huff_ast::*;
use std::collections::BTreeMap;

pub fn generate_for_entrypoint<'src>(
globals: &CompileGlobals<'src, '_>,
globals: &mut CompileGlobals<'src, '_>,
entry_point: &Macro<'src>,
mark_tracker: &mut MarkTracker,
) -> Result<Vec<Asm>, String> {
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn generate_default_constructor(runtime: Vec<u8>) -> Box<[Asm]> {
}

fn generate_for_macro<'src: 'cmp, 'cmp>(
globals: &CompileGlobals<'src, '_>,
globals: &mut CompileGlobals<'src, '_>,
current: &Macro<'src>,
arg_values: Box<[Asm]>,
mark_tracker: &mut MarkTracker,
Expand Down Expand Up @@ -87,7 +87,7 @@ fn generate_for_macro<'src: 'cmp, 'cmp>(
};
generate_for_macro(
globals,
target,
&target,
args.0
.iter()
.map(|arg| instruction_to_asm(globals, &current_args, label_stack, arg))
Expand All @@ -102,7 +102,7 @@ fn generate_for_macro<'src: 'cmp, 'cmp>(
invoke
)),
},
MacroStatement::Instruction(i) => {
MacroStatement::Instruction(ref i) => {
asm.push(instruction_to_asm(globals, &current_args, label_stack, i));
Ok(())
}
Expand Down Expand Up @@ -139,11 +139,19 @@ pub fn u256_to_asm(value: U256, allow_push0: bool) -> Asm {
})
}

#[derive(Debug, Clone)]
pub struct IncludedMacro {
start_id: usize,
end_id: usize,
code: Vec<u8>,
}

#[derive(Debug, Clone)]
pub struct CompileGlobals<'src, 'ast> {
pub allow_push0: bool,
pub defs: BTreeMap<&'src str, &'ast Definition<'src>>,
pub constants: BTreeMap<&'src str, U256>,
pub referenced_macros: BTreeMap<&'src str, IncludedMacro>,
}

impl<'src, 'ast> CompileGlobals<'src, 'ast> {
Expand All @@ -153,6 +161,7 @@ impl<'src, 'ast> CompileGlobals<'src, 'ast> {
allow_push0,
defs,
constants,
referenced_macros: BTreeMap::new(),
}
}
}
Expand Down

0 comments on commit 9d42203

Please sign in to comment.