The Sol Programming Language!
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.

42 lines
768 B

  1. func dump(obj, indent)
  2. if None == indent then
  3. indent = 0
  4. seen = {}
  5. end
  6. io.stdout:write(" "*indent)
  7. if type(obj) == "list" then
  8. buf = buffer.fromobject(obj)
  9. addr = buf:address()
  10. if None != seen[obj] then
  11. print("...("+addr+")")
  12. return
  13. end
  14. seen[obj] = 1
  15. print("[")
  16. for elem in obj do
  17. dump(elem, indent+2)
  18. end
  19. print(" "*indent+"] =("+addr+")")
  20. return
  21. end
  22. if type(obj) == "map" then
  23. buf = buffer.fromobject(obj)
  24. addr = buf:address()
  25. if None != seen[obj] then
  26. print("...("+addr+")")
  27. return
  28. end
  29. seen[obj] = 1
  30. print("{")
  31. for key in obj do
  32. io.stdout:write(" "*(indent+2))
  33. prepr(key, ":")
  34. dump(obj[key], indent+4)
  35. end
  36. print(" "*indent+"} =("+addr+")")
  37. return
  38. end
  39. prepr(obj)
  40. end
  41. dump.closure.seen = {}