From 2d02cc5dcc8077815ffc3d7b14337aa7fdb5ac59 Mon Sep 17 00:00:00 2001 From: cetio Date: Tue, 14 May 2024 08:46:03 -0400 Subject: [PATCH] add more symbols to rt reorganize some stuff add new context state and make glob a symbol (forgot to do this before apparently?) --- rt/array.fn | 37 ------------------ rt/aso.fn | 15 +++++++ rt/object.fn | 39 ++++++++++++++++--- rt/symbols.fn | 93 +++++++++++++++++++++++++++++++++++++++++++- source/fnc/symbols.d | 3 +- 5 files changed, 143 insertions(+), 44 deletions(-) delete mode 100644 rt/array.fn create mode 100644 rt/aso.fn diff --git a/rt/array.fn b/rt/array.fn deleted file mode 100644 index 3e6bc1a..0000000 --- a/rt/array.fn +++ /dev/null @@ -1,37 +0,0 @@ -module rt.array; - -public T[] __iota(T)(T start, T end) - if (T->isIntegral) -{ - return = T[end - start]; - nuint iter; - while (start < end) - return[iter++] = start++; -} - -public T __slice(T)(const T val, nuint start, nuint stop) - if (T->isArray) -{ - return.length = stop - start; - return.ptr = val.ptr + start; -} - -// in void* out void[] from the slice. -public (T->type)[] __slice(T)(T val, nuint start, nuint stop) - if (T->isPointer) -{ - return.length = stop - start; - return.ptr = val + start; -} - -public struct Array(T) -{ - nuint length; - T* ptr; -} - -public struct AsoArray(K, V) -{ - K[] keys; - V?[] values; -} \ No newline at end of file diff --git a/rt/aso.fn b/rt/aso.fn new file mode 100644 index 0000000..6ad1b8f --- /dev/null +++ b/rt/aso.fn @@ -0,0 +1,15 @@ +module rt.aso; + +public struct AsoArray(K, V) +{ + K[] keys; + V?[] values; +} + +/* public ulong hash(T)(const T val) trusted +{ + foreach (b; val |> ubyte[T->size]) + { + + } +} */ \ No newline at end of file diff --git a/rt/object.fn b/rt/object.fn index 502bede..471f9ad 100644 --- a/rt/object.fn +++ b/rt/object.fn @@ -67,10 +67,39 @@ public T->inherits[$-1] __downcast(T)(const T val) return __convert!(T->inherits[$-1])(val); } -/* public ulong hash(T)(const T val) trusted +public T[] __iota(T)(T start, T end) + if (T->isIntegral) { - foreach (b; val |> ubyte[T->size]) - { + return = T[end - start]; + nuint iter; + while (start < end) + return[iter++] = start++; +} - } -} */ \ No newline at end of file +public T __slice(T)(const T val, nuint start, nuint stop) + if (T->isArray) +{ + return.length = stop - start; + return.ptr = val.ptr + start; +} + +// in void* out void[] from the slice. +public (T->type)[] __slice(T)(T val, nuint start, nuint stop) + if (T->isPointer) +{ + return.length = stop - start; + return.ptr = val + start; +} + +public T->type pop(T)(ref T val) + if (T->isDynamicArray) +{ + return = val[$-1]; + val = val[0..$-1]; +} + +public A push(A, B)(ref A val, B elem) + if (T->isDynamicArray) +{ + return = val ~= elem; +} \ No newline at end of file diff --git a/rt/symbols.fn b/rt/symbols.fn index 23f47b1..a3f5607 100644 --- a/rt/symbols.fn +++ b/rt/symbols.fn @@ -1,6 +1,6 @@ module rt.symbols; -public const tagged SymAttr : ^long +public const tagged __SymAttr : ^long { // Top-Level Kind TYPE = 1 << 0; @@ -73,4 +73,95 @@ public const tagged SymAttr : ^long SIGNED = 1 << 52; GLOB = 1 << 53; + ALIAS = 1L << 54; + + FORMAT_MASK = DYNARRAY | ASOARRAY | SIGNED | FLOAT | DOUBLE | BITFIELD; +} + +public class __Symbol +{ +public: + __Glob glob; + __SymAttr symattr; + string name; + __Symbol[] parents; + __Symbol[] children; + __Symbol[string] attributes; + + string identifier() + { + string ret; + foreach (parent; parents) + ret ~= parent.name~'.'; + return ret~name; + } +} + +public class __Type : __Symbol +{ +public: + __Type[string] inherits; + __Variable[] fields; + __Function[] functions; + ubyte[] data; + size_t size; + size_t align; +} + +public class __Function : __Symbol +{ +public: + // Will begin with all alias parameters and then subsequently ret-args. + __Symbol[] parameters; + // Will begin with ret-args and then subsequently all locals. + __Symbol[] locals; + //Instruction[] instructions; + size_t align; +} + + +public class __Variable : __Symbol +{ +public: + __Type type; + ubyte[] data; + size_t size; + size_t align; + size_t offset; +} + +// The tagged is acting like a class here because of kind:heap. +public tagged kind:heap __Alias : __Symbol +{ +public: + __Symbol single; + __Symbol[] many; +} + +public class __Module : __Symbol +{ +public: + __Symbol[] imports; + __Type[] types; + __Variable[] fields; + __Function[] functions; +} + +public class __Glob : __Symbol +{ +public: + __Symbol[string] symbols; + __Module[string] modules; + __Type[string] types; + __Variable[string] variables; + __Function[string] functions; + __Alias[string] aliases; + __Function[] unittests; + __Symbol[] context; +} + +public alias __this() +{ + // TODO: Add this to the language. + return glob->context->prev; } \ No newline at end of file diff --git a/source/fnc/symbols.d b/source/fnc/symbols.d index 4d40cbb..15a5f99 100644 --- a/source/fnc/symbols.d +++ b/source/fnc/symbols.d @@ -443,7 +443,7 @@ final: Function[] functions; } -public class Glob +public class Glob : Symbol { public: final: @@ -454,4 +454,5 @@ final: Function[string] functions; Alias[string] aliases; Function[] unittests; + Scope[] context; } \ No newline at end of file