Announcing Mecca

2018-05-03 Thread Shachar Shemesh via Digitalmars-d-announce

Hello everybody,

I am very happy to announce that Mecca version 0.0.1 (sorry, no more 
zeros than that) is now officially available. You can get the source 
code at https://github.com/weka-io/mecca. The API documentation is at 
https://weka-io.github.com/mecca/docs.


Mecca is a run-time support library for fibers management, as well as a 
few useful containers and libraries.


At this point in time, a getting started tutorial is still not 
available. Instead, I will post this small program for an echo server. 
It should give you a hint what APIs to check out with the documentation, 
so you can expand your search:


import core.sys.posix.sys.socket;
import std.algorithm : move;
import std.functional : toDelegate;

import mecca.log;
import mecca.reactor;
import mecca.reactor.io.fd;
import mecca.reactor.io.signals;

enum EchoerPort = 31337;

int main()
{
theReactor.setup();

reactorSignal.registerHandler(OSSignal.SIGTERM, 
toDelegate());
reactorSignal.registerHandler(OSSignal.SIGINT, 
toDelegate());


theReactor.spawnFiber!listener();

return theReactor.start();
}

void termHandler(ref const(signalfd_siginfo) siginfo) {
// Signal handler, but any non-yielding operation is safe to call 
from here.

theReactor.stop();
}

void listener() {
auto listenSocket = ConnectedSocket.listen( SockAddrIPv4.any( 
EchoerPort ) );

listenSocket.setSockOpt( SOL_SOCKET, SO_REUSEADDR, 1 );

while( true ) {
SockAddr clientAddress;
auto clientSocket = listenSocket.accept(clientAddress);

// The next line's toString is the only reason we can't annotate
// listener as @nogc.
INFO!"Received new connection from %s"(clientAddress.toString());
theReactor.spawnFiber!echoClient( move(clientSocket) );
}
}

void echoClient(ConnectedSocket sock) @nogc {
ssize_t dataLength;
do {
char[4096] buffer;
dataLength = sock.read(buffer);
sock.write(buffer[0..dataLength]);
} while( dataLength>0 );
}


Re: [OT?] C compiler written form scratch in D

2014-12-11 Thread Shachar Shemesh via Digitalmars-d-announce

On 09/12/14 02:45, deadalnix wrote:

On Monday, 8 December 2014 at 15:44:55 UTC, Stefan Koch wrote:

I want to do a C backend first.
Building an LLVM Backand out of that is a small step.


There is already a very popular C to C compiler out there. It is
called cat, and come out of the box with any UNIX like system.


I know it was meant as a joke, but I couldn't resist nitpicking.

When Stroustrup started out with an OO successor to C, he wrote a 
preprocessor that would convert his new syntax to C, to be passed to a C 
compiler. When the language started to evolve, that proved insufficient, 
and he wrote CFront, a C++ to C compiler.


He defines the difference between a preprocessor and a compiler along 
these lines: With a compiler, any and all compilation errors need to be 
caught by the front end. If the front end accepted your program, and the 
back end fails to compile it, it is, by definition, a compiler bug.


As such, cat (nor its close neighbor, tac | tac), are not a compiler, 
since it does not catch compilation errors.


Sorry for the nitpick.
Shachar