Giter Club home page Giter Club logo

koalajs's Introduction

.Author
	Misa.Z [email protected]

.About
	Bytecode compiler and vm are all wrote by Misa.Z. 

.How to do arm cross compile on mac osx:
 
	download arm-toolchain for macosx from:
	https://github.com/downloads/UnhandledException/ARMx/ARMx-2009q3-67.tar.bz2

	tar -zx -C ./ --strip-components 1 -f ARMx-2009q3-67.tar.bz2 

	add the path which has 'arm-none-linux-gnueabi-g++' to default paths. 

----------------------------------------------------------------------------------------
KoalaJS source code reading guide. by Misa.Z([email protected])
----------------------------------------------------------------------------------------
Directories: 
	|
	+- demos : Demos for embedded KoalaJS in your c++ project.
	+- jsvm : Bytecode compiler and virtual machine.
	+- utils : 3rd libs.
	+- native : native class/functions extend.
	+- test : test and demo scripts.

1.Bytecode design (Bytecode.h, Bytecode.cpp)

TinysJS bytecode has been designed by very simple way, it has only two parts: "instruction set" and "string table". Instruction is 32 bits size with 16 bits high for instruction code (short as INSTR), and 16 bit low for short int (SINT) or offset of string table (SOFF).

Instruction set:
		-------------------
		| 32 bits         |
		-------------------
		| instruction 0   |
		| instruction 1   |
		| instruction 2   |
		| ......          |
		| instruction n-1 |
		| instruction n   |
		-------------------

String table:
		-----------------
		|index | string |
		-----------------
		| 0    | str 0  |
		| 1    | str 1  |
		-----------------

Instruction: (defined in Instr.h)
		-------------------------
		| 16 bits   | 16 bits   |
		-------------------------
		| INSTR     | SINT/SOFF |
		-------------------------

For example: push string variable 'str1' to stack.
		-------------------------
		| INSTR_STR  | 0x0001   |
		-------------------------
If INSTR has no operate variable, the lower 16 bits will be filled as 0xFFFF. For example: math operate '='
		-------------------------
		| INSTR_ASIGN | 0xFFFF  |
		-------------------------

How to do with 32 bits INT and FLOAT, INSTR_INT or INSTR_FLOAT will be set the INT or FLOAT value as next instruction. For example: int 655360 
		-------------------------
		| INSTR_INT   | 0xFFFF  |
		-------------------------
		| 0x000A0000            |
		-------------------------

2. Bytecode file format

Bytecode file has two parts: string table and instructions. 
		----------------
		| string table | 
		----------------
		| instructions | 
		----------------

like this:
		----------------------------------
		| str0 len(4 bits) | string 0    | 
		----------------------------------
		| str1 len         | string 1    | 
		----------------------------------
		| ......                         | 
		----------------------------------
		| str(n-1) len     | string(n-1) | 
		----------------------------------
		| str(n) len       | string(n)   | 
		----------------------------------
		| len  = 0 for end of table      |
		----------------------------------
		| instructions                   | 
		----------------------------------

3. Stack VM

KoalaJS virtual machine runing as a typical stack machine, that means push variables to stack before operate, pop variables from stack and operate, then push the result back to stack.

For example: 
	Script code:
		name = "Misa";

	Run as:
		load   name   ; load variable $name and push it to stack
		str    "Misa" ; push string "Misa" to stack. 
		asign         ; pop "Misa", pop $name, and asign "Misa" to $name, and push value of $name to stack.
		pop           ; pop and drop.

	Bytecode:
		-------string table--------------------
		0000: name
		0001: Misa
		---------------------------------------
		0000 0x00030000 ; load name
		0001 0x00090001 ; str "Misa"
		0002 0x0006FFFF ; asign
		0003 0x0080FFFF ; pop

koalajs's People

Contributors

misazhu avatar yorkie avatar

Watchers

ziyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.