Changeset - eb4725b03d58
[Not reviewed]
0 5 3
MH - 3 years ago 2022-03-31 16:23:11
contact@maxhenger.nl
Prepare for using libc
8 files changed with 19 insertions and 12 deletions:
0 comments (0 inline, 0 general)
Cargo.toml
Show inline comments
 
@@ -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 }
src/protocol/parser/mod.rs
Show inline comments
 
@@ -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<usize, ParseError> {
 
        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<usize, ParseError> {
 
    fn feed_internal(&mut self, mut source: InputSource, is_compiler_file: bool, add_to_global_namespace: bool) -> Result<usize, ParseError> {
 
        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,
src/protocol/parser/pass_symbols.rs
Show inline comments
 
@@ -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(..) {
src/runtime2/mod.rs
Show inline comments
 
@@ -3,6 +3,7 @@ mod runtime;
 
mod component;
 
mod communication;
 
mod scheduler;
 
mod std;
 
#[cfg(test)] mod tests;
 

	
 
pub use runtime::Runtime;
src/runtime2/std/internet.rs
Show inline comments
 
new file 100644
src/runtime2/std/mod.rs
Show inline comments
 
new file 100644
 
mod internet;
 
\ No newline at end of file
src/runtime2/tests/mod.rs
Show inline comments
 
@@ -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<u32> generator, u32 num_values) {
 
        auto i = 0;
 
        while (i < num_values) {
std/std.internet.pdl
Show inline comments
 
new file 100644
 
#module std.internet
 

	
0 comments (0 inline, 0 general)