diff --git a/Cargo.toml b/Cargo.toml index 9c3801265cc09b5ee9216ea9d148e4ce62661815..90a6dff1ab7b92bc91b68bef34252b9017e7b97b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,6 @@ socket2 = { version = "0.3.12", optional = true } backtrace = "0.3" lazy_static = "1.4.0" -# ffi - # socket ffi libc = { version = "^0.2", optional = true } os_socketaddr = { version = "0.1.0", optional = true } diff --git a/src/protocol/parser/mod.rs b/src/protocol/parser/mod.rs index f79a81c83522d13a3b39043637b73fc234a79a45..3d4bcba9ff7d17d06a067db4fd631bfc28b8e594 100644 --- a/src/protocol/parser/mod.rs +++ b/src/protocol/parser/mod.rs @@ -54,7 +54,8 @@ pub enum ModuleCompilationPhase { pub struct Module { pub source: InputSource, pub tokens: TokenBuffer, - pub is_compiler_file: bool, // TODO: @Hack + pub is_compiler_file: bool, // TODO: @Hack for custom compiler-only types + pub add_to_global_namespace: bool, pub root_id: RootId, pub name: Option<(PragmaId, StringRef<'static>)>, pub version: Option<(PragmaId, i64)>, @@ -193,7 +194,7 @@ impl Parser { /// it internally for later parsing (when all modules are present). Returns /// the index of the new module. pub fn feed(&mut self, mut source: InputSource) -> Result { - return self.feed_internal(source, false); + return self.feed_internal(source, false, false); } pub fn parse(&mut self) -> Result<(), ParseError> { @@ -296,9 +297,10 @@ impl Parser { use std::path::{Path, PathBuf}; use std::fs; - const FILES: [&'static str; 2] = [ - "std.global.pdl", - "std.random.pdl", + // Pair is (name, add_to_global_namespace) + const FILES: [(&'static str, bool); 2] = [ + ("std.global.pdl", true), + ("std.random.pdl", false), ]; // Determine base directory @@ -324,7 +326,7 @@ impl Parser { let mut file_path = PathBuf::new(); let mut first_file = true; - for file in FILES { + for (file, add_to_global_namespace) in FILES { file_path.clear(); file_path.push(path); file_path.push(file); @@ -340,7 +342,7 @@ impl Parser { let source = source.unwrap(); let input_source = InputSource::new(file.to_string(), source); - let module_index = self.feed_internal(input_source, true); + let module_index = self.feed_internal(input_source, true, add_to_global_namespace); if let Err(err) = module_index { // A bit of a hack, but shouldn't really happen anyway: the // compiler should ship with a decent standard library (at some @@ -358,7 +360,7 @@ impl Parser { return Ok(()) } - fn feed_internal(&mut self, mut source: InputSource, is_compiler_file: bool) -> Result { + fn feed_internal(&mut self, mut source: InputSource, is_compiler_file: bool, add_to_global_namespace: bool) -> Result { let mut token_buffer = TokenBuffer::new(); self.pass_tokenizer.tokenize(&mut source, &mut token_buffer)?; @@ -366,6 +368,7 @@ impl Parser { source, tokens: token_buffer, is_compiler_file, + add_to_global_namespace, root_id: RootId::new_invalid(), name: None, version: None, diff --git a/src/protocol/parser/pass_symbols.rs b/src/protocol/parser/pass_symbols.rs index 3c3b628f105947d8748d9318ac4a237d1606e4fe..2688658feb17f4d0e48c04846443c44f55b7a46c 100644 --- a/src/protocol/parser/pass_symbols.rs +++ b/src/protocol/parser/pass_symbols.rs @@ -45,7 +45,7 @@ impl PassSymbols { self.reset(); let module = &mut modules[module_idx]; - let module_is_compiler_file = module.is_compiler_file; + let add_to_global_namespace = module.add_to_global_namespace; debug_assert_eq!(module.phase, ModuleCompilationPhase::Tokenized); debug_assert!(module.root_id.is_invalid()); // not set yet @@ -89,7 +89,7 @@ impl PassSymbols { } } - if module_is_compiler_file { + if add_to_global_namespace { debug_assert!(self.symbols.is_empty()); ctx.symbols.get_all_symbols_defined_in_scope(module_scope, &mut self.symbols); for symbol in self.symbols.drain(..) { diff --git a/src/runtime2/mod.rs b/src/runtime2/mod.rs index e5a3b8eb2fba77ff1fb0480a18e6aad656c5d425..0f9ac753bfc062373dd3918b663b4546dc8495ce 100644 --- a/src/runtime2/mod.rs +++ b/src/runtime2/mod.rs @@ -3,6 +3,7 @@ mod runtime; mod component; mod communication; mod scheduler; +mod std; #[cfg(test)] mod tests; pub use runtime::Runtime; diff --git a/src/runtime2/std/internet.rs b/src/runtime2/std/internet.rs new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/runtime2/std/mod.rs b/src/runtime2/std/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..272d4fc7f5e5478a1ef3477d6c6a311ef6d1f513 --- /dev/null +++ b/src/runtime2/std/mod.rs @@ -0,0 +1 @@ +mod internet; \ No newline at end of file diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index 28448eebad2897ede211d30682d958c2ac5d8251..bd77094a301b7c01383b7da4faa7cb00425ddec9 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -225,6 +225,8 @@ fn test_empty_select() { #[test] fn test_random_u32_temporary_thingo() { let pd = ProtocolDescription::parse(b" + import std.random::random_u32; + primitive random_taker(in generator, u32 num_values) { auto i = 0; while (i < num_values) { diff --git a/std/std.internet.pdl b/std/std.internet.pdl new file mode 100644 index 0000000000000000000000000000000000000000..a60953f775bc7d181acf4e14b4a8ee8ceef3236a --- /dev/null +++ b/std/std.internet.pdl @@ -0,0 +1,2 @@ +#module std.internet +