Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement %*ENV, $*PROGRAM_NAME

  • Loading branch information...
commit ecfc817031de15773ad97b4434ff3b2604726bf7 1 parent 4024e22
@sorear authored
View
29 lib/Builtins.cs
@@ -1766,4 +1766,33 @@ class CrossSource: ItemSource {
public static bool obj_can(P6any obj, string mname) {
return obj.mo.mro_methods.ContainsKey(mname);
}
+
+ // Used mostly to initialize $*PID et al
+ public static string programName;
+ public static string execName;
+
+ public static Variable getenv(string str) {
+ return Kernel.BoxAnyMO(Environment.GetEnvironmentVariable(str), Kernel.StrMO);
+ }
+
+ public static void setenv(string key, string val) {
+ Environment.SetEnvironmentVariable(key, val);
+ }
+
+ public static Variable sysquery(int ix) {
+ switch (ix) {
+ case 0: return BoxLoS(Kernel.commandArgs);
+ case 1: return Kernel.BoxAnyMO(programName ?? AppDomain.CurrentDomain.FriendlyName, Kernel.StrMO);
+ case 2: return Kernel.BoxAnyMO(execName, Kernel.StrMO);
+ case 3: return Kernel.BoxAnyMO(AppDomain.CurrentDomain.BaseDirectory, Kernel.StrMO);
+ case 4: {
+ VarHash ret = new VarHash();
+ foreach (System.Collections.DictionaryEntry de in Environment.GetEnvironmentVariables()) {
+ ret[(string) de.Key] = Kernel.BoxAnyMO((string)de.Value, Kernel.StrMO);
+ }
+ return Kernel.BoxAnyMO(ret, Kernel.HashMO);
+ }
+ default: return null;
+ }
+ }
}
View
5 lib/CLRBackend.cs
@@ -3803,7 +3803,6 @@ class NamProcessor {
thandlers["exit"] = Methody(null, Tokens.Environment_Exit);
thandlers["slurp"] = Methody(null, typeof(File).GetMethod("ReadAllText", new Type[] { Tokens.String }));
thandlers["spew"] = Methody(null, typeof(File).GetMethod("WriteAllText", new Type[] { Tokens.String, Tokens.String }));
- thandlers["getargv"] = Methody(null, Tokens.Kernel.GetMethod("ArgsHelper"));
thandlers["vvarlist_to_fvarlist"] = Methody(null, Tokens.VVarList.GetMethod("CopyAsArray"));
thandlers["vvarlist_shift"] = Methody(null, Tokens.VVarList.GetMethod("Shift"));
thandlers["vvarlist_pop"] = Methody(null, Tokens.VVarList.GetMethod("Pop"));
@@ -4775,6 +4774,10 @@ public class DownCallAcceptor: CrossDomainReceiver {
CLRBackend.RunMain(args[1], args[2],
args[0] == "evalnam" ? null : argv);
return new string[0];
+ } else if (args[0] == "setnames") {
+ Builtins.execName = args[1];
+ Builtins.programName = args[2];
+ return new string[0];
} else if (args[0] == "replrun") {
string ret = "";
try {
View
14 lib/CORE.setting
@@ -1778,10 +1778,16 @@ sub lines($filehandle = $*IN) { $filehandle.lines }
sub prompt($msg) { print $msg; $*IN.get }
sub getc($handle) { $handle.getc }
-$PROCESS::IN ::= Q:CgOp { (box TextReader (treader_stdin)) };
-$PROCESS::OUT ::= TextWriter.new;
-$PROCESS::ARGFILES ::= IO::ArgFiles.new;
-@PROCESS::ARGS = unitem(Q:CgOp { (box Parcel (getargv)) });
+INIT {
+ $PROCESS::IN ::= Q:CgOp { (box TextReader (treader_stdin)) };
+ $PROCESS::OUT ::= TextWriter.new;
+ $PROCESS::ARGFILES ::= IO::ArgFiles.new;
+ @PROCESS::ARGS ::= Q:CgOp { (sysquery (i 0)) };
+ %PROCESS::ENV ::= Q:CgOp { (sysquery (i 4)) };
+ $PROCESS::EXECUTABLE_NAME ::= Q:CgOp { (sysquery (i 2)) };
+ $PROCESS::PROGRAM_NAME ::= Q:CgOp { (sysquery (i 1)) };
+ $PROCESS::BASE_DIRECTORY ::= Q:CgOp { (sysquery (i 3)) };
+}
# }}}
# This needs to be at the end because it screws up the parsing of everything
View
2  src/NieczaBackendDotnet.pm6
@@ -30,6 +30,8 @@ method accept($unitname, $ast is rw, :$main, :$run, :$evalmode, :$repl) {
downcall("safemode") if $.safemode;
$*repl_outer = $ast.mainline.xref if $repl;
if $run {
+ downcall("setnames", $*PROGRAM_NAME // '???',
+ $*orig_file // '(eval)') unless $repl;
my $nam = NAMOutput.run($ast);
$ast.clear_optrees;
$ast = Any;
View
1  src/NieczaCompiler.pm6
@@ -61,6 +61,7 @@ method !main_name() {
}
method compile_file($file, $run, $stop = "") {
+ my $*orig_file = $file; # XXX
my ($filename, $modtime, $source) = $.module_finder.load_file($file);
self!compile(self!main_name, $filename, $modtime, $source, True, $run, $stop, False, Any, False);
}
View
98 src/niecza
@@ -144,6 +144,104 @@ method make_constant($/, $scope, $name) {
::Op::ConstantDecl.new(|node($/), name => $slot, init => False);
}
+method process_block_traits($/, @tr) {
+ my $sub = $*CURLEX<!sub>;
+ my $pack = $sub.body_of;
+ for @tr -> $T {
+ my $tr = $T.ast;
+ if $pack && ($tr<name>:exists) {
+ my ($name, $path) = $tr<name path>;
+
+ $T.CURSOR.sorry("superclass $name declared outside of any class"),
+ next unless $sub.body_of;
+ $T.CURSOR.sorry("superclass $name declared in an augment"),
+ next if $sub.augmenting;
+ $T.CURSOR.sorry("cannot declare a superclass in this kind of package"),
+ next if !$*unit.deref($pack).^can('add_super');
+
+ $T.CURSOR.trymop({
+ $*unit.deref($pack).add_super($sub.compile_get_pkg(
+ @($path // []), $name).xref);
+ });
+ } elsif $pack && $tr<export> {
+ my @exports = @( $tr<export> );
+ $sub.outer.add_exports($*unit.deref($pack).name, $pack, @exports);
+ } elsif !$pack && $tr<export> {
+ my @exports = @( $tr<export> );
+ $sub.outer.add_exports('&'~$sub.name, $sub.xref, @exports);
+ $sub.strong_used = True;
+ $sub.outer.create_static_pad;
+ $sub.outer.lexicals-used{$sub.outervar} = True
+ if defined $sub.outervar;
+ } elsif !$pack && $tr<nobinder> {
+ $sub.signature = Any;
+ } elsif !$pack && grep { defined $tr{$_} }, <looser tighter equiv> {
+ my $rel = $tr.keys.[0];
+ my $to = $tr.values.[0];
+ $to = $to.inside if $to ~~ ::Op::Paren;
+ $to = $to.children[0] if $to ~~ ::Op::StatementList && $to.children == 1;
+
+ my $oprec;
+ if $to ~~ ::Op::Lexical {
+ $oprec = $T.CURSOR.function_O($to.name);
+ } elsif $to ~~ ::Op::StringLiteral && $sub.name ~~ /^(\w+)\:\<.*\>$/ {
+ $oprec = $T.CURSOR.cat_O(~$0, $to.text);
+ } else {
+ $T.CURSOR.sorry("Cannot interpret operator reference");
+ next;
+ }
+ unless $sub.extend<prec> {
+ $T.CURSOR.sorry("Target does not seem to be an operator");
+ next;
+ }
+ unless $oprec {
+ $T.CURSOR.sorry("No precedence available for reference target");
+ next;
+ }
+ if $rel eq 'equiv' {
+ my %copy = %$oprec;
+ $sub.extend.<prec> = %copy;
+ } else {
+ $sub.extend.<prec><prec> = $oprec.<prec>;
+ }
+ $sub.extend.<prec><prec> ~~ s/\=/<=/ if $rel eq 'looser';
+ $sub.extend.<prec><prec> ~~ s/\=/>=/ if $rel eq 'tighter';
+ } elsif !$pack && $tr<assoc> {
+ my $arg = ~self.trivial_eval($T, $tr<assoc>);
+ unless $sub.extend<prec> {
+ $T.CURSOR.sorry("Target does not seem to be an operator");
+ next;
+ }
+ my @valid = < left right non list unary chain >;
+ unless grep $arg, @valid {
+ $T.CURSOR.sorry("Invalid associativity $arg");
+ next;
+ }
+ $sub.extend.<prec><assoc> = $arg;
+ } elsif !$pack && $tr<Niecza::absprec> {
+ my $arg = ~self.trivial_eval($T, $tr<Niecza::absprec>);
+ unless $sub.extend.<prec> {
+ $T.CURSOR.sorry("Target does not seem to be an operator");
+ next;
+ }
+ $sub.extend.<prec><prec> = $arg;
+ $sub.extend.<prec><dba> = "like $sub.name()";
+ } elsif !$pack && $tr<Niecza::builtin> {
+ $sub.extend.<builtin> = [
+ self.trivial_eval($T, $tr<Niecza::builtin>) ];
+ } elsif !$pack && $tr<return_pass> {
+ $sub.returnable = False;
+ } elsif !$pack && $tr<of> {
+ } elsif !$pack && $tr<rw> {
+ } elsif !$pack && $tr<unsafe> {
+ $sub.unsafe = True;
+ } else {
+ $T.CURSOR.sorry("Unhandled trait $tr.keys[0] for this context");
+ }
+ }
+}
+
+
method quantified_atom($/) { # :: RxOp
my $atom = $<atom>.ast;
my $q = $<quantifier> ?? $<quantifier>.ast !! Any;
View
1  t/spectest.data
@@ -93,6 +93,7 @@ S06-signature/positional-placeholders.t
S06-signature/positional.t
S06-signature/slurpy-and-interpolation.t
S06-traits/is-rw.t
+S06-traits/precedence.t
S06-traits/slurpy-is-rw.t
S09-autovivification/autoincrement.t
S12-class/declaration-order.t
Please sign in to comment.
Something went wrong with that request. Please try again.