Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finish bootstrapping of bootstrap changes

  • Loading branch information...
commit 9c2a362516531c9a0fb5ad4653939b214c8bb2b8 1 parent 19fa03a
Stefan O'Rear authored
2  FETCH_URL
View
@@ -1 +1 @@
-http://cloud.github.com/downloads/sorear/niecza/niecza-22.zip
+http://cloud.github.com/downloads/sorear/niecza/niecza-23.99.zip
52 Makefile
View
@@ -17,49 +17,37 @@ cskernel=Kernel.cs Builtins.cs Cursor.cs JSYNC.cs NieczaCLR.cs Utils.cs \
.PHONY: all aot test spectest clean realclean
.PHONY: help
-libunits=CORE JSYNC
+libunits=CORE
srcunits=CClass CgOp Op OpHelpers Sig RxOp STD NieczaGrammar OptRxSimple \
Operator NieczaActions NieczaFrontendSTD NieczaPassSimplifier \
OptBeta NieczaPathSearch NieczaBackendDotnet NieczaCompiler GetOptLong
-all: run/Niecza.exe run/Run.Kernel.dll obj/CORE.dll
+all: run/Niecza.exe run/Kernel.dll obj/CORE.dll
-$(patsubst %,boot/obj/Run.%.ser,$(srcunits)): boot/obj/Run.%.ser: .fetch-stamp src/%.pm6 boot/obj/Run.CORE.ser
- cd src && NIECZA_KEEP_IL=1 $(RUN_CLR) ../boot/run/Niecza.exe --obj-dir ../boot/obj -C $*
+$(patsubst %,run/%.ser,$(srcunits)): run/%.ser: .fetch-stamp src/%.pm6 run/CORE.ser
+ NIECZA_KEEP_IL=1 $(RUN_CLR) boot/run/Niecza.exe --obj-dir run -I src -C $*
-# hack - put VERSION info in place so the setting build can embed it
-obj/CORE.dll: run/Niecza.exe obj/Run.Kernel.dll lib/CORE.setting
+# hack - put VERSION info in place so the sobj/MAIN.exeetting build can embed it
+obj/CORE.dll: run/Niecza.exe run/Kernel.dll lib/CORE.setting
@git describe --tags > VERSION
$(RUN_CLR) run/Niecza.exe --obj-dir obj -C CORE
-run/Niecza.exe: .fetch-stamp $(patsubst %,boot/obj/Run.%.ser,$(srcunits)) src/niecza
- cd src && NIECZA_KEEP_IL=1 $(RUN_CLR) ../boot/run/Niecza.exe --obj-dir ../boot/obj -c niecza
- $(CP) boot/obj/Kernel.dll run/
- $(CSC) /target:library /out:run/CompilerBlob.dll /r:Kernel \
- /lib:run src/CompilerBlob.cs
- $(RUN_CLR) run/Kernel.dll -gen-app Niecza boot/obj
+run/Niecza.exe: .fetch-stamp $(patsubst %,run/%.ser,$(srcunits)) src/niecza
+ NIECZA_KEEP_IL=1 $(RUN_CLR) boot/run/Niecza.exe --obj-dir run -I src -c src/niecza
+ $(CP) run/MAIN.exe run/Niecza.exe
.fetch-stamp: FETCH_URL
-rm -rf boot/
mkdir boot
$(WGET_O) boot/niecza.zip $$(cat FETCH_URL)
cd boot && unzip niecza.zip
- NIECZA_KEEP_IL=1 $(RUN_CLR) boot/run/Niecza.exe --obj-dir=boot/obj -C $(libunits)
- $(CP) boot/run/Kernel.dll boot/obj/
+ NIECZA_KEEP_IL=1 $(RUN_CLR) boot/run/Niecza.exe --obj-dir=run -C $(libunits)
touch .fetch-stamp
-boot/obj/Run.CORE.ser: .fetch-stamp
+run/CORE.ser: .fetch-stamp
-boot/obj/Run.CompilerBlob.dll: .fetch-stamp src/CompilerBlob.cs
- $(CSC) /target:library /out:boot/obj/Run.CompilerBlob.dll /r:Run.Kernel \
- /lib:boot/obj src/CompilerBlob.cs
-run/Run.Kernel.dll: $(patsubst %,lib/%,$(cskernel)) lib/unidata
- $(CSC) /target:exe /out:run/Run.Kernel.dll /lib:obj /unsafe+ \
+run/Kernel.dll: $(patsubst %,lib/%,$(cskernel)) lib/unidata
+ $(CSC) /target:exe /out:run/Kernel.dll /lib:obj /unsafe+ \
/res:lib/unidata $(patsubst %,lib/%,$(cskernel))
-obj/Kernel.dll: $(patsubst %,lib/%,$(cskernel)) lib/unidata
- $(CSC) /target:exe /out:obj/Kernel.dll /lib:obj /unsafe+ \
- /res:lib/unidata $(patsubst %,lib/%,$(cskernel))
-obj/Run.Kernel.dll: run/Run.Kernel.dll
- $(CP) $< $@
.PHONY: Niecza_pm
perl5: obj/Perl5Interpreter.dll obj/p5embed.so Niecza_pm
@@ -78,6 +66,7 @@ aot: all
test: all
$(RUN_CLR) run/Niecza.exe --obj-dir obj -c test.pl
+ $(CP) run/Kernel.dll obj/
prove -e "$(RUN_CLR)" obj/MAIN.exe
spectest: all
@@ -95,19 +84,18 @@ mkpackage:
rm -rf package/
mkdir package/ package/run/ package/lib/
cp -a docs README.pod LICENSE package/
- cp -a run/Niecza.exe run/Niecza.ser run/Kernel.dll \
- run/CompilerBlob.dll run/Run.Kernel.dll package/run/
+ cp -a run/Kernel.dll package/run
+ $(RUN_CLR) run/Kernel.dll -regenerate run/ package/run/ Niecza
cp lib/*.pm6 lib/*.setting package/lib/
-mknext: run/Niecza.exe obj/Run.Kernel.dll obj/Kernel.dll
+mknext: run/Niecza.exe run/Kernel.dll
rm -rf next/
- mkdir -p next next/boot next/obj next/run next/boot next/boot/obj/
+ mkdir -p next next/boot next/obj next/run next/boot/run next/boot/obj/
touch next/FETCH_URL next/.fetch-stamp
cp -a src lib docs README.pod LICENSE Makefile test.pl next/
cp -a run lib next/boot/
- cp obj/Run.Kernel.dll obj/Kernel.dll next/boot/obj/
ln -s ../t next/t
- NIECZA_KEEP_IL=1 $(RUN_CLR) next/boot/run/Niecza.exe --obj-dir next/boot/obj -C $(libunits)
+ NIECZA_KEEP_IL=1 $(RUN_CLR) next/boot/run/Niecza.exe --obj-dir next/run -C $(libunits)
realclean: clean
@rm .fetch-stamp
@@ -125,8 +113,6 @@ help:
@echo 'help this list of targets'
@echo ''
-boot/obj/Run.NieczaBackendDotnet.ser: boot/obj/Run.CompilerBlob.dll
-
# grep -r '^use' src/*.pm6 | sed 's|src/\(.*\)\.pm6:use \(.*\);|boot/obj/Run.\1.ser: boot/obj/Run.\2.ser|' | grep -v MONKEY_TYPING
boot/obj/Run.NieczaActions.ser: boot/obj/Run.OpHelpers.ser
boot/obj/Run.NieczaFrontendSTD.ser: boot/obj/Run.STD.ser
21 lib/Kernel.cs
View
@@ -6761,18 +6761,18 @@ class LastFrameNode {
}
}
}
- else if (cmd == "-gen-app" && args.Length == 3) {
+ else if (cmd == "-regenerate" && args.Length == 4) {
// Code regeneration: this is required for the bootstrap
// procedure, because initial code generation makes Run.CORE
// and we need to turn it into CORE for the compiler proper.
// this needs to be rethought for the new segregation model
- string exename = args[1];
- string fromdir = args[2];
+ string fromdir = args[1];
+ string todir = args[2];
+ string newname = args[3];
- // allow loading of Run. files, but don't try to load the
- // assemblies, since we're not Run.Kernel
+ // don't try to load the assemblies (we probably can't)
comp.obj_dir = fromdir;
Backend.cross_level_load = true;
@@ -6780,23 +6780,22 @@ class LastFrameNode {
comp.reg.LoadUnit("MAIN").root;
// reset for writing
- comp.obj_dir = AppDomain.CurrentDomain.BaseDirectory;
+ comp.obj_dir = todir;
RewriteUnits(root, root, new HashSet<RuntimeUnit>());
// reset for writability
comp.reg = new ObjectRegistry(comp);
- root.dll_name = exename + ".exe";
- root.asm_name = exename;
- root.name = exename;
+ root.dll_name = newname + ".exe";
+ root.asm_name = newname;
+ root.name = newname;
root.Save();
}
else if (cmd == "-run" && args.Length == 2) {
MainHandler(args[1], new string[0]);
} else {
- Console.WriteLine("usage: Kernel.dll -run Unit.Name");
- Console.WriteLine("usage: Kernel.dll -gen-app App.exe build/dir");
+ Console.WriteLine("usage: Kernel.dll -regenerate fromdir todir App.exe");
Console.WriteLine("usage: Kernel.dll -run Unit.Name");
}
}
274 src/CompilerBlob.cs
View
@@ -1,274 +0,0 @@
-using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-using System.Security.Cryptography;
-using System.IO;
-
-namespace Niecza {
- public abstract class CallReceiver : MarshalByRefObject, IDictionary {
- public bool IsFixedSize { get { return false; } }
- public bool IsReadOnly { get { return false; } }
- public bool IsSynchronized { get { return false; } }
- public int Count { get { return 0; } }
- public object SyncRoot { get { return null; } }
- public ICollection Keys { get { return null; } }
- public ICollection Values { get { return null; } }
- public void Add(object a, object b) { }
- public void Clear() { }
- public IDictionaryEnumerator GetEnumerator() { return null; }
- IEnumerator IEnumerable.GetEnumerator() { return null; }
- public bool Contains(object a) { return false; }
- public void CopyTo(Array a, int offs) { }
- public void Remove(object a) { }
- public abstract object this[object i] { get; set; }
- }
-
- public class UpcallReceiver : CallReceiver {
- public override object this[object i] {
- set { }
- get {
- object[] ia = (object[]) i;
- Variable[] va = new Variable[ia.Length];
- for (int ix = 0; ix < ia.Length; ix++)
- va[ix] = Downcaller.DCResult(ia[ix]);
- try {
- Variable vr = Kernel.RunInferior(
- Downcaller.upcall_cb.Fetch().Invoke(
- Kernel.GetInferiorRoot(), va, null));
- return Downcaller.DCArg(vr);
- } catch (Exception ex) {
- return new Exception(ex.ToString());
- }
- }
- }
- }
-
- public class Downcaller {
- internal static Variable upcall_cb;
- static Variable TrueV, FalseV;
- static IDictionary responder;
- static P6any UnitP, StaticSubP, TypeP, ParamP, ValueP;
- static STable StrMO, NumMO, ListMO, AnyMO, BoolMO;
- static string obj_dir;
-
- // Better, but still fudgy. Relies too much on path structure.
- public static void InitSlave(Variable cb, P6any cmd_obj_dir, Variable unit,
- Variable staticSub, Variable type, Variable param, Variable value,
- Variable str, Variable num, Variable @true, Variable @false,
- Variable list, Variable any, Variable @bool) {
- if (responder != null) return;
-
- UnitP = unit.Fetch();
- StaticSubP = staticSub.Fetch();
- TypeP = type.Fetch();
- ParamP = param.Fetch();
- ValueP = value.Fetch();
- StrMO = str.Fetch().mo;
- NumMO = num.Fetch().mo;
- TrueV = @true;
- FalseV = @false;
- ListMO = list.Fetch().mo;
- AnyMO = any.Fetch().mo;
- BoolMO = @bool.Fetch().mo;
-
- obj_dir = Path.GetFullPath(cmd_obj_dir.IsDefined() ?
- cmd_obj_dir.mo.mro_raw_Str.Get(cmd_obj_dir) :
- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
- "NieczaModuleCache"));
-
- Directory.CreateDirectory(obj_dir); // like mkdir -p
-
- if (!File.Exists(Path.Combine(obj_dir, "Run.Kernel.dll"))) {
- File.Copy(
- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Run.Kernel.dll"),
- Path.Combine(obj_dir, "Run.Kernel.dll")
- );
- }
-
- var down_asm = Assembly.LoadFrom(Path.Combine(obj_dir, "Run.Kernel.dll"));
-
- upcall_cb = cb;
- responder = (IDictionary) down_asm.CreateInstance("Niecza.CLRBackend.DowncallReceiver");
- }
- public static void InitCompartment(Variable c) {
- RawDowncall("set_binding", DCArg(c), obj_dir, new UpcallReceiver());
- }
- public static object RawDowncall(params object[] args) {
- return responder[args];
- }
-
- internal static object DCArg(Variable v) {
- P6any o = v.Fetch();
- if (o is BoxObject<object>)
- return Kernel.UnboxAny<object>(o);
- else if (o.IsDefined()) {
- if (o.Isa(StrMO))
- return (string) o.mo.mro_raw_Str.Get(v);
- else if (o.Isa(BoolMO))
- return (bool) o.mo.mro_raw_Bool.Get(v);
- else if (o.Isa(NumMO)) {
- double d = Kernel.UnboxAny<double>(o);
- if ((d % 1) == 0 && d <= int.MaxValue && d >= int.MinValue)
- return (object)(int)d;
- return (object)d;
- } else if (o.Isa(ListMO)) {
- VarDeque it = o.mo.mro_raw_iterator.Get(v);
- var lo = new List<object>();
- while (Kernel.IterHasFlat(it, true))
- lo.Add(DCArg(it.Shift()));
- return lo.ToArray();
- } else
- return (int) o.mo.mro_raw_Numeric.Get(v);
- } else
- return null;
- }
-
- public static Variable DownCall(Variable list) {
- List<object> lo = new List<object>();
- VarDeque it = Builtins.start_iter(list);
- while (Kernel.IterHasFlat(it, true))
- lo.Add(DCArg(it.Shift()));
-
- return DCResult(RawDowncall(lo.ToArray()));
- }
-
- internal static Variable DCResult(object r) {
- if (r == null) return AnyMO.typeObj;
- else if (r is string) return Kernel.BoxAnyMO((string)r, StrMO);
- else if (r is int) return Builtins.MakeInt((int)r);
- else if (r is bool) return ((bool)r) ? TrueV : FalseV;
- else if (r is Exception) throw new NieczaException(((Exception)r).Message);
- else if (r is object[]) {
- object[] ra = (object[])r;
- Variable[] ba = new Variable[ra.Length];
- for (int i = 0; i < ba.Length; i++) ba[i] = DCResult(ra[i]);
- return Builtins.MakeParcel(ba);
- }
- else {
- string t = (string)RawDowncall("gettype", r);
- P6any pr = (t == "type") ? TypeP :
- (t == "sub") ? StaticSubP :
- (t == "param") ? ParamP :
- (t == "value") ? ValueP :
- (t == "unit") ? UnitP : AnyMO.typeObj;
- return Kernel.BoxAnyMO(r, pr.mo);
- }
- }
-
- static void SerializeNam(Variable v, StringBuilder sb,
- List<object> refs) {
-
- P6any o = v.Fetch();
- if (o is BoxObject<int>) { /* includes bool */
- sb.Append(Kernel.UnboxAny<int>(o));
- } else if (o is BoxObject<double>) {
- sb.Append(Utils.N2S(Kernel.UnboxAny<double>(o)));
- } else if (o is BoxObject<string>) {
- string s = Kernel.UnboxAny<string>(o);
- sb.Append('"');
- foreach (char c in s) {
- if (c >= ' ' && c <= '~' && c != '\\' && c != '"')
- sb.Append(c);
- else {
- sb.Append("\\u");
- sb.AppendFormat("{0:X4}", (int)c);
- }
- }
- sb.Append('"');
- } else if (!o.IsDefined()) {
- sb.Append("null");
- } else if (o.Isa(ListMO)) {
- VarDeque d = o.mo.mro_raw_iterator.Get(v);
- bool comma = false;
- sb.Append('[');
- while (Kernel.IterHasFlat(d, true)) {
- if (comma) sb.Append(',');
- SerializeNam(d.Shift(), sb, refs);
- comma = true;
- }
- sb.Append(']');
- } else if (o is BoxObject<object>) {
- sb.Append('!');
- sb.Append(refs.Count);
- refs.Add(Kernel.UnboxAny<object>(o));
- } else {
- throw new NieczaException("weird object in sub_finish " + o.mo.name);
- }
- }
-
- public static Variable Finish(Variable si, Variable nam) {
- StringBuilder sb = new StringBuilder();
- List<object> refs = new List<object>();
- SerializeNam(nam, sb, refs);
- object[] args = new object[refs.Count + 3];
- args[0] = "sub_finish";
- args[1] = Kernel.UnboxAny<object>(si.Fetch());
- args[2] = sb.ToString();
- refs.CopyTo(args, 3);
- return DCResult(RawDowncall(args));
- }
-
- public static string DoHash(string input) {
- HashAlgorithm sha = SHA256.Create();
- byte[] ibytes = new UTF8Encoding().GetBytes(input);
- byte[] hash = sha.ComputeHash(ibytes);
- char[] buf = new char[hash.Length * 2];
- for (int i = 0; i < hash.Length; i++) {
- buf[i*2] = "0123456789abcdef"[hash[i] >> 4];
- buf[i*2+1] = "0123456789abcdef"[hash[i] & 15];
- }
- return new string(buf);
- }
-
- public static string ExecName() {
- return Assembly.GetEntryAssembly().Location;
- }
-
- static Dictionary<P6any,Dictionary<P6any,Variable>> role_cache =
- new Dictionary<P6any,Dictionary<P6any,Variable>>();
- public static Variable CachedBut(P6any but, Variable v1, Variable v2) {
- P6any a1 = v1.Fetch();
- P6any a2 = v2.Fetch();
- Dictionary<P6any,Variable> subcache;
- if (!role_cache.TryGetValue(a1, out subcache))
- role_cache[a1] = subcache = new Dictionary<P6any,Variable>();
- Variable var;
- if (subcache.TryGetValue(a2, out var))
- return var;
-
- // Mega-Hack - stop lots of internal data from being retained by
- // CALLER pointers
- Kernel.SetTopFrame(null);
-
- var = Kernel.RunInferior(but.Invoke(Kernel.GetInferiorRoot(),
- new [] { v1, v2 }, null));
- return subcache[a2] = var;
- }
-
- public static Variable PruneMatch(Variable vr) {
- Cursor c = (Cursor)vr.Fetch();
- // remove as much as possible - don't call this if you still need
- // the match!
- if (c.feedback != null) {
- c.feedback.CommitRule();
- c.feedback.bt = null;
- c.feedback.st = new State();
- c.feedback.ast = null;
- }
-
- for (CapInfo it = c.captures; it != null; it = it.prev) {
- if (it.cap != null && it.cap.Fetch() is Cursor)
- PruneMatch(it.cap);
- }
-
- c.captures = null;
- c.feedback = null;
- c.ast = null;
- c.xact = null;
- c.nstate = null;
- return vr;
- }
- }
-}
23 src/NieczaBackendDotnet.pm6
View
@@ -2,8 +2,6 @@ our $PassSimplifier;
class NieczaBackendDotnet;
-use JSYNC;
-
has $.safemode = False;
has $.obj_dir;
has $.run_args = [];
@@ -67,34 +65,29 @@ class Value { ... }
method new(*%_) {
my $self = callsame;
- Q:CgOp { (rnull (rawscall Niecza.Downcaller,CompilerBlob.InitSlave {&upcalled} (@ {$self.obj_dir}) {Unit} {StaticSub} {Type} {Param} {Value} {Str} {Num} {True} {False} {List} {Any} {Bool})) };
+ Q:CgOp { (rnull (cb_init_slave {&upcalled} (@ {$self.obj_dir}) {Unit} {StaticSub} {Type} {Param} {Value})) };
downcall("safemode") if $self.safemode;
$self;
}
sub downcall(*@args) {
- Q:CgOp { (rawscall Niecza.Downcaller,CompilerBlob.DownCall {@args}) }
+ Q:CgOp { (cb_downcall {@args}) }
}
method make_role($name, $meth) {
Q:CgOp { (cat_mixin_role (obj_getstr {$name}) (@ {$meth})) }
}
method prune_match($match) {
- Q:CgOp { (rawscall Niecza.Downcaller,CompilerBlob.PruneMatch {$match}) }
+ Q:CgOp { (cb_prune_match {$match}) }
}
method cached_but($cls, $role) {
# TODO: Object hashes!
- Q:CgOp { (rawscall Niecza.Downcaller,CompilerBlob.CachedBut
- (@ {&infix:<but>}) {$cls} {$role}) };
+ Q:CgOp { (cb_cached_but (@ {&infix:<but>}) {$cls} {$role}) };
}
-sub gethash($str) {
- Q:CgOp { (box Str (rawscall Niecza.Downcaller,CompilerBlob.DoHash (obj_getstr {$str}))) }
-}
+sub gethash($str) { Q:CgOp { (box Str (cb_do_hash (obj_getstr {$str}))) } }
method gethash($str) { gethash($str) }
-sub execname() {
- Q:CgOp { (box Str (rawscall Niecza.Downcaller,CompilerBlob.ExecName)) }
-}
+sub execname() { Q:CgOp { (box Str (cb_exec_name)) } }
method accept($unit, :$filename, :$run, :$evalmode, :$repl) {
if $run {
@@ -245,7 +238,7 @@ class StaticSub {
method finish($ops, $done?) {
$ops := $PassSimplifier.invoke_incr(self, $ops) unless $done;
self.set_extend('onlystub', True) if $ops.onlystub;
- Q:CgOp { (rawscall Niecza.Downcaller,CompilerBlob.Finish {self} {$ops.cgop(self)}) }
+ Q:CgOp { (cb_finish {self} {$ops.cgop(self)}) }
}
# helper for compile_get_pkg; handles stuff like SETTING::OUTER::Foo,
@@ -343,7 +336,7 @@ class Unit {
method push_compartment() {
my \c = downcall("push_compartment");
- Q:CgOp { (rnull (rawscall Niecza.Downcaller,CompilerBlob.InitCompartment {c})) };
+ Q:CgOp { (rnull (cb_init_compartment {c})) };
c;
}
method pop_compartment($c) { downcall("pop_compartment", $c) }
2  src/niecza
View
@@ -76,7 +76,7 @@ output options:
--no-include-source # disable source-based introspection, etc
EOM
-my $runobj = Q:CgOp { (box Str (rawcall get_BaseDirectory (rawscall System.AppDomain.get_CurrentDomain))) };
+my $runobj = Q:CgOp { (box Str (cb_get_basedir)) };
my $basedir = $runobj.IO.append("..").realpath;
my @lib = $basedir.append("lib"), ".".IO.realpath;
Please sign in to comment.
Something went wrong with that request. Please try again.