From eab3b357dd7715ada66d84e6c9943e0bb2da7be9 Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Fri, 19 Jul 2019 22:05:35 +0200 Subject: [PATCH] Extend symtable module. --- Cargo.toml | 1 + src/symboltable.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a2c155..6531fc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ license = "MIT" edition = "2018" [dependencies] +indexmap = "1.0" rustpython-bytecode = { path = "../bytecode", version = "0.1.0" } rustpython-parser = { path = "../parser", version = "0.1.0" } num-complex = { version = "0.2", features = ["serde"] } diff --git a/src/symboltable.rs b/src/symboltable.rs index 3122af0..9d4d677 100644 --- a/src/symboltable.rs +++ b/src/symboltable.rs @@ -8,9 +8,9 @@ Inspirational file: https://github.com/python/cpython/blob/master/Python/symtabl */ use crate::error::{CompileError, CompileErrorType}; +use indexmap::map::IndexMap; use rustpython_parser::ast; use rustpython_parser::location::Location; -use std::collections::HashMap; pub fn make_symbol_table(program: &ast::Program) -> Result { let mut builder: SymbolTableBuilder = Default::default(); @@ -48,7 +48,7 @@ pub enum SymbolRole { #[derive(Clone)] pub struct SymbolScope { /// A set of symbols present on this scope level. - pub symbols: HashMap, + pub symbols: IndexMap, /// A list of subscopes in the order as found in the /// AST nodes. @@ -81,8 +81,8 @@ impl SymbolScope { impl Default for SymbolScope { fn default() -> Self { SymbolScope { - symbols: HashMap::new(), - sub_scopes: vec![], + symbols: Default::default(), + sub_scopes: Default::default(), } } }