Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/ironruby/ironruby
Browse files Browse the repository at this point in the history
  • Loading branch information
nrk committed Apr 15, 2009
2 parents 7b819d6 + 2f31eb6 commit 23b77ff
Show file tree
Hide file tree
Showing 34 changed files with 720 additions and 191 deletions.
Expand Up @@ -262,7 +262,7 @@ public class _local {
/// the thread.
/// </summary>
private class ThreadLocalDictionaryStorage : DictionaryStorage {
private readonly ThreadLocal<CommonDictionaryStorage> _storage = new ThreadLocal<CommonDictionaryStorage>();
private readonly Microsoft.Scripting.Utils.ThreadLocal<CommonDictionaryStorage> _storage = new Microsoft.Scripting.Utils.ThreadLocal<CommonDictionaryStorage>();

public override void Add(object key, object value) {
GetStorage().Add(key, value);
Expand Down
39 changes: 39 additions & 0 deletions Merlin/Main/Languages/Ruby/Experimental/Interop/com.rb
@@ -0,0 +1,39 @@
class WIN32OLE
def initialize progIdOrClsId
if progIdOrClsId.is_a? System::Guid
type = System::Type.GetTypeFromCLSID(progIdOrClsId)
raise "Unknown CLSID #{progIdOrClsId}" if type.nil?
elsif WIN32OLE.is_guid progIdOrClsId
type = System::Type.GetTypeFromCLSID(System::Guid.new(progIdOrClsId))
raise "Unknown CLSID #{progIdOrClsId}" if type.nil?
else
type = System::Type.GetTypeFromProgID(progIdOrClsId)
raise "Unknown PROGID '#{progIdOrClsId}'" if type.nil?
end
@com_object = System::Activator.CreateInstance(type)
end

def self.is_guid(str)
!!(/[{]?[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}[}]?|[0-9A-F]{32}/ =~ str)
end

def method_missing name, *args
@com_object.send(name, *args)
end

attr_reader :com_object
end

ex = WIN32OLE.new("Excel.Application")
#ex = WIN32OLE.new("{00024500-0000-0000-C000-000000000046}")

ex.Visible = true
nb = ex.Workbooks.Add
ws = nb.Worksheets[1]
p ws.Name

10.times do |i|
10.times do |j|
ws.Cells[i + 1, j + 1] = (i + 1) * (j + 1)
end
end
18 changes: 13 additions & 5 deletions Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs
Expand Up @@ -358,17 +358,25 @@ print ruby()
py.Execute(@"
def get_python_class():
class C(object):
x = 123
def __str__(self):
return 'this is C'
return C()
", scope);

AssertOutput(() => Engine.Execute(@"
p get_python_class.call
", scope), @"
this is C
");
Engine.Execute(@"self.c = get_python_class.call", scope);

var s = Engine.Execute<MutableString>(@"c.to_str", scope);
Assert(s.ToString() == @"this is C");

var i = Engine.Execute<int>(@"c.x", scope);
Assert(i == 123);

// TODO: test
// c.y, where y is a delegate
// c.p, where p is a Ruby Proc
}

public void PythonInterop5() {
Expand Down
Expand Up @@ -1380,12 +1380,21 @@ internal ThrowCatchUnwinder(string/*!*/ label, object returnValue)
// thread-safe:
[RubyMethod("methods")]
public static RubyArray/*!*/ GetMethods(RubyContext/*!*/ context, object self, [DefaultParameterValue(true)]bool inherited) {
var foreignMembers = context.GetForeignDynamicMemberNames(self);

RubyClass immediateClass = context.GetImmediateClassOf(self);
if (!inherited && !immediateClass.IsSingletonClass) {
return new RubyArray();
var result = new RubyArray();
if (foreignMembers.Count > 0) {
var symbolicNames = context.RubyOptions.Compatibility > RubyCompatibility.Ruby18;
foreach (var name in foreignMembers) {
result.Add(ModuleOps.CreateMethodName(name, symbolicNames));
}
}
return result;
}

return ModuleOps.GetMethods(immediateClass, inherited, RubyMethodAttributes.Public | RubyMethodAttributes.Protected);
return ModuleOps.GetMethods(immediateClass, inherited, RubyMethodAttributes.Public | RubyMethodAttributes.Protected, foreignMembers);
}

// thread-safe:
Expand Down
Expand Up @@ -786,21 +786,31 @@ public static class ModuleOps {
}

internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes) {
return GetMethods(self, inherited, attributes, null);
}

internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes,
IEnumerable<string> foreignMembers) {

var result = new RubyArray();
var symbolicNames = self.Context.RubyOptions.Compatibility > RubyCompatibility.Ruby18;

using (self.Context.ClassHierarchyLocker()) {
self.ForEachMember(inherited, attributes, delegate(string/*!*/ name, RubyMemberInfo member) {
if (symbolicNames) {
result.Add(SymbolTable.StringToId(name));
} else {
result.Add(MutableString.Create(name));
}
self.ForEachMember(inherited, attributes, foreignMembers, delegate(string/*!*/ name, RubyMemberInfo member) {
result.Add(CreateMethodName(name, symbolicNames));
});
}
return result;
}

internal static object CreateMethodName(string/*!*/ name, bool symbolicNames) {
if (symbolicNames) {
return SymbolTable.StringToId(name);
} else {
return MutableString.Create(name);
}
}

#endregion

#region {private_|protected_|public_|}method_defined? (thread-safe)
Expand Down
Expand Up @@ -31,39 +31,6 @@ public static class IronRubyOps {

[RubyModule("Clr")]
public static class ClrOps {

//[RubyConstant("String")]
//public static RubyModule/*!*/ GetClrStringModule(RubyModule/*!*/ module) {
// return GetModule(module, typeof(ClrString));
//}

//[RubyConstant("Float")]
//public static RubyModule/*!*/ GetClrFloatModule(RubyModule/*!*/ module) {
// return GetModule(module, typeof(ClrFloat));
//}

//[RubyConstant("Integer")]
//public static RubyModule/*!*/ GetClrIntegerModule(RubyModule/*!*/ module) {
// return GetModule(module, typeof(ClrInteger));
//}

//[RubyConstant("BigInteger")]
//public static RubyModule/*!*/ GetClrBigIntegerModule(RubyModule/*!*/ module) {
// return GetModule(module, typeof(ClrBigInteger));
//}

//[RubyConstant("MultiDimensionalArray")]
//public static RubyModule/*!*/ GetMultiDimensionalArrayModule(RubyModule/*!*/ module) {
// return GetModule(module, typeof(MultiDimensionalArray));
//}

//private static RubyModule/*!*/ GetModule(RubyModule/*!*/ declaringModule, Type/*!*/ type) {
// RubyModule result;
// declaringModule.Context.TryGetModule(type, out result);
// Debug.Assert(result != null);
// return result;
//}

[RubyMethod("profile", RubyMethodAttributes.PublicSingleton)]
public static Hash/*!*/ GetProfile(RubyContext/*!*/ context, object self) {
if (!((RubyOptions)context.Options).Profile) {
Expand Down
21 changes: 18 additions & 3 deletions Merlin/Main/Languages/Ruby/Ruby.sln
Expand Up @@ -11,13 +11,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassInitGenerator", "Class
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting.Core", "..\..\..\..\ndp\fx\src\Core\Microsoft\Scripting\Microsoft.Scripting.Core.csproj", "{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Dynamic", "..\..\..\..\ndp\fx\src\Dynamic\System\Dynamic\Microsoft.Dynamic.csproj", "{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Libraries", "Libraries.LCA_RESTRICTED\IronRuby.Libraries.csproj", "{77323B06-15A2-4CF4-8A7A-86EAA2B66498}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Libraries.Scanner", "Utils\IronRuby.Libraries.Scanner\IronRuby.Libraries.Scanner.csproj", "{5F692D9C-968B-48BF-AC2F-6B4F54D9C1BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting", "..\..\Runtime\Microsoft.Scripting\Microsoft.Scripting.csproj", "{EB66B766-6354-4208-A3D4-AACBDCB5C3B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Libraries.Yaml", "..\..\..\External.LCA_RESTRICTED\Languages\IronRuby\yaml\IronRuby.Libraries.Yaml\IronRuby.Libraries.Yaml.csproj", "{AA18A245-E342-4368-A474-83178311A742}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Libraries.Yaml", "..\..\..\External.LCA_RESTRICTED\Languages\IronRuby\Yaml\IronRuby.Libraries.Yaml\IronRuby.Libraries.Yaml.csproj", "{AA18A245-E342-4368-A474-83178311A742}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting.ExtensionAttribute", "..\..\..\..\ndp\fx\src\Core\Microsoft\Scripting\Microsoft.Scripting.ExtensionAttribute.csproj", "{8B0F1074-750E-4D64-BF23-A1E0F54261E5}"
EndProject
Expand All @@ -34,7 +36,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClrAssembly", "..\..\Test\C
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 13
SccNumberOfProjects = 14
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = http://vstfdevdiv:8080/
SccLocalPath0 = .
Expand Down Expand Up @@ -62,7 +64,7 @@ Global
SccProjectUniqueName8 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting\\Microsoft.Scripting.Core.csproj
SccProjectName8 = ../../../../ndp/fx/src/Core/Microsoft/Scripting
SccLocalPath8 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting
SccProjectUniqueName9 = ..\\..\\..\\External.LCA_RESTRICTED\\Languages\\IronRuby\\yaml\\IronRuby.Libraries.Yaml\\IronRuby.Libraries.Yaml.csproj
SccProjectUniqueName9 = ..\\..\\..\\External.LCA_RESTRICTED\\Languages\\IronRuby\\Yaml\\IronRuby.Libraries.Yaml\\IronRuby.Libraries.Yaml.csproj
SccProjectName9 = ../../../External.LCA_RESTRICTED/Languages/IronRuby/yaml/IronRuby.Libraries.Yaml
SccLocalPath9 = ..\\..\\..\\External.LCA_RESTRICTED\\Languages\\IronRuby\\yaml\\IronRuby.Libraries.Yaml
SccProjectUniqueName10 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting\\Microsoft.Scripting.ExtensionAttribute.csproj
Expand All @@ -74,6 +76,9 @@ Global
SccProjectUniqueName12 = ..\\..\\Test\\ClrAssembly\\ClrAssembly.csproj
SccProjectName12 = ../../Test/ClrAssembly
SccLocalPath12 = ..\\..\\Test\\ClrAssembly
SccProjectUniqueName13 = ..\\..\\..\\..\\ndp\\fx\\src\\Dynamic\\System\\Dynamic\\Microsoft.Dynamic.csproj
SccProjectName13 = ../../../../ndp/fx/src/Dynamic/System/Dynamic
SccLocalPath13 = ..\\..\\..\\..\\ndp\\fx\\src\\Dynamic\\System\\Dynamic
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Ruby.vsmdi
Expand Down Expand Up @@ -130,6 +135,16 @@ Global
{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU
{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU
{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.FxCop|Any CPU.Build.0 = FxCop|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Release|Any CPU.Build.0 = Release|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Silverlight Debug|Any CPU.Build.0 = Debug|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU
{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Silverlight Release|Any CPU.Build.0 = Release|Any CPU
{77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77323B06-15A2-4CF4-8A7A-86EAA2B66498}.FxCop|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs
Expand Up @@ -28,7 +28,7 @@

namespace IronRuby.Builtins {

public partial class Proc : IDynamicMetaObjectProvider {
public partial class Proc : IRubyDynamicMetaObjectProvider {
public DynamicMetaObject/*!*/ GetMetaObject(Expression/*!*/ parameter) {
return new Meta(parameter, BindingRestrictions.Empty, this);
}
Expand Down
4 changes: 2 additions & 2 deletions Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyEvent.Meta.cs
Expand Up @@ -28,8 +28,8 @@

namespace IronRuby.Builtins {
using Ast = System.Linq.Expressions.Expression;
public partial class RubyEvent : IDynamicMetaObjectProvider {

public partial class RubyEvent : IRubyDynamicMetaObjectProvider {
public DynamicMetaObject/*!*/ GetMetaObject(Expression/*!*/ parameter) {
return new Meta(parameter, BindingRestrictions.Empty, this);
}
Expand Down
4 changes: 2 additions & 2 deletions Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyMethod.Meta.cs
Expand Up @@ -28,8 +28,8 @@

namespace IronRuby.Builtins {
using Ast = System.Linq.Expressions.Expression;
public partial class RubyMethod : IDynamicMetaObjectProvider {

public partial class RubyMethod : IRubyDynamicMetaObjectProvider {
public DynamicMetaObject/*!*/ GetMetaObject(Expression/*!*/ parameter) {
return new Meta(parameter, BindingRestrictions.Empty, this);
}
Expand Down
Expand Up @@ -23,7 +23,7 @@

namespace IronRuby.Builtins {

public partial class RubyModule : IDynamicMetaObjectProvider {
public partial class RubyModule : IRubyDynamicMetaObjectProvider {
public virtual DynamicMetaObject/*!*/ GetMetaObject(Expression/*!*/ parameter) {
return new Meta(parameter, BindingRestrictions.Empty, this);
}
Expand Down
20 changes: 19 additions & 1 deletion Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs
Expand Up @@ -158,6 +158,10 @@ private enum MemberTableState {
get { return false; }
}

public bool IsComClass {
get { return ReferenceEquals(this, Context.ComObjectClass); }
}

internal virtual RubyClass GetSuperClass() {
return null;
}
Expand Down Expand Up @@ -1375,7 +1379,9 @@ private enum ConstantLookupResult {
/// <remarks>
/// Not thread safe.
/// </remarks>
public void ForEachMember(bool inherited, RubyMethodAttributes attributes, Action<string/*!*/, RubyMemberInfo/*!*/>/*!*/ action) {
public void ForEachMember(bool inherited, RubyMethodAttributes attributes, IEnumerable<string> foreignMembers,
Action<string/*!*/, RubyMemberInfo/*!*/>/*!*/ action) {

Context.RequiresClassHierarchyLock();

var visited = new Dictionary<string, bool>();
Expand All @@ -1385,6 +1391,14 @@ private enum ConstantLookupResult {
bool instanceMethods = (attributes & RubyMethodAttributes.Instance) != 0;
bool singletonMethods = (attributes & RubyMethodAttributes.Singleton) != 0;

// TODO: if we allow creating singletons for foreign objects we need to change this:
if (foreignMembers != null) {
foreach (var name in foreignMembers) {
action(name, RubyMethodInfo.ForeignMember);
visited.Add(name, true);
}
}

bool stop = false;
ForEachInstanceMethod(true, delegate(RubyModule/*!*/ module, string name, RubyMemberInfo member) {

Expand Down Expand Up @@ -1416,6 +1430,10 @@ private enum ConstantLookupResult {
});
}

public void ForEachMember(bool inherited, RubyMethodAttributes attributes, Action<string/*!*/, RubyMemberInfo/*!*/>/*!*/ action) {
ForEachMember(inherited, attributes, null, action);
}

#endregion

#region Class variables (TODO: thread-safety)
Expand Down
Expand Up @@ -24,7 +24,7 @@

namespace IronRuby.Builtins {

public partial class RubyObject : IDynamicMetaObjectProvider {
public partial class RubyObject : IRubyDynamicMetaObjectProvider {
public virtual DynamicMetaObject/*!*/ GetMetaObject(Expression/*!*/ parameter) {
return new Meta(parameter, BindingRestrictions.Empty, this);
}
Expand Down
16 changes: 10 additions & 6 deletions Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/SourceUnitTree.cs
Expand Up @@ -115,6 +115,10 @@ public partial class SourceUnitTree : Node {
moduleVariable = null;
}

if (_statements.Count == 0) {
return Ast.Lambda<T>(AstUtils.Constant(null), parameters);
}

gen.EnterSourceUnit(
scope,
selfVariable,
Expand Down Expand Up @@ -198,14 +202,14 @@ public partial class SourceUnitTree : Node {
body = gen.AddReturnTarget(scope.CreateScope(body));
gen.LeaveSourceUnit();

return Ast.Lambda<T>(
body,
RubyExceptionData.EncodeMethodName(gen.SourceUnit, RubyExceptionData.TopLevelMethodName, SourceSpan.None),
parameters
);
return Ast.Lambda<T>(body, GetEncodedName(gen), parameters);
}

private static string/*!*/ GetEncodedName(AstGenerator/*!*/ gen) {
return RubyExceptionData.EncodeMethodName(gen.SourceUnit, RubyExceptionData.TopLevelMethodName, SourceSpan.None);
}

private static MSA.Expression GenerateCheckForAsyncException(ScopeBuilder scope, MSA.Expression runtimeScopeVariable, MSA.Expression body) {
private static MSA.Expression/*!*/ GenerateCheckForAsyncException(ScopeBuilder scope, MSA.Expression runtimeScopeVariable, MSA.Expression body) {
MSA.ParameterExpression exception = scope.DefineHiddenVariable("#exception", typeof(System.Threading.ThreadAbortException));
MSA.CatchBlock handler = Ast.Catch(exception,
Ast.Call(
Expand Down

0 comments on commit 23b77ff

Please sign in to comment.