Finished up to and including chapter 16

This commit is contained in:
Moritz Gmeiner 2023-01-30 17:41:48 +01:00
commit b86985deaf
24 changed files with 1051 additions and 198 deletions

View file

@ -1,14 +1,15 @@
use std::collections::HashMap;
use std::fmt::Display;
use std::io::{stdin, stdout, Read, Write};
use rustc_hash::FxHashMap;
use crate::error::RuntimeError;
use super::lox_std::init_std;
use super::Value;
pub struct Runtime {
globals: HashMap<String, Value>,
globals: FxHashMap<String, Value>,
in_stream: Box<dyn std::io::BufRead>,
out_stream: Box<dyn std::io::Write>,
@ -18,7 +19,7 @@ impl Runtime {
pub fn new(in_stream: Box<dyn std::io::Read>, out_stream: Box<dyn std::io::Write>) -> Self {
let in_stream = Box::new(std::io::BufReader::new(in_stream));
let mut runtime = Runtime {
globals: HashMap::new(),
globals: FxHashMap::default(),
in_stream,
out_stream,
};
@ -28,7 +29,7 @@ impl Runtime {
runtime
}
pub fn globals(&self) -> &HashMap<String, Value> {
pub fn globals(&self) -> &FxHashMap<String, Value> {
&self.globals
}