ZodiacMentor

Cbas

Jun 7th, 2022 (edited)
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. function main(string[] args) < int32:
  2. float f = 1.3
  3. bool b = true
  4. int32[] int_array = [4, 5, 12, 3]
  5. uint8 eightbitInteger = 127
  6.  
  7. string s = "Hellorld!"
  8.  
  9. loop int8 i in range(0,10,1): # range(start, stop-exclusive-optional, step-optional) <-
  10. if (b and f > 1):
  11. print(s)
  12. print(f)
  13. int_array[0]-- # decrement int_array element 0
  14. eighbitInteger++ # increment eightbitInteger
  15. ;
  16. ;
  17.  
  18. loop i in int_array:
  19. print(i)
  20. ;
  21.  
  22. loop while b:
  23. # Condition checked before loop statement
  24. ;
  25.  
  26. loop until not b:
  27. # Condition checked after loop statement, inverse logic
  28. ;
  29.  
  30. loop:
  31. print("This never ends.")
  32. ;
  33.  
  34. return 0
  35. ;
  36.  
  37. function print(string s):
  38. Console.Out.PrintLine(s)
  39. ;
  40.  
  41. class Stream:
  42. static int32 iVal = 0
  43.  
  44. static public function PrintLine(string s):
  45. .iVal = s.length()
  46. loop int32 i from s:
  47. uint8 char = s[i]
  48. #ifdef ASM_6502
  49. asm (char):
  50. PHA
  51. LDA %char%
  52. STA #GPU_CMDQ_ADDRESS
  53. PLA
  54. ;
  55. #endif
  56. ;
  57. ;
  58. ;
  59.  
  60. class Console:
  61. static Stream Out
  62. ;
  63.  
  64. class string:
  65. private uint8[] backingArray
  66.  
  67. public string():
  68. # .<class member> is shorthand for this.<class member>
  69. .backingArray = []
  70. ;
  71.  
  72. public string(uint32 initialBackingArraySize):
  73. .backingArray = [](initialBackingArraySize)
  74. ;
  75.  
  76. public ~string():
  77. .backingArray = None
  78. ;
  79.  
  80. public function addCharacter(uint8 char):
  81. .backingArray.add(char)
  82. ;
  83.  
  84. # short circuit version of returning function - the return type is inferred from the called function
  85. public function length() < .backingArray.length()
  86.  
  87. # overloads [] accessor
  88. public function getItemAt(uint32 itemIndex) < uint8:
  89. return .backingArray[itemIndex]
  90. ;
  91.  
  92. # overloads [] mutator
  93. public function setItemAt(uint32 itemIndex, uint8 char):
  94. .backingArray[itemIndex] = char
  95. ;
  96.  
  97. # overloads =
  98. public function assignment(string other):
  99. .backingArray = other.clone()
  100. ;
  101.  
  102. public function equals(string other) < bool:
  103. bool same = true
  104.  
  105. loop uint32 i from range(0, other.backingArray.length):
  106. if (other[i] != .backingArray[i]):
  107. same = false
  108. break
  109. ;
  110. ;
  111.  
  112. return same
  113. ;
  114.  
  115. public function clone() < uint8[]:
  116. return .backingArray.clone()
  117. ;
  118. ;
  119.  
  120. class array<T>:
  121. private array T backingArray
  122.  
  123. public array<T>():
  124. .backingArray = array T()
  125. ;
  126.  
  127. public array<T>(uint32 initialBackingArraySize):
  128. .backingArray = array T(initialBackingArraySize)
  129. ;
  130. ;
Advertisement
Add Comment
Please, Sign In to add comment