TeamShadow / shadow

Reference compiler for the Shadow programming language.
http://shadow-language.org/
Apache License 2.0
12 stars 8 forks source link

Threading and other major updates #86

Closed bwittman closed 1 year ago

bwittman commented 1 year ago

Threading

This update adds threading to the Shadow compiler through the following syntax:

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.