From be471092ee7ba9e632b181c297277aacc7cc74d4 Mon Sep 17 00:00:00 2001 From: 0x4646 <65192177+StevenClifford@users.noreply.github.com> Date: Sun, 6 Mar 2022 02:20:40 +0100 Subject: [PATCH] REAL rule110 It took me long enough Also, I guess the language is kinda concatenative now, with proper stack management while calling scripts and all --- aasm.c | 2 +- scripts/rule110.aa | 59 ----------------------------- scripts/rule110/binconv.aa | 19 ++++++++++ scripts/rule110/classicexample.aal | Bin 0 -> 429 bytes scripts/rule110/rule110.aa | 38 +++++++++++++++++++ scripts/rule110/ruleconv.aa | 21 ++++++++++ scripts/script.aa | 15 -------- scripts/test.aa | 3 +- 8 files changed, 81 insertions(+), 76 deletions(-) delete mode 100644 scripts/rule110.aa create mode 100644 scripts/rule110/binconv.aa create mode 100644 scripts/rule110/classicexample.aal create mode 100644 scripts/rule110/rule110.aa create mode 100644 scripts/rule110/ruleconv.aa delete mode 100644 scripts/script.aa diff --git a/aasm.c b/aasm.c index 93ce8ed..e3298fc 100644 --- a/aasm.c +++ b/aasm.c @@ -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'; diff --git a/scripts/rule110.aa b/scripts/rule110.aa deleted file mode 100644 index a5aeb55..0000000 --- a/scripts/rule110.aa +++ /dev/null @@ -1,59 +0,0 @@ -cmp loop, 0 ; rule 110, calculates and prints n amount of iterations of the beginning tape t(0) -Ce set ir, 0 ; return stack summary: ( n t(0) -- n t(n) ) -Ce set loop, 1 -Ce set endian, 0 -Ce push 0 ; sets the iteration number to 0 -Ce push 0 ; sets the mode (translate: 0, transform: 1) - -peek gr1 -cmp gr1, 0 ; everything belonging to this cmp translates the tape into numbers -Ce pop -Ce push, 1 -Ce ret -Ce peek gr1 -Ce flip -Ce push gr1 -Ce set gr4, gr1 - -Ce rot gr1, 1 -Ce set gr2, gr1 - -Ce rot gr1, 1- -Ce mul gr1, 2 -Ce add gr2, gr1 - -Ce peek gr1 -Ce rot gr1, 1- -Ce mul gr1, 4 -Ce add gr2, gr1 - -Ce pop -Ce print gr2 - -Ce pop -Ce push 2 -Ce push gr2 - -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 -print gr1 - -inc ir -cmp ir, gr2 -Ce print gr4 -Ce set loop, 0 -Ce pop -Ce pop - -Ce ret -Ce pop -Ce push gr4 -Ce flip - -Ce pop gr4 -Ce inc gr4 -Ce push gr3 diff --git a/scripts/rule110/binconv.aa b/scripts/rule110/binconv.aa new file mode 100644 index 0000000..91cb16d --- /dev/null +++ b/scripts/rule110/binconv.aa @@ -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 diff --git a/scripts/rule110/classicexample.aal b/scripts/rule110/classicexample.aal new file mode 100644 index 0000000000000000000000000000000000000000..deac8e765fe3098ca655286d8034c86dbeeca38b GIT binary patch literal 429 zcmZQzfB;7*O$o&a(<};O;GzeE0%oA&*jSlhPJ}xiBmfqLOJVXj;Hu#akTw*KBS?fo L05=fi1Qs>`3pfEF literal 0 HcmV?d00001 diff --git a/scripts/rule110/rule110.aa b/scripts/rule110/rule110.aa new file mode 100644 index 0000000..5a62bcf --- /dev/null +++ b/scripts/rule110/rule110.aa @@ -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 diff --git a/scripts/rule110/ruleconv.aa b/scripts/rule110/ruleconv.aa new file mode 100644 index 0000000..2bd157c --- /dev/null +++ b/scripts/rule110/ruleconv.aa @@ -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 diff --git a/scripts/script.aa b/scripts/script.aa deleted file mode 100644 index 89d84f8..0000000 --- a/scripts/script.aa +++ /dev/null @@ -1,15 +0,0 @@ -cmp loop, 0 ;Compares loop to 0 -Ce set gr1, 1 ;This sets gr1 to 1 if loop == 0, in other words, at the start of the program -Ce print gr1 ;Same as above but it prints gr1 - -inc gr1 ;increment gr1 a bunch of times and then prints it -inc gr1 -inc gr1 -print gr1 - -set loop, 1 ;sets loop to 1 as default, so the program will loop normally - -cmp gr1, 5 ;compares gr1 to 5 -Cg set loop, 0 ;sets loop to 0 if the result of the comparison is gr1 > 5 - -print 000000000000000000 ;prints a little divider so that the moment of looping is visible diff --git a/scripts/test.aa b/scripts/test.aa index 2b28e58..e9ecbd2 100644 --- a/scripts/test.aa +++ b/scripts/test.aa @@ -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