YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Are the opcodes documented?
billbob
#1 Posted : Saturday, June 18, 2016 5:23:11 PM(UTC)
Rank: Member

Groups: Registered
Joined: 1/19/2015(UTC)
Posts: 10

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Is there documentation about the opcodes?

I'm curious about a couple of things related to how the compiled code is stored. My main question is has to do with symbol look up when calling functions or accessing variables.

when I do:

foo(100)

is "foo" looked up every time the statement is run, or does the compiler have a link to the already hashed object for efficiency? The same question would apply to variable look up as well.

bill.bob = 10

Is it doing string compares for "bill" and "bob" each time this line is executed?

This question came up becasue I want to precompile my source code, so my game ships with just the serialize code. It all seems to work, but looking at the serialized opcodes (using sq_writeclosure), I'm seeing the names of my functions appearing in the opcode steam anytime the functions are called, which made me wonder if they are being looked up (i.e. string compares) each time they are being called.



fagiano
#2 Posted : Sunday, June 19, 2016 3:12:26 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,054

Thanks: 0 times
Was thanked: 77 time(s) in 59 post(s)
The opcodes are not documented at the moment. Squirrel is a dynamic language, everything but local variables is looked up at runtime. however, strings are kept 'unique' so they are pre-hashed they can be compared by pointer. The hash is computed when the string is created, so using a string key is more or less the same performance as a integer key. Local variable are looked up by index, like some sort of virtual register. Squirrel is not a stack machine but a register based one. This approach is pretty standard for dynamic languages(lua, python etc.. use more or less the same approach).

ciao
Alberto
Follow me on Twitter @squirrellang
billbob
#3 Posted : Sunday, June 19, 2016 3:20:57 PM(UTC)
Rank: Member

Groups: Registered
Joined: 1/19/2015(UTC)
Posts: 10

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Thanks. I have one addition question in my quest to pre-compile my code:

It seems that const variables are still being looked up. If I have.

const foo = 10
t <- {
a = foo
}

It compiles fine, but when the code is loaded, I get an error that the index 'foo' could not be found. I would have assumed the compiler would have turn 'foo' into 10. This works fine if I'm compiling at runtime.

Is my assumption incorrect, or am I doing something wrong?

Is it even possible to completely compile the code beforehand and load it later, or is this a fruitless path to be taking?


fagiano
#4 Posted : Monday, June 20, 2016 1:46:50 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,054

Thanks: 0 times
Was thanked: 77 time(s) in 59 post(s)
The code you posted precompiles correctly, I think you are experiencing some different problem.

Alberto
Follow me on Twitter @squirrellang
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.070 seconds.