PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/Languages/Ruby/Ruby/Runtime/RubyOps.cs

http://github.com/IronLanguages/main
C# | 2621 lines | 1994 code | 460 blank | 167 comment | 311 complexity | 19eed4a4fce24d966cf24f60439c7fa4 MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. #if FEATURE_CORE_DLR
  16. using MSA = System.Linq.Expressions;
  17. #else
  18. using MSA = Microsoft.Scripting.Ast;
  19. #endif
  20. using System;
  21. using System.Collections;
  22. using System.Collections.Generic;
  23. using System.Diagnostics;
  24. using System.Dynamic;
  25. using System.Globalization;
  26. using System.IO;
  27. using System.Reflection;
  28. using System.Runtime.CompilerServices;
  29. using System.Runtime.Serialization;
  30. using System.Threading;
  31. using IronRuby.Builtins;
  32. using IronRuby.Compiler;
  33. using IronRuby.Compiler.Generation;
  34. using IronRuby.Runtime.Calls;
  35. using Microsoft.Scripting;
  36. using Microsoft.Scripting.Interpreter;
  37. using Microsoft.Scripting.Math;
  38. using Microsoft.Scripting.Runtime;
  39. using Microsoft.Scripting.Utils;
  40. using IronRuby.Compiler.Ast;
  41. using IronRuby.Runtime.Conversions;
  42. namespace IronRuby.Runtime {
  43. [ReflectionCached, CLSCompliant(false)]
  44. public static partial class RubyOps {
  45. [Emitted]
  46. public static readonly object DefaultArgument = new object();
  47. // Returned by a virtual site if a base call should be performed.
  48. [Emitted]
  49. public static readonly object ForwardToBase = new object();
  50. // an instance of a dummy type that causes any rule based on instance type check to fail
  51. private sealed class _NeedsUpdate {
  52. }
  53. [Emitted]
  54. public static readonly object NeedsUpdate = new _NeedsUpdate();
  55. #region Scopes
  56. [Emitted]
  57. public static MutableTuple GetLocals(RubyScope/*!*/ scope) {
  58. return scope.Locals;
  59. }
  60. [Emitted]
  61. public static MutableTuple GetParentLocals(RubyScope/*!*/ scope) {
  62. return scope.Parent.Locals;
  63. }
  64. [Emitted]
  65. public static RubyScope/*!*/ GetParentScope(RubyScope/*!*/ scope) {
  66. return scope.Parent;
  67. }
  68. [Emitted]
  69. public static Proc GetMethodBlockParameter(RubyScope/*!*/ scope) {
  70. var methodScope = scope.GetInnerMostMethodScope();
  71. return methodScope != null ? methodScope.BlockParameter : null;
  72. }
  73. [Emitted]
  74. public static object GetMethodBlockParameterSelf(RubyScope/*!*/ scope) {
  75. Proc proc = scope.GetInnerMostMethodScope().BlockParameter;
  76. Debug.Assert(proc != null, "CreateBfcForYield is called before this method and it checks non-nullity");
  77. return proc.Self;
  78. }
  79. [Emitted]
  80. public static object GetProcSelf(Proc/*!*/ proc) {
  81. return proc.Self;
  82. }
  83. [Emitted]
  84. public static int GetProcArity(Proc/*!*/ proc) {
  85. return proc.Dispatcher.Arity;
  86. }
  87. [Emitted]
  88. public static void InitializeScope(RubyScope/*!*/ scope, MutableTuple locals, string[] variableNames,
  89. InterpretedFrame interpretedFrame) {
  90. if (!scope.LocalsInitialized) {
  91. scope.SetLocals(locals, variableNames ?? ArrayUtils.EmptyStrings);
  92. }
  93. scope.InterpretedFrame = interpretedFrame;
  94. }
  95. [Emitted]
  96. public static void InitializeScopeNoLocals(RubyScope/*!*/ scope, InterpretedFrame interpretedFrame) {
  97. scope.InterpretedFrame = interpretedFrame;
  98. }
  99. [Emitted]
  100. public static void SetDataConstant(RubyScope/*!*/ scope, string/*!*/ dataPath, int dataOffset) {
  101. Debug.Assert(dataOffset >= 0);
  102. RubyFile dataFile;
  103. RubyContext context = scope.RubyContext;
  104. if (context.DomainManager.Platform.FileExists(dataPath)) {
  105. dataFile = new RubyFile(context, dataPath, IOMode.ReadOnly);
  106. dataFile.Seek(dataOffset, SeekOrigin.Begin);
  107. } else {
  108. dataFile = null;
  109. }
  110. context.ObjectClass.SetConstant("DATA", dataFile);
  111. }
  112. [Emitted]
  113. public static RubyModuleScope/*!*/ CreateModuleScope(MutableTuple locals, string[] variableNames,
  114. RubyScope/*!*/ parent, RubyModule/*!*/ module) {
  115. if (parent.RubyContext != module.Context) {
  116. throw RubyExceptions.CreateTypeError("Cannot open a module `{0}' defined in a foreign runtime #{1}", module.Name, module.Context.RuntimeId);
  117. }
  118. RubyModuleScope scope = new RubyModuleScope(parent, module);
  119. scope.SetDebugName((module.IsClass ? "class" : "module") + " " + module.Name);
  120. scope.SetLocals(locals, variableNames ?? ArrayUtils.EmptyStrings);
  121. return scope;
  122. }
  123. [Emitted]
  124. public static RubyMethodScope/*!*/ CreateMethodScope(MutableTuple locals, string[] variableNames, int visibleParameterCount,
  125. RubyScope/*!*/ parentScope, RubyModule/*!*/ declaringModule, string/*!*/ definitionName,
  126. object selfObject, Proc blockParameter, InterpretedFrame interpretedFrame) {
  127. return new RubyMethodScope(
  128. locals, variableNames ?? ArrayUtils.EmptyStrings, visibleParameterCount,
  129. parentScope, declaringModule, definitionName, selfObject, blockParameter,
  130. interpretedFrame
  131. );
  132. }
  133. [Emitted]
  134. public static RubyScope/*!*/ CreateFileInitializerScope(MutableTuple locals, string[] variableNames, RubyScope/*!*/ parent) {
  135. return new RubyFileInitializerScope(locals, variableNames ?? ArrayUtils.EmptyStrings, parent);
  136. }
  137. [Emitted]
  138. public static RubyBlockScope/*!*/ CreateBlockScope(MutableTuple locals, string[] variableNames,
  139. BlockParam/*!*/ blockParam, object selfObject, InterpretedFrame interpretedFrame) {
  140. return new RubyBlockScope(locals, variableNames ?? ArrayUtils.EmptyStrings, blockParam, selfObject, interpretedFrame);
  141. }
  142. [Emitted]
  143. public static void TraceMethodCall(RubyMethodScope/*!*/ scope, string fileName, int lineNumber) {
  144. // MRI:
  145. // Reports DeclaringModule even though an aliased method in a sub-module is called.
  146. // Also works for singleton module-function, which shares DeclaringModule with instance module-function.
  147. RubyModule module = scope.DeclaringModule;
  148. scope.RubyContext.ReportTraceEvent("call", scope, module, scope.DefinitionName, fileName, lineNumber);
  149. }
  150. [Emitted]
  151. public static void TraceMethodReturn(RubyMethodScope/*!*/ scope, string fileName, int lineNumber) {
  152. RubyModule module = scope.DeclaringModule;
  153. scope.RubyContext.ReportTraceEvent("return", scope, module, scope.DefinitionName, fileName, lineNumber);
  154. }
  155. [Emitted]
  156. public static void TraceBlockCall(RubyBlockScope/*!*/ scope, BlockParam/*!*/ block, string fileName, int lineNumber) {
  157. var method = block.Proc.Method;
  158. if (method != null) {
  159. scope.RubyContext.ReportTraceEvent("call", scope, method.DeclaringModule, method.DefinitionName, fileName, lineNumber);
  160. }
  161. }
  162. [Emitted]
  163. public static void TraceBlockReturn(RubyBlockScope/*!*/ scope, BlockParam/*!*/ block, string fileName, int lineNumber) {
  164. var method = block.Proc.Method;
  165. if (method != null) {
  166. scope.RubyContext.ReportTraceEvent("return", scope, method.DeclaringModule, method.DefinitionName, fileName, lineNumber);
  167. }
  168. }
  169. [Emitted]
  170. public static void PrintInteractiveResult(RubyScope/*!*/ scope, MutableString/*!*/ value) {
  171. var writer = scope.RubyContext.DomainManager.SharedIO.OutputStream;
  172. writer.WriteByte((byte)'=');
  173. writer.WriteByte((byte)'>');
  174. writer.WriteByte((byte)' ');
  175. var bytes = value.ToByteArray();
  176. writer.Write(bytes, 0, bytes.Length);
  177. writer.WriteByte((byte)'\r');
  178. writer.WriteByte((byte)'\n');
  179. }
  180. [Emitted]
  181. public static object GetLocalVariable(RubyScope/*!*/ scope, string/*!*/ name) {
  182. return scope.ResolveLocalVariable(name);
  183. }
  184. [Emitted]
  185. public static object SetLocalVariable(object value, RubyScope/*!*/ scope, string/*!*/ name) {
  186. return scope.ResolveAndSetLocalVariable(name, value);
  187. }
  188. [Emitted]
  189. public static VersionHandle/*!*/ GetSelfClassVersionHandle(RubyScope/*!*/ scope) {
  190. return scope.SelfImmediateClass.Version;
  191. }
  192. #endregion
  193. #region Context
  194. [Emitted]
  195. public static RubyContext/*!*/ GetContextFromModule(RubyModule/*!*/ module) {
  196. return module.Context;
  197. }
  198. [Emitted]
  199. public static RubyContext/*!*/ GetContextFromIRubyObject(IRubyObject/*!*/ obj) {
  200. return obj.ImmediateClass.Context;
  201. }
  202. [Emitted]
  203. public static RubyContext/*!*/ GetContextFromScope(RubyScope/*!*/ scope) {
  204. return scope.RubyContext;
  205. }
  206. [Emitted]
  207. public static RubyContext/*!*/ GetContextFromMethod(RubyMethod/*!*/ method) {
  208. return method.Info.Context;
  209. }
  210. [Emitted]
  211. public static RubyContext/*!*/ GetContextFromBlockParam(BlockParam/*!*/ block) {
  212. return block.RubyContext;
  213. }
  214. [Emitted]
  215. public static RubyContext/*!*/ GetContextFromProc(Proc/*!*/ proc) {
  216. return proc.LocalScope.RubyContext;
  217. }
  218. [Emitted]
  219. public static RubyScope/*!*/ GetEmptyScope(RubyContext/*!*/ context) {
  220. return context.EmptyScope;
  221. }
  222. [Emitted]
  223. public static Scope/*!*/ GetGlobalScopeFromScope(RubyScope/*!*/ scope) {
  224. return scope.GlobalScope.Scope;
  225. }
  226. #endregion
  227. #region Blocks
  228. [Emitted]
  229. public static Proc InstantiateBlock(RubyScope/*!*/ scope, object self, BlockDispatcher/*!*/ dispatcher) {
  230. return (dispatcher.Method != null) ? new Proc(ProcKind.Block, self, scope, dispatcher) : null;
  231. }
  232. [Emitted]
  233. public static Proc InstantiateLambda(RubyScope/*!*/ scope, object self, BlockDispatcher/*!*/ dispatcher) {
  234. return (dispatcher.Method != null) ? new Proc(ProcKind.Lambda, self, scope, dispatcher) : null;
  235. }
  236. [Emitted]
  237. public static Proc/*!*/ DefineBlock(RubyScope/*!*/ scope, object self, BlockDispatcher/*!*/ dispatcher, object/*!*/ clrMethod) {
  238. #if !WIN8
  239. // DLR closures should not be used:
  240. Debug.Assert(!(((Delegate)clrMethod).Target is Closure) || ((Closure)((Delegate)clrMethod).Target).Locals == null);
  241. #endif
  242. return new Proc(ProcKind.Block, self, scope, dispatcher.SetMethod(clrMethod));
  243. }
  244. [Emitted]
  245. public static Proc/*!*/ DefineLambda(RubyScope/*!*/ scope, object self, BlockDispatcher/*!*/ dispatcher, object/*!*/ clrMethod) {
  246. #if !WIN8
  247. // DLR closures should not be used:
  248. Debug.Assert(!(((Delegate)clrMethod).Target is Closure) || ((Closure)((Delegate)clrMethod).Target).Locals == null);
  249. #endif
  250. return new Proc(ProcKind.Lambda, self, scope, dispatcher.SetMethod(clrMethod));
  251. }
  252. /// <summary>
  253. /// Used in a method call with a block to reset proc-kind when the call is retried
  254. /// </summary>
  255. [Emitted]
  256. public static void InitializeBlock(Proc/*!*/ proc) {
  257. Assert.NotNull(proc);
  258. proc.Kind = ProcKind.Block;
  259. }
  260. /// <summary>
  261. /// Implements END block - like if it was a call to at_exit { ... } library method.
  262. /// </summary>
  263. [Emitted]
  264. public static void RegisterShutdownHandler(Proc/*!*/ proc) {
  265. proc.LocalScope.RubyContext.RegisterShutdownHandler(proc);
  266. }
  267. #endregion
  268. #region Yield: TODO: generate
  269. [Emitted]
  270. public static object Yield0(Proc procArg, object self, BlockParam/*!*/ blockParam) {
  271. object result;
  272. var proc = blockParam.Proc;
  273. try {
  274. result = proc.Dispatcher.Invoke(blockParam, self, procArg);
  275. } catch(EvalUnwinder evalUnwinder) {
  276. result = blockParam.GetUnwinderResult(evalUnwinder);
  277. }
  278. return result;
  279. }
  280. [Emitted]
  281. public static object Yield1(object arg1, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  282. object result;
  283. var proc = blockParam.Proc;
  284. try {
  285. result = proc.Dispatcher.Invoke(blockParam, self, procArg, arg1);
  286. } catch (EvalUnwinder evalUnwinder) {
  287. result = blockParam.GetUnwinderResult(evalUnwinder);
  288. }
  289. return result;
  290. }
  291. // YieldNoAutoSplat1 uses InvokeNoAutoSplat instead of Invoke (used by Call1)
  292. internal static object YieldNoAutoSplat1(object arg1, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  293. object result;
  294. var proc = blockParam.Proc;
  295. try {
  296. result = proc.Dispatcher.InvokeNoAutoSplat(blockParam, self, procArg, arg1);
  297. } catch (EvalUnwinder evalUnwinder) {
  298. result = blockParam.GetUnwinderResult(evalUnwinder);
  299. }
  300. return result;
  301. }
  302. [Emitted]
  303. public static object Yield2(object arg1, object arg2, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  304. object result;
  305. var proc = blockParam.Proc;
  306. try {
  307. result = proc.Dispatcher.Invoke(blockParam, self, procArg, arg1, arg2);
  308. } catch (EvalUnwinder evalUnwinder) {
  309. result = blockParam.GetUnwinderResult(evalUnwinder);
  310. }
  311. return result;
  312. }
  313. [Emitted]
  314. public static object Yield3(object arg1, object arg2, object arg3, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  315. object result;
  316. var proc = blockParam.Proc;
  317. try {
  318. result = proc.Dispatcher.Invoke(blockParam, self, procArg, arg1, arg2, arg3);
  319. } catch (EvalUnwinder evalUnwinder) {
  320. result = blockParam.GetUnwinderResult(evalUnwinder);
  321. }
  322. return result;
  323. }
  324. [Emitted]
  325. public static object Yield4(object arg1, object arg2, object arg3, object arg4, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  326. object result;
  327. var proc = blockParam.Proc;
  328. try {
  329. result = proc.Dispatcher.Invoke(blockParam, self, procArg, arg1, arg2, arg3, arg4);
  330. } catch (EvalUnwinder evalUnwinder) {
  331. result = blockParam.GetUnwinderResult(evalUnwinder);
  332. }
  333. return result;
  334. }
  335. [Emitted]
  336. public static object YieldN(object[]/*!*/ args, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  337. Debug.Assert(args.Length > BlockDispatcher.MaxBlockArity);
  338. object result;
  339. var proc = blockParam.Proc;
  340. try {
  341. result = proc.Dispatcher.Invoke(blockParam, self, procArg, args);
  342. } catch (EvalUnwinder evalUnwinder) {
  343. result = blockParam.GetUnwinderResult(evalUnwinder);
  344. }
  345. return result;
  346. }
  347. internal static object Yield(object[]/*!*/ args, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  348. switch (args.Length) {
  349. case 0: return RubyOps.Yield0(procArg, self, blockParam);
  350. case 1: return RubyOps.Yield1(args[0], procArg, self, blockParam);
  351. case 2: return RubyOps.Yield2(args[0], args[1], procArg, self, blockParam);
  352. case 3: return RubyOps.Yield3(args[0], args[1], args[2], procArg, self, blockParam);
  353. case 4: return RubyOps.Yield4(args[0], args[1], args[2], args[3], procArg, self, blockParam);
  354. default: return RubyOps.YieldN(args, procArg, self, blockParam);
  355. }
  356. }
  357. [Emitted]
  358. public static object YieldSplat0(IList/*!*/ splattee, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  359. object result;
  360. var proc = blockParam.Proc;
  361. try {
  362. result = proc.Dispatcher.InvokeSplat(blockParam, self, procArg, splattee);
  363. } catch (EvalUnwinder evalUnwinder) {
  364. result = blockParam.GetUnwinderResult(evalUnwinder);
  365. }
  366. return result;
  367. }
  368. [Emitted]
  369. public static object YieldSplat1(object arg1, IList/*!*/ splattee, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  370. object result;
  371. var proc = blockParam.Proc;
  372. try {
  373. result = proc.Dispatcher.InvokeSplat(blockParam, self, procArg, arg1, splattee);
  374. } catch (EvalUnwinder evalUnwinder) {
  375. result = blockParam.GetUnwinderResult(evalUnwinder);
  376. }
  377. return result;
  378. }
  379. [Emitted]
  380. public static object YieldSplat2(object arg1, object arg2, IList/*!*/ splattee, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  381. object result;
  382. var proc = blockParam.Proc;
  383. try {
  384. result = proc.Dispatcher.InvokeSplat(blockParam, self, procArg, arg1, arg2, splattee);
  385. } catch (EvalUnwinder evalUnwinder) {
  386. result = blockParam.GetUnwinderResult(evalUnwinder);
  387. }
  388. return result;
  389. }
  390. [Emitted]
  391. public static object YieldSplat3(object arg1, object arg2, object arg3, IList/*!*/ splattee, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  392. object result;
  393. var proc = blockParam.Proc;
  394. try {
  395. result = proc.Dispatcher.InvokeSplat(blockParam, self, procArg, arg1, arg2, arg3, splattee);
  396. } catch (EvalUnwinder evalUnwinder) {
  397. result = blockParam.GetUnwinderResult(evalUnwinder);
  398. }
  399. return result;
  400. }
  401. [Emitted]
  402. public static object YieldSplat4(object arg1, object arg2, object arg3, object arg4, IList/*!*/ splattee, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  403. object result;
  404. var proc = blockParam.Proc;
  405. try {
  406. result = proc.Dispatcher.InvokeSplat(blockParam, self, procArg, arg1, arg2, arg3, arg4, splattee);
  407. } catch (EvalUnwinder evalUnwinder) {
  408. result = blockParam.GetUnwinderResult(evalUnwinder);
  409. }
  410. return result;
  411. }
  412. [Emitted]
  413. public static object YieldSplatN(object[]/*!*/ args, IList/*!*/ splattee, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  414. object result;
  415. var proc = blockParam.Proc;
  416. try {
  417. result = proc.Dispatcher.InvokeSplat(blockParam, self, procArg, args, splattee);
  418. } catch (EvalUnwinder evalUnwinder) {
  419. result = blockParam.GetUnwinderResult(evalUnwinder);
  420. }
  421. return result;
  422. }
  423. [Emitted]
  424. public static object YieldSplatNRhs(object[]/*!*/ args, IList/*!*/ splattee, object rhs, Proc procArg, object self, BlockParam/*!*/ blockParam) {
  425. object result;
  426. var proc = blockParam.Proc;
  427. try {
  428. result = proc.Dispatcher.InvokeSplatRhs(blockParam, self, procArg, args, splattee, rhs);
  429. } catch (EvalUnwinder evalUnwinder) {
  430. result = blockParam.GetUnwinderResult(evalUnwinder);
  431. }
  432. return result;
  433. }
  434. #endregion
  435. #region Methods
  436. [Emitted] // MethodDeclaration:
  437. public static object DefineMethod(object target, RubyScope/*!*/ scope, RubyMethodBody/*!*/ body) {
  438. Assert.NotNull(body, scope);
  439. RubyModule instanceOwner, singletonOwner;
  440. RubyMemberFlags instanceFlags, singletonFlags;
  441. bool moduleFunction = false;
  442. if (body.HasTarget) {
  443. if (!RubyUtils.CanDefineSingletonMethod(target)) {
  444. throw RubyExceptions.CreateTypeError("can't define singleton method for literals");
  445. }
  446. instanceOwner = null;
  447. instanceFlags = RubyMemberFlags.Invalid;
  448. singletonOwner = scope.RubyContext.GetOrCreateSingletonClass(target);
  449. singletonFlags = RubyMemberFlags.Public;
  450. } else {
  451. var attributesScope = scope.GetMethodAttributesDefinitionScope();
  452. if ((attributesScope.MethodAttributes & RubyMethodAttributes.ModuleFunction) == RubyMethodAttributes.ModuleFunction) {
  453. // Singleton module-function's scope points to the instance method's RubyMemberInfo.
  454. // This affects:
  455. // 1) super call
  456. // Super call is looking for Method.DeclaringModule while searching MRO, which would fail if the singleton module-function
  457. // was in MRO. Since module-function can only be used on module the singleton method could only be on module's singleton.
  458. // Module's singleton is never part of MRO so we are safe.
  459. // 2) trace
  460. // Method call trace reports non-singleton module.
  461. // MRI 1.8: instance method owner is self -> it is possible (via define_method) to define m.f. on a class (bug)
  462. // MRI 1.9: instance method owner GetMethodDefinitionOwner
  463. // MRI allows to define m.f. on classes but then doesn't work correctly with it.
  464. instanceOwner = scope.GetMethodDefinitionOwner();
  465. if (instanceOwner.IsClass) {
  466. throw RubyExceptions.CreateTypeError("A module function cannot be defined on a class.");
  467. }
  468. instanceFlags = RubyMemberFlags.Private;
  469. singletonOwner = instanceOwner.GetOrCreateSingletonClass();
  470. singletonFlags = RubyMemberFlags.Public;
  471. moduleFunction = true;
  472. } else {
  473. instanceOwner = scope.GetMethodDefinitionOwner();
  474. instanceFlags = (RubyMemberFlags)RubyUtils.GetSpecialMethodVisibility(attributesScope.Visibility, body.Name);
  475. singletonOwner = null;
  476. singletonFlags = RubyMemberFlags.Invalid;
  477. }
  478. }
  479. RubyMethodInfo instanceMethod = null, singletonMethod = null;
  480. if (instanceOwner != null) {
  481. SetMethod(scope.RubyContext, instanceMethod =
  482. new RubyMethodInfo(body, scope, instanceOwner, instanceFlags)
  483. );
  484. }
  485. if (singletonOwner != null) {
  486. SetMethod(scope.RubyContext, singletonMethod =
  487. new RubyMethodInfo(body, scope, singletonOwner, singletonFlags)
  488. );
  489. }
  490. // the method's scope saves the result => singleton module-function uses instance-method
  491. var method = instanceMethod ?? singletonMethod;
  492. method.DeclaringModule.MethodAdded(body.Name);
  493. if (moduleFunction) {
  494. Debug.Assert(!method.DeclaringModule.IsClass);
  495. method.DeclaringModule.GetOrCreateSingletonClass().MethodAdded(body.Name);
  496. }
  497. return null;
  498. }
  499. private static void SetMethod(RubyContext/*!*/ callerContext, RubyMethodInfo/*!*/ method) {
  500. var owner = method.DeclaringModule;
  501. // Do not trigger the add-method event just yet, we need to assign the result into closure before executing any user code.
  502. // If the method being defined is "method_added" itself, we would call that method before the info gets assigned to the closure.
  503. owner.SetMethodNoEvent(callerContext, method.DefinitionName, method);
  504. // expose RubyMethod in the scope (the method is bound to the main singleton instance):
  505. if (owner.GlobalScope != null) {
  506. RubyOps.ScopeSetMember(
  507. owner.GlobalScope.Scope,
  508. method.DefinitionName,
  509. new RubyMethod(owner.GlobalScope.MainObject, method, method.DefinitionName)
  510. );
  511. }
  512. }
  513. [Emitted] // AliasStatement:
  514. public static void AliasMethod(RubyScope/*!*/ scope, string/*!*/ newName, string/*!*/ oldName) {
  515. scope.GetMethodDefinitionOwner().AddMethodAlias(newName, oldName);
  516. }
  517. [Emitted] // UndefineMethod:
  518. public static void UndefineMethod(RubyScope/*!*/ scope, string/*!*/ name) {
  519. RubyModule owner = scope.GetMethodDefinitionOwner();
  520. if (!owner.ResolveMethod(name, VisibilityContext.AllVisible).Found) {
  521. throw RubyExceptions.CreateUndefinedMethodError(owner, name);
  522. }
  523. owner.UndefineMethod(name);
  524. }
  525. #endregion
  526. #region Modules
  527. [Emitted]
  528. public static RubyModule/*!*/ DefineGlobalModule(RubyScope/*!*/ scope, string/*!*/ name) {
  529. return DefineModule(scope, scope.Top.TopModuleOrObject, name);
  530. }
  531. [Emitted]
  532. public static RubyModule/*!*/ DefineNestedModule(RubyScope/*!*/ scope, string/*!*/ name) {
  533. return DefineModule(scope, scope.GetInnerMostModuleForConstantLookup(), name);
  534. }
  535. [Emitted]
  536. public static RubyModule/*!*/ DefineModule(RubyScope/*!*/ scope, object target, string/*!*/ name) {
  537. return DefineModule(scope, RubyUtils.GetModuleFromObject(scope, target), name);
  538. }
  539. // thread-safe:
  540. private static RubyModule/*!*/ DefineModule(RubyScope/*!*/ scope, RubyModule/*!*/ owner, string/*!*/ name) {
  541. Assert.NotNull(scope, owner);
  542. ConstantStorage existing;
  543. if (owner.TryGetConstant(scope.GlobalScope, name, out existing)) {
  544. RubyModule module = existing.Value as RubyModule;
  545. if (module == null || module.IsClass) {
  546. throw RubyExceptions.CreateTypeError(String.Format("{0} is not a module", name));
  547. }
  548. return module;
  549. } else {
  550. // create class/module object:
  551. return owner.Context.DefineModule(owner, name);
  552. }
  553. }
  554. #endregion
  555. #region Classes
  556. [Emitted]
  557. public static RubyClass/*!*/ DefineSingletonClass(RubyScope/*!*/ scope, object obj) {
  558. if (!RubyUtils.HasSingletonClass(obj)) {
  559. throw RubyExceptions.CreateTypeError(String.Format("no virtual class for {0}", scope.RubyContext.GetClassOf(obj).Name));
  560. }
  561. return scope.RubyContext.GetOrCreateSingletonClass(obj);
  562. }
  563. [Emitted]
  564. public static RubyModule/*!*/ DefineGlobalClass(RubyScope/*!*/ scope, string/*!*/ name, object superClassObject) {
  565. return DefineClass(scope, scope.Top.TopModuleOrObject, name, superClassObject);
  566. }
  567. [Emitted]
  568. public static RubyModule/*!*/ DefineNestedClass(RubyScope/*!*/ scope, string/*!*/ name, object superClassObject) {
  569. return DefineClass(scope, scope.GetInnerMostModuleForConstantLookup(), name, superClassObject);
  570. }
  571. [Emitted]
  572. public static RubyModule/*!*/ DefineClass(RubyScope/*!*/ scope, object target, string/*!*/ name, object superClassObject) {
  573. return DefineClass(scope, RubyUtils.GetModuleFromObject(scope, target), name, superClassObject);
  574. }
  575. // thread-safe:
  576. private static RubyClass/*!*/ DefineClass(RubyScope/*!*/ scope, RubyModule/*!*/ owner, string/*!*/ name, object superClassObject) {
  577. Assert.NotNull(owner);
  578. RubyClass superClass = ToSuperClass(owner.Context, superClassObject);
  579. ConstantStorage existing;
  580. if (owner.IsObjectClass
  581. ? owner.TryResolveConstant(scope.GlobalScope, name, out existing)
  582. : owner.TryGetConstant(scope.GlobalScope, name, out existing)) {
  583. RubyClass cls = existing.Value as RubyClass;
  584. if (cls == null || !cls.IsClass) {
  585. throw RubyExceptions.CreateTypeError("{0} is not a class", name);
  586. }
  587. if (superClassObject != null && !ReferenceEquals(cls.SuperClass, superClass)) {
  588. throw RubyExceptions.CreateTypeError("superclass mismatch for class {0}", name);
  589. }
  590. return cls;
  591. } else {
  592. return owner.Context.DefineClass(owner, name, superClass, null);
  593. }
  594. }
  595. private static RubyClass/*!*/ ToSuperClass(RubyContext/*!*/ ec, object superClassObject) {
  596. if (superClassObject != null) {
  597. RubyClass superClass = superClassObject as RubyClass;
  598. if (superClass == null) {
  599. throw RubyExceptions.CreateTypeError("superclass must be a Class ({0} given)", ec.GetClassOf(superClassObject).Name);
  600. }
  601. if (superClass.IsSingletonClass) {
  602. throw RubyExceptions.CreateTypeError("can't make subclass of virtual class");
  603. }
  604. return superClass;
  605. } else {
  606. return ec.ObjectClass;
  607. }
  608. }
  609. #endregion
  610. #region Constants
  611. /// <summary>
  612. /// A
  613. /// ::A
  614. /// </summary>
  615. [Emitted]
  616. public static object GetUnqualifiedConstant(RubyScope/*!*/ scope, ConstantSiteCache/*!*/ cache, string/*!*/ name, bool isGlobal) {
  617. object result = null;
  618. RubyModule missingConstantOwner;
  619. var context = scope.RubyContext;
  620. using (context.ClassHierarchyLocker()) {
  621. // Thread safety:
  622. // Another thread could have already updated the value, so the site version might be the same as CAV.
  623. // We do the lookup anyways since it is no-op and this only happens rarely.
  624. //
  625. // An important invariant holds here: in any time after initialized for the first time the Value field contains a valid value.
  626. // Threads can read an older value (the previous version) but that is still correct since we don't guarantee immediate
  627. // propagation of the constant write to all readers.
  628. //
  629. // if (site.Version = CAV) {
  630. // <- another thread could increment CAV here - we may return old or new value (both are ok)
  631. // value = site.Value;
  632. // } else {
  633. // <- another thread could get here as well and update the site before we get to update it.
  634. // GetConstant(...)
  635. // }
  636. // Constants might be updated during constant resolution due to autoload.
  637. // Any such updates need to invalidate the cache hence we need to capture the version before resolving the constant.
  638. int newVersion = context.ConstantAccessVersion;
  639. ConstantStorage storage;
  640. if (!isGlobal) {
  641. missingConstantOwner = scope.TryResolveConstantNoLock(scope.GlobalScope, name, out storage);
  642. } else if (context.ObjectClass.TryResolveConstantNoLock(scope.GlobalScope, name, out storage)) {
  643. missingConstantOwner = null;
  644. } else {
  645. missingConstantOwner = context.ObjectClass;
  646. }
  647. object newCacheValue;
  648. if (missingConstantOwner == null) {
  649. if (storage.WeakValue != null) {
  650. result = storage.Value;
  651. newCacheValue = storage.WeakValue;
  652. } else {
  653. result = newCacheValue = storage.Value;
  654. }
  655. } else {
  656. newCacheValue = ConstantSiteCache.WeakMissingConstant;
  657. }
  658. cache.Update(newCacheValue, newVersion);
  659. }
  660. if (missingConstantOwner != null) {
  661. result = missingConstantOwner.ConstantMissing(name);
  662. }
  663. return result;
  664. }
  665. /// <summary>
  666. /// A1::..::AN
  667. /// ::A1::..::AN
  668. /// </summary>
  669. [Emitted]
  670. public static object GetQualifiedConstant(RubyScope/*!*/ scope, ConstantSiteCache/*!*/ cache, string/*!*/[]/*!*/ qualifiedName, bool isGlobal) {
  671. var globalScope = scope.GlobalScope;
  672. var context = globalScope.Context;
  673. using (context.ClassHierarchyLocker()) {
  674. int newVersion = context.ConstantAccessVersion;
  675. ConstantStorage storage;
  676. bool anyMissing;
  677. RubyModule topModule = isGlobal ? context.ObjectClass : null;
  678. object result = ResolveQualifiedConstant(scope, qualifiedName, topModule, true, out storage, out anyMissing);
  679. // cache result only if no constant was missing:
  680. if (!anyMissing) {
  681. Debug.Assert(result == storage.Value);
  682. cache.Update(storage.WeakValue ?? result, newVersion);
  683. }
  684. return result;
  685. }
  686. }
  687. /// <summary>
  688. /// {expr}::A1::..::AN
  689. /// </summary>
  690. [Emitted]
  691. public static object GetExpressionQualifiedConstant(object target, RubyScope/*!*/ scope, ExpressionQualifiedConstantSiteCache/*!*/ cache,
  692. string/*!*/[]/*!*/ qualifiedName) {
  693. RubyModule module = target as RubyModule;
  694. if (module == null) {
  695. throw RubyUtils.CreateNotModuleException(scope, target);
  696. }
  697. var condition = cache.Condition;
  698. RubyContext context = module.Context;
  699. // Note that the module can be bound to another runtime:
  700. if (module.Id == condition.ModuleId && context.ConstantAccessVersion == condition.Version) {
  701. object value = cache.Value;
  702. if (value.GetType() == typeof(WeakReference)) {
  703. return ((WeakReference)value).Target;
  704. } else {
  705. return value;
  706. }
  707. }
  708. using (context.ClassHierarchyLocker()) {
  709. int newVersion = context.ConstantAccessVersion;
  710. ConstantStorage storage;
  711. bool anyMissing;
  712. object result = ResolveQualifiedConstant(scope, qualifiedName, module, true, out storage, out anyMissing);
  713. // cache result only if no constant was missing:
  714. if (!anyMissing) {
  715. Debug.Assert(result == storage.Value);
  716. cache.Update(storage.WeakValue ?? result, newVersion, module);
  717. }
  718. return result;
  719. }
  720. }
  721. /// <summary>
  722. /// defined? A
  723. /// </summary>
  724. [Emitted]
  725. public static bool IsDefinedUnqualifiedConstant(RubyScope/*!*/ scope, IsDefinedConstantSiteCache/*!*/ cache, string/*!*/ name) {
  726. var context = scope.RubyContext;
  727. using (context.ClassHierarchyLocker()) {
  728. int newVersion = context.ConstantAccessVersion;
  729. ConstantStorage storage;
  730. bool exists = scope.TryResolveConstantNoLock(null, name, out storage) == null;
  731. cache.Update(exists, newVersion);
  732. return exists;
  733. }
  734. }
  735. /// <summary>
  736. /// defined? ::A
  737. /// </summary>
  738. [Emitted]
  739. public static bool IsDefinedGlobalConstant(RubyScope/*!*/ scope, IsDefinedConstantSiteCache/*!*/ cache, string/*!*/ name) {
  740. var context = scope.RubyContext;
  741. using (context.ClassHierarchyLocker()) {
  742. int newVersion = context.ConstantAccessVersion;
  743. ConstantStorage storage;
  744. bool exists = context.ObjectClass.TryResolveConstantNoLock(null, name, out storage);
  745. cache.Update(exists, newVersion);
  746. return exists;
  747. }
  748. }
  749. /// <summary>
  750. /// defined? A1::..::AN
  751. /// defined? ::A1::..::AN
  752. /// </summary>
  753. [Emitted]
  754. public static bool IsDefinedQualifiedConstant(RubyScope/*!*/ scope, IsDefinedConstantSiteCache/*!*/ cache,
  755. string/*!*/[]/*!*/ qualifiedName, bool isGlobal) {
  756. var context = scope.RubyContext;
  757. using (context.ClassHierarchyLocker()) {
  758. int newVersion = context.ConstantAccessVersion;
  759. ConstantStorage storage;
  760. bool anyMissing;
  761. RubyModule topModule = isGlobal ? context.ObjectClass : null;
  762. RubyModule owner;
  763. try {
  764. owner = ResolveQualifiedConstant(scope, qualifiedName, topModule, false, out storage, out anyMissing) as RubyModule;
  765. } catch {
  766. // autoload can raise an exception
  767. scope.RubyContext.SetCurrentException(null);
  768. return false;
  769. }
  770. // Note that the owner could be another runtime's module:
  771. bool exists = owner != null && owner.TryResolveConstant(context, null, qualifiedName[qualifiedName.Length - 1], out storage);
  772. // cache result only if no constant was missing:
  773. if (!anyMissing) {
  774. cache.Update(exists, newVersion);
  775. }
  776. return exists;
  777. }
  778. }
  779. /// <summary>
  780. /// defined? {expr}::A
  781. /// defined? {expr}::A1::..::AN
  782. /// </summary>
  783. [Emitted]
  784. public static bool IsDefinedExpressionQualifiedConstant(object target, RubyScope/*!*/ scope,
  785. ExpressionQualifiedIsDefinedConstantSiteCache/*!*/ cache, string/*!*/[]/*!*/ qualifiedName) {
  786. RubyModule module = target as RubyModule;
  787. if (module == null) {
  788. return false;
  789. }
  790. var condition = cache.Condition;
  791. RubyContext context = module.Context;
  792. // Note that the module can be bound to another runtime:
  793. if (module.Id == condition.ModuleId && context.ConstantAccessVersion == condition.Version) {
  794. return cache.Value;
  795. }
  796. using (context.ClassHierarchyLocker()) {
  797. int newVersion = context.ConstantAccessVersion;
  798. ConstantStorage storage;
  799. bool exists;
  800. if (qualifiedName.Length == 1) {
  801. // Note that the owner could be another runtime's module:
  802. exists = module.TryResolveConstant(context, null, qualifiedName[0], out storage);
  803. } else {
  804. bool anyMissing;
  805. RubyModule owner;
  806. try {
  807. owner = ResolveQualifiedConstant(scope, qualifiedName, module, false, out storage, out anyMissing) as RubyModule;
  808. } catch {
  809. // autoload can raise an exception:
  810. return false;
  811. }
  812. // Note that the owner could be another runtime's module:
  813. exists = owner != null && owner.TryResolveConstant(context, null, qualifiedName[qualifiedName.Length - 1], out storage);
  814. // cache result only if no constant was missing:
  815. if (anyMissing) {
  816. return exists;
  817. }
  818. }
  819. cache.Update(exists, newVersion, module);
  820. return exists;
  821. }
  822. }
  823. private static object ResolveQualifiedConstant(RubyScope/*!*/ scope, string/*!*/[]/*!*/ qualifiedName, RubyModule topModule, bool isGet,
  824. out ConstantStorage storage, out bool anyMissing) {
  825. Debug.Assert(qualifiedName.Length >= 2 || qualifiedName.Length == 1 && isGet);
  826. RubyContext context = scope.RubyContext;
  827. context.RequiresClassHierarchyLock();
  828. RubyModule missingConstantOwner;
  829. RubyGlobalScope globalScope = scope.GlobalScope;
  830. int nameCount = (isGet) ? qualifiedName.Length : qualifiedName.Length - 1;
  831. string name = qualifiedName[0];
  832. if (topModule == null) {
  833. missingConstantOwner = scope.TryResolveConstantNoLock(globalScope, name, out storage);
  834. } else if (topModule.TryResolveConstant(context, globalScope, name, out storage)) {
  835. missingConstantOwner = null;
  836. } else {
  837. missingConstantOwner = topModule;
  838. }
  839. object result;
  840. if (missingConstantOwner == null) {
  841. result = storage.Value;
  842. anyMissing = false;
  843. } else {
  844. anyMissing = true;
  845. using (context.ClassHierarchyUnlocker()) {
  846. result = missingConstantOwner.ConstantMissing(name);
  847. }
  848. }
  849. for (int i = 1; i < nameCount; i++) {
  850. RubyModule owner = RubyUtils.GetModuleFromObject(scope, result);
  851. // Note that the owner could be another runtime's module:
  852. name = qualifiedName[i];
  853. if (owner.TryResolveConstant(context, globalScope, name, out storage)) {
  854. // Constant write updates constant version in a single runtime only.
  855. // Therefore if the chain mixes modules from different runtimes we cannot cache the result.
  856. if (owner.Context != context) {
  857. anyMissing = true;
  858. }
  859. result = storage.Value;
  860. } else {
  861. anyMissing = true;
  862. using (context.ClassHierarchyUnlocker()) {
  863. result = owner.ConstantMissing(name);
  864. }
  865. }
  866. }
  867. return result;
  868. }
  869. [Emitted]
  870. public static object GetMissingConstant(RubyScope/*!*/ scope, ConstantSiteCache/*!*/ cache, string/*!*/ name) {
  871. return scope.GetInnerMostModuleForConstantLookup().ConstantMissing(name);
  872. }
  873. [Emitted]
  874. public static object GetGlobalMissingConstant(RubyScope/*!*/ scope, ConstantSiteCache/*!*/ cache, string/*!*/ name) {
  875. return scope.RubyContext.ObjectClass.ConstantMissing(name);
  876. }
  877. [Emitted] // ConstantVariable:
  878. public static object SetGlobalConstant(object value, RubyScope/*!*/ scope, string/*!*/ name) {
  879. RubyUtils.SetConstant(scope.RubyContext.ObjectClass, name, value);
  880. return value;
  881. }
  882. [Emitted] // ConstantVariable:
  883. public static object SetUnqualifiedConstant(object value, RubyScope/*!*/ scope, string/*!*/ name) {
  884. RubyUtils.SetConstant(scope.GetInnerMostModuleForConstantLookup(), name, value);
  885. return value;
  886. }
  887. [Emitted] // ConstantVariable:
  888. public static object SetQualifiedConstant(object value, object target, RubyScope/*!*/ scope, string/*!*/ name) {
  889. RubyUtils.SetConstant(RubyUtils.GetModuleFromObject(scope, target), name, value);
  890. return value;
  891. }
  892. #endregion
  893. // MakeArray*
  894. public const int OptimizedOpCallParamCount = 5;
  895. #region MakeArray
  896. [Emitted]
  897. public static RubyArray/*!*/ MakeArray0() {
  898. return new RubyArray(0);
  899. }
  900. [Emitted]
  901. public static RubyArray/*!*/ MakeArray1(object item1) {
  902. RubyArray result = new RubyArray(1);
  903. result.Add(item1);
  904. return result;
  905. }
  906. [Emitted]
  907. public static RubyArray/*!*/ MakeArray2(object item1, object item2) {
  908. RubyArray result = new RubyArray(2);
  909. result.Add(item1);
  910. result.Add(item2);
  911. return result;
  912. }
  913. [Emitted]
  914. public static RubyArray/*!*/ MakeArray3(object item1, object item2, object item3) {
  915. RubyArray result = new RubyArray(3);
  916. result.Add(item1);
  917. result.Add(item2);
  918. result.Add(item3);
  919. return result;
  920. }
  921. [Emitted]
  922. public static RubyArray/*!*/ MakeArray4(object item1, object item2, object item3, object item4) {
  923. RubyArray result = new RubyArray(4);
  924. result.Add(item1);
  925. result.Add(item2);
  926. result.Add(item3);
  927. result.Add(item4);
  928. return result;
  929. }
  930. [Emitted]
  931. public static RubyArray/*!*/ MakeArray5(object item1, object item2, object item3, object item4, object item5) {
  932. RubyArray result = new RubyArray(5);
  933. result.Add(item1);
  934. result.Add(item2);
  935. result.Add(item3);
  936. result.Add(item4);
  937. result.Add(item5);
  938. return result;
  939. }
  940. [Emitted]
  941. public static RubyArray/*!*/ MakeArrayN(object[]/*!*/ items) {
  942. Debug.Assert(items != null);
  943. var array = new RubyArray(items.Length);
  944. array.AddVector(items, 0, items.Length);
  945. return array;
  946. }
  947. #endregion
  948. #region MakeHash
  949. [Emitted]
  950. public static Hash/*!*/ MakeHash0(RubyScope/*!*/ scope) {
  951. return new Hash(scope.RubyContext.EqualityComparer, 0);
  952. }
  953. [Emitted]
  954. public static Hash/*!*/ MakeHash(RubyScope/*!*/ scope, object[]/*!*/ items) {
  955. return RubyUtils.SetHashElements(scope.RubyContext, new Hash(scope.RubyContext.EqualityComparer, items.Length / 2), items);
  956. }
  957. #endregion
  958. #region Array
  959. [Emitted]
  960. public static RubyArray/*!*/ AddRange(RubyArray/*!*/ array, IList/*!*/ list) {
  961. return array.AddRange(list);
  962. }
  963. [Emitted] // method call:
  964. public static RubyArray/*!*/ AddSubRange(RubyArray/*!*/ result, IList/*!*/ array, int start, int count) {
  965. return result.AddRange(array, start, count);
  966. }
  967. [Emitted]
  968. public static RubyArray/*!*/ AddItem(RubyArray/*!*/ array, object item) {
  969. array.Add(item);
  970. return array;
  971. }
  972. [Emitted]
  973. public static IList/*!*/ SplatAppend(IList/*!*/ array, IList/*!*/ list) {
  974. Utils.AddRange(array, list);
  975. return array;
  976. }
  977. [Emitted]
  978. public static object Splat(IList/*!*/ list) {
  979. if (list.Count <= 1) {
  980. return (list.Count > 0) ? list[0] : null;
  981. }
  982. return list;
  983. }
  984. // 1.8 behavior
  985. [Emitted]
  986. public static object SplatPair(object value, IList/*!*/ list) {
  987. if (list.Count == 0) {
  988. return value;
  989. }
  990. RubyArray result = new RubyArray(list.Count + 1);
  991. result.Add(value);
  992. result.AddRange(list);
  993. return result;
  994. }
  995. [Emitted]
  996. public static IList/*!*/ Unsplat(object splattee) {
  997. var list = splattee as IList;
  998. if (list == null) {
  999. list = new RubyArray(1);
  1000. list.Add(splattee);
  1001. }
  1002. return list;
  1003. }
  1004. // CaseExpression
  1005. [Emitted]
  1006. public static bool ExistsUnsplatCompare(CallSite<Func<CallSite, object, object, object>>/*!*/ comparisonSite, object splattee, object value) {
  1007. var list = splattee as IList;
  1008. if (list != null) {
  1009. for (int i = 0; i < list.Count; i++) {
  1010. if (IsTrue(comparisonSite.Target(comparisonSite, list[i], value))) {
  1011. return true;
  1012. }
  1013. }
  1014. return false;
  1015. } else {
  1016. return IsTrue(comparisonSite.Target(comparisonSite, splattee, value));
  1017. }
  1018. }
  1019. // CaseExpression
  1020. [Emitted]
  1021. public static bool ExistsUnsplat(object splattee) {
  1022. var list = splattee as IList;
  1023. if (list != null) {
  1024. for (int i = 0; i < list.Count; i++) {
  1025. if (IsTrue(list[i])) {
  1026. return true;
  1027. }
  1028. }
  1029. return false;
  1030. } else {
  1031. return IsTrue(splattee);
  1032. }
  1033. }
  1034. [Emitted] // parallel assignment:
  1035. public static object GetArrayItem(IList/*!*/ array, int index) {
  1036. Debug.Assert(index >= 0);

Large files files are truncated, but you can click here to view the full file