#comment This file is part of Z80 Scheme Interpreter Z80 Scheme Interpreter is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Copyright 2007, Spencer Putt #endcomment #comment "work" is the register used to operate on active strings. It allows a single locations for all utility functions to operate and provides temporary storage for newly read variables It is important to note that all work functions do not modify de, as de usually will have an environment pointer #endcomment ; input ; hl - string to compare with work ; output ; z, strings were equal, nz, nonequal workstrcmp: work_strcmp: push af call work_strcmp_raw pop bc ; preserve the flag ld a,b ret work_strcmp_raw: push de ld de,work wstrcmp_loop: ld a,(de) ld b,a ld a,(hl) add a,b jr z,wstrcmp_equal ;both zero? good sub b jr z,wstrcmp_fail inc b\ dec b jr z,wstrcmp_fail inc de inc hl sub b jr z,wstrcmp_loop wstrcmp_fail: pop de xor a inc a ; reset z ret wstrcmp_equal: cp a ; set z pop de ret ; input ; hl - start of variable or keyword ; output ; hl - beginning of next word (if it exists) workfetch: work_fetch: push de call next_char ld de,work ld bc,work_size wfetch_loop: ld a,(hl) call white_space? jr z,wfetch_done call terminator? jr z,wfetch_done_skip or a jr z,wfetch_done ldi jp pe,wfetch_loop ; expression was too long dec de wfetch_done: inc hl wfetch_done_skip: xor a ld (de),a pop de ret ; input ; none ; output ; hl - fixnum of what was in work worktofixnum: work_to_fixnum: ld de,work ld hl,0 ld a,(de) cp $2D ;- push af jr nz,worktofixnum_loop inc de worktofixnum_loop: ld a,(de) inc de or a jr z,worktofixnum_done push af call hltimes10 pop af sub '0' ld b,0 ld c,a add hl,bc jp worktofixnum_loop worktofixnum_done: pop af call z,neg_hl #ifdef USE_HEAP_FIXNUMS push hl call alloc pop de call set_car!_skip ld a,l or tag_fixnum ; tag it as fixnum ld l,a #else add hl,hl\ add hl,hl #endif ret hltimes10: push hl bcall(_hltimes9) pop bc add hl,bc ret ; input ; work - keyword ; hl - list to search ; output ; z - work is in the list ; nz - work is not in the list ; hl - list member work_in_list?: ld a,(hl) or a jr z,work_in_list?_done push hl call work_strcmp pop hl ret z _ xor a or (hl) inc hl jr nz,-_ jr work_in_list? work_in_list?_done: inc a ret