added some code to compile function body

This commit is contained in:
hyunghwan.chung 2015-05-22 15:09:45 +00:00
parent 9910380ebf
commit f5d2a0a0aa
4 changed files with 578 additions and 700 deletions

File diff suppressed because it is too large Load Diff

View File

@ -195,8 +195,14 @@ static char* syntax_error_msg[] =
"} expected", "} expected",
") expected", ") expected",
". expected", ". expected",
"| expected",
"> expected",
"identifier expected",
"integer expected",
"primitive: expected",
"wrong class modifier", "wrong class modifier",
"identifier expected" "wrong function name",
"duplicate argument name"
}; };
int main (int argc, char* argv[]) int main (int argc, char* argv[])

View File

@ -207,9 +207,6 @@ typedef stix_ssize_t (*stix_ioimpl_t) (
stix_ioarg_t* arg stix_ioarg_t* arg
); );
struct stix_iotok_t struct stix_iotok_t
{ {
enum enum
@ -265,8 +262,14 @@ enum stix_synerrnum_t
STIX_SYNERR_RBRACE, /* } expected */ STIX_SYNERR_RBRACE, /* } expected */
STIX_SYNERR_RPAREN, /* ) expected */ STIX_SYNERR_RPAREN, /* ) expected */
STIX_SYNERR_PERIOD, /* . expected */ STIX_SYNERR_PERIOD, /* . expected */
STIX_SYNERR_CLASSMOD, /* wrong class modifier */ STIX_SYNERR_VBAR, /* | expected */
STIX_SYNERR_GT, /* > expected */
STIX_SYNERR_IDENT, /* identifier expected */ STIX_SYNERR_IDENT, /* identifier expected */
STIX_SYNERR_INTEGER, /* integer expected */
STIX_SYNERR_PRIMITIVE, /* primitive: expected */
STIX_SYNERR_CLASSMOD, /* wrong class modifier */
STIX_SYNERR_FUNNAME, /* wrong function name */
STIX_SYNERR_DUPARGNAME /* duplicate argument name */
}; };
typedef enum stix_synerrnum_t stix_synerrnum_t; typedef enum stix_synerrnum_t stix_synerrnum_t;
@ -284,6 +287,177 @@ struct stix_synerr_t
}; };
typedef struct stix_synerr_t stix_synerr_t; typedef struct stix_synerr_t stix_synerr_t;
/*
* The Smalltalk-80 Bytecodes
* Range Bits Function
* -------------------------------------------------------------
* 0-15 0000iiii Push Receiver Variable #iiii
* 16-31 0001iiii Push Temporary Location #iiii
* 32-63 001iiiii Push Literal Constant #iiiii
* 64-95 010iiiii Push Literal Variable #iiiii
* 96-103 01100iii Pop and Store Receiver Variable #iii
* 104-111 01101iii Pop and Store Temporary Location #iii
* 112-119 01110iii Push (receiver, _true, _false, _nil, -1, 0, 1, 2) [iii]
* 120-123 011110ii Return (receiver, _true, _false, _nil) [ii] From Message
* 124-125 0111110i Return Stack Top From (Message, Block) [i]
* 126-127 0111111i unused
* 128 10000000 jjkkkkkk Push (Receiver Variable, Temporary Location, Literal Constant, Literal Variable) [jj] #kkkkkk
* 129 10000001 jjkkkkkk Store (Receiver Variable, Temporary Location, Illegal, Literal Variable) [jj] #kkkkkk
* 130 10000010 jjkkkkkk Pop and Store (Receiver Variable, Temporary Location, Illegal, Literal Variable) [jj] #kkkkkk
* 131 10000011 jjjkkkkk Send Literal Selector #kkkkk With jjj Arguments
* 132 10000100 jjjjjjjj kkkkkkkk Send Literal Selector #kkkkkkkk With jjjjjjjj Arguments
* 133 10000101 jjjkkkkk Send Literal Selector #kkkkk To Superclass With jjj Arguments
* 134 10000110 jjjjjjjj kkkkkkkk Send Literal Selector #kkkkkkkk To Superclass With jjjjjjjj Arguments
* 135 10000111 Pop Stack Top
* 136 10001000 Duplicate Stack Top
* 137 10001001 Push Active Context
* 138-143 unused
* 144-151 10010iii Jump iii + 1 (i.e., 1 through 8)
* 152-159 10011iii Pop and Jump On False iii +1 (i.e., 1 through 8)
* 160-167 10100iii jjjjjjjj Jump(iii - 4) *256+jjjjjjjj
* 168-171 101010ii jjjjjjjj Pop and Jump On True ii *256+jjjjjjjj
* 172-175 101011ii jjjjjjjj Pop and Jump On False ii *256+jjjjjjjj
* 176-191 1011iiii Send Arithmetic Message #iiii
* 192-207 1100iiii Send Special Message #iiii
* 208-223 1101iiii Send Literal Selector #iiii With No Arguments
* 224-239 1110iiii Send Literal Selector #iiii With 1 Argument
* 240-255 1111iiii Send Literal Selector #iiii With 2 Arguments
*/
/**
* The stix_code_t type defines byte-code enumerators.
*/
enum stix_code_id_t
{
/* 0-15 */
STIX_PUSH_RECEIVER_VARIABLE = 0x00,
/* 16-31 */
STIX_PUSH_TEMPORARY_LOCATION = 0x10,
/* 32-63 */
STIX_PUSH_LITERAL_CONSTANT = 0x20,
/* 64-95 */
STIX_PUSH_LITERAL_VARIABLE = 0x40,
/* 96-103 */
STIX_POP_STORE_RECEIVER_VARIABLE = 0x60,
/* 104-111 */
STIX_POP_STORE_TEMPORARY_LOCATION = 0x68,
/* 112-119 */
STIX_PUSH_RECEIVER = 0x70,
STIX_PUSH_TRUE = 0x71,
STIX_PUSH_FALSE = 0x72,
STIX_PUSH_NIL = 0x73,
STIX_PUSH_MINUSONE = 0x74,
STIX_PUSH_ZERO = 0x75,
STIX_PUSH_ONE = 0x76,
STIX_PUSH_TWO = 0x77,
/* 120-123 */
STIX_RETURN_RECEIVER = 0x78,
STIX_RETURN_TRUE = 0x79,
STIX_RETURN_FALSE = 0x7A,
STIX_RETURN_NIL = 0x7B,
/* 124-125 */
STIX_RETURN_FROM_MESSAGE = 0x7C,
STIX_RETURN_FROM_BLOCK = 0x7D,
/* 128 */
STIX_PUSH_EXTENDED = 0x80,
/* 129 */
STIX_STORE_EXTENDED = 0x81,
/* 130 */
STIX_POP_STORE_EXTENDED = 0x82,
/* 131 */
STIX_SEND_TO_SELF = 0x83,
/* 132 */
STIX_SEND_TO_SUPER = 0x84,
/* 133 */
STIX_SEND_TO_SELF_EXTENDED = 0x85,
/* 134 */
STIX_SEND_TO_SUPER_EXTENDED = 0x86,
/* 135 */
STIX_POP_STACK_TOP = 0x87,
/* 136 */
STIX_DUP_STACK_TOP = 0x88,
/* 137 */
STIX_PUSH_ACTIVE_CONTEXT = 0x89,
/* 138 */
STIX_DO_PRIMITIVE = 0x8A,
/* 144-151 */
STIX_JUMP = 0x90,
/* 152-159 */
STIX_POP_JUMP_ON_FALSE = 0x98,
/* 160-167 */
STIX_JUMP_EXTENDED = 0xA0,
/* 168-171 */
STIX_POP_JUMP_ON_TRUE_EXTENDED = 0xA8,
/* 172-175 */
STIX_POP_JUMP_ON_FALSE_EXTENDED = 0xAC,
#if 0
STIX_PUSH_RECEIVER_VARIABLE_EXTENDED = 0x60
STIX_PUSH_TEMPORARY_LOCATION_EXTENDED = 0x61
STIX_PUSH_LITERAL_CONSTANT_EXTENDED = 0x62
STIX_PUSH_LITERAL_VARIABLE_EXTENDED = 0x63
STIX_STORE_RECEIVER_VARIABLE_EXTENDED = 0x64
STIX_STORE_TEMPORARY_LOCATION_EXTENDED = 0x65
STIX_POP_STACK_TOP = 0x67
STIX_DUPLICATE_STACK_TOP = 0x68
STIX_PUSH_ACTIVE_CONTEXT = 0x69
STIX_PUSH_NIL = 0x6A
STIX_PUSH_TRUE = 0x6B
STIX_PUSH_FALSE = 0x6C
STIX_PUSH_RECEIVER = 0x6D
STIX_SEND_TO_SELF = 0x70
STIX_SEND_TO_SUPER = 0x71
STIX_SEND_TO_SELF_EXTENDED = 0x72
STIX_SEND_TO_SUPER_EXTENDED = 0x73
STIX_RETURN_RECEIVER = 0x78
STIX_RETURN_TRUE = 0x79
STIX_RETURN_FALSE = 0x7A
STIX_RETURN_NIL = 0x7B
STIX_RETURN_FROM_MESSAGE = 0x7C
STIX_RETURN_FROM_BLOCK = 0x7D
STIX_DO_PRIMITIVE = 0xF0
#endif
};
typedef enum stix_code_id_t stix_code_id_t;
struct stix_code_t
{
stix_uint8_t* ptr;
stix_size_t len;
};
typedef struct stix_code_t stix_code_t;
struct stix_compiler_t struct stix_compiler_t
{ {
/* input handler */ /* input handler */
@ -308,7 +482,6 @@ struct stix_compiler_t
/* the last token read */ /* the last token read */
stix_iotok_t tok; stix_iotok_t tok;
stix_iolink_t* io_names; stix_iolink_t* io_names;
stix_synerr_t synerr; stix_synerr_t synerr;
@ -324,11 +497,18 @@ struct stix_compiler_t
stix_ucs_t name; stix_ucs_t name;
stix_size_t name_capa; stix_size_t name_capa;
int tmpr_count; /* total number of temporaries including arguments */ /* single string containing a space separated list of temporaries */
int tmpr_nargs; stix_ucs_t tmprs;
stix_size_t tmprs_capa;
stix_size_t tmpr_count; /* total number of temporaries including arguments */
stix_size_t tmpr_nargs;
/* literals */ /* literals */
int literal_count; int literal_count;
stix_code_t code;
stix_size_t code_capa;
} fun; } fun;
}; };

View File

@ -326,168 +326,6 @@ typedef struct stix_obj_uint16_t* stix_oop_uint16_t;
#define STIX_OOW_BITS (STIX_SIZEOF(stix_oow_t) * 8) #define STIX_OOW_BITS (STIX_SIZEOF(stix_oow_t) * 8)
#define STIX_OOP_BITS (STIX_SIZEOF(stix_oop_t) * 8) #define STIX_OOP_BITS (STIX_SIZEOF(stix_oop_t) * 8)
/*
* The Smalltalk-80 Bytecodes
* Range Bits Function
* -------------------------------------------------------------
* 0-15 0000iiii Push Receiver Variable #iiii
* 16-31 0001iiii Push Temporary Location #iiii
* 32-63 001iiiii Push Literal Constant #iiiii
* 64-95 010iiiii Push Literal Variable #iiiii
* 96-103 01100iii Pop and Store Receiver Variable #iii
* 104-111 01101iii Pop and Store Temporary Location #iii
* 112-119 01110iii Push (receiver, _true, _false, _nil, -1, 0, 1, 2) [iii]
* 120-123 011110ii Return (receiver, _true, _false, _nil) [ii] From Message
* 124-125 0111110i Return Stack Top From (Message, Block) [i]
* 126-127 0111111i unused
* 128 10000000 jjkkkkkk Push (Receiver Variable, Temporary Location, Literal Constant, Literal Variable) [jj] #kkkkkk
* 129 10000001 jjkkkkkk Store (Receiver Variable, Temporary Location, Illegal, Literal Variable) [jj] #kkkkkk
* 130 10000010 jjkkkkkk Pop and Store (Receiver Variable, Temporary Location, Illegal, Literal Variable) [jj] #kkkkkk
* 131 10000011 jjjkkkkk Send Literal Selector #kkkkk With jjj Arguments
* 132 10000100 jjjjjjjj kkkkkkkk Send Literal Selector #kkkkkkkk With jjjjjjjj Arguments
* 133 10000101 jjjkkkkk Send Literal Selector #kkkkk To Superclass With jjj Arguments
* 134 10000110 jjjjjjjj kkkkkkkk Send Literal Selector #kkkkkkkk To Superclass With jjjjjjjj Arguments
* 135 10000111 Pop Stack Top
* 136 10001000 Duplicate Stack Top
* 137 10001001 Push Active Context
* 138-143 unused
* 144-151 10010iii Jump iii + 1 (i.e., 1 through 8)
* 152-159 10011iii Pop and Jump On False iii +1 (i.e., 1 through 8)
* 160-167 10100iii jjjjjjjj Jump(iii - 4) *256+jjjjjjjj
* 168-171 101010ii jjjjjjjj Pop and Jump On True ii *256+jjjjjjjj
* 172-175 101011ii jjjjjjjj Pop and Jump On False ii *256+jjjjjjjj
* 176-191 1011iiii Send Arithmetic Message #iiii
* 192-207 1100iiii Send Special Message #iiii
* 208-223 1101iiii Send Literal Selector #iiii With No Arguments
* 224-239 1110iiii Send Literal Selector #iiii With 1 Argument
* 240-255 1111iiii Send Literal Selector #iiii With 2 Arguments
*/
/**
* The stix_code_t type defines byte-code enumerators.
*/
enum stix_code_t
{
/* 0-15 */
STIX_PUSH_RECEIVER_VARIABLE = 0x00,
/* 16-31 */
STIX_PUSH_TEMPORARY_LOCATION = 0x10,
/* 32-63 */
STIX_PUSH_LITERAL_CONSTANT = 0x20,
/* 64-95 */
STIX_PUSH_LITERAL_VARIABLE = 0x40,
/* 96-103 */
STIX_POP_STORE_RECEIVER_VARIABLE = 0x60,
/* 104-111 */
STIX_POP_STORE_TEMPORARY_LOCATION = 0x68,
/* 112-119 */
STIX_PUSH_RECEIVER = 0x70,
STIX_PUSH_TRUE = 0x71,
STIX_PUSH_FALSE = 0x72,
STIX_PUSH_NIL = 0x73,
STIX_PUSH_MINUSONE = 0x74,
STIX_PUSH_ZERO = 0x75,
STIX_PUSH_ONE = 0x76,
STIX_PUSH_TWO = 0x77,
/* 120-123 */
STIX_RETURN_RECEIVER = 0x78,
STIX_RETURN_TRUE = 0x79,
STIX_RETURN_FALSE = 0x7A,
STIX_RETURN_NIL = 0x7B,
/* 124-125 */
STIX_RETURN_FROM_MESSAGE = 0x7C,
STIX_RETURN_FROM_BLOCK = 0x7D,
/* 128 */
STIX_PUSH_EXTENDED = 0x80,
/* 129 */
STIX_STORE_EXTENDED = 0x81,
/* 130 */
STIX_POP_STORE_EXTENDED = 0x82,
/* 131 */
STIX_SEND_TO_SELF = 0x83,
/* 132 */
STIX_SEND_TO_SUPER = 0x84,
/* 133 */
STIX_SEND_TO_SELF_EXTENDED = 0x85,
/* 134 */
STIX_SEND_TO_SUPER_EXTENDED = 0x86,
/* 135 */
STIX_POP_STACK_TOP = 0x87,
/* 136 */
STIX_DUP_STACK_TOP = 0x88,
/* 137 */
STIX_PUSH_ACTIVE_CONTEXT = 0x89,
/* 138 */
STIX_DO_PRIMITIVE = 0x8A,
/* 144-151 */
STIX_JUMP = 0x90,
/* 152-159 */
STIX_POP_JUMP_ON_FALSE = 0x98,
/* 160-167 */
STIX_JUMP_EXTENDED = 0xA0,
/* 168-171 */
STIX_POP_JUMP_ON_TRUE_EXTENDED = 0xA8,
/* 172-175 */
STIX_POP_JUMP_ON_FALSE_EXTENDED = 0xAC,
#if 0
STIX_PUSH_RECEIVER_VARIABLE_EXTENDED = 0x60
STIX_PUSH_TEMPORARY_LOCATION_EXTENDED = 0x61
STIX_PUSH_LITERAL_CONSTANT_EXTENDED = 0x62
STIX_PUSH_LITERAL_VARIABLE_EXTENDED = 0x63
STIX_STORE_RECEIVER_VARIABLE_EXTENDED = 0x64
STIX_STORE_TEMPORARY_LOCATION_EXTENDED = 0x65
STIX_POP_STACK_TOP = 0x67
STIX_DUPLICATE_STACK_TOP = 0x68
STIX_PUSH_ACTIVE_CONTEXT = 0x69
STIX_PUSH_NIL = 0x6A
STIX_PUSH_TRUE = 0x6B
STIX_PUSH_FALSE = 0x6C
STIX_PUSH_RECEIVER = 0x6D
STIX_SEND_TO_SELF = 0x70
STIX_SEND_TO_SUPER = 0x71
STIX_SEND_TO_SELF_EXTENDED = 0x72
STIX_SEND_TO_SUPER_EXTENDED = 0x73
STIX_RETURN_RECEIVER = 0x78
STIX_RETURN_TRUE = 0x79
STIX_RETURN_FALSE = 0x7A
STIX_RETURN_NIL = 0x7B
STIX_RETURN_FROM_MESSAGE = 0x7C
STIX_RETURN_FROM_BLOCK = 0x7D
STIX_DO_PRIMITIVE = 0xF0
#endif
};
typedef enum stix_code_t stix_code_t;
/* /*
* OOP encoding * OOP encoding