variable support cleanup

This commit is contained in:
FeralChild64 committed 2020-07-19 08:54:53 +02:00
1 parent 51aec45c8d
commit 09f85cea8a
64 files changed
+266 -87

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@
cmd_input,
cmd_dim,
cmd_read,
cmd_let,
assign_variable, // cmd_let
cmd_goto,
cmd_run,
cmd_if,
+14 -8
View File
@@ -36,13 +36,18 @@ oper_add_strings:
pla
sta __FAC2+0
beq oper_add_strings_end // if string 2 is empty, we have nothing to do
// If string 2 is empty, release it and quit
beq oper_add_strings_end
// If string 1 is empty, just copy the metadata
lda __FAC1+0
bne !+
jsr tmpstr_free_FAC1
lda __FAC2+0
sta __FAC1+0
lda __FAC2+1
@@ -88,7 +93,7 @@ oper_add_strings:
// Increase INDEX pointer by the size of the 1st string
tya
jsr varstr_INDEX_up_A
jsr helper_INDEX_up_A
// Copy data from the second string
@@ -104,7 +109,7 @@ oper_add_strings:
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
jsr helper_add_concat
jsr helper_strconcat
#else // CONFIG_MEMORY_MODEL_38K
@@ -121,7 +126,7 @@ oper_add_strings:
// Increase INDEX pointer by the size of the 1st string
tya
jsr varstr_INDEX_up_A
jsr helper_INDEX_up_A
// Copy data from the second string
@@ -135,11 +140,9 @@ oper_add_strings:
#endif
// Free old strings - if they are temporary
// Free old FAC1 string - if it was temporary
// XXX
// XXX
// XXX
jsr tmpstr_free_FAC1
// Copy the descriptor to __FAC1
@@ -150,6 +153,9 @@ oper_add_strings:
dey
bpl !-
// FALLTROUGH
oper_add_strings_end:
jsr tmpstr_free_FAC2
jmp FRMEVL_continue
-10
View File
@@ -1,10 +0,0 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
tmpstr_free_all:
// XXX implement this
rts
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -250,4 +250,4 @@ execute_statements_var_assign:
#else
dew TXTPTR
#endif
jmp cmd_let
jmp assign_variable
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -3,8 +3,7 @@
// #LAYOUT# * * #IGNORE
cmd_let:
assign_variable:
// Fetch variable name, should be followed by assign operator
@@ -62,14 +61,14 @@ cmd_let:
// Determine what to assign
pla
bmi cmd_let_assign_string
beq cmd_let_assign_float
bmi assign_string
beq assign_float
// FALLTROUGH
// XXX integer and float probably have much in common
cmd_let_assign_integer:
assign_integer:
lda VALTYP
bmi_16 do_TYPE_MISMATCH_error
@@ -97,7 +96,7 @@ cmd_let_assign_integer:
jmp do_NOT_IMPLEMENTED_error
cmd_let_assign_float:
assign_float:
lda VALTYP
bmi_16 do_TYPE_MISMATCH_error
@@ -125,7 +124,7 @@ cmd_let_assign_float:
jmp do_NOT_IMPLEMENTED_error
cmd_let_assign_string:
assign_string:
// Check if value type matches
@@ -134,12 +133,12 @@ cmd_let_assign_string:
// Copy the string descriptor to DSCPNT
jsr helper_let_strdesccpy
jsr helper_strdesccpy
// First special case - check if the new string has size 0
lda __FAC1+0
bne cmd_let_assign_string_not_empty
bne assign_string_not_empty
// Yes, it is empty - free the old one
@@ -159,41 +158,41 @@ cmd_let_assign_string:
rts
cmd_let_assign_string_not_empty:
assign_string_not_empty:
// Check if the source and destination strings are the same
lda DSCPNT+1
cmp __FAC1+1
bne cmd_let_assign_string_not_same
bne assign_string_not_same
iny
lda DSCPNT+2
cmp __FAC1+2
bne cmd_let_assign_string_not_same
bne assign_string_not_same
// If we are here, than both source and destination strings are the same - nothing more to be done
rts
cmd_let_assign_string_not_same:
assign_string_not_same:
// Strings are not the same - check if the new one is located within the text area, between TXTTAB and VARTAB
lda VARTAB+1
cmp __FAC1+2
bcc cmd_let_assign_string_not_text_area
bcc assign_string_not_text_area
bne !+
lda VARTAB+0
cmp __FAC1+1
bcc cmd_let_assign_string_not_text_area
bcc assign_string_not_text_area
!:
lda __FAC1+2
cmp TXTTAB+1
bcc cmd_let_assign_string_not_text_area
bcc assign_string_not_text_area
bne !+
lda __FAC1+1
cmp TXTTAB+0
bcc cmd_let_assign_string_not_text_area
bcc assign_string_not_text_area
!:
// String is located within text area - great, just copy the descriptor
@@ -227,7 +226,7 @@ cmd_let_assign_string_not_same:
rts
cmd_let_assign_string_not_text_area:
assign_string_not_text_area:
// Check if the new string is a temporary one - if so, reuse alocation
@@ -235,12 +234,12 @@ cmd_let_assign_string_not_text_area:
// Check if the old string belongs to the string area (is above FRETOP)
jsr varstr_cmp_fretop
bcc cmd_let_assign_string_no_optimizations
jsr helper_cmp_fretop
bcc assign_string_no_optimizations
// FALLTROUGH
cmd_let_assign_string_try_reuse:
assign_string_try_reuse:
// Check if we can reuse old string memory
@@ -249,9 +248,9 @@ cmd_let_assign_string_try_reuse:
// If size of both string equals - simply reuse it
beq_16 helper_let_strvarcpy
beq_16 helper_strvarcpy
cmd_let_assign_string_try_reuse_unsuccesful:
assign_string_try_reuse_unsuccesful:
// No special case optimization is possible - but first get rid of the old string
@@ -259,7 +258,7 @@ cmd_let_assign_string_try_reuse_unsuccesful:
// FALLTROUGH
cmd_let_assign_string_no_optimizations:
assign_string_no_optimizations:
// Allocate memory for the new string
@@ -281,4 +280,4 @@ cmd_let_assign_string_no_optimizations:
// Copy the string and quit
jmp helper_let_strvarcpy
jmp helper_strvarcpy
@@ -11,7 +11,7 @@ fetch_variable_TI_string:
lda #$06
jsr tmpstr_alloc
jsr helper_let_strdesccpy
jsr helper_strdesccpy
// Fetch the time in a safe way, store it in temporary area
@@ -10,7 +10,7 @@
// - Carry flag set - this string belongs to the string area
varstr_cmp_fretop:
helper_cmp_fretop:
lda DSCPNT+2
cmp FRETOP+1
@@ -3,10 +3,10 @@
// #LAYOUT# * * #IGNORE
//
// Helper routines for 'varstr_alloc'
// Helper routines for FRETOP handling
//
varstr_FRETOP_down_A: // .A - bytes to lower FRETOP, uses DSCPNT+0
helper_FRETOP_down_A: // .A - bytes to lower FRETOP, uses DSCPNT+0
sta DSCPNT+0
@@ -19,7 +19,7 @@ varstr_FRETOP_down_A: // .A - bytes to lower FRETOP, uses DSCPN
!:
// FALLTROUGH
varstr_FRETOP_check: // check if FRETOP > STREND, Carry set if not
helper_FRETOP_check: // check if FRETOP > STREND, Carry set if not
lda STREND+1
cmp FRETOP+1
@@ -3,11 +3,11 @@
// #LAYOUT# * * #IGNORE
//
// Helper routines for 'varstr_free'
// Helper routine for FRETOP handling
//
varstr_FRETOP_up: // DSCPNT+0 - bytes to increment FRETO
helper_FRETOP_up: // DSCPNT+0 - bytes to increment FRETO
clc
lda FRETOP+0
@@ -0,0 +1,24 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine, used by garbage collector and string concatenation
//
#if CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_60K
helper_INDEX_up_A: // .A - bytes to increase TXTPTR, uses DSCPNT+0
sta DSCPNT+0
clc
lda INDEX+0
adc DSCPNT+0
sta INDEX+0
bcc !+
dec INDEX+1
!:
rts
#endif
@@ -8,8 +8,9 @@
// Helper routine, used by garbage collector and string concatenation
//
#if CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
varstr_INDEX_up_A: // .A - bytes to increase TXTPTR, uses DSCPNT+0
helper_INDEX_up_A: // .A - bytes to increase TXTPTR, uses DSCPNT+0
sta DSCPNT+0
@@ -21,3 +22,5 @@ varstr_INDEX_up_A: // .A - bytes to increase TXTPTR, uses DS
dec INDEX+1
!:
rts
#endif
@@ -11,7 +11,7 @@
#if CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
helper_add_concat:
helper_strconcat:
// Unmap BASIC lower ROM
@@ -31,7 +31,7 @@ helper_add_concat:
// Increase INDEX pointer by the size of the 1st string
tya
jsr varstr_INDEX_up_A
jsr helper_INDEX_up_A
// Copy data from the second string
@@ -3,13 +3,13 @@
// #LAYOUT# * * #IGNORE
//
// Helper routine to copy string descriptor, for LET command and TI$ variable support
// Helper routine to copy string descriptor
//
#if CONFIG_MEMORY_MODEL_38K
helper_let_strdesccpy:
helper_strdesccpy:
ldy #$00
lda (VARPNT), y
@@ -5,13 +5,13 @@
// This has to go $E000 or above - routines below banks out the main BASIC ROM!
//
// Helper routine to copy string descriptor, for LET command and TI$ variable support
// Helper routine to copy string descriptor
//
#if CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
helper_let_strdesccpy:
helper_strdesccpy:
// Unmap BASIC lower ROM
@@ -3,13 +3,13 @@
// #LAYOUT# * * #IGNORE
//
// Helper routine to copy string descriptor, for LET command and TI$ variable support
// Helper routine to copy string descriptor
//
#if CONFIG_MEMORY_MODEL_60K
helper_let_strdesccpy:
helper_strdesccpy:
ldx #<VARPNT
@@ -3,13 +3,13 @@
// #LAYOUT# * * #IGNORE
//
// Helper routine to copy string descriptor, for LET command
// Helper routine to copy string descriptor
//
#if CONFIG_MEMORY_MODEL_38K
helper_let_strvarcpy:
helper_strvarcpy:
// Retrieve pointer to destination
@@ -5,13 +5,13 @@
// This has to go $E000 or above - routines below banks out the main BASIC ROM!
//
// Helper routine to copy string variable content, for LET command
// Helper routine to copy string variable content
//
#if CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
helper_let_strvarcpy:
helper_strvarcpy:
// Unmap BASIC lower ROM
@@ -3,13 +3,13 @@
// #LAYOUT# * * #IGNORE
//
// Helper routine to copy string descriptor, for LET command
// Helper routine to copy string descriptor
//
#if CONFIG_MEMORY_MODEL_60K
helper_let_strvarcpy:
helper_strvarcpy:
ldx #<VARPNT
@@ -7,7 +7,7 @@
//
varstr_TXTPTR_down_A: // .A - bytes to decrease TXTPTR, uses DSCPNT+0
helper_TXTPTR_down_A: // .A - bytes to decrease TXTPTR, uses DSCPNT+0
sta DSCPNT+0
@@ -20,7 +20,7 @@ tmpstr_alloc:
lda TEMPPT
cmp #$22
bcs_16 do_FORMULA_TOO_COMPLEX_error
bcs tmpstr_alloc_try_reuse
tay
sta LASTPT
@@ -28,18 +28,43 @@ tmpstr_alloc:
adc #$03
sta TEMPPT
// FALLTROUGH
tmpstr_alloc_found:
// Store desired string length
stx $00, y
// Store descriptor address
lda LASTPT
sta VARPNT+0
sty VARPNT+0
lda #$00
sta VARPNT+1
// Jump to alocation routine
// XXX consider falltrough
jmp varstr_alloc
tmpstr_alloc_try_reuse:
// It seems there is no space left - try to find empty entry
ldy #$19
// FALLTROUGH
tmpstr_alloc_try_reuse_loop:
lda $00, y
beq tmpstr_alloc_found // branch if free entry found
iny
iny
iny
cpy #$22
bne tmpstr_alloc_try_reuse_loop
// Everything failed - give up
jmp do_FORMULA_TOO_COMPLEX_error
+97
View File
@@ -0,0 +1,97 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Frees the string if it belongs to temporary string stack
//
// Input:
// - DSCPNT+1/+2 - pointer to string (depending on the call addres, can fetch from FAC1/FAC2)
//
tmpstr_free_FAC1:
lda __FAC1+1
sta DSCPNT+1
lda __FAC1+2
#if HAS_OPCODES_65C02
bra !+
#else
jmp !+
#endif
tmpstr_free_FAC2:
lda __FAC2+1
sta DSCPNT+1
lda __FAC2+2
!:
sta DSCPNT+2
// FALLTROUGH
tmpstr_free:
// First find the descriptor matching the given string
ldx #$19
//FALLTROUGH
tmpstr_free_loop:
cpx TEMPPT
bne !+
rts // quit if not found
!:
// First fetch the string size - if 0, do not even try to compare
ldy $00, x
beq tmpstr_free_next_3
// Check if current string
inx
lda $00, x
cmp DSCPNT+1
bne tmpstr_free_next_2
inx
lda $00, x
cmp DSCPNT+2
bne tmpstr_free_next_1
// This is the string we need to free
sty DSCPNT+0
phx_trash_a
jsr varstr_free
plx_trash_a
// Mark empty string as free and quit
dex
dex
lda #$00
sta $00, x
rts
tmpstr_free_next_3:
inx
// FALLTROUGH
tmpstr_free_next_2:
inx
// FALLTROUGH
tmpstr_free_next_1:
inx
bne tmpstr_free_loop
@@ -0,0 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
tmpstr_free_all:
// Go through all the temporary descriptors and free everything
ldx #$19
// XXX implement this
//FALLTROUGH
tmpstr_free_all_loop:
// XXX finish, deduplicate part with CLR
rts
@@ -48,14 +48,14 @@ varstr_alloc_retry:
#if !HAS_OPCODES_65CE02
lda #$02
jsr varstr_FRETOP_down_A
jsr helper_FRETOP_down_A
#else // HAS_OPCODES_65CE02 - this time code is slightly longer, but faster
dew FRETOP
dew FRETOP
jsr varstr_FRETOP_check
jsr helper_FRETOP_check
#endif
@@ -95,7 +95,7 @@ varstr_alloc_retry:
lda (VARPNT),y
#endif
jsr varstr_FRETOP_down_A
jsr helper_FRETOP_down_A
bcs varstr_alloc_fail
// Success - fill in the string descriptor
@@ -20,9 +20,9 @@ varstr_free:
rts
!:
// Check if string is above FRETOP (in string area)
// XXX consider moving this check out of this routine
// XXX move this check out of the routine
jsr varstr_cmp_fretop
jsr helper_cmp_fretop
bcs !+
// No, it does not belong to string area - quit
@@ -36,13 +36,13 @@ varstr_free:
// This is the lowest string - so just increase FRETOP, this way
// the garbage collector will not be needed that quickly
jsr varstr_FRETOP_up // free the string data
jsr helper_FRETOP_up // free the string data
#if !HAS_OPCODES_65CE02
lda #$02 // free the back-pointer
sta DSCPNT+0
jmp varstr_FRETOP_up
jmp helper_FRETOP_up
#else // HAS_OPCODES_65CE02
@@ -79,7 +79,7 @@ varstr_garbage_collect_check_bptr:
#if !HAS_OPCODES_65CE02
lda #$02
jsr varstr_TXTPTR_down_A
jsr helper_TXTPTR_down_A
#else // HAS_OPCODES_65CE02
dew TXTPTR
dew TXTPTR
@@ -271,7 +271,7 @@ varstr_garbage_collect_check_bptr:
lda (OLDTXT),y
#endif
jsr varstr_TXTPTR_down_A
jsr helper_TXTPTR_down_A
// Check if variable descriptor in __FAC1 matches the previously moved string;
// if so - adapt it too
@@ -317,7 +317,7 @@ varstr_garbage_collect_unused:
#if !HAS_OPCODES_65CE02
lda #$01
jsr varstr_TXTPTR_down_A
jsr helper_TXTPTR_down_A
#else // HAS_OPCODES_65CE02
dew TXTPTR
#endif
@@ -338,14 +338,14 @@ varstr_garbage_collect_unused:
// Increase INDEX (shift offset) by string length + back-pointer length
lda #$03
jsr varstr_INDEX_up_A
jsr helper_INDEX_up_A
txa
jsr varstr_INDEX_up_A
jsr helper_INDEX_up_A
// Decrease TXTPTR by unused string length-1
txa
jsr varstr_TXTPTR_down_A
jsr helper_TXTPTR_down_A
// Next iteration