Skip to content
Browse files

Remove capability of rebinding lexical constants (fixes #46)

  • Loading branch information...
1 parent eb2bc3c commit ccb1914eb2a684d0f0bb9f72346b3a7645f2ee0d @sorear committed Nov 4, 2011
Showing with 24 additions and 23 deletions.
  1. +4 −4 lib/CodeGen.cs
  2. +19 −18 lib/Kernel.cs
  3. +1 −1 lib/Serialize.cs
View
8 lib/CodeGen.cs
@@ -3734,8 +3734,8 @@ public class DowncallReceiver : CallReceiver {
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;
+ if (li is LIConstant) {
+ ((LIConstant)li).value = v;
} else if (li is LICommon) {
StashEnt hkey = Kernel.currentGlobals[((LICommon)li).hkey];
hkey.constant = true;
@@ -3858,7 +3858,7 @@ public class DowncallReceiver : CallReceiver {
var llab = li as LILabel;
if (llab != null)
r = new object[] { "label",null,null,null };
- var lhint = li as LIHint;
+ var lhint = li as LIConstant;
if (lhint != null)
r = new object[] { "hint",null,null,null };
var lcomm = li as LICommon;
@@ -4186,7 +4186,7 @@ public class DowncallReceiver : CallReceiver {
return AddLexical(args, new LISimple(flags, type));
} else if (cmd == "add_hint") {
- return AddLexical(args, new LIHint());
+ return AddLexical(args, new LIConstant());
} else if (cmd == "add_label") {
return AddLexical(args, new LILabel());
} else if (cmd == "add_dispatcher") {
View
37 lib/Kernel.cs
@@ -1091,7 +1091,7 @@ public abstract class LexInfo {
internal abstract void DoFreeze(FreezeBuffer fb);
internal enum LexSerCode {
- Simple, Sub, Label, Dispatch, Common, Hint, Package, Alias
+ Simple, Sub, Label, Dispatch, Common, Constant, Package, Alias
}
}
@@ -1170,32 +1170,33 @@ public class LICommon : LexInfo {
}
}
- public class LIHint : LexInfo {
- public StashEnt var;
- public LIHint() { }
- public LIHint(StashEnt var) { this.var = var; }
+ public class LIConstant : LexInfo {
+ public Variable value;
+ public LIConstant() { this.value = Kernel.AnyMO.typeVar; }
+ internal LIConstant(Variable value) { this.value = value; }
public override void Init(Frame f) { }
- public override void BindFields() {
- var = new StashEnt();
- }
+ public override void BindFields() { }
- public override object Get(Frame f) { return var.v; }
- public override void Set(Frame f, object to) { var.v = (Variable)to; }
+ public override object Get(Frame f) { return value; }
+ public override void Set(Frame f, object to) {
+ throw new NieczaException("Cannot bind to constant " + name);
+ }
internal override ClrOp GetCode(int up) {
- return new ClrGetField(Tokens.StashEnt_v,
- EmitUnit.Current.RefConstant(name, "E", var, null).head);
+ return EmitUnit.Current.RefConstant(name, "", value, typeof(Variable)).head;
}
// XXX should die() with constant improvements
internal override ClrOp SetCode(int up, ClrOp to) {
- return new ClrSetField(Tokens.StashEnt_v,
- EmitUnit.Current.RefConstant(name, "E", var, null).head, to);
+ return new ClrOperator(Tokens.Void, OpCodes.Throw, new [] {
+ new ClrConstructorCall(typeof(NieczaException).
+ GetConstructor(new [] { typeof(string) }),
+ new [] { new ClrStringLiteral("Cannot bind to constant " + name) }) });
}
internal override void DoFreeze(FreezeBuffer fb) {
- fb.Byte((byte)LexSerCode.Hint);
- fb.ObjRef(var);
+ fb.Byte((byte)LexSerCode.Constant);
+ fb.ObjRef(value);
}
}
@@ -2101,8 +2102,8 @@ public class UsedInScopeInfo {
case (int) LexInfo.LexSerCode.Common:
li = new LICommon(tb.String());
break;
- case (int) LexInfo.LexSerCode.Hint:
- li = new LIHint((StashEnt) tb.ObjRef());
+ case (int) LexInfo.LexSerCode.Constant:
+ li = new LIConstant((Variable) tb.ObjRef());
break;
case (int) LexInfo.LexSerCode.Package:
li = new LIPackage((STable) tb.ObjRef());
View
2 lib/Serialize.cs
@@ -64,7 +64,7 @@ struct ObjRef {
internal static HashAlgorithm NewHash() { return new SHA256Managed(); }
static readonly string signature = "Niecza-Serialized-Module";
- static readonly int version = 5;
+ static readonly int version = 6;
// Routines for use by serialization code
public bool CheckWriteObject(SerUnit into, object o,

0 comments on commit ccb1914

Please sign in to comment.
Something went wrong with that request. Please try again.