get-set.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. let get_data = f (
  2. 'get_data',
  3. 'function get_data (C: ES_Class, k: ES_Key, nf: Bool) -> Object',
  4. (C, k, nf) => (k in C)? C[k]: (ensure(nf, 'key_error', k), Nil),
  5. 'function get_data (o: ES_Object, k: ES_Key, nf: Bool) -> Object',
  6. (o, k, nf) => (k in o)? o[k]: (ensure(nf, 'key_error', k), Nil),
  7. 'function get_data (e: Error, k: String, nf: Bool) -> Object',
  8. (e, k, nf) => {
  9. if (is(e.data, Types.Hash) && has(k, e.data)) {
  10. return e.data[k]
  11. } else {
  12. ensure(nf, 'key_error', k)
  13. return Nil
  14. }
  15. },
  16. 'function get_data (nil: Nil, k: Any, nf: Bool) -> Object',
  17. (_, __, nf) => (ensure(nf, 'get_from_nil'), Nil),
  18. 'function get_data (M: Module, k: String, nf: Bool) -> Object',
  19. (M, k, nf) => M.has(k)? M.get(k): (ensure(nf, 'key_error', k), Nil),
  20. 'function get_data (C: Class, k: String, nf: Bool) -> Object',
  21. (C, k, nf) => C.has(k)? C.get(k): (ensure(nf, 'key_error', k), Nil),
  22. 'function get_data (e: Enum, k: String, nf: Bool) -> Object',
  23. (e, k, nf) => e.has(k)? e.get(k): (ensure(nf, 'key_error', k), Nil),
  24. 'function get_data (g: Getter, k: Any, nf: Bool) -> Object',
  25. (g, k, nf) => call_method(null, g, 'get', [k, nf]),
  26. 'function get_data (s: Struct, k: String, nf: Bool) -> Object',
  27. (s, k, nf) => (ensure(!nf, 'struct_nil_flag'), s.get(k)),
  28. 'function get_data (l: List, i: Index, nf: Bool) -> Object',
  29. (l, i, nf) => (i < l.length)? l[i]: (ensure(nf, 'index_error', i), Nil),
  30. 'function get_data (h: Hash, k: String, nf: Bool) -> Object',
  31. (h, k, nf) => has(k, h)? h[k]: (ensure(nf, 'key_error', k), Nil)
  32. )
  33. let set_data = f (
  34. 'set_data',
  35. 'function set_data (o: ES_Object, k: ES_Key, v: Any) -> Void',
  36. (o, k, v) => {
  37. o[k] = v
  38. return Void
  39. },
  40. 'function set_data (e: Error, k: String, v: Any) -> Void',
  41. (e, k, v) => {
  42. if (!is(e.data, Types.Hash)) {
  43. e.data = {}
  44. }
  45. e.data[k] = v
  46. return Void
  47. },
  48. 'function set_data (s: Setter, k: Any, v: Any) -> Void',
  49. (s, k, v) => call_method(null, s, 'set', [k, v]),
  50. 'function set_data (s: Struct, k: String, v: Any) -> Void',
  51. (s, k, v) => {
  52. s.set(k, v)
  53. return Void
  54. },
  55. 'function set_data (l: List, i: Index, v: Any) -> Void',
  56. (l, i, v) => {
  57. ensure(i < l.length, 'index_error', i)
  58. l[i] = v
  59. return Void
  60. },
  61. 'function set_data (h: Hash, k: String, v: Any) -> Void',
  62. (h, k, v) => {
  63. h[k] = v
  64. return Void
  65. }
  66. )
  67. let get_slice = f (
  68. 'get_slice',
  69. 'function get_slice (o: SliceGetter, lo: SliceIndex, hi: SliceIndex) -> Any'
  70. ,(o, lo, hi) => call_method(null, o, 'slice', [lo, hi]),
  71. 'function get_slice (l: List, lo: SliceIndex, hi: SliceIndex) -> List',
  72. (l, lo, hi) => {
  73. lo = (lo === Types.SliceIndexDefault)? 0: lo
  74. hi = (hi === Types.SliceIndexDefault)? l.length: hi
  75. ensure(lo <= hi, 'invalid_slice')
  76. ensure(hi <= l.length, 'slice_index_error', hi)
  77. return l.slice(lo, hi)
  78. }
  79. )