Skip to content

Commit

Permalink
add more symbols to rt
Browse files Browse the repository at this point in the history
reorganize some stuff
add new context state and make glob a symbol (forgot to do this before apparently?)
  • Loading branch information
cetio committed May 14, 2024
1 parent cee4b13 commit 2d02cc5
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 44 deletions.
37 changes: 0 additions & 37 deletions rt/array.fn

This file was deleted.

15 changes: 15 additions & 0 deletions rt/aso.fn
Original file line number Diff line number Diff line change
@@ -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])
{

}
} */
39 changes: 34 additions & 5 deletions rt/object.fn
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

}
} */
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;
}
93 changes: 92 additions & 1 deletion rt/symbols.fn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module rt.symbols;

public const tagged SymAttr : ^long
public const tagged __SymAttr : ^long
{
// Top-Level Kind
TYPE = 1 << 0;
Expand Down Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion source/fnc/symbols.d
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ final:
Function[] functions;
}

public class Glob
public class Glob : Symbol
{
public:
final:
Expand All @@ -454,4 +454,5 @@ final:
Function[string] functions;
Alias[string] aliases;
Function[] unittests;
Scope[] context;
}

0 comments on commit 2d02cc5

Please sign in to comment.