Skip to content

Commit

Permalink
REAL rule110
Browse files Browse the repository at this point in the history
It took me long enough
Also, I guess the language is kinda concatenative now, with proper stack management while calling scripts and all
  • Loading branch information
Stvff committed Mar 6, 2022
1 parent b367d25 commit be47109
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 76 deletions.
2 changes: 1 addition & 1 deletion aasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ bool dothing(file_t file){
break;
case LOAD:
thatoff = offsetbegin + 5;
for(readfilei = offsetbegin + thatoff; userInput[readfilei] != '\0' && userInput[readfilei] != '\r' && userInput[readfilei] != '\n'; readfilei++)
for(readfilei = thatoff; userInput[readfilei] != '\0' && userInput[readfilei] != '\r' && userInput[readfilei] != '\n'; readfilei++)
userInput[readfilei - thatoff] = userInput[readfilei];
userInput[readfilei - thatoff] = '\0';

Expand Down
59 changes: 0 additions & 59 deletions scripts/rule110.aa

This file was deleted.

19 changes: 19 additions & 0 deletions scripts/rule110/binconv.aa
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; takes the tape and encodes the neigbours of each cell in each cell
; return stack summary: ( binarytape -- encodedtape )
ret
peek gr1

set gr2, gr1 ; first neigbor has no shift
mul gr2, 2 ; but it has a weight of 2

rot gr1, 1 ; second neighbor is the one to the left
add gr2, gr1 ; and has a weight of 1, so is directly added

peek gr1 ; refresh gr1
rot gr1, 1- ; third neigbor is the one to the right
mul gr1, 4 ; and has a weight of 4
add gr2, gr1

pop
push gr2 ; these three add the encoded tape to the return stack again
flip
Binary file added scripts/rule110/classicexample.aal
Binary file not shown.
38 changes: 38 additions & 0 deletions scripts/rule110/rule110.aa
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; THIS IS MAIN
; rule 110, calculates and prints n amount of iterations of the beginning tape t(0)
; return stack summary: ( tape(0) n -- tape(n) )
cmp loop, 0
; uncomment next line if you just want to see the pretty pattern
Ce LOAD classicexample.aal
Ce set loop, 1
Ce set endian, 0
Ce set ir, 0
Ce ret
Ce pop gr4 ; gr4 now contains n (the target amount of iterations)

Ce ret ; these four lines print the initial tape
Ce peek gr1
Ce print gr1
Ce flip

push ir ; saving the registers this script needs before the other scripts mess them up
push loop
push gr4

set loop, 0
SCR binconv.aa

SCR ruleconv.aa

pop gr4 ; retrieving the registers this script needs
pop loop
pop ir

ret ; these four lines print the updated tape each iteration
peek gr1
print gr1
flip

inc ir
ucmp ir, gr4
Cg set loop, 0
21 changes: 21 additions & 0 deletions scripts/rule110/ruleconv.aa
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; Takes the encoded tape and enforces rule 110
; return stack summary: ( encodedtape -- binarytape )
cmp loop, 0
Ce set loop, 1
Ce ret
Ce set ir, 0
Ce peek gr4

peek gr1
len gr1, gr2
dget gr1, ir
set gr3, 00111110 ; 0: 000, 1: 100, 2: 010, 3: 110, 4: 001, 5: 101, 6: 011, 7: 111
dget gr3, gr1
dset gr4, ir, gr3

inc ir
cmp ir, gr2
Ce set loop, 0
Ce pop
Ce push gr4
Ce flip
15 changes: 0 additions & 15 deletions scripts/script.aa

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/test.aa
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ add gr1, 3
print gr1

cmp gr1, 3
Ce SCR test.aa
Ce SCR test.aa
Ce LOAD state.aal
print 8888

0 comments on commit be47109

Please sign in to comment.