#any open source, GML parsers or string_execute?

1 messages · Page 1 of 1 (latest)

keen cove
#

Looking to throw together a project, similar to GMLive, except running inside GM. Doesn't need to be overly advanced, just the bare bones. I know a reliable option would be to make use of katspeak, but the project is just a personal project so no need for anything advanced.

lapis remnant
#

TXR or katsaii's Catspeak

#

neither are exactly GM-compliant though

keen cove
#

Yeah that's kinda the issue. The closer it can possibly resemble GML the better.

lapis remnant
#

there were some attempts a while ago for pre-2.3 GML but post 2.3 i think people gave up trying

#

left it to Vadym

keen cove
#

Yeah I seen mimpy's string execute. And obviously GMLive. How ever the first is broken, and the second one close source

lapis remnant
#

if it's a personal project i'm sure Vadym wouldn't mind you doing a little hacking

#

i think GMLive even has a string_execute-ish feature doesn't it?

keen cove
#

Does it?

#

But yeah just making a portable GM notebook. For use on long trips where you can't bring your laptop. Neeri was looking for something for Android and I've wanted something similar for a while. So figured it was about time to try some attempt at it. Doesn't even need to support most of GM, it's just code snippets for testing.

lapis remnant
#

super cool!

#

good luck!

#

i have no idea where to start with that stuff. compilers are scary man

keen cove
#

That they are.

#

Luckily I have a firm grasp of what to do, just not how to do it lol

lapis remnant
#

haha

keen cove
#

Yeah after speaking with Knno, creator of kengine, TXR seems extremely viable if proper GML syntax is desired.

#

@summer kraken I have a question in relation to TXR, and I was wondering if a function defined in the executed string is possible to define. I assume it would act internally like a macro and parentheses tokens do. So TXR would just execute the tokens until a break/return/exit is met.

summer kraken
#

you'd want a function literal to become a node that emits a method that does txr_exec of its contents or something

keen cove
#

Ah so I'd need to snip that bit out, then txr_exec, and handle its return if any?

summer kraken
#

I think treating it as a separate program is the easiest

#

IIRC TXR's "programs" are just arrays with nothing that has to be manually destroyed, yeah?

keen cove
#

As a note. This is the example input text.

@'
function log(str) {
return show_debug_message(str)
}

log("hello world")
'
summer kraken
#

GML itself handles function name() as name = function()

keen cove
#

Depending, it could be global.name but yeah that's what I've picked up

summer kraken
#

cool trick time, try doing show_debug_message(self) outside of a script

#

(it's global)

keen cove
#

Though the function it's self is still a, 'at compile time' reference. Which is what I was planning to try for txr

#

Oh yes good point

summer kraken
#

mhm

keen cove
#

Alright, I think I have a good grasp on it now. Excited to try it out when I get home.

dim schooner
#

Thanks for the suggestion yal..
Btw, I would also want to make array syntax.. but also not sure how to start

summer kraken
#

I think it has arrays these days

#

or do you mean a new accessor?

dim schooner
#

No just simply a index like this
myarray[0]

summer kraken
#

I think that's supported in git version

keen cove
#

Yeah I thought I seen that too

dim schooner
#

Oh okay, I'll try it

summer kraken
#

git version has a bunch more stuff than the post did because people would ask me for something small and I'd add that

dim schooner
#

Tomorrow I'll try to see if I can do something for functions

#

And maybe a git pr

#

Ok but theoretically can we have constructors in a txr program?

#

I might try to write that too.. but a suggestion or guidance would be great

summer kraken
#

constructors are kind of tricky since you can't bind metadata to a constructor function

#

if it's only used inside the TXR program though, you can represent it in whatever way you want

dim schooner
#

Yea just inside the txr program I believe

keen cove
#

For my purposes yes. But imagine others would need a better solution.

#

How ever I would be interested in a GM feature request to include such data into the static struct for new runtime.

summer kraken
#

I could tell you the idea that I have considered for GMLive, but you will cry

keen cove
#

Check for txr meta data, if none exists check for GML metadata?

summer kraken
#
function __constructor_0() {
  // (collect arguments into an array)
  txr_construct(0, arg_array);
}

repeat 500 times and maintain a pool of "vacant" constructors to hand to the game code

keen cove
#

Wtf

#

Yeah really dirty

dim schooner
#

What about struct syntax (values)

#

Hmm that's difficult lol

summer kraken
dim schooner
#

Oh sorry

#

I just think constructors are not possible

stark patrol
#

if you're just gonna try write your own compiler, just use Catspeak

#

you can generate your own code using the IR interface, or even write your own parser for it

#

Catspeak isn't limited to just "the Catspeak language"

#

it's more of a compiler framework like LLVM, which you can compile to an IR, and then that IR can get further compiled into callable GML functions and (in the future) interpreted VM

#

lots of people recently have been asking about execute_string, and every time someone brings up Catspeak it's always discarded as not being GML enough

#

rly demotivates me

keen cove
# stark patrol lots of people recently have been asking about execute_string, and every time so...

Sorry that wasn't really the intent. I think the main reason why i sidestepped Katspeak was probably because current open source implementations to not appear similar enough to gml, so when i would go about implementing it, a lot of what i'd be doing is reading through docs and probably end up with something a bit more hacky, as i've not used katspeak before, and would be doing something a bit different.
If you're available some time maybe we could speak about the implementation of this further in DMs? I've been looking into TXR, but it also has its issues trying to near-perfectly imitate gml. So it would be refreshing to get your take on using Katspeak.

stark patrol
#

Catspeak mirrors GML semantically, it's only syntactically different because that's how i wanted it to be

#

the reason i mention it is because Catspeak already supports function definitions, like

let log = fun(str) {
  return show_debug_message(str)
}

log("hello world")
#

you can use #katsaii___catspeak for questions, and if it's just the syntax you want to be different i can walk you through creating your own parser

keen cove
#

really appreciate it. Yeah i'll be available the week after next to look further into this.

dim schooner
#

From my side
I don't know but it's feature-rich for me, as I am writing my own big engine and I don't really know how catspeak works internally. Also performance wise I dont know I feel like txr is more lightweight that's all. So yea, personally I do need external scripts but it's that I feel for my engine it's overkill. Since my engine should just ask for simple scripts like an init script that sets some vars that's all.

#

like booleans to set behaviors enabled or not etc.

#

Is there a comparison regarding performance?

stark patrol
#

probably similar speed, Catspeak is heavily under optimised but still manages to get close to GML performance

#

i imagine TXR may have similar gains, though I'm not sure, i trust YAL knows what he's doing

#

btw the interface for Catspeak is very simple and similar to TXR

#

TXR:

txr_function_add("show_message", show_message, 1);

var pg = txr_compile(@'
  var hi = "hello from TXR";
  show_message(hi);
');

txr_exec(pg);

Catspeak:

Catspeak.interface.exposeFunction("show_message", show_message);

var func = Catspeak.compileGML(Catspeak.parseString(@'
  let hi = "hello from Catspeak";
  show_message(hi);
'));

func();
#

it necessarily needs to do some things different, but if all you want is basic scripts it's really similar

keen cove
# stark patrol i imagine TXR may have similar gains, though I'm not sure, i trust YAL knows wha...

I'm not sure, I trust YAL knows what he's doing
This is a bold claim, I am un familiar with both systems, but with confidence such as that... I mean obviously one can't look away easily. I suppose it's time for a couple tests next time I'm free.
Personally the importance of it is due to the compile times, and with little experience in both, I must say my interests has peaked in both a lot from a statement as such.
(Please note im only curious and am not encouraging aggressions., but ya know... if it make libraries better i mean... :P)

#

Sorry if i pinged you Katsaii, i may have

stark patrol
#

compile times are not a big deal, you should really only be compiling a script once

#

runtime is more important, and that's what i was referring to

#

last i checked i can run this code:

let n = 1000
while n {
    n -= 1
}```
in Catspeak around 80 times per frame without dropping frames
#

so 80000 iterations aint too bad