From 27f00148a157ceea957db6e9cdf79a0fc1e91930 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 5 Jul 2016 15:22:29 +0000 Subject: [PATCH] added a new reserved word - thisProcess --- stix/kernel/Except.st | 7 +++++-- stix/kernel/Process.st | 5 +++-- stix/lib/comp.c | 15 ++++++++++++++- stix/lib/decode.c | 4 ++++ stix/lib/exec.c | 5 +++++ stix/lib/stix-prv.h | 10 ++++++---- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/stix/kernel/Except.st b/stix/kernel/Except.st index 20f42a1..5051db5 100644 --- a/stix/kernel/Except.st +++ b/stix/kernel/Except.st @@ -60,10 +60,13 @@ ## FATAL ERROR - no exception handler. ## ----------------------------------------------------------------- ##thisContext unwindTo: nil return: nil. - thisContext unwindTo: (Processor activeProcess initialContext) return: nil. + ##thisContext unwindTo: (Processor activeProcess initialContext) return: nil. + thisContext unwindTo: (thisProcess initialContext) return: nil. ('### EXCEPTION NOT HANDLED #### ', self class name, ' - ', self messageText) dump. ## TODO: debug the current process???? " - Processor activeProcess terminate. + + ##Processor activeProcess terminate. + thisProcess terminate. } #method signal: text diff --git a/stix/kernel/Process.st b/stix/kernel/Process.st index 3a95aa2..2935936 100644 --- a/stix/kernel/Process.st +++ b/stix/kernel/Process.st @@ -65,7 +65,7 @@ ## ## 2) process terminated by itself ## p := [ - ## [ Processor activeProcess terminate. ] ensure: [System logNl: 'ensured....'] + ## [ thisProcess terminate. ] ensure: [System logNl: 'ensured....'] ## ] newProcess. ## p resume. ## p terminate. @@ -74,7 +74,8 @@ ## the process must not be scheduled. ## ---------------------------------------------------------------------------------------------------------- - (Processor activeProcess ~~ self) ifTrue: [ self _suspend ]. + ##(Processor activeProcess ~~ self) ifTrue: [ self _suspend ]. + (thisProcess ~~ self) ifTrue: [ self _suspend ]. self.current_context unwindTo: self.initial_context return: nil. ^self _terminate } diff --git a/stix/lib/comp.c b/stix/lib/comp.c index f8de4ee..817bcc8 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -103,6 +103,7 @@ static struct voca_t { 4, { 's','e','l','f' } }, { 5, { 's','u','p','e','r' } }, { 11, { 't','h','i','s','C','o','n','t','e','x','t' } }, + { 11, { 't','h','i','s','P','r','o','c','e','s','s' } }, { 4, { 't','r','u','e' } }, { 4, { 'w','o','r','d' } }, @@ -138,6 +139,7 @@ enum voca_id_t VOCA_SELF, VOCA_SUPER, VOCA_THIS_CONTEXT, + VOCA_THIS_PROCESS, VOCA_TRUE, VOCA_WORD, @@ -292,7 +294,8 @@ static int is_reserved_word (const stix_oocs_t* ucs) VOCA_NIL, VOCA_TRUE, VOCA_FALSE, - VOCA_THIS_CONTEXT + VOCA_THIS_CONTEXT, + VOCA_THIS_PROCESS }; int i; @@ -857,6 +860,10 @@ static int get_ident (stix_t* stix, stix_ooci_t char_read_ahead) { stix->c->tok.type = STIX_IOTOK_THIS_CONTEXT; } + else if (is_token_word(stix, VOCA_THIS_PROCESS)) + { + stix->c->tok.type = STIX_IOTOK_THIS_PROCESS; + } } return 0; @@ -3271,6 +3278,7 @@ static int __read_array_literal (stix_t* stix, stix_oop_t* xlit) case STIX_IOTOK_SELF: case STIX_IOTOK_SUPER: case STIX_IOTOK_THIS_CONTEXT: + case STIX_IOTOK_THIS_PROCESS: lit = stix_makesymbol (stix, stix->c->tok.name.ptr, stix->c->tok.name.len); break; @@ -3506,6 +3514,11 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c GET_TOKEN (stix); break; + case STIX_IOTOK_THIS_PROCESS: + if (emit_byte_instruction(stix, BCODE_PUSH_PROCESS) <= -1) return -1; + GET_TOKEN (stix); + break; + case STIX_IOTOK_CHARLIT: STIX_ASSERT (stix->c->tok.name.len == 1); if (add_character_literal(stix, stix->c->tok.name.ptr[0], &index) <= -1 || diff --git a/stix/lib/decode.c b/stix/lib/decode.c index 65ea56c..3d8dac7 100644 --- a/stix/lib/decode.c +++ b/stix/lib/decode.c @@ -415,6 +415,10 @@ return -1; LOG_INST_0 (stix, "push_context"); break; + case BCODE_PUSH_PROCESS: + LOG_INST_0 (stix, "push_process"); + break; + case BCODE_PUSH_NEGONE: LOG_INST_0 (stix, "push_negone"); break; diff --git a/stix/lib/exec.c b/stix/lib/exec.c index 6da6a97..4d72530 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -3787,6 +3787,11 @@ return -1; STIX_STACK_PUSH (stix, (stix_oop_t)stix->active_context); break; + case BCODE_PUSH_PROCESS: + LOG_INST_0 (stix, "push_process"); + STIX_STACK_PUSH (stix, (stix_oop_t)stix->processor->active); + break; + case BCODE_PUSH_NEGONE: LOG_INST_0 (stix, "push_negone"); STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-1)); diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index f445d14..78123af 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -330,6 +330,7 @@ struct stix_iotok_t STIX_IOTOK_TRUE, STIX_IOTOK_FALSE, STIX_IOTOK_THIS_CONTEXT, + STIX_IOTOK_THIS_PROCESS, STIX_IOTOK_IDENT, STIX_IOTOK_IDENT_DOTTED, STIX_IOTOK_BINSEL, @@ -879,10 +880,11 @@ enum stix_bcode_t BCODE_PUSH_TRUE = 0x83, /* 131 */ BCODE_PUSH_FALSE = 0x84, /* 132 */ BCODE_PUSH_CONTEXT = 0x85, /* 133 */ - BCODE_PUSH_NEGONE = 0x86, /* 134 */ - BCODE_PUSH_ZERO = 0x87, /* 135 */ - BCODE_PUSH_ONE = 0x89, /* 137 */ - BCODE_PUSH_TWO = 0x8A, /* 138 */ + BCODE_PUSH_PROCESS = 0x86, /* 134 */ + BCODE_PUSH_NEGONE = 0x87, /* 135 */ + BCODE_PUSH_ZERO = 0x89, /* 137 */ + BCODE_PUSH_ONE = 0x8A, /* 138 */ + BCODE_PUSH_TWO = 0x8B, /* 139 */ BCODE_PUSH_INTLIT = 0xB1, /* 177 */ BCODE_PUSH_NEGINTLIT = 0xB2, /* 178 */