|
From: <ppr...@us...> - 2003-11-17 06:18:53
|
Update of /cvsroot/forthy/forthy
In directory sc8-pr-cvs1:/tmp/cvs-serv26139
Modified Files:
fcode.c fcode.h fstack.c fsystem.c fsystem.h ftype.h fvalue.c
main.c
Added Files:
test.txt
Log Message:
- null value deref bux fix
- script loading function added to main
- external test script
- changed code table layout in preperation for decompile
--- NEW FILE: test.txt ---
8 voc.new
: also
0 voc.pick voc.push
;
: definitions
voc.depth if 0 voc.pick current! else current.clear then
;
: vocabulary
variable last last >data ! does> voc.depth if voc.pop drop then
@ voc.push
;
: order
"CONTEXT: " . voc.depth dup for dup i - voc.pick name . next cr
"CURRENT: " . current@ dup datatype if name . else drop then cr drop
;
: voc.path ( word -- )
"/" begin over >voc datatype while ( word str )
over >voc name swap cat ( word str )
swap >voc swap "/" swap cat ( word str )
repeat swap drop
;
: which
' dup voc.path swap name cat .
;
: } voc.pop drop
voc.depth if
voc.pop dup current! voc.push
else current.clear
then ; immediate
: namespace 32 word
"{" cat ncreate last last >data ! immediate
does> @ dup voc.push current! ;
: maze
[ 80 50 * ] literal
for rand 2 % if
[ char \ ] literal emit
else
[ char / ] literal emit
then next cr ;
Index: fcode.c
===================================================================
RCS file: /cvsroot/forthy/forthy/fcode.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** fcode.c 16 Nov 2003 16:45:06 -0000 1.4
--- fcode.c 17 Nov 2003 06:18:00 -0000 1.5
***************
*** 33,38 ****
void code_enter(FSYSTEM *sys);
void code_exit(FSYSTEM *sys);
- void code_exit_all(FSYSTEM *sys);
void code_exit_inner(FSYSTEM *sys);
--- 33,38 ----
void code_enter(FSYSTEM *sys);
+ void code_exit_fast(FSYSTEM *sys);
void code_exit(FSYSTEM *sys);
void code_exit_inner(FSYSTEM *sys);
***************
*** 43,47 ****
void code_branch(FSYSTEM *sys);
! void code_branch_ne(FSYSTEM *sys);
void code_for(FSYSTEM *sys);
--- 43,47 ----
void code_branch(FSYSTEM *sys);
! void code_branch_z(FSYSTEM *sys);
void code_for(FSYSTEM *sys);
***************
*** 59,62 ****
--- 59,86 ----
//void code_compile(FSYSTEM *sys);
+ FOPCODE code_table[]=
+ {
+ {code_exit_inner, "EXIT_INNER"},
+ {code_docon, "DO_CON"},
+ {code_dovar, "DO_VAR"},
+ {code_enter, "ENTER"},
+ {code_exit_fast, "EXIT_FAST"},
+ {code_exit, "EXIT"},
+ {code_lit_int, "LIT_INT"},
+ {code_lit_float, "LIT_FLOAT"},
+ {code_lit_string, "LIT_STRING"},
+ {code_lit_wordref, "LIT_WORD"},
+ {code_branch, "BRANCH"},
+ {code_branch_z, "BRANCH_Z"},
+ {code_for, "FOR"},
+ {code_next, "NEXT"},
+ {code_break, "BREAK"},
+ {code_compile, "COMPILE"},
+ {code_does, "DOES"},
+ {code_dodoes, "DO_DOES"},
+ {code_dodefer, "DO_DEFER"},
+ };
+
+ /*
FCFUNC code_table[]=
{
***************
*** 81,85 ****
code_dodefer,
};
!
void code_lit_int(FSYSTEM *sys)
--- 105,109 ----
code_dodefer,
};
! */
void code_lit_int(FSYSTEM *sys)
***************
*** 193,197 ****
! void code_exit(FSYSTEM *sys)
{
FVALUE *value;
--- 217,221 ----
! void code_exit_fast(FSYSTEM *sys)
{
FVALUE *value;
***************
*** 213,220 ****
! void code_branch_ne(FSYSTEM *sys)
{
! if(!stack_depth(sys->stack))
! VOID_THROW(sys, FS_UNDERFLOW);
// FALSE, so branch
--- 237,244 ----
! void code_branch_z(FSYSTEM *sys)
{
! // if(!stack_depth(sys->stack))
! // VOID_THROW(sys, FS_UNDERFLOW);
// FALSE, so branch
***************
*** 238,243 ****
// OPTIMIZE:
! if(!fs_depth(sys))
! VOID_THROW(sys, FS_UNDERFLOW);
count=fs_get_int(sys, -1);
--- 262,267 ----
// OPTIMIZE:
! // if(!fs_depth(sys))
! // VOID_THROW(sys, FS_UNDERFLOW);
count=fs_get_int(sys, -1);
***************
*** 331,335 ****
// Exit the current word
! code_exit(sys);
}
--- 355,359 ----
// Exit the current word
! code_exit_fast(sys);
}
***************
*** 361,365 ****
// Special exit that drops control-flow data and returns immediately
! void code_exit_all(FSYSTEM *sys)
{
// While there are non-FXTOKENs (control-flow) on the stack
--- 385,389 ----
// Special exit that drops control-flow data and returns immediately
! void code_exit(FSYSTEM *sys)
{
// While there are non-FXTOKENs (control-flow) on the stack
***************
*** 375,379 ****
}
! code_exit(sys);
}
--- 399,403 ----
}
! code_exit_fast(sys);
}
Index: fcode.h
===================================================================
RCS file: /cvsroot/forthy/forthy/fcode.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** fcode.h 16 Nov 2003 16:54:54 -0000 1.3
--- fcode.h 17 Nov 2003 06:18:00 -0000 1.4
***************
*** 5,10 ****
! #define OPCODE(code) (&code_table[(code)])
! #define OPFUNC(code) (code_table[(code)])
enum{OP_EXIT_INNER, OP_DOCON, OP_DOVAR, OP_ENTER, OP_EXIT, OP_EXIT_ALL,
--- 5,10 ----
! #define OPCODE(code) (&code_table[(code)].exec)
! #define OPFUNC(code) (code_table[(code)].exec)
enum{OP_EXIT_INNER, OP_DOCON, OP_DOVAR, OP_ENTER, OP_EXIT, OP_EXIT_ALL,
***************
*** 17,21 ****
// - (DO) (?DO) (+LOOP) (LOOP) (LEAVE)
! extern FCFUNC code_table[];
#endif
--- 17,22 ----
// - (DO) (?DO) (+LOOP) (LOOP) (LEAVE)
! //extern FCFUNC code_table[];
! extern FOPCODE code_table[];
#endif
Index: fstack.c
===================================================================
RCS file: /cvsroot/forthy/forthy/fstack.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** fstack.c 16 Nov 2003 16:24:58 -0000 1.3
--- fstack.c 17 Nov 2003 06:18:00 -0000 1.4
***************
*** 285,288 ****
--- 285,291 ----
value=stack_get_deref(sys, stack, offset);
+ if(!value)
+ VOID_THROW(sys, FS_BAD_REF);
+
stack_push_value(sys, stack, value);
}
Index: fsystem.c
===================================================================
RCS file: /cvsroot/forthy/forthy/fsystem.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** fsystem.c 16 Nov 2003 16:45:06 -0000 1.6
--- fsystem.c 17 Nov 2003 06:18:00 -0000 1.7
***************
*** 180,183 ****
--- 180,184 ----
sys->temp_str=NULL;
sys->result_str=NULL;
+ sys->result=FS_OK;
sys->in_source=NULL;
***************
*** 1497,1501 ****
{
if(!handle)
! return FS_NULL;
// Dump return stack
--- 1498,1502 ----
{
if(!handle)
! INT_THROW(sys, FS_NULL);
// Dump return stack
***************
*** 1677,1680 ****
--- 1678,1683 ----
int fs_throw_it(FSYSTEM *sys, int value)
{
+ sys->result=value;
+
if(!value)
return FS_OK;
Index: fsystem.h
===================================================================
RCS file: /cvsroot/forthy/forthy/fsystem.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** fsystem.h 16 Nov 2003 16:24:58 -0000 1.5
--- fsystem.h 17 Nov 2003 06:18:00 -0000 1.6
***************
*** 40,43 ****
--- 40,44 ----
char *temp_str; // last read string value
char *result_str; // last requested error string value
+ int result; // last thrown result
FCFUNC vm_inner; // Which inner loop we're using
Index: ftype.h
===================================================================
RCS file: /cvsroot/forthy/forthy/ftype.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ftype.h 20 Oct 2003 00:26:41 -0000 1.2
--- ftype.h 17 Nov 2003 06:18:00 -0000 1.3
***************
*** 50,53 ****
--- 50,54 ----
typedef struct FVALUE FVALUE;
typedef struct FSYMREC FSYMREC;
+ typedef struct FOPCODE FOPCODE;
typedef struct FSTACK FSTACK;
typedef struct FREFCOUNT FREFCOUNT;
***************
*** 143,150 ****
--- 144,158 ----
};
+ struct FOPCODE
+ {
+ FCFUNC exec; // Code Field
+ char *name; // Name Field
+ };
+
// Execution token union
union FTOKEN
{
FCFUNC func;
+ FOPCODE code;
FSYMREC rec;
};
Index: fvalue.c
===================================================================
RCS file: /cvsroot/forthy/forthy/fvalue.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** fvalue.c 16 Nov 2003 16:45:06 -0000 1.4
--- fvalue.c 17 Nov 2003 06:18:00 -0000 1.5
***************
*** 482,485 ****
--- 482,488 ----
return atoi(value->value.str);
break;
+
+ default:
+ break;
}
***************
*** 503,506 ****
--- 506,512 ----
return (double)atof(value->value.str);
break;
+
+ default:
+ break;
}
***************
*** 536,539 ****
--- 542,548 ----
break;
}
+
+ default:
+ break;
}
Index: main.c
===================================================================
RCS file: /cvsroot/forthy/forthy/main.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** main.c 16 Nov 2003 16:45:06 -0000 1.10
--- main.c 17 Nov 2003 06:18:00 -0000 1.11
***************
*** 18,21 ****
--- 18,22 ----
}
+
void fortify_output(const char *text)
{
***************
*** 29,32 ****
--- 30,59 ----
+ char *load_text(char *filename)
+ {
+ FILE *fp;
+ char *text;
+ int size;
+
+ fp=fopen(filename, "rb");
+
+ if(!fp)
+ return NULL;
+
+ fseek(fp, 0, SEEK_END);
+ size=ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ text=malloc(size+1);
+
+ fread(text, size, 1, fp);
+ fclose(fp);
+
+ text[size]=0;
+
+ return text;
+ }
+
+
void show_stack(FSYSTEM *sys)
{
***************
*** 1455,1460 ****
int load(FSYSTEM *sys)
{
- int i=0;
-
fs_register_func(sys, "*", word_mul, FS_DEFAULT);
fs_register_func(sys, "+", word_add, FS_DEFAULT);
--- 1482,1485 ----
***************
*** 1604,1607 ****
--- 1629,1633 ----
+ /*
char *script=
{
***************
*** 1630,1634 ****
": which ' dup voc.path swap name cat . ; "
};
!
void word_root_1(FSYSTEM *sys)
--- 1656,1660 ----
": which ' dup voc.path swap name cat . ; "
};
! */
void word_root_1(FSYSTEM *sys)
***************
*** 1690,1696 ****
int i;
- fs_load_string(sys, script);
- fs_run(sys);
-
fs_load_string(sys, ": test 1 2 3 ; : test2 test swap drop dup + - . ; ");
fs_run(sys);
--- 1716,1719 ----
***************
*** 1783,1786 ****
--- 1806,1824 ----
+ void load_script(FSYSTEM *sys, char *filename)
+ {
+ char *script;
+
+ script=load_text(filename);
+
+ if(!script)
+ return;
+
+ fs_load_string(sys, script);
+ fs_run(sys);
+ free(script);
+ }
+
+
int main()
{
***************
*** 1818,1821 ****
--- 1856,1862 ----
load(&sys);
+
+ load_script(&sys, "test.txt");
+
#ifdef _DEBUG
test(&sys);
***************
*** 1846,1852 ****
printf("@ ");
! while(1)
{
! ch=getchar();
if(ch==EOF)
{
--- 1887,1893 ----
printf("@ ");
! for(;;)
{
! ch=(char)getchar();
if(ch==EOF)
{
|