Permalink
Browse files

sync to head of tfs

  • Loading branch information...
1 parent 2b53470 commit 03054a5be81928afaacd16b5ef5d4067f7ecc69a @jredville jredville committed Sep 28, 2009
Showing with 455 additions and 107 deletions.
  1. +4 −0 Merlin/Main/Languages/IronPython/IronPython.Modules/_random.cs
  2. +86 −46 Merlin/Main/Languages/IronPython/IronPython.Modules/array.cs
  3. +4 −4 Merlin/Main/Languages/IronPython/IronPython.Modules/cPickle.cs
  4. +8 −2 Merlin/Main/Languages/IronPython/IronPython.Modules/copy_reg.cs
  5. +75 −8 Merlin/Main/Languages/IronPython/IronPython.Modules/datetime.cs
  6. +1 −1 Merlin/Main/Languages/IronPython/IronPython.Modules/re.cs
  7. +3 −1 Merlin/Main/Languages/IronPython/IronPython.Modules/thread.cs
  8. +6 −0 Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/ListComprehension.cs
  9. +1 −1 Merlin/Main/Languages/IronPython/IronPython/Compiler/Parser.cs
  10. +1 −1 Merlin/Main/Languages/IronPython/IronPython/Modules/Builtin.cs
  11. +1 −0 Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonFunction.cs
  12. +31 −6 Merlin/Main/Languages/IronPython/IronPython/Runtime/ErrorCodes.cs
  13. +2 −2 Merlin/Main/Languages/IronPython/IronPython/Runtime/Exceptions/PythonExceptions.cs
  14. +11 −3 Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/ObjectOps.cs
  15. +8 −3 Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/PythonOps.cs
  16. +1 −1 Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/StringOps.cs
  17. +19 −0 Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonContext.cs
  18. +11 −0 Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonFunction.cs
  19. +17 −1 Merlin/Main/Languages/IronPython/IronPython/Runtime/Set.cs
  20. +1 −8 Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/OldInstance.cs
  21. +21 −0 Merlin/Main/Languages/IronPython/IronPythonTest/EngineTest.cs
  22. +6 −0 Merlin/Main/Languages/Ruby/Experimental/Process/X/A B/x.cs
  23. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/A B/x.exe
  24. 0 Merlin/Main/Languages/Ruby/Experimental/Process/X/a
  25. +1 −0 Merlin/Main/Languages/Ruby/Experimental/Process/X/a.cmd
  26. +8 −0 Merlin/Main/Languages/Ruby/Experimental/Process/X/a.cs
  27. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/a.exe
  28. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/attrib.exe
  29. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/b.exe
  30. +7 −0 Merlin/Main/Languages/Ruby/Experimental/Process/X/inspect.cs
  31. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/inspect.exe
  32. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/notepad.exe
  33. +1 −0 Merlin/Main/Languages/Ruby/Experimental/Process/X/p.com
  34. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/q.com
  35. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/w.exe.exe
  36. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/w.t.exe
  37. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/w.tx.exe
  38. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/z.txt.exe
  39. BIN Merlin/Main/Languages/Ruby/Experimental/Process/X/z.txtt.exe
  40. +75 −0 Merlin/Main/Languages/Ruby/Experimental/Process/shellexec.rb
  41. +3 −3 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/GenerateInitializers.cmd
  42. +25 −16 Merlin/Main/Languages/Ruby/context.rb
  43. +2 −0 Merlin/Main/Languages/Ruby/rake/compile.rake
  44. +15 −0 Merlin/Main/Runtime/Microsoft.Dynamic/Actions/ReflectedPropertyTracker.cs
@@ -82,6 +82,10 @@ public class Random {
}
}
+ public void jumpahead(double count) {
+ throw PythonOps.TypeError("jumpahead requires an integer, not 'float'");
+ }
+
public object random() {
lock (this) {
return _rnd.NextDouble();
@@ -26,7 +26,9 @@
using Microsoft.Scripting;
using Microsoft.Scripting.Math;
using Microsoft.Scripting.Runtime;
+using Microsoft.Scripting.Utils;
using SpecialName = System.Runtime.CompilerServices.SpecialNameAttribute;
+using System.Reflection;
[assembly: PythonModule("array", typeof(IronPython.Modules.ArrayModule))]
namespace IronPython.Modules {
@@ -49,7 +51,12 @@ public class array : IPythonArray, IValueEquality, IEnumerable, IWeakReferenceab
_typeCode = type[0];
_data = CreateData(_typeCode);
- if (initializer != Type.Missing) extend(initializer);
+ if (initializer != Missing.Value) extend(initializer);
+ }
+
+ private array(char typeCode, ArrayData data) {
+ _typeCode = typeCode;
+ _data = data;
}
private static ArrayData CreateData(char typecode) {
@@ -87,7 +94,7 @@ public class array : IPythonArray, IValueEquality, IEnumerable, IWeakReferenceab
public static array operator +(array self, array other) {
if (self.typecode != other.typecode) throw PythonOps.TypeError("cannot add different typecodes");
- array res = new array(self.typecode, Type.Missing);
+ array res = new array(self.typecode, Missing.Value);
foreach (object o in self) {
res.append(o);
}
@@ -117,44 +124,31 @@ public class array : IPythonArray, IValueEquality, IEnumerable, IWeakReferenceab
if ((BigInteger)value * array.__len__() * array.itemsize > SysModule.maxsize) {
throw PythonOps.MemoryError("");
}
- array data = new array(array.typecode, Type.Missing);
- for (int i = 0; i < value; i++) {
- data.extend(array);
+
+ if (value <= 0) {
+ return new array(array.typecode, Missing.Value);
}
- return data;
+
+ return new array(array._typeCode, array._data.Multiply(value));
}
public static array operator *(array array, BigInteger value) {
- if (value * array.__len__() * array.itemsize > SysModule.maxsize) {
- throw PythonOps.MemoryError("");
- }
int intValue;
if (!value.AsInt32(out intValue)) {
throw PythonOps.OverflowError("cannot fit 'long' into an index-sized integer");
+ } else if (value * array.__len__() * array.itemsize > SysModule.maxsize) {
+ throw PythonOps.MemoryError("");
}
+
return array * intValue;
}
public static array operator *(int value, array array) {
- if ((BigInteger)value * array.__len__() * array.itemsize > SysModule.maxsize) {
- throw PythonOps.MemoryError("");
- }
- array data = new array(array.typecode, Type.Missing);
- for (int i = 0; i < value; i++) {
- data.extend(array);
- }
- return data;
+ return array * value;
}
public static array operator *(BigInteger value, array array) {
- if (value * array.__len__() * array.itemsize > SysModule.maxsize) {
- throw PythonOps.MemoryError("");
- }
- int intValue;
- if (!value.AsInt32(out intValue)) {
- throw PythonOps.OverflowError("cannot fit 'long' into an index-sized integer");
- }
- return intValue * array;
+ return array * value;
}
public void append(object iterable) {
@@ -273,12 +267,18 @@ public class array : IPythonArray, IValueEquality, IEnumerable, IWeakReferenceab
}
public void fromunicode(CodeContext/*!*/ context, string s) {
- if (s == null) throw PythonOps.TypeError("expected string");
- if (s.Length == 0) throw PythonOps.ValueError("empty string");
- if (_typeCode != 'u' && (s.Length % itemsize) != 0) throw PythonOps.ValueError("string length not a multiple of itemsize");
- MemoryStream ms = new MemoryStream(PythonContext.GetContext(context).DefaultEncoding.GetBytes(s));
-
- FromStream(ms);
+ if (s == null) {
+ throw PythonOps.TypeError("expected string");
+ } else if (_typeCode != 'u') {
+ throw PythonOps.ValueError("fromunicode() may only be called on type 'u' arrays");
+ }
+
+ ArrayData<char> data = (ArrayData<char>)_data;
+ data.EnsureSize(data.Length + s.Length);
+ for (int i = 0; i < s.Length; i++) {
+ data.Data[i + data.Length] = s[i];
+ }
+ data.Length += s.Length;
}
public int index(object x) {
@@ -482,7 +482,7 @@ public class array : IPythonArray, IValueEquality, IEnumerable, IWeakReferenceab
int start, stop, step;
index.indices(_data.Length, out start, out stop, out step);
- array pa = new array(new string(_typeCode, 1), Type.Missing);
+ array pa = new array(new string(_typeCode, 1), Missing.Value);
if (step < 0) {
for (int i = start; i > stop; i += step) {
pa._data.Append(_data.GetData(i));
@@ -620,11 +620,7 @@ public class array : IPythonArray, IValueEquality, IEnumerable, IWeakReferenceab
public string tounicode(CodeContext/*!*/ context) {
if (_typeCode != 'u') throw PythonOps.ValueError("only 'u' arrays can be converted to unicode");
- Stream s = ToStream();
- byte[] bytes = new byte[s.Length];
- s.Read(bytes, 0, (int)s.Length);
-
- return PythonContext.GetContext(context).DefaultEncoding.GetString(bytes, 0, bytes.Length);
+ return new string(((ArrayData<char>)_data).Data, 0, _data.Length);
}
public void write(PythonFile f) {
@@ -646,10 +642,11 @@ private abstract class ArrayData {
public abstract void Insert(int index, object value);
public abstract void Remove(object value);
public abstract void RemoveAt(int index);
- public abstract int Length { get; }
+ public abstract int Length { get; set; }
public abstract void Swap(int x, int y);
public abstract void Clear();
public abstract IntPtr GetAddress();
+ public abstract ArrayData Multiply(int count);
}
internal MemoryStream ToStream() {
@@ -833,15 +830,30 @@ private class ArrayData<T> : ArrayData {
private GCHandle? _dataHandle;
public ArrayData() {
+ GC.SuppressFinalize(this);
_data = new T[8];
+ }
+
+ private ArrayData(int size) {
GC.SuppressFinalize(this);
+ _data = new T[size];
+ _count = size;
}
~ArrayData() {
Debug.Assert(_dataHandle.HasValue);
_dataHandle.Value.Free();
}
+ public T[] Data {
+ get {
+ return _data;
+ }
+ set {
+ _data = value;
+ }
+ }
+
public override object GetData(int index) {
return _data[index];
}
@@ -872,7 +884,7 @@ private class ArrayData<T> : ArrayData {
_data[_count++] = GetValue(value);
}
- private void EnsureSize(int size) {
+ public void EnsureSize(int size) {
if (_data.Length < size) {
Array.Resize(ref _data, _data.Length * 2);
if (_dataHandle != null) {
@@ -942,6 +954,9 @@ private class ArrayData<T> : ArrayData {
get {
return _count;
}
+ set {
+ _count = value;
+ }
}
public override void Clear() {
@@ -971,6 +986,24 @@ private class ArrayData<T> : ArrayData {
}
return _dataHandle.Value.AddrOfPinnedObject();
}
+
+ public override ArrayData Multiply(int count) {
+ var res = new ArrayData<T>(count * _count);
+ if (count != 0) {
+ Array.Copy(_data, res._data, _count);
+
+ int newCount = count * _count;
+ int block = _count;
+ int pos = _count;
+ while (pos < newCount) {
+ Array.Copy(res._data, 0, res._data, pos, Math.Min(block, newCount - pos));
+ pos += block;
+ block *= 2;
+ }
+ }
+
+ return res;
+ }
}
#region IValueEquality Members
@@ -1015,16 +1048,23 @@ private class ArrayData<T> : ArrayData {
StringBuilder sb = new StringBuilder(res);
if (_typeCode == 'c' || _typeCode == 'u') {
+ char quote = '\'';
+ string s = new string(((ArrayData<char>)_data).Data, 0, _data.Length);
+ if (s.IndexOf('\'') != -1 && s.IndexOf('\"') == -1) {
+ quote = '\"';
+ }
+
if (_typeCode == 'u') {
- sb.Append(", u'");
+ sb.Append(", u");
} else {
- sb.Append(", '");
- }
- for (int i = 0; i < _data.Length; i++) {
- bool isUnicode = _typeCode == 'u';
- sb.Append(StringOps.ReprEncode(CharOps.ConvertToString((char)_data.GetData(i)), ref isUnicode));
+ sb.Append(", ");
}
- sb.Append("')");
+ sb.Append(quote);
+
+ bool isUnicode = false;
+ sb.Append(StringOps.ReprEncode(s, quote, ref isUnicode));
+ sb.Append(quote);
+ sb.Append(")");
} else {
sb.Append(", [");
for (int i = 0; i < _data.Length; i++) {
@@ -682,15 +682,15 @@ public class PicklerObject {
result = PythonCalls.Call(context, reduceCallable, obj);
} else if (PythonOps.TryGetBoundAttr(context, obj, "__reduce_ex__", out reduceCallable)) {
if (obj is PythonType) {
- result = PythonOps.CallWithContext(context, reduceCallable, obj, _protocol);
+ result = context.LanguageContext.Call(context, reduceCallable, obj, _protocol);
} else {
- result = PythonOps.CallWithContext(context, reduceCallable, _protocol);
+ result = context.LanguageContext.Call(context, reduceCallable, _protocol);
}
} else if (PythonOps.TryGetBoundAttr(context, obj, "__reduce__", out reduceCallable)) {
if (obj is PythonType) {
- result = PythonOps.CallWithContext(context, reduceCallable, obj);
+ result = context.LanguageContext.Call(context, reduceCallable, obj);
} else {
- result = PythonOps.CallWithContext(context, reduceCallable);
+ result = context.LanguageContext.Call(context, reduceCallable);
}
} else {
throw PythonOps.AttributeError("no reduce function found for {0}", obj);
@@ -175,8 +175,14 @@ public static class PythonCopyReg {
+ "protocols 0 or 1\" for details."
)]
public static object _reconstructor(CodeContext/*!*/ context, object objType, object baseType, object baseState) {
- object obj = PythonOps.Invoke(context, baseType, "__new__", objType, baseState);
- PythonOps.Invoke(context, baseType, "__init__", obj, baseState);
+ object obj;
+ if (baseState == null) {
+ obj = PythonOps.Invoke(context, baseType, "__new__", objType);
+ PythonOps.Invoke(context, baseType, "__init__", obj);
+ } else {
+ obj = PythonOps.Invoke(context, baseType, "__new__", objType, baseState);
+ PythonOps.Invoke(context, baseType, "__init__", obj, baseState);
+ }
return obj;
}
Oops, something went wrong.

0 comments on commit 03054a5

Please sign in to comment.