diff --git a/moo/kernel/Apex.moo b/moo/kernel/Apex.moo index a535c23..9d1e728 100644 --- a/moo/kernel/Apex.moo +++ b/moo/kernel/Apex.moo @@ -312,8 +312,10 @@ extend Error ^false } - method(#primitive) asInteger. method(#primitive) asCharacter. + method asError { ^self } + method(#primitive) asInteger. + method(#primitive) asString. method signal diff --git a/moo/kernel/Magnitu.moo b/moo/kernel/Magnitu.moo index 2f19d97..6c27a5c 100644 --- a/moo/kernel/Magnitu.moo +++ b/moo/kernel/Magnitu.moo @@ -1,5 +1,24 @@ class Magnitude(Object) { + method < aMagnitude { self subclassResponsibility: #< } + method > aMagnitude { ^aMagnitude < self } + method <= aMagnitude { ^(aMagnitude < self) not } + method >= aMagnitude { ^(self < aMagnitude) not } + + method between: min and: max + { + ^self >= min and: [self <= max] + } + + method min: aMagnitude + { + ^self < aMagnitude ifTrue: [self] ifFalse: [aMagnitude] + } + + method max: aMagnitude + { + ^self > aMagnitude ifTrue: [self] ifFalse: [aMagnitude] + } } class Association(Magnitude) @@ -45,59 +64,17 @@ class Association(Magnitude) class(#limited) Character(Magnitude) { -## method(#primitive,#class) fromCode: code. -## method(#primitive) toCode. +## method(#primitive,#class) codePoint: code. +## method(#primitive) codePoint. + method asCharacter { ^self } + method(#primitive) asError. method(#primitive) asInteger. - method = aCharacter - { - - self primitiveFailed. - } - - method ~= char - { - - self primitiveFailed. - } - - method < char - { - - self primitiveFailed. - } - - method > char - { - - self primitiveFailed. - } - - method <= char - { - - self primitiveFailed. - } - - method >= char - { - - self primitiveFailed. - } - - method - char - { - - ^(self asInteger - char asInteger) asCharacter - } - - method + char - { - - ^(self asInteger + char asInteger) asCharacter - } - + method(#primitive) < char. + method(#primitive) > char. + method(#primitive) <= char. + method(#primitive) >= char. } class(#limited) Number(Magnitude) @@ -345,15 +322,12 @@ class(#limited) Integer(Number) count := 0. while (count < self) { aBlock value. count := count + 1 } } + + method asInteger { ^self } } class(#limited) SmallInteger(Integer) { - ## method basicSize - ## { - ## ^0 - ## } - method(#primitive) asCharacter. method(#primitive) asError. } diff --git a/moo/kernel/Process.moo b/moo/kernel/Process.moo index a8d33f0..fe7e18b 100644 --- a/moo/kernel/Process.moo +++ b/moo/kernel/Process.moo @@ -371,29 +371,6 @@ class(#final,#limited) ProcessScheduler(Object) var(#get) suspended_count := 0. var suspended_head, suspended_tail. - method activeProcess - { - ^self.active. - } - - method resume: process - { - - self primitiveFailed. - - (* The primitive does something like the following in principle: - (self.tally == 0) - ifTrue: [ - self.head := process. - self.tail := process. - self.tally := 1. - ] - ifFalse: [ - process ps_next: self.head. - self.head ps_prev: process. - self.head := process. - self.tally := self.tally + 1. - ]. - *) - } + method activeProcess { ^self.active } + method resume: aProcess { ^aProcess resume } } diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index ff2afe7..bcc30be 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -57,7 +57,7 @@ class(#byte) IP4Address(IPAddress) if (acc > 255) { Exception signal: ('invalid IPv4 address B ' & str). }. digits := digits + 1. } - elsif (c == $.) + elsif (c = $.) { if (dots >= 3 or: [digits == 0]) { Exception signal: ('invalid IPv4 address C ' & str). }. self basicAt: dots put: acc. diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 794767f..ff4e53b 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -8210,13 +8210,13 @@ static void fini_compiler (moo_t* moo) } } -int moo_compile (moo_t* moo, moo_ioimpl_t io) +static MOO_INLINE int _compile (moo_t* moo, moo_ioimpl_t io) { int n; if (!io) { - moo_seterrnum (moo, MOO_EINVAL); + moo_seterrbfmt (moo, MOO_EINVAL, "no IO implementation provided"); return -1; } @@ -8297,6 +8297,19 @@ oops: return -1; } +int moo_compile (moo_t* moo, moo_ioimpl_t io) +{ + int n; + int log_default_type_mask; + + log_default_type_mask = moo->log.default_type_mask; + moo->log.default_type_mask |= MOO_LOG_COMPILER; + n = _compile (moo, io); + moo->log.default_type_mask = log_default_type_mask; + + return n; +} + void moo_getsynerr (moo_t* moo, moo_synerr_t* synerr) { MOO_ASSERT (moo, moo->c != MOO_NULL); diff --git a/moo/lib/err.c b/moo/lib/err.c index acb69ce..1f8ab50 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -323,7 +323,7 @@ void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, char** btsyms; #endif - moo_logbfmt (moo, MOO_LOG_DEBUG, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); + moo_logbfmt (moo, MOO_LOG_UNTYPED | MOO_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); #if defined(HAVE_BACKTRACE) @@ -332,11 +332,11 @@ void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, if (btsyms) { moo_oow_t i; - moo_logbfmt (moo, MOO_LOG_DEBUG, "[BACKTRACE]\n"); + moo_logbfmt (moo, MOO_LOG_UNTYPED | MOO_LOG_DEBUG, "[BACKTRACE]\n"); for (i = 0; i < btsize; i++) { - moo_logbfmt(moo, MOO_LOG_DEBUG, " %s\n", btsyms[i]); + moo_logbfmt(moo, MOO_LOG_UNTYPED | MOO_LOG_DEBUG, " %s\n", btsyms[i]); } free (btsyms); } diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 43170d6..5eb7155 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -102,7 +102,7 @@ static MOO_INLINE const char* proc_state_to_string (int state) #endif #if defined(MOO_DEBUG_VM_EXEC) -# define LOG_MASK_INST (MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_MNEMONIC | MOO_LOG_DEBUG) +# define LOG_MASK_INST (MOO_LOG_IC | MOO_LOG_MNEMONIC | MOO_LOG_DEBUG) /* TODO: for send_message, display the method name. or include the method name before 'ip' */ # define LOG_INST0(moo,fmt) MOO_LOG1(moo, LOG_MASK_INST, " %06zd " fmt "\n", (moo)->last_inst_pointer) @@ -133,7 +133,7 @@ static MOO_INLINE int vm_startup (moo_t* moo) { moo_oow_t i; - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "VM started up\n"); + MOO_DEBUG0 (moo, "VM started up\n"); for (i = 0; i < moo->sem_io_map_capa; i++) { @@ -188,7 +188,7 @@ static MOO_INLINE void vm_cleanup (moo_t* moo) moo->sem_gcfin = (moo_oop_semaphore_t)moo->_nil; moo->sem_gcfin_sigreq = 0; - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "VM cleaned up\n"); + MOO_DEBUG0 (moo, "VM cleaned up\n"); } static MOO_INLINE void vm_gettime (moo_t* moo, moo_ntime_t* now) @@ -229,7 +229,7 @@ static MOO_INLINE int prepare_to_alloc_pid (moo_t* moo) if (moo->proc_map_capa >= MOO_SMOOI_MAX) { #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_FATAL, "Processor - too many processes\n"); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Processor - too many processes\n"); #endif moo_seterrnum (moo, MOO_EPFULL); return -1; @@ -297,7 +297,7 @@ static moo_oop_process_t make_process (moo_t* moo, moo_oop_context_t c) if (total_count >= MOO_SMOOI_MAX) { #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_FATAL, "Processor - too many processes\n"); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Processor - too many processes\n"); #endif moo_seterrnum (moo, MOO_EPFULL); return MOO_NULL; @@ -324,7 +324,7 @@ static moo_oop_process_t make_process (moo_t* moo, moo_oop_context_t c) MOO_ASSERT (moo, (moo_oop_t)c->sender == moo->_nil); #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] **CREATED**->%hs\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] **CREATED**->%hs\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif /* a process is created in the SUSPENDED state. chain it to the suspended process list */ @@ -348,7 +348,7 @@ static MOO_INLINE void sleep_active_process (moo_t* moo, int state) MOO_ASSERT (moo, moo->processor->active != moo->nil_process); #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->%hs in sleep_active_process\n", MOO_OOP_TO_SMOOI(moo->processor->active->id), proc_state_to_string(MOO_OOP_TO_SMOOI(moo->processor->active->state)), proc_state_to_string(state)); + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->%hs in sleep_active_process\n", MOO_OOP_TO_SMOOI(moo->processor->active->id), proc_state_to_string(MOO_OOP_TO_SMOOI(moo->processor->active->state)), proc_state_to_string(state)); #endif moo->processor->active->current_context = moo->active_context; @@ -359,7 +359,7 @@ static MOO_INLINE void wake_process (moo_t* moo, moo_oop_process_t proc) { /* activate the given process */ #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->RUNNING in wake_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->RUNNING in wake_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); @@ -374,7 +374,7 @@ static MOO_INLINE void wake_process (moo_t* moo, moo_oop_process_t proc) SWITCH_ACTIVE_CONTEXT (moo, proc->current_context); #if defined(MOO_DEBUG_VM_PROCESSOR) && (MOO_DEBUG_VM_PROCESSOR >= 2) - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - woke up process [%zd] context %O ip=%zd\n", MOO_OOP_TO_SMOOI(moo->processor->active->id), moo->active_context, moo->ip); + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - woke up process[%zd] context %O ip=%zd\n", MOO_OOP_TO_SMOOI(moo->processor->active->id), moo->active_context, moo->ip); #endif } @@ -430,8 +430,8 @@ static MOO_INLINE void chain_into_processor (moo_t* moo, moo_oop_process_t proc, MOO_ASSERT (moo, new_state == PROC_STATE_RUNNABLE || new_state == PROC_STATE_RUNNING); #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, - "Processor - process [%zd] %hs->%hs in chain_into_processor\n", + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, + "Processor - process[%zd] %hs->%hs in chain_into_processor\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state)), proc_state_to_string(new_state)); @@ -467,7 +467,7 @@ static MOO_INLINE void unchain_from_processor (moo_t* moo, moo_oop_process_t pro MOO_ASSERT (moo, proc->state != MOO_SMOOI_TO_OOP(new_state)); #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->%hs in unchain_from_processor\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state)), proc_state_to_string(MOO_OOP_TO_SMOOI(new_state))); + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->%hs in unchain_from_processor\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state)), proc_state_to_string(MOO_OOP_TO_SMOOI(new_state))); #endif if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)) @@ -568,7 +568,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) { /* RUNNING/RUNNABLE ---> TERMINATED */ #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->TERMINATED in terminate_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->TERMINATED in terminate_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif if (proc == moo->processor->active) @@ -589,7 +589,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) { /* no runnable process after termination */ MOO_ASSERT (moo, moo->processor->active == moo->nil_process); - MOO_LOG5 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, + MOO_LOG5 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "No runnable process after termination of process %zd - total %zd runnable/running %zd suspended %zd - sem_io_wait_count %zu\n", MOO_OOP_TO_SMOOI(proc->id), MOO_OOP_TO_SMOOI(moo->processor->total_count), @@ -616,7 +616,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) { /* SUSPENDED ---> TERMINATED */ #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->TERMINATED in terminate_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->TERMINATED in terminate_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif /*proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_TERMINATED);*/ @@ -649,7 +649,7 @@ static void resume_process (moo_t* moo, moo_oop_process_t proc) MOO_ASSERT (moo, (moo_oop_t)proc->ps.next == moo->_nil);*/ #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->RUNNABLE in resume_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->RUNNABLE in resume_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif /* don't switch to this process. just change the state to RUNNABLE. @@ -676,7 +676,7 @@ static void suspend_process (moo_t* moo, moo_oop_process_t proc) /* RUNNING/RUNNABLE ---> SUSPENDED */ #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->SUSPENDED in suspend_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->SUSPENDED in suspend_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif if (proc == moo->processor->active) @@ -735,7 +735,7 @@ static void yield_process (moo_t* moo, moo_oop_process_t proc) if (nrp != proc) { #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process [%zd] %hs->RUNNABLE in yield_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->RUNNABLE in yield_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); #endif switch_to_process (moo, nrp, PROC_STATE_RUNNABLE); } @@ -1212,11 +1212,11 @@ static int add_to_sem_io (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi_t io_hand if (n <= -1) { - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_WARN, "Failed to add an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); + MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to add an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); return -1; } - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Added an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Added an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); sem->io_index = MOO_SMOOI_TO_OOP(index); sem->io_handle = MOO_SMOOI_TO_OOP(io_handle); @@ -1277,11 +1277,11 @@ static int delete_from_sem_io (moo_t* moo, moo_oop_semaphore_t sem) moo_poptmp (moo); if (x <= -1) { - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_WARN, "Failed to delete an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); + MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to delete an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); return -1; } - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Deleted an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Deleted an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle); sem->io_index = moo->_nil; sem->io_type = moo->_nil; sem->io_handle = moo->_nil; @@ -1317,7 +1317,7 @@ static int delete_from_sem_io (moo_t* moo, moo_oop_semaphore_t sem) moo->sem_io_map[moo->sem_io_tuple[index].handle] = index; - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Migrated an IO semaphore tuple from index %zd to %zd\n", moo->sem_io_tuple_count, index); + MOO_LOG2 (moo, MOO_LOG_DEBUG, "Migrated an IO semaphore tuple from index %zd to %zd\n", moo->sem_io_tuple_count, index); } moo->sem_io_map[io_handle] = -1; @@ -1374,7 +1374,7 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask } else { - MOO_LOG1 (moo, MOO_LOG_VM | MOO_LOG_WARN, "Warning - semaphore signaling requested on an unmapped handle %zd\n", io_handle); + MOO_LOG1 (moo, MOO_LOG_WARN, "Warning - semaphore signaling requested on an unmapped handle %zd\n", io_handle); } } /* ------------------------------------------------------------------------- */ @@ -1598,7 +1598,7 @@ not_found: } } - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Method '%.*js' not found in %O\n", message->len, message->ptr, receiver); + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Method '%.*js' not found in %O\n", message->len, message->ptr, receiver); moo_seterrbfmt (moo, MOO_ENOENT, "unable to find the method '%.*js' in %O", message->len, message->ptr, receiver); return MOO_NULL; } @@ -1630,14 +1630,14 @@ static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objn ass = moo_lookupsysdic (moo, objname); if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_class) { - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Cannot find a class '%.*js'", objname->len, objname->ptr); + MOO_LOG2 (moo, MOO_LOG_DEBUG, "Cannot find a class '%.*js'", objname->len, objname->ptr); return -1; } mth = moo_findmethod (moo, ass->value, mthname, 0); if (!mth) { - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Cannot find a method %.*js>>%.*js", objname->len, objname->ptr, mthname->len, mthname->ptr); + MOO_LOG4 (moo, MOO_LOG_DEBUG, "Cannot find a method %.*js>>%.*js", objname->len, objname->ptr, mthname->len, mthname->ptr); return -1; } @@ -1647,7 +1647,7 @@ static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objn * i can't use it as a start-up method. TODO: overcome this problem - accept parameters.... */ - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, (moo, "Arguments not supported by a startup method - %.*js>>%.*js", objname->len, objname->ptr, mthname->len, mthname->ptr); + MOO_LOG4 (moo, MOO_LOG_DEBUG, (moo, "Arguments not supported by a startup method - %.*js>>%.*js", objname->len, objname->ptr, mthname->len, mthname->ptr); moo_seterrbfmt (moo, MOO_EINVAL, "arguments not supported by a startup method %.*js>>%.*js", objname->len, objname->ptr, mthname->len, mthname->ptr); return -1; } @@ -1661,13 +1661,13 @@ TODO: overcome this problem - accept parameters.... mth = moo_findmethod (moo, (moo_oop_t)moo->_system, &startup, 0); if (!mth) { - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Cannot find the startup method in the system class"); + MOO_LOG0 (moo, MOO_LOG_DEBUG, "Cannot find the startup method in the system class"); goto oops; } if (MOO_OOP_TO_SMOOI(mth->tmpr_nargs) != 2) { - MOO_LOG1 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Weird argument count %zd for a startup method - should be 2", MOO_OOP_TO_SMOOI(mth->tmpr_nargs)); + MOO_LOG1 (moo, MOO_LOG_DEBUG, "Weird argument count %zd for a startup method - should be 2", MOO_OOP_TO_SMOOI(mth->tmpr_nargs)); moo_seterrbfmt (moo, MOO_EINVAL, "%.*js>>%.*js accepting weird argument count %zd, must accept 2 only", objname->len, objname->ptr, mthname->len, mthname->ptr, MOO_OOP_TO_SMOOI(mth->tmpr_nargs)); goto oops; } @@ -2422,25 +2422,6 @@ static moo_pfrc_t pf_semaphore_group_wait (moo_t* moo, moo_ooi_t nargs) return MOO_PF_SUCCESS; } -static moo_pfrc_t pf_processor_schedule (moo_t* moo, moo_ooi_t nargs) -{ - moo_oop_t arg; - - /*MOO_PF_CHECK_RCV (moo, MOO_STACK_GETRCV(moo, nargs) == (moo_oop_t)moo->processor);*/ - - MOO_ASSERT (moo, nargs == 1); - arg = MOO_STACK_GETARG(moo, nargs, 0); - MOO_PF_CHECK_ARGS (moo, nargs, MOO_CLASSOF(moo,arg) == moo->_process); - - /* set the return value before resume_process() in case it changes the active process */ - MOO_STACK_SETRETTORCV (moo, nargs); - - resume_process (moo, (moo_oop_process_t)arg); - - return MOO_PF_SUCCESS; -} - - /* ------------------------------------------------------------------ */ static moo_pfrc_t pf_system_add_gcfin_semaphore (moo_t* moo, moo_ooi_t nargs) @@ -2519,7 +2500,7 @@ static moo_pfrc_t pf_system_add_timed_semaphore (moo_t* moo, moo_ooi_t nargs) if (ft.sec < 0 || ft.sec > MOO_SMOOI_MAX) { /* soft error - cannot represent the expiry time in a small integer. */ - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, + MOO_LOG3 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - time (%ld) out of range(0 - %zd) when adding a timed semaphore\n", __PRIMITIVE_NAME__, (unsigned long int)ft.sec, (moo_ooi_t)MOO_SMOOI_MAX); @@ -3128,43 +3109,21 @@ static moo_pfrc_t pf_character_ge (moo_t* moo, moo_ooi_t nargs) /* ------------------------------------------------------------------ */ -static moo_pfrc_t pf_character_add (moo_t* moo, moo_ooi_t nargs) +static moo_pfrc_t pf_character_as_error (moo_t* moo, moo_ooi_t nargs) { - moo_oop_t rcv, arg, res; + moo_oop_t rcv; + moo_ooi_t c; - MOO_ASSERT (moo, nargs == 1); + MOO_ASSERT (moo, nargs == 0); rcv = MOO_STACK_GETRCV(moo, nargs); - arg = MOO_STACK_GETARG(moo, nargs, 0); - MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_CHAR(rcv)); - MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_CHAR(arg)); - res = MOO_CHAR_TO_OOP(MOO_OOP_TO_CHAR(rcv) + MOO_OOP_TO_CHAR(arg)); - - MOO_STACK_SETRET (moo, nargs, res); + c = MOO_OOP_TO_CHAR(rcv); + MOO_STACK_SETRET (moo, nargs, MOO_ERROR_TO_OOP(c)); return MOO_PF_SUCCESS; } -static moo_pfrc_t pf_character_sub (moo_t* moo, moo_ooi_t nargs) -{ - moo_oop_t rcv, arg, res; - - MOO_ASSERT (moo, nargs == 1); - - rcv = MOO_STACK_GETRCV(moo, nargs); - arg = MOO_STACK_GETARG(moo, nargs, 0); - - MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_CHAR(rcv)); - MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_CHAR(arg)); - - res = MOO_CHAR_TO_OOP(MOO_OOP_TO_CHAR(rcv) - MOO_OOP_TO_CHAR(arg)); - - MOO_STACK_SETRET (moo, nargs, res); - return MOO_PF_SUCCESS; -} -/* ------------------------------------------------------------------ */ - static moo_pfrc_t pf_character_as_smooi (moo_t* moo, moo_ooi_t nargs) { moo_oop_t rcv; @@ -3378,32 +3337,9 @@ typedef struct pf_t pf_t; static pf_t pftab[] = { - { "_dump", { pf_dump, 0, MA } }, - - { "_processor_schedule", { pf_processor_schedule, 1, 1 } }, - - { "_integer_add", { pf_integer_add, 1, 1 } }, - { "_integer_sub", { pf_integer_sub, 1, 1 } }, - { "_integer_mul", { pf_integer_mul, 1, 1 } }, - { "_integer_quo", { pf_integer_quo, 1, 1 } }, - { "_integer_rem", { pf_integer_rem, 1, 1 } }, - { "_integer_quo2", { pf_integer_quo2, 1, 1 } }, - { "_integer_rem2", { pf_integer_rem2, 1, 1 } }, - { "_integer_negated", { pf_integer_negated, 0, 0 } }, - { "_integer_bitat", { pf_integer_bitat, 1, 1 } }, - { "_integer_bitand", { pf_integer_bitand, 1, 1 } }, - { "_integer_bitor", { pf_integer_bitor, 1, 1 } }, - { "_integer_bitxor", { pf_integer_bitxor, 1, 1 } }, - { "_integer_bitinv", { pf_integer_bitinv, 0, 0 } }, - { "_integer_bitshift", { pf_integer_bitshift, 1, 1 } }, - { "_integer_eq", { pf_integer_eq, 1, 1 } }, - { "_integer_ne", { pf_integer_ne, 1, 1 } }, - { "_integer_lt", { pf_integer_lt, 1, 1 } }, - { "_integer_gt", { pf_integer_gt, 1, 1 } }, - { "_integer_le", { pf_integer_le, 1, 1 } }, - { "_integer_ge", { pf_integer_ge, 1, 1 } }, - { "_integer_inttostr", { pf_integer_inttostr, 1, 1 } }, - + + { "Apex_=", { moo_pf_equal, 1, 1 } }, + { "Apex_==", { moo_pf_identical, 1, 1 } }, { "Apex_addToBeFinalized", { pf_add_to_be_finalized, 0, 0 } }, { "Apex_basicAt:", { moo_pf_basic_at, 1, 1 } }, { "Apex_basicAt:put:", { moo_pf_basic_at_put, 2, 2 } }, @@ -3417,24 +3353,18 @@ static pf_t pftab[] = { "Apex_removeToBeFinalized", { pf_remove_to_be_finalized, 0, 0 } }, { "Apex_respondsTo:", { moo_pf_responds_to, 1, 1 } }, { "Apex_shallowCopy", { moo_pf_shallow_copy, 0, 0 } }, - - { "Apex_==", { moo_pf_identical, 1, 1 } }, - { "Apex_~~", { moo_pf_not_identical, 1, 1 } }, - { "Apex_=", { moo_pf_equal, 1, 1 } }, { "Apex_~=", { moo_pf_not_equal, 1, 1 } }, + { "Apex_~~", { moo_pf_not_identical, 1, 1 } }, - { "BlockContext_value", { pf_block_value, 0, MA } }, { "BlockContext_newProcess", { pf_block_new_process, 0, MA } }, + { "BlockContext_value", { pf_block_value, 0, MA } }, - { "Character_add", { pf_character_add, 1, 1 } }, + { "Character_<", { pf_character_lt, 1, 1 } }, + { "Character_<=", { pf_character_le, 1, 1 } }, + { "Character_>", { pf_character_gt, 1, 1 } }, + { "Character_>=", { pf_character_ge, 1, 1 } }, + { "Character_asError", { pf_character_as_error, 0, 0 } }, { "Character_asInteger", { pf_character_as_smooi, 0, 0 } }, - { "Character_eq", { pf_character_eq, 1, 1 } }, - { "Character_le", { pf_character_le, 1, 1 } }, - { "Character_lt", { pf_character_lt, 1, 1 } }, - { "Character_ne", { pf_character_ne, 1, 1 } }, - { "Character_ge", { pf_character_ge, 1, 1 } }, - { "Character_gt", { pf_character_gt, 1, 1 } }, - { "Character_sub", { pf_character_sub, 1, 1 } }, { "Error_asCharacter", { pf_error_as_character, 0, 0 } }, { "Error_asInteger", { pf_error_as_integer, 0, 0 } }, @@ -3445,14 +3375,15 @@ static pf_t pftab[] = { "Process_resume", { pf_process_resume, 0, 0 } }, { "Process_sp", { pf_process_sp, 0, 0 } }, { "Process_suspend", { pf_process_suspend, 0, 0 } }, - { "Process_yield", { pf_process_yield, 0, 0 } }, { "Process_terminate", { pf_process_terminate, 0, 0 } }, + { "Process_yield", { pf_process_yield, 0, 0 } }, - { "Semaphore_signal", { pf_semaphore_signal, 0, 0 } }, - { "Semaphore_wait", { pf_semaphore_wait, 0, 0 } }, { "SemaphoreGroup_addSemaphore:", { pf_semaphore_group_add_semaphore, 1, 1 } }, { "SemaphoreGroup_removeSemaphore:", { pf_semaphore_group_remove_semaphore, 1, 1 } }, { "SemaphoreGroup_wait", { pf_semaphore_group_wait, 0, 0 } }, + + { "Semaphore_signal", { pf_semaphore_signal, 0, 0 } }, + { "Semaphore_wait", { pf_semaphore_wait, 0, 0 } }, { "SmallInteger_asCharacter", { pf_smooi_as_character, 0, 0 } }, { "SmallInteger_asError", { pf_smooi_as_error, 0, 0 } }, @@ -3469,14 +3400,14 @@ static pf_t pftab[] = { "SmallPointer_getUint64", { moo_pf_smptr_get_uint64, 1, 1 } }, { "SmallPointer_getUint8", { moo_pf_smptr_get_uint8, 1, 1 } }, { "SmallPointer_putBytes", { moo_pf_smptr_put_bytes, 4, 4 } }, - { "SmallPointer_putInt8", { moo_pf_smptr_put_int8, 2, 2 } }, { "SmallPointer_putInt16", { moo_pf_smptr_put_int16, 2, 2 } }, { "SmallPointer_putInt32", { moo_pf_smptr_put_int32, 2, 2 } }, { "SmallPointer_putInt64", { moo_pf_smptr_put_int64, 2, 2 } }, - { "SmallPointer_putUint8", { moo_pf_smptr_put_uint8, 2, 2 } }, + { "SmallPointer_putInt8", { moo_pf_smptr_put_int8, 2, 2 } }, { "SmallPointer_putUint16", { moo_pf_smptr_put_uint16, 2, 2 } }, { "SmallPointer_putUint32", { moo_pf_smptr_put_uint32, 2, 2 } }, { "SmallPointer_putUint64", { moo_pf_smptr_put_uint64, 2, 2 } }, + { "SmallPointer_putUint8", { moo_pf_smptr_put_uint8, 2, 2 } }, { "String_strlen", { pf_strlen, 0, 0 } }, @@ -3500,43 +3431,69 @@ static pf_t pftab[] = { "System_malloc:", { moo_pf_system_malloc, 1, 1 } }, { "System_popCollectable", { moo_pf_system_pop_collectable, 0, 0 } }, { "System_putBytes", { moo_pf_system_put_bytes, 5, 5 } }, - { "System_putInt8", { moo_pf_system_put_int8, 3, 3 } }, { "System_putInt16", { moo_pf_system_put_int16, 3, 3 } }, { "System_putInt32", { moo_pf_system_put_int32, 3, 3 } }, { "System_putInt64", { moo_pf_system_put_int64, 3, 3 } }, - { "System_putUint8", { moo_pf_system_put_uint8, 3, 3 } }, + { "System_putInt8", { moo_pf_system_put_int8, 3, 3 } }, { "System_putUint16", { moo_pf_system_put_uint16, 3, 3 } }, { "System_putUint32", { moo_pf_system_put_uint32, 3, 3 } }, { "System_putUint64", { moo_pf_system_put_uint64, 3, 3 } }, + { "System_putUint8", { moo_pf_system_put_uint8, 3, 3 } }, { "System_return:to:", { pf_system_return_value_to_context, 2, 2 } }, { "System_signal:afterSecs:", { pf_system_add_timed_semaphore, 2, 2 } }, { "System_signal:afterSecs:nanosecs:", { pf_system_add_timed_semaphore, 3, 3 } }, { "System_signal:onInput:", { pf_system_add_input_semaphore, 2, 2 } }, { "System_signal:onOutput:", { pf_system_add_output_semaphore, 2, 2 } }, { "System_signalOnGCFin:", { pf_system_add_gcfin_semaphore, 1, 1 } }, - { "System_unsignal:", { pf_system_remove_semaphore, 1, 1 } } + { "System_unsignal:", { pf_system_remove_semaphore, 1, 1 } }, + + { "_dump", { pf_dump, 0, MA } }, + + { "_integer_add", { pf_integer_add, 1, 1 } }, + { "_integer_bitand", { pf_integer_bitand, 1, 1 } }, + { "_integer_bitat", { pf_integer_bitat, 1, 1 } }, + { "_integer_bitinv", { pf_integer_bitinv, 0, 0 } }, + { "_integer_bitor", { pf_integer_bitor, 1, 1 } }, + { "_integer_bitshift", { pf_integer_bitshift, 1, 1 } }, + { "_integer_bitxor", { pf_integer_bitxor, 1, 1 } }, + { "_integer_eq", { pf_integer_eq, 1, 1 } }, + { "_integer_ge", { pf_integer_ge, 1, 1 } }, + { "_integer_gt", { pf_integer_gt, 1, 1 } }, + { "_integer_inttostr", { pf_integer_inttostr, 1, 1 } }, + { "_integer_le", { pf_integer_le, 1, 1 } }, + { "_integer_lt", { pf_integer_lt, 1, 1 } }, + { "_integer_mul", { pf_integer_mul, 1, 1 } }, + { "_integer_ne", { pf_integer_ne, 1, 1 } }, + { "_integer_negated", { pf_integer_negated, 0, 0 } }, + { "_integer_quo", { pf_integer_quo, 1, 1 } }, + { "_integer_quo2", { pf_integer_quo2, 1, 1 } }, + { "_integer_rem", { pf_integer_rem, 1, 1 } }, + { "_integer_rem2", { pf_integer_rem2, 1, 1 } }, + { "_integer_sub", { pf_integer_sub, 1, 1 } } }; moo_pfbase_t* moo_getpfnum (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, moo_ooi_t* pfnum) { - moo_ooi_t i; + moo_oow_t base, mid, lim; + int n; -/* TODO: have the pftable sorted alphabetically and do binary search */ -/* TODO: sort pftab and utilize moo_findpfbase? */ - for (i = 0; i < MOO_COUNTOF(pftab); i++) + for (base = 0, lim = MOO_COUNTOF(pftab); lim > 0; lim >>= 1) { + mid = base + (lim >> 1); /* moo_compoocharsbcstr() is not aware of multibyte encoding. * so the names above should be composed of the single byte * characters only */ - if (moo_compoocharsbcstr(ptr, len, pftab[i].name) == 0) + n = moo_compoocharsbcstr(ptr, len, pftab[mid].name); + if (n == 0) { - MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(i)); /* this must never be so big */ - *pfnum = i; - return &pftab[i].pfbase; + MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(mid)); /* this must never be so big */ + *pfnum = mid; + return &pftab[mid].pfbase; } + if (n > 0) { base = mid + 1; lim--; } } - moo_seterrnum (moo, MOO_ENOENT); + moo_seterrbfmt (moo, MOO_ENOENT, "unknown primitive specifier %.*js", len, ptr); return MOO_NULL; } @@ -3568,7 +3525,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) { /* TODO: better to throw a moo exception so that the caller can catch it??? */ arg_count_mismatch: - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_FATAL, + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - Argument count mismatch for a non-variadic method [%O] - %zd expected, %zu given\n", method->name, MOO_OOP_TO_SMOOI(method->tmpr_nargs), nargs); moo_seterrnum (moo, MOO_EINVAL); @@ -3691,7 +3648,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) if ((nargs < pftab[pfnum].pfbase.minargs || nargs > pftab[pfnum].pfbase.maxargs)) { - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG4 (moo, MOO_LOG_DEBUG, "Soft failure due to argument count mismatch for primitive function %hs - %zu-%zu expected, %zu given\n", pftab[pfnum].name, pftab[pfnum].pfbase.minargs, pftab[pfnum].pfbase.maxargs, nargs); moo_seterrnum (moo, MOO_ENUMARGS); @@ -3703,20 +3660,20 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) moo_poptmp (moo); if (n <= MOO_PF_HARD_FAILURE) { - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Hard failure indicated by primitive function %p - %hs - return code %d\n", pftab[pfnum].pfbase.handler, pftab[pfnum].name, n); return -1; } if (n >= MOO_PF_SUCCESS) break; - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG2 (moo, MOO_LOG_DEBUG, "Soft failure indicated by primitive function %p - %hs\n", pftab[pfnum].pfbase.handler, pftab[pfnum].name); } else { - MOO_LOG1 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Cannot call primitive function numbered %zd - unknown primitive function number\n", pfnum); + MOO_LOG1 (moo, MOO_LOG_DEBUG, "Cannot call primitive function numbered %zd - unknown primitive function number\n", pfnum); moo_seterrbfmt (moo, MOO_ENOENT, "unknown primitive function number %zd", pfnum); } @@ -3762,7 +3719,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) exec_handler: if (nargs < pfbase->minargs || nargs > pfbase->maxargs) { - MOO_LOG5 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG5 (moo, MOO_LOG_DEBUG, "Soft failure due to argument count mismatch for primitive function %.*js - %zu-%zu expected, %zu given\n", MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname), pfbase->minargs, pfbase->maxargs, nargs); @@ -3786,7 +3743,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) moo_poptmp (moo); if (n <= MOO_PF_HARD_FAILURE) { - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG4 (moo, MOO_LOG_DEBUG, "Hard failure indicated by primitive function %p - %.*js - return code %d\n", pfbase->handler, MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname), n); return -1; /* hard primitive failure */ @@ -3794,14 +3751,14 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) if (n >= MOO_PF_SUCCESS) break; /* primitive ok*/ /* soft primitive failure */ - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Soft failure indicated by primitive function %p - %.*js\n", pfbase->handler, MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname)); } else { /* no handler found */ - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, + MOO_LOG2 (moo, MOO_LOG_DEBUG, "Soft failure for non-existent primitive function - %.*js\n", MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname)); } @@ -3853,12 +3810,12 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) if (stack_base != moo->sp - nargs - 1) { /* a primitive function handler must not touch the stack when it returns soft failure */ - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Stack seems to get corrupted by a primitive handler function - %O>>%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name)); + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Stack seems to get corrupted by a primitive handler function - %O>>%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name)); moo_seterrnum (moo, MOO_EINTERN); return -1; } - MOO_LOG3 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "Sending primitiveFailed - %O>>%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name)); + MOO_LOG3 (moo, MOO_LOG_DEBUG, "Sending primitiveFailed - %O>>%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name)); /* * | arg1 | <---- stack_base + 3 * | arg0 | <---- stack_base + 2 @@ -3925,7 +3882,7 @@ static int send_message (moo_t* moo, moo_oop_char_t selector, int to_super, moo_ { /* this must not happen as long as doesNotUnderstand: is implemented under Apex. * this check should indicate a very serious internal problem */ - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_FATAL, + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - receiver [%O] of class [%O] does not understand a message [%.*js]\n", receiver, MOO_CLASSOF(moo, receiver), mthname.len, mthname.ptr); @@ -3960,7 +3917,7 @@ static int send_message_with_str (moo_t* moo, const moo_ooch_t* nameptr, moo_oow method = moo_findmethod (moo, receiver, &mthname, to_super); if (!method) { - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_FATAL, + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - receiver [%O] of class [%O] does not understand a private message [%.*js]\n", receiver, MOO_CLASSOF(moo, receiver), mthname.len, mthname.ptr); moo_seterrnum (moo, MOO_EMSGSND); @@ -4015,7 +3972,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) * process at this moment */ #if defined(MOO_DEBUG_VM_PROCESSOR) && (MOO_DEBUG_VM_PROCESSOR >= 2) - MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - switching to a process [%zd] while no process is active - total runnables %zd\n", MOO_OOP_TO_SMOOI(proc->id), MOO_OOP_TO_SMOOI(moo->processor->runnable.count)); + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - switching to a process[%zd] while no process is active - total runnables %zd\n", MOO_OOP_TO_SMOOI(proc->id), MOO_OOP_TO_SMOOI(moo->processor->runnable.count)); #endif MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); @@ -4101,7 +4058,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) if (moo->sem_gcfin_sigreq) { signal_sem_gcfin: - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "Signaled GCFIN semaphore\n"); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Signaled GCFIN semaphore\n"); proc = signal_semaphore (moo, moo->sem_gcfin); if (moo->processor->active == moo->nil_process && (moo_oop_t)proc != moo->_nil) @@ -4141,7 +4098,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) * to schedule. */ - MOO_LOG4 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Signaled GCFIN semaphore without gcfin signal request - total %zd runnable/running %zd suspended %zd - sem_io_wait_count %zu\n", MOO_OOP_TO_SMOOI(moo->processor->total_count), MOO_OOP_TO_SMOOI(moo->processor->runnable.count), @@ -4180,12 +4137,12 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) { /* no more waiting semaphore and no more process */ MOO_ASSERT (moo, moo->processor->runnable.count = MOO_SMOOI_TO_OOP(0)); - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, "No more runnable process\n"); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "No more runnable process\n"); if (MOO_OOP_TO_SMOOI(moo->processor->suspended.count) > 0) { /* there exist suspended processes while no processes are runnable. * most likely, the running program contains process/semaphore related bugs */ - MOO_LOG1 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_DEBUG, + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "%zd suspended process(es) found - check your program\n", MOO_OOP_TO_SMOOI(moo->processor->suspended.count)); } @@ -4346,12 +4303,12 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context->origin) == moo->_method_context); MOO_ASSERT (moo, moo->active_context->origin->ip == MOO_SMOOI_TO_OOP(-1)); - MOO_LOG0 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_ERROR, "Error - cannot return from dead context\n"); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_ERROR, "Error - cannot return from dead context\n"); moo_seterrnum (moo, MOO_EINTERN); /* TODO: can i make this error catchable at the moo level? */ return -1; non_local_return_ok: -/*MOO_LOG2 (moo, MOO_LOG_VM | MOO_LOG_DEBUG, "NON_LOCAL RETURN OK TO... %p %p\n", moo->active_context->origin, moo->active_context->origin->sender);*/ +/*MOO_LOG2 (moo, MOO_LOG_DEBUG, "NON_LOCAL RETURN OK TO... %p %p\n", moo->active_context->origin, moo->active_context->origin->sender);*/ if (bcode != BCODE_LOCAL_RETURN) { /* mark that the context is dead */ @@ -5374,7 +5331,7 @@ static int __execute (moo_t* moo) NEXT_INST(); ON_UNKNOWN_INST() - MOO_LOG1 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode); + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode); moo_seterrnum (moo, MOO_EINTERN); return -1; @@ -5390,6 +5347,10 @@ static int __execute (moo_t* moo) int moo_execute (moo_t* moo) { int n; + int log_default_type_mask; + + log_default_type_mask = moo->log.default_type_mask; + moo->log.default_type_mask |= MOO_LOG_VM; #if defined(MOO_PROFILE_VM) moo->inst_counter = 0; @@ -5405,9 +5366,10 @@ int moo_execute (moo_t* moo) vm_cleanup (moo); #if defined(MOO_PROFILE_VM) - MOO_LOG1 (moo, MOO_LOG_VM | MOO_LOG_IC | MOO_LOG_INFO, "TOTAL_INST_COUTNER = %zu\n", moo->inst_counter); + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_INFO, "TOTAL_INST_COUTNER = %zu\n", moo->inst_counter); #endif + moo->log.default_type_mask = log_default_type_mask; return n; } diff --git a/moo/lib/logfmt.c b/moo/lib/logfmt.c index 8a4b1a4..aa25fe2 100644 --- a/moo/lib/logfmt.c +++ b/moo/lib/logfmt.c @@ -613,6 +613,12 @@ moo_ooi_t moo_logbfmt (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...) va_list ap; moo_fmtout_t fo; + if (moo->log.default_type_mask & MOO_LOG_ALL_TYPES) + { + mask &= ~MOO_LOG_UNTYPED; + mask |= (moo->log.default_type_mask & MOO_LOG_ALL_TYPES); + } + fo.mask = mask; fo.putch = put_ooch; fo.putcs = put_oocs; @@ -635,6 +641,12 @@ moo_ooi_t moo_logufmt (moo_t* moo, moo_oow_t mask, const moo_uch_t* fmt, ...) va_list ap; moo_fmtout_t fo; + if (moo->log.default_type_mask & MOO_LOG_ALL_TYPES) + { + mask &= ~MOO_LOG_UNTYPED; + mask |= (moo->log.default_type_mask & MOO_LOG_ALL_TYPES); + } + fo.mask = mask; fo.putch = put_ooch; fo.putcs = put_oocs; diff --git a/moo/lib/main.c b/moo/lib/main.c index 4bcb9f3..15813c7 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -2041,6 +2041,7 @@ static int handle_logopt (moo_t* moo, const moo_bch_t* str) if (cm) *cm = '\0'; if (moo_compbcstr(flt, "app") == 0) xtn->logmask |= MOO_LOG_APP; + else if (moo_compbcstr(flt, "compiler") == 0) xtn->logmask |= MOO_LOG_COMPILER; else if (moo_compbcstr(flt, "vm") == 0) xtn->logmask |= MOO_LOG_VM; else if (moo_compbcstr(flt, "mnemonic") == 0) xtn->logmask |= MOO_LOG_MNEMONIC; else if (moo_compbcstr(flt, "gc") == 0) xtn->logmask |= MOO_LOG_GC; @@ -2277,7 +2278,7 @@ int main (int argc, char* argv[]) if (moo_ignite(moo) <= -1) { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "ERROR: cannot ignite moo - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo)); + moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot ignite moo - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo)); close_moo (moo); return -1; } @@ -2301,33 +2302,33 @@ int main (int argc, char* argv[]) moo_getsynerr (moo, &synerr); - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "ERROR: "); + moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: "); if (synerr.loc.file) { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "%js", synerr.loc.file); + moo_logbfmt (moo, MOO_LOG_STDERR, "%js", synerr.loc.file); } else { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "%s", xtn->source_path); + moo_logbfmt (moo, MOO_LOG_STDERR, "%s", xtn->source_path); } - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "[%zu,%zu] syntax error - %js", synerr.loc.line, synerr.loc.colm, moo_synerrnum_to_errstr(synerr.num)); + moo_logbfmt (moo, MOO_LOG_STDERR, "[%zu,%zu] syntax error - %js", synerr.loc.line, synerr.loc.colm, moo_synerrnum_to_errstr(synerr.num)); if (synerr.tgt.len > 0) { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, " - %.*js", synerr.tgt.len, synerr.tgt.ptr); + moo_logbfmt (moo, MOO_LOG_STDERR, " - %.*js", synerr.tgt.len, synerr.tgt.ptr); } if (moo_geterrmsg(moo) != moo_geterrstr(moo)) { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, " - %js", moo_geterrmsg(moo)); + moo_logbfmt (moo, MOO_LOG_STDERR, " - %js", moo_geterrmsg(moo)); } - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "\n"); + moo_logbfmt (moo, MOO_LOG_STDERR, "\n"); } else { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "ERROR: cannot compile code - [%d] %js\n", moo_geterrnum(moo), moo_geterrmsg(moo)); + moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot compile code - [%d] %js\n", moo_geterrnum(moo), moo_geterrmsg(moo)); } close_moo (moo); @@ -2350,7 +2351,7 @@ int main (int argc, char* argv[]) mthname.len = 4; if (moo_invoke (moo, &objname, &mthname) <= -1) { - moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "ERROR: cannot execute code - [%d] %js\n", moo_geterrnum(moo), moo_geterrmsg(moo)); + moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot execute code - [%d] %js\n", moo_geterrnum(moo), moo_geterrmsg(moo)); xret = -1; } diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 3551f7f..1f75f33 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -1200,6 +1200,7 @@ struct moo_t moo_oow_t len; moo_oow_t capa; int last_mask; + int default_type_mask; } log; @@ -1413,15 +1414,17 @@ enum moo_log_mask_t MOO_LOG_ERROR = (1 << 3), MOO_LOG_FATAL = (1 << 4), - MOO_LOG_VM = (1 << 6), - MOO_LOG_MNEMONIC = (1 << 7), /* bytecode mnemonic */ - MOO_LOG_GC = (1 << 8), - MOO_LOG_IC = (1 << 9), /* instruction cycle, fetch-decode-execute */ - MOO_LOG_PRIMITIVE = (1 << 10), - MOO_LOG_APP = (1 << 11), /* moo applications, set by moo logging primitive */ + MOO_LOG_UNTYPED = (1 << 6), /* only to be used by MOO_DEBUGx() and MOO_INFOx() */ + MOO_LOG_COMPILER = (1 << 7), + MOO_LOG_VM = (1 << 8), + MOO_LOG_MNEMONIC = (1 << 9), /* bytecode mnemonic */ + MOO_LOG_GC = (1 << 10), + MOO_LOG_IC = (1 << 11), /* instruction cycle, fetch-decode-execute */ + MOO_LOG_PRIMITIVE = (1 << 12), + MOO_LOG_APP = (1 << 13), /* moo applications, set by moo logging primitive */ MOO_LOG_ALL_LEVELS = (MOO_LOG_DEBUG | MOO_LOG_INFO | MOO_LOG_WARN | MOO_LOG_ERROR | MOO_LOG_FATAL), - MOO_LOG_ALL_TYPES = (MOO_LOG_VM | MOO_LOG_MNEMONIC | MOO_LOG_GC | MOO_LOG_IC | MOO_LOG_PRIMITIVE | MOO_LOG_APP), + MOO_LOG_ALL_TYPES = (MOO_LOG_UNTYPED | MOO_LOG_COMPILER | MOO_LOG_VM | MOO_LOG_MNEMONIC | MOO_LOG_GC | MOO_LOG_IC | MOO_LOG_PRIMITIVE | MOO_LOG_APP), MOO_LOG_STDOUT = (1 << 14), /* write log messages to stdout without timestamp. MOO_LOG_STDOUT wins over MOO_LOG_STDERR. */ @@ -1454,22 +1457,22 @@ typedef enum moo_log_mask_t moo_log_mask_t; # define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) # define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) #else -# define MOO_DEBUG0(moo,fmt) MOO_LOG0(moo, MOO_LOG_DEBUG, fmt) -# define MOO_DEBUG1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_DEBUG, fmt, a1) -# define MOO_DEBUG2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_DEBUG, fmt, a1, a2) -# define MOO_DEBUG3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3) -# define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3, a4) -# define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3, a4, a5) -# define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3, a4, a5, a6) +# define MOO_DEBUG0(moo,fmt) MOO_LOG0(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt) +# define MOO_DEBUG1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1) +# define MOO_DEBUG2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2) +# define MOO_DEBUG3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3) +# define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4) +# define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5) +# define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5, a6) #endif -#define MOO_INFO0(moo,fmt) MOO_LOG0(moo, MOO_LOG_INFO, fmt) -#define MOO_INFO1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_INFO, fmt, a1) -#define MOO_INFO2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_INFO, fmt, a1, a2) -#define MOO_INFO3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_INFO, fmt, a1, a2, a3) -#define MOO_INFO4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_INFO, fmt, a1, a2, a3, a4) -#define MOO_INFO5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_INFO, fmt, a1, a2, a3, a4, a5) -#define MOO_INFO6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_INFO, fmt, a1, a2, a3, a4, a5, a6) +#define MOO_INFO0(moo,fmt) MOO_LOG0(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt) +#define MOO_INFO1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1) +#define MOO_INFO2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2) +#define MOO_INFO3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3) +#define MOO_INFO4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4) +#define MOO_INFO5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5) +#define MOO_INFO6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5, a6) /* ========================================================================= diff --git a/moo/lib/utl.c b/moo/lib/utl.c index b31a9e1..9286255 100644 --- a/moo/lib/utl.c +++ b/moo/lib/utl.c @@ -111,36 +111,61 @@ int moo_compucharsucstr (const moo_uch_t* str1, moo_oow_t len, const moo_uch_t* { const moo_uch_t* end = str1 + len; while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++; - if (str1 == end && *str2 == '\0') return 0; - if (*str1 == *str2) return (str1 < end)? 1: -1; - return (*str1 > *str2)? 1: -1; + + if (str1 == end) + { + return (*str2 == '\0')? 0: -1; + } + else /* str1 < end */ + { + /* for "abc\0" of length 4 vs "abc", the fourth character + * of the first string is equal to the terminating null of + * the second string. the first string is still considered + * bigger */ + return (*str1 >= *str2)? 1: -1; + } } int moo_compucharsbcstr (const moo_uch_t* str1, moo_oow_t len, const moo_bch_t* str2) { const moo_uch_t* end = str1 + len; while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++; - if (str1 == end && *str2 == '\0') return 0; - if (*str1 == *str2) return (str1 < end)? 1: -1; - return (*str1 > *str2)? 1: -1; + if (str1 == end) + { + return (*str2 == '\0')? 0: -1; + } + else /* str1 < end */ + { + return (*str1 >= *str2)? 1: -1; + } } int moo_compbcharsbcstr (const moo_bch_t* str1, moo_oow_t len, const moo_bch_t* str2) { const moo_bch_t* end = str1 + len; while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++; - if (str1 == end && *str2 == '\0') return 0; - if (*str1 == *str2) return (str1 < end)? 1: -1; - return (*str1 > *str2)? 1: -1; + if (str1 == end) + { + return (*str2 == '\0')? 0: -1; + } + else + { + return (*str1 >= *str2)? 1: -1; + } } int moo_compbcharsucstr (const moo_bch_t* str1, moo_oow_t len, const moo_uch_t* str2) { const moo_bch_t* end = str1 + len; while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++; - if (str1 == end && *str2 == '\0') return 0; - if (*str1 == *str2) return (str1 < end)? 1: -1; - return (*str1 > *str2)? 1: -1; + if (str1 == end) + { + return (*str2 == '\0')? 0: -1; + } + else + { + return (*str1 >= *str2)? 1: -1; + } }