mirror of
https://github.com/irmen/prog8.git
synced 2025-07-19 02:24:31 +00:00
Compare commits
4 Commits
structs-wi
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
720988ae72 | ||
|
ea5deeefbd | ||
|
054c98da7c | ||
|
a4a1b563aa |
@@ -19,7 +19,7 @@ class StatementOptimizer(private val program: Program,
|
|||||||
val functionName = functionCallStatement.target.nameInSource[0]
|
val functionName = functionCallStatement.target.nameInSource[0]
|
||||||
if (functionName in functions.purefunctionNames) {
|
if (functionName in functions.purefunctionNames) {
|
||||||
if("ignore_unused" !in parent.definingBlock.options())
|
if("ignore_unused" !in parent.definingBlock.options())
|
||||||
errors.info("statement has no effect (function return value is discarded)", functionCallStatement.position)
|
errors.warn("statement has no effect (function return value is discarded)", functionCallStatement.position)
|
||||||
return listOf(IAstModification.Remove(functionCallStatement, parent as IStatementContainer))
|
return listOf(IAstModification.Remove(functionCallStatement, parent as IStatementContainer))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -376,7 +376,7 @@ hline_filled_right .byte 0, %10000000, %11000000, %11100000, %11110000, %1111
|
|||||||
_ormask .byte 128, 64, 32, 16, 8, 4, 2, 1
|
_ormask .byte 128, 64, 32, 16, 8, 4, 2, 1
|
||||||
|
|
||||||
; note: this can be even faster if we also have a 320 word x-lookup table, but hey, that's a lot of memory.
|
; note: this can be even faster if we also have a 320 word x-lookup table, but hey, that's a lot of memory.
|
||||||
; see http://codebase64.org/doku.php?id=base:various_techniques_to_calculate_adresses_fast_common_screen_formats_for_pixel_graphics
|
; see https://codebase64.net/doku.php?id=base:various_techniques_to_calculate_adresses_fast_common_screen_formats_for_pixel_graphics
|
||||||
; the y lookup tables encodes this formula: BITMAP_ADDRESS + 320*(py>>3) + (py & 7) (y from 0..199)
|
; the y lookup tables encodes this formula: BITMAP_ADDRESS + 320*(py>>3) + (py & 7) (y from 0..199)
|
||||||
; We use the 64tass syntax for range expressions to calculate this table on assembly time.
|
; We use the 64tass syntax for range expressions to calculate this table on assembly time.
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
;
|
;
|
||||||
; some more interesting routines can be found here:
|
; some more interesting routines can be found here:
|
||||||
; http://6502org.wikidot.com/software-math
|
; http://6502org.wikidot.com/software-math
|
||||||
; http://codebase64.org/doku.php?id=base:6502_6510_maths
|
; https://codebase64.net/doku.php?id=base:6502_6510_maths
|
||||||
; https://github.com/TobyLobster/multiply_test
|
; https://github.com/TobyLobster/multiply_test
|
||||||
; https://github.com/TobyLobster/sqrt_test
|
; https://github.com/TobyLobster/sqrt_test
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ _divisor .word ?
|
|||||||
randword .proc
|
randword .proc
|
||||||
; -- 16 bit pseudo random number generator into AY
|
; -- 16 bit pseudo random number generator into AY
|
||||||
; default seed = $00c2 $1137. NOTE: uses self-modifying code so won't work in ROM (use randword_rom instead)
|
; default seed = $00c2 $1137. NOTE: uses self-modifying code so won't work in ROM (use randword_rom instead)
|
||||||
; routine from https://codebase64.org/doku.php?id=base:x_abc_random_number_generator_8_16_bit
|
; routine from https://codebase64.net/doku.php?id=6502_6510_maths:x_abc_random_number_generator_8_16_bit
|
||||||
inc x1
|
inc x1
|
||||||
clc
|
clc
|
||||||
x1=*+1
|
x1=*+1
|
||||||
@@ -377,7 +377,7 @@ b1=*+1
|
|||||||
randword_rom .proc
|
randword_rom .proc
|
||||||
; -- 16 bit pseudo random number generator into AY. Can run from ROM.
|
; -- 16 bit pseudo random number generator into AY. Can run from ROM.
|
||||||
; NOTE: you have to set the initial seed using randseed_rom! (a good default seed = $00c2 $1137)
|
; NOTE: you have to set the initial seed using randseed_rom! (a good default seed = $00c2 $1137)
|
||||||
; routine from https://codebase64.org/doku.php?id=base:x_abc_random_number_generator_8_16_bit
|
; routine from https://codebase64.net/doku.php?id=6502_6510_maths:x_abc_random_number_generator_8_16_bit
|
||||||
inc _x1
|
inc _x1
|
||||||
clc
|
clc
|
||||||
lda _x1
|
lda _x1
|
||||||
|
@@ -380,7 +380,7 @@ _quadrant_region_to_direction:
|
|||||||
asmsub atan2(ubyte x1 @R0, ubyte y1 @R1, ubyte x2 @R2, ubyte y2 @R3) -> ubyte @A {
|
asmsub atan2(ubyte x1 @R0, ubyte y1 @R1, ubyte x2 @R2, ubyte y2 @R3) -> ubyte @A {
|
||||||
;; Calculate the angle, in a 256-degree circle, between two points into A.
|
;; Calculate the angle, in a 256-degree circle, between two points into A.
|
||||||
;; The points (x1, y1) and (x2, y2) have to use *unsigned coordinates only* from the positive quadrant in the carthesian plane!
|
;; The points (x1, y1) and (x2, y2) have to use *unsigned coordinates only* from the positive quadrant in the carthesian plane!
|
||||||
;; https://www.codebase64.org/doku.php?id=base:8bit_atan2_8-bit_angle
|
;; http://codebase64.net/doku.php?id=base:8bit_atan2_8-bit_angle
|
||||||
;; This uses 2 large lookup tables so uses a lot of memory but is super fast.
|
;; This uses 2 large lookup tables so uses a lot of memory but is super fast.
|
||||||
|
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@@ -1470,6 +1470,17 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(functionCallStatement: FunctionCallStatement) {
|
override fun visit(functionCallStatement: FunctionCallStatement) {
|
||||||
|
|
||||||
|
if(functionCallStatement.target.nameInSource.size==1) {
|
||||||
|
val functionName = functionCallStatement.target.nameInSource[0]
|
||||||
|
if (functionName in program.builtinFunctions.purefunctionNames) {
|
||||||
|
if("ignore_unused" !in functionCallStatement.parent.definingBlock.options()) {
|
||||||
|
errors.warn("statement has no effect (function return value is discarded)", functionCallStatement.position)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// most function calls, even to builtin functions, are still regular FunctionCall nodes here.
|
// most function calls, even to builtin functions, are still regular FunctionCall nodes here.
|
||||||
// they get converted to the more specialized node type in BeforeAsmTypecastCleaner
|
// they get converted to the more specialized node type in BeforeAsmTypecastCleaner
|
||||||
val targetStatement = functionCallStatement.target.checkFunctionOrLabelExists(program, functionCallStatement, errors)
|
val targetStatement = functionCallStatement.target.checkFunctionOrLabelExists(program, functionCallStatement, errors)
|
||||||
|
@@ -133,7 +133,7 @@ private fun integrateDefers(subdefers: Map<PtSub, List<PtDefer>>, program: PtPro
|
|||||||
is PtNumber,
|
is PtNumber,
|
||||||
is PtRange,
|
is PtRange,
|
||||||
is PtString -> true
|
is PtString -> true
|
||||||
// note that unlike most other times, PtIdentifier IS "complex" this time (it's a variable that might change)
|
is PtIdentifier -> true // actually PtIdentifier IS "complex" this time (it's a variable that might change) but it's kinda annoying to give a warning message for this very common case
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import io.kotest.engine.spec.tempdir
|
|||||||
import io.kotest.inspectors.shouldForAll
|
import io.kotest.inspectors.shouldForAll
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import io.kotest.matchers.shouldNotBe
|
import io.kotest.matchers.shouldNotBe
|
||||||
|
import io.kotest.matchers.string.shouldContain
|
||||||
import prog8.ast.expressions.NumericLiteral
|
import prog8.ast.expressions.NumericLiteral
|
||||||
import prog8.ast.statements.Assignment
|
import prog8.ast.statements.Assignment
|
||||||
import prog8.ast.statements.FunctionCallStatement
|
import prog8.ast.statements.FunctionCallStatement
|
||||||
@@ -13,6 +14,7 @@ import prog8.code.core.BuiltinFunctions
|
|||||||
import prog8.code.core.RegisterOrPair
|
import prog8.code.core.RegisterOrPair
|
||||||
import prog8.code.core.isNumeric
|
import prog8.code.core.isNumeric
|
||||||
import prog8.code.target.Cx16Target
|
import prog8.code.target.Cx16Target
|
||||||
|
import prog8tests.helpers.ErrorReporterForTests
|
||||||
import prog8tests.helpers.compileText
|
import prog8tests.helpers.compileText
|
||||||
|
|
||||||
class TestBuiltinFunctions: FunSpec({
|
class TestBuiltinFunctions: FunSpec({
|
||||||
@@ -103,5 +105,31 @@ main {
|
|||||||
|
|
||||||
compileText(Cx16Target(), true, src, outputDir, writeAssembly = true) shouldNotBe null
|
compileText(Cx16Target(), true, src, outputDir, writeAssembly = true) shouldNotBe null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("warning for return value discarding of pure functions") {
|
||||||
|
val src="""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
word @shared ww = 2222
|
||||||
|
|
||||||
|
abs(ww)
|
||||||
|
sgn(ww)
|
||||||
|
sqrt(ww)
|
||||||
|
min(ww, 0)
|
||||||
|
max(ww, 0)
|
||||||
|
clamp(ww, 0, 319)
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
|
||||||
|
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
|
||||||
|
compileText(Cx16Target(), true, src, outputDir, errors=errors, writeAssembly = false) shouldNotBe null
|
||||||
|
errors.warnings.size shouldBe 6
|
||||||
|
errors.warnings[0] shouldContain "statement has no effect"
|
||||||
|
errors.warnings[1] shouldContain "statement has no effect"
|
||||||
|
errors.warnings[2] shouldContain "statement has no effect"
|
||||||
|
errors.warnings[3] shouldContain "statement has no effect"
|
||||||
|
errors.warnings[4] shouldContain "statement has no effect"
|
||||||
|
errors.warnings[5] shouldContain "statement has no effect"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@@ -27,7 +27,7 @@ of these library modules automatically as required.
|
|||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Several algorithms and math routines in Prog8's assembly library files are adapted from
|
Several algorithms and math routines in Prog8's assembly library files are adapted from
|
||||||
code publicly available on https://www.codebase64.org/
|
code publicly available on https://www.codebase64.net/
|
||||||
|
|
||||||
|
|
||||||
.. _builtinfunctions:
|
.. _builtinfunctions:
|
||||||
|
@@ -65,6 +65,11 @@ Various things:
|
|||||||
and it does it at run time. In this demo a jump table is not only created in the library,
|
and it does it at run time. In this demo a jump table is not only created in the library,
|
||||||
but also in the main program and copied into the library for its use.
|
but also in the main program and copied into the library for its use.
|
||||||
|
|
||||||
|
`Additional custom compilation targets (such as VIC-20) <https://github.com/gillham/prog8targets>`_
|
||||||
|
Various custom targets for Prog8 that are not (yet?) part of the Prog8 examples themselves.
|
||||||
|
These additional compilation targets may be in varying state of completeness.
|
||||||
|
Perhaps most recognisable at the time of adding this link, are the various VIC-20 targets.
|
||||||
|
|
||||||
|
|
||||||
.. image:: _static/curious.png
|
.. image:: _static/curious.png
|
||||||
:align: center
|
:align: center
|
||||||
|
@@ -1,27 +1,16 @@
|
|||||||
|
%option no_sysinit
|
||||||
|
%zeropage basicsafe
|
||||||
|
%import textio
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
uword uw = 9999
|
word @shared ww = 2222
|
||||||
word sw = -2222
|
|
||||||
ubyte ub = 42
|
|
||||||
byte sb = -99
|
|
||||||
bool bb = true
|
|
||||||
|
|
||||||
cx16.r0 = uw
|
abs(ww)
|
||||||
cx16.r0s = sw
|
sgn(ww)
|
||||||
cx16.r0L = ub
|
sqrt(ww)
|
||||||
cx16.r0H = ub
|
min(ww, 0)
|
||||||
cx16.r0sL = sb
|
max(ww, 0)
|
||||||
cx16.r0sH = sb
|
clamp(ww, 0, 319)
|
||||||
cx16.r0bL = bb
|
|
||||||
cx16.r0bH = bb
|
|
||||||
|
|
||||||
uw = cx16.r0
|
|
||||||
sw = cx16.r0s
|
|
||||||
ub = cx16.r0L
|
|
||||||
ub = cx16.r0H
|
|
||||||
sb = cx16.r0sL
|
|
||||||
sb = cx16.r0sH
|
|
||||||
bb = cx16.r0bL
|
|
||||||
bb = cx16.r0bH
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
Reference in New Issue
Block a user