Skip to content

Commit

Permalink
inside joke
Browse files Browse the repository at this point in the history
  • Loading branch information
cetio committed May 9, 2024
1 parent 84be05f commit 320f544
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 24 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Examples [exist](examples) but are small tidbits meant to facilitate parser test

2. [Grammar](spec/grammar.md)
3. [Lexical](spec/lexical.md)
4. [Metaprogramming](spec/metaprogramming.md)

Fern is planned to be able to, as well as natively compile, compile into CIL which may be interpreted directly as if Fern were C# and the standard library is likely to incorporate a more fully fleshed out rendition of [Godwit](https://github.com/cetio/godwit) to enable full seamless integration and interop with .NET languages.

Expand Down
41 changes: 20 additions & 21 deletions source/fern/symbols.d
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public enum SymAttr : ulong
FLOAT = 1L << 50,
DOUBLE = 1L << 51,
SIGNED = 1L << 52,

GLOB = 1L << 53,
}

public class Symbol
Expand All @@ -90,12 +92,11 @@ final:
Symbol[] attributes;
}

public class Type
public class Type : Symbol
{
public:
final:
Symbol sym;
Symbol[] inherits;
Type[string] inherits;
Field[string] fields;
Function[string] functions;
ubyte[] data;
Expand All @@ -104,32 +105,32 @@ final:

string type()
{
if ((sym.attr & SymAttr.CLASS) != 0)
if ((attr & SymAttr.CLASS) != 0)
return "class";
else if ((sym.attr & SymAttr.TAGGED) != 0)
else if ((attr & SymAttr.TAGGED) != 0)
return "tagged";
else //if ((sym.attr & SymAttr.STRUCT) != 0)
else //if ((attr & SymAttr.STRUCT) != 0)
return "struct";
}
}

public class Function
public class Function : Symbol
{
public:
final:
Symbol sym;
Symbol returnof;
Symbol[] parameters;
// The first parameter is always the return.
Local[string] parameters;
// This will include the return and parameters as the first locals.
Local[string] locals;
Instruction[] instructions;
size_t alignment;

string type()
{
// ctor and dtor are also functions, so we needn't check for them.
if ((sym.attr & SymAttr.FUNCTION) != 0)
if ((attr & SymAttr.FUNCTION) != 0)
return "function";
else if ((sym.attr & SymAttr.UNITTEST) != 0)
else if ((attr & SymAttr.UNITTEST) != 0)
return "unittest";
else
return "delegate";
Expand All @@ -142,31 +143,29 @@ public alias Local = Field;
// Expressions and literals should also be represented by a field,
// but I haven't yet worked this out.

public class Field
public class Field : Symbol
{
Marker marker;
alias marker this;

public:
final:
Symbol sym;
ubyte[] data;
size_t size;
size_t alignment;
size_t offset;
Marker marker;

alias marker this;

Symbol type()
{
return sym.parents[$-1];
return parents[$-1];
}
}

public class Module
public class Module : Symbol
{
public:
final:
Symbol sym;
Symbol[] imports;
Symbol[string] imports;
Field[string] fields;
Function[string] functions;
}
Expand Down
90 changes: 87 additions & 3 deletions spec/metaprogramming.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Member Evaluations

> Locals are commonly referred to as variables, which in Fern are specifically variables that are local to a function (ie: not a field or parameter variable. )
| Member | Evaluates | Applicable |
|--------|-----------|------------|
| `attributes` | All attributes of the given symbol. | All |
Expand All @@ -16,9 +18,91 @@
| `offsetof` | The offset of the given symbol's data. | Variables |
| `returnof` | Return type of the given symbol. | Functions |
| `parameters` | Parameters of the given symbol. | Functions |
| `locals` | Locals of the given symbol. | Functions |
| `children` | Imported symbols of the given symbol. | Module |

## Symbol Kinds & Formats
## Symbol Attributes & Formats

| Symbol Kind | Definition |
| Symbol Attribute | Definition |
|-------------|------------|
|
| `type` | Structure of data with or without instance presence - `struct`, `class`, `tagged` or `tuple`. |
| `struct` | A product-type aggregate passed by-value. |
| `class` | A product-type aggregate passed by-reference. |
| `tagged` | A sum-type aggregate passed by-value with a `tag`. |
| `tuple` | A sum-type aggregate passed by-value with arbitrary types. |
| `module` | Top or domain level scope with no instance presence. |
| `function` | Executable code scope taking parameters and returning a return type. |
| `delegate` | Dynamic executable code scope taking parameters and returning a return type from an address. |
| `lambda` | Special inline format of `delegate`. |
| `ctor` | Scope constructor, namely used for `type` and `module`. |
| `dtor` | Scope destructor, namely used for `type` and `module`. |
| `unittest` | Scope independent executable code taking no parameters and not returning anything. Executes synchronously and may not be called. |
| `field` | Data that exists and persists outside of an execution scope. |
| `local` | Data that exists and persists only inside of an execution scope. |
| `parameter` | Local declarations in a function signature which require arguments. |
| `expression` | Code which may not function without an existing statement to modify, like `1 + 1` |
| `literal` | Value known to the compiler before execution. |
| `glob` | The global scope of the entire program, containing all of its symbols. |

This is implementation defined, but generally symbols have or store the same information as the following formats internally:

```
Symbol [
SymAttr attr;
string name;
Symbol[] parents;
Symbol[] children;
Symbol[] attributes;
]
```

```
Type : Symbol [
Type[string] inherits;
Field[string] fields;
Function[string] functions;
ubyte[] init;
size_t sizeof;
size_t alignof;
]
```

```
# This is also used for delegates, lambdas, ctors, dtors, and unittests.
Function : Symbol [
// The first parameter is always the return.
Local[string] parameters;
// This will include the return and parameters as the first locals.
Local[string] locals;
Instruction[] instructions;
size_t alignof;
]
```

```
# This is also used for locals, parameters, expressions, and literals.
Field : Symbol [
ubyte[] init;
size_t sizeof;
size_t alignof;
size_t offsetof;
Marker marker;
]
```

```
Module : Symbol [
Symbol[string] imports;
Field[string] fields;
Function[string] functions;
]
```

```
# This is used to store global information about the program.
Glob : Symbol [
Symbol[string] imports;
Field[string] fields;
Function[string] functions;
]
```

0 comments on commit 320f544

Please sign in to comment.