Changeset - 95e019faaf52
[Not reviewed]
0 8 1
mh - 3 years ago 2022-03-29 18:18:12
contact@maxhenger.nl
Getting builtin component instantiation to compile
9 files changed with 42 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/protocol/ast.rs
Show inline comments
 
@@ -1838,7 +1838,7 @@ pub struct CallExpression {
 

	
 
#[derive(Debug, Clone, PartialEq, Eq)]
 
pub enum Method {
 
    // Builtin, accessible by programmer
 
    // Builtin function, accessible by programmer
 
    Get,
 
    Put,
 
    Fires,
 
@@ -1846,10 +1846,12 @@ pub enum Method {
 
    Length,
 
    Assert,
 
    Print,
 
    // Builtin, not accessible by programmer
 
    // Builtin function, not accessible by programmer
 
    SelectStart, // SelectStart(total_num_cases, total_num_ports)
 
    SelectRegisterCasePort, // SelectRegisterCasePort(case_index, port_index, port_id)
 
    SelectWait, // SelectWait() -> u32
 
    // Builtin component,
 
    ComponentRandomU32,
 
    // User-defined
 
    UserFunction,
 
    UserComponent,
 
@@ -1860,6 +1862,7 @@ impl Method {
 
        use Method::*;
 
        match self {
 
            Get | Put | Fires | Create | Length | Assert | Print => true,
 
            ComponentRandomU32 => true,
 
            _ => false,
 
        }
 
    }
src/protocol/eval/executor.rs
Show inline comments
 
@@ -755,11 +755,15 @@ impl Prompt {
 
                                        },
 
                                    }
 
                                },
 
                                Method::ComponentRandomU32 => {
 
                                    debug_assert_eq!(heap[expr.procedure].parameters.len(), cur_frame.expr_values.len());
 
                                    debug_assert_eq!(heap[cur_frame.position].as_new().expression, expr.this);
 
                                },
 
                                Method::UserComponent => {
 
                                    // This is actually handled by the evaluation
 
                                    // of the statement.
 
                                    debug_assert_eq!(heap[expr.procedure].parameters.len(), cur_frame.expr_values.len());
 
                                    debug_assert_eq!(heap[cur_frame.position].as_new().expression, expr.this)
 
                                    debug_assert_eq!(heap[cur_frame.position].as_new().expression, expr.this);
 
                                },
 
                                Method::UserFunction => {
 
                                    // Push a new frame. Note that all expressions have
src/protocol/parser/mod.rs
Show inline comments
 
@@ -296,8 +296,9 @@ impl Parser {
 
        use std::path::{Path, PathBuf};
 
        use std::fs;
 

	
 
        const FILES: [&'static str; 1] = [
 
        const FILES: [&'static str; 2] = [
 
            "std.global.pdl",
 
            "std.random.pdl",
 
        ];
 

	
 
        // Determine base directory
 
@@ -324,6 +325,7 @@ impl Parser {
 
        let mut first_file = true;
 

	
 
        for file in FILES {
 
            file_path.clear();
 
            file_path.push(path);
 
            file_path.push(file);
 

	
src/protocol/parser/pass_definitions.rs
Show inline comments
 
@@ -376,6 +376,7 @@ impl PassDefinitions {
 
                ("std.global", "length") => ProcedureSource::FuncLength,
 
                ("std.global", "assert") => ProcedureSource::FuncAssert,
 
                ("std.global", "print") => ProcedureSource::FuncPrint,
 
                ("std.random", "random_u32") => ProcedureSource::CompRandomU32,
 
                _ => panic!(
 
                    "compiler error: unknown builtin procedure '{}' in module '{}'",
 
                    procedure_name, module_name
 
@@ -825,10 +826,8 @@ impl PassDefinitions {
 
        if let Expression::Call(expression) = expression {
 
            // Allow both components and functions, as it makes more sense to
 
            // check their correct use in the validation and linking pass
 
            if expression.method == Method::UserComponent || expression.method == Method::UserFunction {
 
                call_id = expression.this;
 
                valid = true;
 
            }
 
            call_id = expression.this;
 
            valid = true;
 
        }
 

	
 
        if !valid {
 
@@ -1658,7 +1657,8 @@ impl PassDefinitions {
 
                                    ProcedureSource::FuncLength => Method::Length,
 
                                    ProcedureSource::FuncAssert => Method::Assert,
 
                                    ProcedureSource::FuncPrint => Method::Print,
 
                                    _ => todo!("other proc sources")
 
                                    ProcedureSource::CompRandomU32 => Method::ComponentRandomU32,
 
                                    _ => todo!("other procedure sources"),
 
                                };
 

	
 
                                // Function call: consume the arguments
src/protocol/parser/pass_validation_linking.rs
Show inline comments
 
@@ -1160,6 +1160,9 @@ impl Visitor for PassValidationLinking {
 
            Method::SelectStart
 
            | Method::SelectRegisterCasePort
 
            | Method::SelectWait => unreachable!(), // not usable by programmer directly
 
            Method::ComponentRandomU32 => {
 
                expecting_wrapping_new_stmt = true;
 
            },
 
            Method::UserFunction => {}
 
            Method::UserComponent => {
 
                expecting_wrapping_new_stmt = true;
src/protocol/parser/type_table.rs
Show inline comments
 
@@ -2045,6 +2045,7 @@ impl TypeTable {
 

	
 
        // And now, we're actually, properly, done
 
        self.encountered_types.clear();
 
        self.size_alignment_stack.clear();
 
    }
 

	
 
    /// Attempts to compute size/alignment for the provided type. Note that this
src/runtime2/tests/mod.rs
Show inline comments
 
@@ -219,4 +219,21 @@ fn test_empty_select() {
 
    ").expect("compilation");
 
    let rt = Runtime::new(3, false, pd);
 
    create_component(&rt, "", "constructor", no_args());
 
}
 

	
 
#[test]
 
fn test_random_u32_temporary_thingo() {
 
    let pd = ProtocolDescription::parse(b"
 
    primitive random_taker(in<u32> generator) {
 
        sync {
 
            auto a = get(generator);
 
        }
 
    }
 

	
 
    composite constructor() {
 
        channel tx -> rx;
 
        new random_u32(tx, 1, 100);
 
        new random_taker(rx);
 
    }
 
    ").expect("compilation");
 
}
 
\ No newline at end of file
std/std.global.pdl
Show inline comments
 
#module std.global
 

	
 
// Note: parsing of token ranges and pragma needs to change. For now we insert
 
// spaces to work with the current system. Needs to be a system where the
 
// pragmas, "func" keywords (and similar keywords) indicate initial points to
 
// start parsing.
 

	
 
func get<T>(in<T> input) -> T { #builtin }
 
func put<T>(out<T> output, T value) -> #type_void { #builtin }
 
func fires<T>(#type_portlike<T> port) -> bool { #builtin }
std/std.random.pdl
Show inline comments
 
new file 100644
 
#module std.random
 

	
 
primitive random_u32(out<u32> generator, u32 min, u32 max) { #builtin }
0 comments (0 inline, 0 general)