Thread: [Waba-commits] CVS: waba/src/win32 config.h,NONE,1.1 constants.h,NONE,1.1 debug.h,NONE,1.1 error.c,N
Status: Abandoned
Brought to you by:
bornet
From: Manfred R. <mr...@us...> - 2004-12-20 23:24:59
|
Update of /cvsroot/waba/waba/src/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24332 Added Files: config.h constants.h debug.h error.c error.h exception.h memory.c memory.h native.c native.h nmwin32_a.c nmwin32_a.h nmwin32_b.c nmwin32_b.h nmwin32_c.c nmwin32_c.h opcodes.h thread.h types.h waba.c waba.h Log Message: Added at correct location --- NEW FILE: config.h --- /* * $Id: config.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines all the configuration for the VM * * ---------------------------------------------------------------------------- */ #ifndef __CONFIG_H__ #define __CONFIG_H__ /* * Which OS */ // #define PALMOS 1 // #define WINCE 1 // #define WIN32 1 /* * Memory options */ #define QUICKBIND 1 #define SANITYCHECK 1 #define SECURE_CLASS_HEAP 1 #define SMALLMEM 1 /* * With classic Waba support */ #define WITH_WABA 1 #define WITH_CATALOG 1 #define WITH_CATALOG_CLASS 1 #define WITH_DOUBLE_BUFFER 1 #define WITH_FILE_CLASS 1 #define WITH_FONTMETRICS_CLASS 1 #define WITH_GRAPHICS_CLASS 1 #define WITH_GUI_CLASS 1 #define WITH_SERIALPORT_CLASS 1 #define WITH_SOCKET_CLASS 1 #define WITH_SOUNDCLIP_CLASS 1 /* * With Waba extension support */ // #define WITH_SMARTDATA_CLASSES 1 /* * With thread support */ #define WITH_THREAD 1 #define WITH_THREAD_NATIVE 1 /* * With 64 bits support */ #define WITH_64BITS 1 #endif --- NEW FILE: constants.h --- /* * $Id: constants.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __CONSTANTS_H__ #define __CONSTANTS_H__ /* * Waba classic key constants. */ #define WABA_KEY_PAGE_UP 75000 #define WABA_KEY_PAGE_DOWN 75001 #define WABA_KEY_HOME 75002 #define WABA_KEY_END 75003 #define WABA_KEY_UP 75004 #define WABA_KEY_DOWN 75005 #define WABA_KEY_LEFT 75006 #define WABA_KEY_RIGHT 75007 #define WABA_KEY_INSERT 75008 #define WABA_KEY_ENTER 75009 #define WABA_KEY_TAB 75010 #define WABA_KEY_BACKSPACE 75011 #define WABA_KEY_ESCAPE 75012 #define WABA_KEY_DELETE 75013 #define WABA_KEY_MENU 75014 #define WABA_KEY_COMMAND 75015 /* * Waba classic event constants. */ #define WABA_EVENT_KEY_PRESS 100 #define WABA_EVENT_PEN_DOWN 200 #define WABA_EVENT_PEN_MOVE 201 #define WABA_EVENT_PEN_UP 202 #define WABA_EVENT_PEN_DRAG 203 #endif --- NEW FILE: debug.h --- /* * $Id: debug.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines support for debugging. * * ---------------------------------------------------------------------------- */ #ifndef __DEBUG_H__ #define __DEBUG_H__ #ifdef DEBUG_OPCODE #define OP_MAX_OP 202 static char * _OP_name [] = { "OP_nop", "OP_aconst_null", "OP_iconst_m1", "OP_iconst_0", "OP_iconst_1", "OP_iconst_2", "OP_iconst_3", "OP_iconst_4", "OP_iconst_5", "OP_lconst_0", "OP_lconst_1", "OP_fconst_0", "OP_fconst_1", "OP_fconst_2", "OP_dconst_0", "OP_dconst_1", "OP_bipush", "OP_sipush", "OP_ldc", "OP_ldc_w", "OP_ldc2_w", "OP_iload", "OP_lload", "OP_fload", "OP_dload", "OP_aload", "OP_iload_0", "OP_iload_1", "OP_iload_2", "OP_iload_3", "OP_lload_0", "OP_lload_1", "OP_lload_2", "OP_lload_3", "OP_fload_0", "OP_fload_1", "OP_fload_2", "OP_fload_3", "OP_dload_0", "OP_dload_1", "OP_dload_2", "OP_dload_3", "OP_aload_0", "OP_aload_1", "OP_aload_2", "OP_aload_3", "OP_iaload", "OP_laload", "OP_faload", "OP_daload", "OP_aaload", "OP_baload", "OP_caload", "OP_saload", "OP_istore", "OP_lstore", "OP_fstore", "OP_dstore", "OP_astore", "OP_istore_0", "OP_istore_1", "OP_istore_2", "OP_istore_3", "OP_lstore_0", "OP_lstore_1", "OP_lstore_2", "OP_lstore_3", "OP_fstore_0", "OP_fstore_1", "OP_fstore_2", "OP_fstore_3", "OP_dstore_0", "OP_dstore_1", "OP_dstore_2", "OP_dstore_3", "OP_astore_0", "OP_astore_1", "OP_astore_2", "OP_astore_3", "OP_iastore", "OP_lastore", "OP_fastore", "OP_dastore", "OP_aastore", "OP_bastore", "OP_castore", "OP_sastore", "OP_pop", "OP_pop2", "OP_dup", "OP_dup_x1", "OP_dup_x2", "OP_dup2", "OP_dup2_x1", "OP_dup2_x2", "OP_swap", "OP_iadd", "OP_ladd", "OP_fadd", "OP_dadd", "OP_isub", "OP_lsub", "OP_fsub", "OP_dsub", "OP_imul", "OP_lmul", "OP_fmul", "OP_dmul", "OP_idiv", "OP_ldiv", "OP_fdiv", "OP_ddiv", "OP_irem", "OP_lrem", "OP_frem", "OP_drem", "OP_ineg", "OP_lneg", "OP_fneg", "OP_dneg", "OP_ishl", "OP_lshl", "OP_ishr", "OP_lshr", "OP_iushr", "OP_lushr", "OP_iand", "OP_land", "OP_ior", "OP_lor", "OP_ixor", "OP_lxor", "OP_iinc", "OP_i2l", "OP_i2f", "OP_i2d", "OP_l2i", "OP_l2f", "OP_l2d", "OP_f2i", "OP_f2l", "OP_f2d", "OP_d2i", "OP_d2l", "OP_d2f", "OP_i2b", "OP_i2c", "OP_i2s", "OP_lcmp", "OP_fcmpl", "OP_fcmpg", "OP_dcmpl", "OP_dcmpg", "OP_ifeq", "OP_ifne", "OP_iflt", "OP_ifge", "OP_ifgt", "OP_ifle", "OP_if_icmpeq", "OP_if_icmpne", "OP_if_icmplt", "OP_if_icmpge", "OP_if_icmpgt", "OP_if_icmple", "OP_if_acmpeq", "OP_if_acmpne", "OP_goto", "OP_jsr", "OP_ret", "OP_tableswitch", "OP_lookupswitch", "OP_ireturn", "OP_lreturn", "OP_freturn", "OP_dreturn", "OP_areturn", "OP_return", "OP_getstatic", "OP_putstatic", "OP_getfield", "OP_putfield", "OP_invokevirtual", "OP_invokespecial", "OP_invokestatic", "OP_invokeinterface", "OP_new", "OP_newarray", "OP_anewarray", "OP_arraylength", "OP_athrow", "OP_checkcast", "OP_instanceof", "OP_monitorenter", "OP_monitorexit", "OP_wide", "OP_multianewarray", "OP_ifnull", "OP_ifnonnull", "OP_goto_w", "OP_jsr_w", "OP_breakpoint" }; #endif #endif --- NEW FILE: error.c --- /* * $Id: error.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Implements support for errors. * * ---------------------------------------------------------------------------- */ #include "waba.h" #include "error.h" void VmError( uint16 errNum, WClass *iclass, UtfString *desc1, UtfString *desc2 ) { WClass *wclass; WClassMethod *method; UtfString className, iclassName, methodName, methodDesc; // NOTE: Don't overwrite an existing error since it may be the // root cause of this error. if (vmStatus.errNum != 0) return; vmStatus.errNum = errNum; // get current class and method off stack if (vmStackPtr > 0) { wclass = (WClass *)vmStack[vmStackPtr - 1].refValue; method = (WClassMethod *)vmStack[vmStackPtr - 2].refValue; } else { wclass = 0; method = 0; } // output class and method name if (wclass) { className = getUtfString(wclass, wclass->classNameIndex); printToBuf(vmStatus.className, 40, &className, NULL); } if (method) { methodName = getUtfString(wclass, METH_nameIndex(method)); methodDesc = getUtfString(wclass, METH_descIndex(method)); printToBuf(vmStatus.methodName, 40, &methodName, &methodDesc); } // output additional error arguments (target class, desc, etc.) if (iclass) { iclassName = getUtfString(iclass, iclass->classNameIndex); printToBuf(vmStatus.arg1, 40, &iclassName, NULL); } printToBuf(vmStatus.arg2, 40, desc1, desc2); #ifdef WIN32 #ifndef WINCE dumpStackTrace(); #endif #endif } void VmQuickError(uint16 errNum) { VmError( errNum, NULL, NULL, NULL ); } --- NEW FILE: error.h --- /* * $Id: error.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines support for errors. * * ---------------------------------------------------------------------------- */ #ifndef __ERROR_H__ #define __ERROR_H__ /* * Error messages */ static char *errorMessages[] = { "sanity", "incompatible device", "can't access waba classes", "can't access app classes", "can't allocate memory", "out of class memory", "out of object memory", "native stack overflow", "native stack underflow", "stack overflow", "bad class", "bad opcode", "can't find class", "can't find method", "can't find field", "null object access", "null array access", "index out of range", "divide by zero", "bad class cast", "class too large" }; /* * Fatal errors */ #define ERR_SanityCheckFailed 1 #define ERR_IncompatibleDevice 2 #define ERR_CantAccessCoreClasses 3 #define ERR_CantAccessAppClasses 4 #define ERR_CantAllocateMemory 5 #define ERR_OutOfClassMem 6 #define ERR_OutOfObjectMem 7 #define ERR_NativeStackOverflow 8 #define ERR_NativeStackUnderflow 9 #define ERR_StackOverflow 10 /* * Program errors */ #define ERR_BadClass 11 #define ERR_BadOpcode 12 #define ERR_CantFindClass 13 #define ERR_CantFindMethod 14 #define ERR_CantFindField 15 #define ERR_NullObjectAccess 16 #define ERR_NullArrayAccess 17 #define ERR_IndexOutOfRange 18 #define ERR_DivideByZero 19 #define ERR_ClassCastException 20 #define ERR_ClassTooLarge 21 /* * Function prototypes * ------------------- * * NOTE: the function prototypes should be enabled here once we have finished * cleaning up interdepencies. * * void VmError( uint16 errNum, * WClass *iclass, * UtfString *desc1, * UtfString *desc2); * * void VmQuickError( uint16 errNum ); */ #endif --- NEW FILE: exception.h --- /* * $Id: exception.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines the exception support in the VM. * * ---------------------------------------------------------------------------- */ #ifndef __EXCEPTION_H__ #define __EXCEPTION_H__ #endif --- NEW FILE: memory.c --- /* * $Id: memory.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Memory Management * ----------------- * * Here's the garbage collector. I implemented the mark and sweep below after * testing out a few different ones and reading: * * Garbage Collection, Algorithms for Automatic Dynamic Memory Management * by Richard Jones and Rafael Lins * * which is an excellent book. Also, this collector has gone through a lot of * testing. It runs when the system is completely out of memory which can * happen at any time ... for example during class loading. * * To test it out, tests were run where 1000's of random objects were loaded, * constructed and random methods called on them over some period of days. * This found a couple subtle bugs that were fixed like when the garbage * collector ran in the middle of array allocation and moved pointers around * from under the array allocator code ( those have all been fixed ). * * The heap is comprised of Hos objects (an array) that grows from the * "right" of object memory and objects that take up the space on on the * "left" side. The Hos array keeps track of where the objects are on the * left. * * The Hos structure (strange, but aptly named) is used to keep track of * handles (pointers to memory locations), order (order of handles with * respect to memory) and temporary items (used during the scan phase). * * The 3 items in the Hos structure do not relate to each other. They are * each a part of 3 conceptually distinct arrays that grow from the right of * the heap while the objects grow from the left. So, when the Hos array is * indexed, it is always negative (first element is 0, next is -1, next * is -2, etc). * * ---------------------------------------------------------------------------- */ #include "waba.h" #include "memory.h" /* * The heap with objects. */ static ObjectHeap heap; #define VALID_OBJ(o) (o > FIRST_OBJ && o <= FIRST_OBJ + heap.numHandles) // mark bits in the handle order array since it is not used during // the mark object process (its used in the sweep phase) #define MARK(o) heap.hos[- (int32)(o - FIRST_OBJ - 1)].order |= 0x80000000 #define IS_MARKED(o) (heap.hos[- (int32)(o - FIRST_OBJ - 1)].order & 0x80000000) /* * NOTE: There are no waba methods that are called when objects are destroyed. * This is because if a method was called, the object would be on its * way to being GC'd and if we set another object (or static field) to * reference it, after the GC, the reference would be stale. */ void sweep() { WObject obj; WClass *wclass; uint32 i, h, objSize, prevObjectSize, numUsedHandles; uchar *src, *dst; prevObjectSize = heap.objectSize; heap.objectSize = 0; // move all the marks over into the scan array so we don't have // to do lots of bit shifting for (i = 0; i < heap.numHandles; i++) { if (heap.hos[- (int32)i].order & 0x80000000) { heap.hos[- (int32)i].order &= 0x7FFFFFFF; // clear mark bit heap.hos[- (int32)i].temp = 1; } else { heap.hos[- (int32)i].temp = 0; } } numUsedHandles = 0; for (i = 0; i < heap.numHandles; i++) { // we need to scan in memory order so we can compact things without // copying objects over each other h = heap.hos[- (int32)i].order; obj = h + FIRST_OBJ + 1; if (!heap.hos[- (int32)h].temp) { // handle is free - dereference object if (objectPtr(obj) != NULL) { wclass = WOBJ_class(obj); // for non-arrays, call objDestroy if present if (wclass != NULL && wclass->objDestroyFunc) wclass->objDestroyFunc(obj); heap.hos[- (int32)h].ptr = NULL; } continue; } wclass = WOBJ_class(obj); if (wclass == NULL) objSize = arraySize(WOBJ_arrayType(obj), WOBJ_arrayLen(obj)); else objSize = WCLASS_objectSize(wclass); // copy object to new heap src = (uchar *)heap.hos[- (int32)h].ptr; dst = &heap.mem[heap.objectSize]; if (src != dst) // NOTE: overlapping regions need to copy correctly xmemmove(dst, src, objSize); heap.hos[- (int32)h].ptr = (Var *)dst; heap.hos[- (int32)numUsedHandles].order = h; heap.objectSize += objSize; numUsedHandles++; } heap.numFreeHandles = heap.numHandles - numUsedHandles; for (i = 0; i < heap.numHandles; i++) if (!heap.hos[- (int32)i].temp) { // add free handle to free section of order array heap.hos[- (int32)numUsedHandles].order = i; numUsedHandles++; } // zero out the part of the heap that is now junk xmemzero(&heap.mem[heap.objectSize], prevObjectSize - heap.objectSize); } /* * NOTE: this method is only for printing the status of memory and can be * removed. Also note, there is no such thing as the "amount of free * memory" because of garbage collection. */ uint32 getUnusedMem() { return heap.memSize - (heap.objectSize + (heap.numHandles * sizeof(Hos))); } int initObjectHeap(uint32 heapSize) { // NOTE: we must intiailize all the variables since after // a freeObjectHeap() we get called again heap.numHandles = 0; heap.numFreeHandles = 0; heap.memSize = heapSize; #if FIXED_OBJECT_HEAP_SIZE > 0 // align to 4 byte boundry for correct alignment of the Hos array heap.memSize = sizeof(objectHeapArea); // allocate and zero out memory region heap.mem = &objectHeapArea[0]; #else // align to 4 byte boundry for correct alignment of the Hos array heap.memSize = (heap.memSize + 3) & ~3; // allocate and zero out memory region heap.mem = (uchar *)xmalloc(heap.memSize); if (heap.mem == NULL) return -1; #endif xmemzero(heap.mem, heap.memSize); heap.hos = (Hos *)(&heap.mem[heap.memSize - sizeof(Hos)]); heap.objectSize = 0; return 0; } void freeObjectHeap() { #ifdef FREE_ON_EXIT { WObject obj; uint32 h; WClass *wclass; // call any native object destroy methods to free system resources for (h = 0; h < heap.numHandles; h++) { obj = h + FIRST_OBJ + 1; if (objectPtr(obj) != NULL) { wclass = WOBJ_class(obj); if (wclass != NULL && wclass->objDestroyFunc) wclass->objDestroyFunc(obj); } } } #endif #if FIXED_OBJECT_HEAP_SIZE <= 0 if (heap.mem) xfree(heap.mem); #endif } // mark this object and all the objects this object refers to and all // objects those objects refer to, etc. void markObject(WObject obj) { WClass *wclass; WObject *arrayStart, o; uint32 i, len, type, numScan; if (!VALID_OBJ(obj) || objectPtr(obj) == NULL || IS_MARKED(obj)) return; MARK(obj); numScan = 0; markinterior: wclass = WOBJ_class(obj); if (wclass == NULL) { // array - see if it contains object references type = WOBJ_arrayType(obj); if (type == 1 || type == 2) { // for an array of arrays or object array arrayStart = (WObject *)WOBJ_arrayStart(obj); len = WOBJ_arrayLen(obj); for (i = 0; i < len; i++) { o = arrayStart[i]; if (VALID_OBJ(o) && objectPtr(o) != NULL && !IS_MARKED(o)) { MARK(o); heap.hos[- (int32)numScan].temp = o; numScan++; } } } } else { // object len = wclass->numVars; for (i = 0; i < len; i++) { o = WOBJ_var(obj, i).obj; if (VALID_OBJ(o) && objectPtr(o) != NULL && !IS_MARKED(o)) { MARK(o); heap.hos[- (int32)numScan].temp = o; numScan++; } } } if (numScan > 0) { // Note: we use goto since we want to avoid recursion here // since structures like linked links could create deep // stack calls --numScan; obj = heap.hos[- (int32)numScan].temp; goto markinterior; } } // NOTE: size passed must be 4 byte aligned (see arraySize()) WObject allocObject(int32 size) { uint32 i, sizeReq, hosSize; if (size <= 0) return 0; sizeReq = size; if (!heap.numFreeHandles) sizeReq += sizeof(Hos); hosSize = heap.numHandles * sizeof(Hos); if (sizeReq + hosSize + heap.objectSize > heap.memSize) { gc(); // heap.objectSize changed or we are out of memory if (sizeReq + hosSize + heap.objectSize > heap.memSize) { VmQuickError(ERR_OutOfObjectMem); return 0; } } if (heap.numFreeHandles) { i = heap.hos[- (int32)(heap.numHandles - heap.numFreeHandles)].order; heap.numFreeHandles--; } else { // no free handles, get a new one i = heap.numHandles; heap.hos[- (int32)i].order = i; heap.numHandles++; } heap.hos[- (int32)i].ptr = (Var *)&heap.mem[heap.objectSize]; heap.objectSize += size; return FIRST_OBJ + i + 1; } // NOTE: we made this function a #define and it showed no real performance // gain over having it a function on either PalmOS or Windows when // optimization was turned on. Var *objectPtr(WObject obj) { return heap.hos[- (int32)(obj - FIRST_OBJ - 1)].ptr; } void gc() { WClass *wclass; WObject obj; uint32 i, j; // mark objects on vm stack for (i = 0; i < vmStackPtr; i++) if (VALID_OBJ(vmStack[i].obj)) markObject(vmStack[i].obj); // mark objects on native stack for (i = 0; i < nmStackPtr; i++) if (VALID_OBJ(nmStack[i])) markObject(nmStack[i]); // mark all static class objects for (i = 0; i < CLASS_HASH_SIZE; i++) { wclass = classHashList[i]; while (wclass != NULL) { for (j = 0; j < wclass->numFields; j++) { WClassField *field; field = &wclass->fields[j]; if (!FIELD_isStatic(field)) continue; obj = field->var.staticVar.obj; if (VALID_OBJ(obj)) markObject(obj); } wclass = wclass->nextClass; } } sweep(); #ifdef DEBUGMEMSIZE debugMemSize(); #endif } --- NEW FILE: memory.h --- /* * $Id: memory.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines support for memory management. * * ---------------------------------------------------------------------------- */ #ifndef __MEMORY_H__ #define __MEMORY_H__ #define FIRST_OBJ 2244 typedef struct { Var *ptr; uint32 order; uint32 temp; } Hos; /* * NOTE: The total amount of memory used up at any given time in the heap is: * objectSize + ( numHandles * sizeof( Hos ) ) */ typedef struct { Hos *hos; /* handle, order and scan arrays (interlaced) */ uint32 numHandles; /* */ uint32 numFreeHandles; /* */ uchar *mem; /* */ uint32 memSize; /* total size of memory (including free) */ uint32 objectSize; /* size of all objects in heap */ } ObjectHeap; #endif --- NEW FILE: native.c --- /* * $Id: native.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "waba.h" #include "native.h" --- NEW FILE: native.h --- /* * $Id: native.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __NATIVE_H__ #define __NATIVE_H__ #endif --- NEW FILE: nmwin32_a.c --- /* $Id: nmwin32_a.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ Copyright (C) 1998, 1999, 2000 Wabasoft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* all the needed include */ #include "../waba.h" // // type converters // #ifdef WITH_64BITS // get one 64 float value from buf and return it float64 getFloat64bits(uchar *buf) { float64HiLo fhl; fhl.ul.lo = getInt32( buf ); fhl.ul.hi = getInt32( buf + 4 ); return fhl.value; } // get one 64 float value from buf and return it int64 getInt64bits(uchar *buf) { int64HiLo ihl; ihl.ul.lo = getInt32( buf ); ihl.ul.hi = getInt32( buf + 4 ); return ihl.value; } #endif /* WITH_64BITS */ float32 getFloat32(uchar *buf) { uint32 i; float32 f; // we need to make sure we're aligned before casting i = ((uint32)buf[0] << 24) | ((uint32)buf[1] << 16) | ((uint32)buf[2] << 8) | (uint32)buf[3]; f = *((float32 *)&i); return f; } --- NEW FILE: nmwin32_a.h --- /* * $Id: nmwin32_a.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __NMWIN32_A_H__ #define __NMWIN32_A_H__ #include <tchar.h> #include <windows.h> #include <stdlib.h> #ifndef WINCE #include <stdio.h> #include <fcntl.h> #include <conio.h> #endif #ifdef WINCE #include <winsock.h> #include <winnetwk.h> #endif #undef FREE_ON_EXIT #undef SECURE_CLASS_HEAP #define LOCK_CLASS_HEAP #define UNLOCK_CLASS_HEAP #define uchar unsigned char #define int32 int #define uint32 unsigned int #define float32 float #define int16 short #define uint16 unsigned short #ifdef WITH_64BITS // - int64 is a signed 64 bit value #define int64 __int64 //INT64 //long long // - uint64 is an unsigned 64 bit value #define uint64 unsigned __int64 //UINT64 //unsigned long long // - float64 is a signed 64 bit floating point value #define float64 double // --- define a struct for double and long support in two Var ... // ... the hi/lo decomposition typedef struct { uint32 lo; uint32 hi; } HiLoDoubleOrLong; //... for the double typedef union { float64 value; HiLoDoubleOrLong ul; } float64HiLo; //... for the long typedef union { int64 value; HiLoDoubleOrLong ul; } int64HiLo; #endif /* WITH_64BITS */ #define cprintf printf // // type converters // #define getUInt32(b) (uint32)( (uint32)((b)[0])<<24 | (uint32)((b)[1])<<16 | (uint32)((b)[2])<<8 | (uint32)((b)[3]) ) #define getUInt16(b) (uint16)(((b)[0]<<8)|(b)[1]) #define getInt32(b) (int32)( (uint32)((b)[0])<<24 | (uint32)((b)[1])<<16 | (uint32)((b)[2])<<8 | (uint32)((b)[3]) ) #define getInt16(b) (int16)(((b)[0]<<8)|(b)[1]) #ifdef WITH_64BITS // get one 64 float value from buf and return it float64 getFloat64bits(uchar *buf); // get one 64 float value from buf and return it int64 getInt64bits(uchar *buf); #endif /* WITH_64BITS */ float32 getFloat32(uchar *buf); // // x portability functions // // NOTE: The str, mem and malloc routines aren't documented in the reference // manuals for CE, however, the methods do exist in the CE library and have // prototypes, etc. #define xstrncmp(s1, s2, n) strncmp(s1, s2, n) #define xstrncpy(dst, src, n) strncpy(dst, src, n) #define xstrlen(s) strlen(s) #define xstrcat(dst, src) strcat(dst, src) #define xmemmove(dst, src, size) memmove(dst, src, size) #define xmemzero(mem, len) memset(mem, 0, len) #define xmalloc(size) malloc(size); #define xfree(ptr) free(ptr) #endif /* __NMWIN32_A_H__ */ --- NEW FILE: nmwin32_b.c --- /* $Id: nmwin32_b.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ Copyright (C) 1998, 1999, 2000 Wabasoft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* all the needed include */ #include "../waba.h" [...1705 lines suppressed...] FILE *fp; AllocConsole(); GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &coninfo ); coninfo.dwSize.Y = 500; SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), coninfo.dwSize ); lStdHandle = (long) GetStdHandle( STD_OUTPUT_HANDLE ); hConHandle = _open_osfhandle( lStdHandle, _O_TEXT ); fp = _fdopen( hConHandle, "w" ); *stdout = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); #endif } --- NEW FILE: nmwin32_b.h --- /* $Id: nmwin32_b.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ */ #ifndef __NMWIN32_B_H__ #define __NMWIN32_B_H__ /* Copyright (C) 1998, 1999, 2000 Wabasoft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ static int g_mainWinWidth = 0; static int g_mainWinHeight = 0; static DWORD g_startTime = 0; static DWORD g_messageTime = 0; static HINSTANCE g_hInstance; static TCHAR *pszWndClassName = TEXT("WabaWndClass"); #define WARP_CORE_PATH "\\Program Files\\waba\\waba.wrp" #define MAX_CLASSPATHS 20 static int numClassPaths = -1; static char *classPaths[MAX_CLASSPATHS]; typedef struct { HANDLE fileH; HANDLE mapH; int viewIsMapped; uchar *ptr; } MemFile; #define MAX_MEM_FILES 16 static MemFile memFiles[MAX_MEM_FILES]; static uint32 numMemFiles = 0; static int memFileNotSupported = 0; static int win32WSAStarted = 0; #ifdef QUICKBIND static int32 postPaintMethodMapNum = -1; static int32 postEventMethodMapNum = -1; static int32 onTimerTickMethodMapNum = -1; #endif int asciiToUnicode(char *src, TCHAR *dst, int max); WObject createStringFromUnicode(TCHAR *s, uint32 len); uchar *loadFromMem(char *path, uint32 pathLen, uint32 *size); uchar *readFileIntoMemory(char *path, int nullTerminate, uint32 *size); int32 getTimeStamp(); void dumpStackTrace(); uchar *nativeLoadClass(UtfString className, uint32 *size); #ifdef WITH_THREAD //*** Monaka's Multithread implemantasion //*** based on Isao's Multithread implementation #define THREAD_LIST_MAX_SIZE 8 typedef struct _queue { struct _queue *next; struct _queue *prev; } Queue; typedef struct { //Use either "syncObj" or "syncMethod", //Not both at the same time. WObject syncObj; WClassMethod* syncMethod; #ifdef WITH_THREAD_NATIVE CRITICAL_SECTION syncLock; #endif } WSync; typedef struct { WObject signalObj; #ifdef WITH_THREAD_NATIVE HANDLE signalHandle; #endif } WSignal; //This trick is necessary for Win32 native threads. typedef struct { WClass* vclass; WClassMethod* method; Var params[7]; uint32 paramSize; } WVmParam; typedef struct { Queue queue; /* 'Queue' must be first to use type cast trick. */ WClass* tClass; WObject tObject; //Since I don't know how to override: //"java.Object.wait()", //"java.Object.notify()", and //"java.Object.notifyAll()" //witout getting a JDK 1.2.2 compiler error, //I have coded so that "Thread" class handles the synchronization. //Someone who can handle this, any help wl be appreciated. WSync wSyncObj; WSignal wSignal; int32 runMethodMapNum; uint32 sleepCountSet; uint32 sleepCountNow; uchar isSleepCountAlreadySet; uchar isWaiting; //This trick is necessary for Win32 native threads. #ifdef WITH_THREAD_NATIVE WVmParam wParams; HANDLE wThreadHandle; DWORD wThreadID; #endif } WThread; extern int InitThread(uint32 stack_size); //*** This "ThreadStart()" method is called from "start()" method. extern Var ThreadStart(Var stack[]); //*** This "ThreadStop()" method is called from "stop()" method. extern Var ThreadStop(Var stack[]); void ThreadDestroy(WObject targetObj); //*** This "ThreadSleep()" method is called from "sleep()" method. extern Var ThreadSleep(Var stack[]); //*** This "ThreadWaitForSignal()" method is called from "waitForSignal()" method. extern Var ThreadWaitForSignal(Var stack[]); extern Var ThreadSignalAll(Var stack[]); //*** Isao's Multithread implementation END *** //*** This "ThreadCurrentThread()" method is called from "curentThread()" method. extern Var ThreadCurrentThread(Var stack[]); void tickThread(void); int registerAsSyncronized(WClassMethod* method); void exitFromSyncronized(WClassMethod* method); int enterMonitor(WObject obj); int exitMonitor(WObject obj); #ifdef WITH_DOUBLE_BUFFER void setMainWinObj(WObject winObj); WObject getMainWinObj(void); WObject theMainWinObj; #endif #endif /* WITH_THREAD */ #endif /* __NMWIN32_B_H__ */ --- NEW FILE: nmwin32_c.c --- /* $Id: nmwin32_c.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ Copyright (C) 1998, 1999, 2000 Wabasoft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // NOTE: General rule for native functions.. don't hold a pointer across any // call that could garbage collect. For example, this is bad: [...3881 lines suppressed...] NULL); WriteFile(hCout, str.str, str.len, &cbWritten, NULL); CloseHandle(hCout); return v; } #ifdef WIN32 Var SystemInit( Var stack[] ) { Var v; printf( "SystemInit\n" ); v.obj = 0; return v; } #endif --- NEW FILE: nmwin32_c.h --- /* $Id: nmwin32_c.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ */ #ifndef __NMWIN32_C_H__ #define __NMWIN32_C_H__ /* Copyright (C) 1998, 1999, 2000 Wabasoft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef WITH_DOUBLE_BUFFER HBITMAP hMainScrBitmap; HBITMAP hOffScrBitmap; HDC hMainScrDC; HDC hOffScrDC; HWND hMainWnd; int mainWinWidth, mainWinHeight; HDC createOffScreenBuffer(WObject winObj); void deleteOffScreenBuffer(void); void paint(void); #endif //*** Isao's internationalization stuff START *** //static HFONT createWin32Font(WObject font, HDC hDC); static HFONT createWin32Font(WObject font); //*** Isao's internationalization stuff END *** static void WindowDestroy(WObject obj); static void MainWinDestroy(WObject obj); static void GraphicsDestroy(WObject obj); static void ImageDestroy(WObject obj); #if WITH_CATALOG static void CatalogDestroy(WObject obj); #endif static void FileDestroy(WObject obj); static void SocketDestroy(WObject obj); static void SerialPortDestroy(WObject obj); extern ClassHook classHooks[]; #define FUNC(f) extern Var f (Var stack[]) /* some generic functions */ FUNC(Return0Func); FUNC(ReturnNeg1Func); /* all the native functions */ FUNC(VmPrintLn); FUNC(VmPrint); FUNC(VmExec); FUNC(VmGetTimeStamp); FUNC(copyArray); FUNC(VmExit); FUNC(VmSleep); FUNC(VmSetDeviceAutoOff); FUNC(VmGetUserName); FUNC(VmGetPlatform); FUNC(VmIsColor); FUNC(FileGetLength); FUNC(FileCreateDir); FUNC(FileReadBytes); FUNC(FileRename); FUNC(FileCreate); FUNC(FileWriteBytes); FUNC(FileListDir); FUNC(FileSeekWaba); FUNC(FileIsDir); FUNC(FileCloseWaba); FUNC(FileIsOpen); FUNC(FileDeleteWaba); FUNC(FileExists); FUNC(ImageCreate); FUNC(ImageFree); FUNC(ImageSetPixels); FUNC(ImageUseImagePalette); FUNC(ImageLoad); FUNC(SoundBeep); FUNC(SoundTone); FUNC(TimeCreate); FUNC(SocketCreate); FUNC(SocketRead); FUNC(SocketWrite); FUNC(SocketSetReadTimeout); FUNC(SocketClose); FUNC(SocketIsOpen); FUNC(WindowCreate); #if WITH_CATALOG FUNC(CatalogListCatalogs); FUNC(CatalogAddRecord); FUNC(CatalogSkipBytes); FUNC(CatalogCreate); FUNC(CatalogRead); FUNC(CatalogDeleteRecord); FUNC(CatalogSetRecordPos); FUNC(CatalogGetRecordSize); FUNC(CatalogResizeRecord); FUNC(CatalogWrite); FUNC(CatalogGetRecordCount); FUNC(CatalogClose); FUNC(CatalogIsOpen); FUNC(CatalogDelete); #endif //WITH_CATALOG FUNC(GraphicsCopyRect); FUNC(GraphicsClearClip); FUNC(GraphicsSetFont); FUNC(GraphicsSetDrawOp); FUNC(GraphicsSetClip); FUNC(GraphicsSetBackColor); FUNC(GraphicsSetColor); FUNC(GraphicsGetClip); FUNC(GraphicsFillRect); FUNC(GraphicsDrawLine); FUNC(GraphicsTranslate); FUNC(GraphicsDrawDots); FUNC(GraphicsDrawChars); FUNC(GraphicsCreate); FUNC(GraphicsDrawCursor); FUNC(GraphicsSetClip); FUNC(GraphicsFree); FUNC(GraphicsSetForeColor); FUNC(GraphicsSetTextColor); FUNC(GraphicsFillPolygon); FUNC(GraphicsDrawString); FUNC(ConvertStringToInt); FUNC(ConvertFloatToIntBitwise); FUNC(ConvertCharToString); FUNC(ConvertIntToFloatBitwise); FUNC(ConvertFloatToString); FUNC(ConvertDoubleToString); FUNC(ConvertIntToString); FUNC(ConvertLongToString); FUNC(ConvertBooleanToString); FUNC(SoundClipPlay); FUNC(PalmOsPrefSetPalmOsPref); FUNC(PalmOsPrefGetPalmOsPref); FUNC(MainWinCreate); FUNC(MainWinExit); FUNC(MainWinSetTimerInterval); #ifdef WITH_DOUBLE_BUFFER FUNC(MainWinPaint); #endif FUNC(SerialPortReadCheck); FUNC(SerialPortRead); FUNC(SerialPortWrite); FUNC(SerialPortSetReadTimeout); FUNC(SerialPortClose); FUNC(SerialPortSetFlowControl); FUNC(SerialPortIsOpen); FUNC(SerialPortCreate); FUNC(FontMetricsGetStringWidth); FUNC(FontMetricsGetCharWidth); FUNC(FontMetricsCreate); FUNC(FontMetricsGetCharArrayWidth); /* * Begin of J2ME compliant code. */ #ifdef WIN32 FUNC(SystemInit); #endif #endif /* __NMWIN32_C_H__ */ --- NEW FILE: opcodes.h --- /* * $Id: opcodes.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines all the opcodes known by the JVM. * * ---------------------------------------------------------------------------- */ #ifndef __OPCODES_H__ #define __OPCODES_H__ #define OP_nop 0 #define OP_aconst_null 1 #define OP_iconst_m1 2 #define OP_iconst_0 3 #define OP_iconst_1 4 #define OP_iconst_2 5 #define OP_iconst_3 6 #define OP_iconst_4 7 #define OP_iconst_5 8 #define OP_lconst_0 9 #define OP_lconst_1 10 #define OP_fconst_0 11 #define OP_fconst_1 12 #define OP_fconst_2 13 #define OP_dconst_0 14 #define OP_dconst_1 15 #define OP_bipush 16 #define OP_sipush 17 #define OP_ldc 18 #define OP_ldc_w 19 #define OP_ldc2_w 20 #define OP_iload 21 #define OP_lload 22 #define OP_fload 23 #define OP_dload 24 #define OP_aload 25 #define OP_iload_0 26 #define OP_iload_1 27 #define OP_iload_2 28 #define OP_iload_3 29 #define OP_lload_0 30 #define OP_lload_1 31 #define OP_lload_2 32 #define OP_lload_3 33 #define OP_fload_0 34 #define OP_fload_1 35 #define OP_fload_2 36 #define OP_fload_3 37 #define OP_dload_0 38 #define OP_dload_1 39 #define OP_dload_2 40 #define OP_dload_3 41 #define OP_aload_0 42 #define OP_aload_1 43 #define OP_aload_2 44 #define OP_aload_3 45 #define OP_iaload 46 #define OP_laload 47 #define OP_faload 48 #define OP_daload 49 #define OP_aaload 50 #define OP_baload 51 #define OP_caload 52 #define OP_saload 53 #define OP_istore 54 #define OP_lstore 55 #define OP_fstore 56 #define OP_dstore 57 #define OP_astore 58 #define OP_istore_0 59 #define OP_istore_1 60 #define OP_istore_2 61 #define OP_istore_3 62 #define OP_lstore_0 63 #define OP_lstore_1 64 #define OP_lstore_2 65 #define OP_lstore_3 66 #define OP_fstore_0 67 #define OP_fstore_1 68 #define OP_fstore_2 69 #define OP_fstore_3 70 #define OP_dstore_0 71 #define OP_dstore_1 72 #define OP_dstore_2 73 #define OP_dstore_3 74 #define OP_astore_0 75 #define OP_astore_1 76 #define OP_astore_2 77 #define OP_astore_3 78 #define OP_iastore 79 #define OP_lastore 80 #define OP_fastore 81 #define OP_dastore 82 #define OP_aastore 83 #define OP_bastore 84 #define OP_castore 85 #define OP_sastore 86 #define OP_pop 87 #define OP_pop2 88 #define OP_dup 89 #define OP_dup_x1 90 #define OP_dup_x2 91 #define OP_dup2 92 #define OP_dup2_x1 93 #define OP_dup2_x2 94 #define OP_swap 95 #define OP_iadd 96 #define OP_ladd 97 #define OP_fadd 98 #define OP_dadd 99 #define OP_isub 100 #define OP_lsub 101 #define OP_fsub 102 #define OP_dsub 103 #define OP_imul 104 #define OP_lmul 105 #define OP_fmul 106 #define OP_dmul 107 #define OP_idiv 108 #define OP_ldiv 109 #define OP_fdiv 110 #define OP_ddiv 111 #define OP_irem 112 #define OP_lrem 113 #define OP_frem 114 #define OP_drem 115 #define OP_ineg 116 #define OP_lneg 117 #define OP_fneg 118 #define OP_dneg 119 #define OP_ishl 120 #define OP_lshl 121 #define OP_ishr 122 #define OP_lshr 123 #define OP_iushr 124 #define OP_lushr 125 #define OP_iand 126 #define OP_land 127 #define OP_ior 128 #define OP_lor 129 #define OP_ixor 130 #define OP_lxor 131 #define OP_iinc 132 #define OP_i2l 133 #define OP_i2f 134 #define OP_i2d 135 #define OP_l2i 136 #define OP_l2f 137 #define OP_l2d 138 #define OP_f2i 139 #define OP_f2l 140 #define OP_f2d 141 #define OP_d2i 142 #define OP_d2l 143 #define OP_d2f 144 #define OP_i2b 145 #define OP_i2c 146 #define OP_i2s 147 #define OP_lcmp 148 #define OP_fcmpl 149 #define OP_fcmpg 150 #define OP_dcmpl 151 #define OP_dcmpg 152 #define OP_ifeq 153 #define OP_ifne 154 #define OP_iflt 155 #define OP_ifge 156 #define OP_ifgt 157 #define OP_ifle 158 #define OP_if_icmpeq 159 #define OP_if_icmpne 160 #define OP_if_icmplt 161 #define OP_if_icmpge 162 #define OP_if_icmpgt 163 #define OP_if_icmple 164 #define OP_if_acmpeq 165 #define OP_if_acmpne 166 #define OP_goto 167 #define OP_jsr 168 #define OP_ret 169 #define OP_tableswitch 170 #define OP_lookupswitch 171 #define OP_ireturn 172 #define OP_lreturn 173 #define OP_freturn 174 #define OP_dreturn 175 #define OP_areturn 176 #define OP_return 177 #define OP_getstatic 178 #define OP_putstatic 179 #define OP_getfield 180 #define OP_putfield 181 #define OP_invokevirtual 182 #define OP_invokespecial 183 #define OP_invokestatic 184 #define OP_invokeinterface 185 #define OP_new 187 #define OP_newarray 188 #define OP_anewarray 189 #define OP_arraylength 190 #define OP_athrow 191 #define OP_checkcast 192 #define OP_instanceof 193 #define OP_monitorenter 194 #define OP_monitorexit 195 #define OP_wide 196 #define OP_multianewarray 197 #define OP_ifnull 198 #define OP_ifnonnull 199 #define OP_goto_w 200 #define OP_jsr_w 201 #define OP_breakpoint 202 #endif --- NEW FILE: thread.h --- /* * $Id: thread.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines support for threads. * * ---------------------------------------------------------------------------- */ #ifndef __THREAD_H__ #define __THREAD_H__ #endif --- NEW FILE: types.h --- /* * $Id: types.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ---------------------------------------------------------------------------- * * Defines the basic types used in the VM. * * ---------------------------------------------------------------------------- */ #ifndef __TYPES_H__ #define __TYPES_H__ #if defined(DOS) #include "dos/nmdos_a.h" #elif defined(LINUX) #include "linux/nm_linux_a.h" #elif defined(PALMOS) #include "palm/nmpalm_a.h" #elif defined(TOPPERS) #include "toppers/nmtoppers_a.h" #elif defined(WIN32) #include "nmwin32_a.h" #elif defined(WINCE) #include "win32/nmwin32_a.h" #endif #endif --- NEW FILE: waba.c --- /* * $Id: waba.c,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (C) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * --------------------------------------------------------------------------- * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * [...5445 lines suppressed...] stack++; } else if (pushReturnedValue == 2) { stack[0] = returnedValue; stack[1] = returnedValue2; stack += 2; } var = (Var *)vmStack[--vmStackPtr].refValue; pc = vmStack[--vmStackPtr].pc; wclass = (WClass *)vmStack[vmStackPtr - 1].refValue; method = (WClassMethod *)vmStack[vmStackPtr - 2].refValue; goto step; } /* * --END */ --- NEW FILE: waba.h --- /* * $Id: waba.h,v 1.1 2004/12/20 23:24:50 mriem Exp $ * * Copyright (c) 2001, 2002, 2003, Waba @ Sourceforge. * Copyright (c) 1998, 1999, 2000, Wabasoft. * All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * -------------------------------------------------------------------------- * * "True words are not beautiful, beautiful words are not true. * The good are not argumentative, the argumentative are not good. * Knowers do not generalize, generalists do not know. * Sages do not accumulate anything but give everything to others, * having more the more they give. * The Way of heaven helps and does not harm. * The Way for humans is to act without contention." * * - Lao-tzu, Tao Te Ching circa 500 B.C. * * -------------------------------------------------------------------------- */ #ifndef __WABA_H__ #define __WABA_H__ #include "config.h" #include "types.h" #include "debug.h" #include "error.h" #include "exception.h" #include "opcodes.h" #include "constants.h" #include "thread.h" // // TYPES AND METHODS // // Access flags #define ACCESS_PUBLIC 0x0001 #define ACCESS_PRIVATE 0x0002 #define ACCESS_PROTECTED 0x0004 #define ACCESS_STATIC 0x0008 #define ACCESS_FINAL 0x0010 #define ACCESS_SYNCHRONIZED 0x0020 #define ACCESS_VOLATILE 0x0040 #define ACCESS_TRANSIENT 0x0080 #define ACCESS_NATIVE 0x0100 #define ACCESS_INTERFACE 0x0200 #define ACCESS_ABSTRACT 0x0400 // Constant Pool tags #define CONSTANT_Utf8 1 #define CONSTANT_Integer 3 #define CONSTANT_Float 4 #define CONSTANT_Long 5 #define CONSTANT_Double 6 #define CONSTANT_Class 7 #define CONSTANT_String 8 #define CONSTANT_Fieldref ... [truncated message content] |