Skip to content

Commit

Permalink
Steal a bit more structure from NieczaFrontendSTD
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jun 10, 2012
1 parent b08e5f6 commit fcffb6e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -8,7 +8,8 @@ CP=cp

cskernel=Kernel.cs Builtins.cs Cursor.cs JSYNC.cs NieczaCLR.cs Utils.cs \
ObjModel.cs BigInteger.cs Printf.cs CodeGen.cs CClass.cs CompMgr.cs \
GeneratedTrigFunctions.cs Serialize.cs UCD.cs CgOp.cs Op.cs RxOp.cs
GeneratedTrigFunctions.cs Serialize.cs UCD.cs CgOp.cs Op.cs RxOp.cs \
MiniParser.cs

# Tell make to regard the following targets as not being filenames
.PHONY: all aot test spectest clean realclean
Expand Down
90 changes: 89 additions & 1 deletion lib/CompMgr.cs
Expand Up @@ -73,7 +73,15 @@ class CompJob {
unitname = "CORE";
double start = Builtins.usertime() - mgr.discount_time;

var u = run_internal(runit);
RuntimeUnit u;
if (!is_eval)
Compartment.Push();
try {
u = run_internal(runit);
} finally {
if (!is_eval)
Compartment.Pop();
}

double time = Builtins.usertime() - mgr.discount_time - start;

Expand All @@ -90,7 +98,58 @@ class CompJob {
Console.WriteLine("unitname = " + unitname);
Console.WriteLine("filename = " + filename);
Console.WriteLine("source = " + source.Length);

RuntimeUnit ru = new RuntimeUnit(unitname, filename,
(mgr.no_source ? Utils.HashString(source) : source),
is_main, runit);

if (Kernel.containerRootUnit == null) {
// this is a module unit
Kernel.InitCompartment();
Kernel.containerRootUnit = ru;
ru.depended_units.Add(ru);
ru.owner = ru;
ru.globals = Kernel.currentGlobals =
new Dictionary<string,StashEnt>();
} else {
// needs to use the same globals as the other units in
// this serialization unit
ru.globals = Kernel.currentGlobals;
ru.owner = Kernel.containerRootUnit;
ru.owner.subordinates.Add(ru);
}

string lang = mgr.language;
if (unitname == "CORE") {
lang = "NULL";
string altname = Path.Combine(Path.GetDirectoryName(filename),
"Parser.src");
string altsrc = File.ReadAllText(altname);

new MiniParser(altsrc, ru).Parse();
} else if (unitname != "MAIN") { // modules aren't affected by -L
lang = "CORE";
}

CompUtils.rel_pkg(ru, true, null, "GLOBAL");
CompUtils.rel_pkg(ru, true, null, "PROCESS");

// Parser/actions tree runs here
throw new NotImplementedException();

if (runit) {
//if (!is_repl) setnames(execname(), filename);
//run_unit(ru, is_eval, run_args);
if (is_repl) {
// mgr.repl_outer_frame = replrun();
// mgr.repl_outer = ru.mainline;
}
} else {
// save_unit(ru);
// if (is_repl) mgr.repl_outer = ru.mainline;
}

return is_eval ? ru : null;
}

// borrowed from STD, try to allow p5 and p6 to coexist
Expand Down Expand Up @@ -294,5 +353,34 @@ static class CompUtils {
"_inline", lis.def));
}
public static void MarkUsed(Cursor at, string name) { throw new NotImplementedException(); }
public static STable rel_pkg(RuntimeUnit c, bool auto, STable pkg,
params string[] args) {

for (int i = 0; i < args.Length; i++) {
string key = args[i];
string who = "";
if (pkg != null) {
if (!pkg.who.Isa(Kernel.StashMO))
throw new NieczaException(pkg.name + " fails to name a standard package");
who = Kernel.UnboxAny<string>(pkg.who);
}
StashEnt v;
string hkey = (char)who.Length + who + key;
if (c.globals.TryGetValue(hkey, out v)) {
if (v.v.Rw || v.v.Fetch().IsDefined())
throw new NieczaException((who + "::" + key).Substring(2) + " names a non-package");
pkg = v.v.Fetch().mo;
} else if (!auto) {
throw new NieczaException((who + "::" + key).Substring(2) + " does not name any package");
} else {
c.globals[hkey] = v = new StashEnt();
v.constant = true;
v.v = StashCursor.MakePackage((who + "::" + key).Substring(2), Kernel.BoxRaw<string>(who + "::" + key, Kernel.StashMO));
pkg = v.v.Fetch().mo;
}
}
return pkg;
}

}
}
23 changes: 23 additions & 0 deletions lib/MiniParser.cs
@@ -0,0 +1,23 @@
// Yuck. This file is part of the bootstrap mechanism; it is used to parse
// Perl 6 grammars, because Perl 6's own grammar cannot be written using yacc.

using System;
using System.Collections.Generic;

namespace Niecza.Compiler {
class MiniParser {
char[] src;
string src_s;
RuntimeUnit unit;

public MiniParser(string gsrc, RuntimeUnit core) {
this.src_s = gsrc;
this.src = gsrc.ToCharArray();
this.unit = core;
}

public void Parse() {
throw new NotImplementedException();
}
}
}
5 changes: 5 additions & 0 deletions lib/Utils.cs
Expand Up @@ -584,6 +584,11 @@ public class Utils {
return new string(buf);
}

public static string HashString(string inp) {
return HashToStr(ObjectRegistry.NewHash().ComputeHash(
new System.Text.UTF8Encoding().GetBytes(inp)));
}

public static void HexDump(byte[] heap) {
for (int offs = 0; offs < heap.Length; offs += 16) {
Console.Write("{0:X6} ", offs);
Expand Down

0 comments on commit fcffb6e

Please sign in to comment.