Advertisement
PsichiX

Symbol language draft

Nov 13th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. // 'entrypoint' directive tells the compiler which function or static method will be starting point of the program
  2. #entrypoint SomeNamespace.class ^ main
  3.  
  4. // or probably in some next version you could just call given function or method directly like that?:
  5. // SomeNamespace.class ^ main
  6.  
  7. // namespace keeps any identifiers bound to given scope
  8. &SomeNamespace
  9.  
  10. // declare some variable
  11. $a:int
  12.  
  13. // you can also define initial value of given variable during it's declaring
  14. $b:int = 0
  15.  
  16. // at this point arrays can be only used with fixed items count
  17. // (in next version there will be a special 'string' class for strings implemented on standard library side)
  18. $c:byte[3] = "hi"
  19.  
  20. // copying value to another variable is done by using '\' symbol
  21. // (by default when you assign one object to another it's done just by copying references)
  22. a = \b
  23.  
  24. // function that just returns some integer value
  25. // '<-' symbol is used to return values (functions and methods of type 'void' does not use this symbol)
  26. @doNothing:int ->
  27. <- 10
  28.  
  29. // define class
  30. %class
  31.  
  32. // class fields (for now everything is public, but i need to design proper way of fields and methods accessibility)
  33. $a:int = 1
  34. $b:float = 0.5
  35. $c:byte[13]
  36.  
  37. // constructor method - we provide arguments layout after '->' symbol in the way just like variables
  38. // ('.c' means that we are using 'c' field of calling object)
  39. * -> $text:byte[10]
  40. .c = text
  41.  
  42. // destructor method
  43. ~ ->
  44. .a = 0
  45. .b = 0.0
  46. .c = ""
  47.  
  48. // typical method with arguments provided at calling point
  49. @add:float -> $a:int, $b:float
  50. <- a + b
  51.  
  52. // method with arguments bound to given context
  53. // ('a' and 'b' fields of calling object are used as 'a' and 'b' arguments)
  54. @sub:float -> a, b
  55. <- a - b
  56.  
  57. // typical method without arguments
  58. @mul:float ->
  59. <- .a * .b
  60.  
  61. // methods and functions of type 'void' (without type) does not use ':type' suffix
  62. // use '|' prefix to mark field or method as static
  63. // (in this case entry point can be only a global function or static method)
  64. |@main ->
  65.  
  66. // create new object of type 'class'
  67. $someObj:class = *class -> "hello world!"
  68.  
  69. // make a copy of 'someObj' object reference
  70. $obj:class = someObj
  71.  
  72. // dereference 'someObj' object - mark as ready to be deleted
  73. // (in this case it will be dereferenced because 'obj' object is still holding reference to this object)
  74. ~someObj
  75.  
  76. // call method 'add' of object 'obj' with it's 'a' and 'b' fields as arguments
  77. $r0:float = obj ^ add -> obj.a, obj.b
  78.  
  79. // now call method 'sub' but without arguments
  80. // (we declared context-bound arguments for this method so they will be passed automatically)
  81. $r1:float = obj ^ sub
  82.  
  83. // and here we call method without arguments because we are using fields of calling object directly in this method
  84. $r2:float = obj ^ mul
  85.  
  86. // and now we dereference 'obj' object and mark it's data to be deleted
  87. // (because now no one object has reference to it's data so it will be immediatelly deleted - magic of smart pointers)
  88. ~obj
  89.  
  90. // 'debug' directive means that we wants to show something in debug console
  91. #debug "add: " + $r0
  92. #debug "sub: " + $r1
  93. #debug "mul: " + $r2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement