Skip to content

Commit

Permalink
wretched souls... part your ways with agony, i decree thine misery sh…
Browse files Browse the repository at this point in the history
…all end... and all will become whole once more
  • Loading branch information
cetio committed May 13, 2024
1 parent 05f85a6 commit 6b71740
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions source/fnc/symbols.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module fnc.symbols;
import fnc.emission;
import tern.state;
import tern.algorithm.mutation : insert, alienate;
import tern.algorithm.searching : contains, indexOf;

// All symbols may have their members accessed at comptime using `->` followed by the member name, alignment is internally align and marker is not visible.
// All symbols may have their children accessed at comptime using `->` followed by the Child name, alignment is internally align and marker is not visible.

public enum SymAttr : ulong
{
Expand Down Expand Up @@ -99,7 +100,7 @@ final:
string name;
Symbol[] parents;
Symbol[] children;
Symbol[] attributes;
Symbol[string] attributes;

string identifier()
{
Expand Down Expand Up @@ -181,7 +182,9 @@ final:
bool isNested() => parents.length > 0 && !parent.isModule;
bool isPrimitive() => !isAggregate && !isArray;
bool isBuiltin() => !isAggregate;
bool hasDepth() => depth > 0;
bool hasDepth() => isType && (cast(Type)this).depth > 0;
bool hasBody() => isFunction && (cast(Function)this).instructions.length > 0;
bool hasDataAllocations() => (isFunction && (cast(Function)this).locals.length > 0) || (isAggregate && (cast(Type)this).fields.length > 0);
bool isEnum()
{
if (!isTagged)
Expand Down Expand Up @@ -222,14 +225,30 @@ final:
}
throw new Throwable("Tried to iterate overloads "~name~" for a non-function carrying symbol!");
}
// hasMember
// getMember
// getParent
// getInherit
// getField
// getFuncion
// getSymbol
// ...

Symbol getChild(string name) => glob.symbols[identifier~'.'~name];
Symbol getParent(string name) => glob.symbols[name~'.'~this.name];
Symbol getAttribute(string name) => attributes[name];
Field getField(string name) => glob.fields[identifier~'.'~name];
Function getFunction(string name) => glob.functions[identifier~'.'~name];
Symbol getInherit(string name) => (cast(Type)this).inherits[name];
Alias getAlias(string name) => glob.aliases[identifier~'.'~name];
// Templated functions/types need to be figured out somehow
bool hasParent(string name) => name~'.'~this.name in glob.symbols;
bool hasChild(string name) => identifier~'.'~name in glob.symbols;
bool hasAttribute(string name) => name in attributes;
bool hasField(string name) => hasChild(name) && getChild(name).isField;
bool hasFunction(string name) => hasChild(name) && getChild(name).isFunction;
bool hasInherit(string name) => isType && name in (cast(Type)this).inherits;
bool hasAlias(string name) => identifier~'.'~name in glob.symbols && getChild(name).isAlias;

bool hasParent(Symbol sym) => parents.contains(sym);
bool hasChild(Symbol sym) => sym.parent == this;
bool hasAttribute(Symbol sym) => sym.name in attributes;
bool hasField(Symbol sym) => sym.isField && sym.parent == this;
bool hasFunction(Symbol sym) => sym.isFunction && sym.parent == this;
bool hasInherit(Symbol sym) => inherits.contains(sym);
bool hasAlias(Symbol sym) => sym.isAlias && sym.parent == this;

Symbol freeze()
{
Expand All @@ -246,13 +265,22 @@ final:
{
return parents[$-1];
}

// The _ should not show up when doing symbol work in Fern.
// sym->module not sym->_module!
Module _module()
{
if (isPrimitive)
throw new Throwable("Tried to take the module of a primitive type!");
return cast(Module)parents[0];
}
}

public class Type : Symbol
{
public:
final:
Type[] inherits;
Type[string] inherits;
Variable[] fields;
Function[] functions;
ubyte[] data;
Expand Down Expand Up @@ -362,6 +390,7 @@ public class Variable : Symbol
{
public:
final:
Type type;
ubyte[] data;
size_t size;
size_t alignment;
Expand All @@ -370,11 +399,6 @@ final:
Marker marker;

alias marker this;

Type type()
{
return cast(Type)parents[$-1];
}
}

public class Alias : Symbol
Expand Down

0 comments on commit 6b71740

Please sign in to comment.