This update adds threading to the Shadow compiler through the following syntax:
spawn( object ): Returns a new Thread object running the run() method of object (which must have the CanRun interface)
spawn[name]( object ): Returns a new Thread object called name (which must be of type String) running the run() method of object (which must have the CanRun interface)
send( data, thread ): Send the object data to thread thread, blocking if there isn't room in message queue
send*( data, thread ): Send the object data to thread thread, throwing an exception if there isn't room in message queue
receive<type>(): Receive data of type type from any thread, blocking until data is available, throwing an error if the data has the wrong type
receive<type>( thread ): Receive data of type type from thread thread, blocking until data is available, throwing an error if the data has the wrong type
receive*<type>(): Receive data of type type from any thread, returning null if no data is available, throwing an error if the data has the wrong type
receive*<type>( thread ): Receive data of type type from thread thread, returning null if no data is available, throwing an error if the data has the wrong type
Additional threading features like joining threads and sleeping are provided through the Thread class and the Thread:Current singleton.
Attributes
This update also includes attributes that can be used to mark methods:
[Attribute(3, "text")]
public method(int x) => (double)
{
...
}
Attributes (like the one shown above) can have create calls that take one or more arguments, but many attributes will take no arguments and thus require no parentheses. Values and methods inside of attributes are interpreted at compile time but can be referenced in code. In the future, it should be possible to request from an object a list of its methods that math given attributes. Likewise, more code interpretation will become available. (Loops, for example, are not currently supported but one day will be, dangerous though that is.) Attributes allow a kind of meta-programming that shares commonalities with #define in C or templates in C++ but is type-safe and less powerful.
C Micro-architecture
The standard library extensively uses the C micro-architecture developed by @claude-abounegm. For a lot of system-specific code, it's possible to write it in C instead of LLVM IR. (A few things still require IR, especially relating to garbage collection.) The threading libraries would be impossible with the C micro-architecture.
Writing code in C is still dangerous and should be done as rarely as possible. (But it's much more readable than writing LLVM IR.)
In addition, some changes were made to allow native compilation on Windows, using VS tools, linked through clang, allowing arbitrary Windows libraries to be linked. Windows executables are also somewhat smaller than before since some libraries are dynamically linked.
In another advancement, only clang and not the other LLVM utilities like llc and opt are now required.
Compilation Improvements
Many improvements were made to the speed and simplicity of the compiler. Now, the compiler produces .o files. If a Shadow file doesn't need to be recompiled, an existing .o file can simply be linked. A matching pair of a .meta file and a .o file is similar to a matching pair of a .h and a .o file in C.
Another important change is that the configuration file allows a list of src and matching bin directories to be specified, allowing the source and resulting object files to have separate but mirrored directory structures. Similarly, source, include, and binary directories can be specified for the standard library, allowing these files to be installed in a central location with global read but not write access.
Threading
This update adds threading to the Shadow compiler through the following syntax:
spawn( object )
: Returns a newThread
object running therun()
method ofobject
(which must have theCanRun
interface)spawn[name]( object )
: Returns a newThread
object calledname
(which must be of typeString
) running therun()
method ofobject
(which must have theCanRun
interface)send( data, thread )
: Send the objectdata
to threadthread
, blocking if there isn't room in message queuesend*( data, thread )
: Send the objectdata
to threadthread
, throwing an exception if there isn't room in message queuereceive<type>()
: Receive data of typetype
from any thread, blocking until data is available, throwing an error if the data has the wrong typereceive<type>( thread )
: Receive data of typetype
from threadthread
, blocking until data is available, throwing an error if the data has the wrong typereceive*<type>()
: Receive data of typetype
from any thread, returningnull
if no data is available, throwing an error if the data has the wrong typereceive*<type>( thread )
: Receive data of typetype
from threadthread
, returningnull
if no data is available, throwing an error if the data has the wrong typeAdditional threading features like joining threads and sleeping are provided through the
Thread
class and theThread:Current
singleton.Attributes
This update also includes attributes that can be used to mark methods:
Attributes (like the one shown above) can have
create
calls that take one or more arguments, but many attributes will take no arguments and thus require no parentheses. Values and methods inside of attributes are interpreted at compile time but can be referenced in code. In the future, it should be possible to request from an object a list of its methods that math given attributes. Likewise, more code interpretation will become available. (Loops, for example, are not currently supported but one day will be, dangerous though that is.) Attributes allow a kind of meta-programming that shares commonalities with#define
in C or templates in C++ but is type-safe and less powerful.C Micro-architecture
The standard library extensively uses the C micro-architecture developed by @claude-abounegm. For a lot of system-specific code, it's possible to write it in C instead of LLVM IR. (A few things still require IR, especially relating to garbage collection.) The threading libraries would be impossible with the C micro-architecture.
Writing code in C is still dangerous and should be done as rarely as possible. (But it's much more readable than writing LLVM IR.)
In addition, some changes were made to allow native compilation on Windows, using VS tools, linked through
clang
, allowing arbitrary Windows libraries to be linked. Windows executables are also somewhat smaller than before since some libraries are dynamically linked.In another advancement, only
clang
and not the other LLVM utilities likellc
andopt
are now required.Compilation Improvements
Many improvements were made to the speed and simplicity of the compiler. Now, the compiler produces
.o
files. If a Shadow file doesn't need to be recompiled, an existing.o
file can simply be linked. A matching pair of a.meta
file and a.o
file is similar to a matching pair of a.h
and a.o
file in C.Another important change is that the configuration file allows a list of
src
and matchingbin
directories to be specified, allowing the source and resulting object files to have separate but mirrored directory structures. Similarly, source, include, and binary directories can be specified for the standard library, allowing these files to be installed in a central location with global read but not write access.