Skip to content

Commit

Permalink
Better compilation of code words (no need to use LIT-EXECUTE for them)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton committed May 2, 2010
1 parent 243c4fe commit a85cf14
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
24 changes: 22 additions & 2 deletions abi-code-test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end-code

: my-constant ( w "name" -- )
create ,
;abi-code ( -- w )
;abi-code ( -- w )
\ sp in di, address of fp in si, body address in dx
-8 di d) ax lea \ compute new sp in result reg
dx ) cx mov \ load w
Expand All @@ -45,7 +45,7 @@ foo-compiled 5 <> throw

: my-constant2 ( w "name" -- )
create ,
;code ( -- w )
;code ( -- w )
\ sp=r15, tos=r14, ip=bx
8 # bx add
r14 r15 ) mov
Expand All @@ -56,3 +56,23 @@ end-code

7 my-constant2 bar
: bar-compiled bar ;

bar 7 <> throw
bar-compiled 7 <> throw

code my-1+ ( n1 -- n2 )
8 # bx add
r14 inc
-8 bx d) jmp
end-code

: compiled-my-1+
my-1+ ;

7 my-1+ 8 <> throw
8 compiled-my-1+ 9 <> throw

: funny-compiler-test
drop my-1+ 1 ;

\ 6 9 funny-compiler-test 1 <> throw 7 <> throw
6 changes: 3 additions & 3 deletions engine/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1832,9 +1832,6 @@ void compile_prim1(Cell *start)
#elif defined(INDIRECT_THREADED)
return;
#else /* !(defined(DOUBLY_INDIRECT) || defined(INDIRECT_THREADED)) */
/* !! does not work, for unknown reasons; but something like this is
probably needed to ensure that we don't call compile_prim_dyn
before the inline arguments are there */
static Cell *instps[MAX_BB];
static PrimNum origs[MAX_BB];
static int ninsts=0;
Expand All @@ -1853,9 +1850,12 @@ void compile_prim1(Cell *start)
}
prim_num = ((Xt)*start)-vm_prims;
if(prim_num >= npriminfos) {
/* code word */
optimize_rewrite(instps,origs,ninsts);
/* fprintf(stderr,"optimize_rewrite(...,%d)\n",ninsts);*/
ninsts=0;
append_jump();
*start = *(Cell *)*start;
return;
}
assert(ninsts<MAX_BB);
Expand Down
8 changes: 6 additions & 2 deletions kernel/comp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ has? primcentric [IF]
do;abicode: OF ['] ;abi-code-exec peephole-compile, , EXIT ENDOF
\ code words and ;code-defined words (code words could be
\ optimized, if we could identify them):
dup in-dictionary? IF
drop ['] lit-execute peephole-compile, , EXIT
dup in-dictionary? IF ( xt code-address )
over >body = if ( xt )
\ definitely a CODE word
peephole-compile, EXIT THEN
\ not sure, might be a ;CODE word
['] lit-execute peephole-compile, , EXIT
\ drop POSTPONE literal ['] execute peephole-compile, EXIT
THEN
ENDCASE
Expand Down

0 comments on commit a85cf14

Please sign in to comment.