Search Unity

Creating a interpreter with the job system & burst

Discussion in 'Burst' started by TDCreationStudios, Mar 25, 2019.

  1. TDCreationStudios

    TDCreationStudios

    Joined:
    May 16, 2018
    Posts:
    18
    Hey guys, so I've recently decided on a project that I have been debating on picking up for a while - writing a game which teaches you how to program. Due to the nature of how I have it planned, I'll need to implement my own language(s) - and I'm wondering if it is possible to write it usiing the Job System. I obviously want it to be performant and hopefully multithreaded (each "runtime" will be single threaded, but multiple runtimes on different threads).

    The main issue I face is with vairables - how do I store something which could be the size of a single bit, or 64 bytes long? Or should I use entities for this? Each entity being a seperate type - float entity, bool entity, etc (this could be problematic, to get a syntax tree the entities need to point to eachother as children/parents. Is that even possible?)

    Thanks for any help guys~
     
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    There are probably several ways to do it.

    One method I can think of off the bat is use a DynamicBuffer<T> for interpreter opcode instruction memory, then temp buffers in the runner job for additional stack space.

    To do variables, you could do the following, have a table of "NativeString" -> Entity mappings combined with *FromEntity<T> lookups. Where the NativeString gets replaced with an entity or Offset into a DynamicBuffer<T>.

    ADDENDUM:
    One thing I wholeheartedly suggest you look into is how C# IL Assembly works, it's higher-level than straight assembly, but it's stack-based, which makes it relatively straightforward to understand once you wrap your head around it's commands.

    Decompiling a .NET program also shows you how it stores variables, which might get you some additional insight for a good strategy.
     
  3. TDCreationStudios

    TDCreationStudios

    Joined:
    May 16, 2018
    Posts:
    18
    Thank you for the reply! I understand Intermediate Language - but this wasn't quite the approach I was thinking of. However, this might not be a bad shout per say, although I was thinking more of a standard lexing and interpreting approach, using tokens which map directly to methods instead of compiling down to some form of "higher level" assembly.
     
    recursive likes this.