You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(135) |
Jul
(116) |
Aug
(33) |
Sep
(16) |
Oct
|
Nov
(30) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
|
Feb
|
Mar
|
Apr
(16) |
May
(26) |
Jun
|
Jul
(23) |
Aug
(24) |
Sep
|
Oct
|
Nov
|
Dec
|
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(8) |
Sep
|
Oct
|
Nov
|
Dec
|
From: Keith J. <bu...@us...> - 2003-08-08 11:38:24
|
Update of /cvsroot/cup-language/cup/src/vm In directory sc8-pr-cvs1:/tmp/cvs-serv6306/vm Modified Files: debug.c execute.c Log Message: Completed the ADD opcode, the println() function will now work. Index: debug.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/debug.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** debug.c 6 Aug 2003 19:06:47 -0000 1.12 --- debug.c 8 Aug 2003 11:38:20 -0000 1.13 *************** *** 10,17 **** "NOP", "PUSH", "SET", "ADD", "SUB", "MUL", "DIV", "MOD", ! "NEG", "NOT", "EQ", "JMP", ! "JMPF", "JMPT", "JMPR", "RET", ! "BUILTIN", "ARG", "POP", "VAR", ! "PUSHSCOPE", "POPSCOPE", "EXIT" }; --- 10,17 ---- "NOP", "PUSH", "SET", "ADD", "SUB", "MUL", "DIV", "MOD", ! "NEG", "NOT", "EQ", "NEQ", ! "JMP", "JMPF", "JMPT", "JMPR", ! "RET", "BUILTIN", "ARG", "POP", ! "VAR", "PUSHSCOPE", "POPSCOPE", "EXIT" }; Index: execute.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/execute.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** execute.c 7 Aug 2003 17:09:57 -0000 1.16 --- execute.c 8 Aug 2003 11:38:20 -0000 1.17 *************** *** 11,14 **** --- 11,15 ---- void cupvm_NOT(CUPVM *); void cupvm_EQ(CUPVM *); + void cupvm_ADD(CUPVM *); void cupvm_SET(CUPVM *); void cupvm_ARG(CUPVM *, unsigned long); *************** *** 53,56 **** --- 54,60 ---- break; case CUPOP_ADD: + cupvm_ADD(vm); + vm->pc++; + break; case CUPOP_SUB: case CUPOP_MUL: *************** *** 471,473 **** --- 475,544 ---- if (!cupvm_value_push(vm, ret)) cupvm_tb(vm, "cupvm_EQ()", "failed to push value"); + } + + void cupvm_ADD(CUPVM *vm) + { + CUPVALUE *v1, *v2, *ret; + + v2 = cupvm_value_pop(vm); + if (!v2) + { + cupvm_tb(vm, "cupvm_EQ()", "failed to pop value 2"); + return; + } + v2->references--; + v1 = cupvm_value_pop(vm); + if (!v1) + { + cupvm_tb(vm, "cupvm_EQ()", "failed to pop value 1"); + if (!v2->references) + cupvm_value_free(v2); + return; + } + v1->references--; + + if (v1->type != v2->type) + ret = NULL; + else + { + switch (v1->type) + { + case CUPTYPE_STRING: + ret = cupvm_value_new(); + ret->references = 1; + ret->type = CUPTYPE_STRING; + ret->data.val_string = dstrdup(v1->data.val_string, TYPE_CUPVM); + ret->data.val_string = drealloc(ret->data.val_string, + strlen(v1->data.val_string) + strlen(v2->data.val_string) + 1); + strcat(ret->data.val_string, v2->data.val_string); + break; + case CUPTYPE_INTEGER: + ret = cupvm_value_new(); + ret->references = 1; + ret->type = CUPTYPE_INTEGER; + ret->data.val_integer = v1->data.val_integer + v2->data.val_integer; + break; + case CUPTYPE_FLOAT: + ret = cupvm_value_new(); + ret->references = 1; + ret->type = CUPTYPE_FLOAT; + ret->data.val_float = v1->data.val_float + v2->data.val_float; + break; + default: + ret = NULL; + break; + } + } + + if (!v1->references) + cupvm_value_free(v1); + if (!v2->references) + cupvm_value_free(v2); + if (ret) + { + if (!cupvm_value_push(vm, ret)) + cupvm_tb(vm, "cupvm_ADD()", "failed to push value"); + } + else + cupvm_tb(vm, "cupvm_ADD()", "unable to add types"); } |
From: Keith J. <bu...@us...> - 2003-08-07 17:10:00
|
Update of /cvsroot/cup-language/cup/src/vm In directory sc8-pr-cvs1:/tmp/cvs-serv24091/cup/src/vm Modified Files: execute.c values.c vm.h Log Message: Added != (NEQ) and == (EQ). Also finished NOT opcode. Index: execute.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/execute.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** execute.c 7 Aug 2003 14:09:40 -0000 1.15 --- execute.c 7 Aug 2003 17:09:57 -0000 1.16 *************** *** 9,12 **** --- 9,14 ---- void cupvm_PUSH(CUPVM *, unsigned long); void cupvm_POP(CUPVM *); + void cupvm_NOT(CUPVM *); + void cupvm_EQ(CUPVM *); void cupvm_SET(CUPVM *); void cupvm_ARG(CUPVM *, unsigned long); *************** *** 59,72 **** break; case CUPOP_NEG: case CUPOP_NOT: case CUPOP_EQ: vm->pc++; break; case CUPOP_JMP: - case CUPOP_JMPF: - case CUPOP_JMPT: memcpy(&(vm->pc), &(vm->codeptr[vm->pc + 1]), sizeof(unsigned long int)); break; case CUPOP_BUILTIN: memcpy(&ul, &(vm->codeptr[vm->pc + 1]), sizeof(unsigned long)); --- 61,105 ---- break; case CUPOP_NEG: + vm->pc++; + break; case CUPOP_NOT: + cupvm_NOT(vm); + if (vm->traceback) + return; + vm->pc++; + break; case CUPOP_EQ: + cupvm_EQ(vm); + if (vm->traceback) + return; + vm->pc++; + break; + case CUPOP_NEQ: + cupvm_EQ(vm); + if (vm->traceback) + return; + cupvm_NOT(vm); + if (vm->traceback) + return; vm->pc++; break; case CUPOP_JMP: memcpy(&(vm->pc), &(vm->codeptr[vm->pc + 1]), sizeof(unsigned long int)); break; + case CUPOP_JMPF: + if (!cupvm_stacktrue(vm)) + memcpy(&(vm->pc), &(vm->codeptr[vm->pc + 1]), + sizeof(unsigned long int)); + else + vm->pc = vm->pc + sizeof(unsigned long) + 1; + break; + case CUPOP_JMPT: + if (cupvm_stacktrue(vm)) + memcpy(&(vm->pc), &(vm->codeptr[vm->pc + 1]), + sizeof(unsigned long int)); + else + vm->pc = vm->pc + sizeof(unsigned long) + 1; + break; case CUPOP_BUILTIN: memcpy(&ul, &(vm->codeptr[vm->pc + 1]), sizeof(unsigned long)); *************** *** 305,307 **** --- 338,473 ---- if (!v->references) cupvm_value_free(v); + } + + void cupvm_NOT(CUPVM *vm) + { + CUPVALUE *v, *ret; + + v = cupvm_value_pop(vm); + if (!v) + { + cupvm_tb(vm, "cupvm_NOT()", "empty stack"); + return; + } + v->references--; + + switch (v->type) + { + case CUPTYPE_INTEGER: + if (v->data.val_integer) + { + ret = cupvm_value_new(); + ret->type = CUPTYPE_INTEGER; + ret->data.val_integer = 0; + } + else + { + ret = cupvm_value_new(); + ret->type = CUPTYPE_INTEGER; + ret->data.val_integer = 1; + } + break; + case CUPTYPE_STRING: + if (v->data.val_string && v->data.val_string[0]) + { + ret = cupvm_value_new(); + ret->type = CUPTYPE_STRING; + ret->data.val_string = dstrdup("", TYPE_CUPVM); + } + else + { + ret = cupvm_value_new(); + ret->type = CUPTYPE_STRING; + ret->data.val_string = dstrdup("true", TYPE_CUPVM); + } + break; + case CUPTYPE_FILE: + cupvm_tb(vm, "cupvm_NOT", "cannot NOT a file pointer"); + if (!v->references) + cupvm_value_free(v); + return; + case CUPTYPE_FLOAT: + if (v->data.val_float) + { + ret = cupvm_value_new(); + ret->type = CUPTYPE_FLOAT; + ret->data.val_float = 0; + } + else + { + ret = cupvm_value_new(); + ret->type = CUPTYPE_FLOAT; + ret->data.val_float = 1; + } + break; + default: + cupvm_tb(vm, "cupvm_NOT", "unknown data type"); + if (!v->references) + cupvm_value_free(v); + return; + } + + if (!v->references) + cupvm_value_free(v); + ret->references++; + if (!cupvm_value_push(vm, ret)) + cupvm_tb(vm, "cupvm_NOT()", "failed to push value"); + } + + void cupvm_EQ(CUPVM *vm) + { + CUPVALUE *v1, *v2, *ret; + + v1 = cupvm_value_pop(vm); + if (!v1) + { + cupvm_tb(vm, "cupvm_EQ()", "failed to pop value 1"); + return; + } + v1->references--; + v2 = cupvm_value_pop(vm); + if (!v2) + { + cupvm_tb(vm, "cupvm_EQ()", "failed to pop value 2"); + if (!v1->references) + cupvm_value_free(v1); + return; + } + v2->references--; + + ret = cupvm_value_new(); + ret->type = CUPTYPE_INTEGER; + + ret->data.val_integer = 1; + if (v1->type != v2->type) + ret->data.val_integer = 0; + else + { + switch (v1->type) + { + case CUPTYPE_INTEGER: + if (v1->data.val_integer != v2->data.val_integer) + ret->data.val_integer = 0; + break; + case CUPTYPE_FLOAT: + if (v1->data.val_float != v2->data.val_float) + ret->data.val_integer = 0; + break; + case CUPTYPE_FILE: + if (v1->data.val_file != v2->data.val_file) + ret->data.val_integer = 0; + break; + case CUPTYPE_STRING: + if (strcmp(v1->data.val_string, v2->data.val_string) != 0) + ret->data.val_integer = 0; + } + } + + if (!v1->references) + cupvm_value_free(v1); + if (!v2->references) + cupvm_value_free(v2); + ret->references++; + if (!cupvm_value_push(vm, ret)) + cupvm_tb(vm, "cupvm_EQ()", "failed to push value"); } Index: values.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/values.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** values.c 23 Aug 2002 15:22:40 -0000 1.9 --- values.c 7 Aug 2003 17:09:57 -0000 1.10 *************** *** 49,50 **** --- 49,82 ---- return ret; } + + bool cupvm_stacktrue(CUPVM *vm) + { + CUPVALUE *v; + + if (!vm->stack) + return FALSE; + + v = (CUPVALUE *) list_item_from_back(vm->stack, 0); + if (!v) + return FALSE; + + switch (v->type) + { + case CUPTYPE_INTEGER: + if (v->data.val_integer) + return TRUE; + return FALSE; + case CUPTYPE_STRING: + if (v->data.val_string && v->data.val_string[0]) + return TRUE; + return FALSE; + case CUPTYPE_FILE: + return TRUE; + case CUPTYPE_FLOAT: + if (v->data.val_float) + return TRUE; + return FALSE; + default: + return FALSE; + } + } Index: vm.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** vm.h 7 Aug 2003 14:09:40 -0000 1.9 --- vm.h 7 Aug 2003 17:09:57 -0000 1.10 *************** *** 25,28 **** --- 25,29 ---- bool cupvm_value_push(CUPVM *, CUPVALUE *); CUPVALUE *cupvm_value_pop(CUPVM *); + bool cupvm_stacktrue(CUPVM *vm); CUPSCOPE *cupvm_scope_new(void); void cupvm_scope_free(CUPSCOPE *); |
From: Keith J. <bu...@us...> - 2003-08-07 17:10:00
|
Update of /cvsroot/cup-language/cup/src In directory sc8-pr-cvs1:/tmp/cvs-serv24091/cup/src Modified Files: cup.c cup.h.in cupvm.c Log Message: Added != (NEQ) and == (EQ). Also finished NOT opcode. Index: cup.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/cup.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** cup.c 7 Aug 2003 14:09:40 -0000 1.28 --- cup.c 7 Aug 2003 17:09:57 -0000 1.29 *************** *** 480,483 **** --- 480,488 ---- ret = cup_new_value(CUPTYPE_STRING, buf); } + else if (v1->type == CUPTYPE_FLOAT) + { + sprintf(buf, "%f", (float) v1->data.val_float); + ret = cup_new_value(CUPTYPE_STRING, buf); + } else if (v1->type == CUPTYPE_STRING) { *************** *** 487,492 **** else { ! sprintf(buf, "Not Implemented"); ! ret = cup_new_value(CUPTYPE_STRING, buf); } --- 492,499 ---- else { ! cupvm_tb(vm, "tostring() builtin", "data type not implemented"); ! if (!v1->references) ! cupvm_value_free(v1); ! return; } Index: cup.h.in =================================================================== RCS file: /cvsroot/cup-language/cup/src/cup.h.in,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** cup.h.in 7 Aug 2003 14:09:40 -0000 1.16 --- cup.h.in 7 Aug 2003 17:09:57 -0000 1.17 *************** *** 184,187 **** --- 184,188 ---- CUPOP_NOT, // SP = ! POP(SP) CUPOP_EQ, // SP = POP(SP) == POP(SP) + CUPOP_NEQ, // SP = POP(SP) != POP(SP) CUPOP_JMP, // PC = ARG Index: cupvm.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/cupvm.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** cupvm.c 7 Aug 2003 14:09:40 -0000 1.7 --- cupvm.c 7 Aug 2003 17:09:57 -0000 1.8 *************** *** 269,272 **** --- 269,277 ---- ret = cup_new_value(CUPTYPE_STRING, buf); } + else if (v1->type == CUPTYPE_FLOAT) + { + sprintf(buf, "%f", (float) v1->data.val_float); + ret = cup_new_value(CUPTYPE_STRING, buf); + } else if (v1->type == CUPTYPE_STRING) { *************** *** 276,281 **** else { ! sprintf(buf, "Not Implemented"); ! ret = cup_new_value(CUPTYPE_STRING, buf); } --- 281,288 ---- else { ! cupvm_tb(vm, "tostring() builtin", "data type not implemented"); ! if (!v1->references) ! cupvm_value_free(v1); ! return; } |
From: Keith J. <bu...@us...> - 2003-08-07 17:10:00
|
Update of /cvsroot/cup-language/cup/src/compiler In directory sc8-pr-cvs1:/tmp/cvs-serv24091/cup/src/compiler Modified Files: binary.c compiler.h parser.y Log Message: Added != (NEQ) and == (EQ). Also finished NOT opcode. Index: binary.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/binary.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** binary.c 6 Aug 2003 19:06:47 -0000 1.17 --- binary.c 7 Aug 2003 17:09:57 -0000 1.18 *************** *** 258,261 **** --- 258,285 ---- cupc_code_write(comp, CUPOP_SET); break; + case CUPCOP_EQ: + // Node 1 + // Node 2 + // EQ + cupc_bin_build(comp, node->one, 0, 0, 0); + if (comp->traceback) + return; + cupc_bin_build(comp, node->two, 0, 0, 0); + if (comp->traceback) + return; + cupc_code_write(comp, CUPOP_EQ); + break; + case CUPCOP_NEQ: + // Node 1 + // Node 2 + // EQ + cupc_bin_build(comp, node->one, 0, 0, 0); + if (comp->traceback) + return; + cupc_bin_build(comp, node->two, 0, 0, 0); + if (comp->traceback) + return; + cupc_code_write(comp, CUPOP_NEQ); + break; case CUPCOP_ADD: // Node 1 Index: compiler.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/compiler.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** compiler.h 22 Aug 2002 18:57:25 -0000 1.12 --- compiler.h 7 Aug 2003 17:09:57 -0000 1.13 *************** *** 65,68 **** --- 65,71 ---- CUPCOP_OR, + CUPCOP_EQ, + CUPCOP_NEQ, + CUPCOP_BLOCK, CUPCOP_WHILE, Index: parser.y =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/parser.y,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** parser.y 23 Aug 2002 19:01:34 -0000 1.14 --- parser.y 7 Aug 2003 17:09:57 -0000 1.15 *************** *** 64,67 **** --- 64,68 ---- %left TOKEN_OR %left TOKEN_AND + %left TOKEN_EQ TOKEN_NEQ %left '%' %left '-' '+' *************** *** 252,255 **** --- 253,260 ---- | '-' expr { $$ = cupc_node_new(CUPCOP_NEG, $2, NULL, NULL, NULL); } + | expr TOKEN_EQ expr + { $$ = cupc_node_new(CUPCOP_EQ, $1, $3, NULL, NULL); } + | expr TOKEN_NEQ expr + { $$ = cupc_node_new(CUPCOP_NEQ, $1, $3, NULL, NULL); } ; |
From: Keith J. <bu...@us...> - 2003-08-07 17:10:00
|
Update of /cvsroot/cup-language/cup/doc In directory sc8-pr-cvs1:/tmp/cvs-serv24091/cup/doc Modified Files: TODO Log Message: Added != (NEQ) and == (EQ). Also finished NOT opcode. Index: TODO =================================================================== RCS file: /cvsroot/cup-language/cup/doc/TODO,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** TODO 23 Aug 2002 20:10:50 -0000 1.4 --- TODO 7 Aug 2003 17:09:56 -0000 1.5 *************** *** 17,21 **** * Indexing l[1] == 1, d["Bob"] == 28752 * Ranging l[1:2] == [1, "doh"], l[:2] == [1, "doh"], l[3:] == [1, 4.5] ! * > < >= <= == != ++ -- * Compile debug info * 'compress' data section (no duplicates): --- 17,21 ---- * Indexing l[1] == 1, d["Bob"] == 28752 * Ranging l[1:2] == [1, "doh"], l[:2] == [1, "doh"], l[3:] == [1, 4.5] ! * > < >= <= ++ -- * Compile debug info * 'compress' data section (no duplicates): *************** *** 47,56 **** * Existing opcodes to complete: ! JMPF/JMPT SET ! ADD/SUB/MUL/DIV/MOD/NEG/NOT EQ * Implement new opcodes for new language functionality (ranges, lists, etc) - * API adherance - 'Built in' functions - 'Built in' variables * parse and use debug info --- 47,52 ---- * Existing opcodes to complete: ! ADD/SUB/MUL/DIV/MOD/NEG * Implement new opcodes for new language functionality (ranges, lists, etc) * parse and use debug info *************** *** 61,63 **** * getopts library, handle long options * clean up windows install (add documentation to start menu, readme, ! instructions, etc) \ No newline at end of file --- 57,59 ---- * getopts library, handle long options * clean up windows install (add documentation to start menu, readme, ! instructions, etc) |
From: Keith J. <bu...@us...> - 2003-08-07 14:46:54
|
Update of /cvsroot/cup-language/cup/src In directory sc8-pr-cvs1:/tmp/cvs-serv18096 Modified Files: cup.c cup.h.in cupvm.c Log Message: Builtin functions are now mostly working. Implemented is enough to make the stdio.cup 'print' function work. 'println' will also work, as far as builtin functions are concerned, but the ADD VM OP code is not implemented to add the '\n' on the end, and to add 1 to the length() return value. Index: cup.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/cup.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -r1.27 -r1.28 *** cup.c 6 Aug 2003 19:06:47 -0000 1.27 --- cup.c 7 Aug 2003 14:09:40 -0000 1.28 *************** *** 272,280 **** vm->vm_debug = opt_idebug; - /* cup_set_globalvar(vm, cup_new_value(CUPTYPE_FILE, stdin), "stdin"); cup_set_globalvar(vm, cup_new_value(CUPTYPE_FILE, stdout), "stdout"); cup_set_globalvar(vm, cup_new_value(CUPTYPE_FILE, stderr), "stderr"); - */ cup_execute(vm); --- 272,278 ---- *************** *** 441,448 **** void cup_callback_builtin(CUPVM *vm, const char *fname) { if (strcmp(fname, "fwrite") == 0) { ! cupvm_value_pop(vm)->references--; ! cupvm_value_pop(vm)->references--; } } --- 439,553 ---- void cup_callback_builtin(CUPVM *vm, const char *fname) { + CUPVALUE *v1, *v2, *v3; + + + if (strcmp(fname, "length") == 0) + { + CUPVALUE *ret; + + v1 = cupvm_value_pop(vm); + v1->references--; + + if (v1->type == CUPTYPE_STRING) + { + long int len = strlen(v1->data.val_string); + ret = cup_new_value(CUPTYPE_INTEGER, &len); + } + else + { + cupvm_tb(vm, "length() builtin", "length on this type not implemented"); + if (!v1->references) + cupvm_value_free(v1); + return; + } + + if (!v1->references) + cupvm_value_free(v1); + cupvm_value_push(vm, ret); + return; + } + if (strcmp(fname, "tostring") == 0) + { + CUPVALUE *ret; + char buf[32]; + + v1 = cupvm_value_pop(vm); + v1->references--; + + if (v1->type == CUPTYPE_INTEGER) + { + sprintf(buf, "%ld", v1->data.val_integer); + ret = cup_new_value(CUPTYPE_STRING, buf); + } + else if (v1->type == CUPTYPE_STRING) + { + ret = v1; + v1->references++; + } + else + { + sprintf(buf, "Not Implemented"); + ret = cup_new_value(CUPTYPE_STRING, buf); + } + + if (!v1->references) + cupvm_value_free(v1); + cupvm_value_push(vm, ret); + return; + } if (strcmp(fname, "fwrite") == 0) { ! long ret; ! ! v3 = cupvm_value_pop(vm); ! v3->references--; ! v2 = cupvm_value_pop(vm); ! v2->references--; ! v1 = cupvm_value_pop(vm); ! v1->references--; ! ! if (v1->type != CUPTYPE_FILE) ! { ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_tb(vm, "fwrite() builtin", "arg1 is not a file"); ! return; ! } ! if (v2->type != CUPTYPE_STRING) ! { ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_tb(vm, "fwrite() builtin", "arg2 is not a string"); ! return; ! } ! if (v3->type != CUPTYPE_INTEGER) ! { ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_tb(vm, "fwrite() builtin", "arg3 is not an integer"); ! return; ! } ! ! ret = fwrite(v2->data.val_string, 1, v3->data.val_integer, v1->data.val_file); ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_value_push(vm, cup_new_value(CUPTYPE_INTEGER, &ret)); ! return; } } Index: cup.h.in =================================================================== RCS file: /cvsroot/cup-language/cup/src/cup.h.in,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** cup.h.in 6 Aug 2003 19:06:47 -0000 1.15 --- cup.h.in 7 Aug 2003 14:09:40 -0000 1.16 *************** *** 144,147 **** --- 144,148 ---- long double val_float; char *val_string; + FILE *val_file; } data; *************** *** 150,153 **** --- 151,163 ---- enum { + CUPTYPE_NONE = 0, + CUPTYPE_FLOAT, + CUPTYPE_INTEGER, + CUPTYPE_STRING, + CUPTYPE_FILE + }; + + enum + { CUPDATA_DONE = 0, CUPDATA_FLOAT, *************** *** 205,211 **** void cup_free_vm(CUPVM *); void cup_callback_builtin(CUPVM *, const char *); - /* CUPVALUE *cup_new_value(int, void *); ! void cup_set_globalvar(CUPVM *, CUPVALUE *, const char *); CUPVALUE *cup_get_globalvar(CUPVM *, const char *); */ --- 215,221 ---- void cup_free_vm(CUPVM *); void cup_callback_builtin(CUPVM *, const char *); CUPVALUE *cup_new_value(int, void *); ! bool cup_set_globalvar(CUPVM *, CUPVALUE *, const char *); ! /* CUPVALUE *cup_get_globalvar(CUPVM *, const char *); */ Index: cupvm.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/cupvm.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** cupvm.c 6 Aug 2003 19:06:47 -0000 1.6 --- cupvm.c 7 Aug 2003 14:09:40 -0000 1.7 *************** *** 159,167 **** vm->vm_debug = opt_idebug; - /* cup_set_globalvar(vm, cup_new_value(CUPTYPE_FILE, stdin), "stdin"); cup_set_globalvar(vm, cup_new_value(CUPTYPE_FILE, stdout), "stdout"); cup_set_globalvar(vm, cup_new_value(CUPTYPE_FILE, stderr), "stderr"); - */ cup_execute(vm); --- 159,165 ---- *************** *** 230,237 **** void cup_callback_builtin(CUPVM *vm, const char *fname) { if (strcmp(fname, "fwrite") == 0) { ! cupvm_value_pop(vm)->references--; ! cupvm_value_pop(vm)->references--; } } --- 228,342 ---- void cup_callback_builtin(CUPVM *vm, const char *fname) { + CUPVALUE *v1, *v2, *v3; + + + if (strcmp(fname, "length") == 0) + { + CUPVALUE *ret; + + v1 = cupvm_value_pop(vm); + v1->references--; + + if (v1->type == CUPTYPE_STRING) + { + long int len = strlen(v1->data.val_string); + ret = cup_new_value(CUPTYPE_INTEGER, &len); + } + else + { + cupvm_tb(vm, "length() builtin", "length on this type not implemented"); + if (!v1->references) + cupvm_value_free(v1); + return; + } + + if (!v1->references) + cupvm_value_free(v1); + cupvm_value_push(vm, ret); + return; + } + if (strcmp(fname, "tostring") == 0) + { + CUPVALUE *ret; + char buf[32]; + + v1 = cupvm_value_pop(vm); + v1->references--; + + if (v1->type == CUPTYPE_INTEGER) + { + sprintf(buf, "%ld", v1->data.val_integer); + ret = cup_new_value(CUPTYPE_STRING, buf); + } + else if (v1->type == CUPTYPE_STRING) + { + ret = v1; + v1->references++; + } + else + { + sprintf(buf, "Not Implemented"); + ret = cup_new_value(CUPTYPE_STRING, buf); + } + + if (!v1->references) + cupvm_value_free(v1); + cupvm_value_push(vm, ret); + return; + } if (strcmp(fname, "fwrite") == 0) { ! long ret; ! ! v3 = cupvm_value_pop(vm); ! v3->references--; ! v2 = cupvm_value_pop(vm); ! v2->references--; ! v1 = cupvm_value_pop(vm); ! v1->references--; ! ! if (v1->type != CUPTYPE_FILE) ! { ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_tb(vm, "fwrite() builtin", "arg1 is not a file"); ! return; ! } ! if (v2->type != CUPTYPE_STRING) ! { ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_tb(vm, "fwrite() builtin", "arg2 is not a string"); ! return; ! } ! if (v3->type != CUPTYPE_INTEGER) ! { ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_tb(vm, "fwrite() builtin", "arg3 is not an integer"); ! return; ! } ! ! ret = fwrite(v2->data.val_string, 1, v3->data.val_integer, v1->data.val_file); ! if (!v1->references) ! cupvm_value_free(v1); ! if (!v2->references) ! cupvm_value_free(v2); ! if (!v3->references) ! cupvm_value_free(v3); ! cupvm_value_push(vm, cup_new_value(CUPTYPE_INTEGER, &ret)); ! return; } } |
From: Keith J. <bu...@us...> - 2003-08-07 14:09:43
|
Update of /cvsroot/cup-language/cup/src/vm In directory sc8-pr-cvs1:/tmp/cvs-serv18096/vm Modified Files: execute.c scopes.c vm.c vm.h Log Message: Builtin functions are now mostly working. Implemented is enough to make the stdio.cup 'print' function work. 'println' will also work, as far as builtin functions are concerned, but the ADD VM OP code is not implemented to add the '\n' on the end, and to add 1 to the length() return value. Index: execute.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/execute.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** execute.c 6 Aug 2003 19:06:47 -0000 1.14 --- execute.c 7 Aug 2003 14:09:40 -0000 1.15 *************** *** 264,280 **** void cupvm_SET(CUPVM *vm) { ! // TEMPORARY. For now, just pop the last value. ! // In real code, this would pop it, then set the current stack value ! // to this popped value ! CUPVALUE *val; ! val = cupvm_value_pop(vm); ! val->references--; ! if (!val) ! cupvm_tb(vm, "cupvm_POP()", "failed to pop data"); ! else { ! if (!val->references) ! cupvm_value_free(val); } } --- 264,307 ---- void cupvm_SET(CUPVM *vm) { ! CUPVALUE *v, *set; ! v = cupvm_value_pop(vm); ! if (!v) { ! cupvm_tb(vm, "cupvm_SET()", "failed to pop data"); ! return; } + v->references--; + + set = list_item_from_back(vm->stack, 0); + switch (set->type) + { + case CUPTYPE_STRING: + dfree(set->data.val_string); + switch (v->type) + { + case CUPTYPE_STRING: + set->data.val_string = dstrdup(v->data.val_string, TYPE_CUPVM); + break; + default: + set->data = v->data; + break; + } + break; + default: + switch (v->type) + { + case CUPTYPE_STRING: + set->data.val_string = dstrdup(v->data.val_string, TYPE_CUPVM); + break; + default: + set->data = v->data; + break; + } + break; + } + set->type = v->type; + + if (!v->references) + cupvm_value_free(v); } Index: scopes.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/scopes.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** scopes.c 6 Aug 2003 19:06:48 -0000 1.3 --- scopes.c 7 Aug 2003 14:09:40 -0000 1.4 *************** *** 7,11 **** "@(#) $Id$"; ! bool cupvm_scope_declvar(CUPVM *vm, CUPVALUE *var, char *name) { CUPSCOPE *scope; --- 7,11 ---- "@(#) $Id$"; ! bool cupvm_scope_declvar(CUPVM *vm, CUPVALUE *var, const char *name) { CUPSCOPE *scope; *************** *** 78,83 **** if (!scopevar->val->references) cupvm_value_free(scopevar->val); - else - printf("References: %s/%d\n", scopevar->name, scopevar->val->references); dfree(scopevar->name); dfree(scopevar); --- 78,81 ---- Index: vm.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** vm.c 6 Aug 2003 19:06:48 -0000 1.19 --- vm.c 7 Aug 2003 14:09:40 -0000 1.20 *************** *** 27,30 **** --- 27,32 ---- vm->binlen = 0; vm->traceback = NULL; + vm->scopes = NULL; + cupvm_PUSHSCOPE(vm); return vm; } *************** *** 32,35 **** --- 34,43 ---- void cup_free_vm(CUPVM *vm) { + if (vm->scopes) + { + while (list_length(vm->scopes)) + cupvm_scope_free(list_item_pop_back(vm->scopes)); + list_free(vm->scopes); + } if (vm->traceback) dfree(vm->traceback); *************** *** 53,73 **** vm->retval = NULL; vm->stack = NULL; - vm->scopes = NULL; ! cupvm_PUSHSCOPE(vm); ! if (!vm->traceback) ! { ! cupvm_execute(vm); ! if (!vm->traceback) ! cupvm_POPSCOPE(vm); ! } ! ! if (vm->scopes) ! { ! while (list_length(vm->scopes)) ! cupvm_scope_free(list_item_pop_back(vm->scopes)); ! list_free(vm->scopes); ! } if (vm->stack) --- 61,69 ---- vm->retval = NULL; vm->stack = NULL; ! cupvm_execute(vm); + while (list_length(vm->scopes) > 1) + cupvm_scope_free(list_item_pop_back(vm->scopes)); if (vm->stack) *************** *** 176,178 **** --- 172,205 ---- vm->traceback = drealloc(vm->traceback, strlen(vm->traceback) + len); strcat(vm->traceback, buf); + } + + CUPVALUE *cup_new_value(int type, void *val) + { + CUPVALUE *ret; + + ret = dmalloc(sizeof(CUPVALUE), TYPE_CUPVM); + ret->references = 1; + switch (type) + { + case CUPTYPE_FILE: + ret->type = CUPTYPE_FILE; + ret->data.val_file = (FILE *) val; + return ret; + case CUPTYPE_INTEGER: + ret->type = CUPTYPE_INTEGER; + ret->data.val_integer = *((long int *) val); + return ret; + case CUPTYPE_STRING: + ret->type = CUPTYPE_STRING; + ret->data.val_string = dstrdup(val, TYPE_CUPVM); + return ret; + } + + dfree(ret); + return NULL; + } + + bool cup_set_globalvar(CUPVM *vm, CUPVALUE *val, const char *name) + { + return cupvm_scope_declvar(vm, val, name); } Index: vm.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** vm.h 23 Aug 2002 15:22:40 -0000 1.8 --- vm.h 7 Aug 2003 14:09:40 -0000 1.9 *************** *** 3,14 **** #define VM_H_ID "@(#) $Id$" - enum - { - CUPTYPE_NONE = 0, - CUPTYPE_FLOAT, - CUPTYPE_INTEGER, - CUPTYPE_STRING - }; - typedef struct cupscope CUPSCOPE; struct cupscope --- 3,6 ---- *************** *** 38,42 **** CUPSCOPE *cupvm_scope_pop(CUPVM *); CUPVALUE *cupvm_scope_findvar(CUPVM *, const char *); ! bool cupvm_scope_declvar(CUPVM *, CUPVALUE *, char *); void cupvm_PUSHSCOPE(CUPVM *); void cupvm_POPSCOPE(CUPVM *); --- 30,34 ---- CUPSCOPE *cupvm_scope_pop(CUPVM *); CUPVALUE *cupvm_scope_findvar(CUPVM *, const char *); ! bool cupvm_scope_declvar(CUPVM *, CUPVALUE *, const char *); void cupvm_PUSHSCOPE(CUPVM *); void cupvm_POPSCOPE(CUPVM *); |
From: Keith J. <bu...@us...> - 2003-08-06 20:34:06
|
Update of /cvsroot/cup-language/cup/doc In directory sc8-pr-cvs1:/tmp/cvs-serv6532/cup/doc Modified Files: CupAPI-Proposed.txt Log Message: documentation updates Index: CupAPI-Proposed.txt =================================================================== RCS file: /cvsroot/cup-language/cup/doc/CupAPI-Proposed.txt,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** CupAPI-Proposed.txt 23 Aug 2002 18:48:42 -0000 1.12 --- CupAPI-Proposed.txt 6 Aug 2003 19:48:56 -0000 1.13 *************** *** 108,111 **** --- 108,121 ---- compile is complete, it may all be freed. + long cup_callback_isbuiltin(const char *funcname); + + During a Cup program's compilation, if a function call is made and no + function is in the source that has a matching name, this function is + called. If -1 is returned, the cup compiler will throw an error that + the function is not defined. If a number is returned, the proper OP codes + to call a builtin function with that number of arguments are created in + the binary. When the binary is run, a function named 'funcname' is + expected to exist. + *************** *** 115,131 **** Overview: - The Cup Virtual Machine API is designed to run Cup programs according to - the following general flow: - - Allocate a Virtual Machine - - Set the Virtual Machine up for running a Cup program <----+ - Maybe set variables/functions in the global scope | - Execute the binary | - Maybe get various values from the global scope | - Maybe do it again -----------------------------------------+ - - Free the Virtual Machine - Many different programs, or even the same program can be run again and again in the same Virtual Machine. Many different Virtual Machines can be --- 125,128 ---- *************** *** 229,241 **** replaced via cup_set_globalvar(). - bool cup_set_globalfunc(CUPVM *vm, const char *name, CUP_BUILTIN_FUNC *); - - Cup has a method by which you can define additional builtin functions at - runtime. The three arguments to this function are the VM to add the - function to, the name of the function, and a pointer to the function. - Various typedefs and macros have been declared to make this task easier. - For further information on this subject, and more detailed descriptions - of adding builtin functions, see 'Adding Builtin Functions'. - void cup_execute(CUPVM *vm); --- 226,229 ---- *************** *** 249,255 **** CallBack Functions: ! The VM has no required callback functions, unless the program uses ! cup_add_globalfunc() to create a new builtin function. If that is the ! case, the programmer must provide such callback functions. Example Code: --- 237,242 ---- CallBack Functions: ! void cup_callback_builtin(CUPVM *vm, const char *funcname); ! Example Code: |
From: Keith J. <bu...@us...> - 2002-08-23 20:10:54
|
Update of /cvsroot/cup-language/cup/doc In directory usw-pr-cvs1:/tmp/cvs-serv28062 Modified Files: TODO Log Message: updated Index: TODO =================================================================== RCS file: /cvsroot/cup-language/cup/doc/TODO,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** TODO 23 Aug 2002 19:02:57 -0000 1.3 --- TODO 23 Aug 2002 20:10:50 -0000 1.4 *************** *** 19,22 **** --- 19,43 ---- * > < >= <= == != ++ -- * Compile debug info + * 'compress' data section (no duplicates): + var x; + var k = 1; + x = 1; + k = 2; + + Data should be: + x + k + 1 + 2 + + NOT: + x + k + 1 + x + 1 + k + 2 + Virtual Machine |
From: Keith J. <bu...@us...> - 2002-08-23 19:03:02
|
Update of /cvsroot/cup-language/cup/doc In directory usw-pr-cvs1:/tmp/cvs-serv3428 Modified Files: TODO Log Message: Added debug info to TODO Index: TODO =================================================================== RCS file: /cvsroot/cup-language/cup/doc/TODO,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** TODO 23 Aug 2002 18:48:42 -0000 1.2 --- TODO 23 Aug 2002 19:02:57 -0000 1.3 *************** *** 18,21 **** --- 18,22 ---- * Ranging l[1:2] == [1, "doh"], l[:2] == [1, "doh"], l[3:] == [1, 4.5] * > < >= <= == != ++ -- + * Compile debug info Virtual Machine *************** *** 31,34 **** --- 32,36 ---- 'Built in' functions 'Built in' variables + * parse and use debug info |
From: Keith J. <bu...@us...> - 2002-08-23 19:01:38
|
Update of /cvsroot/cup-language/cup/src/compiler In directory usw-pr-cvs1:/tmp/cvs-serv2890/compiler Modified Files: parser.y Log Message: Won't crash if cup_callback_include returns NULL now :) Index: parser.y =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/parser.y,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** parser.y 22 Aug 2002 14:15:53 -0000 1.13 --- parser.y 23 Aug 2002 19:01:34 -0000 1.14 *************** *** 542,546 **** const char *oldsrc, *oldfname; unsigned long oldplace, oldline; ! bool ret; oldsrc = comp->source; --- 542,546 ---- const char *oldsrc, *oldfname; unsigned long oldplace, oldline; ! bool ret = TRUE; oldsrc = comp->source; *************** *** 550,561 **** comp->source = cup_callback_include(comp->data, filename); comp->filename = filename; comp->place = 0; comp->line = 1; ! if (yyparse(comp) != 1) ! ret = TRUE; ! else ! ret = FALSE; comp->source = oldsrc; --- 550,569 ---- comp->source = cup_callback_include(comp->data, filename); + if (!comp->source) + { + cupc_tb(comp, "cupc_include()", "include source not found"); + ret = FALSE; + } comp->filename = filename; comp->place = 0; comp->line = 1; ! if (ret) ! { ! if (yyparse(comp) != 1) ! ret = TRUE; ! else ! ret = FALSE; ! } comp->source = oldsrc; |
From: Keith J. <bu...@us...> - 2002-08-23 18:48:47
|
Update of /cvsroot/cup-language/cup/doc In directory usw-pr-cvs1:/tmp/cvs-serv31555 Modified Files: CupAPI-Proposed.txt TODO Log Message: Updated documentation Index: CupAPI-Proposed.txt =================================================================== RCS file: /cvsroot/cup-language/cup/doc/CupAPI-Proposed.txt,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** CupAPI-Proposed.txt 29 Apr 2002 19:26:20 -0000 1.11 --- CupAPI-Proposed.txt 23 Aug 2002 18:48:42 -0000 1.12 *************** *** 4,8 **** machine, and, in fact, are physically seperate libraries. If both the compiler and VM are needed, both libraries should not be linked, instead, ! libcup should be linked. --- 4,9 ---- machine, and, in fact, are physically seperate libraries. If both the compiler and VM are needed, both libraries should not be linked, instead, ! libcup should be linked, so that common libraries between compiler and ! virtual machine are not doubly-linked. *************** *** 21,30 **** Structures: typedef struct cupcompiled CUPCOMPILED; struct cupcompiled { ! char *binary; ! unsigned long int binlen; ! char *traceback; }; --- 22,38 ---- Structures: + // These structures may contain other values, but, are for internal Cup + // use only and subject to change. Do not rely on any members not defined + // here. + typedef struct cupcompiled CUPCOMPILED; struct cupcompiled { ! char *binary; // Resultant Binary Code ! unsigned long int binlen; // Length of Resultant Binary Code ! char *traceback; // If an error occurs, this character ! // buffer is a traceback of the error. ! // If there was no error, this is NULL. ! // Suitable for printing directly to a user. }; *************** *** 33,37 **** CUPCOMPILED *cup_compile(const char *program, const char *filename, ! void *data, bool debug); This function will compile the NULL terminated string 'program' into a --- 41,45 ---- CUPCOMPILED *cup_compile(const char *program, const char *filename, ! void *data, bool debug, bool idebug); This function will compile the NULL terminated string 'program' into a *************** *** 48,55 **** terminated string specifying the filename of the source. This is used for debugging, if a traceback occurs, it reports it happening in such ! and such file. It may not be NULL. Finally, if the debug argument is not ! true, then debugging information will not be compiled into the binary. ! If errors occur during runtime, the VM will be unable to describe where ! or what source caused it, instead only showing the error that happened. This function will always return a CUPCOMPILED structure, unless there --- 56,66 ---- terminated string specifying the filename of the source. This is used for debugging, if a traceback occurs, it reports it happening in such ! and such file. It may not be NULL. If the debug argument is false, then ! debugging information will not be compiled into the binary. If errors ! occur during runtime, the VM will be unable to describe where or what ! source caused it, instead only showing the error that happened. If the ! idebug variable is true, then internal compiler debugging info will be ! shown. This is of no use to most people, except those working on the cup ! compiler. This function will always return a CUPCOMPILED structure, unless there *************** *** 60,68 **** failed, 'binary' will be NULL, and traceback will contain a NULL-terminated string which is a description of the compilation error. ! The application is responsible for freeing the structure, and either the ! binary data, or the traceback. The application must copy the binary to ! it's own memory if it intends to keep a reference to it. The data ! returned by Cup API calls is not standard-allocated memory, and should ! only by copied or freed by the Cup API functions. During compilation, cup_callback_include() may be called, and that --- 71,80 ---- failed, 'binary' will be NULL, and traceback will contain a NULL-terminated string which is a description of the compilation error. ! The application is responsible for freeing the structure with ! cup_free_compiled(), which will also free the binary and/or traceback. ! The application must copy the binary to it's own memory if it intends to ! keep a reference to it. The data returned by Cup API calls is not ! standard-allocated memory, and should only by copied or freed by the Cup ! API functions. During compilation, cup_callback_include() may be called, and that *************** *** 71,75 **** void cup_free_compiled(CUPCOMPILED *compiled); ! This function frees the CUPCOMPILED data structure. Callback Functions: --- 83,89 ---- void cup_free_compiled(CUPCOMPILED *compiled); ! This function frees the CUPCOMPILED data structure, including the binary ! and/or traceback data. Those members are not to be freed by the ! programmer. Callback Functions: *************** *** 107,111 **** Set the Virtual Machine up for running a Cup program <----+ ! Maybe set variables in the global scope | Execute the binary | Maybe get various values from the global scope | --- 121,125 ---- Set the Virtual Machine up for running a Cup program <----+ ! Maybe set variables/functions in the global scope | Execute the binary | Maybe get various values from the global scope | *************** *** 133,142 **** bool vm_debug; // VM Debugger on bool debug; // Debugger on - bool implicit_vars; // Allow implicit variables - bool allow_fopen; // Allow fopen() builtin - bool allow_fwrite; // Allow fwrite() builtin - bool allow_call; // Allow call() builtin - bool allow_getenv; // Allow getenv() builtin - bool allow_chdir; // Allow chdir() builtin void *binary; // Holds pointer to binary --- 147,150 ---- *************** *** 182,185 **** --- 190,194 ---- CUPTYPE_LIST n/a CUPTYPE_DICT n/a + CUPTYPE_FILE FILE * When creating a dictionary or list, the 'val' argument is ignored, and *************** *** 210,214 **** memory, invalidating the original pointer. If the programmer needs access to a VM's variable, it can use the cup_get_globalvar() function. ! Once a value is passed to Cup in this mannar, Cup will manage it internally, and the programmer should not attempt to reference it again. --- 219,223 ---- memory, invalidating the original pointer. If the programmer needs access to a VM's variable, it can use the cup_get_globalvar() function. ! Once a value is passed to Cup in this manner, Cup will manage it internally, and the programmer should not attempt to reference it again. *************** *** 244,248 **** case, the programmer must provide such callback functions. ! Example Psuedocode: CUPVM *vm; --- 253,257 ---- case, the programmer must provide such callback functions. ! Example Code: CUPVM *vm; *************** *** 250,254 **** vm = cup_new_vm(); vm->max_instructions = 500; - vm->allow_fopen = FALSE; vm->binary = pre_compiled_binary_image; --- 259,262 ---- Index: TODO =================================================================== RCS file: /cvsroot/cup-language/cup/doc/TODO,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** TODO 30 Apr 2002 13:04:02 -0000 1.1 --- TODO 23 Aug 2002 18:48:42 -0000 1.2 *************** *** 6,14 **** * Write a tutorial * Some kind of doc for the compiler/vm internal code for wannabe Cup ! developers Compiler -------- * Lists decl l = [1, "doh", [1, 4.5]] * Dictionaries decl d = '[["Jason", 29752], ["Keith", 27503], ["Bob", 28752]] --- 6,16 ---- * Write a tutorial * Some kind of doc for the compiler/vm internal code for wannabe Cup ! developers (Pondering/Playing with doxygen) Compiler -------- + * Already 100% adheres to the API documentation + * Lists decl l = [1, "doh", [1, 4.5]] * Dictionaries decl d = '[["Jason", 29752], ["Keith", 27503], ["Bob", 28752]] *************** *** 16,65 **** * Ranging l[1:2] == [1, "doh"], l[:2] == [1, "doh"], l[3:] == [1, 4.5] * > < >= <= == != ++ -- - * Functions - - Compiler already parses nodes as follows - - Function Definition: - decl max(a1, a2) - { - ... - } - - max(1, 2); - - Nodes: - FUNCTION - Name: token (max) - Args: variable (a1) - variable (a2) - Code: ... parse tree - CALL - Name: token (max) - Args: int (1) - int (2) - POP - EXIT - - So, the compiler needs to take the FUNCTION tree, and compile it to the - end of the binary - The compiler needs to convert the CALL into a JMPRET to that part of the - binary - returns need to be compiled into RET which will jump back to the last - JMPRET. VM will track this - Compiling CALLs into simple JMPs will not work. When the function returns, - we don't know where to jump BACK to. A function could be called from - hundreds of different places in the code. This is why we need JMPRET and - RET opcodes. - If after parsing the entire code, there are CALLs which have no FUNCTION, - then it's a compile error - Exception being builtin functions, however, ignore builtin functions for - now. I want to think more about how to do them. I want them externalized - somehow. Need to think... Virtual Machine --------------- ! * Make it actually do useful stuff, just a shell for now. Making JMPF/JMPT ! actually do what they are supposed to might be a start. ! --- 18,40 ---- * Ranging l[1:2] == [1, "doh"], l[:2] == [1, "doh"], l[3:] == [1, 4.5] * > < >= <= == != ++ -- Virtual Machine --------------- ! * Fix to adhere to API documentation + * Existing opcodes to complete: + JMPF/JMPT SET + ADD/SUB/MUL/DIV/MOD/NEG/NOT EQ + * Implement new opcodes for new language functionality (ranges, lists, etc) + * API adherance + 'Built in' functions + 'Built in' variables + + + Miscellaneous + ------------- + + * getopts library, handle long options + * clean up windows install (add documentation to start menu, readme, + instructions, etc) \ No newline at end of file |
From: Keith J. <bu...@us...> - 2002-08-23 15:22:46
|
Update of /cvsroot/cup-language/cup/src/vm In directory usw-pr-cvs1:/tmp/cvs-serv29748/vm Modified Files: debug.c execute.c scopes.c values.c vm.c vm.h Log Message: Lot of work being done Index: debug.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/debug.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** debug.c 22 Aug 2002 18:57:25 -0000 1.10 --- debug.c 23 Aug 2002 15:22:40 -0000 1.11 *************** *** 183,187 **** pc++; while (vm->binary[pc] != '\0') ! printf("%c", vm->binary[pc++]); printf("\"\n"); break; --- 183,201 ---- pc++; while (vm->binary[pc] != '\0') ! { ! switch (vm->binary[pc]) ! { ! case '\\': ! printf("\\\\"); ! break; ! case '\n': ! printf("\\n"); ! break; ! default: ! printf("%c", vm->binary[pc]); ! break; ! } ! pc++; ! } printf("\"\n"); break; Index: execute.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/execute.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** execute.c 22 Aug 2002 18:57:25 -0000 1.12 --- execute.c 23 Aug 2002 15:22:40 -0000 1.13 *************** *** 10,13 **** --- 10,15 ---- void cupvm_POP(CUPVM *); void cupvm_SET(CUPVM *); + void cupvm_ARG(CUPVM *, unsigned long); + void cupvm_VAR(CUPVM *, unsigned long); void cupvm_execute(CUPVM *vm) *************** *** 34,41 **** break; case CUPOP_VAR: vm->pc = vm->pc + sizeof(unsigned long) + 1; break; case CUPOP_ARG: ! cupvm_POP(vm); // TEMPORARY vm->pc = vm->pc + sizeof(unsigned long) + 1; break; --- 36,50 ---- break; case CUPOP_VAR: + memcpy(&ul, &(vm->codeptr[vm->pc + 1]), sizeof(unsigned long)); + cupvm_VAR(vm, ul); + if (vm->traceback) + return; vm->pc = vm->pc + sizeof(unsigned long) + 1; break; case CUPOP_ARG: ! memcpy(&ul, &(vm->codeptr[vm->pc + 1]), sizeof(unsigned long)); ! cupvm_ARG(vm, ul); ! if (vm->traceback) ! return; vm->pc = vm->pc + sizeof(unsigned long) + 1; break; *************** *** 101,104 **** --- 110,156 ---- } + // increment references by 1, since we are creating a value + void cupvm_VAR(CUPVM *vm, unsigned long addr) + { + CUPVALUE *val; + + if (vm->dataptr[addr] != CUPDATA_VARIABLE) + { + cupvm_tb(vm, "cupvm_VAR()", "data pointed to is not a token"); + return; + } + + val = cupvm_value_new(); + val->type = CUPTYPE_INTEGER; + val->data.val_integer = 0; + val->references++; + + if (!cupvm_scope_declvar(vm, val, &(vm->dataptr[addr + 1]))) + cupvm_tb(vm, "cupvm_VAR()", "unable to declare argument (most likely duplicate names)"); + } + + // Since we pop from stack, and add to scope, our references count is + // unchanged. It's just ref'd in a diff place now + void cupvm_ARG(CUPVM *vm, unsigned long addr) + { + CUPVALUE *val; + + val = cupvm_value_pop(vm); + if (!val) + { + cupvm_tb(vm, "cupvm_ARG()", "unable to pop value"); + return; + } + + if (vm->dataptr[addr] != CUPDATA_VARIABLE) + { + cupvm_tb(vm, "cupvm_ARG()", "data pointed to is not a token"); + return; + } + + if (!cupvm_scope_declvar(vm, val, &(vm->dataptr[addr + 1]))) + cupvm_tb(vm, "cupvm_ARG()", "unable to declare argument (most likely duplicate names)"); + } + void cupvm_PUSHSCOPE(CUPVM *vm) { *************** *** 112,116 **** void cupvm_POPSCOPE(CUPVM *vm) { - CUPVALUE *val; CUPSCOPE *scope; --- 164,167 ---- *************** *** 122,135 **** } - if (scope->vars) - { - while ((val = (CUPVALUE *) list_item_pop_back(scope->vars))) - cupvm_value_free(val); - list_free(scope->vars); - } - cupvm_scope_free(scope); } void cupvm_PUSH(CUPVM *vm, unsigned long addr) { --- 173,180 ---- } cupvm_scope_free(scope); } + // increment references, we are adding to the stack void cupvm_PUSH(CUPVM *vm, unsigned long addr) { *************** *** 149,155 **** memcpy(&(val->data.val_float), &(vm->dataptr[addr + 1]), sizeof(long double)); ! if (!cupvm_value_push(vm, val)) ! cupvm_tb(vm, "cupvm_PUSH()", "failed to push value"); ! return; case CUPDATA_INTEGER: val = cupvm_value_new(); --- 194,198 ---- memcpy(&(val->data.val_float), &(vm->dataptr[addr + 1]), sizeof(long double)); ! break; case CUPDATA_INTEGER: val = cupvm_value_new(); *************** *** 157,182 **** memcpy(&(val->data.val_integer), &(vm->dataptr[addr + 1]), sizeof(long int)); ! if (!cupvm_value_push(vm, val)) ! cupvm_tb(vm, "cupvm_PUSH()", "failed to push value"); ! return; case CUPDATA_STRING: val = cupvm_value_new(); val->type = CUPTYPE_STRING; val->data.val_string = dstrdup(&(vm->dataptr[addr + 1]), TYPE_CUPVM); ! if (!cupvm_value_push(vm, val)) ! cupvm_tb(vm, "cupvm_PUSH()", "failed to push value"); ! return; case CUPDATA_VARIABLE: // TEMPORARY. Need scoping/variable code ! val = cupvm_scope_findtoken(vm, &(vm->dataptr[addr + 1])); if (!val) cupvm_tb(vm, "cupvm_PUSH()", "could not find variable in scope"); ! return; default: cupvm_tb(vm, "cupvm_PUSH()", "unknown data at address"); return; } } void cupvm_POP(CUPVM *vm) { --- 200,229 ---- memcpy(&(val->data.val_integer), &(vm->dataptr[addr + 1]), sizeof(long int)); ! break; case CUPDATA_STRING: val = cupvm_value_new(); val->type = CUPTYPE_STRING; val->data.val_string = dstrdup(&(vm->dataptr[addr + 1]), TYPE_CUPVM); ! break; case CUPDATA_VARIABLE: // TEMPORARY. Need scoping/variable code ! val = cupvm_scope_findvar(vm, &(vm->dataptr[addr + 1])); if (!val) + { cupvm_tb(vm, "cupvm_PUSH()", "could not find variable in scope"); ! return; ! } ! break; default: cupvm_tb(vm, "cupvm_PUSH()", "unknown data at address"); return; } + + val->references++; + if (!cupvm_value_push(vm, val)) + cupvm_tb(vm, "cupvm_PUSH()", "failed to push value"); } + // decrement references, popping from the stack. if refs == 0, free value void cupvm_POP(CUPVM *vm) { *************** *** 184,191 **** val = cupvm_value_pop(vm); if (!val) cupvm_tb(vm, "cupvm_POP()", "failed to pop data"); else ! cupvm_value_free(val); } --- 231,242 ---- val = cupvm_value_pop(vm); + val->references--; if (!val) cupvm_tb(vm, "cupvm_POP()", "failed to pop data"); else ! { ! if (!val->references) ! cupvm_value_free(val); ! } } *************** *** 198,204 **** val = cupvm_value_pop(vm); if (!val) cupvm_tb(vm, "cupvm_POP()", "failed to pop data"); else ! cupvm_value_free(val); } --- 249,259 ---- val = cupvm_value_pop(vm); + val->references--; if (!val) cupvm_tb(vm, "cupvm_POP()", "failed to pop data"); else ! { ! if (!val->references) ! cupvm_value_free(val); ! } } Index: scopes.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/scopes.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** scopes.c 22 Aug 2002 18:57:25 -0000 1.1 --- scopes.c 23 Aug 2002 15:22:40 -0000 1.2 *************** *** 7,23 **** "@(#) $Id$"; ! CUPVALUE *cupvm_scope_findtoken(CUPVM *vm, const char *tok) { CUPSCOPE *scope; ! CUPVALUE *val; ! unsigned long depth = 0; ! unsigned long idx = 0; while ((scope = list_item_from_back(vm->scopes, depth))) { ! while ((val = list_item_from_front(scope->vars, idx))) { ! if (strcmp(val->name, tok) == 0) ! return val; idx++; } --- 7,53 ---- "@(#) $Id$"; ! bool cupvm_scope_declvar(CUPVM *vm, CUPVALUE *var, char *name) { CUPSCOPE *scope; ! CUPSCOPEVAR *scopevar; ! unsigned long idx; + scope = list_item_from_back(vm->scopes, 0); + + if (!scope->vars) + scope->vars = list_new(); + + idx = 0; + while ((scopevar = list_item_from_front(scope->vars, idx))) + { + if (strcmp(scopevar->name, name) == 0) + return FALSE; + idx++; + } + + scopevar = dmalloc(sizeof(CUPSCOPEVAR), TYPE_CUPVM); + scopevar->name = dstrdup(name, TYPE_CUPVM); + scopevar->val = var; + + list_item_push_back(scope->vars, scopevar); + + return TRUE; + } + + CUPVALUE *cupvm_scope_findvar(CUPVM *vm, const char *name) + { + CUPSCOPE *scope; + CUPSCOPEVAR *scopevar; + unsigned long depth; + unsigned long idx; + + depth = 0; while ((scope = list_item_from_back(vm->scopes, depth))) { ! idx = 0; ! while ((scopevar = list_item_from_front(scope->vars, idx))) { ! if (strcmp(scopevar->name, name) == 0) ! return scopevar->val; idx++; } *************** *** 39,42 **** --- 69,88 ---- void cupvm_scope_free(CUPSCOPE *scope) { + CUPSCOPEVAR *scopevar; + + if (scope->vars) + { + while ((scopevar = list_item_pop_back(scope->vars))) + { + scopevar->val->references--; + if (!scopevar->val->references) + cupvm_value_free(scopevar->val); + dfree(scopevar->name); + dfree(scopevar); + } + + list_free(scope->vars); + } + dfree(scope); } Index: values.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/values.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** values.c 2 Aug 2002 15:50:44 -0000 1.8 --- values.c 23 Aug 2002 15:22:40 -0000 1.9 *************** *** 12,15 **** --- 12,17 ---- val = dmalloc(sizeof(CUPVALUE), TYPE_CUPVM); + val->type = CUPTYPE_NONE; + val->references = 0; return val; } Index: vm.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** vm.c 22 Aug 2002 18:57:25 -0000 1.17 --- vm.c 23 Aug 2002 15:22:40 -0000 1.18 *************** *** 59,64 **** { cupvm_execute(vm); ! cupvm_POPSCOPE(vm); } if (vm->stack) --- 59,73 ---- { cupvm_execute(vm); ! if (!vm->traceback) ! cupvm_POPSCOPE(vm); } + + if (vm->scopes) + { + while (list_length(vm->scopes)) + cupvm_scope_free(list_item_pop_back(vm->scopes)); + list_free(vm->scopes); + } + if (vm->stack) Index: vm.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** vm.h 22 Aug 2002 18:57:25 -0000 1.7 --- vm.h 23 Aug 2002 15:22:40 -0000 1.8 *************** *** 5,8 **** --- 5,9 ---- enum { + CUPTYPE_NONE = 0, CUPTYPE_FLOAT, CUPTYPE_INTEGER, *************** *** 16,19 **** --- 17,27 ---- }; + typedef struct cupscopevar CUPSCOPEVAR; + struct cupscopevar + { + CUPVALUE *val; + char *name; + }; + void cupvm_tb(CUPVM *, const char *, const char *); void cupvm_debug(CUPVM *); *************** *** 29,33 **** bool cupvm_scope_push(CUPVM *, CUPSCOPE *); CUPSCOPE *cupvm_scope_pop(CUPVM *); ! CUPVALUE *cupvm_scope_findtoken(CUPVM *, const char *); void cupvm_PUSHSCOPE(CUPVM *); void cupvm_POPSCOPE(CUPVM *); --- 37,42 ---- bool cupvm_scope_push(CUPVM *, CUPSCOPE *); CUPSCOPE *cupvm_scope_pop(CUPVM *); ! CUPVALUE *cupvm_scope_findvar(CUPVM *, const char *); ! bool cupvm_scope_declvar(CUPVM *, CUPVALUE *, char *); void cupvm_PUSHSCOPE(CUPVM *); void cupvm_POPSCOPE(CUPVM *); |
From: Keith J. <bu...@us...> - 2002-08-23 15:22:46
|
Update of /cvsroot/cup-language/cup/src In directory usw-pr-cvs1:/tmp/cvs-serv29748 Modified Files: cup.h.in Log Message: Lot of work being done Index: cup.h.in =================================================================== RCS file: /cvsroot/cup-language/cup/src/cup.h.in,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** cup.h.in 22 Aug 2002 18:57:24 -0000 1.13 --- cup.h.in 23 Aug 2002 15:22:40 -0000 1.14 *************** *** 138,142 **** { int type; ! char *name; union { --- 138,142 ---- { int type; ! int references; union { |
From: Keith J. <bu...@us...> - 2002-08-23 15:22:46
|
Update of /cvsroot/cup-language/cup/src/compiler In directory usw-pr-cvs1:/tmp/cvs-serv29748/compiler Modified Files: binary.c Log Message: Lot of work being done Index: binary.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/binary.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** binary.c 22 Aug 2002 18:57:25 -0000 1.15 --- binary.c 23 Aug 2002 15:22:40 -0000 1.16 *************** *** 598,601 **** --- 598,602 ---- case CUPCOP_RETURN: // PUSH arg (optional?) + // POPSCOPE // RET if (node->one) *************** *** 603,606 **** --- 604,608 ---- if (comp->traceback) return; + cupc_code_write(comp, CUPOP_POPSCOPE); cupc_code_write(comp, CUPOP_RET); break; *************** *** 658,664 **** --- 660,668 ---- case CUPCOP_FUNCTION: // JMP label1 + // PUSHSCOPE // ARG blah // ARG y // code + // POPSCOPE // RET lstart = comp->codelen; *************** *** 671,674 **** --- 675,679 ---- comp->codelen); cupc_code_free_label(node->label); + cupc_code_write(comp, CUPOP_PUSHSCOPE); for (argnode = node->two; argnode && argnode->next; argnode = argnode->next) *************** *** 690,693 **** --- 695,699 ---- d = 0; cupc_code_write_data(comp, &d, sizeof(unsigned long)); + cupc_code_write(comp, CUPOP_POPSCOPE); cupc_code_write(comp, CUPOP_RET); cupc_code_fix_jumps(comp, label1, comp->codelen, lstart); |
From: Keith J. <bu...@us...> - 2002-08-22 18:57:30
|
Update of /cvsroot/cup-language/cup/src/compiler In directory usw-pr-cvs1:/tmp/cvs-serv15220/compiler Modified Files: binary.c compiler.h nodes.c Log Message: Changlog? Changelog?? I don't need no stinkin' CHANGELOG! Besides, no one is here but me. ;) -drops a pin, waits for echo- Index: binary.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/binary.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** binary.c 22 Aug 2002 14:15:53 -0000 1.14 --- binary.c 22 Aug 2002 18:57:25 -0000 1.15 *************** *** 13,16 **** --- 13,17 ---- void cupc_bin_make_funcmap(CUPCOMPILED *, CUPCNODE *); void cupc_bin_clean_funcmap(CUPCOMPILED *); + unsigned long cupc_bin_funcmap_get_numargs(CUPCOMPILED *, const char *); unsigned long cupc_bin_funcmap_get_label(CUPCOMPILED *, const char *); void cupc_bin_funcmap_set_label(CUPCOMPILED *, const char *, unsigned long); *************** *** 85,88 **** --- 86,90 ---- { CUPCFUNC *func; + CUPCNODE *arg; if (!comp->funcmap) *************** *** 92,95 **** --- 94,100 ---- func->name = dstrdup(node->one->const_string, TYPE_CUPC); func->label = cupc_code_new_label(); + func->numargs = 0; + for (arg = node->two; arg; arg = arg->next) + func->numargs++; func->next = NULL; if (lfunc) *************** *** 124,128 **** CUPCFUNC *func; ! for (func = (CUPCFUNC *) list_item_first(comp->funcmap); func; func = func->next) { --- 129,133 ---- CUPCFUNC *func; ! for (func = (CUPCFUNC *) list_item_from_front(comp->funcmap, 0); func; func = func->next) { *************** *** 134,137 **** --- 139,156 ---- } + unsigned long cupc_bin_funcmap_get_numargs(CUPCOMPILED *comp, const char *name) + { + CUPCFUNC *func; + + for (func = (CUPCFUNC *) list_item_from_front(comp->funcmap, 0); func; + func = func->next) + { + if (strcmp(func->name, name) == 0) + return func->numargs; + } + + return 0; + } + void cupc_bin_funcmap_set_label(CUPCOMPILED *comp, const char *name, unsigned long label) *************** *** 139,143 **** CUPCFUNC *func; ! for (func = (CUPCFUNC *) list_item_first(comp->funcmap); func; func = func->next) { --- 158,162 ---- CUPCFUNC *func; ! for (func = (CUPCFUNC *) list_item_from_front(comp->funcmap, 0); func; func = func->next) { *************** *** 169,173 **** CUPCNODE *casenode, *defaultnode; CUPCNODE *argnode; ! unsigned long d; switch (node->op) --- 188,192 ---- CUPCNODE *casenode, *defaultnode; CUPCNODE *argnode; ! unsigned long d, x; switch (node->op) *************** *** 589,595 **** // PUSH args // JMPR function label - cupc_bin_build(comp, node->two, 0, 0, 0); - if (comp->traceback) - return; label1 = cupc_bin_funcmap_get_label(comp, node->one->const_string); if (!label1) --- 608,611 ---- *************** *** 610,613 **** --- 626,656 ---- return; } + d = 0; + for (argnode = node->two; argnode; argnode = argnode->next) + d++; + x = cupc_bin_funcmap_get_numargs(comp, node->one->const_string); + + if (d != x) + { + char errbuf[TBUFSIZE]; + const char *sfile; + + comp->line = node->line; + sfile = comp->filename; + comp->filename = node->sourcefile; + + sprintf(errbuf, "function '%s' being called with %ld arguments, requires %ld", + node->one->const_string, d, x); + cupc_tb(comp, "CUPCOP_CALL", errbuf); + + comp->line = 0; + comp->filename = sfile; + + return; + } + + cupc_bin_build(comp, node->two, 0, 0, 0); + if (comp->traceback) + return; cupc_code_write(comp, CUPOP_JMPR); cupc_code_write_data(comp, &label1, sizeof(unsigned long)); Index: compiler.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/compiler.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** compiler.h 22 Aug 2002 14:15:53 -0000 1.11 --- compiler.h 22 Aug 2002 18:57:25 -0000 1.12 *************** *** 10,13 **** --- 10,14 ---- char *name; unsigned long label; + unsigned long numargs; CUPCFUNC *next; }; Index: nodes.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/nodes.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** nodes.c 22 Aug 2002 14:15:53 -0000 1.12 --- nodes.c 22 Aug 2002 18:57:25 -0000 1.13 *************** *** 25,29 **** LIST *list; ! list = (LIST *) list_item_last(comp->nodestack); while (new) { --- 25,29 ---- LIST *list; ! list = (LIST *) list_item_from_back(comp->nodestack, 0); while (new) { *************** *** 52,56 **** return NULL; ! list = list_item_last(comp->nodestack); ret = list_item_pop_front(list); node = ret; --- 52,56 ---- return NULL; ! list = list_item_from_back(comp->nodestack, 0); ret = list_item_pop_front(list); node = ret; |
From: Keith J. <bu...@us...> - 2002-08-22 18:57:30
|
Update of /cvsroot/cup-language/cup/src/common In directory usw-pr-cvs1:/tmp/cvs-serv15220/common Modified Files: list.c list.h Log Message: Changlog? Changelog?? I don't need no stinkin' CHANGELOG! Besides, no one is here but me. ;) -drops a pin, waits for echo- Index: list.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/common/list.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** list.c 2 Aug 2002 15:50:44 -0000 1.6 --- list.c 22 Aug 2002 18:57:25 -0000 1.7 *************** *** 192,209 **** } ! void *list_item_first(LIST *list) { ! if (list && list->first) ! return list->first->data; ! return NULL; } ! void *list_item_last(LIST *list) { ! if (list && list->last) ! return list->last->data; ! return NULL; } --- 192,239 ---- } ! void *list_item_from_front(LIST *list, unsigned long idx) { ! LISTITEM *item; ! if (!list) ! return NULL; ! ! item = list->first; ! if (!item) ! return NULL; ! ! while (idx) ! { ! item = item->next; ! if (!item) ! return NULL; ! ! idx--; ! } ! ! return item->data; } ! void *list_item_from_back(LIST *list, unsigned long idx) { ! LISTITEM *item; ! ! if (!list) ! return NULL; ! ! item = list->last; ! if (!item) ! return NULL; ! ! while (idx) ! { ! item = item->prev; ! if (!item) ! return NULL; ! ! idx--; ! } ! return item->data; } Index: list.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/common/list.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** list.h 2 Aug 2002 15:50:44 -0000 1.4 --- list.h 22 Aug 2002 18:57:25 -0000 1.5 *************** *** 11,16 **** void list_item_push_front(LIST *, void *); void *list_item_pop_front(LIST *); ! void *list_item_first(LIST *); ! void *list_item_last(LIST *); unsigned long list_length(LIST *); void list_startup(void); --- 11,16 ---- void list_item_push_front(LIST *, void *); void *list_item_pop_front(LIST *); ! void *list_item_from_front(LIST *, unsigned long); ! void *list_item_from_back(LIST *, unsigned long); unsigned long list_length(LIST *); void list_startup(void); |
From: Keith J. <bu...@us...> - 2002-08-22 18:57:30
|
Update of /cvsroot/cup-language/cup/src/vm In directory usw-pr-cvs1:/tmp/cvs-serv15220/vm Modified Files: Makefile debug.c execute.c rules.mk vm.c vm.h Added Files: scopes.c Log Message: Changlog? Changelog?? I don't need no stinkin' CHANGELOG! Besides, no one is here but me. ;) -drops a pin, waits for echo- --- NEW FILE: scopes.c --- /* (c) CrimeBucket Productions */ #include "../cup.h" #include "../common/dmem.h" #include "vm.h" char *scopes_c_id = "@(#) $Id: scopes.c,v 1.1 2002/08/22 18:57:25 bucket Exp $"; CUPVALUE *cupvm_scope_findtoken(CUPVM *vm, const char *tok) { CUPSCOPE *scope; CUPVALUE *val; unsigned long depth = 0; unsigned long idx = 0; while ((scope = list_item_from_back(vm->scopes, depth))) { while ((val = list_item_from_front(scope->vars, idx))) { if (strcmp(val->name, tok) == 0) return val; idx++; } depth++; } return NULL; } CUPSCOPE *cupvm_scope_new(void) { CUPSCOPE *scope; scope = dmalloc(sizeof(CUPSCOPE), TYPE_CUPVM); scope->vars = NULL; return scope; } void cupvm_scope_free(CUPSCOPE *scope) { dfree(scope); } bool cupvm_scope_push(CUPVM *vm, CUPSCOPE *scope) { if (!vm->scopes) vm->scopes = list_new(); if (!vm->scopes) return FALSE; list_item_push_back(vm->scopes, scope); return TRUE; } CUPSCOPE *cupvm_scope_pop(CUPVM *vm) { CUPSCOPE *ret; if (!vm->scopes) return NULL; ret = (CUPSCOPE *) list_item_pop_back(vm->scopes); if (!ret) return NULL; if (list_length(vm->scopes) == 0) { list_free(vm->scopes); vm->scopes = NULL; } return ret; } Index: Makefile =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/Makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** Makefile 2 Aug 2002 15:50:44 -0000 1.5 --- Makefile 22 Aug 2002 18:57:25 -0000 1.6 *************** *** 4,9 **** -include ../rules.mk ! OBJS = debug.o execute.o values.o vm.o ! SRCS = debug.c execute.c values.c vm.c HDRS = vm.h --- 4,9 ---- -include ../rules.mk ! OBJS = debug.o execute.o scopes.o values.o vm.o ! SRCS = debug.c execute.c scopes.c values.c vm.c HDRS = vm.h *************** *** 14,17 **** --- 14,19 ---- execute.o: execute.c $(HDRS) ../cup.h $(CC) $(CFLAGS) -c execute.c + scopes.o: scopes.c $(HDRS) ../cup.h + $(CC) $(CFLAGS) -c scopes.c values.o: values.c $(HDRS) ../cup.h $(CC) $(CFLAGS) -c values.c Index: debug.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/debug.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** debug.c 2 Aug 2002 15:50:44 -0000 1.9 --- debug.c 22 Aug 2002 18:57:25 -0000 1.10 *************** *** 6,9 **** --- 6,19 ---- char *debug_c_id = "@(#) $Id$"; + // Data from ../cup.h + char *op_to_str[] = { + "NOP", "PUSH", "SET", "ADD", + "SUB", "MUL", "DIV", "MOD", + "NEG", "NOT", "EQ", "JMP", + "JMPF", "JMPT", "JMPR", "RET", + "ARG", "POP", "VAR", "PUSHSCOPE", + "POPSCOPE", "EXIT" + }; + void cupvm_debug(CUPVM *vm) { *************** *** 101,130 **** { case CUPOP_ADD: - printf("%4lX: ADD\n", display); - break; case CUPOP_SUB: - printf("%4lX: SUB\n", display); - break; case CUPOP_MUL: - printf("%4lX: MUL\n", display); - break; case CUPOP_DIV: - printf("%4lX: DIV\n", display); - break; case CUPOP_MOD: - printf("%4lX: MOD\n", display); - break; case CUPOP_NEG: - printf("%4lX: NEG\n", display); - break; case CUPOP_NOT: - printf("%4lX: NOT\n", display); - break; case CUPOP_EQ: - printf("%4lX: EQ\n", display); - break; case CUPOP_SET: ! printf("%4lX: SET\n", display); break; case CUPOP_JMP: memcpy(&ul, &(vm->binary[pc + 1]), sizeof(unsigned long)); --- 111,130 ---- { case CUPOP_ADD: case CUPOP_SUB: case CUPOP_MUL: case CUPOP_DIV: case CUPOP_MOD: case CUPOP_NEG: case CUPOP_NOT: case CUPOP_EQ: case CUPOP_SET: ! case CUPOP_RET: ! case CUPOP_EXIT: ! case CUPOP_POP: ! case CUPOP_PUSHSCOPE: ! case CUPOP_POPSCOPE: ! printf("%4lX: %s\n", display, op_to_str[(int) vm->binary[pc]]); break; + case CUPOP_JMP: memcpy(&ul, &(vm->binary[pc + 1]), sizeof(unsigned long)); *************** *** 143,149 **** printf("%4lX: JMPR: %lX\n", display, ul); break; - case CUPOP_RET: - printf("%4lX: RET\n", display); - break; case CUPOP_PUSH: printf("%4lX: PUSH ", display); --- 143,146 ---- *************** *** 160,175 **** memcpy(&ul, &(vm->binary[pc + 1]), sizeof(unsigned long)); cupvm_debug_data(vm, ul + (vm->dataptr - vm->binary)); - break; - case CUPOP_EXIT: - printf("%4lX: EXIT\n", display); - break; - case CUPOP_POP: - printf("%4lX: POP\n", display); - break; - case CUPOP_PUSHSCOPE: - printf("%4lX: PUSHSCOPE\n", display); - break; - case CUPOP_POPSCOPE: - printf("%4lX: POPSCOPE\n", display); break; default: --- 157,160 ---- Index: execute.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/execute.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** execute.c 2 Aug 2002 15:50:44 -0000 1.11 --- execute.c 22 Aug 2002 18:57:25 -0000 1.12 *************** *** 81,85 **** --- 81,93 ---- break; case CUPOP_PUSHSCOPE: + cupvm_PUSHSCOPE(vm); + if (vm->traceback) + return; + vm->pc++; + break; case CUPOP_POPSCOPE: + cupvm_POPSCOPE(vm); + if (vm->traceback) + return; vm->pc++; break; *************** *** 93,96 **** --- 101,135 ---- } + void cupvm_PUSHSCOPE(CUPVM *vm) + { + CUPSCOPE *scope; + + scope = cupvm_scope_new(); + if (!cupvm_scope_push(vm, scope)) + cupvm_tb(vm, "cupvm_PUSHSCOPE()", "failed to push scope"); + } + + void cupvm_POPSCOPE(CUPVM *vm) + { + CUPVALUE *val; + CUPSCOPE *scope; + + scope = cupvm_scope_pop(vm); + if (!scope) + { + cupvm_tb(vm, "cupvm_POPSCOPE()", "failed to pop scope"); + return; + } + + if (scope->vars) + { + while ((val = (CUPVALUE *) list_item_pop_back(scope->vars))) + cupvm_value_free(val); + list_free(scope->vars); + } + + cupvm_scope_free(scope); + } + void cupvm_PUSH(CUPVM *vm, unsigned long addr) { *************** *** 130,138 **** case CUPDATA_VARIABLE: // TEMPORARY. Need scoping/variable code ! val = cupvm_value_new(); ! val->type = CUPTYPE_INTEGER; ! val->data.val_integer = 0; ! if (!cupvm_value_push(vm, val)) ! cupvm_tb(vm, "cupvm_PUSH()", "failed to push value"); return; default: --- 169,175 ---- case CUPDATA_VARIABLE: // TEMPORARY. Need scoping/variable code ! val = cupvm_scope_findtoken(vm, &(vm->dataptr[addr + 1])); ! if (!val) ! cupvm_tb(vm, "cupvm_PUSH()", "could not find variable in scope"); return; default: Index: rules.mk =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/rules.mk,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** rules.mk 4 May 2002 18:27:49 -0000 1.1 --- rules.mk 22 Aug 2002 18:57:25 -0000 1.2 *************** *** 2,6 **** # @(#) $Id$ ! VMOBJS = vm/debug.o vm/execute.o vm/values.o vm/vm.o ! VMSRCS = vm/debug.c vm/execute.c vm/values.c vm/vm.c VMHDRS = vm/vm.h --- 2,6 ---- # @(#) $Id$ ! VMOBJS = vm/debug.o vm/execute.o vm/scopes.o vm/values.o vm/vm.o ! VMSRCS = vm/debug.c vm/execute.c vm/scopes.c vm/values.c vm/vm.c VMHDRS = vm/vm.h Index: vm.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** vm.c 2 Aug 2002 15:50:44 -0000 1.16 --- vm.c 22 Aug 2002 18:57:25 -0000 1.17 *************** *** 53,58 **** vm->retval = NULL; vm->stack = NULL; ! cupvm_execute(vm); if (vm->stack) --- 53,64 ---- vm->retval = NULL; vm->stack = NULL; + vm->scopes = NULL; ! cupvm_PUSHSCOPE(vm); ! if (!vm->traceback) ! { ! cupvm_execute(vm); ! cupvm_POPSCOPE(vm); ! } if (vm->stack) Index: vm.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/vm/vm.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** vm.h 2 Aug 2002 15:50:44 -0000 1.6 --- vm.h 22 Aug 2002 18:57:25 -0000 1.7 *************** *** 10,20 **** }; void cupvm_tb(CUPVM *, const char *, const char *); void cupvm_debug(CUPVM *); void cupvm_debug_op(CUPVM *, unsigned long, unsigned long); void cupvm_debug_data(CUPVM *, unsigned long); CUPVALUE *cupvm_value_new(void); void cupvm_value_free(CUPVALUE *); - void cupvm_execute(CUPVM *); bool cupvm_value_push(CUPVM *, CUPVALUE *); CUPVALUE *cupvm_value_pop(CUPVM *); --- 10,33 ---- }; + typedef struct cupscope CUPSCOPE; + struct cupscope + { + LIST *vars; + }; + void cupvm_tb(CUPVM *, const char *, const char *); void cupvm_debug(CUPVM *); void cupvm_debug_op(CUPVM *, unsigned long, unsigned long); void cupvm_debug_data(CUPVM *, unsigned long); + void cupvm_execute(CUPVM *); CUPVALUE *cupvm_value_new(void); void cupvm_value_free(CUPVALUE *); bool cupvm_value_push(CUPVM *, CUPVALUE *); CUPVALUE *cupvm_value_pop(CUPVM *); + CUPSCOPE *cupvm_scope_new(void); + void cupvm_scope_free(CUPSCOPE *); + bool cupvm_scope_push(CUPVM *, CUPSCOPE *); + CUPSCOPE *cupvm_scope_pop(CUPVM *); + CUPVALUE *cupvm_scope_findtoken(CUPVM *, const char *); + void cupvm_PUSHSCOPE(CUPVM *); + void cupvm_POPSCOPE(CUPVM *); |
From: Keith J. <bu...@us...> - 2002-08-22 18:57:30
|
Update of /cvsroot/cup-language/cup/src In directory usw-pr-cvs1:/tmp/cvs-serv15220 Modified Files: Makefile cup.h.in Log Message: Changlog? Changelog?? I don't need no stinkin' CHANGELOG! Besides, no one is here but me. ;) -drops a pin, waits for echo- Index: Makefile =================================================================== RCS file: /cvsroot/cup-language/cup/src/Makefile,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** Makefile 22 Aug 2002 14:15:52 -0000 1.10 --- Makefile 22 Aug 2002 18:57:24 -0000 1.11 *************** *** 18,22 **** @echo @echo .... Building cup .... ! $(CC) $(CFLAGS) -DLIBDIR=$(LIBDIRS) -c cup.c $(CC) cup.o ../lib/libcup.a $(LDFLAGS) -o ../bin/cup --- 18,22 ---- @echo @echo .... Building cup .... ! $(CC) $(CFLAGS) -DLIBDIR=\"$(LIBDIR)\" -c cup.c $(CC) cup.o ../lib/libcup.a $(LDFLAGS) -o ../bin/cup *************** *** 24,28 **** @echo @echo .... Building cupc .... ! $(CC) $(CFLAGS) -DLIBDIR=$(LIBDIRS) -c cupc.c $(CC) cupc.o ../lib/libcupc.a $(LDFLAGS) -o ../bin/cupc --- 24,28 ---- @echo @echo .... Building cupc .... ! $(CC) $(CFLAGS) -DLIBDIR=\"$(LIBDIR)\" -c cupc.c $(CC) cupc.o ../lib/libcupc.a $(LDFLAGS) -o ../bin/cupc Index: cup.h.in =================================================================== RCS file: /cvsroot/cup-language/cup/src/cup.h.in,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** cup.h.in 2 Aug 2002 15:50:44 -0000 1.12 --- cup.h.in 22 Aug 2002 18:57:24 -0000 1.13 *************** *** 132,135 **** --- 132,136 ---- unsigned long datalen; // Length of data section LIST *stack; // Stack + LIST *scopes; // Scopes }; *************** *** 137,140 **** --- 138,142 ---- { int type; + char *name; union { *************** *** 142,146 **** long double val_float; char *val_string; - char *val_variable; } data; --- 144,147 ---- |
From: Keith J. <bu...@us...> - 2002-08-22 14:15:56
|
Update of /cvsroot/cup-language/cup/src/compiler In directory usw-pr-cvs1:/tmp/cvs-serv5715/compiler Modified Files: binary.c compiler.h nodes.c parser.y Log Message: make WINBINARY=no now compiles/installs like under a unix environment, with cygwin, good for testing unknown functions now can report the correct filename/line number some unix make install bugs fixed Index: binary.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/binary.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** binary.c 2 Aug 2002 15:50:44 -0000 1.13 --- binary.c 22 Aug 2002 14:15:53 -0000 1.14 *************** *** 595,599 **** if (!label1) { ! cupc_tb(comp, "CUPCOP_CALL", "unknown function"); return; } --- 595,611 ---- if (!label1) { ! char errbuf[TBUFSIZE]; ! const char *sfile; ! ! comp->line = node->line; ! sfile = comp->filename; ! comp->filename = node->sourcefile; ! ! sprintf(errbuf, "unknown function '%s'", node->one->const_string); ! cupc_tb(comp, "CUPCOP_CALL", errbuf); ! ! comp->line = 0; ! comp->filename = sfile; ! return; } Index: compiler.h =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/compiler.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** compiler.h 2 Aug 2002 15:50:44 -0000 1.10 --- compiler.h 22 Aug 2002 14:15:53 -0000 1.11 *************** *** 29,32 **** --- 29,35 ---- long int const_integer; char *const_string; + + char *sourcefile; + unsigned long line; }; Index: nodes.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/nodes.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** nodes.c 2 Aug 2002 15:50:44 -0000 1.11 --- nodes.c 22 Aug 2002 14:15:53 -0000 1.12 *************** *** 85,88 **** --- 85,90 ---- newnode->op = op; newnode->const_string = NULL; + newnode->sourcefile = NULL; + newnode->line = 0; return newnode; *************** *** 153,156 **** --- 155,160 ---- if (node->next) cupc_node_free(node->next); + if (node->sourcefile) + dfree(node->sourcefile); dfree(node); } Index: parser.y =================================================================== RCS file: /cvsroot/cup-language/cup/src/compiler/parser.y,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** parser.y 2 Aug 2002 15:50:44 -0000 1.12 --- parser.y 22 Aug 2002 14:15:53 -0000 1.13 *************** *** 259,263 **** { $$ = cupc_node_new(CUPCOP_CALL, cupc_node_new_token($1), cupc_node_stack_pop((CUPCOMPILED *) parm), ! NULL, NULL); } ; --- 259,265 ---- { $$ = cupc_node_new(CUPCOP_CALL, cupc_node_new_token($1), cupc_node_stack_pop((CUPCOMPILED *) parm), ! NULL, NULL); ! $$->sourcefile = dstrdup(((CUPCOMPILED *) parm)->filename, TYPE_CUPC); ! $$->line = ((CUPCOMPILED *) parm)->line; } ; *************** *** 539,543 **** { const char *oldsrc, *oldfname; ! unsigned long oldplace; bool ret; --- 541,545 ---- { const char *oldsrc, *oldfname; ! unsigned long oldplace, oldline; bool ret; *************** *** 545,552 **** --- 547,556 ---- oldfname = comp->filename; oldplace = comp->place; + oldline = comp->line; comp->source = cup_callback_include(comp->data, filename); comp->filename = filename; comp->place = 0; + comp->line = 1; if (yyparse(comp) != 1) *************** *** 558,561 **** --- 562,566 ---- comp->filename = oldfname; comp->place = oldplace; + comp->line = oldline; dfree(filename); *************** *** 592,595 **** --- 597,601 ---- { cupc_node_link(comp, cupc_node_new(CUPCOP_EXIT, cupc_node_new_integer(0), NULL, NULL, NULL)); + comp->line = 0; if (comp_debug) |
From: Keith J. <bu...@us...> - 2002-08-22 14:15:56
|
Update of /cvsroot/cup-language/cup/src In directory usw-pr-cvs1:/tmp/cvs-serv5715 Modified Files: Makefile rules.mk.in Log Message: make WINBINARY=no now compiles/installs like under a unix environment, with cygwin, good for testing unknown functions now can report the correct filename/line number some unix make install bugs fixed Index: Makefile =================================================================== RCS file: /cvsroot/cup-language/cup/src/Makefile,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** Makefile 2 Aug 2002 15:50:43 -0000 1.9 --- Makefile 22 Aug 2002 14:15:52 -0000 1.10 *************** *** 7,11 **** -include common/rules.mk ! ifeq ($(CYGWIN),yes) HOWTOINSTALL = inno else --- 7,11 ---- -include common/rules.mk ! ifeq ($(WINBINARY),yes) HOWTOINSTALL = inno else *************** *** 18,22 **** @echo @echo .... Building cup .... ! $(CC) $(CFLAGS) -DLIBDIR=$(LIBDIR) -c cup.c $(CC) cup.o ../lib/libcup.a $(LDFLAGS) -o ../bin/cup --- 18,22 ---- @echo @echo .... Building cup .... ! $(CC) $(CFLAGS) -DLIBDIR=$(LIBDIRS) -c cup.c $(CC) cup.o ../lib/libcup.a $(LDFLAGS) -o ../bin/cup *************** *** 24,28 **** @echo @echo .... Building cupc .... ! $(CC) $(CFLAGS) -DLIBDIR=$(LIBDIR) -c cupc.c $(CC) cupc.o ../lib/libcupc.a $(LDFLAGS) -o ../bin/cupc --- 24,28 ---- @echo @echo .... Building cupc .... ! $(CC) $(CFLAGS) -DLIBDIR=$(LIBDIRS) -c cupc.c $(CC) cupc.o ../lib/libcupc.a $(LDFLAGS) -o ../bin/cupc *************** *** 119,123 **** @echo .... Distribution Squeeky Clean .... ! install: $(HOWTOINSTALL) shell: --- 119,123 ---- @echo .... Distribution Squeeky Clean .... ! install: all $(HOWTOINSTALL) shell: *************** *** 125,131 **** $(INSTALL) ./cup.h $(INCDIR) $(INSTALL) ../lib/stdio.cup $(LIBDIR) ! $(INSTALL) ../lib/string.cup $(LIBDIR) ! $(INSTALL) ../lib/cgi.cup $(LIBDIR) ! $(INSTALL) ../lib/ansi.cup $(LIBDIR) $(INSTALL) ../doc/man/cup.1 $(MANDIR)/man1 --- 125,129 ---- $(INSTALL) ./cup.h $(INCDIR) $(INSTALL) ../lib/stdio.cup $(LIBDIR) ! $(INSTALL) -d $(MANDIR)/man1 $(INSTALL) ../doc/man/cup.1 $(MANDIR)/man1 *************** *** 133,137 **** $(INSTALL) ../lib/libcupc.a $(LIBDIR) $(INSTALL) ../lib/libcupvm.a $(LIBDIR) - $(INSTALL) ../lib/libdmem.a $(LIBDIR) @echo "Cup is installed." --- 131,134 ---- Index: rules.mk.in =================================================================== RCS file: /cvsroot/cup-language/cup/src/rules.mk.in,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** rules.mk.in 2 Aug 2002 15:50:44 -0000 1.7 --- rules.mk.in 22 Aug 2002 14:15:52 -0000 1.8 *************** *** 9,12 **** --- 9,18 ---- ifeq ($(CYGWIN),yes) + WINBINARY = yes + else + WINBINARY = no + endif + + ifeq ($(WINBINARY),yes) CFLAGS += -mno-cygwin LDFLAGS += -mno-cygwin *************** *** 19,24 **** INSTALL = @INSTALL@ ! LIBDIR = \"@prefix@@libdir@\" ! BINDIR = \"@prefix@@bindir@\" ! MANDIR = \"@prefix@@mandir@\" ! INCDIR = \"@prefix@@includedir@\" --- 25,32 ---- INSTALL = @INSTALL@ ! LIBDIRS = \"@prefix@@libdir@\" ! ! LIBDIR = @prefix@@libdir@ ! BINDIR = @prefix@@bindir@ ! MANDIR = @prefix@@mandir@ ! INCDIR = @prefix@@includedir@ |
From: Keith J. <bu...@us...> - 2002-08-02 20:38:40
|
Update of /cvsroot/cup-language/cup/lib In directory usw-pr-cvs1:/tmp/cvs-serv31624/lib Added Files: stdio.cup Log Message: Started working on standard cup libs |
From: Keith J. <bu...@us...> - 2002-08-02 20:29:55
|
Update of /cvsroot/cup-language/cup/src In directory usw-pr-cvs1:/tmp/cvs-serv27403 Modified Files: winsetup.iss Log Message: Index: winsetup.iss =================================================================== RCS file: /cvsroot/cup-language/cup/src/winsetup.iss,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** winsetup.iss 2 Aug 2002 15:50:44 -0000 1.2 --- winsetup.iss 2 Aug 2002 20:29:51 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- [Icons] + Name: "{group}\Cup Language Reference"; Filename: "{app}\doc\CupLanguage.txt" Name: "{group}\FAQ"; Filename: "{app}\doc\FAQ.txt" |
From: Keith J. <bu...@us...> - 2002-08-02 20:26:36
|
Update of /cvsroot/cup-language/cup/doc In directory usw-pr-cvs1:/tmp/cvs-serv25770 Modified Files: CupLanguage.txt Log Message: I'm HORRIBLE at documenting this, but damnit, I'm trying. Index: CupLanguage.txt =================================================================== RCS file: /cvsroot/cup-language/cup/doc/CupLanguage.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** CupLanguage.txt 1 May 2002 12:10:47 -0000 1.4 --- CupLanguage.txt 2 Aug 2002 20:26:33 -0000 1.5 *************** *** 4,30 **** 1.1 History ! Cup has been and continues to be an ongoing project. It began as a ! overly simple scripting utility to be put into a MUD (Multi User ! Dungeon) for world builders to create triggers and events. As Cup grew, ! it became apparent that it had the potential to be much more. While ! other languages such as Java, REXX, Perl, Ruby, Python and so on exist, ! they lacked a specific feature that was required. That was the ability ! to run compiled bytecode in a 100% safe sandbox. For example, stopping ! execution on endless loops, instead of keeping control of the ! application for an unlimited amount of time. If the application Cup is ! embedded in cannot trust the Cup VM to recover from ANY code, then it ! can't be trusted at all. I'm not claiming that other packages cannot ! garuntee the same thing, I simply did not find them when I needed them, ! and thus Cup was born. ! Since then, Cup has grown and I decided to move it onto SourceForge. ! Surprisingly, others have wanted to help, and it's grown further. As of ! today, Cup is going through a major re-write which will put it into ! version 0.1.0. This has been a learning process for myself, and so ! things I've learned in the first versions are now being implemented in ! this newer rewrite. I expect to learn even more as more time goes on. ! The bottom line is I'm doing this because it's fun for me to do, and I ! needed it for a specific task at one time. So basically, I make no ! garuntee that Cup can do anything better than any other language. --- 4,10 ---- 1.1 History ! Cup has been and continues to be an ongoing project. It began as an overly simple scripting utility to be put into a MUD (Multi User Dungeon) for world builders to create triggers and events. As Cup grew, it became apparent that it had the potential to be much more. While other languages such as Java, REXX, Perl, Ruby, Python and so on exist, they lacked a specific feature that was required. That was the ability to run compiled bytecode in a 100% safe sandbox. For example, stopping execution on endless loops, instead of keeping control of the application for an unlimited amount of time. If the application Cup is embedded in cannot trust the Cup VM to recover from ANY code, then it can't be trusted at all. I'm not claiming that other packages cannot guarantee the same thing, I simply did not find them when I needed them, and thus Cup was born. ! Since then, Cup has grown and I decided to move it onto SourceForge. Surprisingly, others have wanted to help, and it's grown further. As of today, Cup is going through a major re-write which will put it into version 0.1.0. This has been a learning process for myself, and so things I've learned in the first versions are now being implemented in this newer rewrite. I expect to learn even more as more time goes on. The bottom line is I'm doing this because it's fun for me to do, and I needed it for a specific task at one time. So basically, I make no guarantee that Cup can do anything better than any other language. This is my toy. *************** *** 32,40 **** --------------------- 2.1 Data Types ! Cup by default has 3 basic data types, and 2 complex data types. A ! complex data type is defined as a data type which is built based on one ! of the basic data types. The basic data types are defined as follows: Type Example False --- 12,63 ---- --------------------- + 2.1 Syntax + + 2.1.1 Program Structure + + A Cup Program consists of zero or more statements, which can be either a 'simple' statement, or a 'complex' statement. A Cup Program can also contain zero or more function definitions. An appendix is provided showing the complete language definition in ???? format, built from the yacc/bison grammar file, for those interested in the formal definition. + + 2.1.2 Simple Statements + + A simple statement is any expression followed by a semicolon, or a null statement, which is simply a semicolon. Expressions are defined further in this document. + + 2.1.3 Complex Statements + + Complex statements are defined as 'special' statements, such as if and while blocks. Each type of complex statement is defined here. + + 2.1.3.1 Include Statements + + Include statements have the syntax: + + include <string>; + + The string argument to the keyword 'include' must be of the data type STRING, and must be completely parseable during compile-time, as include is a compile-time directive. The string could be something like '"stdio" + ".cup"' however could NOT be '"stdio" + cup_extention' since cup_extention would be a variable of which the value is not known at compile time. The safest bet is to assume this must be a single string constant. + + The default behaviour of the include statement should be to pause parsing, and open the specified file. Parsing should continue on the included file until it is complete (optionally including more files), and then the including file is further processed. The default Cup compiler will look in the current directory, and then in the Cup include directory, which contains many standard libraries such as stdio.cup. If Cup is embedded into another application, the behavior of the include statement can be changed, for example, to include different types of data, such as Cup source code from a database. + + 2.1.3.2 Variable Declarations + + Variable declarations have the syntax: + + var <varname>; + var <varname> = <expression>; + var <varname>, ...; + var <varname> = <expression>, ...; + + After a var keyword, one or more variables, each with an optional initializer are introduced into the current scope. If a variable is already in the current scope that would conflict with the new variable, it is considered a compile-time error. Each initializer may be any Cup expression. + + 2.1.3.3 Block Statement + + A block statement is zero or more statements grouped together as one statement. The syntax is as follows: + + { ... } + + Blocks can contain both simple and complex statements, but not function declarations. Indeed, a block may have other sub blocks. + + A block introduces a new scope. A variable 'x' declared in the global scope is different from a variable 'x' declared in another scope. + 2.1 Data Types ! Cup by default has 3 basic data types, and 2 complex data types. A complex data type is defined as a data type which is built based on one of the basic data types. The basic data types are defined as \follows: Type Example False *************** *** 45,484 **** +---------+----------+----+ ! The above chart shows the type, an example of the type, and then the ! boolean false value for the type. Any value other than the false value ! is considered to be true in boolean logic. Integers and Floats are ! mostly interchangeable. If a Float has no fractional element, then it is ! automatically mutated into an Integer. Any Integer operating on another ! Integer will yeild an Integer. Any fractional part is truncated. If a ! Float operates on an Integer or a Float, then the result will be a ! Float. That result however is vulnerable to the mutation from a Float to ! an Integer if there is no fractional element. Thus, 3.0 / 2 will yeild ! 1.5, a Float. However, 2.0 / 2 will yeild 1.0, which is then mutated to ! the Integer 1, the final result. Integers and Floats are always signed, ! not unsigned, so the ranges are from a negative number to a positive ! number that is currently implementation specific. This is a bug. Strings ! can be added to eachother which yeilds a String that is equal to the ! left value and right value combined into one String. The only other ! legal operation on a String is multiplication by an Integer, which will ! repeat the given String that number of times. For example "x" * 5 will ! yeild "xxxxx". ! ! ! ! ! ! <---- Old ----> ! ! #!../bin/cup ! // The Cup Programming Language ! // (c) CrimeBucket Productions 2001 ! ! include "stdio.cup"; ! ! /****************** The Cup Programming Language ************************* ! ! Cup is designed to be a lightweight virtual machine, suitable for ! embedding into larger parent applications. Cup programs are compiled into ! machine-independent bytecode, which can be saved and run later in the Cup ! Virtual Machine (VM). The VM is the 'core' of Cup, and is very careful to ! 'play nice'. When calling the VM, parameters can be passed as to maximum ! execution time, or maximum memory usage, or other limits. Cup will never ! run away with your program, like other 'embedable' languages might in the ! right conditions. This makes Cup invaluable for running untrusted code, ! and even resilient to corrupt bytecode. This document will show the syntax ! and semantics of the Cup Programming Language, and hopefully offer an ! insight into the workings of the VM. For help on embedding and other lower ! level functionality, see "Embedding.txt" ! ! Finally, it ought to be noted that this document is also an executable ! Cup Program itself. While it has no real useful functionality, you can ! edit it to see what happens, and is a good place to 'play' with it. No ! one ever learned anything without making use of it. ! ! *************************************************************************/ ! ! ! // COMMENTS ! // ! // Style 1: ! // The Cup Compiler ignores "//" and anything after it, until a newline ! // ! // Style 2: ! // The Cup Compiler ignores "#" and anything after it, until a newline ! // This style should not be used, except for the first line, for creating ! // shell scripts. It may be deprecated later, except for the first line. ! // ! // Style 3: ! // The Cup Compiler ignores everything between and including "/*" and "*/" ! // Such comments cannot be nested. ! ! ! /* DATA TYPES ! ! Cup has the following data types: ! ! integers 1 ! 3.45 ! strings "Hello, world!" ! lists [1, 1.25, "Hello, world!", [1, 2, 3], 5] ! ! Lists can contain any number of values, of any type, including other ! lists. Strings and lists can both be 'empty', having either 0 characters, ! or in the case of a list, 0 values, as in [] and "". ! */ ! ! ! /* STATEMENTS ! ! A Cup statement is any language construct, such as ifs/whiles, or an ! expression followed by a semicolon. There is also a 'null' statement, ! which is simply a semicolon. Enclosing statements in braces ('{' and '}') ! groups them together in a 'block' that is executed as one statement. ! ! NOTE: Blocks also introduce a new SCOPE, covered later. ! */ ! ! ; ! ! 1; ! ! 1.5; ! ! "Hello, world"; ! ! [1, 2, 3, 4]; ! ! if ([1, 2, 3]) ! "Doh"; ! else ! 2.82; ! ! while ("") ! ["Hrm"]; ! ! if ("Johnny") ! { ! 1; ! [[2]]; ! } ! else ! [[2, 3], 1]; ! ! while (0.0) ! { ! 1; ! 2; ! 3; ! } ! ! print(""); ! ! ! /* EXPRESSIONS ! ! Expressions in Cup are basically 'values'. Such values can be the result ! of computation. For example, 1 + 1 is an expression, with a value of two. ! All functions return values, even if a function is not specified to return ! a value, its value is 0. ! ! There are many Cup 'operators' for coming up with expressions. The ! following is a list, in order of precedence. Two operators on one line ! indicate equal precedence. ! ! [ ] INDEX / RANGE ! ! ++ -- NOT, INCREMENT, DECREMENT ! * / MULTIPLY, DIVIDE ! + - ADD, SUBTRACT ! > >= < <= GREATER THAN, GREATER THAN OR EQUAL, LESS THAN, LESS THAN OR EQUAL ! >= can be written as => ! <= can be written as =< ! == != EQUAL TO, NOT EQUAL TO ! && LOGICAL AND ! || LOGICAL OR ! = ASSIGNMENT ! ! INDEX/RANGE: Indexing and ranging values, covered in STRINGS AND ! LISTS ! NOT: Reverses the 'truth' of a value ! INCREMENT: ++x increments x by 1 and returns the result ! x++ returns the value of x and then increments x by 1 ! DECREMENT: --x decrements x by 1 and returns the result ! x-- returns the value of x and then decrements x by 1 ! MULTIPLY: x * y multiplies x and y ! DIVIDE: x / y divides x by y ! ADD: x + y adds x and y ! SUBTRACT: x - y subtracts y from x ! GREATER THAN: x > y is 1 if x is greater than y, otherwise 0 ! GREATER THAN OR EQUAL: x >= y is 1 if x is greater than or equal to y, ! otherwise 0 ! LESS THAN: x < y is 1 if x is less than y, otherwise 0 ! LESS THAN OR EQUAL: x <= y is 1 if x is less than or equal to y, ! otherwise 0 ! EQUAL TO: x == y is 1 if x and y are equal, otherwise 0 ! NOT EQUAL TO: x != y is 1 if x and y are not equal, otherwise 0 ! LOGICAL AND: x && y is true if x and y are true, otherwise false ! LOGICAL OR: x || y is true if x or y are true, otherwise false ! ASSIGNMENT: x = y sets the value x to be equal to y ! ! NOTE: The Cup Virtual Machine, when evaluating AND and OR, ! does not continue evaluating when the truth or falsehood ! of an expression can be computed. i.e.: ! */ ! ! x = 0; ! j = 0; ! x && (j = 5); // (j = 5) will not be evaluated. Cup can see that x is false, ! // so no matter the next value, the statement is false. Thus, j ! // is still equal to 0 ! x = 1; ! j = 0; ! x || (j = 5); // As in AND, (j = 5) is never evaluated. Cup can see x is ! // true, so no matter the next value, the statement is true. ! // Thus, j is still equal to 0 ! ! /* ! Secondly, unlike other expressions, where Cup will ! produce a '1' or a '0' on the stack, an AND or OR ! expression is equal to its last evaluated expression. ! So: ! */ ! ! x = "Hi" && "Doh"; ! j = "Hi" || "Doh"; ! ! /* ! x and j both do not equal 1, x is equal to "Doh!" and j ! is equal to "Hi". Both strings are 'true', however. ! Every Cup data type has true/false values, and a value ! that is used for negating. ( using '!' (NOT) ): ! ! Type Truth False Not ! ---- ----- ----- --- ! integer any value but 0 0 1 0 ! string any string not empty "" "true" "" ! list any list not empty [] [1] [] ! */ ! ! !1; // 0 ! 1 * 1; 1 / 1; // 1, 1 ! 1 + 1; 1 - 1; // 2, 0 ! 1 < 1; 1 <= 1; 1 > 1; 1 >= 1; // 0, 1, 0, 1 ! 1 == 1; 1 != 1; // 1, 0 ! 3 && 4; // 4 ! 5 || 6; // 5 ! x = 1; // 1 ! ! /* VARIABLES ! ! Cup variables can be declared anywhere. Just using a token name not known ! creates a variable. This is both powerful, and, can be a pain. Since you ! can create a variable just by referring to it, if you are coding and make ! a typo, it may be hard to catch. For example: ! */ ! ! difference = 50; ! x = 20; ! if (diference == 50) ! x = 50; ! ! /* ! At a quick glance, x ought to equal 50; however, it doesn't. x will still ! equal 20, as the comparison 'diference' is missing an 'f'. ! ! Variables can also be declared explicitly, and, you may wish to program ! that way as a general rule. Cup has functionality to disallow implicit ! variable declaring, so even if you allow it, you may want to declare ! variables explicitly, as a rule of thumb: ! */ ! ! decl john, keith = "Keith Jackson"; ! // decl john; // error ! ! /* ! The 'decl' keyword declares a variable. Declaring a variable that already ! exists in the current scope, even if it was implicit, is a runtime error. ! Variables can be assigned the result of any expression at declaration ! time. This does not truly 'initialize' the variable, since it is FIRST ! created, THEN assigned a value. The question then arises what value are ! new variables given. All new variables, declared either implicitly or ! explicitly, are integers equal to 0. ! */ ! ! decl jamie; // 0 ! jason; // 0 ! ! ! /* SCOPE ! ! Variables exist in scopes. When the Cup Virtual Machine starts, a ! top-level scope is created automatically for you. All variables we have ! used so far exist in this global scope. When this program ends, the global ! scope will be deleted, and all variables declared in the scope are freed. ! ! When using { and }, you are creating a new scope. Any variables either ! implicitly or explicitly declared in the scope are local to that scope, ! and once the scope ends, the variables are destroyed. Here is an example: ! */ ! ! i = 0; ! { ! newi = 50; ! } ! ! if (newi == 50) ! i = 5; ! ! /* ! After executing that code, 'i' will still be equal to 0. 'newi' is created ! in a new scope. When that scope ends, newi is destroyed. Thus, when ! comparing newi, it is again implicitly declared, this time at the global ! scope, and is initialized to 0 by default, which is NOT equal to 50. ! ! Now, if we wanted to use the variable name 'i' in the block, it would ! assume we meant the global 'i', and not create a new 'i'. This is one ! reason implicit declaration can be dangerous. To have a DIFFERENT 'i' ! variable in our new block, we have to explicitly declare it: ! */ ! ! i = 0; ! { ! decl i; ! ! i = 5; ! } ! ! if (i == 5) ! i = 15; ! ! /* ! In that example, 'i' will still be equal to 0. Inside the block, we ! created a NEW variable 'i', and, once the end of the block is reached, ! that 'i' is destroyed. The global scope 'i' is never changed. ! */ ! ! /* CONDITIONALS ! ! So far, we have seen it used many times, but never really explained. 'if' ! statements are a way to have the program do different things, depending on ! values. Without that kind of control, programs are nothing more than lists ! of things to do. The most 'basic' type of descision making in most ! programming languages is the 'if' statement. Such as: ! ! if ( condition ) ! statement-1; ! else ! statement-2; ! ! Condition is an expression, and if it is 'true', statement-1 is executed, ! otherwise, statement-2 is executed. The 'else' part is optional. ! */ ! ! i = 30; ! if (i == 30) ! i = 40; // This will be executed. ! else ! i = 35; // This will not. ! ! /* ! You may want to do more than one thing under some conditions; in that ! case, we learned earlier, blocks are considered one statement, so, it fits ! the if-else syntax well. ! */ ! ! if ("strings are true, if they are not empty") ! { ! "And we can do"; ! "multiple things here"; ! "because we are in a block"; ! } ! else ! "Here, though, we aren't. We could if we wanted to be, though"; ! ! /* ! Sometimes you might want to have more than one option depending on a ! variable's value. Consider the following: ! */ ! ! if (i == 1) ! "Do this if i is 1"; ! else ! if (i == 2) ! "Do this if it equals 2"; ! else ! if (i == 3) ! "Do this if it equals 3"; ! else ! if (i == 4) ! "Do this if it equals 4"; ! else ! "Otherwise, do this"; ! ! /* ! The above shows how you can make lots of different choices with if-else ! statements; however, experienced programmers understand that since ! langauges like Cup ignore how you format it, it could be re-written like ! the following and have the same effect: ! */ ! ! if (i == 1) ! "Do this if i is 1"; ! else if (i == 2) ! "Do this if it equals 2"; ! else if (i == 3) ! "Do this if it equals 3"; ! else if (i == 4) ! "Do this if it equals 4"; ! else ! "Otherwise, do this"; ! ! /* ! If you look careful, it is the exact same as the previous, just spaced ! differently. If it helps, you can just consider 'else if' part of the if ! syntax, and, in fact, many programmers do not understand that there is no ! 'else if' keyword. ! */ ! ! /* LOOPING ! ! Another consideration is doing things many times over. Maybe we wanted to ! create a list of numbers, from 1 to 100. We could, of course, type it all ! out into our program: ! */ ! ! list = [1, 2, 3, 4, 5, 6, 7, 8, /* and so on */ 97, 98, 99, 100]; ! ! /* ! Or we could loop: ! */ ! ! i = 1; ! list = []; ! while (i <= 100) ! { ! list = list + [i]; ! ++i; ! } ! ! /* ! The true syntax for a while statement is: ! ! while ( expression ) ! statement; ! ! While statements will continue to execute 'statement' until 'expression' ! is false. Expression is evaluated, then statement is run, then expression ! is evaluated again, and so on. ! */ ! ! ! /* FUNCTIONS ! ! */ ! ! ! decl print_with_newline(val) ! { ! print(val + "\n"); ! } ! ! print_with_newline("Hi there"); --- 68,72 ---- +---------+----------+----+ ! The above chart shows the type, an example of the type, and then the boolean false value for the type. Any value other than the false value is considered to be true in boolean logic. Integers and Floats are mostly interchangeable. If a Float has no fractional element, then it is automatically mutated into an Integer. Any Integer operating on another Integer will yield an Integer. Any fractional part is truncated. If a Float operates on an Integer or a Float, then the result will be a Float. That result however is vulnerable to the mutation from a Float to an Integer if there is no fractional element. Thus, 3.0 / 2 will yield 1.5, a Float. However, 2.0 / 2 will yield 1.0, which is then mutated to the Integer 1, the final result. Integers and Floats are always signed, not unsigned, so the ranges are from a negative number to a positive number that is currently implementation specific. This is a bug. Strings can be added to each other which yields a String that is equal to the left value and right value combined into one String. The only other legal operation on a String is multiplication by an Integer, which will repeat the given String that number of times. For example "x" * 5 will yield "xxxxx". ! ! Complex data types consist of 2 container style data types that contain other data. These two types are a list type, and a dictionary type. |
From: Keith J. <bu...@us...> - 2002-08-02 20:26:02
|
Update of /cvsroot/cup-language/cup/src/common In directory usw-pr-cvs1:/tmp/cvs-serv25444/common Modified Files: getopts.c Log Message: extra args len now respected Index: getopts.c =================================================================== RCS file: /cvsroot/cup-language/cup/src/common/getopts.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** getopts.c 2 Aug 2002 15:50:44 -0000 1.2 --- getopts.c 2 Aug 2002 20:25:58 -0000 1.3 *************** *** 31,37 **** if (arg[0] != '-' || endofopts) { ! if (exargs[0]) ! strcat(exargs, " "); ! strcat(exargs, arg); continue; } --- 31,45 ---- if (arg[0] != '-' || endofopts) { ! if (exargslen - (strlen(exargs) + 1) > 1 + strlen(arg)) ! { ! if (exargs[0]) ! strcat(exargs, " "); ! strcat(exargs, arg); ! } ! else ! { ! fprintf(stderr, "%s: not enough memory for extra arguments\n", argv[0]); ! return 0; ! } continue; } *************** *** 59,65 **** if (!o || *(o->gotit)) { ! if (exargs[0]) ! strcat(exargs, " "); ! strcat(exargs, arg); break; } --- 67,81 ---- if (!o || *(o->gotit)) { ! if (exargslen - (strlen(exargs) + 1) > 1 + strlen(arg)) ! { ! if (exargs[0]) ! strcat(exargs, " "); ! strcat(exargs, arg); ! } ! else ! { ! fprintf(stderr, "%s: not enough memory for extra arguments\n", argv[0]); ! return 0; ! } break; } *************** *** 98,104 **** else /* just a '-' */ { ! if (exargs[0]) ! strcat(exargs, " "); ! strcat(exargs, "-"); } } --- 114,128 ---- else /* just a '-' */ { ! if (exargslen - (strlen(exargs) + 1) > 1 + 1) ! { ! if (exargs[0]) ! strcat(exargs, " "); ! strcat(exargs, "-"); ! } ! else ! { ! fprintf(stderr, "%s: not enough memory for extra arguments\n", argv[0]); ! return 0; ! } } } |