/* ***************************************************************** * * * SB-Prolog * * Copyright SUNY at Stony Brook, 1986 * * * ****************************************************************** */ /*----------------------------------------------------------------- SB-Prolog is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the SB-Prolog General Public License for full details. Everyone is granted permission to copy, modify and redistribute SB-Prolog, but only under the conditions described in the SB-Prolog General Public License. A copy of this license is supposed to have been given to you along with SB-Prolog so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. ------------------------------------------------------------------ */ /* begin asmpass21.P ****************************************/ /* ********************************************************************** $asmpass21_export([$asm_p2/3,$asm_p4/3,$asm_lookup0/3,$asm_lookup/3]). $asmpass21_use($aux1,[_,_,_,_,$umsg/1,_,_,_,_]). $asmpass21_use($listutil1,[_,_,_,_,_,$nthmember1/3,_,_]). ********************************************************************** */ /* pass2 takes as input a program containing symbolic labels, structure symbols and constants and the symbol tables and returns a program in which all symbols have been replaced by their byte code offsets of PSC indices. Also, for "internal" predicates, i.e. those which are not exported, static linking is carried out as far as possible. */ $asm_p2(getcon(Con,R), getcon(I,R), Csym) :- $asm_lookup((Con, 0, _), Csym, I). $asm_p2(getstr((Str,Arity), R),getstr(I,R),Csym):- $asm_lookup((Str,Arity,_), Csym, I). $asm_p2(getstrv((Str,Arity), R),getstrv(I,R),Csym) :- $asm_lookup((Str,Arity,_), Csym, I). $asm_p2(unicon(Con), unicon(I), Csym) :- $asm_lookup((Con,0,_), Csym, I). $asm_p2(putcon(Con,R), putcon(I,R), Csym) :- $asm_lookup((Con,0,_), Csym, I). $asm_p2(putstr((Str,Arity), R),putstr(I,R),Csym) :- $asm_lookup((Str,Arity,_), Csym, I). $asm_p2(putstrv((Str,Arity), R),putstrv(I,R),Csym):- $asm_lookup((Str,Arity,_), Csym, I). $asm_p2(bldcon(Con),bldcon(I),Csym) :- $asm_lookup((Con,0,_), Csym, I). $asm_p2(call((Pname, Arity), B), call(I,B), Csym) :- $asm_lookup((Pname, Arity, _), Csym, I). $asm_p2(execute((Pname, Arity)), execute(I), Csym) :- $asm_lookup((Pname, Arity, _), Csym, I). $asm_p4(trymeelse(L, A), trymeelse(Val,A), Lsym) :- $asm_lookup((L, Val), Lsym, _). $asm_p4(retrymeelse(L, A), retrymeelse(Val,A), Lsym) :- $asm_lookup((L, Val), Lsym, _). $asm_p4(try(L, A), try(Val,A), Lsym) :- $asm_lookup((L, Val), Lsym, _). $asm_p4(retry(L, A), retry(Val,A), Lsym) :- $asm_lookup((L, Val), Lsym, _). $asm_p4(trust(L, A), trust(Val,A), Lsym) :- $asm_lookup((L, Val), Lsym, _). $asm_p4(jump(L), jump(Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(jumpz(R, L), jumpz(R,Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(jumpnz(R, L), jumpnz(R,Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(jumplt(R, L), jumplt(R,Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(jumple(R, L), jumple(R,Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(jumpgt(R, L), jumpgt(R,Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(jumpge(R, L), jumpge(R,Val), Lsym) :- $asm_lookup((L, Val),Lsym,_). $asm_p4(switchonterm(R, L1, L2), switchonterm(R,Val1,Val2), Lsym) :- $asm_lookup((L1, Val1), Lsym, _), $asm_lookup((L2, Val2), Lsym, _). $asm_p4(switchoncon(L), switchoncon(Val), Lsym) :- $asm_lookup((L,Val),Lsym,_). $asm_p4(switchonstr(L), switchonstr(Val), Lsym) :- $asm_lookup((L,Val),Lsym, _). /* "$asm_lookup0" is the same as "$asm_lookup", except that it doesn't give an error message if $asm_lookup fails, but simply fails quietly. */ $asm_lookup0( ( abs(Value), Value ), _, _). $asm_lookup0( Symbol, Symtab, Index ) :- $nthmember1( Symbol, Symtab, Index). $asm_lookup(Symbol,Symtab,Index) :- $asm_lookup0(Symbol,Symtab,Index). $asm_lookup(Symbol, _, _) :- $umsg(['error on lookup in pass2: ',Symbol,'... aborting execution']), abort. /* end asmpass21.P ***************************************************/