mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
sub improvements
This commit is contained in:
parent
548f4fc2c6
commit
468c080859
@ -450,6 +450,7 @@ class CodeGenerator:
|
||||
else:
|
||||
raise TypeError("call sub target should be mmapped")
|
||||
if stmt.is_goto:
|
||||
generate_param_assignments()
|
||||
self.p("\t\tjmp " + targetstr)
|
||||
return
|
||||
clobbered = set() # type: Set[str]
|
||||
|
@ -380,6 +380,9 @@ class ParseResult:
|
||||
self._immediate_string_vars[self.right.value] = (cur_block.name, stringvar_name)
|
||||
|
||||
def remove_identity_assigns(self) -> None:
|
||||
for lv in self.leftvalues:
|
||||
if lv == self.right:
|
||||
print("warning: {:d}: removed identity assignment".format(self.lineno))
|
||||
remaining_leftvalues = [lv for lv in self.leftvalues if lv != self.right]
|
||||
self.leftvalues = remaining_leftvalues
|
||||
|
||||
@ -558,7 +561,7 @@ class Parser:
|
||||
if isinstance(stmt, ParseResult.AssignmentStmt):
|
||||
stmt.remove_identity_assigns()
|
||||
if not stmt.leftvalues:
|
||||
print("warning: {:s}:{:d}: removed identity assignment".format(self.sourceref.file, stmt.lineno))
|
||||
print("warning: {:s}:{:d}: removed identity assignment statement".format(self.sourceref.file, stmt.lineno))
|
||||
have_removed_stmts = True
|
||||
block.statements[index] = None
|
||||
if have_removed_stmts:
|
||||
@ -570,9 +573,21 @@ class Parser:
|
||||
self.sourceref.line = stmt.lineno
|
||||
self.sourceref.column = 0
|
||||
stmt.desugar_call_arguments(self)
|
||||
for sub in block.symbols.iter_subroutines():
|
||||
if sub.address is None and sub.sub_block:
|
||||
for stmt in sub.sub_block.statements:
|
||||
if isinstance(stmt, ParseResult.CallStmt):
|
||||
self.sourceref.line = stmt.lineno
|
||||
self.sourceref.column = 0
|
||||
stmt.desugar_call_arguments(self)
|
||||
block.flatten_statement_list()
|
||||
# desugar immediate string value assignments
|
||||
for index, stmt in enumerate(list(block.statements)):
|
||||
if isinstance(stmt, ParseResult.CallStmt):
|
||||
for stmt in stmt.desugared_call_arguments:
|
||||
self.sourceref.line = stmt.lineno
|
||||
self.sourceref.column = 0
|
||||
stmt.desugar_immediate_string(self)
|
||||
if isinstance(stmt, ParseResult.AssignmentStmt):
|
||||
self.sourceref.line = stmt.lineno
|
||||
self.sourceref.column = 0
|
||||
@ -610,6 +625,7 @@ class Parser:
|
||||
self.cur_lineidx = min(self.cur_lineidx, len(self.lines) - 1)
|
||||
if self.cur_lineidx:
|
||||
sourceline = self.lines[self.cur_lineidx][1].strip()
|
||||
# XXX source line is wrong when dealing with errors in sub call
|
||||
return ParseError(message, sourceline, SourceRef(self.sourceref.file, lineno, column))
|
||||
|
||||
def get_datatype(self, typestr: str) -> Tuple[DataType, int, Optional[Tuple[int, int]]]:
|
||||
|
@ -16,18 +16,6 @@ start
|
||||
var .float myfloatsmall1 = 1.234
|
||||
var .float myfloatsmall2 = 2.6677
|
||||
|
||||
c64.MOVFM!(#myfloatsmall1)
|
||||
c64.FCOMP!(#myfloatsmall1)
|
||||
[$0400]=A
|
||||
c64.MOVFM!(#myfloatsmall1)
|
||||
c64.FCOMP!(#myfloatsmall2)
|
||||
[$0401]=A
|
||||
c64.MOVFM!(#myfloatsmall2)
|
||||
c64.FCOMP!(#myfloatsmall1)
|
||||
[$0402]=A
|
||||
|
||||
c64util.FREADS32()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -55,6 +43,14 @@ start
|
||||
var .word wordvar = $cdef
|
||||
|
||||
|
||||
sub printflt (float: AY) -> (A?, X?, Y?) {
|
||||
c64.MOVFM!(AY)
|
||||
goto c64.FPRINTLN!()
|
||||
; c64.FOUT!()
|
||||
; c64util.print_string!(AY)
|
||||
;goto c64.CHROUT!('\n')
|
||||
}
|
||||
|
||||
|
||||
start
|
||||
; assign some float values to the memory
|
||||
@ -65,75 +61,47 @@ start
|
||||
|
||||
; print some floating points from source and compare them with ROM
|
||||
|
||||
c64.MOVFM!(#flt_pi)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_PIVAL)
|
||||
c64.FPRINTLN !()
|
||||
printflt(#flt_pi)
|
||||
printflt(#c64.FL_PIVAL)
|
||||
|
||||
c64.MOVFM!(#flt_minus32768)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_N32768)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_minus32768)
|
||||
printflt(#c64.FL_N32768)
|
||||
|
||||
c64.MOVFM!(#flt_1)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_FONE)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_1)
|
||||
printflt(#c64.FL_FONE)
|
||||
|
||||
c64.MOVFM!(#flt_half_sqr2)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!( # c64.FL_SQRHLF)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_half_sqr2)
|
||||
printflt( # c64.FL_SQRHLF)
|
||||
|
||||
c64.MOVFM!(#flt_sqr2)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_SQRTWO)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_sqr2)
|
||||
printflt(#c64.FL_SQRTWO)
|
||||
|
||||
c64.MOVFM!(#flt_minus_half)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_NEGHLF)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_minus_half)
|
||||
printflt(#c64.FL_NEGHLF)
|
||||
|
||||
c64.MOVFM!(#flt_log_2)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_LOG2)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_log_2)
|
||||
printflt(#c64.FL_LOG2)
|
||||
|
||||
c64.MOVFM!(#flt_10)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_TENC)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_10)
|
||||
printflt(#c64.FL_TENC)
|
||||
|
||||
c64.MOVFM!(#flt_1e9)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_NZMIL)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_1e9)
|
||||
printflt(#c64.FL_NZMIL)
|
||||
|
||||
c64.MOVFM!(#flt_half)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_FHALF)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_half)
|
||||
printflt(#c64.FL_FHALF)
|
||||
|
||||
c64.MOVFM!(#flt_one_over_log_2)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_LOGEB2)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_one_over_log_2)
|
||||
printflt(#c64.FL_LOGEB2)
|
||||
|
||||
c64.MOVFM!(#flt_half_pi)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_PIHALF)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_half_pi)
|
||||
printflt(#c64.FL_PIHALF)
|
||||
|
||||
c64.MOVFM!(#flt_double_pi)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_TWOPI)
|
||||
c64.FPRINTLN!()
|
||||
printflt(#flt_double_pi)
|
||||
printflt(#c64.FL_TWOPI)
|
||||
|
||||
c64.MOVFM!(# flt_point25)
|
||||
c64.FPRINTLN!()
|
||||
c64.MOVFM!(#c64.FL_FR4)
|
||||
c64.FPRINTLN!()
|
||||
printflt(# flt_point25)
|
||||
printflt(#c64.FL_FR4)
|
||||
|
||||
reg_to_float
|
||||
c64.CHROUT!('\n')
|
||||
@ -143,31 +111,25 @@ reg_to_float
|
||||
Y=55
|
||||
|
||||
my_float = A
|
||||
c64.MOVFM(#my_float)
|
||||
c64.FPRINTLN()
|
||||
printflt(#my_float)
|
||||
|
||||
my_float = X
|
||||
c64.MOVFM(#my_float)
|
||||
c64.FPRINTLN()
|
||||
printflt(#my_float)
|
||||
|
||||
my_float = Y
|
||||
c64.MOVFM(#my_float)
|
||||
c64.FPRINTLN()
|
||||
printflt(#my_float)
|
||||
|
||||
XY = 11122
|
||||
my_float = XY
|
||||
c64.MOVFM(#my_float)
|
||||
c64.FPRINTLN()
|
||||
printflt(#my_float)
|
||||
|
||||
AX = 33344
|
||||
my_float = AX
|
||||
c64.MOVFM(#my_float)
|
||||
c64.FPRINTLN()
|
||||
printflt(#my_float)
|
||||
|
||||
AY = 55566
|
||||
my_float = AY
|
||||
c64.MOVFM(#my_float)
|
||||
c64.FPRINTLN()
|
||||
printflt(#my_float)
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user