demo004.odin 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import "core:fmt.odin";
  2. import "core:utf8.odin";
  3. import "core:hash.odin";
  4. import "core:mem.odin";
  5. main :: proc() {
  6. { // New Standard Library stuff
  7. s := "Hello";
  8. fmt.println(s,
  9. utf8.valid_string(s),
  10. hash.murmur64(cast([]u8)s));
  11. // utf8.odin
  12. // hash.odin
  13. // - crc, fnv, fnva, murmur
  14. // mem.odin
  15. // - Custom allocators
  16. // - Helpers
  17. }
  18. {
  19. arena: mem.Arena;
  20. mem.init_arena_from_context(&arena, mem.megabytes(16)); // Uses default allocator
  21. defer mem.destroy_arena(&arena);
  22. push_allocator mem.arena_allocator(&arena) {
  23. x := new(int);
  24. x^ = 1337;
  25. fmt.println(x^);
  26. }
  27. /*
  28. push_allocator x {
  29. ..
  30. }
  31. is equivalent to:
  32. {
  33. prev_allocator := __context.allocator
  34. __context.allocator = x
  35. defer __context.allocator = prev_allocator
  36. ..
  37. }
  38. */
  39. // You can also "push" a context
  40. c := context; // Create copy of the allocator
  41. c.allocator = mem.arena_allocator(&arena);
  42. push_context c {
  43. x := new(int);
  44. x^ = 365;
  45. fmt.println(x^);
  46. }
  47. }
  48. // Backend improvements
  49. // - Minimal dependency building (only build what is needed)
  50. // - Numerous bugs fixed
  51. // - Mild parsing recovery after bad syntax error
  52. }