- PencilBox is a stack based VM.
variables | description |
---|---|
env | the object share with the outside of VM |
ctx | the context of canvas in HTML |
pc | program counter(pointer to the current byte) |
stack | store and calcuate temp values |
stack_scopeindex | the list of the index of the start of current stack length when a new scope generated |
varstack | store values for local variable definition |
varstack_callindex | the list of the index of the start of arguments in var_stack of current calling function |
textstack | store all the texts defined in program |
funcstack | store JIT compiled functions |
- PencilBox will convert any
func
to native JavaScript funciton.
The unicode for end of text
0x0300
0xHH
means one byte with any content0xHHHH[]
means a list with multiple of two bytes
- The constructor of data types
- The runtime system will push all the value in Opdata construction to stack
operation name | code | description | construction |
---|---|---|---|
sot | 0 | the start of text(represented as utf-16) | sot 0xHHHH[] EOT |
iot | 1 | the index of textstack | iot Opdata |
int8 | 2 | signed 8-bit integer | int8 0xHH |
uint8 | 3 | unsigned 8-bit integer | uint8 0xHH |
int16 | 4 | signed 16-bit integer | int16 0xHHHH |
uint16 | 5 | unsigned 16-bit integer | uint16 0xHHHH |
int32 | 6 | signed 32-bit integer | int32 0xHHHHHHHH |
uint32 | 7 | unsigned 32-bit integer | uint32 0xHHHHHHHH |
float32 | 8 | 32-bit float | float32 0xHHHHHHHH |
float64 | 9 | 64-bit float | float64 0xHHHHHHHH 0xHHHHHHHH |
- The operations generated by compiler
operation name | code | description | construction |
---|---|---|---|
textstack | 16 | the mark of text stack | textstack 0xHHHHHHHH (0xHHHH[] EOT)[] |
sweep | 17 | pop the top element from variable stack | sweep |
sweepn | 18 | pop n top elements from variable stack | sweep 0xHH |
jump | 19 | pop the top element from stack and jump to the specific value of pc | jump |
jumpoffset | 20 | pop the top element from stack and jump to the value offset to the current pc | jumpoffset |
localfget | 21 | push the the content in var_callindex with offset of var_stack to stack | localfget |
- Operations can be used by users
operation name | code | description | construction |
---|---|---|---|
scope | 31 | pop the top element in stack and push it to variable stack | scope |
get | 32 | push the value from variable stack of the value popped the top element in stack | |
func | 33 | push the function pc value to stack | func 0xHHHHHHHH 0xHH 0xHH[] sweepn jump |
apply | 34 | modify pc to the popped value from stack | apply |
35 | console log the popped value from stack | print |
|
add | 36 | pop 2 elements from stack and push the addition of them to stack | add |
sub | 37 | pop 2 elements from stack and push the substraction of them to stack | sub |
div | 38 | pop 2 elements from stack and push the division of them to stack | div |
mul | 39 | pop 2 elements from stack and push the multiplication of them to stack | mul |
mod | 40 | pop 2 elements from stack and push the modulo result of them to stack | mod |
envGet | 41 | get value from env with popped value from stack as key | envGet |
envSet | 42 | set value in env with popped value from stack as key | envSet |
ifElse | 43 | detect if the popped value from stack is 1 or 0 | ifElse |
eq | 44 | push the equalization of popped 2 values from stack(true is 1 and false is 0) | eq |
gt | 45 | greater than detection for 2 popped values from stack | gt |
ge | 46 | greater than or equal to detection for 2 popped values from stack | ge |
lt | 47 | less than detection for 2 popped values from stack | lt |
le | 48 | less than or equal to detection for 2 popped values from stack | le |
list | 49 | construct list of data | list |
index | 50 | get value from list with index and push to stack | index |
pop | 51 | pop the last element from list and push to stack | pop |
push | 52 | push the value popped from stack to list | push |
shift | 53 | shift the first element from list and push to stack | shift |
unshift | 54 | unshift the value popped from stack to list from behind | unshift |
ANY CANVAS CONTEXT PROPERTY | - | get or set the canvas context property | - |
ANY CANVAS CONTEXT OPERATION | - | run the canvas context methods | - |