Skip to content

VM Table Scoping

duangsuse edited this page Jan 9, 2018 · 2 revisions

Scoping

https://github.com/minized-lang/MVM/wiki/OpCodes#global-table-scoping

Opcode scope and scopeDel and scopeEnd is used to enter/save an Object to destory/leave a scope.

Scope in MinVM

Why???

🌚 MinVM uses a Hashtable<Integer, Object> (in Java) to store Objects but Integer.MAX_VALUE is 2147483647 (in OpenJDK 64-Bit Server VM build 25.151-b12) but in fact EMMC will bind every variable to an index, even it's scoped...

Just for fun. 🌝

How MinVM Stores Objects?

MinVM uses a Hashtable<Integer, Object> (in Java) to store Objects

How MinVM Implement Scopes?

🌚 That's it

es: Scope Stack <Array<Scope>>

scope: push a new scope Object to es

scopeDel: add an Object index to es.top

scopeEnd: es.top.deleteObjects(); es.pop()

How to create&use a scope?

Like this

scope
loadInt 8
put 0
scopeDel 0
scopeEnd
;resid 0 is not a valid key to global table now