Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make my A::B $x work, add lots of debugging code to the blob loader
  • Loading branch information
sorear committed May 27, 2011
1 parent a828415 commit af8a3f2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/CLRBackend.cs
Expand Up @@ -4635,7 +4635,8 @@ public class CLRBackend {
(object[])Reader.Read(contents.Substring(contents.IndexOf('\n'))));
CLRBackend old_Current = Current;
Dictionary<string,Unit> old_used_units = used_units;
CLRBackend c = new CLRBackend(dir, root.name, null);
string op = Environment.GetEnvironmentVariable("NIECZA_FORCE_SAVE") == null ? null : root.name + "-TEMP.dll";
CLRBackend c = new CLRBackend(dir, root.name, op);
Current = c;

used_units = new Dictionary<string, Unit>();
Expand All @@ -4650,6 +4651,8 @@ public class CLRBackend {
root.BindDepends(true);

c.Process(root, true);
if (op != null)
c.Finish(op);

Type t = c.tb.CreateType();
used_units = old_used_units; Current = old_Current;
Expand All @@ -4660,6 +4663,10 @@ public class CLRBackend {
}

public static void Main(string[] args) {
if (args.Length == 3 && args[0] == "-run") {
RunMain(args[1], File.ReadAllText(args[2]), new string[0]);
return;
}
if (args.Length != 4) {
Console.Error.WriteLine("usage : CLRBackend DIR UNITFILE OUTFILE ISMAIN");
return;
Expand Down Expand Up @@ -4695,6 +4702,11 @@ public class CLRBackend {
// instantiatable for the sake of reflecty loading
public class DownCallAcceptor: CrossDomainReceiver {
public override string[] Call(AppDomain up, string[] args) {
if (Environment.GetEnvironmentVariable("NIECZA_TRACE_DOWNCALLS") != null) {
Console.WriteLine(args.Length);
foreach(string a in args)
Console.WriteLine(a);
}
Builtins.up_domain = up;
if (args[0] == "post_save") {
CLRBackend.Main(new string[] { args[1], args[2], args[3], args[4] });
Expand Down
34 changes: 34 additions & 0 deletions lib/Kernel.cs
Expand Up @@ -194,6 +194,7 @@ public sealed class RuntimeUnit {
public DynBlockDelegate[] methods; /*C*/
public FieldInfo[] meta_fields;
public object[] xref;
public static bool TraceLoad = Environment.GetEnvironmentVariable("NIECZA_TRACE_LOAD") != null;

public RuntimeUnit(Type type, byte[] heap, RuntimeUnit[] depends,
int nx) {
Expand All @@ -204,6 +205,29 @@ public sealed class RuntimeUnit {
this.methods = new DynBlockDelegate[nx];
this.meta_fields = new FieldInfo[nx*2];

if (TraceLoad) {
Console.WriteLine("Setting up unit {0}", type.Name);
for (int offs = 0; offs < heap.Length; offs += 16) {
Console.Write("{0:X6} ", offs);
int len = heap.Length - offs;
if (len > 16) len = 16;
for (int col = 0; col < 16; col++) {
if (col >= len)
Console.Write(" ");
else
Console.Write("{0:X2} ", heap[offs+col]);
if (col == 7)
Console.Write(" ");
}
Console.Write(" |");
for (int col = 0; col < len; col++)
Console.Write(
(heap[offs+col] < 32 || heap[offs+col] > 126)
? '.' : (char)heap[offs+col]);
Console.WriteLine("|");
}
}

uint d = 0;
foreach (MethodInfo mi in type.GetMethods()) {
int acc = 0;
Expand Down Expand Up @@ -408,6 +432,7 @@ public sealed class RuntimeUnit {
}

public void LoadSubInfo(int from) {
int _ifrom = from;
int ix = ReadInt(ref from);
byte spec = heap[from++];
SubInfo ns = new SubInfo(
Expand All @@ -422,6 +447,8 @@ public sealed class RuntimeUnit {
ReadStrArray(ref from), /*dylexn*/
ReadIntArray(ref from)); /*dylexi*/

if (TraceLoad)
Console.WriteLine("Installing sub {0} \"{1}\" from {2}", ix, ns.name, _ifrom);
xref[ix] = ns;

if ((spec & SUB_IS_UNSAFE) != 0)
Expand Down Expand Up @@ -449,6 +476,8 @@ public sealed class RuntimeUnit {
STable mo = xref[i] as STable;
if (mo == null) continue;
int from = mo.fixups_from;
if (TraceLoad)
Console.WriteLine("Finishing load of package {0} \"{1}\" from {2}", i, mo.name, from);

int nex = ReadInt(ref from);
for (int j = 0; j < nex; j++)
Expand All @@ -462,6 +491,8 @@ public sealed class RuntimeUnit {
SubInfo si = xref[i] as SubInfo;
if (si == null) continue;
int from = si.fixups_from;
if (TraceLoad)
Console.WriteLine("Finishing load of sub {0} \"{1}\" from {2}", i, si.name, from);
ReadSignature(si, ref from);
int ph = heap[from++];
if (ph != 0xFF) Kernel.AddPhaser(ph, si.protosub);
Expand All @@ -473,8 +504,11 @@ public sealed class RuntimeUnit {
}

public STable LoadPackage(int from, STable existing_mo) {
int _ifrom = from;
int ix = ReadInt(ref from);
string name = ReadStr(ref from);
if (TraceLoad)
Console.WriteLine("Installing package {0} \"{1}\" from {2}", ix, name, _ifrom);
STable mo = existing_mo != null ? existing_mo :
new STable(name);
xref[ix] = mo;
Expand Down
7 changes: 7 additions & 0 deletions src/niecza
Expand Up @@ -28,6 +28,13 @@ use OptRxSimple;
use STD;
use Sig;

augment class NieczaActions {
method simple_longname($/) {
my $r = self.mangle_longname($/);
($r<path>:exists) ?? [ @($r<path>), $r<name> ] !! [ 'MY', $r<name> ];
}
}

augment class Op::ForLoop { #OK exist
method statement_level() {
my $var = [ map { ::GLOBAL::NieczaActions.gensym },
Expand Down
6 changes: 6 additions & 0 deletions test2.pl
Expand Up @@ -19,6 +19,12 @@
is $str, "1|2,3|4,", 'multivariable for works';
}

{
class X7140::X1122 { }
my X7140::X1122 $obj .= new;
isa_ok $obj, X7140::X1122, 'Type constraints via :: work';
}

#is $?FILE, 'test.pl', '$?FILE works';
#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';

Expand Down

0 comments on commit af8a3f2

Please sign in to comment.