mirror of
https://github.com/irmen/prog8.git
synced 2025-11-01 22:16:16 +00:00
make sizeof(float) work, so you don't have to use sys.SIZEOF_FLOAT anymore etc.
define sys.SIZEOF_FLOAT in terms of sizeof(float)
This commit is contained in:
@@ -262,12 +262,13 @@ class TestMemory: FunSpec({
|
||||
shouldThrow<IllegalArgumentException> {
|
||||
target.memorySize(BaseDataType.UNDEFINED)
|
||||
}
|
||||
shouldThrow<IllegalArgumentException> {
|
||||
target.memorySize(BaseDataType.LONG)
|
||||
shouldThrow<NoSuchElementException> {
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.LONG), 10)
|
||||
}
|
||||
target.memorySize(BaseDataType.BOOL) shouldBe 1
|
||||
target.memorySize(BaseDataType.BYTE) shouldBe 1
|
||||
target.memorySize(BaseDataType.WORD) shouldBe 2
|
||||
target.memorySize(BaseDataType.LONG) shouldBe 4
|
||||
target.memorySize(BaseDataType.FLOAT) shouldBe target.FLOAT_MEM_SIZE
|
||||
|
||||
target.memorySize(DataType.BOOL, null) shouldBe 1
|
||||
@@ -283,13 +284,14 @@ class TestMemory: FunSpec({
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.BOOL), 10) shouldBe 10
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.BYTE), 10) shouldBe 10
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.WORD), 10) shouldBe 20
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.WORD), 10) shouldBe 20
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.UWORD), 10) shouldBe 20
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.FLOAT), 10) shouldBe 10*target.FLOAT_MEM_SIZE
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.WORD, true), 10) shouldBe 20
|
||||
target.memorySize(DataType.arrayFor(BaseDataType.UWORD, true), 10) shouldBe 20
|
||||
|
||||
target.memorySize(DataType.BOOL, 10) shouldBe 10
|
||||
target.memorySize(DataType.UWORD, 10) shouldBe 20
|
||||
target.memorySize(DataType.LONG, 10) shouldBe 40
|
||||
target.memorySize(DataType.FLOAT, 10) shouldBe 10*target.FLOAT_MEM_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1062,4 +1062,47 @@ main {
|
||||
st.size shouldBe 3
|
||||
}
|
||||
|
||||
test("allow type name as argument for sizeof()") {
|
||||
val src="""
|
||||
%option enable_floats
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
bool @shared b
|
||||
float @shared f
|
||||
word @shared w
|
||||
const long ll = 9999999
|
||||
ubyte @shared ub1, ub2
|
||||
|
||||
ub1 = sys.SIZEOF_BOOL
|
||||
ub2 = sys.SIZEOF_WORD
|
||||
ub1 = sys.SIZEOF_LONG
|
||||
ub2 = sys.SIZEOF_FLOAT
|
||||
|
||||
ub1 = sizeof(true)
|
||||
ub2 = sizeof(1234)
|
||||
ub1 = sizeof(12345678)
|
||||
ub2 = sizeof(9.999)
|
||||
|
||||
ub1 = sizeof(b)
|
||||
ub2 = sizeof(w)
|
||||
ub1 = sizeof(ll)
|
||||
ub2 = sizeof(f)
|
||||
|
||||
ub1 = sizeof(bool)
|
||||
ub2 = sizeof(word)
|
||||
ub1 = sizeof(long)
|
||||
ub2 = sizeof(float)
|
||||
}
|
||||
}"""
|
||||
|
||||
val result = compileText(VMTarget(), false, src, outputDir, writeAssembly = false)!!
|
||||
val st = result.compilerAst.entrypoint.statements
|
||||
st.size shouldBe 27
|
||||
val assignments = st.dropLast(1).takeLast(16)
|
||||
assignments.forEach { a ->
|
||||
(a as Assignment).value shouldBe instanceOf<NumericLiteral>()
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user