Skip to content

Commit

Permalink
Merge pull request #968 from arturo-lang/fix-evaluator-issues
Browse files Browse the repository at this point in the history
[VM/eval] Fix pending issues, add unit-tests & cleanup
  • Loading branch information
drkameleon authored Jan 26, 2023
2 parents 8f8d7b7 + f34e268 commit 2cdb2cb
Show file tree
Hide file tree
Showing 103 changed files with 6,176 additions and 2,051 deletions.
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
3rd-party:
- src/extras/*

ast:
- src/vm/ast.nim

bytecode:
- src/vm/bytecode.nim
- src/vm/opcodes.nim
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Setup nim
uses: jiro4989/setup-nim-action@v1
with:
nim-version: '1.6.6'
nim-version: 'stable'

- name: Verify dependecies
run: |
Expand Down
5 changes: 3 additions & 2 deletions build.nims
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let
"arm" : "--cpu:arm",
"arm64" : "--cpu:arm64 --gcc.path:/usr/bin --gcc.exe:aarch64-linux-gnu-gcc --gcc.linkerexe:aarch64-linux-gnu-gcc",
"debug" : "-d:DEBUG --debugger:on --debuginfo --linedir:on",
"dev" : "--embedsrc:on -d:DEV --listCmd --verbosity:1 --hints:on --hint:ProcessingStmt:off --hint:XCannotRaiseY:off --warning:GcUnsafe:off --warning:ProveInit:off --warning:ProveField:off --warning:Uninit:off",
"dev" : "--embedsrc:on -d:DEV --listCmd",
"docgen" : "-d:DOCGEN",
"dontcompress" : "",
"dontinstall" : "",
Expand Down Expand Up @@ -98,7 +98,8 @@ var
IS_DEV = false
MODE = ""

FLAGS* = "--skipUserCfg:on --colors:off -d:danger " &
FLAGS* = "--verbosity:1 --hints:on --hint:ProcessingStmt:off --hint:XCannotRaiseY:off --warning:GcUnsafe:off --warning:ProveInit:off --warning:ProveField:off --warning:Uninit:off " &
"--skipUserCfg:on --colors:off -d:danger " &
"--panics:off --mm:orc -d:useMalloc --checks:off " &
"-d:ssl --cincludes:extras --opt:speed --nimcache:.cache " &
"--path:src "
Expand Down
28 changes: 28 additions & 0 deletions examples/rosetta/abundant odd numbers.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
the first 25 abundant odd numbers:
945 => sum: 1920
1575 => sum: 3224
2205 => sum: 4446
2835 => sum: 5808
3465 => sum: 7488
4095 => sum: 8736
4725 => sum: 9920
5355 => sum: 11232
5775 => sum: 11904
5985 => sum: 12480
6435 => sum: 13104
6615 => sum: 13680
6825 => sum: 13888
7245 => sum: 14976
7425 => sum: 14880
7875 => sum: 16224
8085 => sum: 16416
8415 => sum: 16848
8505 => sum: 17472
8925 => sum: 17856
9135 => sum: 18720
9555 => sum: 19152
9765 => sum: 19968
10395 => sum: 23040
11025 => sum: 22971
the 1000th abundant odd number: 492975 => sum: 1012336
the first abundant odd number greater than one billion (10^9): 1000000575 => sum: 2083561584
58 changes: 58 additions & 0 deletions examples/rosetta/alternade words.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
accost => cot acs
accuse => cue acs
afield => fed ail
agleam => gem ala
alcott => lot act
allele => lee all
allied => lid ale
alpert => let apr
ambient => min abet
annette => net ante
apport => pot apr
ariadne => ran aide
assist => sit ass
battle => ate btl
blaine => lie ban
brenda => rna bed
calliope => aloe clip
choose => hoe cos
choosy => hoy cos
claire => lie car
collude => old clue
effete => fee eft
fabric => arc fbi
fealty => ely fat
fluent => let fun
forwent => own fret
friend => red fin
george => ere gog
inroad => nod ira
israel => sal ire
jaunty => any jut
joanne => one jan
lounge => one lug
oriole => roe oil
oswald => sad owl
parrot => art pro
peoria => era poi
pierre => ire per
poodle => ode pol
pounce => one puc
racial => ail rca
realty => ely rat
sordid => odd sri
spatial => pta sail
sprain => pan sri
strain => tan sri
strait => tat sri
sturdy => try sud
sweaty => way set
tattle => ate ttl
theorem => hoe term
though => huh tog
throaty => hot tray
triode => roe tid
triune => rue tin
troupe => rue top
truant => rat tun
twirly => wry til
2 changes: 1 addition & 1 deletion examples/rosetta/ascending primes.art
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ascending?: function [x][
and? [equal? sort initial initial][equal? size initial size unique initial]
]

candidates: select (1..1456789) ++ [
candidates: select (@1..1456789) ++ [
12345678, 12345679, 12345689, 12345789, 12346789,
12356789, 12456789, 13456789, 23456789, 123456789
] => prime?
Expand Down
10 changes: 10 additions & 0 deletions examples/rosetta/ascending primes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
2 3 5 7 13 17 19 23 29 37
47 59 67 79 89 127 137 139 149 157
167 179 239 257 269 347 349 359 367 379
389 457 467 479 569 1237 1249 1259 1279 1289
1367 1459 1489 1567 1579 1789 2347 2357 2389 2459
2467 2579 2689 2789 3457 3467 3469 4567 4679 4789
5689 12347 12379 12457 12479 12569 12589 12689 13457 13469
13567 13679 13789 15679 23459 23567 23689 23789 25679 34589
34679 123457 123479 124567 124679 125789 134789 145679 234589 235679
235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789
8 changes: 8 additions & 0 deletions examples/rosetta/brazilian numbers.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
First 20 brazilian numbers:
7 8 10 12 13 14 15 16 18 20 21 22 24 26 27 28 30 31 32 33

First 20 odd brazilian numbers:
7 13 15 21 27 31 33 35 39 43 45 51 55 57 63 65 69 73 75 77

First 20 prime brazilian numbers:
7 13 31 43 73 127 157 211 241 307 421 463 601 757 1093 1123 1483 1723 2551 2801
26 changes: 26 additions & 0 deletions examples/rosetta/change e letters to i in words.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
analyses => analysis
atlantes => atlantis
bellow => billow
breton => briton
clench => clinch
convect => convict
crises => crisis
diagnoses => diagnosis
enfant => infant
enquiry => inquiry
frances => francis
galatea => galatia
harden => hardin
heckman => hickman
inequity => iniquity
inflect => inflict
jacobean => jacobian
marten => martin
module => moduli
pegging => pigging
psychoses => psychosis
rabbet => rabbit
sterling => stirling
synopses => synopsis
vector => victor
welles => willis
26 changes: 26 additions & 0 deletions examples/rosetta/changeable words.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
aristotelean - aristotelian
claustrophobia - claustrophobic
committeeman - committeemen
committeewoman - committeewomen
complementary - complimentary
confirmation - conformation
congresswoman - congresswomen
councilwoman - councilwomen
craftsperson - draftsperson
eavesdropped - eavesdropper
frontiersman - frontiersmen
handicraftsman - handicraftsmen
incommutable - incomputable
installation - instillation
kaleidescope - kaleidoscope
neuroanatomy - neuroanotomy
newspaperman - newspapermen
nonagenarian - nonogenarian
onomatopoeia - onomatopoeic
philanthrope - philanthropy
prescription - proscription
schizophrenia - schizophrenic
shakespearean - shakespearian
spectroscope - spectroscopy
underclassman - underclassmen
upperclassman - upperclassmen
19 changes: 19 additions & 0 deletions examples/rosetta/circular primes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
2
3
5
7
11
13
17
37
79
113
197
199
337
1193
3779
11939
19937
193939
199933
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
valid?: function [n][
pf: factors.prime n
every? pf 'f ->
every? factors.prime n 'f ->
and? [contains? to :string n to :string f]
[1 <> size digits f]
]
Expand Down
2 changes: 1 addition & 1 deletion examples/rosetta/count the coins.art
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ changes: function [amount coins][

loop coins 'coin [
loop coin..amount 'j ->
set ways j (get ways j) + get ways j-coin
ways\[j]: ways\[j] + ways\[j-coin]
]

ways\[amount]
Expand Down
2 changes: 2 additions & 0 deletions examples/rosetta/count the coins.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
242
13398445413854501
9 changes: 9 additions & 0 deletions examples/rosetta/descending primes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
2 3 5 7 31 41 43 53 61 71
73 83 97 421 431 521 541 631 641 643
653 743 751 761 821 853 863 941 953 971
983 5431 6421 6521 7321 7541 7621 7643 8431 8521
8543 8641 8731 8741 8753 8761 9421 9431 9521 9631
9643 9721 9743 9851 9871 75431 76421 76541 76543 86531
87421 87541 87631 87641 87643 94321 96431 97651 98321 98543
98621 98641 98731 764321 865321 876431 975421 986543 987541 987631
8764321 8765321 9754321 9875321 97654321 98764321 98765431
3 changes: 2 additions & 1 deletion examples/rosetta/detect division by zero.art
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
try? -> 3/0
a: 0
try? -> 3 / a
else -> print "division by zero"
8 changes: 8 additions & 0 deletions examples/rosetta/emirp primes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The first 20 emirps:
13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389

Emirps between 7700 and 8000:
7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963

The 10000th emirp:
948349
4 changes: 4 additions & 0 deletions examples/rosetta/factorions.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Base 9 factorions: [1 2 41282]
Base 10 factorions: [1 2 145 40585]
Base 11 factorions: [1 2 26 48 40472]
Base 12 factorions: [1 2]
25 changes: 25 additions & 0 deletions examples/rosetta/fibonacci sequence - recursive.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Fibonacci of 1 = 1
Fibonacci of 2 = 2
Fibonacci of 3 = 3
Fibonacci of 4 = 5
Fibonacci of 5 = 8
Fibonacci of 6 = 13
Fibonacci of 7 = 21
Fibonacci of 8 = 34
Fibonacci of 9 = 55
Fibonacci of 10 = 89
Fibonacci of 11 = 144
Fibonacci of 12 = 233
Fibonacci of 13 = 377
Fibonacci of 14 = 610
Fibonacci of 15 = 987
Fibonacci of 16 = 1597
Fibonacci of 17 = 2584
Fibonacci of 18 = 4181
Fibonacci of 19 = 6765
Fibonacci of 20 = 10946
Fibonacci of 21 = 17711
Fibonacci of 22 = 28657
Fibonacci of 23 = 46368
Fibonacci of 24 = 75025
Fibonacci of 25 = 121393
3 changes: 3 additions & 0 deletions examples/rosetta/hailstone sequence.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hailstone sequence for 27:
27 82 41 124 62 31 94 47 142 71 214 107 322 161 484 242 121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526 263 790 395 1186 593 1780 890 445 1336 668 334 167 502 251 754 377 1132 566 283 850 425 1276 638 319 958 479 1438 719 2158 1079 3238 1619 4858 2429 7288 3644 1822 911 2734 1367 4102 2051 6154 3077 9232 4616 2308 1154 577 1732 866 433 1300 650 325 976 488 244 122 61 184 92 46 23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1
max hailstone sequence found (<100000): of length 179 for 871
3 changes: 3 additions & 0 deletions examples/rosetta/hamming numbers_res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36
2125764000
519312780448388736089589843750000000000000000000000000000000000000000000000000000000
2 changes: 1 addition & 1 deletion examples/rosetta/largest int from concatenated ints.art
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
largestConcInt: function [arr]->
max map permutate arr 's [
to :integer join map s => [to :string]
to :integer join map s => [to :string &]
]

loop [[1 34 3 98 9 76 45 4] [54 546 548 60]] 'a ->
Expand Down
2 changes: 2 additions & 0 deletions examples/rosetta/largest int from concatenated ints.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
998764543431
6054854654
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9867312
2 changes: 1 addition & 1 deletion examples/rosetta/ludic numbers.art
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

ludicGen: function [nmax][
result: [1]
lst: 2..nmax+1
lst: @2..nmax+1
i: 0
worked: false
while [and? [not? empty? lst] [i < size lst]][
Expand Down
9 changes: 9 additions & 0 deletions examples/rosetta/ludic numbers.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The first 25 ludic numbers:
1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107

There are 142 ludic numbers less than/or equal to 1000

The ludic numbers from 2000th to 2005th are: [21475 21481 21487 21493 21503 21511]

The triplets of ludic numbers less than 250 are:
[1 3 7] [5 7 11] [11 13 17] [23 25 29] [41 43 47] [173 175 179] [221 223 227] [233 235 239]
25 changes: 25 additions & 0 deletions examples/rosetta/magic constant_res
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The first 20 magic constants are:
15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 4641

The 1,000th magic constant is:
503006505

10 ^ 1 => 3
10 ^ 2 => 6
10 ^ 3 => 13
10 ^ 4 => 28
10 ^ 5 => 59
10 ^ 6 => 126
10 ^ 7 => 272
10 ^ 8 => 585
10 ^ 9 => 1260
10 ^ 10 => 2715
10 ^ 11 => 5849
10 ^ 12 => 12600
10 ^ 13 => 27145
10 ^ 14 => 58481
10 ^ 15 => 125993
10 ^ 16 => 271442
10 ^ 17 => 584804
10 ^ 18 => 1259922
10 ^ 19 => 2714418
Loading

0 comments on commit 2cdb2cb

Please sign in to comment.