Advertisement
ZoriaRPG

Structs, 2D 3D Arays, Function Pointers, Classes MODEL CHAT

Aug 19th, 2019
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.81 KB | None | 0 0
  1.  
  2. Venrob04/25/2019
  3. Notice the Would be nice tag; we have no plans to even implement this at this time
  4. part of the syntax is limited by the bison, as well, due to shift-reduce and reduce-reduce errors
  5. one of the reasons casting is <type> instead of (type)
  6.  
  7. Mr Mustache04/25/2019
  8. ok thats just one of the things I hate in c++ is the * and &
  9.  
  10. Venrob04/25/2019
  11. I understand the feeling, because they always confuse me
  12. but, they are actually very important in what they allow
  13.  
  14. Mr Mustache04/25/2019
  15. what is even the point in pointers if you can pass by refrence?
  16. like idk why anyone would need a pointer
  17.  
  18. ZoriaRPG04/25/2019
  19. Erhm, I needed one many times today.
  20. Look at all of my commits from today and yesterday in branch 2.55.
  21. I use pointers everywhere.
  22.  
  23. Mr Mustache04/25/2019
  24. hmm is it needed for scripts though?
  25. i guess functions as variables could be handled internally on assign
  26. so you don't have to use *
  27. anyways I got to get off
  28. gn
  29.  
  30. ZoriaRPG04/26/2019
  31. @Mr Mustache : This might be useful to you:
  32. http://www.cplusplus.com/doc/tutorial/pointers/
  33. In ZScript, the logical way to handle a function pointer, would be fpr the pointer to reference the ZASM instruction line on whichn the function begins.
  34. We don't have certain elements such as an address system, just ZASM line IDs.
  35. When we call a function in ZScript, we jump to its line, so, a function pointer would store that line.
  36. and when called, we would jump to that line, until we reach OReturn
  37. Of course, we'd also need to store the types and number of params used by the function pointer, in addition to its ZASM line address somehow.
  38.  
  39. This could probab;y take a similar form to how array data works. Store the 'size' in index 0, the 'address' of this segment (pointer) in index 1. then for each arg, an index for its type.
  40.  
  41. Thus, the pointer would look like this:
  42.  
  43. (*fun)(int,bool,bitmap)
  44. {4, &fun, TYPE_FLOAT, TYPE_BOOL, TYPE_BITMAP}
  45. The first index tells us how far into the vector from this point we are reading. The second is the ZASM line number, and the last tell us how to cast its values. We may need additional space to store them when called.
  46.  
  47. The actual initialisation of a function pointer:
  48. void(*foo)(int,bool,bitmap); would push onto the stack, a flag that the next stack value is going to be a function pointer, then the array address in the vector.
  49. @Venrob Feasibility?
  50. It would have been better if our syntax always required pointer tokens for this sort of thing, because the way that we pass arrays by reference is exactly why it is hard to fix some of their problems, and a cause for not being able to ever migrate away from how they now work.
  51. Thus, if we ever want real structs, 2D arrays, or classes, we would need some kind of address system for those.
  52. In that case, the pointer would be the starting point of the struct/array/class in a vector.
  53. as v->at(address)
  54.  
  55. ZoriaRPG04/26/2019
  56. The benefit of function pointers, is that you can do stuff like this:
  57.  
  58. Mr Mustache04/26/2019
  59. I would perfer the at(address) then using *
  60.  
  61. ZoriaRPG04/26/2019
  62. PSEUDOCODE ALERT
  63. int(*global_set_ghost)(void) = Ghost_Main;
  64. int (*global_set_tango)(void) = Tango_Main;
  65. int global_loop[1024]; int highest_global_call = 0;
  66. global script init_add_ghost //if we have multiple init scripts, each can add stuff to the global active
  67. {
  68. void run()
  69. {
  70. global_loop[highest_global_call] = &global_set_ghost;
  71. ++highest_global_call;
  72. }
  73. }
  74.  
  75. global script init_add_tango //if we have multiple init scripts, each can add stuff to the global active
  76. {
  77. void run()
  78. {
  79. global_loop[highest_global_call] = &global_set_tango;
  80. ++highest_global_call;
  81. }
  82. }
  83.  
  84. global script active
  85. {
  86. void run()
  87. {
  88. int f;
  89. while(1)
  90. {
  91. for ( int q = 0; q <= highest_global_call; ++q )
  92. {
  93. f = &global_loop[q];
  94. f();
  95. }
  96. }
  97. }
  98. }
  99. I would perfer the at(address) then using * Except, you can't KNOW the address until runtime.
  100. Now, you could use a literal token of (at), or something.
  101. even @ or $
  102.  
  103. Mr Mustache04/26/2019
  104. at and ref like...
  105.  
  106. ZoriaRPG04/26/2019
  107. Different languages have different tokens to represent a pointer.
  108. and an address ID
  109. @ is used for handles
  110.  
  111. Mr Mustache04/26/2019
  112. int x = 25
  113. int y = ref x
  114. int z = at y
  115.  
  116. ZoriaRPG04/26/2019
  117. IIRC
  118. Those would just be alt tokens.
  119. Like and for &&
  120.  
  121. Mr Mustache04/26/2019
  122. there is no way to force them to be in ()?
  123. int x = 25
  124. int y = ref(x)
  125. int z = at(y)
  126.  
  127. ZoriaRPG04/26/2019
  128. Oh
  129. no, C++ HANDLE is typedef'd
  130.  
  131. Mr Mustache04/26/2019
  132. oh ok :(
  133.  
  134. ZoriaRPG04/26/2019
  135. So, there you go.
  136. typedef void *HANDLE;
  137. typedef void* ptr
  138.  
  139. Mr Mustache04/26/2019
  140. well now that I know that a pointer is a way to get a variable from a refrence
  141. its not so bad
  142. @ would be nice for *
  143.  
  144. ZoriaRPG04/26/2019
  145. It's a way to get either the address of a variable, or the value stored at a particular address.
  146.  
  147. Mr Mustache04/26/2019
  148. as an alias
  149. oh i see
  150.  
  151. ZoriaRPG04/26/2019
  152. Most scripting systems don't also have an address system, or a heap.
  153. True programming languages need these.
  154. Especially if you want dynamic memory management.
  155.  
  156. Mr Mustache04/26/2019
  157. ya i understand
  158. can you at least implement the @ alias though?
  159. it seems more clear
  160. because its the literal at symbol
  161.  
  162. ZoriaRPG04/26/2019
  163. I would prefer to keep things to C syntax, because that way, people can look up basic C docs and learn the language.
  164.  
  165. Mr Mustache04/26/2019
  166. ok
  167.  
  168. ZoriaRPG04/26/2019
  169. Also, @ has other connotations, however, because of how flex works, who knows if we can ever get * or & to work.
  170.  
  171. Mr Mustache04/26/2019
  172. I wonder why c++ didn't do it
  173. oh ok
  174.  
  175. ZoriaRPG04/26/2019
  176. making rules so that they are detected as pointer tokens and not as mult or bitand, isn't trivial.
  177. I suppose as long as the left side is a type, it'd be fine, for *
  178. Just even more complex OoO stuff.
  179.  
  180. Mr Mustache04/26/2019
  181. uhh I have a question
  182. is zscript compadable with C#?
  183. like could it be made into a library for me to use?
  184.  
  185. ZoriaRPG04/26/2019
  186. I don't know enough about C# to tell you if it'd port over.
  187. IDK if flex-bison can be used in conjunction with C#
  188.  
  189. Mr Mustache04/26/2019
  190. oh ok
  191.  
  192. ZoriaRPG04/26/2019
  193. You should just just something better anyway.
  194.  
  195. Mr Mustache04/26/2019
  196. well I might just do lua where I make a visual and C style converters
  197. that convert it to lua
  198.  
  199. ZoriaRPG04/26/2019
  200. C# has its own .NET scripting language.
  201. So, you could just use that.
  202.  
  203. Mr Mustache04/26/2019
  204. ya I know
  205. :(
  206.  
  207. ZoriaRPG04/26/2019
  208. C# can be its own scripting language, so IDK why you would ever use something as system-heavy as ZScript if you are already using C#
  209.  
  210. Mr Mustache04/26/2019
  211. lua would be easier to make a visual scripting laguage with I think
  212. because the code widgets could just be lua snippits
  213. I just hate the then end
  214.  
  215. ZoriaRPG04/26/2019
  216. Eh
  217. I actually prefer that. it's Pascal syntax.
  218.  
  219. Mr Mustache04/26/2019
  220. ya i know we have had this discussion before :P
  221. I saw this thing were a team of people made a c style lua scripting language
  222. I think its called bright
  223. but I don't like how they do types at the end of the declaration instead of the beginning
  224. function foo() : void
  225.  
  226. end
  227. I think thats how it went
  228.  
  229. ZoriaRPG04/26/2019
  230. What you could do, is make a scanner as a preprocessor that reads an input file, and appends the C# tokens to a C style syntax.
  231. That however, would slow down code excution considerably just because you don't like the syntax.
  232. I would advise against it.
  233. That's also based on pascal.
  234. http://wiki.freepascal.org/Function
  235.  
  236. Venrob
  237.  
  238.  
  239. Adding class to ZScript
  240.  
  241. If @Venrob manages to get namespace working, fully, then I don't think that this will be as big of a bitch as he imagines it would.
  242.  
  243. (A) ZScript will not need, nor be able to use multiple instances, so we can dispose of new m and instance behaviour, and focus on the following:
  244.  
  245. (B) Inheritence
  246. A class should be able to inherit variables, and functions from its parent. In essence, it would be like appending one namespace to another, for its internal instance.
  247.  
  248. (C) Polymorphism
  249. This one is trickier, but in essence, we'd need to allow a shadow declaration to take precedence. If youhave the following classes:
  250.  
  251. class foo
  252. {
  253. public:
  254. int x;
  255. };
  256.  
  257. class bar : public foo
  258. {
  259. public:
  260. int y;
  261. };
  262.  
  263.  
  264. ...then both bar.x and bar.y are legal, as is foo.x, butfoo.y is not legal.
  265.  
  266. (D) Function and Variable Storage Types
  267. public and private
  268. We'd need to mark if a function is private, and thus, only available to that class.
  269.  
  270. We wouldn't need protected.
  271. I'd rather have structs, but I do like the idea of adding the ability to create inherited and polymorphed functions and variables, at some point.
  272. Structs have the same issue as real 2D or 3D arrays.
  273. The issue with storage comes down to storing data in a save file.
  274.  
  275. You don't save instances. They are allocated onto the heap only during operation.
  276.  
  277. We also don't have a heap, and you'd never properly reconstruct that heap to recover them, from the save file, without losing the correct address pointers
  278.  
  279. Look at how array data is stored when you want.
  280.  
  281. I think that 2D arrays, using a new type specifier, might be viable, and if they ever are, then structs may also be; but of course, then we run into potentially needing real pointers and other stuff. IDK
  282.  
  283. 2D arrays, structs, that might one day be viable:
  284. IIRC, Array data is all stored in a vector that contains first the array pointer, then its size, then its data.
  285. 2D or 3D would need to contain the different dimensions, and the data in the correct sequence.
  286. structs would need to store the struct pointer, the number of members, then the datatype of each member, the size and dimensions of each member, and then the data.
  287.  
  288.  
  289. As I said, inheriting data member access is something that I'd like to have, but I can live without it.
  290. I'm just putting the whole thing there for you, to archive it, with some contextual corrections.
  291.  
  292. Mr Mustache04/25/2019
  293. so i know this says would very much be nice but if this was implemented wouldn't it be cleaner and more clear to do..
  294. class foo
  295. {
  296. public int x;
  297. public int y;
  298. };
  299. rather then
  300. class foo
  301. {
  302. public:
  303. int x;
  304. int y;
  305. };
  306. this is another thing I hate about c++ although c++ ide's are the ones forcing me to use the second one
  307. I could easly do..
  308. class foo
  309. {
  310. public: int x;
  311. public: int y;
  312. };
  313.  
  314. Venrob04/25/2019
  315. Again, inactive channel
  316. this entire category is
  317.  
  318.  
  319. ZoriaRPG03/24/2019
  320. 2D arrays, structs, that might one day be viable.
  321. Array data is all stored in a vector that contains first the array pointer, then its size, then its data.
  322. 2D or 3D would need to contain the different dimensions, and the data in the correct sequence.
  323. structs would need to store the struct pointer, the number of members, then the datatype of each member, the size and dimensions of each member, and then the data.
  324.  
  325. Venrob03/24/2019
  326. My main issue is I know almost nothing about the ASM side, or anything related (including save file stuff)
  327. I don't think I've even added an opcode, that got merged (KoolAid and I did the TriComp, as a test to learn how the parser worked, but that's not getting merged, because we don't want it)
  328.  
  329.  
  330. That was part of the discussion.
  331. Not sure where I detailed the rest.
  332. (*fun)(int,bool,bitmap)
  333. {4, &fun, TYPE_FLOAT, TYPE_BOOL, TYPE_BITMAP}
  334. The first index tells us how far into the vector from this point we are reading. The second is the ZASM line number, and the last tell us how to cast its values. We may need additional space to store them when called.
  335. that was for function pointers, though
  336.  
  337. ZoriaRPGToday at 1:06 AM
  338. aaaah
  339. #????classes-with-instances
  340. Attachment file type: document
  341. zscriptstructmodel.txt
  342. 10.47 KB
  343. i think those were all of my models.
  344. I'm syure that at some point I typed out a vector format, though.
  345.  
  346. ZoriaRPGToday at 1:18 AM
  347. structs would need to store the struct pointer, the number of members, then the datatype of each member, the size and dimensions of each member, and then the data.
  348.  
  349. Found it
  350. on the script server
  351. Still missing where I typed it in an array format
  352. { pointer, number_members, { member types }, { member sizes }, { member data } }
  353. stored in a vector
  354. IDR if you can search a vector for a 'substring'
  355. if you can,then pointer should be a string like $1000
  356. that way, the zasm stringsearches the vector for $1000 and gets the ->at() index of the pointer
  357. that, or pointers need registration regularly
  358. oh
  359. or
  360. skip that index
  361. this needs to ve a vector of vectors
  362. so, the pointer is the entry point in the D2 vector containing the vector of data
  363. thus
  364. STRUCT
  365. { vectors } == pointer
  366. { vectors { number_members, { member types }, { member sizes }, { member data } } }
  367. 2D array
  368. { vectors } == pointer
  369. { vectors { { types }, { sizea, sizeb }, { data,data,data... } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement