Permalink
Browse files

[dotnet] Make sure at_pos and at_key never return null, but rather so…

…mething undefined. Allows duplicate method check to be uncommented.
  • Loading branch information...
1 parent 0d51c06 commit 2fd812db57b59d96627003770584318b718c107e @jnthn committed Oct 31, 2010
Showing with 27 additions and 11 deletions.
  1. +11 −11 common/NQP/NQPSetting.pm
  2. +1 −0 dotnet/compiler/Actions.pm
  3. +15 −0 dotnet/runtime/Runtime/Ops.cs
View
@@ -80,6 +80,11 @@ knowhow NQPNum is repr('P6num') {
}
}
+# XXX Bad hack, we'll replace this later.
+knowhow Any {
+ method defined() { 0 }
+}
+
knowhow NQPList is repr('P6list') {
method new() {
nqp::instance_of(self.WHAT)
@@ -91,7 +96,7 @@ knowhow NQPList is repr('P6list') {
self.elems
}
method at_pos($idx) {
- nqp::lllist_get_at_pos(self, $idx.Int)
+ nqp::vivify(nqp::lllist_get_at_pos(self, $idx.Int), Any)
}
method defined() {
nqp::repr_defined(self)
@@ -109,7 +114,7 @@ knowhow NQPArray is repr('P6list') {
nqp::lllist_elems(self)
}
method at_pos($idx) {
- nqp::lllist_get_at_pos(self, $idx.Int)
+ nqp::vivify(nqp::lllist_get_at_pos(self, $idx.Int), Any)
}
method bind_pos($idx, $value) {
nqp::lllist_bind_at_pos(self, $idx.Int, $value)
@@ -130,7 +135,7 @@ knowhow NQPHash is repr('P6mapping') {
nqp::llmapping_elems(self)
}
method at_key($key) {
- nqp::llmapping_get_at_key(self, $key.Str)
+ nqp::vivify(nqp::llmapping_get_at_key(self, $key.Str), Any)
}
method bind_key($key, $value) {
nqp::llmapping_bind_at_key(self, $key.Str, $value)
@@ -326,10 +331,9 @@ knowhow NQPClassHOW {
}
method add_method($obj, $name, $code_obj) {
- # XXX TODO This crashes due to lack of auto-viv. :/
- #if %!methods{$name} {
- # die("This class already has a method named " ~ $name);
- #}
+ if %!methods{$name}.defined {
+ die("This class already has a method named " ~ $name);
+ }
%!methods{$name} := $code_obj;
}
@@ -378,10 +382,6 @@ knowhow NQPClassHOW {
}
}
-# XXX Bad hack, we'll replace this later.
-knowhow Any {
-}
-
# GLOBAL stash.
# (XXX Really want one per compilation unit and unify, but this will get us
# started. Also really want a stash type that knows its name rather than just
@@ -696,6 +696,7 @@ sub is_lexical($name) {
%setting_names<NQPList> := 1;
%setting_names<NQPArray> := 1;
%setting_names<NQPHash> := 1;
+ %setting_names<Any> := 1;
if %setting_names{$name} {
return 1;
}
@@ -768,6 +768,21 @@ public static RakudoObject llmapping_elems(ThreadContext TC, RakudoObject LLMapp
}
}
+ /// <summary>
+ /// If the first passed object reference is not null, returns it. Otherwise,
+ /// returns the second passed object reference. (Note, we should one day drop
+ /// this and implement it as a compiler transformation, to avoid having to
+ /// look up the thing to vivify).
+ /// </summary>
+ /// <param name="TC"></param>
+ /// <param name="Check"></param>
+ /// <param name="VivifyWith"></param>
+ /// <returns></returns>
+ public static RakudoObject vivify(ThreadContext TC, RakudoObject Check, RakudoObject VivifyWith)
+ {
+ return Check ?? VivifyWith;
+ }
+
/// <summary>
/// Leaves the specified block, returning the specified value from it. This
/// unwinds the stack.

0 comments on commit 2fd812d

Please sign in to comment.