Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
cetio committed May 22, 2024
1 parent ae2f61e commit c167e5a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
2 changes: 1 addition & 1 deletion rt
Submodule rt updated 5 files
+1 −1 aso.fn
+1 −1 gc.fn
+13 −1 object.fn
+6 −6 symbols.fn
+2 −2 x86.fn
10 changes: 5 additions & 5 deletions source/arbore/cache.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import std.stdio;
public:
void store()
{
string[Module] caches;
dstring[Module] caches;
foreach (symbol; glob.symbols.byValue)
{
if (!symbol.evaluated)
Expand All @@ -16,13 +16,13 @@ void store()
caches[symbol._module] = null;

if (!symbol.isAliasSeq)
caches[symbol._module] ~= "alias "~symbol.identifier~" = "~(cast(Alias)symbol).single.identifier~";";
caches[symbol._module] ~= "alias "d~symbol.identifier~" = "d~(cast(Alias)symbol).single.identifier~";"d;
else
{
caches[symbol._module] ~= "alias[] "~symbol.identifier~" = [";
caches[symbol._module] ~= "alias[] "d~symbol.identifier~" = ["d;
foreach (sym; (cast(Alias)symbol).many)
caches[symbol._module] ~= sym.identifier~", ";
caches[symbol._module] = caches[symbol._module][0..$-2]~"];";
caches[symbol._module] ~= sym.identifier~", "d;
caches[symbol._module] = caches[symbol._module][0..$-2]~"];"d;
}
}
}
2 changes: 1 addition & 1 deletion source/fnc/rewritemeinfernwhenthelanguagecompiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Glob parse(string text)
foreach (line; text.splitLines)
{
string[] words = lines.split(' ');
size_t position;
nuint position;
if (words.length == 0)
continue;

Expand Down
72 changes: 42 additions & 30 deletions source/fnc/symbols.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import fnc.emission;
import tern.state;
import tern.algorithm.mutation : insert, alienate, filter;
import tern.algorithm.searching : contains, indexOf;
import tern.typecons.security : Atomic;
import core.thread.osthread;
import core.time;

// All symbols may have their children accessed at comptime using `->` followed by the child name, alignment is internally align and marker is not visible.
// TODO: Interface passing as argument, alias this. Inheriting and declaring as a field?
Expand Down Expand Up @@ -104,24 +107,33 @@ public class Symbol
public:
final:
SymAttr symattr;
string name;
dstring name;
Symbol parent;
Symbol[] children;
Symbol[] attributes;
// This is not front-facing!
Marker marker;
size_t refcount;
bool evaluated;
shared Atomic!bool lock;

alias marker this;

string identifier()
bool unlock() => lock = false;
bool waitLock()
{
string ret;
while (lock)
Thread.sleep(dur!("msecs")(10));
return lock = true;
}

dstring identifier()
{
dstring ret;
Symbol sym = parent;
while (sym !is null)
{
ret ~= sym.name~'.';
ret ~= sym.name~"."d;
sym = sym.parent;
}
return ret~name;
Expand All @@ -140,7 +152,7 @@ final:
// stupid ass language forces an explicit default constructor to be written
}

this(SymAttr symattr, string name, Symbol parent, Symbol[] children, Symbol[] attributes, Marker marker)
this(SymAttr symattr, dstring name, Symbol parent, Symbol[] children, Symbol[] attributes, Marker marker)
{
this.symattr = symattr;
this.name = name;
Expand Down Expand Up @@ -238,7 +250,7 @@ final:
}
return true;
}
Function[] getOverloads(string name)
Function[] getOverloads(dstring name)
{
Function[] ret;
if (isModule)
Expand All @@ -261,24 +273,24 @@ final:
}
return ret;
}
throw new Throwable("Tried to iterate overloads "~name~" for a non-function carrying symbol!");
throw new Throwable("Tried to iterate overloads "~cast(string)name~" for a non-function carrying symbol!");
}

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

bool hasParent(Symbol sym) => parents.contains(sym);
bool hasChild(Symbol sym) => sym.parent == this;
Expand Down Expand Up @@ -324,7 +336,7 @@ final:
// This is not front-facing to the runtime.
uint depth;

string type()
dstring type()
{
if ((symattr & SymAttr.CLASS) != 0)
return "class";
Expand Down Expand Up @@ -400,7 +412,7 @@ final:
Instruction[] instructions;
size_t alignment;

string type()
dstring type()
{
// ctor and dtor are also functions, so we needn't check for them.
if ((symattr & SymAttr.FUNCTION) != 0)
Expand Down Expand Up @@ -461,7 +473,7 @@ final:
return this;
}

string type()
dstring type()
{
if (isAliasSeq)
return "alias[]";
Expand All @@ -484,12 +496,12 @@ public class Glob : Symbol
{
public:
final:
Symbol[string] symbols;
Module[string] modules;
Type[string] types;
Variable[string] variables;
Function[string] functions;
Alias[string] aliases;
Symbol[dstring] symbols;
Module[dstring] modules;
Type[dstring] types;
Variable[dstring] variables;
Function[dstring] functions;
Alias[dstring] aliases;
Function[] unittests;
Symbol[] context;
}
3 changes: 1 addition & 2 deletions source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import fnc.treegen.scope_parser;
import fnc.treegen.expression_parser;
import fnc.treegen.relationships;
void main() {



ScopeData globalScope = parseMultilineScope(GLOBAL_SCOPE_PARSE, "
private module foo.bar;
int main(){
Expand Down
2 changes: 1 addition & 1 deletion std

0 comments on commit c167e5a

Please sign in to comment.