mirror of
https://github.com/irmen/prog8.git
synced 2025-11-01 22:16:16 +00:00
allow struct initializers to occur in array literals
This commit is contained in:
@@ -11,34 +11,32 @@ main{
|
||||
uword area ; 1000 km^2
|
||||
}
|
||||
|
||||
^^Country[100] countries ; won't be fully filled
|
||||
ubyte num_countries
|
||||
^^Country[] countries = [
|
||||
^^Country:["Indonesia", 285.72, 1904],
|
||||
^^Country:["Congo", 112.83, 2344],
|
||||
^^Country:["Vietnam", 101.60, 331],
|
||||
^^Country:["United States", 347.28, 9372],
|
||||
^^Country:["Iran", 92.42, 1648],
|
||||
^^Country:["Turkey", 87.69, 783],
|
||||
^^Country:["Brazil", 212.81, 8515],
|
||||
^^Country:["Bangladesh", 175.69, 147],
|
||||
^^Country:["Germany", 84.08, 357],
|
||||
^^Country:["Japan", 123.10, 377],
|
||||
^^Country:["India", 1463.87, 3287],
|
||||
^^Country:["China", 1416.10, 9596],
|
||||
^^Country:["Philippines", 116.79, 300],
|
||||
^^Country:["Russia", 143.99, 17098],
|
||||
^^Country:["Pakistan", 255.22, 881],
|
||||
^^Country:["Nigeria", 237.53, 923],
|
||||
^^Country:["Ethiopia", 135.47, 1104],
|
||||
^^Country:["Mexico", 131.95, 1964],
|
||||
^^Country:["Thailand", 71.62, 513],
|
||||
^^Country:["Egypt", 118.37, 1002],
|
||||
]
|
||||
|
||||
sub start() {
|
||||
txt.lowercase()
|
||||
|
||||
; because pointer array initialization is not supported yet, we have to add the countries in separate statements for now
|
||||
add(^^Country:["Indonesia", 285.72, 1904])
|
||||
add(^^Country:["Congo", 112.83, 2344])
|
||||
add(^^Country:["Vietnam", 101.60, 331])
|
||||
add(^^Country:["United States", 347.28, 9372])
|
||||
add(^^Country:["Iran", 92.42, 1648])
|
||||
add(^^Country:["Turkey", 87.69, 783])
|
||||
add(^^Country:["Brazil", 212.81, 8515])
|
||||
add(^^Country:["Bangladesh", 175.69, 147])
|
||||
add(^^Country:["Germany", 84.08, 357])
|
||||
add(^^Country:["Japan", 123.10, 377])
|
||||
add(^^Country:["India", 1463.87, 3287])
|
||||
add(^^Country:["China", 1416.10, 9596])
|
||||
add(^^Country:["Philippines", 116.79, 300])
|
||||
add(^^Country:["Russia", 143.99, 17098])
|
||||
add(^^Country:["Pakistan", 255.22, 881])
|
||||
add(^^Country:["Nigeria", 237.53, 923])
|
||||
add(^^Country:["Ethiopia", 135.47, 1104])
|
||||
add(^^Country:["Mexico", 131.95, 1964])
|
||||
add(^^Country:["Thailand", 71.62, 513])
|
||||
add(^^Country:["Egypt", 118.37, 1002])
|
||||
|
||||
txt.print("UNSORTED:\n")
|
||||
dump()
|
||||
|
||||
@@ -57,7 +55,7 @@ main{
|
||||
|
||||
sub sort_by_name() {
|
||||
; stupid slow bubble sort
|
||||
ubyte n = num_countries
|
||||
ubyte n = len(countries)
|
||||
do {
|
||||
ubyte newn=0
|
||||
ubyte i
|
||||
@@ -73,7 +71,7 @@ main{
|
||||
|
||||
sub sort_by_population() {
|
||||
; stupid slow bubble sort
|
||||
ubyte n = num_countries
|
||||
ubyte n = len(countries)
|
||||
do {
|
||||
ubyte newn=0
|
||||
ubyte i
|
||||
@@ -89,7 +87,7 @@ main{
|
||||
|
||||
sub sort_by_area() {
|
||||
; stupid slow bubble sort
|
||||
ubyte n = num_countries
|
||||
ubyte n = len(countries)
|
||||
do {
|
||||
ubyte newn=0
|
||||
ubyte i
|
||||
@@ -125,10 +123,5 @@ main{
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
|
||||
sub add(^^Country c) {
|
||||
countries[num_countries] = c
|
||||
num_countries++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user