#Stair Engine
First of all, we regard global code as a function and treat it accordingly.
##Object Struct
Everything in Stair JS is Object and would be instantiated by a struct
which is implemented by C.
struct Object{
Type type;
char* name;
void* fileds;
char* code;
struct Object* this;
struct Object* outFunction;
char** arguments;
};Fields of this structure would be filled according to its type. ##Dictionary
struct Dict;This data structure would provide a flexiable method to record status of
every object, whose key is name of field and value is object structure.
Thus its structure is {char* : struct Object*}
##FuncProto
We demonstrate basic plain code as FuncProto object which is used in
instantiation of Function. And FuncProto would be instantiated by Interpreter
automatically.
- Flied
typewould be filled byFuncProto. - And interpreter would only fill code with
text. - Besides fileds is set to be
NULL. - Especially, outFunction must be set to the
funtionwhere we define thisfunction. - arguments must be specified explicitly. We pass a list of name to
the
FuncProtowhenever instantiation ofFuncProtohappend.
##Function
Whenever a function is invoked. A Funtion Object would be instantiated by
corresponding FuncProto.
- type would be set to
Function - And fileds would be allocated new memory space, which
represented by a
pointertoDict. - Copy
FuncProto's code toFunction's code filed. - Pass arguments to this structure as well as outFunction.
- This also need to be specified, but it depends on specfic condition.
###Function Invocation
In
Functioninvocations, there are following two situation. f(); this we pass is current localthis. a.f(); And in this situation, this ispointerfoObjecta.
##Object
A Object could be instantiated by Function. Basic operation is like the
way we perform in Function instatiation but this must be a new pointer
to struct Object that we allocate recently.
##Primtive Type
We present Primtive Type in format of Struct Object. However, Javascript
treat her reference mechanism like Java. Its fileds would be corresponding
type. Primtive Type is passed by value.
Thus, we must create a new object as same as original one. Currently, following
Primtive Type is planed to be implemented.
- int
- float
- string
- bool
##Parameter Pass
Parameters would be passed to the fields. And interpretor would scrutinize
the number of parameter is matched or not.
##Return Value
Simply, we just return struct Object.
##Function Closure
In order to accomplish Function Closure, we introduce outFunction.
Interpretor would scan local scope to find current variables. It would find
variables in outFunction if not find in local scope yet. Searching priority
is presented below.
- Local scope
- This
- outFunction Recursively.
##Code Slice
We confine syntas of Stair JS restrictly. Every operand and operator must
be sperated by blank. Similarily semicolon would split every statement.