Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor interpreter for IKC to match the behavior and structure of IKJ.

  • Loading branch information...
commit 86178cf01049beed38e37f558ece5824e73817f7 1 parent 01810fa
@olabini authored
Showing with 1,671 additions and 1,467 deletions.
  1. +1 −3 src/builtin/iik.ik
  2. +25 −3 src/ikc/main/Ioke.Lang/AliasMethod.cs
  3. +71 −71 src/ikc/main/Ioke.Lang/AssignmentBehavior.cs
  4. +56 −33 src/ikc/main/Ioke.Lang/Base.cs
  5. +208 −0 src/ikc/main/Ioke.Lang/Body.cs
  6. +7 −7 src/ikc/main/Ioke.Lang/Call.cs
  7. +7 −7 src/ikc/main/Ioke.Lang/CaseBehavior.cs
  8. +23 −23 src/ikc/main/Ioke.Lang/ConditionsBehavior.cs
  9. +8 −7 src/ikc/main/Ioke.Lang/DefaultArgumentsDefinition.cs
  10. +13 −13 src/ikc/main/Ioke.Lang/DefaultBehavior.cs
  11. +15 −52 src/ikc/main/Ioke.Lang/DefaultMacro.cs
  12. +40 −95 src/ikc/main/Ioke.Lang/DefaultMethod.cs
  13. +15 −17 src/ikc/main/Ioke.Lang/DefaultSyntax.cs
  14. +2 −2 src/ikc/main/Ioke.Lang/DefinitionsBehavior.cs
  15. +7 −7 src/ikc/main/Ioke.Lang/Dict.cs
  16. +4 −4 src/ikc/main/Ioke.Lang/Extensions/Benchmark/Benchmark.cs
  17. +2 −2 src/ikc/main/Ioke.Lang/FileSystem.cs
  18. +29 −28 src/ikc/main/Ioke.Lang/FlowControlBehavior.cs
  19. +20 −20 src/ikc/main/Ioke.Lang/Hook.cs
  20. +8 −7 src/ikc/main/Ioke.Lang/InternalBehavior.cs
  21. +293 −0 src/ikc/main/Ioke.Lang/Interpreter.cs
  22. +36 −39 src/ikc/main/Ioke.Lang/IokeData.cs
  23. +2 −2 src/ikc/main/Ioke.Lang/IokeIO.cs
  24. +14 −14 src/ikc/main/Ioke.Lang/IokeList.cs
  25. +507 −345 src/ikc/main/Ioke.Lang/IokeObject.cs
  26. +7 −7 src/ikc/main/Ioke.Lang/IokeSet.cs
  27. +3 −3 src/ikc/main/Ioke.Lang/IokeSystem.cs
  28. +17 −24 src/ikc/main/Ioke.Lang/LexicalBlock.cs
  29. +5 −56 src/ikc/main/Ioke.Lang/LexicalContext.cs
  30. +22 −44 src/ikc/main/Ioke.Lang/LexicalMacro.cs
  31. +4 −4 src/ikc/main/Ioke.Lang/LiteralsBehavior.cs
  32. +31 −31 src/ikc/main/Ioke.Lang/Locals.cs
  33. +17 −233 src/ikc/main/Ioke.Lang/Message.cs
  34. +21 −21 src/ikc/main/Ioke.Lang/Method.cs
  35. +8 −8 src/ikc/main/Ioke.Lang/Mixins.cs
  36. +7 −2 src/ikc/main/Ioke.Lang/NativeMethod.cs
  37. +0 −15 src/ikc/main/Ioke.Lang/NullObject.cs
  38. +8 −10 src/ikc/main/Ioke.Lang/Number.cs
  39. +2 −2 src/ikc/main/Ioke.Lang/Origin.cs
  40. +2 −2 src/ikc/main/Ioke.Lang/Pair.cs
  41. +2 −2 src/ikc/main/Ioke.Lang/Parser/Operators.cs
  42. +31 −31 src/ikc/main/Ioke.Lang/Range.cs
  43. +6 −6 src/ikc/main/Ioke.Lang/ReflectionBehavior.cs
  44. +13 −13 src/ikc/main/Ioke.Lang/Reflector.cs
  45. +5 −5 src/ikc/main/Ioke.Lang/Regexp.cs
  46. +4 −4 src/ikc/main/Ioke.Lang/RegexpMatch.cs
  47. +31 −18 src/ikc/main/Ioke.Lang/Runtime.cs
  48. +1 −1  src/ikc/main/Ioke.Lang/SpaceshipComparator.cs
  49. +5 −21 src/ikc/main/Ioke.Lang/Text.cs
  50. +2 −2 src/ikj/main/ioke/lang/AssignmentBehavior.java
  51. +4 −1 src/ikj/main/ioke/lang/Interpreter.java
  52. +0 −50 test/base_spec.ik
  53. +0 −50 test/reflector_spec.ik
View
4 src/builtin/iik.ik
@@ -1,5 +1,4 @@
-
IIk = Origin mimic do(
Exit = Condition mimic
@@ -93,7 +92,7 @@ IIk = Origin mimic do(
nestStack length + currentState open
)
)
-
+
nested? = method(data,
Nesting with(data: data) anyOpen?
)
@@ -105,7 +104,6 @@ IIk = Origin mimic do(
mainLoop = method(
"Runs the main loop of IIk, continously reading input from 'System in' until the interpreter is quitted in some of the standard ways",
-
io = if(IIk cell?(:ReadlineInputMethod),
ReadlineInputMethod new,
StdioInputMethod new)
View
28 src/ikc/main/Ioke.Lang/AliasMethod.cs
@@ -4,7 +4,7 @@ public class AliasMethod : IokeData, Named, Inspectable, AssociatedCode {
IokeData realMethod;
IokeObject realSelf;
- public AliasMethod(string name, IokeData realMethod, IokeObject realSelf) {
+ public AliasMethod(string name, IokeData realMethod, IokeObject realSelf) : base(IokeData.TYPE_ALIAS_METHOD) {
this.name = name;
this.realMethod = realMethod;
this.realSelf = realSelf;
@@ -55,8 +55,30 @@ public class AliasMethod : IokeData, Named, Inspectable, AssociatedCode {
return "";
}
- public override object Activate(IokeObject self, IokeObject context, IokeObject message, object on) {
- return realMethod.Activate(realSelf, context, message, on);
+ public new static object ActivateFixed(IokeObject self, IokeObject ctx, IokeObject message, object obj) {
+ AliasMethod am = (AliasMethod)self.data;
+ IokeObject realSelf = am.realSelf;
+ switch(am.realMethod.type) {
+ case IokeData.TYPE_DEFAULT_METHOD:
+ return DefaultMethod.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_DEFAULT_MACRO:
+ return DefaultMacro.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_DEFAULT_SYNTAX:
+ return DefaultSyntax.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_LEXICAL_MACRO:
+ return LexicalMacro.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_NATIVE_METHOD:
+ return NativeMethod.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_METHOD_PROTOTYPE:
+ return Method.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_LEXICAL_BLOCK:
+ return LexicalBlock.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_ALIAS_METHOD:
+ return AliasMethod.ActivateFixed(realSelf, ctx, message, obj);
+ case IokeData.TYPE_NONE:
+ default:
+ return IokeData.ActivateFixed(realSelf, ctx, message, obj);
+ }
}
}
}
View
142 src/ikc/main/Ioke.Lang/AssignmentBehavior.cs
@@ -13,9 +13,9 @@ public class AssignmentBehavior {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
IokeObject nameMessage = (IokeObject)(Message.GetArguments(message)[0]);
string name = nameMessage.Name;
- object current = IokeObject.As(on, context).Perform(context, message, name);
- object value = ((Message)IokeObject.dataOf(runtime.succMessage)).SendTo(runtime.succMessage, context, current);
- return ((Message)IokeObject.dataOf(runtime.setValueMessage)).SendTo(runtime.setValueMessage, context, on, nameMessage, value);
+ object current = Interpreter.Perform(on, IokeObject.As(on, context), context, message, name);
+ object value = Interpreter.Send(runtime.succMessage, context, current);
+ return Interpreter.Send(runtime.setValueMessage, context, on, nameMessage, value);
})));
obj.RegisterMethod(runtime.NewNativeMethod("expects one argument, which is the unevaluated name of the cell to work on. will retrieve the current value of this cell, call 'pred' to that value and then send = to the current receiver with the name and the resulting value.",
@@ -26,9 +26,9 @@ public class AssignmentBehavior {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
IokeObject nameMessage = (IokeObject)(Message.GetArguments(message)[0]);
string name = nameMessage.Name;
- object current = IokeObject.As(on, context).Perform(context, message, name);
- object value = ((Message)IokeObject.dataOf(runtime.predMessage)).SendTo(runtime.predMessage, context, current);
- return ((Message)IokeObject.dataOf(runtime.setValueMessage)).SendTo(runtime.setValueMessage, context, on, nameMessage, value);
+ object current = Interpreter.Perform(on, IokeObject.As(on, context), context, message, name);
+ object value = Interpreter.Send(runtime.predMessage, context, current);
+ return Interpreter.Send(runtime.setValueMessage, context, on, nameMessage, value);
})));
obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. if that cell doesn't exist or the value it contains is not true, that cell will be set to the second argument, otherwise nothing will happen. the second argument will NOT be evaluated if the place is not assigned. the result of the expression is the value of the cell. it will use = for this assignment. this method also work together with forms such as []=.",
@@ -43,16 +43,16 @@ public class AssignmentBehavior {
string name = m1.Name;
if(m1.Arguments.Count == 0) {
- object val = IokeObject.FindCell(on, message, context, name);
+ object val = IokeObject.FindCell(((IokeObject)on), name);
if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
} else {
return val;
}
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
+ object val = Interpreter.Send(m1, context, on);
if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
} else {
return val;
}
@@ -71,18 +71,18 @@ public class AssignmentBehavior {
string name = m1.Name;
if(m1.Arguments.Count == 0) {
- object val = IokeObject.FindCell(on, message, context, name);
+ object val = IokeObject.FindCell(((IokeObject)on), name);
if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
- return val;
+ return context.runtime.nil;
} else {
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
}
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
+ object val = Interpreter.Send(m1, context, on);
if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
- return val;
+ return context.runtime.nil;
} else {
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
}
}
})));
@@ -100,12 +100,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.plusMessage)).SendTo(context.runtime.plusMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.plusMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.plusMessage)).SendTo(context.runtime.plusMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.plusMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -122,12 +122,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.minusMessage)).SendTo(context.runtime.minusMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.minusMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.minusMessage)).SendTo(context.runtime.minusMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.minusMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -144,12 +144,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.multMessage)).SendTo(context.runtime.multMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.multMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.multMessage)).SendTo(context.runtime.multMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.multMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -166,12 +166,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.divMessage)).SendTo(context.runtime.divMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.divMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.divMessage)).SendTo(context.runtime.divMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.divMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -188,12 +188,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.modMessage)).SendTo(context.runtime.modMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.modMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.modMessage)).SendTo(context.runtime.modMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.modMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -210,12 +210,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.expMessage)).SendTo(context.runtime.expMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.expMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.expMessage)).SendTo(context.runtime.expMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.expMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -232,12 +232,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.binAndMessage)).SendTo(context.runtime.binAndMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.binAndMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.binAndMessage)).SendTo(context.runtime.binAndMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.binAndMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -254,12 +254,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.binOrMessage)).SendTo(context.runtime.binOrMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.binOrMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.binOrMessage)).SendTo(context.runtime.binOrMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.binOrMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -276,12 +276,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.binXorMessage)).SendTo(context.runtime.binXorMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.binXorMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.binXorMessage)).SendTo(context.runtime.binXorMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.binXorMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -298,12 +298,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.lshMessage)).SendTo(context.runtime.lshMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.lshMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.lshMessage)).SendTo(context.runtime.lshMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.lshMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
@@ -320,12 +320,12 @@ public class AssignmentBehavior {
if(m1.Arguments.Count == 0) {
object val = IokeObject.GetCell(on, message, context, name);
- object result = ((Message)IokeObject.dataOf(context.runtime.rshMessage)).SendTo(context.runtime.rshMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object result = Interpreter.Send(context.runtime.rshMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
} else {
- object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
- object result = ((Message)IokeObject.dataOf(context.runtime.rshMessage)).SendTo(context.runtime.rshMessage, context, val, Message.GetArguments(message)[1]);
- return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
+ object val = Interpreter.Send(m1, context, on);
+ object result = Interpreter.Send(context.runtime.rshMessage, context, val, Message.GetArguments(message)[1]);
+ return Interpreter.Send(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
}
})));
}
View
89 src/ikc/main/Ioke.Lang/Base.cs
@@ -23,12 +23,12 @@ public class Base {
if(cutoff != current) {
foreach(IokeObject o in current.GetMimics()) toVisit.Add(o);
}
-
- var mso = current.Cells;
-
- foreach(string s in mso.Keys) {
+
+ Cell c = current.body.firstAdded;
+ while(c != null) {
+ string s = c.name;
if(!undefined.Contains(s)) {
- if(mso[s] == runtime.nul) {
+ if(c.value == runtime.nul) {
undefined.Add(s);
} else {
object x = runtime.GetSymbol(s);
@@ -38,22 +38,25 @@ public class Base {
}
}
}
+
+ c = c.orderedNext;
}
}
}
return runtime.NewList(names);
} else {
- var mso = IokeObject.As(on, context).Cells;
var names = new SaneArrayList();
Runtime runtime = context.runtime;
- foreach(string s in mso.Keys) {
- if(mso[s] != runtime.nul) {
+ Cell c = IokeObject.As(on, context).body.firstAdded;
+ while(c != null) {
+ string s = c.name;
+ if(c.value != runtime.nul) {
names.Add(runtime.GetSymbol(s));
}
+ c = c.orderedNext;
}
-
return runtime.NewList(names);
}
}
@@ -74,11 +77,12 @@ public class Base {
if(!visited.Contains(current)) {
visited[current] = null;
foreach(IokeObject o in current.GetMimics()) toVisit.Add(o);
- var mso = current.Cells;
- foreach(string s in mso.Keys) {
+ Cell c = current.body.firstAdded;
+ while(c != null) {
+ string s = c.name;
if(!undefined.Contains(s)) {
- object val = mso[s];
+ object val = c.value;
if(val == runtime.nul) {
undefined.Add(s);
} else {
@@ -88,24 +92,25 @@ public class Base {
}
}
}
+ c = c.orderedNext;
}
}
}
} else {
- var mso = IokeObject.As(on, context).Cells;
-
- foreach(string s in mso.Keys) {
- object val = mso[s];
- if(val != runtime.nul) {
- cells[runtime.GetSymbol(s)] = val;
+ Cell c = IokeObject.As(on, context).body.firstAdded;
+ while(c != null) {
+ string s = c.name;
+ if(c.value != runtime.nul) {
+ cells[runtime.GetSymbol(s)] = c.value;
}
+ c = c.orderedNext;
}
}
return runtime.NewDict(cells);
}
public static object AssignCell(IokeObject context, IokeObject message, object on, object first, object val) {
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, first));
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, first));
if(val is IokeObject) {
if((IokeObject.dataOf(val) is Named) && ((Named)IokeObject.dataOf(val)).Name == null) {
@@ -141,7 +146,7 @@ public class Base {
}
private static object RecursiveDestructuring(IList places, int numPlaces, IokeObject message, IokeObject context, object on, object toTuple) {
- object tupledValue = ((Message)IokeObject.dataOf(context.runtime.asTuple)).SendTo(context.runtime.asTuple, context, toTuple);
+ object tupledValue = Interpreter.Send(context.runtime.asTuple, context, toTuple);
object[] values = Tuple.GetElements(tupledValue);
int numValues = values.Length;
@@ -181,7 +186,7 @@ public class Base {
IList arguments = new SaneArrayList(m1.Arguments);
arguments.Add(context.runtime.CreateMessage(Message.Wrap(IokeObject.As(values[i], context))));
IokeObject msg = context.runtime.NewMessageFrom(message, newName, arguments);
- ((Message)IokeObject.dataOf(msg)).SendTo(msg, context, on);
+ Interpreter.Send(msg, context, on);
}
}
}
@@ -214,12 +219,13 @@ public class Base {
.Arguments,
(method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
+
var args = message.Arguments;
if(args.Count == 2) {
IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
string name = m1.Name;
if(m1.Arguments.Count == 0) {
- object value = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 1, context);
+ object value = Interpreter.GetEvaluatedArgument(message, 1, context);
IokeObject.Assign(on, name, value, context, message);
if(value is IokeObject) {
@@ -240,13 +246,13 @@ public class Base {
IList arguments = new SaneArrayList(m1.Arguments);
arguments.Add(Message.GetArguments(message)[1]);
IokeObject msg = context.runtime.NewMessageFrom(message, newName, arguments);
- return ((Message)IokeObject.dataOf(msg)).SendTo(msg, context, on);
+ return Interpreter.Send(msg, context, on);
}
} else {
int lastIndex = args.Count - 1;
int numPlaces = lastIndex;
- return RecursiveDestructuring(args, numPlaces, message, context, on, Message.GetEvaluatedArgument(args[lastIndex], context));
+ return RecursiveDestructuring(args, numPlaces, message, context, on, Interpreter.GetEvaluatedArgument(args[lastIndex], context));
}
})));
@@ -275,14 +281,14 @@ public class Base {
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, args[0]));
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
return IokeObject.GetCell(on, message, context, name);
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns a hash for the object",
new NativeMethod.WithNoArguments("hash", (method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
- return context.runtime.NewNumber(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(IokeObject.As(on, context).Cells));
+ return context.runtime.NewNumber(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(IokeObject.As(on, context).body));
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns true if the left hand side is equal to the right hand side. exactly what this means depend on the object. the default behavior of Ioke objects is to only be equal if they are the same instance.",
@@ -292,7 +298,7 @@ public class Base {
(method, context, message, on, outer) => {
IList args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- return (IokeObject.As(on, context).Cells == IokeObject.As(args[0], context).Cells) ? context.runtime.True : context.runtime.False;
+ return (IokeObject.As(on, context).body == IokeObject.As(args[0], context).body) ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("expects one evaluated text or symbol argument and returns a boolean indicating whether such a cell is reachable from this point.",
new NativeMethod("cell?", DefaultArgumentsDefinition.builder()
@@ -302,8 +308,8 @@ public class Base {
IList args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, args[0]));
- return IokeObject.FindCell(on, message, context, name) != context.runtime.nul ? context.runtime.True : context.runtime.False;
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
+ return IokeObject.FindCell((IokeObject)on, name) != context.runtime.nul ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the documentation text of the object called on. anything can have a documentation text - this text will initially be nil.",
@@ -313,6 +319,23 @@ public class Base {
return Documentation(context, message, on);
})));
+ obj.RegisterMethod(obj.runtime.NewNativeMethod("returns a boolean indicating of this object should be activated or not.",
+ new NativeMethod.WithNoArguments("activatable",
+ (method, context, message, on, outer) => {
+ outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, new SaneArrayList(), new SaneDictionary<string, object>());
+ return IokeObject.As(on, context).IsActivatable ? context.runtime.True : context.runtime.False;
+ })));
+
+ obj.RegisterMethod(obj.runtime.NewNativeMethod("sets the activatable flag for a specific object. this will not impact objects that mimic this object..",
+ new TypeCheckingNativeMethod("activatable=", TypeCheckingArgumentsDefinition.builder()
+ .WithRequiredPositional("activatableFlag")
+ .Arguments,
+ (method, on, args, keywords, context, message) => {
+ IokeObject.As(on, context).SetActivatable(IokeObject.IsObjectTrue(args[0]));
+ return args[0];
+ }
+ )));
+
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns this object",
new NativeMethod.WithNoArguments("identity",
(method, context, message, on, outer) => {
@@ -335,7 +358,7 @@ public class Base {
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, args[0]));
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
return (IokeObject.FindPlace(on, message, context, name) == on) ? context.runtime.True : context.runtime.False;
})));
@@ -346,7 +369,7 @@ public class Base {
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, args[0]));
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
object result = IokeObject.FindPlace(on, message, context, name);
if(result == context.runtime.nul) {
return context.runtime.nil;
@@ -361,7 +384,7 @@ public class Base {
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, args[0]));
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
IokeObject.RemoveCell(on, message, context, name);
return on;
})));
@@ -373,7 +396,7 @@ public class Base {
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string name = Text.GetText(((Message)IokeObject.dataOf(context.runtime.asText)).SendTo(context.runtime.asText, context, args[0]));
+ string name = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
IokeObject.UndefineCell(on, message, context, name);
return on;
})));
View
208 src/ikc/main/Ioke.Lang/Body.cs
@@ -0,0 +1,208 @@
+
+namespace Ioke.Lang {
+ using System.Collections;
+ using System.Collections.Generic;
+
+ using Ioke.Lang.Util;
+
+ public class Cell {
+ internal string name;
+ internal int hash;
+ public object value;
+ internal Cell next; // next in hash table bucket
+ internal Cell orderedNext; // next in linked list
+
+ internal Cell(string name, int hash) {
+ this.name = name;
+ this.hash = hash;
+ }
+ }
+
+ public class Body {
+ internal string documentation;
+
+ internal IokeObject mimic = null;
+ internal IokeObject[] mimics = null;
+ internal int mimicCount = 0;
+
+ internal List<IokeObject> hooks = null;
+ // zeroed by jvm
+ internal int flags;
+
+ public void Put(string name, object value) {
+ Cell cell = GetCell(name, false);
+ cell.value = value;
+ }
+
+ public bool Has(string name) {
+ return null != GetCell(name, true);
+ }
+
+ public object Get(string name) {
+ Cell cell = GetCell(name, true);
+ if(cell == null) {
+ return cell;
+ }
+ return cell.value;
+ }
+
+ public object Remove(string name) {
+ int hash = name.GetHashCode();
+
+ Cell[] cellsLocalRef = cells;
+ if(count != 0) {
+ int tableSize = cells.Length;
+ int cellIndex = GetCellIndex(tableSize, hash);
+ Cell prev = cellsLocalRef[cellIndex];
+ Cell cell = prev;
+ while(cell != null) {
+ if(cell.name == name || name.Equals(cell.name)) {
+ break;
+ }
+ prev = cell;
+ cell = cell.next;
+ }
+ if(cell != null) {
+ count--;
+ // remove slot from hash table
+ if(prev == cell) {
+ cellsLocalRef[cellIndex] = cell.next;
+ } else {
+ prev.next = cell.next;
+ }
+
+ if(firstAdded == cell) {
+ firstAdded = cell.orderedNext;
+ if(lastAdded == cell) {
+ lastAdded = null;
+ }
+ } else {
+ Cell p2 = firstAdded;
+ while(p2.orderedNext != cell) {
+ p2 = p2.orderedNext;
+ }
+ if(p2 != null) {
+ p2.orderedNext = cell.orderedNext;
+ }
+ if(lastAdded == cell) {
+ lastAdded = p2;
+ }
+ }
+
+ return cell.value;
+ }
+ }
+ return null;
+ }
+
+ private Cell[] cells;
+ private int count;
+
+ internal Cell firstAdded;
+ internal Cell lastAdded;
+
+ private static readonly int INITIAL_CELL_SIZE = 4;
+
+
+ private Cell GetCell(string name, bool query) {
+ Cell[] cellsLocalRef = cells;
+ if(cellsLocalRef == null && query) {
+ return null;
+ }
+ int hash = name.GetHashCode();
+ if(cellsLocalRef != null) {
+ Cell cell;
+ int cellIndex = GetCellIndex(cellsLocalRef.Length, hash);
+ for(cell = cellsLocalRef[cellIndex];
+ cell != null;
+ cell = cell.next) {
+ string sname = cell.name;
+ if(sname == name || name.Equals(sname)) {
+ break;
+ }
+ }
+ if(query || (!query && cell != null)) {
+ return cell;
+ }
+ }
+
+ return CreateCell(name, hash, query);
+ }
+
+ private static int GetCellIndex(int tableSize, int hash) {
+ return hash & (tableSize - 1);
+ }
+
+ private Cell CreateCell(string name, int hash, bool query) {
+ Cell[] cellsLocalRef = cells;
+ int insertPos;
+ if(count == 0) {
+ cellsLocalRef = new Cell[INITIAL_CELL_SIZE];
+ cells = cellsLocalRef;
+ insertPos = GetCellIndex(cellsLocalRef.Length, hash);
+ } else {
+ int tableSize = cellsLocalRef.Length;
+ insertPos = GetCellIndex(tableSize, hash);
+ Cell prev = cellsLocalRef[insertPos];
+ Cell cell = prev;
+ while(cell != null) {
+ if(cell.name == name || name.Equals(cell.name)) {
+ break;
+ }
+ prev = cell;
+ cell = cell.next;
+ }
+
+ if(cell != null) {
+ return cell;
+ } else {
+ if(4 * (count + 1) > 3 * cellsLocalRef.Length) {
+ cellsLocalRef = new Cell[cellsLocalRef.Length * 2];
+ CopyTable(cells, cellsLocalRef, count);
+ cells = cellsLocalRef;
+ insertPos = GetCellIndex(cellsLocalRef.Length, hash);
+ }
+ }
+ }
+ Cell newCell = new Cell(name, hash);
+ ++count;
+ if(lastAdded != null)
+ lastAdded.orderedNext = newCell;
+ if(firstAdded == null)
+ firstAdded = newCell;
+ lastAdded = newCell;
+ AddKnownAbsentCell(cellsLocalRef, newCell, insertPos);
+ return newCell;
+ }
+
+ private static void CopyTable(Cell[] cells, Cell[] newCells, int count) {
+ int tableSize = newCells.Length;
+ int i = cells.Length;
+ for (;;) {
+ --i;
+ Cell cell = cells[i];
+ while(cell != null) {
+ int insertPos = GetCellIndex(tableSize, cell.hash);
+ Cell next = cell.next;
+ AddKnownAbsentCell(newCells, cell, insertPos);
+ cell.next = null;
+ cell = next;
+ if(--count == 0)
+ return;
+ }
+ }
+ }
+
+ private static void AddKnownAbsentCell(Cell[] cells, Cell cell, int insertPos) {
+ if(cells[insertPos] == null) {
+ cells[insertPos] = cell;
+ } else {
+ Cell prev = cells[insertPos];
+ while(prev.next != null) {
+ prev = prev.next;
+ }
+ prev.next = cell;
+ }
+ }
+ }
+}
View
14 src/ikc/main/Ioke.Lang/Call.cs
@@ -32,10 +32,10 @@ public class Call : IokeData {
.Arguments,
(self, _on, args, keywords, context, _message) => {
Call c = (Call)IokeObject.dataOf(_on);
- string name = Text.GetText(((Message)IokeObject.dataOf(runtime.asText)).SendTo(runtime.asText, context, args[0]));
+ string name = Text.GetText(Interpreter.Send(runtime.asText, context, args[0]));
IokeObject m = Message.Copy(c.message);
Message.SetName(m, name);
- return ((Message)IokeObject.dataOf(m)).SendTo(m, c.surroundingContext, c.on);
+ return Interpreter.Send(m, c.surroundingContext, c.on);
})));
obj.RegisterMethod(runtime.NewNativeMethod("takes one evaluated object and resends the current message with that object as the new receiver",
@@ -45,7 +45,7 @@ public class Call : IokeData {
.Arguments,
(self, _on, args, keywords, context, _message) => {
Call c = (Call)IokeObject.dataOf(_on);
- return ((Message)IokeObject.dataOf(c.message)).SendTo(c.message, c.surroundingContext, args[0]);
+ return Interpreter.Send(c.message, c.surroundingContext, args[0]);
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns a list of all the unevaluated arguments",
@@ -88,7 +88,7 @@ public class Call : IokeData {
runtime.Call,
(method, _on, args, keywords, context, _message) => {
IokeObject msg = ((Call)IokeObject.dataOf(_on)).message;
- return context.runtime.NewList(((Message)IokeObject.dataOf(msg)).GetEvaluatedArguments(msg, ((Call)IokeObject.dataOf(_on)).surroundingContext));
+ return context.runtime.NewList(Interpreter.GetEvaluatedArguments(msg, ((Call)IokeObject.dataOf(_on)).surroundingContext));
})));
@@ -105,7 +105,7 @@ public class Call : IokeData {
self = args[1];
}
- return IokeObject.GetOrActivate(args[0], c.surroundingContext, c.message, self);
+ return Interpreter.GetOrActivate(args[0], c.surroundingContext, c.message, self);
})));
obj.RegisterMethod(runtime.NewNativeMethod("uhm. this one isn't too bad.",
@@ -122,7 +122,7 @@ public class Call : IokeData {
self = args[1];
}
- return IokeObject.As(args[0], context).ActivateWithData(c.surroundingContext, c.message, self, keys);
+ return Interpreter.ActivateWithData(IokeObject.As(args[0], context), c.surroundingContext, c.message, self, keys);
})));
obj.RegisterMethod(runtime.NewNativeMethod("I really ought to write documentation for these methods, but I don't know how to describe what they do.",
@@ -139,7 +139,7 @@ public class Call : IokeData {
self = args[1];
}
- return IokeObject.As(args[0], context).ActivateWithCallAndData(c.surroundingContext, c.message, self, _on, keys);
+ return Interpreter.ActivateWithCallAndData(IokeObject.As(args[0], context), c.surroundingContext, c.message, self, _on, keys);
})));
}
View
14 src/ikc/main/Ioke.Lang/CaseBehavior.cs
@@ -5,7 +5,7 @@ public class CaseBehavior {
public static IokeObject TransformWhenStatement(object when, IokeObject context, IokeObject message, IokeObject caseMimic) {
string outerName = Message.GetName(when);
- if(caseMimic.Cells.ContainsKey("case:" + outerName)) {
+ if(caseMimic.body.Has("case:" + outerName)) {
IokeObject cp = Message.DeepCopy(when);
ReplaceAllCaseNames(cp, context, message, caseMimic);
return cp;
@@ -16,7 +16,7 @@ public class CaseBehavior {
private static void ReplaceAllCaseNames(IokeObject when, IokeObject context, IokeObject message, IokeObject caseMimic) {
string theName = "case:" + Message.GetName(when);
- if(caseMimic.Cells.ContainsKey(theName)) {
+ if(caseMimic.body.Has(theName)) {
Message.SetName(when, theName);
foreach(object arg in when.Arguments) {
@@ -42,15 +42,15 @@ public class CaseBehavior {
int argCount = args.Count;
int index = 0;
IokeObject msg = IokeObject.As(args[index++], context);
- object value = ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
+ object value = runtime.interpreter.Evaluate(msg, context, context.RealContext, context);
argCount--;
while(argCount > 1) {
msg = TransformWhenStatement(args[index++], context, message, obj);
- object when = ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
- if(IokeObject.IsObjectTrue(((Message)IokeObject.dataOf(runtime.eqqMessage)).SendTo(runtime.eqqMessage, context, when, value))) {
+ object when = runtime.interpreter.Evaluate(msg, context, context.RealContext, context);
+ if(IokeObject.IsObjectTrue(Interpreter.Send(runtime.eqqMessage, context, when, value))) {
msg = IokeObject.As(args[index++], context);
- return ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
+ return runtime.interpreter.Evaluate(msg, context, context.RealContext, context);
} else {
index++;
}
@@ -59,7 +59,7 @@ public class CaseBehavior {
if(argCount == 1) {
msg = IokeObject.As(args[index++], context);
- return ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
+ return runtime.interpreter.Evaluate(msg, context, context.RealContext, context);
}
return runtime.nil;
View
46 src/ikc/main/Ioke.Lang/ConditionsBehavior.cs
@@ -28,7 +28,7 @@ public class ConditionsBehavior {
IList<Runtime.HandlerInfo> handlers = context.runtime.FindActiveHandlersFor(newCondition, (rescue == null) ? new Runtime.BindIndex(-1,-1) : rescue.index);
foreach(Runtime.HandlerInfo rhi in handlers) {
- ((Message)IokeObject.dataOf(context.runtime.callMessage)).SendTo(context.runtime.callMessage, context, ((Message)IokeObject.dataOf(context.runtime.handlerMessage)).SendTo(context.runtime.handlerMessage, context, rhi.handler), newCondition);
+ Interpreter.Send(context.runtime.callMessage, context, Interpreter.Send(context.runtime.handlerMessage, context, rhi.handler), newCondition);
}
if(rescue != null) {
@@ -93,9 +93,9 @@ public class ConditionsBehavior {
if(m.IsKeyword()) {
string n = m.Name;
if(n.Equals("report:")) {
- report = IokeObject.As(((Message)IokeObject.dataOf(m.next)).EvaluateCompleteWithoutExplicitReceiver(m.next, context, context.RealContext), context);
+ report = IokeObject.As(runtime.interpreter.Evaluate(m.next, context, context.RealContext, context), context);
} else if(n.Equals("test:")) {
- test = IokeObject.As(((Message)IokeObject.dataOf(m.next)).EvaluateCompleteWithoutExplicitReceiver(m.next, context, context.RealContext), context);
+ test = IokeObject.As(runtime.interpreter.Evaluate(m.next, context, context.RealContext, context), context);
} else {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition,
message,
@@ -123,8 +123,8 @@ public class ConditionsBehavior {
}
}
- code = IokeObject.As(((Message)IokeObject.dataOf(code)).EvaluateCompleteWithoutExplicitReceiver(code, context, context.RealContext), context);
- object restart = ((Message)IokeObject.dataOf(runtime.mimicMessage)).SendTo(runtime.mimicMessage, context, runtime.Restart);
+ code = IokeObject.As(runtime.interpreter.Evaluate(code, context, context.RealContext, context), context);
+ object restart = Interpreter.Send(runtime.mimicMessage, context, runtime.Restart);
IokeObject.SetCell(restart, "code", code, context);
@@ -152,15 +152,15 @@ public class ConditionsBehavior {
int count = message.Arguments.Count;
IList conds = new SaneArrayList();
for(int i=0, j=count-1; i<j; i++) {
- conds.Add(((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, i, context));
+ conds.Add(Interpreter.GetEvaluatedArgument(message, i, context));
}
if(conds.Count == 0) {
conds.Add(context.runtime.Condition);
}
- object handler = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, count-1, context);
- object rescue = ((Message)IokeObject.dataOf(context.runtime.mimicMessage)).SendTo(context.runtime.mimicMessage, context, context.runtime.Rescue);
+ object handler = Interpreter.GetEvaluatedArgument(message, count-1, context);
+ object rescue = Interpreter.Send(context.runtime.mimicMessage, context, context.runtime.Rescue);
IokeObject.SetCell(rescue, "handler", handler, context);
IokeObject.SetCell(rescue, "conditions", context.runtime.NewList(conds), context);
@@ -177,15 +177,15 @@ public class ConditionsBehavior {
int count = message.Arguments.Count;
IList conds = new SaneArrayList();
for(int i=0, j=count-1; i<j; i++) {
- conds.Add(((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, i, context));
+ conds.Add(Interpreter.GetEvaluatedArgument(message, i, context));
}
if(conds.Count == 0) {
conds.Add(context.runtime.Condition);
}
- object code = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, count-1, context);
- object handle = ((Message)IokeObject.dataOf(context.runtime.mimicMessage)).SendTo(context.runtime.mimicMessage, context, context.runtime.Handler);
+ object code = Interpreter.GetEvaluatedArgument(message, count-1, context);
+ object handle = Interpreter.Send(context.runtime.mimicMessage, context, context.runtime.Handler);
IokeObject.SetCell(handle, "handler", code, context);
IokeObject.SetCell(handle, "conditions", context.runtime.NewList(conds), context);
@@ -218,12 +218,12 @@ public class ConditionsBehavior {
try {
foreach(object o in ArrayList.Adapter(args).GetRange(0, argCount-1)) {
IokeObject msg = IokeObject.As(o, context);
- IokeObject bindable = IokeObject.As(((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext), context);
+ IokeObject bindable = IokeObject.As(runtime.interpreter.Evaluate(msg, context, context.RealContext, context), context);
bool loop = false;
do {
loop = false;
if(IokeObject.IsKind(bindable, "Restart")) {
- object ioName = ((Message)IokeObject.dataOf(runtime.nameMessage)).SendTo(runtime.nameMessage, context, bindable);
+ object ioName = Interpreter.Send(runtime.nameMessage, context, bindable);
string name = null;
if(ioName != runtime.nil) {
name = Symbol.GetText(ioName);
@@ -231,12 +231,12 @@ public class ConditionsBehavior {
restarts.Insert(0, new Runtime.RestartInfo(name, bindable, restarts, index, null));
index = index.NextCol();
} else if(IokeObject.IsKind(bindable, "Rescue")) {
- object conditions = ((Message)IokeObject.dataOf(runtime.conditionsMessage)).SendTo(runtime.conditionsMessage, context, bindable);
+ object conditions = Interpreter.Send(runtime.conditionsMessage, context, bindable);
var applicable = IokeList.GetList(conditions);
rescues.Insert(0, new Runtime.RescueInfo(bindable, applicable, rescues, index));
index = index.NextCol();
} else if(IokeObject.IsKind(bindable, "Handler")) {
- object conditions = ((Message)IokeObject.dataOf(runtime.conditionsMessage)).SendTo(runtime.conditionsMessage, context, bindable);
+ object conditions = Interpreter.Send(runtime.conditionsMessage, context, bindable);
var applicable = IokeList.GetList(conditions);
handlers.Insert(0, new Runtime.HandlerInfo(bindable, applicable, handlers, index));
index = index.NextCol();
@@ -265,7 +265,7 @@ public class ConditionsBehavior {
runtime.RegisterRescues(rescues);
runtime.RegisterHandlers(handlers);
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWithoutExplicitReceiver(code, context, context.RealContext);
+ return runtime.interpreter.Evaluate(code, context, context.RealContext, context);
} catch(ControlFlow.Restart e) {
Runtime.RestartInfo ri = null;
if((ri = e.GetRestart).token == restarts) {
@@ -273,7 +273,7 @@ public class ConditionsBehavior {
runtime.UnregisterRescues(rescues);
runtime.UnregisterRestarts(restarts);
doUnregister = false;
- return ((Message)IokeObject.dataOf(runtime.callMessage)).SendTo(runtime.callMessage, context, ((Message)IokeObject.dataOf(runtime.codeMessage)).SendTo(runtime.codeMessage, context, ri.restart), e.Arguments);
+ return Interpreter.Send(runtime.callMessage, context, Interpreter.Send(runtime.codeMessage, context, ri.restart), e.Arguments);
} else {
throw e;
}
@@ -284,7 +284,7 @@ public class ConditionsBehavior {
runtime.UnregisterRescues(rescues);
runtime.UnregisterRestarts(restarts);
doUnregister = false;
- return ((Message)IokeObject.dataOf(runtime.callMessage)).SendTo(runtime.callMessage, context, ((Message)IokeObject.dataOf(runtime.handlerMessage)).SendTo(runtime.handlerMessage, context, ri.rescue), e.Condition);
+ return Interpreter.Send(runtime.callMessage, context, Interpreter.Send(runtime.handlerMessage, context, ri.rescue), e.Condition);
} else {
throw e;
}
@@ -410,7 +410,7 @@ public class ConditionsBehavior {
foreach(var lri in activeRestarts) {
foreach(var rri in lri) {
- if(IokeObject.IsObjectTrue(((Message)IokeObject.dataOf(runtime.callMessage)).SendTo(runtime.callMessage, context, ((Message)IokeObject.dataOf(runtime.testMessage)).SendTo(runtime.testMessage, context, rri.restart), toLookFor))) {
+ if(IokeObject.IsObjectTrue(Interpreter.Send(runtime.callMessage, context, Interpreter.Send(runtime.testMessage, context, rri.restart), toLookFor))) {
result.Add(rri.restart);
}
}
@@ -453,13 +453,13 @@ public class ConditionsBehavior {
IokeObject condition = Signal(datum, positionalArgs, keywordArgs, message, context);
IokeObject err = IokeObject.As(context.runtime.System.GetCell(message, context, "err"), context);
- ((Message)IokeObject.dataOf(context.runtime.printMessage)).SendTo(context.runtime.printMessage, context, err, context.runtime.NewText("*** - "));
- ((Message)IokeObject.dataOf(context.runtime.printlnMessage)).SendTo(context.runtime.printlnMessage, context, err, ((Message)IokeObject.dataOf(context.runtime.reportMessage)).SendTo(context.runtime.reportMessage, context, condition));
+ Interpreter.Send(context.runtime.printMessage, context, err, context.runtime.NewText("*** - "));
+ Interpreter.Send(context.runtime.printlnMessage, context, err, Interpreter.Send(context.runtime.reportMessage, context, condition));
- IokeObject currentDebugger = IokeObject.As(((Message)IokeObject.dataOf(context.runtime.currentDebuggerMessage)).SendTo(context.runtime.currentDebuggerMessage, context, context.runtime.System), context);
+ IokeObject currentDebugger = IokeObject.As(Interpreter.Send(context.runtime.currentDebuggerMessage, context, context.runtime.System), context);
if(!currentDebugger.IsNil) {
- ((Message)IokeObject.dataOf(context.runtime.invokeMessage)).SendTo(context.runtime.invokeMessage, context, currentDebugger, condition, context);
+ Interpreter.Send(context.runtime.invokeMessage, context, currentDebugger, condition, context);
}
throw new ControlFlow.Exit(condition);
View
15 src/ikc/main/Ioke.Lang/DefaultArgumentsDefinition.cs
@@ -230,9 +230,9 @@ private class NewArgumentGivingRestart : Restart.ArgumentGivingRestart {
foreach(object o in arguments) {
if(Message.IsKeyword(o)) {
- givenKeywords[IokeObject.As(o, context).Name] = Message.GetEvaluatedArgument(((Message)IokeObject.dataOf(o)).next, context);
+ givenKeywords[IokeObject.As(o, context).Name] = Interpreter.GetEvaluatedArgument(((Message)IokeObject.dataOf(o)).next, context);
} else if(Message.HasName(o, "*") && IokeObject.As(o, context).Arguments.Count == 1) { // Splat
- object result = Message.GetEvaluatedArgument(IokeObject.As(o, context).Arguments[0], context);
+ object result = Interpreter.GetEvaluatedArgument(IokeObject.As(o, context).Arguments[0], context);
if(IokeObject.dataOf(result) is IokeList) {
IList elements = IokeList.GetList(result);
foreach(object ox in elements) argumentsWithoutKeywords.Add(ox);
@@ -242,8 +242,8 @@ private class NewArgumentGivingRestart : Restart.ArgumentGivingRestart {
foreach(DictionaryEntry me in keys) {
givenKeywords[Text.GetText(IokeObject.ConvertToText(me.Key, message, context, true)) + ":"] = me.Value;
}
- } else if(IokeObject.FindCell(result, message, context, "asTuple") != runtime.nul) {
- object tupledValue = ((Message)IokeObject.dataOf(runtime.asTuple)).SendTo(runtime.asTuple, context, result);
+ } else if(IokeObject.FindCell((IokeObject)result, "asTuple") != runtime.nul) {
+ object tupledValue = Interpreter.Send(runtime.asTuple, context, result);
object[] values = Tuple.GetElements(tupledValue);
foreach(object val in values) argumentsWithoutKeywords.Add(val);
argCount += values.Length;
@@ -269,7 +269,8 @@ private class NewArgumentGivingRestart : Restart.ArgumentGivingRestart {
argCount += outp.Count;
}
} else {
- argumentsWithoutKeywords.Add(Message.GetEvaluatedArgument(o, context));
+ var xx = Interpreter.GetEvaluatedArgument(o, context);
+ argumentsWithoutKeywords.Add(xx);
argCount++;
}
}
@@ -386,7 +387,7 @@ private class NewArgumentGivingRestart : Restart.ArgumentGivingRestart {
object defVal = ((KeywordArgument)a).DefaultValue;
if(!(defVal is string)) {
IokeObject m1 = IokeObject.As(defVal, context);
- result = ((Message)IokeObject.dataOf(m1)).EvaluateCompleteWithoutExplicitReceiver(m1, locals, locals.RealContext);
+ result = runtime.interpreter.Evaluate(m1, locals, locals.RealContext, locals);
locals.SetCell(a.Name, result);
}
}
@@ -394,7 +395,7 @@ private class NewArgumentGivingRestart : Restart.ArgumentGivingRestart {
object defVal = ((OptionalArgument)a).DefaultValue;
if(!(defVal is string)) {
IokeObject m2 = IokeObject.As(defVal, context);
- locals.SetCell(a.Name, ((Message)IokeObject.dataOf(m2)).EvaluateCompleteWithoutExplicitReceiver(m2, locals, locals.RealContext));
+ locals.SetCell(a.Name, runtime.interpreter.Evaluate(m2, locals, locals.RealContext, locals));
}
} else {
locals.SetCell(a.Name, argumentsWithoutKeywords[ix++]);
View
26 src/ikc/main/Ioke.Lang/DefaultBehavior.cs
@@ -11,19 +11,19 @@ public class DefaultBehavior {
IokeObject baseBehavior = new IokeObject(runtime, "contains behavior copied from Base");
baseBehavior.Kind = "DefaultBehavior BaseBehavior";
- baseBehavior.SetCell("=", runtime.Base.Cells["="]);
- baseBehavior.SetCell("==", runtime.Base.Cells["=="]);
- baseBehavior.SetCell("cell", runtime.Base.Cells["cell"]);
- baseBehavior.SetCell("cell?", runtime.Base.Cells["cell?"]);
- baseBehavior.SetCell("cell=", runtime.Base.Cells["cell="]);
- baseBehavior.SetCell("cells", runtime.Base.Cells["cells"]);
- baseBehavior.SetCell("cellNames", runtime.Base.Cells["cellNames"]);
- baseBehavior.SetCell("removeCell!", runtime.Base.Cells["removeCell!"]);
- baseBehavior.SetCell("undefineCell!", runtime.Base.Cells["undefineCell!"]);
- baseBehavior.SetCell("cellOwner?", runtime.Base.Cells["cellOwner?"]);
- baseBehavior.SetCell("cellOwner", runtime.Base.Cells["cellOwner"]);
- baseBehavior.SetCell("documentation", runtime.Base.Cells["documentation"]);
- baseBehavior.SetCell("identity", runtime.Base.Cells["identity"]);
+ baseBehavior.SetCell("=", runtime.Base.body.Get("="));
+ baseBehavior.SetCell("==", runtime.Base.body.Get("=="));
+ baseBehavior.SetCell("cell", runtime.Base.body.Get("cell"));
+ baseBehavior.SetCell("cell?", runtime.Base.body.Get("cell?"));
+ baseBehavior.SetCell("cell=", runtime.Base.body.Get("cell="));
+ baseBehavior.SetCell("cells", runtime.Base.body.Get("cells"));
+ baseBehavior.SetCell("cellNames", runtime.Base.body.Get("cellNames"));
+ baseBehavior.SetCell("removeCell!", runtime.Base.body.Get("removeCell!"));
+ baseBehavior.SetCell("undefineCell!", runtime.Base.body.Get("undefineCell!"));
+ baseBehavior.SetCell("cellOwner?", runtime.Base.body.Get("cellOwner?"));
+ baseBehavior.SetCell("cellOwner", runtime.Base.body.Get("cellOwner"));
+ baseBehavior.SetCell("documentation", runtime.Base.body.Get("documentation"));
+ baseBehavior.SetCell("identity", runtime.Base.body.Get("identity"));
obj.MimicsWithoutCheck(baseBehavior);
obj.RegisterCell("BaseBehavior", baseBehavior);
View
67 src/ikc/main/Ioke.Lang/DefaultMacro.cs
@@ -8,7 +8,7 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
string name;
IokeObject code;
- public DefaultMacro(string name) {
+ public DefaultMacro(string name) : base(IokeData.TYPE_DEFAULT_MACRO) {
this.name = name;
}
@@ -18,7 +18,7 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
public override void Init(IokeObject obj) {
obj.Kind = "DefaultMacro";
- obj.RegisterCell("activatable", obj.runtime.True);
+ obj.SetActivatable(true);
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the name of the macro",
new TypeCheckingNativeMethod.WithNoArguments("name", obj,
@@ -33,7 +33,7 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
.WithRestUnevaluated("arguments")
.Arguments,
(method, _context, message, on, outer) => {
- return IokeObject.As(on, _context).Activate(_context, message, _context.RealContext);
+ return Interpreter.Activate(IokeObject.As(on, _context), _context, message, _context.RealContext);
})));
@@ -125,8 +125,9 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
get { return "..."; }
}
- public override object ActivateWithCallAndData(IokeObject self, IokeObject context, IokeObject message, object on, object call, IDictionary<string, object> data) {
- if(code == null) {
+ public static object ActivateWithCallAndDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, object call, IDictionary<string, object> data) {
+ DefaultMacro dm = (DefaultMacro)self.data;
+ if(dm.code == null) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
@@ -160,7 +161,7 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
}
try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ return context.runtime.interpreter.Evaluate(dm.code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
return e.Value;
@@ -170,48 +171,9 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
}
}
- public override object ActivateWithCall(IokeObject self, IokeObject context, IokeObject message, object on, object call) {
- if(code == null) {
- IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
- message,
- context,
- "Error",
- "Invocation",
- "NotActivatable"), context).Mimic(message, context);
- condition.SetCell("message", message);
- condition.SetCell("context", context);
- condition.SetCell("receiver", on);
- condition.SetCell("method", self);
- condition.SetCell("report", context.runtime.NewText("You tried to activate a method without any code - did you by any chance activate the DefaultMacro kind by referring to it without wrapping it inside a call to cell?"));
- context.runtime.ErrorCondition(condition);
- return null;
- }
-
- IokeObject c = context.runtime.Locals.Mimic(message, context);
- c.SetCell("self", on);
- c.SetCell("@", on);
- c.RegisterMethod(c.runtime.NewNativeMethod("will return the currently executing macro receiver", new NativeMethod.WithNoArguments("@@",
- (method, _context, _message, _on, outer) => {
- outer.ArgumentsDefinition.GetEvaluatedArguments(_context, _message, _on, new SaneArrayList(), new SaneDictionary<string, object>());
- return self;
- })));
- c.SetCell("currentMessage", message);
- c.SetCell("surroundingContext", context);
- c.SetCell("call", call);
-
- try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
- } catch(ControlFlow.Return e) {
- if(e.context == c) {
- return e.Value;
- } else {
- throw e;
- }
- }
- }
-
- public override object Activate(IokeObject self, IokeObject context, IokeObject message, object on) {
- if(code == null) {
+ public new static object ActivateFixed(IokeObject self, IokeObject context, IokeObject message, object on) {
+ DefaultMacro dm = (DefaultMacro)self.data;
+ if(dm.code == null) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
@@ -240,7 +202,7 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
c.SetCell("call", context.runtime.NewCallFrom(c, message, context, IokeObject.As(on, context)));
try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ return context.runtime.interpreter.Evaluate(dm.code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
return e.Value;
@@ -250,8 +212,9 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
}
}
- public override object ActivateWithData(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary<string, object> data) {
- if(code == null) {
+ public static object ActivateWithDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary<string, object> data) {
+ DefaultMacro dm = (DefaultMacro)self.data;
+ if(dm.code == null) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
@@ -285,7 +248,7 @@ public class DefaultMacro : IokeData, Named, Inspectable, AssociatedCode {
}
try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ return context.runtime.interpreter.Evaluate(dm.code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
return e.Value;
View
135 src/ikc/main/Ioke.Lang/DefaultMethod.cs
@@ -8,8 +8,8 @@ public class DefaultMethod : Method, AssociatedCode {
DefaultArgumentsDefinition arguments;
IokeObject code;
- public DefaultMethod(string name) : base(name) {}
- public DefaultMethod(IokeObject context, DefaultArgumentsDefinition arguments, IokeObject code) : base(context) {
+ public DefaultMethod(string name) : base(name, IokeData.TYPE_DEFAULT_METHOD) {}
+ public DefaultMethod(IokeObject context, DefaultArgumentsDefinition arguments, IokeObject code) : base(context, IokeData.TYPE_DEFAULT_METHOD) {
this.arguments = arguments;
this.code = code;
}
@@ -77,73 +77,38 @@ public class DefaultMethod : Method, AssociatedCode {
})));
}
- IokeObject CreateSuperCallFor(IokeObject out_self, IokeObject out_context, IokeObject out_message, object out_on, object out_superCell) {
- return out_context.runtime.NewNativeMethod("will call the super method of the current message on the same receiver",
+ private static IokeObject CreateSuperCallFor(IokeObject out_self, IokeObject out_context, IokeObject out_message, object out_on, string out_name) {
+ return out_context.runtime.NewNativeMethod("will call the super method of the current message on the same receiver",
new NativeMethod("super", DefaultArgumentsDefinition.builder()
.WithRestUnevaluated("arguments")
.Arguments,
(method, context, message, on, outer) => {
- if(IokeObject.dataOf(out_superCell) is Method) {
- return IokeObject.Activate(out_superCell, context, message, out_on);
+ object superCell = context.runtime.nul;
+ string realname = out_name;
+ if(realname != null) {
+ superCell = IokeObject.FindSuperCellOn(out_on, out_self, out_context, realname);
+ }
+ if(superCell == context.runtime.nul) {
+ realname = Message.GetName(out_message);
+ superCell = IokeObject.FindSuperCellOn(out_on, out_self, out_context, realname);
+ }
+
+ if(superCell != context.runtime.nul) {
+ if(IokeObject.dataOf(superCell) is Method) {
+ return Interpreter.Activate(((IokeObject)superCell), context, message, out_on);
+ } else {
+ return superCell;
+ }
} else {
- return out_superCell;
+ return Interpreter.SignalNoSuchCell(message, context, out_on, realname, superCell, out_self);
+
}
}));
}
- public override object ActivateWithCall(IokeObject self, IokeObject context, IokeObject message, object on, object call) {
- if(code == null) {
- IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
- message,
- context,
- "Error",
- "Invocation",
- "NotActivatable"), context).Mimic(message, context);
- condition.SetCell("message", message);
- condition.SetCell("context", context);
- condition.SetCell("receiver", on);
- condition.SetCell("method", self);
- condition.SetCell("report", context.runtime.NewText("You tried to activate a method without any code - did you by any chance activate the DefaultMethod kind by referring to it without wrapping it inside a call to cell?"));
- context.runtime.ErrorCondition(condition);
- return null;
- }
-
- IokeObject c = context.runtime.Locals.Mimic(message, context);
- c.SetCell("self", on);
- c.SetCell("@", on);
- c.RegisterMethod(c.runtime.NewNativeMethod("will return the currently executing method receiver",
- new NativeMethod.WithNoArguments("@@",
- (method, _context, _message, _on, outer) => {
- outer.ArgumentsDefinition.GetEvaluatedArguments(_context, _message, _on, new SaneArrayList(), new SaneDictionary<string, object>());
- return self;
- })));
- c.SetCell("currentMessage", message);
- c.SetCell("surroundingContext", context);
-
- object superCell = IokeObject.FindSuperCellOn(on, self, message, context, name);
- if(superCell == context.runtime.nul) {
- superCell = IokeObject.FindSuperCellOn(on, self, message, context, Message.GetName(message));
- }
-
- if(superCell != context.runtime.nul) {
- c.SetCell("super", CreateSuperCallFor(self, context, message, on, superCell));
- }
-
- arguments.AssignArgumentValues(c, context, message, on, ((Call)IokeObject.dataOf(call)));
-
- try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
- } catch(ControlFlow.Return e) {
- if(e.context == c) {
- return e.Value;
- } else {
- throw e;
- }
- }
- }
-
- public override object ActivateWithCallAndData(IokeObject self, IokeObject context, IokeObject message, object on, object call, IDictionary<string, object> data) {
- if(code == null) {
+ public static object ActivateWithCallAndDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, object call, IDictionary<string, object> data) {
+ DefaultMethod dm = (DefaultMethod)self.data;
+ if(dm.code == null) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
@@ -176,19 +141,12 @@ public class DefaultMethod : Method, AssociatedCode {
c.SetCell(s.Substring(0, s.Length-1), d.Value);
}
- object superCell = IokeObject.FindSuperCellOn(on, self, message, context, name);
- if(superCell == context.runtime.nul) {
- superCell = IokeObject.FindSuperCellOn(on, self, message, context, Message.GetName(message));
- }
+ c.SetCell("super", CreateSuperCallFor(self, context, message, on, dm.name));
- if(superCell != context.runtime.nul) {
- c.SetCell("super", CreateSuperCallFor(self, context, message, on, superCell));
- }
-
- arguments.AssignArgumentValues(c, context, message, on, ((Call)IokeObject.dataOf(call)));
+ dm.arguments.AssignArgumentValues(c, context, message, on, ((Call)IokeObject.dataOf(call)));
try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ return context.runtime.interpreter.Evaluate(dm.code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
return e.Value;
@@ -198,8 +156,9 @@ public class DefaultMethod : Method, AssociatedCode {
}
}
- public override object Activate(IokeObject self, IokeObject context, IokeObject message, object on) {
- if(code == null) {
+ public new static object ActivateFixed(IokeObject self, IokeObject context, IokeObject message, object on) {
+ DefaultMethod dm = (DefaultMethod)self.data;
+ if(dm.code == null) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
@@ -226,20 +185,12 @@ public class DefaultMethod : Method, AssociatedCode {
})));
c.SetCell("currentMessage", message);
c.SetCell("surroundingContext", context);
+ c.SetCell("super", CreateSuperCallFor(self, context, message, on, dm.name));
- object superCell = IokeObject.FindSuperCellOn(on, self, message, context, name);
- if(superCell == context.runtime.nul) {
- superCell = IokeObject.FindSuperCellOn(on, self, message, context, Message.GetName(message));
- }
-
- if(superCell != context.runtime.nul) {
- c.SetCell("super", CreateSuperCallFor(self, context, message, on, superCell));
- }
-
- arguments.AssignArgumentValues(c, context, message, on);
+ dm.arguments.AssignArgumentValues(c, context, message, on);
try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ return context.runtime.interpreter.Evaluate(dm.code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
return e.Value;
@@ -249,8 +200,9 @@ public class DefaultMethod : Method, AssociatedCode {
}
}
- public override object ActivateWithData(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary<string, object> data) {
- if(code == null) {
+ public static object ActivateWithDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary<string, object> data) {
+ DefaultMethod dm = (DefaultMethod)self.data;
+ if(dm.code == null) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
@@ -283,19 +235,12 @@ public class DefaultMethod : Method, AssociatedCode {
c.SetCell(s.Substring(0, s.Length-1), d.Value);
}
- object superCell = IokeObject.FindSuperCellOn(on, self, message, context, name);
- if(superCell == context.runtime.nul) {
- superCell = IokeObject.FindSuperCellOn(on, self, message, context, Message.GetName(message));
- }
-
- if(superCell != context.runtime.nul) {
- c.SetCell("super", CreateSuperCallFor(self, context, message, on, superCell));
- }
+ c.SetCell("super", CreateSuperCallFor(self, context, message, on, dm.name));
- arguments.AssignArgumentValues(c, context, message, on);
+ dm.arguments.AssignArgumentValues(c, context, message, on);
try {
- return ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ return context.runtime.interpreter.Evaluate(dm.code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
return e.Value;
View
32 src/ikc/main/Ioke.Lang/DefaultSyntax.cs
@@ -9,7 +9,7 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
IokeObject context;
IokeObject code;
- public DefaultSyntax(string name) {
+ public DefaultSyntax(string name) : base(IokeData.TYPE_DEFAULT_SYNTAX) {
this.name = name;
}
@@ -20,7 +20,7 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
public override void Init(IokeObject obj) {
obj.Kind = "DefaultSyntax";
- obj.RegisterCell("activatable", obj.runtime.True);
+ obj.SetActivatable(true);
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the name of the syntax",
new TypeCheckingNativeMethod.WithNoArguments("name", obj,
@@ -34,7 +34,7 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
.WithRestUnevaluated("arguments")
.Arguments,
(method, _context, message, on, outer) => {
- return IokeObject.As(on, _context).Activate(_context, message, _context.RealContext);
+ return Interpreter.Activate(IokeObject.As(on, _context), _context, message, _context.RealContext);
})));
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the result of activating this syntax without actually doing the replacement or execution part.",
@@ -175,7 +175,7 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
object result = null;
try {
- result = ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ result = context.runtime.interpreter.Evaluate(code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
result = e.Value;
@@ -225,7 +225,7 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
object result = null;
try {
- result = ((Message)IokeObject.dataOf(code)).EvaluateCompleteWith(code, c, on);
+ result = context.runtime.interpreter.Evaluate(code, c, on, c);
} catch(ControlFlow.Return e) {
if(e.context == c) {
result = e.Value;
@@ -237,8 +237,9 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
return result;
}
- public override object ActivateWithCallAndData(IokeObject self, IokeObject context, IokeObject message, object on, object call, IDictionary<string, object> data) {
- object result = ExpandWithCall(self, context, message, on, call, data);
+ public static object ActivateWithCallAndDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, object call, IDictionary<string, object> data) {
+ DefaultSyntax dm = (DefaultSyntax)self.data;
+ object result = dm.ExpandWithCall(self, context, message, on, call, data);
if(result == context.runtime.nil) {
// Remove chain completely
@@ -281,20 +282,17 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
// We need to distinguish explicit calls to self, and calls through a local context.
object receiver = (prev == null || Message.IsTerminator(prev)) ? context : on;
- return ((Message)IokeObject.dataOf(message)).SendTo(message, context, receiver);
+ return Interpreter.Send(message, context, receiver);
}
}
- public override object ActivateWithCall(IokeObject self, IokeObject context, IokeObject message, object on, object call) {
- return ActivateWithCallAndData(self, context, message, on, call, null);
+ public new static object ActivateFixed(IokeObject self, IokeObject context, IokeObject message, object on) {
+ return ActivateWithDataFixed(self, context, message, on, null);
}
- public override object Activate(IokeObject self, IokeObject context, IokeObject message, object on) {
- return ActivateWithData(self, context, message, on, null);
- }
-
- public override object ActivateWithData(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary<string, object> data) {
- object result = Expand(self, context, message, on, data);
+ public static object ActivateWithDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary<string, object> data) {
+ DefaultSyntax dm = (DefaultSyntax)self.data;
+ object result = dm.Expand(self, context, message, on, data);
if(result == context.runtime.nil) {
// Remove chain completely
@@ -337,7 +335,7 @@ public class DefaultSyntax : IokeData, Named, Inspectable, AssociatedCode {
// We need to distinguish explicit calls to self, and calls through a local context.
object receiver = (prev == null || Message.IsTerminator(prev)) ? context : on;
- return ((Message)IokeObject.dataOf(message)).SendTo(message, context, receiver);
+ return Interpreter.Send(message, context, receiver);
}
}
}
View
4 src/ikc/main/Ioke.Lang/DefinitionsBehavior.cs
@@ -175,8 +175,8 @@ public class DefinitionsBehavior {
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
- string fromName = Text.GetText(((Message)IokeObject.dataOf(runtime.asText)).SendTo(runtime.asText, context, args[0]));
- string toName = Text.GetText(((Message)IokeObject.dataOf(runtime.asText)).SendTo(runtime.asText, context, args[1]));
+ string fromName = Text.GetText(Interpreter.Send(runtime.asText, context, args[0]));
+ string toName = Text.GetText(Interpreter.Send(runtime.asText, context, args[1]));
IokeObject.As(on, context).AliasMethod(fromName, toName, message, context);
return on;
})));
View
14 src/ikc/main/Ioke.Lang/Dict.cs
@@ -41,7 +41,7 @@ public class Dict : IokeData {
Runtime runtime = obj.runtime;
obj.Kind = "Dict";
- obj.Mimics(IokeObject.As(runtime.Mixins.GetCell(null, null, "Sequenced"), null), runtime.nul, runtime.nul);
+ obj.Mimics(IokeObject.As(IokeObject.FindCell(runtime.Mixins, "Sequenced"), null), runtime.nul, runtime.nul);
obj.RegisterMethod(obj.runtime.NewNativeMethod("returns a hash for the dictionary",
new NativeMethod.WithNoArguments("hash", (method, context, message, on, outer) => {
@@ -194,29 +194,29 @@ public class Dict : IokeData {
var ls = Dict.GetMap(on);
switch(message.Arguments.Count) {
case 0: {
- return ((Message)IokeObject.dataOf(runtime.seqMessage)).SendTo(runtime.seqMessage, context, on);
+ return Interpreter.Send(runtime.seqMessage, context, on);
}
case 1: {
IokeObject code = IokeObject.As(message.Arguments[0], context);
foreach(DictionaryEntry o in ls) {
- ((Message)IokeObject.dataOf(code)).EvaluateCompleteWithReceiver(code, context, context.RealContext, runtime.NewPair(o.Key, o.Value));
+ context.runtime.interpreter.Evaluate(code, context, context.RealContext, runtime.NewPair(o.Key, o.Value));
}
break;
}
case 2: {
- LexicalContext c = new LexicalContext(context.runtime, context, "Lexical activation context for List#each", message, context);
+ IokeObject c = context.runtime.NewLexicalContext(context, "Lexical activation context for Dict#each", context);
string name = IokeObject.As(message.Arguments[0], context).Name;
IokeObject code = IokeObject.As(message.Arguments[1], context);
foreach(DictionaryEntry o in ls) {
c.SetCell(name, runtime.NewPair(o.Key, o.Value));
- ((Message)IokeObject.dataOf(code)).EvaluateCompleteWithoutExplicitReceiver(code, c, c.RealContext);
+ context.runtime.interpreter.Evaluate(code, c, c.RealContext, c);
}
break;
}
case 3: {
- LexicalContext c = new LexicalContext(context.runtime, context, "Lexical activation context for List#each", message, context);
+ IokeObject c = context.runtime.NewLexicalContext(context, "Lexical activation context for Dict#each", context);
string iname = IokeObject.As(message.Arguments[0], context).Name;
string name = IokeObject.As(message.Arguments[1], context).Name;
IokeObject code = IokeObject.As(message.Arguments[2], context);
@@ -225,7 +225,7 @@ public class Dict : IokeData {
foreach(DictionaryEntry o in ls) {
c.SetCell(name, runtime.NewPair(o.Key, o.Value));
c.SetCell(iname, runtime.NewNumber(index++));
- ((Message)IokeObject.dataOf(code)).EvaluateCompleteWithoutExplicitReceiver(code, c, c.RealContext);
+ context.runtime.interpreter.Evaluate(code, c, c.RealContext, c);
}
break;
}
View
8 src/ikc/main/Ioke.Lang/Extensions/Benchmark/Benchmark.cs
@@ -28,10 +28,10 @@ public abstract class Benchmark {
long iterations = 1;
int index = 0;
if(count > 1) {
- bmRounds = ((Number)IokeObject.dataOf(IokeObject.ConvertToNumber(((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, index, context), message, context))).AsNativeInteger();
+ bmRounds = ((Number)IokeObject.dataOf(IokeObject.ConvertToNumber(Interpreter.GetEvaluatedArgument(message, index, context), message, context))).AsNativeInteger();
index++;
if(count > 2) {
- iterations = ((Number)IokeObject.dataOf(IokeObject.ConvertToNumber(((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, index, context), message, context))).AsNativeLong();
+ iterations = ((Number)IokeObject.dataOf(IokeObject.ConvertToNumber(Interpreter.GetEvaluatedArgument(message, index, context), message, context))).AsNativeLong();
index++;
}
}
@@ -39,7 +39,7 @@ public abstract class Benchmark {
for(int i=0;i<bmRounds;i++) {
long before = System.DateTime.Now.Ticks;
for(int j=0;j<iterations;j++) {
- ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, index, context);
+ Interpreter.GetEvaluatedArgument(message, index, context);
}
long after = System.DateTime.Now.Ticks;
long time = after-before;
@@ -48,7 +48,7 @@ public abstract class Benchmark {
string theCode = Message.ThisCode(((IokeObject)message.Arguments[index]));
- ((Message)IokeObject.dataOf(context.runtime.printlnMessage)).SendTo(context.runtime.printlnMessage, context, ((Message)IokeObject.dataOf(context.runtime.outMessage)).SendTo(context.runtime.outMessage, context, context.runtime.System), context.runtime.NewText(string.Format("{0,-32} {1:d6}.{2:d9}", theCode, secs, rest)));
+ Interpreter.Send(context.runtime.printlnMessage, context, Interpreter.Send(context.runtime.outMessage, context, context.runtime.System), context.runtime.NewText(string.Format("{0,-32} {1:d6}.{2:d9}", theCode, secs, rest)));
}
return context.runtime.nil;
View
4 src/ikc/main/Ioke.Lang/FileSystem.cs
@@ -209,9 +209,9 @@ public class IokeFile : IokeIO {
object result = context.runtime.nil;
try {
- result = ((Message)IokeObject.dataOf(context.runtime.callMessage)).SendTo(context.runtime.callMessage, context, args[1], ff);
+ result = Interpreter.Send(context.runtime.callMessage, context, args[1], ff);
} finally {
- ((Message)IokeObject.dataOf(context.runtime.closeMessage)).SendTo(context.runtime.closeMessage, context, ff);
+ Interpreter.Send(context.runtime.closeMessage, context, ff);
}
return result;
View
57 src/ikc/main/Ioke.Lang/FlowControlBehavior.cs
@@ -19,20 +19,21 @@ public class FlowControlBehavior {
(method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
- object test = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 0, context);
+ object test = Interpreter.GetEvaluatedArgument(message, 0, context);
- LexicalContext itContext = new LexicalContext(context.runtime, context.RealContext, "Lexical activation context", message, context);
+
+ IokeObject itContext = context.runtime.NewLexicalContext(context.RealContext, "Lexical activation context", context);
itContext.SetCell("it", test);
if(IokeObject.IsObjectTrue(test)) {
if(message.Arguments.Count > 1) {
- return ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 1, itContext);
+ return Interpreter.GetEvaluatedArgument(message, 1, itContext);
} else {
return test;
}
} else {
if(message.Arguments.Count > 2) {
- return ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 2, itContext);
+ return Interpreter.GetEvaluatedArgument(message, 2, itContext);
} else {
return test;
}
@@ -48,20 +49,20 @@ public class FlowControlBehavior {
(method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
- object test = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 0, context);
+ object test = Interpreter.GetEvaluatedArgument(message, 0, context);
- LexicalContext itContext = new LexicalContext(context.runtime, context.RealContext, "Lexical activation context", message, context);
+ IokeObject itContext = context.runtime.NewLexicalContext(context.RealContext, "Lexical activation context", context);
itContext.SetCell("it", test);
if(IokeObject.IsObjectTrue(test)) {
if(message.Arguments.Count > 2) {
- return ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 2, itContext);
+ return Interpreter.GetEvaluatedArgument(message, 2, itContext);
} else {
return test;
}
} else {
if(message.Arguments.Count > 1) {
- return ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 1, itContext);
+ return Interpreter.GetEvaluatedArgument(message, 1, itContext);
} else {
return test;
}
@@ -77,7 +78,7 @@ public class FlowControlBehavior {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
var args = message.Arguments;
- LexicalContext lc = new LexicalContext(context.runtime, context.RealContext, "Let lexical activation context", message, context);
+ IokeObject lc = context.runtime.NewLexicalContext(context.RealContext, "Let lexical activation context", context);
int ix = 0;
int end = args.Count-1;
var valuesToUnbind = new LinkedList<object[]>();
@@ -86,7 +87,7 @@ public class FlowControlBehavior {
IokeObject place = IokeObject.As(args[ix++], context);
if(Message.GetNext(place) == null && place.Arguments.Count == 0) {
- object value = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, ix++, context);
+ object value = Interpreter.GetEvaluatedArgument(message, ix++, context);
lc.SetCell(Message.GetName(place), value);
} else {
place = Message.DeepCopy(place);
@@ -103,26 +104,26 @@ public class FlowControlBehavior {
object wherePlace = context.RealContext;
if(place != realPlace) {
- wherePlace = Message.GetEvaluatedArgument(place, context);
+ wherePlace = Interpreter.GetEvaluatedArgument(place, context);
}
- object originalValue = runtime.WithReturningRescue(context, null, () => {return ((Message)IokeObject.dataOf(realPlace)).SendTo(realPlace, context, wherePlace);});
+ object originalValue = runtime.WithReturningRescue(context, null, () => {return Interpreter.Send(realPlace, context, wherePlace);});
if(realPlace.Arguments.Count != 0) {
string newName = realPlace.Name + "=";
var arguments = new SaneArrayList(realPlace.Arguments);
arguments.Add(args[ix++]);
IokeObject msg = context.runtime.NewMessageFrom(realPlace, newName, arguments);
- ((Message)IokeObject.dataOf(msg)).SendTo(msg, context, wherePlace);
+ Interpreter.Send(msg, context, wherePlace);
valuesToUnbind.AddFirst(new object[]{wherePlace, originalValue, realPlace});
} else {
- object value = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, ix++, context);
+ object value = Interpreter.GetEvaluatedArgument(message, ix++, context);
IokeObject.Assign(wherePlace, realPlace.Name, value, context, message);
valuesToUnbind.AddFirst(new object[]{wherePlace, originalValue, realPlace});
}
}
}
- return ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, end, lc);
+ return Interpreter.GetEvaluatedArgument(message, end, lc);
} finally {
while(valuesToUnbind.Count > 0) {
try {
@@ -138,16 +139,16 @@ public class FlowControlBehavior {
if(value == null) {
if(newName.Equals("cell=")) {
- ((Message)IokeObject.dataOf(context.runtime.removeCellMessage)).SendTo(context.runtime.removeCellMessage, context, wherePlace, new SaneArrayList(realPlace.Arguments));
+ Interpreter.Send(context.runtime.removeCellMessage, context, wherePlace, new SaneArrayList(realPlace.Arguments));
} else {
arguments.Add(context.runtime.CreateMessage(Message.Wrap(context.runtime.nil)));
IokeObject msg = context.runtime.NewMessageFrom(realPlace, newName, arguments);
- ((Message)IokeObject.dataOf(msg)).SendTo(msg, context, wherePlace);
+ Interpreter.Send(msg, context, wherePlace);
}
} else {
arguments.Add(context.runtime.CreateMessage(Message.Wrap(IokeObject.As(value, context))));
IokeObject msg = context.runtime.NewMessageFrom(realPlace, newName, arguments);
- ((Message)IokeObject.dataOf(msg)).SendTo(msg, context, wherePlace);
+ Interpreter.Send(msg, context, wherePlace);
}
} else {
if(value == null) {
@@ -173,7 +174,7 @@ public class FlowControlBehavior {
object value = runtime.nil;
if(message.Arguments.Count > 0) {
- value = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 0, context);
+ value = Interpreter.GetEvaluatedArgument(message, 0, context);
}
throw new ControlFlow.Break(value);
})));
@@ -190,8 +191,8 @@ public class FlowControlBehavior {
value = args[0];
}
IokeObject ctx = context;
- while(ctx is LexicalContext) {
- ctx = ((LexicalContext)ctx).surroundingContext;
+ while(ctx.data is LexicalContext) {
+ ctx = ((LexicalContext)ctx.data).surroundingContext;
}
throw new ControlFlow.Return(value, ctx);
@@ -223,9 +224,9 @@ public class FlowControlBehavior {
do {
doAgain = false;
try {
- while(!IokeObject.IsObjectTrue(((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 0, context))) {
+ while(!IokeObject.IsObjectTrue(Interpreter.GetEvaluatedArgument(message, 0, context))) {
if(body) {
- ret = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 1, context);
+ ret = Interpreter.GetEvaluatedArgument(message, 1, context);
}
}
} catch(ControlFlow.Break e) {
@@ -256,9 +257,9 @@ public class FlowControlBehavior {
do {
doAgain = false;
try {
- while(IokeObject.IsObjectTrue(((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 0, context))) {
+ while(IokeObject.IsObjectTrue(Interpreter.GetEvaluatedArgument(message, 0, context))) {
if(body) {
- ret = ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 1, context);
+ ret = Interpreter.GetEvaluatedArgument(message, 1, context);
}
}
} catch(ControlFlow.Break e) {
@@ -282,7 +283,7 @@ public class FlowControlBehavior {
while(true) {
try {
while(true) {
- ((Message)IokeObject.dataOf(message)).GetEvaluatedArgument(message, 0, context);
+ Interpreter.GetEvaluatedArgument(message, 0, context);
}
} catch(ControlFlow.Break e) {
return e.Value;
@@ -308,11 +309,11 @@ public class FlowControlBehavior {
try {
IokeObject msg = IokeObject.As(args[0], context);
- result = ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
+ result = context.runtime.interpreter.Evaluate(msg, context, context.RealContext, context);
} finally {
foreach(object o in ArrayList.Adapter(args).GetRange(1, argCount-1)) {
IokeObject msg = IokeObject.As(o, context);
- ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
+ context.runtime.interpreter.Evaluate(msg, context, context.RealContext, context);
}
}
View
40 src/ikc/main/Ioke.Lang/Hook.cs
@@ -14,95 +14,95 @@ public class Hook : IokeData {
void Rewire(IokeObject self) {
foreach(object io in connected) {
IokeObject oo = (IokeObject)io;
- if(oo.hooks == null) {
- oo.hooks = new SaneList<IokeObject>();
+ if(oo.body.hooks == null) {
+ oo.body.hooks = new SaneList<IokeObject>();
}
- if(!oo.hooks.Contains(self)) {
- oo.hooks.Add(self);
+ if(!oo.body.hooks.Contains(self)) {
+ oo.body.hooks.Add(self);
}
}
}
public static void FireCellAdded(IokeObject on, IokeObject message, IokeObject context, string name) {
- List<IokeObject> hooks = on.hooks;
+ List<IokeObject> hooks = on.body.hooks;
if(hooks != null) {
IokeObject sym = context.runtime.GetSymbol(name);
IokeObject cellAddedMessage = context.runtime.cellAddedMessage;
foreach(IokeObject h in hooks) {
- ((Message)IokeObject.dataOf(cellAddedMessage)).SendTo(cellAddedMessage, context, h, on, sym);
+ Interpreter.Send(cellAddedMessage, context, h, on, sym);
}
}
}