diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index 09b7d41..795037a 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -332,7 +332,7 @@ class OrderedCollection(SequenceableCollection) { | i | i := index + self.firstIndex. - if (i >= self.firstIndex and: [i < self.lastIndex]) { ^self.buffer at: index }. + if ((i >= self.firstIndex) and (i < self.lastIndex)) { ^self.buffer at: index }. Exception signal: ('index ' & index asString & ' out of range'). } @@ -341,7 +341,7 @@ class OrderedCollection(SequenceableCollection) ## replace an existing element. it doesn't grow the buffer. | i | i := index + self.firstIndex. - if (i >= self.firstIndex and: [i < self.lastIndex]) { ^self.buffer at: index put: obj }. + if ((i >= self.firstIndex) and (i < self.lastIndex)) { ^self.buffer at: index put: obj }. Exception signal: ('index ' & index asString & ' out of range'). } @@ -433,7 +433,7 @@ class OrderedCollection(SequenceableCollection) method removeFirst: count { | r i | - if (count > self size or: [count < 0]) { Exception signal: 'removal count too big/small' }. + if ((count > self size) or (count < 0)) { Exception signal: 'removal count too big/small' }. r := Array new: count. i := 0. while (i < count) @@ -449,7 +449,7 @@ class OrderedCollection(SequenceableCollection) method removeLast: count { | r i li | - if (count > self size or: [count < 0]) { Exception signal: 'removal count too big/small' }. + if ((count > self size) or (count < 0)) { Exception signal: 'removal count too big/small' }. r := Array new: count. i := 0. while (i < count) @@ -468,7 +468,7 @@ class OrderedCollection(SequenceableCollection) ## remove the element at the given position. | obj | obj := self at: index. ## the range is checed by the at: method. - self __remove_Index(index + self.firstIndex). + self __remove_index(index + self.firstIndex). ^obj } @@ -580,7 +580,7 @@ class OrderedCollection(SequenceableCollection) else { cursize := self size. - if (self.firstIndex > 0 and: [index <= (cursize bitShift: -1)]) + if ((self.firstIndex > 0) and (index <= (cursize bitShift: -1))) { start := self.firstIndex - 1. self.buffer replaceFrom: start to: (start + index - 1) with: self.buffer startingAt: self.firstIndex. @@ -778,7 +778,7 @@ class Set(Collection) { | ass | ass := self __find: key or_upsert: false with: nil. - ^ass key = key and: [ass value = value] + ^(ass key = key) and (ass value = value) } method __find_index: key @@ -818,7 +818,7 @@ class Set(Collection) z := (ass key hash) rem: bs. (* move an element if necessary *) - if ((y > x and: [(z <= x) or: [z > y]]) or: [(y < x) and: [(z <= x) and: [z > y]]]) + if (((y > x) and ((z <= x) or (z > y))) or ((y < x) and ((z <= x) and (z > y)))) { self.bucket at: x put: (self.bucket at: y). x := y. diff --git a/moo/kernel/Except.moo b/moo/kernel/Except.moo index 067ebfe..2fc19e8 100644 --- a/moo/kernel/Except.moo +++ b/moo/kernel/Except.moo @@ -51,7 +51,8 @@ TODO: can i convert 'thisProcess primError' to a relevant exception? while (exctx notNil) { exblk := exctx findExceptionHandlerFor: (self class). - if (exblk notNil and: [actpos := exctx basicSize - 1. exctx basicAt: actpos]) + ##if (exblk notNil and: [actpos := exctx basicSize - 1. exctx basicAt: actpos]) + if ((exblk notNil) and (exctx basicAt: (actpos := exctx basicSize - 1))) { self.handlerContext := exctx. exctx basicAt: actpos put: false. @@ -119,7 +120,7 @@ System logNl: '== END OF BACKTRACE =='. ## TODO: verify if return:to: causes unnecessary stack growth. ## is this correct??? | ctx | - if (self.signalContext notNil and: [self.handlerContext notNil]) + if ((self.signalContext notNil) and (self.handlerContext notNil)) { ctx := self.signalContext sender. self.signalContext := nil. @@ -272,7 +273,7 @@ extend MethodContext while (i < size) { exc := self basicAt: i. - if ((exception_class == exc) or: [exception_class inheritsFrom: exc]) + if ((exception_class == exc) or (exception_class inheritsFrom: exc)) { ^self basicAt: (i + 1). }. @@ -301,7 +302,7 @@ extend MethodContext actpos := (self basicSize) - 1. excblk := self findExceptionHandlerFor: (exception class). - if (excblk isNil or: [(self basicAt: actpos) not]) + if ((excblk isNil) or ((self basicAt: actpos) not)) { ## self is an exception context but doesn't have a matching ## exception handler or the exception context is already diff --git a/moo/kernel/Magnitu.moo b/moo/kernel/Magnitu.moo index 15fbfd9..47ff68a 100644 --- a/moo/kernel/Magnitu.moo +++ b/moo/kernel/Magnitu.moo @@ -7,17 +7,20 @@ class Magnitude(Object) method between: min and: max { - ^self >= min and: [self <= max] + ^self >= min and self <= max } method min: aMagnitude { - ^self < aMagnitude ifTrue: [self] ifFalse: [aMagnitude] + ##^self < aMagnitude ifTrue: [self] ifFalse: [aMagnitude] + ^if (self < aMagnitude) { self } else { aMagnitude }. } method max: aMagnitude { - ^self > aMagnitude ifTrue: [self] ifFalse: [aMagnitude] + ##^self > aMagnitude ifTrue: [self] ifFalse: [aMagnitude] + ^if (self > aMagnitude) { self } else { aMagnitude }. + } } @@ -53,7 +56,7 @@ class Association(Magnitude) method = ass { - ^(self.key = ass key) and: [ self.value = ass value ] + ^(self.key = ass key) and (self.value = ass value) } method hash @@ -85,15 +88,15 @@ class(#limited) Character(Magnitude) { ## - if (self >= $0 and: [self <= $9]) + if ((self >= $0) and (self <= $9)) { ^self asInteger - $0 asInteger } - elsif (self >= $A and: [self <= $Z]) + elsif ((self >= $A) and (self <= $Z)) { ^self asInteger - $A asInteger + 10 } - elsif (self >= $a and: [self <= $z]) + elsif ((self >= $a) and (self <= $z)) { ^self asInteger - $a asInteger + 10 }. diff --git a/moo/kernel/Process.moo b/moo/kernel/Process.moo index 770ed46..58edd63 100644 --- a/moo/kernel/Process.moo +++ b/moo/kernel/Process.moo @@ -395,7 +395,7 @@ class SemaphoreHeap(Object) left := self leftChildIndex: cindex. right := self rightChildIndex: cindex. - younger := if ((right < self.size) and: [(self.arr at: right) youngerThan: (self.arr at: left)]) { right } else { left }. + younger := if ((right < self.size) and ((self.arr at: right) youngerThan: (self.arr at: left))) { right } else { left }. xitem := self.arr at: younger. if (item youngerThan: xitem) { break }. diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index 809528e..a401dbe 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -54,13 +54,13 @@ class(#byte(4)) IP4Address(IPAddress) c := str at: pos. pos := pos + 1. - if (c >= $0 and: [c <= $9]) + if ((c >= $0) and (c <= $9)) { acc := acc * 10 + (c asInteger - $0 asInteger). if (acc > 255) { Exception signal: ('invalid IPv4 address B ' & str). }. digits := digits + 1. } - elsif (c = $.) + elsif (c == $.) { if (dots >= 3 or: [digits == 0]) { ^Error.Code.EINVAL }. self basicAt: (dots + address_offset) put: acc. @@ -113,7 +113,7 @@ class(#byte(16)) IP6Address(IP4Address) mysize := self basicSize. ## handle leading :: specially - if (size > 0 and: [(str at: pos) == $:]) + if ((size > 0) and ((str at: pos) == $:)) { pos := pos + 1. if (pos >= size or: [ (str at: pos) ~~ $:]) { ^Error.Code.EINVAL }. @@ -131,7 +131,7 @@ class(#byte(16)) IP6Address(IP4Address) pos := pos + 1. v1 := ch digitValue. - if (v1 >= 0 and: [v1 <= 15]) + if ((v1 >= 0) and (v1 <= 15)) { val := (val bitShift: 4) bitOr: v1. if (val > 16rFFFF) { ^Error.Code.EINVAL }. @@ -168,7 +168,7 @@ class(#byte(16)) IP6Address(IP4Address) continue. }. - if (ch == $. and: [tgpos + 4 <= mysize]) + if ((ch == $.) and (tgpos + 4 <= mysize)) { ##if ((super __fromString: (str copyFrom: curseg) offset:0 offset: tgpos) isError) { ^Error.Code.EINVAL }. if ((super __fromString: str offset: curseg offset: tgpos) isError) { ^Error.Code.EINVAL }. diff --git a/moo/kernel/generr.moo b/moo/kernel/generr.moo index 26b62b7..d041238 100644 --- a/moo/kernel/generr.moo +++ b/moo/kernel/generr.moo @@ -164,7 +164,7 @@ class MyObject(Object) 0 to: c do: [:i | | ch | ch := s at: i. - if (ch == $\ or: [ch == $"]) + if ((ch == $\) or (ch == $")) { f putc($', $\, (s at: i), $'). } diff --git a/moo/lib/comp.c b/moo/lib/comp.c index a932ddf..9aae21a 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -2250,8 +2250,8 @@ static int emit_single_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1 case BCODE_JUMP_FORWARD_0: case BCODE_JUMP_BACKWARD_0: - case BCODE_JUMP_BACKWARD_IF_FALSE_0: - case BCODE_JUMP_BACKWARD_IF_TRUE_0: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_0: + case BCODE_JUMPOP_BACKWARD_IF_TRUE_0: if (param_1 < 4) { /* low 2 bits to hold the parameter */ @@ -2271,11 +2271,13 @@ static int emit_single_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1 } case BCODE_JUMP_BACKWARD_X: - case BCODE_JUMP_BACKWARD_IF_FALSE_X: - case BCODE_JUMP_BACKWARD_IF_TRUE_X: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_X: + case BCODE_JUMPOP_BACKWARD_IF_TRUE_X: case BCODE_JUMP_FORWARD_X: - case BCODE_JUMP_FORWARD_IF_FALSE: case BCODE_JUMP_FORWARD_IF_TRUE: + case BCODE_JUMP_FORWARD_IF_FALSE: + case BCODE_JUMPOP_FORWARD_IF_FALSE: + case BCODE_JUMPOP_FORWARD_IF_TRUE: if (param_1 > MAX_CODE_JUMP) { cmd = cmd + 1; /* convert to a JUMP2 instruction */ @@ -2283,11 +2285,13 @@ static int emit_single_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1 } /* fall thru */ case BCODE_JUMP2_FORWARD: - case BCODE_JUMP2_BACKWARD: - case BCODE_JUMP2_BACKWARD_IF_FALSE: - case BCODE_JUMP2_BACKWARD_IF_TRUE: - case BCODE_JUMP2_FORWARD_IF_FALSE: case BCODE_JUMP2_FORWARD_IF_TRUE: + case BCODE_JUMP2_FORWARD_IF_FALSE: + case BCODE_JUMP2_BACKWARD: + case BCODE_JUMPOP2_BACKWARD_IF_FALSE: + case BCODE_JUMPOP2_BACKWARD_IF_TRUE: + case BCODE_JUMPOP2_FORWARD_IF_FALSE: + case BCODE_JUMPOP2_FORWARD_IF_TRUE: case BCODE_PUSH_INTLIT: case BCODE_PUSH_NEGINTLIT: case BCODE_PUSH_CHARLIT: @@ -2441,8 +2445,8 @@ static MOO_INLINE int emit_backward_jump_instruction (moo_t* moo, int cmd, moo_o moo_oow_t adj; MOO_ASSERT (moo, cmd == BCODE_JUMP_BACKWARD_0 || - cmd == BCODE_JUMP_BACKWARD_IF_FALSE_0 || - cmd == BCODE_JUMP_BACKWARD_IF_TRUE_0); + cmd == BCODE_JUMPOP_BACKWARD_IF_FALSE_0 || + cmd == BCODE_JUMPOP_BACKWARD_IF_TRUE_0); /* the short BCODE_JUMP_BACKWARD instructions use low 2 bits to encode * the jump offset. so it can encode 0, 1, 2, 3. the instruction itself @@ -2475,7 +2479,9 @@ static int patch_long_forward_jump_instruction (moo_t* moo, moo_oow_t jip, moo_o MOO_ASSERT (moo, moo->c->mth.code.ptr[jip] == BCODE_JUMP_FORWARD_X || moo->c->mth.code.ptr[jip] == BCODE_JUMP_FORWARD_IF_FALSE || - moo->c->mth.code.ptr[jip] == BCODE_JUMP_FORWARD_IF_TRUE); + moo->c->mth.code.ptr[jip] == BCODE_JUMP_FORWARD_IF_TRUE || + moo->c->mth.code.ptr[jip] == BCODE_JUMPOP_FORWARD_IF_FALSE || + moo->c->mth.code.ptr[jip] == BCODE_JUMPOP_FORWARD_IF_TRUE); if (code_size > MAX_CODE_JUMP) { @@ -5534,23 +5540,16 @@ start_over: } #endif - - if (TOKEN_TYPE(moo) == MOO_IOTOK_AND) + if (TOKEN_TYPE(moo) == MOO_IOTOK_AND || TOKEN_TYPE(moo) == MOO_IOTOK_OR) { + int bcode; + bcode = (TOKEN_TYPE(moo) == MOO_IOTOK_AND)? BCODE_JUMP_FORWARD_IF_FALSE: BCODE_JUMP_FORWARD_IF_TRUE; + /* TODO: optimization if the expression is a known constant that can be determined to be boolean */ if (add_to_oow_pool(moo, &jumptoend, moo->c->mth.code.len) <= -1 || - emit_single_param_instruction(moo, BCODE_JUMP_FORWARD_IF_FALSE, MAX_CODE_JUMP) <= -1 || - emit_byte_instruction(moo, BCODE_POP_STACKTOP) <= -1) goto oops; + emit_single_param_instruction(moo, bcode, MAX_CODE_JUMP) <= -1) goto oops; GET_TOKEN (moo); goto start_over; } - else if (TOKEN_TYPE(moo) == MOO_IOTOK_OR) - { - if (add_to_oow_pool(moo, &jumptoend, moo->c->mth.code.len) <= -1 || - emit_single_param_instruction(moo, BCODE_JUMP_FORWARD_IF_TRUE, MAX_CODE_JUMP) <= -1 || - emit_byte_instruction(moo, BCODE_POP_STACKTOP) <= -1) goto oops; - GET_TOKEN (moo); - goto start_over; - } /* patch instructions that jumps to the end of if expression */ for (jumptoend_chunk = jumptoend.head, i = 0; jumptoend_chunk; jumptoend_chunk = jumptoend_chunk->next) @@ -5694,11 +5693,11 @@ static int compile_if_expression (moo_t* moo) } else { - /* remember position of the jump_forward_if_false instruction to be generated */ + /* remember position of the jumpop_forward_if_false instruction to be generated */ jumptonext = moo->c->mth.code.len; - /* BCODE_JUMP_FORWARD_IF_FALSE is always a long jump instruction. + /* BCODE_JUMPOP_FORWARD_IF_FALSE is always a long jump instruction. * just specify MAX_CODE_JUMP for consistency with short jump variants */ - if (emit_single_param_instruction (moo, BCODE_JUMP_FORWARD_IF_FALSE, MAX_CODE_JUMP) <= -1) goto oops; + if (emit_single_param_instruction (moo, BCODE_JUMPOP_FORWARD_IF_FALSE, MAX_CODE_JUMP) <= -1) goto oops; } GET_TOKEN (moo); /* get { */ @@ -5827,9 +5826,9 @@ static int compile_while_expression (moo_t* moo) /* or compile_until_expression if (cond_style != 1) { - /* BCODE_JUMP_FORWARD_IF_FALSE is always a long jump instruction. + /* BCODE_JUMPOP_FORWARD_IF_FALSE is always a long jump instruction. * just specify MAX_CODE_JUMP for consistency with short jump variants */ - if (emit_single_param_instruction (moo, (is_until_loop? BCODE_JUMP_FORWARD_IF_TRUE: BCODE_JUMP_FORWARD_IF_FALSE), MAX_CODE_JUMP) <= -1) goto oops; + if (emit_single_param_instruction (moo, (is_until_loop? BCODE_JUMPOP_FORWARD_IF_TRUE: BCODE_JUMPOP_FORWARD_IF_FALSE), MAX_CODE_JUMP) <= -1) goto oops; } /* remember information about this while loop. */ @@ -5954,7 +5953,7 @@ static int compile_do_while_expression (moo_t* moo) if (compile_conditional (moo) <= -1) goto oops; postcondpos = moo->c->mth.code.len; - jbinst = (is_until_loop? BCODE_JUMP_BACKWARD_IF_FALSE_0: BCODE_JUMP_BACKWARD_IF_TRUE_0); + jbinst = (is_until_loop? BCODE_JUMPOP_BACKWARD_IF_FALSE_0: BCODE_JUMPOP_BACKWARD_IF_TRUE_0); if (precondpos + 1 == postcondpos) { /* simple optimization - diff --git a/moo/lib/decode.c b/moo/lib/decode.c index 5569781..dacd45d 100644 --- a/moo/lib/decode.c +++ b/moo/lib/decode.c @@ -264,41 +264,6 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn) LOG_INST_1 (moo, "jump_backward %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ break; - - case BCODE_JUMP_BACKWARD_IF_FALSE_X: - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST_1 (moo, "jump_backward_if_false %zu", b1); - break; - - case BCODE_JUMP_BACKWARD_IF_FALSE_0: - case BCODE_JUMP_BACKWARD_IF_FALSE_1: - case BCODE_JUMP_BACKWARD_IF_FALSE_2: - case BCODE_JUMP_BACKWARD_IF_FALSE_3: - LOG_INST_1 (moo, "jump_backward_if_false %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ - break; - - case BCODE_JUMP_BACKWARD_IF_TRUE_X: - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST_1 (moo, "jump_backward_if_true %zu", b1); - break; - - case BCODE_JUMP_BACKWARD_IF_TRUE_0: - case BCODE_JUMP_BACKWARD_IF_TRUE_1: - case BCODE_JUMP_BACKWARD_IF_TRUE_2: - case BCODE_JUMP_BACKWARD_IF_TRUE_3: - LOG_INST_1 (moo, "jump_backward_if_true %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ - break; - - case BCODE_JUMP_FORWARD_IF_FALSE: - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST_1 (moo, "jump_forward_if_false %zu", b1); - break; - - case BCODE_JUMP_FORWARD_IF_TRUE: - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST_1 (moo, "jump_forward_if_true %zu", b1); - break; - case BCODE_JUMP2_FORWARD: FETCH_PARAM_CODE_TO (moo, b1); LOG_INST_1 (moo, "jump2_forward %zu", b1); @@ -309,19 +274,73 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn) LOG_INST_1 (moo, "jump2_backward %zu", b1); break; + case BCODE_JUMP_FORWARD_IF_TRUE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump_forward_if_true %zu", b1); + break; + + case BCODE_JUMP_FORWARD_IF_FALSE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump_forward_if_false %zu", b1); + break; + + case BCODE_JUMP2_FORWARD_IF_TRUE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump2_forward_if_true %zu", b1); + break; + case BCODE_JUMP2_FORWARD_IF_FALSE: FETCH_PARAM_CODE_TO (moo, b1); LOG_INST_1 (moo, "jump2_forward_if_false %zu", b1); break; - case BCODE_JUMP2_BACKWARD_IF_FALSE: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_X: FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST_1 (moo, "jump2_backward_if_false %zu", b1); + LOG_INST_1 (moo, "jumpop_backward_if_false %zu", b1); break; - case BCODE_JUMP2_BACKWARD_IF_TRUE: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_0: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_1: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_2: + case BCODE_JUMPOP_BACKWARD_IF_FALSE_3: + LOG_INST_1 (moo, "jumpop_backward_if_false %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ + break; + + case BCODE_JUMPOP_BACKWARD_IF_TRUE_X: FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST_1 (moo, "jump2_backward_if_true %zu", b1); + LOG_INST_1 (moo, "jumpop_backward_if_true %zu", b1); + break; + + case BCODE_JUMPOP_BACKWARD_IF_TRUE_0: + case BCODE_JUMPOP_BACKWARD_IF_TRUE_1: + case BCODE_JUMPOP_BACKWARD_IF_TRUE_2: + case BCODE_JUMPOP_BACKWARD_IF_TRUE_3: + LOG_INST_1 (moo, "jumpop_backward_if_true %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ + break; + + case BCODE_JUMPOP_FORWARD_IF_FALSE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jumpop_forward_if_false %zu", b1); + break; + + case BCODE_JUMPOP_FORWARD_IF_TRUE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jumpop_forward_if_true %zu", b1); + break; + + case BCODE_JUMPOP2_FORWARD_IF_FALSE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jumpop2_forward_if_false %zu", b1); + break; + + case BCODE_JUMPOP2_BACKWARD_IF_FALSE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jumpop2_backward_if_false %zu", b1); + break; + + case BCODE_JUMPOP2_BACKWARD_IF_TRUE: + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jumpop2_backward_if_true %zu", b1); break; /* -------------------------------------------------------- */ diff --git a/moo/lib/exec.c b/moo/lib/exec.c index aa299ac..73c3bd7 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -4939,55 +4939,6 @@ static int __execute (moo_t* moo) moo->ip -= (bcode & 0x3); /* low 2 bits */ NEXT_INST(); - ON_INST(BCODE_JUMP_BACKWARD_IF_FALSE_X) - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump_backward_if_false %zu", b1); - if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip -= b1; - MOO_STACK_POP (moo); - NEXT_INST(); - - ON_INST(BCODE_JUMP_BACKWARD_IF_FALSE_0) - ON_INST(BCODE_JUMP_BACKWARD_IF_FALSE_1) - ON_INST(BCODE_JUMP_BACKWARD_IF_FALSE_2) - ON_INST(BCODE_JUMP_BACKWARD_IF_FALSE_3) - LOG_INST1 (moo, "jump_backward_if_false %zu", (moo_oow_t)(bcode & 0x3)); - if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip -= (bcode & 0x3); /* low 2 bits */ - MOO_STACK_POP (moo); - NEXT_INST(); - - ON_INST(BCODE_JUMP_BACKWARD_IF_TRUE_X) - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump_backward_if_true %zu", b1); - /*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= b1;*/ - if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= b1; - MOO_STACK_POP (moo); - NEXT_INST(); - - ON_INST(BCODE_JUMP_BACKWARD_IF_TRUE_0) - ON_INST(BCODE_JUMP_BACKWARD_IF_TRUE_1) - ON_INST(BCODE_JUMP_BACKWARD_IF_TRUE_2) - ON_INST(BCODE_JUMP_BACKWARD_IF_TRUE_3) - LOG_INST1 (moo, "jump_backward_if_true %zu", (moo_oow_t)(bcode & 0x3)); - /*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= (bcode & 0x3);*/ /* low 2 bits */ - if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= (bcode & 0x3); - MOO_STACK_POP (moo); - NEXT_INST(); - - ON_INST(BCODE_JUMP_FORWARD_IF_FALSE) - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump_forward_if_false %zu", b1); - if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip += b1; - MOO_STACK_POP (moo); - NEXT_INST(); - - ON_INST(BCODE_JUMP_FORWARD_IF_TRUE) - FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump_forward_if_true %zu", b1); - /*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip += b1;*/ - if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip += b1; - MOO_STACK_POP (moo); - NEXT_INST(); - ON_INST(BCODE_JUMP2_FORWARD) FETCH_PARAM_CODE_TO (moo, b1); LOG_INST1 (moo, "jump2_forward %zu", b1); @@ -5000,31 +4951,103 @@ static int __execute (moo_t* moo) moo->ip -= MAX_CODE_JUMP + b1; NEXT_INST(); - ON_INST(BCODE_JUMP2_FORWARD_IF_FALSE) + ON_INST(BCODE_JUMP_FORWARD_IF_TRUE) FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump2_forward_if_false %zu", b1); - if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip += MAX_CODE_JUMP + b1; - MOO_STACK_POP (moo); + LOG_INST1 (moo, "jump_forward_if_true %zu", b1); + if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip += b1; + NEXT_INST(); + + ON_INST(BCODE_JUMP_FORWARD_IF_FALSE) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jump_forward_if_false %zu", b1); + if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip += b1; NEXT_INST(); ON_INST(BCODE_JUMP2_FORWARD_IF_TRUE) FETCH_PARAM_CODE_TO (moo, b1); LOG_INST1 (moo, "jump2_forward_if_true %zu", b1); - /*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip += MAX_CODE_JUMP + b1;*/ + if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip += MAX_CODE_JUMP + b1; + NEXT_INST(); + + ON_INST(BCODE_JUMP2_FORWARD_IF_FALSE) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jump2_forward_if_false %zu", b1); + if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip += MAX_CODE_JUMP + b1; + NEXT_INST(); + + + ON_INST(BCODE_JUMPOP_BACKWARD_IF_FALSE_X) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jumpop_backward_if_false %zu", b1); + if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip -= b1; + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP_BACKWARD_IF_FALSE_0) + ON_INST(BCODE_JUMPOP_BACKWARD_IF_FALSE_1) + ON_INST(BCODE_JUMPOP_BACKWARD_IF_FALSE_2) + ON_INST(BCODE_JUMPOP_BACKWARD_IF_FALSE_3) + LOG_INST1 (moo, "jumpop_backward_if_false %zu", (moo_oow_t)(bcode & 0x3)); + if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip -= (bcode & 0x3); /* low 2 bits */ + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP_BACKWARD_IF_TRUE_X) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jumpop_backward_if_true %zu", b1); + /*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= b1;*/ + if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= b1; + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP_BACKWARD_IF_TRUE_0) + ON_INST(BCODE_JUMPOP_BACKWARD_IF_TRUE_1) + ON_INST(BCODE_JUMPOP_BACKWARD_IF_TRUE_2) + ON_INST(BCODE_JUMPOP_BACKWARD_IF_TRUE_3) + LOG_INST1 (moo, "jumpop_backward_if_true %zu", (moo_oow_t)(bcode & 0x3)); + /*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= (bcode & 0x3);*/ /* low 2 bits */ + if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= (bcode & 0x3); + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP_FORWARD_IF_FALSE) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jumpop_forward_if_false %zu", b1); + if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip += b1; + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP_FORWARD_IF_TRUE) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jumpop_forward_if_true %zu", b1); + if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip += b1; + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP2_FORWARD_IF_FALSE) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jumpop2_forward_if_false %zu", b1); + if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip += MAX_CODE_JUMP + b1; + MOO_STACK_POP (moo); + NEXT_INST(); + + ON_INST(BCODE_JUMPOP2_FORWARD_IF_TRUE) + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST1 (moo, "jumpop2_forward_if_true %zu", b1); if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip += MAX_CODE_JUMP + b1; MOO_STACK_POP (moo); NEXT_INST(); - ON_INST(BCODE_JUMP2_BACKWARD_IF_FALSE) + ON_INST(BCODE_JUMPOP2_BACKWARD_IF_FALSE) FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump2_backward_if_false %zu", b1); + LOG_INST1 (moo, "jumpop2_backward_if_false %zu", b1); if (MOO_STACK_GETTOP(moo) == moo->_false) moo->ip -= MAX_CODE_JUMP + b1; MOO_STACK_POP (moo); NEXT_INST(); - ON_INST(BCODE_JUMP2_BACKWARD_IF_TRUE) + ON_INST(BCODE_JUMPOP2_BACKWARD_IF_TRUE) FETCH_PARAM_CODE_TO (moo, b1); - LOG_INST1 (moo, "jump2_backward_if_true %zu", b1); + LOG_INST1 (moo, "jumpop2_backward_if_true %zu", b1); /* if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= MAX_CODE_JUMP + b1; */ if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= MAX_CODE_JUMP + b1; MOO_STACK_POP (moo); diff --git a/moo/lib/moo-bct.h b/moo/lib/moo-bct.h index c21012c..e1de61a 100644 --- a/moo/lib/moo-bct.h +++ b/moo/lib/moo-bct.h @@ -76,14 +76,14 @@ /* 73 */ &&case_BCODE_JUMP_BACKWARD_1, /* 74 */ &&case_BCODE_JUMP_BACKWARD_2, /* 75 */ &&case_BCODE_JUMP_BACKWARD_3, - /* 76 */ &&case_BCODE_JUMP_BACKWARD_IF_FALSE_0, - /* 77 */ &&case_BCODE_JUMP_BACKWARD_IF_FALSE_1, - /* 78 */ &&case_BCODE_JUMP_BACKWARD_IF_FALSE_2, - /* 79 */ &&case_BCODE_JUMP_BACKWARD_IF_FALSE_3, - /* 80 */ &&case_BCODE_JUMP_BACKWARD_IF_TRUE_0, - /* 81 */ &&case_BCODE_JUMP_BACKWARD_IF_TRUE_1, - /* 82 */ &&case_BCODE_JUMP_BACKWARD_IF_TRUE_2, - /* 83 */ &&case_BCODE_JUMP_BACKWARD_IF_TRUE_3, + /* 76 */ &&case_BCODE_JUMPOP_BACKWARD_IF_FALSE_0, + /* 77 */ &&case_BCODE_JUMPOP_BACKWARD_IF_FALSE_1, + /* 78 */ &&case_BCODE_JUMPOP_BACKWARD_IF_FALSE_2, + /* 79 */ &&case_BCODE_JUMPOP_BACKWARD_IF_FALSE_3, + /* 80 */ &&case_BCODE_JUMPOP_BACKWARD_IF_TRUE_0, + /* 81 */ &&case_BCODE_JUMPOP_BACKWARD_IF_TRUE_1, + /* 82 */ &&case_BCODE_JUMPOP_BACKWARD_IF_TRUE_2, + /* 83 */ &&case_BCODE_JUMPOP_BACKWARD_IF_TRUE_3, /* 84 */ &&case_DEFAULT, /* 85 */ &&case_DEFAULT, /* 86 */ &&case_DEFAULT, @@ -198,24 +198,24 @@ /* 195 */ &&case_DEFAULT, /* 196 */ &&case_BCODE_JUMP_FORWARD_X, /* 197 */ &&case_BCODE_JUMP2_FORWARD, - /* 198 */ &&case_DEFAULT, - /* 199 */ &&case_DEFAULT, + /* 198 */ &&case_BCODE_JUMP_FORWARD_IF_TRUE, + /* 199 */ &&case_BCODE_JUMP2_FORWARD_IF_TRUE, /* 200 */ &&case_BCODE_JUMP_BACKWARD_X, /* 201 */ &&case_BCODE_JUMP2_BACKWARD, /* 202 */ &&case_DEFAULT, /* 203 */ &&case_DEFAULT, - /* 204 */ &&case_BCODE_JUMP_BACKWARD_IF_FALSE_X, - /* 205 */ &&case_BCODE_JUMP2_BACKWARD_IF_FALSE, + /* 204 */ &&case_BCODE_JUMPOP_BACKWARD_IF_FALSE_X, + /* 205 */ &&case_BCODE_JUMPOP2_BACKWARD_IF_FALSE, /* 206 */ &&case_DEFAULT, /* 207 */ &&case_DEFAULT, - /* 208 */ &&case_BCODE_JUMP_BACKWARD_IF_TRUE_X, - /* 209 */ &&case_BCODE_JUMP2_BACKWARD_IF_TRUE, - /* 210 */ &&case_DEFAULT, - /* 211 */ &&case_DEFAULT, - /* 212 */ &&case_BCODE_JUMP_FORWARD_IF_FALSE, - /* 213 */ &&case_BCODE_JUMP2_FORWARD_IF_FALSE, - /* 214 */ &&case_BCODE_JUMP_FORWARD_IF_TRUE, - /* 215 */ &&case_BCODE_JUMP2_FORWARD_IF_TRUE, + /* 208 */ &&case_BCODE_JUMPOP_BACKWARD_IF_TRUE_X, + /* 209 */ &&case_BCODE_JUMPOP2_BACKWARD_IF_TRUE, + /* 210 */ &&case_BCODE_JUMP_FORWARD_IF_FALSE, + /* 211 */ &&case_BCODE_JUMP2_FORWARD_IF_FALSE, + /* 212 */ &&case_BCODE_JUMPOP_FORWARD_IF_FALSE, + /* 213 */ &&case_BCODE_JUMPOP2_FORWARD_IF_FALSE, + /* 214 */ &&case_BCODE_JUMPOP_FORWARD_IF_TRUE, + /* 215 */ &&case_BCODE_JUMPOP2_FORWARD_IF_TRUE, /* 216 */ &&case_BCODE_STORE_INTO_CTXTEMPVAR_X, /* 217 */ &&case_DEFAULT, /* 218 */ &&case_DEFAULT, diff --git a/moo/lib/moo-prv.h b/moo/lib/moo-prv.h index 3a0844a..6bc336b 100644 --- a/moo/lib/moo-prv.h +++ b/moo/lib/moo-prv.h @@ -54,13 +54,11 @@ /*#define MOO_DEBUG_LEXER 1*/ #define MOO_DEBUG_COMPILER 1 #define MOO_DEBUG_VM_PROCESSOR 1 -#define MOO_DEBUG_VM_EXEC +/*#define MOO_DEBUG_VM_EXEC*/ #define MOO_PROFILE_VM 1 #endif - - /* allow the caller to drive process switching by calling * moo_switchprocess(). */ #define MOO_EXTERNAL_PROCESS_SWITCH @@ -714,17 +712,21 @@ SHORT INSTRUCTION CODE LONG INSTRUCTION C 68-71 0100 01XX JUMP_FORWARD 196 1100 0100 XXXXXXXX JUMP_FORWARD_X - 197 1000 0101 XXXXXXXX JUMP2_FORWARD + 197 1100 0101 XXXXXXXX JUMP2_FORWARD + 198 1100 0110 XXXXXXXX JUMP_FORWARD_IF_TRUE + 199 1100 0111 XXXXXXXX JUMP2_FORWARD_IF_TRUE 72-75 0100 10XX JUMP_BACKWARD 200 1100 1000 XXXXXXXX JUMP_BACKWARD_X 201 1101 1001 XXXXXXXX JUMP2_BACKWARD -76-79 0100 11XX JUMP_BACKWARD_IF_FALSE 204 1100 1100 XXXXXXXX JUMP_BACKWARD_IF_FALSE_X - 205 1101 1101 XXXXXXXX JUMP2_BACKWARD_IF_FALSE -80-83 0101 00XX JUMP_BACKWARD_IF_TRUE 208 1101 0000 XXXXXXXX JUMP_BACKWARD_IF_TRUE_X - 209 1101 0001 XXXXXXXX JUMP2_FORWARD_IF_TRUE -84-87 0101 01XX UNUSED 212 1101 0100 XXXXXXXX JUMP_FORWARD_IF_FALSE - 213 1101 0101 XXXXXXXX JUMP2_FORWARD_IF_FALSE - 214 1101 0110 XXXXXXXX JUMP_FORWARD_IF_TRUE - 215 1101 0111 XXXXXXXX JUMP2_FORWARD_IF_TRUE +76-79 0100 11XX JUMPOP_BACKWARD_IF_FALSE 204 1100 1100 XXXXXXXX JUMPOP_BACKWARD_IF_FALSE_X + 205 1101 1101 XXXXXXXX JUMPOP2_BACKWARD_IF_FALSE +80-83 0101 00XX JUMPOP_BACKWARD_IF_TRUE 208 1101 0000 XXXXXXXX JUMPOP_BACKWARD_IF_TRUE_X + 209 1101 0001 XXXXXXXX JUMPOP2_FORWARD_IF_TRUE +84-87 0101 01XX UNUSED 210 1101 0010 XXXXXXXX JUMP_FORWARD_IF_FALSE + 211 1101 0011 XXXXXXXX JUMP2_FORWARD_IF_FALSE + 212 1101 0100 XXXXXXXX JUMPOP_FORWARD_IF_FALSE + 213 1101 0101 XXXXXXXX JUMPOP2_FORWARD_IF_FALSE + 214 1101 0110 XXXXXXXX JUMPOP_FORWARD_IF_TRUE + 215 1101 0111 XXXXXXXX JUMPOP2_FORWARD_IF_TRUE vv 88-91 0101 10XX YYYYYYYY STORE_INTO_CTXTEMPVAR 216 1101 1000 XXXXXXXX YYYYYYYY STORE_INTO_CTXTEMPVAR_X (bit 3 on, bit 2 off) @@ -850,15 +852,15 @@ enum moo_bcode_t BCODE_JUMP_BACKWARD_2 = 0x4A, /* 74 */ BCODE_JUMP_BACKWARD_3 = 0x4B, /* 75 */ - BCODE_JUMP_BACKWARD_IF_FALSE_0 = 0x4C, /* 76 */ - BCODE_JUMP_BACKWARD_IF_FALSE_1 = 0x4D, /* 77 */ - BCODE_JUMP_BACKWARD_IF_FALSE_2 = 0x4E, /* 78 */ - BCODE_JUMP_BACKWARD_IF_FALSE_3 = 0x4F, /* 79 */ + BCODE_JUMPOP_BACKWARD_IF_FALSE_0 = 0x4C, /* 76 */ + BCODE_JUMPOP_BACKWARD_IF_FALSE_1 = 0x4D, /* 77 */ + BCODE_JUMPOP_BACKWARD_IF_FALSE_2 = 0x4E, /* 78 */ + BCODE_JUMPOP_BACKWARD_IF_FALSE_3 = 0x4F, /* 79 */ - BCODE_JUMP_BACKWARD_IF_TRUE_0 = 0x50, /* 80 */ - BCODE_JUMP_BACKWARD_IF_TRUE_1 = 0x51, /* 81 */ - BCODE_JUMP_BACKWARD_IF_TRUE_2 = 0x52, /* 82 */ - BCODE_JUMP_BACKWARD_IF_TRUE_3 = 0x53, /* 83 */ + BCODE_JUMPOP_BACKWARD_IF_TRUE_0 = 0x50, /* 80 */ + BCODE_JUMPOP_BACKWARD_IF_TRUE_1 = 0x51, /* 81 */ + BCODE_JUMPOP_BACKWARD_IF_TRUE_2 = 0x52, /* 82 */ + BCODE_JUMPOP_BACKWARD_IF_TRUE_3 = 0x53, /* 83 */ /* UNUSED 0x54 - 0x57 */ @@ -938,18 +940,22 @@ enum moo_bcode_t BCODE_JUMP_FORWARD_X = 0xC4, /* 196 ## */ BCODE_JUMP2_FORWARD = 0xC5, /* 197 */ + BCODE_JUMP_FORWARD_IF_TRUE = 0xC6, /* 198 ## */ + BCODE_JUMP2_FORWARD_IF_TRUE = 0xC7, /* 199 */ BCODE_JUMP_BACKWARD_X = 0xC8, /* 200 ## */ BCODE_JUMP2_BACKWARD = 0xC9, /* 201 */ - BCODE_JUMP_BACKWARD_IF_FALSE_X = 0xCC, /* 204 ## */ - BCODE_JUMP2_BACKWARD_IF_FALSE = 0xCD, /* 205 */ - BCODE_JUMP_BACKWARD_IF_TRUE_X = 0xD0, /* 208 ## */ - BCODE_JUMP2_BACKWARD_IF_TRUE = 0xD1, /* 209 */ + BCODE_JUMPOP_BACKWARD_IF_FALSE_X = 0xCC, /* 204 ## */ + BCODE_JUMPOP2_BACKWARD_IF_FALSE = 0xCD, /* 205 */ + BCODE_JUMPOP_BACKWARD_IF_TRUE_X = 0xD0, /* 208 ## */ + BCODE_JUMPOP2_BACKWARD_IF_TRUE = 0xD1, /* 209 */ - BCODE_JUMP_FORWARD_IF_FALSE = 0xD4, /* 212 ## */ - BCODE_JUMP2_FORWARD_IF_FALSE = 0xD5, /* 213 */ - BCODE_JUMP_FORWARD_IF_TRUE = 0xD6, /* 214 ## */ - BCODE_JUMP2_FORWARD_IF_TRUE = 0xD7, /* 215 */ + BCODE_JUMP_FORWARD_IF_FALSE = 0xD2, /* 210 ## */ + BCODE_JUMP2_FORWARD_IF_FALSE = 0xD3, /* 211 */ + BCODE_JUMPOP_FORWARD_IF_FALSE = 0xD4, /* 212 ## */ + BCODE_JUMPOP2_FORWARD_IF_FALSE = 0xD5, /* 213 */ + BCODE_JUMPOP_FORWARD_IF_TRUE = 0xD6, /* 214 ## */ + BCODE_JUMPOP2_FORWARD_IF_TRUE = 0xD7, /* 215 */ BCODE_STORE_INTO_CTXTEMPVAR_X = 0xD8, /* 216 ## */ BCODE_POP_INTO_CTXTEMPVAR_X = 0xDC, /* 220 ## */