/Backend/Runtime/Interfaces.cs

https://bitbucket.org/AdamMil/boaold · C# · 151 lines · 103 code · 25 blank · 23 comment · 0 complexity · da361d31395f2ede00ed17aed8a3a99a MD5 · raw file

  1. /*
  2. Boa is the reference implementation for a language similar to Python,
  3. also called Boa. This implementation is both interpreted and compiled,
  4. targeting the Microsoft .NET Framework.
  5. http://www.adammil.net/
  6. Copyright (C) 2004-2005 Adam Milazzo
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. using System;
  20. using System.Collections;
  21. // TODO: respect this: http://rgruet.free.fr/PQR2.3.html
  22. namespace Boa.Runtime
  23. {
  24. public interface ICallable
  25. { object Call(params object[] args);
  26. }
  27. public interface IFancyCallable : ICallable
  28. { object Call(object[] positional, string[] names, object[] values);
  29. }
  30. public interface IContainer
  31. { int __len__();
  32. bool __contains__(object value);
  33. }
  34. public interface IDescriptor
  35. { object __get__(object instance);
  36. }
  37. public interface IDataDescriptor : IDescriptor
  38. { void __set__(object instance, object value);
  39. void __delete__(object instance);
  40. }
  41. public interface IDynamicObject
  42. { DynamicType GetDynamicType();
  43. }
  44. #region IFile
  45. public interface IFile
  46. { bool canread { get; }
  47. bool canseek { get; }
  48. bool canwrite { get; }
  49. bool closed { get; }
  50. System.Text.Encoding encoding { get; set; }
  51. int length { get; }
  52. void close();
  53. void flush();
  54. bool isatty();
  55. string next();
  56. byte[] read();
  57. byte[] read(int bytes);
  58. string readstr();
  59. string readstr(int bytes);
  60. int readbyte();
  61. string readline();
  62. string readline(int size);
  63. List readlines();
  64. List readlines(int sizehint);
  65. int seek(int offset);
  66. int seek(int offset, int whence);
  67. int tell();
  68. void truncate();
  69. void truncate(int size);
  70. void write(byte[] bytes);
  71. void write(string str);
  72. void writebyte(int value);
  73. void writelines(object sequence);
  74. }
  75. #endregion
  76. public interface IHasAttributes
  77. { List __attrs__();
  78. object __getattr__(string key);
  79. void __setattr__(string key, object value);
  80. void __delattr__(string key);
  81. }
  82. public interface IInstance : IDynamicObject
  83. { Dict __dict__ { get; }
  84. UserType __class__ { get; set; }
  85. }
  86. public interface IRepresentable
  87. { string __repr__();
  88. }
  89. public interface ISequence : IContainer
  90. { object __add__(object o);
  91. object __getitem__(int index);
  92. object __getitem__(Slice slice);
  93. }
  94. public interface IMutableSequence : ISequence
  95. { void __delitem__(int index);
  96. void __delitem__(Slice slice);
  97. void __setitem__(int index, object value);
  98. void __setitem__(Slice slice, object value);
  99. }
  100. public interface IMapping : IContainer
  101. { void clear();
  102. object copy();
  103. object get(object key);
  104. object get(object key, object defaultValue);
  105. bool has_key(object key);
  106. //static object fromkeys(object seq);
  107. //static object fromkeys(object seq, object value);
  108. object pop(object key);
  109. object pop(object key, object defaultValue);
  110. Tuple popitem();
  111. object setdefault(object key);
  112. object setdefault(object key, object defaultValue);
  113. void update(object dict);
  114. List items();
  115. List keys();
  116. List values();
  117. IEnumerator iteritems();
  118. IEnumerator iterkeys();
  119. IEnumerator itervalues();
  120. void __delitem__(object key);
  121. object __getitem__(object key);
  122. void __setitem__(object key, object value);
  123. }
  124. } // namespace Boa.Runtime