Changeset - 1ae65b0b574e
.gitignore
Show inline comments
 
@@ -4,5 +4,7 @@ target
 
Cargo.lock
 
main
 
examples/*/*.exe
 
examples/*.dll
 
examples/*.dll
 
examples/reowolf*
 
logs
 
\ No newline at end of file
examples/1_minimal/amy.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main(int argc, char** argv) {
 
	char * pdl_ptr = buffer_pdl("eg_protocols.pdl");
 
	size_t pdl_len = strlen(pdl_ptr);
 
	Arc_ProtocolDescription * pd = protocol_description_parse(pdl_ptr, pdl_len);
 
	size_t err_len;
 
	printf("Ptr is %p.\nErr is `%s`.\n", pd, reowolf_error_peek(&err_len));
 
	free(pdl_ptr);
 
	return 0;
 
}
 
\ No newline at end of file
examples/1_minimal/make.sh
Show inline comments
 
new file 100644
 
#!/bin/sh
 

	
 
LIB_PATH="../../target/release"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH amy.c -o ./amy
examples/1_minimal/reowolf.h
Show inline comments
 
new file 100644
 
/* CBindgen generated */
 

	
 
#ifndef REOWOLF_HEADER_DEFINED
 
#define REOWOLF_HEADER_DEFINED
 

	
 
#include <stdarg.h>
 
#include <stdbool.h>
 
#include <stdint.h>
 
#include <stdlib.h>
 

	
 
typedef enum {
 
  Active,
 
  Passive,
 
} EndpointPolarity;
 

	
 
typedef enum {
 
  Putter,
 
  Getter,
 
} Polarity;
 

	
 
typedef struct Arc_ProtocolDescription Arc_ProtocolDescription;
 

	
 
typedef struct Connector Connector;
 

	
 
typedef struct Payload Payload;
 

	
 
typedef int32_t ErrorCode;
 

	
 
typedef uint32_t ConnectorId;
 

	
 
typedef uint32_t PortSuffix;
 

	
 
typedef struct {
 
  ConnectorId connector_id;
 
  PortSuffix u32_suffix;
 
} PortId;
 

	
 
/**
 
 * Given
 
 * - an initialized connector in setup or connecting state,
 
 * - a string slice for the component's identifier in the connector's configured protocol description,
 
 * - a set of ports (represented as a slice; duplicates are ignored) in the native component's interface,
 
 * the connector creates a new (internal) protocol component C, such that the set of native ports are moved to C.
 
 * Usable in {setup, communication} states.
 
 */
 
ErrorCode connector_add_component(Connector *connector,
 
                                  const uint8_t *ident_ptr,
 
                                  uintptr_t ident_len,
 
                                  const PortId *ports_ptr,
 
                                  uintptr_t ports_len);
 

	
 
/**
 
 * Given
 
 * - an initialized connector in setup or connecting state,
 
 * - a utf-8 encoded socket address,
 
 * - the logical polarity of P,
 
 * - the "physical" polarity in {Active, Passive} of the endpoint through which P's peer will be discovered,
 
 * returns P, a port newly added to the native interface.
 
 */
 
ErrorCode connector_add_net_port(Connector *connector,
 
                                 const uint8_t *addr_str_ptr,
 
                                 uintptr_t addr_str_len,
 
                                 Polarity port_polarity,
 
                                 EndpointPolarity endpoint_polarity,
 
                                 PortId *port);
 

	
 
/**
 
 * Given an initialized connector in setup or connecting state,
 
 * - Creates a new directed port pair with logical channel putter->getter,
 
 * - adds the ports to the native component's interface,
 
 * - and returns them using the given out pointers.
 
 * Usable in {setup, communication} states.
 
 */
 
void connector_add_port_pair(Connector *connector, PortId *out_putter, PortId *out_getter);
 

	
 
/**
 
 * Connects this connector to the distributed system of connectors reachable through endpoints,
 
 * Usable in setup state, and changes the state to communication.
 
 */
 
ErrorCode connector_connect(Connector *connector, int64_t timeout_millis);
 

	
 
/**
 
 * Destroys the given a pointer to the connector on the heap, freeing its resources.
 
 * Usable in {setup, communication} states.
 
 */
 
void connector_destroy(Connector *connector);
 

	
 
ErrorCode connector_get(Connector *connector, PortId port);
 

	
 
const uint8_t *connector_gotten_bytes(Connector *connector, PortId port, uintptr_t *len);
 

	
 
/**
 
 * Allocates a new connector on the heap and returning a pointer,
 
 * given an initialized protocol description.
 
 */
 
Connector *connector_new(const Arc_ProtocolDescription *pd);
 

	
 
/**
 
 * Initializes `out` with a new connector using the given protocol description as its configuration.
 
 * The connector uses the given (internal) connector ID.
 
 */
 
Connector *connector_new_with_id(const Arc_ProtocolDescription *pd, ConnectorId cid);
 

	
 
intptr_t connector_next_batch(Connector *connector);
 

	
 
/**
 
 * Convenience function combining the functionalities of
 
 * "payload_new" with "connector_put_payload".
 
 */
 
ErrorCode connector_put_bytes(Connector *connector,
 
                              PortId port,
 
                              const uint8_t *bytes_ptr,
 
                              uintptr_t bytes_len);
 

	
 
ErrorCode connector_put_payload(Connector *connector, PortId port, Payload *payload);
 

	
 
ErrorCode connector_put_payload_cloning(Connector *connector, PortId port, const Payload *payload);
 

	
 
intptr_t connector_sync(Connector *connector, int64_t timeout_millis);
 

	
 
/**
 
 * Given an initialized protocol description, initializes `out` with a clone which can be independently created or destroyed.
 
 */
 
Arc_ProtocolDescription *protocol_description_clone(const Arc_ProtocolDescription *pd);
 

	
 
/**
 
 * Destroys the given initialized protocol description and frees its resources.
 
 */
 
void protocol_description_destroy(Arc_ProtocolDescription *pd);
 

	
 
/**
 
 * Parses the utf8-encoded string slice to initialize a new protocol description object.
 
 * - On success, initializes `out` and returns 0
 
 * - On failure, stores an error string (see `reowolf_error_peek`) and returns -1
 
 */
 
Arc_ProtocolDescription *protocol_description_parse(const uint8_t *pdl, uintptr_t pdl_len);
 

	
 
/**
 
 * Returns length (via out pointer) and pointer (via return value) of the last Reowolf error.
 
 * - pointer is NULL iff there was no last error
 
 * - data at pointer is null-delimited
 
 * - len does NOT include the length of the null-delimiter
 
 */
 
const uint8_t *reowolf_error_peek(uintptr_t *len);
 

	
 
#endif /* REOWOLF_HEADER_DEFINED */
examples/cpy_dll.sh
Show inline comments
 
new file 100644
 
cp ./../target/release/reowolf_rs.dll ./ --force
examples/eg_protocols.pdl
Show inline comments
 

	
 
primitive forward(in i, out o) {
 
	while(true) synchronous {
 
		put(o, get(i));
 
	}
 
}
 
composite dynamic(in i, out o) {
 
	new forward(i, o);
 
}
 
primitive sync(in i, out o) {
 
	while(true) synchronous {
 
		if(fires(i)) {
 
			put(o, get(i));
 
		}
 
	}
 
}
 

	
 
primitive sync_two(in ia, in ib, out oa, out ob) {
 
	while(true) synchronous {
 
		if (fires(ia)) {
 
			put(oa, get(ia));
 
			put(ob, get(ib));
 
		}
 
	}
 
}
 

	
 
primitive xor_three(in ai, out ao, in bi, out bo, in ci, out co) {
 
	synchronous {
 
		if      (fires(ai)) put(ao, get(ai));
 
		else if (fires(bi)) put(bo, get(bi));
 
		else                put(co, get(ci)); 
 
	}
 
}
 
\ No newline at end of file
 
primitive foo(){}
 
\ No newline at end of file
examples/old/1_socketlike/amy.c
Show inline comments
 
file renamed from examples/1_socketlike/amy.c to examples/old/1_socketlike/amy.c
examples/old/1_socketlike/bob.c
Show inline comments
 
file renamed from examples/1_socketlike/bob.c to examples/old/1_socketlike/bob.c
examples/old/1_socketlike/make.sh
Show inline comments
 
file renamed from examples/1_socketlike/make.sh to examples/old/1_socketlike/make.sh
examples/old/2_dynamic_pdl/amy.c
Show inline comments
 
file renamed from examples/2_dynamic_pdl/amy.c to examples/old/2_dynamic_pdl/amy.c
examples/old/2_dynamic_pdl/make.sh
Show inline comments
 
file renamed from examples/2_dynamic_pdl/make.sh to examples/old/2_dynamic_pdl/make.sh
examples/old/3_atomicity/amy.c
Show inline comments
 
file renamed from examples/3_atomicity/amy.c to examples/old/3_atomicity/amy.c
examples/old/3_atomicity/bob.c
Show inline comments
 
file renamed from examples/3_atomicity/bob.c to examples/old/3_atomicity/bob.c
examples/old/3_atomicity/make.sh
Show inline comments
 
file renamed from examples/3_atomicity/make.sh to examples/old/3_atomicity/make.sh
examples/old/4_nondeterminism/amy.c
Show inline comments
 
file renamed from examples/4_nondeterminism/amy.c to examples/old/4_nondeterminism/amy.c
examples/old/4_nondeterminism/make.sh
Show inline comments
 
file renamed from examples/4_nondeterminism/make.sh to examples/old/4_nondeterminism/make.sh
examples/old/5_recovery/amy.c
Show inline comments
 
file renamed from examples/5_recovery/amy.c to examples/old/5_recovery/amy.c
examples/old/5_recovery/bob.c
Show inline comments
 
file renamed from examples/5_recovery/bob.c to examples/old/5_recovery/bob.c
examples/old/5_recovery/make.sh
Show inline comments
 
file renamed from examples/5_recovery/make.sh to examples/old/5_recovery/make.sh
examples/old/6_constraint_solve/main.c
Show inline comments
 
file renamed from examples/6_constraint_solve/main.c to examples/old/6_constraint_solve/main.c
examples/old/6_constraint_solve/make.sh
Show inline comments
 
file renamed from examples/6_constraint_solve/make.sh to examples/old/6_constraint_solve/make.sh
examples/old/REMINDER dll is a symlink.txt
Show inline comments
 
file renamed from examples/REMINDER dll is a symlink.txt to examples/old/REMINDER dll is a symlink.txt
examples/old/eg_protocols.pdl
Show inline comments
 
new file 100644
 

	
 
primitive forward(in i, out o) {
 
	while(true) synchronous {
 
		put(o, get(i));
 
	}
 
}
 
composite dynamic(in i, out o) {
 
	new forward(i, o);
 
}
 
primitive sync(in i, out o) {
 
	while(true) synchronous {
 
		if(fires(i)) {
 
			put(o, get(i));
 
		}
 
	}
 
}
 

	
 
primitive sync_two(in ia, in ib, out oa, out ob) {
 
	while(true) synchronous {
 
		if (fires(ia)) {
 
			put(oa, get(ia));
 
			put(ob, get(ib));
 
		}
 
	}
 
}
 

	
 
primitive xor_three(in ai, out ao, in bi, out bo, in ci, out co) {
 
	synchronous {
 
		if      (fires(ai)) put(ao, get(ai));
 
		else if (fires(bi)) put(bo, get(bi));
 
		else                put(co, get(ci)); 
 
	}
 
}
 
\ No newline at end of file
examples/old/utility.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <errno.h>
 

	
 
void check(const char* phase, int code) {
 
	if (code < 0) {
 
		printf("ERR %d in phase `%s`. Err was `%s`\nEXITING!\n",
 
			code, phase, connector_error_peek());
 
		exit(1);
 
	}
 
}
 

	
 
// allocates a buffer!
 
char * buffer_pdl(char * filename) {
 
	FILE *f = fopen(filename, "rb");
 
	if (f == NULL) {
 
		printf("Opening pdl file returned errno %d!\n", errno);
 
		exit(1);
 
	}
 
	fseek(f, 0, SEEK_END);
 
	long fsize = ftell(f);
 
	fseek(f, 0, SEEK_SET);
 
	char *pdl = malloc(fsize + 1);
 
	fread(pdl, 1, fsize, f);
 
	fclose(f);
 
	pdl[fsize] = 0;
 
	return pdl;
 
}
 
\ No newline at end of file

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)