mirror of
https://github.com/zeroflag/fcl.git
synced 2025-01-11 20:01:10 +01:00
temp lookup words are no longer inlined but compiled to a temp scratch area
This commit is contained in:
parent
36449eff35
commit
feeec2952c
2 changed files with 12 additions and 2 deletions
|
@ -384,6 +384,7 @@ public class Fcl {
|
||||||
addPrimitive("false", () -> stack.push(Bool.FALSE));
|
addPrimitive("false", () -> stack.push(Bool.FALSE));
|
||||||
addPrimitive("nil", () -> stack.push(Nil.INSTANCE));
|
addPrimitive("nil", () -> stack.push(Nil.INSTANCE));
|
||||||
addPrimitive("here", () -> stack.push(new Num(dp)));
|
addPrimitive("here", () -> stack.push(new Num(dp)));
|
||||||
|
addPrimitive("dp!", () -> dp = stack.pop().intValue() );
|
||||||
addPrimitive("interpret", () -> mode = Mode.INTERPRET);
|
addPrimitive("interpret", () -> mode = Mode.INTERPRET);
|
||||||
addPrimitive("trace", () -> trace = stack.pop().boolValue());
|
addPrimitive("trace", () -> trace = stack.pop().boolValue());
|
||||||
addPrimitive("lit", () -> stack.push((Obj)heap[ip++]));
|
addPrimitive("lit", () -> stack.push((Obj)heap[ip++]));
|
||||||
|
|
|
@ -17,12 +17,17 @@ var: psp ( top of the parameter stack, each allocation ad
|
||||||
var: qpsp ( parameter stack pointer used by quotations )
|
var: qpsp ( parameter stack pointer used by quotations )
|
||||||
var: frame.allocated ( compile time variable for checking if a frame was already allocated )
|
var: frame.allocated ( compile time variable for checking if a frame was already allocated )
|
||||||
var: q.count ( compile time counter for quotations, nested into each other )
|
var: q.count ( compile time counter for quotations, nested into each other )
|
||||||
|
var: ldp
|
||||||
|
|
||||||
|
6 val: look-word-size ( compiled size of one lookup word )
|
||||||
8 val: max#loc ( maximum number of local variables per word )
|
8 val: max#loc ( maximum number of local variables per word )
|
||||||
1024 val: ps.size ( max pstack size )
|
1024 val: ps.size ( max pstack size )
|
||||||
ps.size allot val: pstack ( parameter stack for storing the locals )
|
ps.size allot val: pstack ( parameter stack for storing the locals )
|
||||||
max#loc allot val: names ( names of the local variables )
|
max#loc allot val: names ( names of the local variables )
|
||||||
|
|
||||||
|
max#loc look-word-size *
|
||||||
|
allot val: scratch ( scratch area for compiling temporary lookup words )
|
||||||
|
|
||||||
0 q.count !
|
0 q.count !
|
||||||
false frame.allocated !
|
false frame.allocated !
|
||||||
|
|
||||||
|
@ -68,19 +73,23 @@ false frame.allocated !
|
||||||
frame.allocated @ not if ( is this the first local? )
|
frame.allocated @ not if ( is this the first local? )
|
||||||
true frame.allocated !
|
true frame.allocated !
|
||||||
['] frame.alloc , ( alloc new stack frame for max#loc )
|
['] frame.alloc , ( alloc new stack frame for max#loc )
|
||||||
|
scratch ldp !
|
||||||
then
|
then
|
||||||
(frame.top)
|
(frame.top)
|
||||||
['] lit , #loc @ , ( local index )
|
['] lit , #loc @ , ( local index )
|
||||||
['] - , ['] ! , ( move local to from data stack to the stack frame )
|
['] - , ['] ! , ( move local to from data stack to the stack frame )
|
||||||
['] jmp , (dummy) ( bypass the lookup word )
|
here ( save this dp and restore it after the lookup word is compiled to the scratch area )
|
||||||
word dup >names ( store lookup word name )
|
word dup >names ( store lookup word name )
|
||||||
|
ldp @ dp! ( set dp to scratch area )
|
||||||
create postpone: immediate ( compile immediate lookup word )
|
create postpone: immediate ( compile immediate lookup word )
|
||||||
['] lit , swap , ( type 1=val 0=var )
|
['] lit , swap , ( type 1=val 0=var )
|
||||||
['] lit , #loc @ , ( local index within the frame )
|
['] lit , #loc @ , ( local index within the frame )
|
||||||
['] lookup ,
|
['] lookup ,
|
||||||
['] exit ,
|
['] exit ,
|
||||||
|
here ldp @ - look-word-size != if 'Invalid lookup word size' abort then
|
||||||
#loc inc
|
#loc inc
|
||||||
resolve ;
|
here ldp !
|
||||||
|
dp! ;
|
||||||
|
|
||||||
: -> immediate 1 local ;
|
: -> immediate 1 local ;
|
||||||
: => immediate 0 local ;
|
: => immediate 0 local ;
|
||||||
|
|
Loading…
Reference in a new issue