Advertisement
sci4me

an older idea i had for a language that compiles to bf

Mar 1st, 2023
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. /*
  2.  
  3. constants:
  4. x :: 42;
  5. y :: []cell{ 1, 2, 3 };
  6.  
  7. variables:
  8. x : cell
  9. y : [x]cell ; x is an int
  10. z : byte ; z is a number at compile time and does not exist at runtime
  11.  
  12. assignment:
  13. x = 0
  14. x = 5
  15. y[3] = 4 ; 3 is an int at compile time
  16. y[x] = 6 ; x is a cell at runtime (we don't support >1 byte numbers at runtime natively yet)
  17.  
  18. arrays:
  19. x : [5]cell
  20.  
  21. x[0] = 4
  22. x[1] = 2
  23.  
  24. type inference in declaration:
  25. x := 5 ; x : cell = 5
  26.  
  27. copying:
  28. x := 5
  29. y : cell
  30.  
  31. y = x
  32.  
  33. addition / subtraction:
  34. x := 5
  35. y := 3
  36. x += y
  37. y -= x
  38.  
  39. while loops:
  40. x := 5
  41. while x { ; does not clear x
  42. x -= 1
  43. ...
  44. }
  45.  
  46. for loops:
  47. x := 5
  48. for x { ; does not clear x
  49. ...
  50. }
  51.  
  52. if statements:
  53. x := 1
  54. if x { ; does not clear x
  55. ...
  56. } /* else { ... } */
  57.  
  58. macros:
  59. blah :: macro(x: cell) {
  60. x -= 5
  61. }
  62.  
  63. y := 8
  64. blah(y)
  65. // y = 3
  66.  
  67. code as (compile time) data:
  68. blah :: macro(x: block) {
  69. x()
  70. }
  71.  
  72. blah({
  73. ...
  74. })
  75.  
  76. static for:
  77. #for i in 0..5 {
  78. ...
  79. }
  80.  
  81. static if:
  82. x :: macro(y: byte) {
  83. #if y > 5 {
  84. ...
  85. }
  86. }
  87.  
  88. x(7)
  89.  
  90. polymorphism in array parameters:
  91. zero :: macro(x: [y]cell) {
  92. #for i in 0..y-1 {
  93. x[i] = 0
  94. }
  95. }
  96.  
  97. with restrictions:
  98. copy :: macro(src: [x]cell, dst: [x]cell) {
  99. #for i in 0..x-1 {
  100. dst[i] = src[i]
  101. }
  102. }
  103.  
  104. x in arg 0 must equal x in arg 1
  105.  
  106. type coercion:
  107. zero :: macro(x: [y]cell) { ... }
  108.  
  109. a : cell = 5
  110. zero(a) ; 'zero' treats 'a' as `[1]cell` instead of just `cell`
  111. ; all `cell`s are desugared into this behind the scenes
  112.  
  113. custom data structures:
  114. struct Foo {
  115. x: cell;
  116. y: cell;
  117. }
  118.  
  119. x : Foo
  120. x.x = 5;
  121. x.y = 1;
  122.  
  123. blah :: macro(x: Foo) {
  124. x.x += x.y;
  125. }
  126.  
  127. blah(x);
  128.  
  129. with compile-time data too:
  130.  
  131. Stack :: struct<n: int> {
  132. data: [n]cell;
  133. ptr: cell;
  134. }
  135.  
  136. push :: macro(stack: Stack, data: cell) {
  137. stack.data[stack.ptr] = data;
  138. stack.ptr += 1;
  139. }
  140.  
  141. pop :: macro(stack: Stack, result: cell) {
  142. stack.ptr -= 1;
  143. result = stack.data[stack.ptr];
  144. }
  145.  
  146. */
  147.  
  148. zero :: macro(x: [y]cell) {
  149. #for i in 0..y-1 {
  150. x[i] = 0;
  151. }
  152. }
  153.  
  154. x := 5;
  155. zero(x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement