Gobra implements a Python 3 virtual machine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

frame_cell.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package gobra
  2. import (
  3. "fmt"
  4. "maze.io/gobra.v0/types"
  5. )
  6. var cellType = &types.TypeDescription{
  7. Name: "cell",
  8. }
  9. // cell is a container for a wrapped value
  10. type cell struct {
  11. value types.Object
  12. }
  13. func (o *cell) Delete() types.Object {
  14. if o.value != nil {
  15. o.value = nil
  16. return types.Nil
  17. }
  18. panic(types.ValueError.Raise("delete() on an empty cell"))
  19. }
  20. func (o *cell) Clone() *cell {
  21. c := &cell{value: o.value}
  22. return c
  23. }
  24. func (o *cell) ID() types.Int {
  25. return types.ID(o)
  26. }
  27. func (o *cell) Hash() types.Int {
  28. if o.value != nil {
  29. return o.value.Hash()
  30. }
  31. return 0
  32. }
  33. func (o *cell) Repr() types.Str {
  34. return o.Str()
  35. }
  36. func (o *cell) Type() types.Type {
  37. if o.value != nil {
  38. return o.value.Type()
  39. }
  40. return cellType
  41. }
  42. func (o *cell) TypeName() types.Str {
  43. if o.value != nil {
  44. return o.value.TypeName()
  45. }
  46. return cellType.Name
  47. }
  48. func (o *cell) Dir() types.List {
  49. return types.TypeAttrDir(o)
  50. }
  51. func (o *cell) Attr(name types.Str, standard types.Object) types.Object {
  52. return types.TypeAttr(o, name, standard)
  53. }
  54. func (o *cell) AttrSet(name types.Str, value types.Object) {
  55. types.TypeAttrSet(o, name, value)
  56. }
  57. func (o *cell) CompareLess(other types.Object) bool {
  58. if o.value != nil {
  59. return o.value.CompareLess(other)
  60. }
  61. return true
  62. }
  63. // Casting
  64. func (o *cell) Bool() types.Bool {
  65. return types.Bool(o.value != nil)
  66. }
  67. func (o *cell) Str() types.Str {
  68. var content types.Str
  69. if o.value != nil {
  70. content = o.value.Repr()
  71. }
  72. return types.Str(fmt.Sprintf("<cell(%s) at %p>", content, o))
  73. }
  74. func newCell() *cell {
  75. return new(cell)
  76. }
  77. var _ types.Object = (*cell)(nil)