Permalink
Browse files

Decouple constant initialization from the ability to rebind constants

  • Loading branch information...
1 parent 750c097 commit 149198748ff4bb8fcace2db9433e81cb30e3bc8a @sorear committed Nov 5, 2011
Showing with 20 additions and 10 deletions.
  1. +12 −1 lib/CodeGen.cs
  2. +2 −3 lib/Kernel.cs
  3. +6 −6 src/niecza
View
@@ -3729,7 +3729,18 @@ public class DowncallReceiver : CallReceiver {
((SubInfo)Handle.Unbox(args[1])).SetInlined();
return null;
} else if (cmd == "sub_run_BEGIN") {
- ((SubInfo)Handle.Unbox(args[1])).RunBEGIN();
+ SubInfo si = (SubInfo)Handle.Unbox(args[1]);
+ Variable v = si.RunBEGIN();
+ string cn = (string)args[2];
+ while (si != null && !si.dylex.ContainsKey(cn)) si = si.outer;
+ LexInfo li = si == null ? null : si.dylex[cn];
+ if (li is LIHint) {
+ ((LIHint)li).var.v = v;
+ } else if (li is LICommon) {
+ li.Set(null, v);
+ } else {
+ return new Exception("cannot bind constant value");
+ }
return null;
} else if (cmd == "sub_get_unit") {
return new Handle(((SubInfo)Handle.Unbox(args[1])).unit);
View
@@ -1857,10 +1857,9 @@ public class UsedInScopeInfo {
}
}
- internal void RunBEGIN() {
- Kernel.RunInferior(protosub.Invoke(Kernel.GetInferiorRoot(),
+ internal Variable RunBEGIN() {
+ return Kernel.RunInferior(protosub.Invoke(Kernel.GetInferiorRoot(),
Variable.None, null));
- SetInlined();
}
internal bool IsTopicalizer() {
View
@@ -154,15 +154,15 @@ method statement_prefix:BEGIN ($/) {
}
$*CURLEX<!sub>.create_static_pad;
- $<blast>.ast.run_BEGIN;
- make ::Op::StatementList.new;
+ my $con = self.make_constant($/, 'anon', 'BEGIN');
+ $<blast>.ast.run_BEGIN($con.name);
+ $con.init = True;
+ make $con;
}
method init_constant($con, $rhs) {
- my $body = self.thunk_sub(
- ::Op::LexicalBind.new(name => $con.name, :$rhs),
- name => "$con.name() init");
+ my $body = self.thunk_sub($rhs, name => "$con.name() init");
$body.outer.create_static_pad;
- $body.run_BEGIN;
+ $body.run_BEGIN($con.name);
$con.init = True;
$con;
}

0 comments on commit 1491987

Please sign in to comment.