Skip to content

Commit

Permalink
add symbols for keywords and refactor flags a bit to allow for more f…
Browse files Browse the repository at this point in the history
…lags eventually
  • Loading branch information
cetio committed May 23, 2024
1 parent a25e7a9 commit 03a18d8
Showing 1 changed file with 190 additions and 78 deletions.
268 changes: 190 additions & 78 deletions source/fnc/symbols.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,64 @@ import core.time;
public:
/// The global glob from which all symbols should originate.
static Glob glob;
static Symbol _class;
static Symbol _struct;
static Symbol _class;
static Symbol _tagged;
static Symbol _alias;
static Symbol _function;
static Symbol _delegate;
static Symbol _unittest;
static Symbol _aliasseq;
static Symbol _return;
static Symbol _this;
static Symbol _delete;
static Symbol _bool;
static Symbol _true;
static Symbol _false;
static Symbol _byte;
static Symbol _ubyte;
static Symbol _short;
static Symbol _ushort;
static Symbol _int;
static Symbol _uint;
static Symbol _long;
static Symbol _ulong;
static Symbol _float;
static Symbol _double;
static Symbol _nint;
static Symbol _nuint;
static Symbol _void;
static Symbol _char;
static Symbol _wchar;
static Symbol _dchar;
static Symbol _string;
static Symbol _wstring;
static Symbol _dstring;
static Symbol _pure;
static Symbol _const;
static Symbol _static;
static Symbol _public;
static Symbol _private;
static Symbol _internal;
static Symbol _partial;
static Symbol _system;
static Symbol _trusted;
static Symbol _safe;
static Symbol _inline;
static Symbol _mustuse;
static Symbol _ref;
static Symbol _atomic;
static Symbol _import;
static Symbol _if;
static Symbol _else;
static Symbol _foreach;
static Symbol _foreach_reverse;
static Symbol _while;
static Symbol _goto;
static Symbol _with;
static Symbol _break;
static Symbol _continue;
static Symbol _is;

shared static this()
{
Expand All @@ -34,88 +84,148 @@ shared static this()
_delegate = new Expression("delegate");
_unittest = new Expression("unittest");
_aliasseq = new Expression("alias[]");
_return = new Expression("return");
_this = new Expression("this");
_delete = new Expression("delete");
_bool = new Expression("bool");
_true = new Expression("true");
_false = new Expression("false");
_byte = new Expression("byte");
_ubyte = new Expression("ubyte");
_short = new Expression("short");
_ushort = new Expression("ushort");
_int = new Expression("int");
_uint = new Expression("uint");
_long = new Expression("long");
_ulong = new Expression("ulong");
_float = new Expression("float");
_double = new Expression("double");
_nint = new Expression("nint");
_nuint = new Expression("nuint");
_void = new Expression("void");
_char = new Expression("char");
_wchar = new Expression("wchar");
_dchar = new Expression("dchar");
_string = new Expression("string");
_wstring = new Expression("wstring");
_dstring = new Expression("dstring");
_pure = new Expression("pure");
_const = new Expression("const");
_static = new Expression("static");
_public = new Expression("public");
_private = new Expression("private");
_internal = new Expression("internal");
_partial = new Expression("partial");
_system = new Expression("system");
_trusted = new Expression("trusted");
_safe = new Expression("safe");
_inline = new Expression("inline");
_mustuse = new Expression("mustuse");
_ref = new Expression("ref");
_atomic = new Expression("atomic");
_import = new Expression("import");
_if = new Expression("if");
_else = new Expression("else");
_foreach = new Expression("foreach");
_foreach_reverse = new Expression("foreach_reverse");
_while = new Expression("while");
_goto = new Expression("goto");
_with = new Expression("with");
_break = new Expression("break");
_continue = new Expression("continue");
_is = new Expression("is");
}

public enum SymAttr : ulong
{
// TODO: Make sure Fern can automatically infer long from shifting,
// D doesn't do this so 1 << 32 throws an error about the fact that 1 is assumed to be int.

// Top-Level Kind
// Variants
TYPE = 1L << 0,
STRUCT = 1L << 1,
CLASS = 1L << 2,
TAGGED = 1L << 3,
TUPLE = 1L << 4,

FUNCTION = 1L << 5,
DELEGATE = 1L << 6,
LAMBDA = 1L << 7,
CTOR = 1L << 8,
DTOR = 1L << 9,
UNITTEST = 1L << 10,

FIELD = 1L << 11,
LOCAL = 1L << 12,
PARAMETER = 1L << 13,

EXPRESSION = 1L << 14,
LITERAL = 1L << 15,
MODULE = 1L << 1,
VARIABLE = 1L << 2,
FUNCTION = 1L << 3,
EXPRESSION = 1L << 4,
LITERAL = 1L << 5,
GLOB = 1L << 6,
ALIAS = 1L << 7,

// Attributes
PUBLIC = 1L << 16,
PRIVATE = 1L << 17,
INTERNAL = 1L << 18,

SAFE = 1L << 19,
SYSTEM = 1L << 20,
TRUSTED = 1L << 21,

STATIC = 1L << 22,
// NOT thread-local storage.
GLOBAL = 1L << 23,
// Non-temporal.
TRANSIENT = 1L << 24,
ATOMIC = 1L << 25,
BITFIELD = 1L << 26,
PURE = 1L << 36,
CONST = 1L << 37,
REF = 1L << 38,

KIND_HEAP = 1L << 27,
KIND_STACK = 1L << 28,
KIND_SCALAR = 1L << 29,
KIND_FLOAT = 1L << 30,
KIND_XMM = 1L << 31,
KIND_YMM = 1L << 32,
KIND_ZMM = 1L << 33,
KIND_READONLY = 1L << 34,
KIND_DEFAULT = 1L << 35,

ARRAY = 1L << 39,
DYNARRAY = 1L << 40,
// Static array.
FIXARRAY = 1L << 41,
// Associative array.
ASOARRAY = 1L << 42,

STRING = 1L << 43,
WSTRING = 1L << 44,
DSTRING = 1L << 45,
BYTE = 1L << 46,
WORD = 1L << 47,
DWORD = 1L << 48,
QWORD = 1L << 49,
FLOAT = 1L << 50,
DOUBLE = 1L << 51,
SIGNED = 1L << 52,

GLOB = 1L << 53,
ALIAS = 1L << 54,
PUBLIC_IMPORT = 1L << 55,
MODULE = 1L << 56,
//OPTIONAL = 1L << 57,

PUBLIC = 1L << 8,
PRIVATE = 1L << 9,
INTERNAL = 1L << 10,
STATIC = 1L << 11,

// Variable and functions
CONST = 1L << 12,
// Is this variable's size too large to put in the executable as data?
// Is this function's code size too large to inline?
FAT = 1L << 13,
// Is this variable or function safe to do anything we want with it in terms of size?
TINY = 1L << 14,

// Functions
DELEGATE = 1L << 15,
UNITTEST = 1L << 16,
LAMBDA = 1L << 17,
CTOR = 1L << 18,
DTOR = 1L << 19,
PURE = 1L << 20,
SAFE = 1L << 21,
TRUSTED = 1L << 22,
SYSTEM = 1L << 23,

// Variables
// Is this variable's data not TLS?
GLOBAL = 1L << 15,
// Is this variable non-temporal and won't enter the cache?
TRANSIENT = 1L << 16,
ATOMIC = 1L << 17,
BITFIELD = 1L << 18,
// Is this variable going to have its GC allocation inlined?
EMPLACE = 1L << 19,
LOCAL = 1L << 20,
PARAMETER = 1L << 21,

// Variables, types, and literals
ARRAY = 1L << 22,
DYNARRAY = 1L << 23,
FIXARRAY = 1L << 24,
ASOARRAY = 1L << 26,

STRING = 1L << 27,
WSTRING = 1L << 28,
DSTRING = 1L << 29,
BYTE = 1L << 30,
WORD = 1L << 31,
DWORD = 1L << 32,
QWORD = 1L << 33,
FLOAT = 1L << 34,
DOUBLE = 1L << 34,
SIGNED = 1L << 35,

STRUCT = 1L << 36,
CLASS = 1L << 37,
TAGGED = 1L << 38,
TUPLE = 1L << 39,
KIND_HEAP = 1L << 40,
KIND_STACK = 1L << 41,
KIND_SCALAR = 1L << 42,
KIND_FLOAT = 1L << 43,
KIND_XMM = 1L << 44,
KIND_YMM = 1L << 45,
KIND_ZMM = 1L << 46,
KIND_READONLY = 1L << 47,
KIND_DEFAULT = 1L << 48,

/// Is this symbol a pointer or variable passed by ref?
REF = 1L << 25,

FIELD = VARIABLE | LOCAL | PARAMETER,
AGGREGATE = TYPE | MODULE,
FLOATING = FLOAT | DOUBLE,
INTEGRAL = BYTE | WORD | DWORD | QWORD,
FORMAT_MASK = DYNARRAY | ASOARRAY | SIGNED | FLOAT | DOUBLE | BITFIELD
}

Expand Down Expand Up @@ -168,6 +278,7 @@ final:
return ret;
}

// TODO: Destroy symbols and create a new reference if they already exist to minimize footprint.
void finalize()
{
// TODO: Lock in more places for safety?
Expand Down Expand Up @@ -225,7 +336,7 @@ final:
bool isGlob() => (symattr & SymAttr.GLOB) != 0;
bool isAlias() => (symattr & SymAttr.ALIAS) != 0;
bool isAliasSeq() => isAlias && isArray;
bool isAggregate() => isModule || isStruct || isClass || isTagged || isTuple;
bool isAggregate() => (symattr & SymAttr.AGGREGATE) != 0;

bool isFunction() => (symattr & SymAttr.FUNCTION) != 0;
bool isDelegate() => (symattr & SymAttr.DELEGATE) != 0;
Expand All @@ -234,10 +345,10 @@ final:
bool isDtor() => (symattr & SymAttr.DTOR) != 0;
bool isUnittest() => (symattr & SymAttr.UNITTEST) != 0;

bool isField() => (symattr & SymAttr.FIELD) != 0;
bool isField() => (symattr & SymAttr.FIELD) == SymAttr.VARIABLE;
bool isLocal() => (symattr & SymAttr.LOCAL) != 0;
bool isParameter() => (symattr & SymAttr.PARAMETER) != 0;
bool isVariable() => isField || isLocal || isParameter;
bool isVariable() => (symattr & SymAttr.VARIABLE) != 0;

bool isExpression() => (symattr & SymAttr.EXPRESSION) != 0;
bool isLiteral() => (symattr & SymAttr.LITERAL) != 0;
Expand All @@ -249,8 +360,8 @@ final:
bool isString() => (symattr & SymAttr.STRING) != 0;
bool isWideString() => (symattr & SymAttr.WSTRING) != 0 || (symattr & SymAttr.DSTRING) != 0;
bool isSigned() => (symattr & SymAttr.SIGNED) != 0;
bool isIntegral() => (symattr & SymAttr.BYTE) != 0 || (symattr & SymAttr.WORD) != 0 || (symattr & SymAttr.DWORD) != 0 || (symattr & SymAttr.QWORD) != 0;
bool isFloating() => (symattr & SymAttr.FLOAT) != 0 || (symattr & SymAttr.DOUBLE) != 0;
bool isIntegral() => (symattr & SymAttr.INTEGRAL) != 0;
bool isFloating() => (symattr & SymAttr.FLOATING) != 0;
bool isNumeric() => isIntegral || isFloating;
bool isByRef() => isClass || isKHeap || isRef;
bool isVector() => isKXMM || isKYMM || isKZMM;
Expand Down Expand Up @@ -556,6 +667,7 @@ public class Module : Symbol
{
public:
final:
// TODO: Public imports.
Symbol[] imports;
Type[] types;
Variable[] fields;
Expand Down

0 comments on commit 03a18d8

Please sign in to comment.