diff --git a/build.sh b/build.sh index 9afa4d1..ece79a3 100755 --- a/build.sh +++ b/build.sh @@ -67,11 +67,14 @@ if [ -z "$DEBUG" ]; then fi # Sorry -cpp -P -w -D $DEBUG config/pre-options.tal -o config/options.tal -cpp -P -w -D $DEBUG src/debugger/routines/pre-after-eval.tal \ --o src/debugger/routines/after-eval.tal -cpp -P -w -D $DEBUG src/debugger/routines/pre-before-eval.tal \ --o src/debugger/routines/before-eval.tal +cpp -P -w -D $DEBUG config/options.talp -o config/options.tal +cpp -P -w -D $DEBUG src/debugger/routines/after-eval.talp \ + -o src/debugger/routines/after-eval.tal +cpp -P -w -D $DEBUG src/debugger/routines/before-eval.talp \ + -o src/debugger/routines/before-eval.tal +cpp -P -w -D $DEBUG src/repl/data.talp -o src/repl/data.tal +cpp -P -w -D $DEBUG src/talos/main.talp -o src/talos/main.tal +cpp -P -w -D $DEBUG src/talos/macros.talp -o src/talos/macros.tal # Build mkdir -p rom diff --git a/config/macros.tal b/config/macros.tal index 3dd3a45..6609806 100644 --- a/config/macros.tal +++ b/config/macros.tal @@ -1,7 +1,6 @@ ( @|config/macros ) -%UXN { LIT2 "փ } %SPACER { \s \s \s \s \s \s } %ENABLE { |00 } diff --git a/config/pre-options.tal b/config/options.talp similarity index 96% rename from config/pre-options.tal rename to config/options.talp index c87be8b..cad919b 100644 --- a/config/pre-options.tal +++ b/config/options.talp @@ -50,7 +50,7 @@ DEBUG @LOG-LEVEL ( valid values: OFF INFO WARN DEBUG ( most verbose ) ) ENABLE @INFO-STACKS ( print stacks after each evaluation ) DISABLE @INFO-PROMPT ( print the heap's `head` pointer inside the prompt ) -ENABLE @INFO-ASSEMBLER-SUMMARY ( print the assembled definition summary ) +DISABLE @INFO-ASSEMBLER-SUMMARY ( print the assembled definition summary ) ENABLE @WARN-ABORT ( warn each time an evaluation is aborted ) ENABLE @WARN-REDEFINITION ( warn on each redefinition ) diff --git "a/etc/src/demos/\326\203sh/\326\203sh.tal" "b/etc/src/demos/\326\203sh/\326\203sh.tal" index e3eb370..dce4472 100644 --- "a/etc/src/demos/\326\203sh/\326\203sh.tal" +++ "b/etc/src/demos/\326\203sh/\326\203sh.tal" @@ -42,6 +42,7 @@ ;Command/buf ;Command/pos STA2 JMP2r + @prompt 0a &first "փsh> 2000 @Command &pos $2 &buf diff --git a/src/debugger/routines/pre-after-eval.tal b/src/debugger/routines/after-eval.talp similarity index 100% rename from src/debugger/routines/pre-after-eval.tal rename to src/debugger/routines/after-eval.talp diff --git a/src/debugger/routines/pre-before-eval.tal b/src/debugger/routines/before-eval.talp similarity index 100% rename from src/debugger/routines/pre-before-eval.tal rename to src/debugger/routines/before-eval.talp diff --git a/src/logger/data.tal b/src/logger/data.tal index da77091..c407c60 100644 --- a/src/logger/data.tal +++ b/src/logger/data.tal @@ -5,9 +5,9 @@ "INFO: \s \0 &unused "-- \s "Unused: \s \0 &on-repl "expression \0 - &assembled "Assembled \s \0 - &in \s "in \s \0 - &bytes \s "bytes. \n \0 + &assembled \n "Assembled \fg-2 \s \0 + &in \s \fg-3 "in \s \0 + &bytes \s "bytes. \0 &labels \s "labels 29 ". \n \0 &sym-ext ".sym \0 &multiline-info-prompt \n "... \s "... \s ": \s \0 diff --git a/src/repl/data.tal b/src/repl/data.tal index 9fa5235..df7cce9 100644 --- a/src/repl/data.tal +++ b/src/repl/data.tal @@ -1,24 +1,14 @@ ( @|repl/data ) - -@banner [ - \bold \bg-1 \fg-0 MARGIN \n - - \s \s \bg-2 \s \s \s \underline "/ \s \reset-console-style \bold \bg-1 \fg-0 - \s \s \bg-3 \fg-1 \s \s "⋃ \s "⨉ \s "⋂ \s \s \bg-0 \fg-3 \s \s NAME \s - \s \bg-2 \fg-0 \s \s "v VERSION \s 28 DATE 29 \s \s \bg-1 \fg-0 \s \s \n - - \s \s \bg-2 \underline "/ \s \reset-console-style \bold \bg-2 \fg-0 "/ \s "/ - \bg-1 \s \s \s \s \s "©2024 \s AUTHOR \s \s \s \s \s \n - - \s \s \bg-2 \s "/ \s \s \s \bg-1 \s \s \s \s "Type \s \bold \italic \fg-3 "help - \reset-console-style \bold \bg-1 \fg-0 \s "for \s "more \s "information. \s \s - \s \s \n - - MARGIN \n - - \reset-console-style \bg-0 \fg-1 \0 ] - -@ok [ \underline \fg-3 \s \s \s \s "ok \n \n \0 ] - -@multiline-prompt [ \n "... \s \0 ] + @banner [ + \n \s \s \s \s \s "/_ \s \s "UXN \s \s \s \s \s NAME \s \s \s \s + \s "v VERSION \s 28 DATE 29 \n + \s \s "/_/ \s "/ \s \s "(c)2024 \s AUTHOR \n + \s \s \s "/ \s \s \s \s \s "Type \s "help \s "for \s "more \s + "information. \n \n \0 ] + @ok [ "____ok \n \n \0 ] + @shell-prompt \n \n "uxnsh> \s \0 + @prompt [ "uxn \s "> \s \0 ] + @prompt-start [ "uxn \0 ] + @multiline-prompt [ \n \s "... \s \0 ] +@prompt-end [ "> \s \0 ] diff --git a/src/repl/data.talp b/src/repl/data.talp new file mode 100644 index 0000000..2dcc282 --- /dev/null +++ b/src/repl/data.talp @@ -0,0 +1,54 @@ +( +@|repl/data ) + +#ifdef ANSI + @banner [ + \bold \bg-1 \fg-0 MARGIN \n + + \s \s \bg-2 \s \s \s \underline "/ \s \reset-console-style \bold \bg-1 \fg-0 + \s \s \bg-3 \fg-1 \s \s "⋃ \s "⨉ \s "⋂ \s \s \bg-0 \fg-3 \s \s NAME \s + \s \bg-2 \fg-0 \s \s "v VERSION \s 28 DATE 29 \s \s \bg-1 \fg-0 \s \s \n + + \s \s \bg-2 \underline "/ \s \reset-console-style \bold \bg-2 \fg-0 "/ \s "/ + \bg-1 \s \s \s \s \s "©2024 \s AUTHOR \s \s \s \s \s \n + + \s \s \bg-2 \s "/ \s \s \s \bg-1 \s \s \s \s "Type \s \bold \italic \fg-3 "help + \reset-console-style \bold \bg-1 \fg-0 \s "for \s "more \s "information. \s \s + \s \s \n + + MARGIN \n + + \reset-console-style \bg-0 \fg-1 \0 ] + + @ok [ \underline \fg-3 \s \s \s \s "ok \n \n \0 ] + + @shell-prompt [ + \r \s \s \s \s \s \s \s \s \s \r \bg-0 \fg-2 \bold "փsh> \s + \reset-console-style \bg-0 \fg-1 \0 ] + + @prompt [ + \r \s \s \s \s \r \bg-0 \fg-3 \bold "փ \s "> \s + \reset-console-style \bg-0 \fg-1 \0 ] + + @prompt-start [ "փ \s \0 ] + @multiline-prompt [ \n "... \s \0 ] +#else + @banner [ + \n \s \s \s \s \s "/_ \s \s "UXN \s \s \s \s \s NAME \s \s \s \s + \s "v VERSION \s 28 DATE 29 \n + + \s \s "/_/ \s "/ \s \s "(c)2024 \s AUTHOR \n + + \s \s \s "/ \s \s \s \s \s "Type \s "help \s "for \s "more \s + "information. \n \n \0 ] + + @ok [ "____ok \n \n \0 ] + + @shell-prompt \n \n "uxnsh> \s \0 + + @prompt [ "uxn \s "> \s \0 ] + @prompt-start [ "uxn \0 ] + @multiline-prompt [ \n \s "... \s \0 ] +#endif + +@prompt-end [ "> \s \0 ] diff --git a/src/repl/routines.tal b/src/repl/routines.tal index 69a19c8..7b2116f 100644 --- a/src/repl/routines.tal +++ b/src/repl/routines.tal @@ -111,14 +111,10 @@ ;&shell-mode LDA #00 EQU ;&shell-mode STA POP ;&shell-mode LDA ?{ - pstr: - \r \s \s \s \s \s \s \s \s \s \r \bg-0 \fg-2 \bold "փsh> \s - \reset-console-style \bg-0 \fg-1 \0 + ;shell-prompt pstr BRK } - pstr: - \r \s \s \s \s \r \bg-0 \fg-3 \bold "փ \s "> \s - \reset-console-style \bg-0 \fg-1 \0 + ;prompt pstr BRK } DUP LIT "@ NEQ ?{ #01 ;&expression STA } @@ -141,7 +137,7 @@ !&multiline-end } #01 ,&break STR - POP LIT \n } + POP LIT \0 } DUP \emit @@ -155,7 +151,7 @@ #0000 ;length STA2 ~debugger/routines/before-eval.tal - POP ( consume newline ) + POP ( consume newline) ( @|Eval ) @@ -230,15 +226,12 @@ ( ;input ;input-ptr LDA2 NEQ2 ?{ pstr: \console-cursor-up \0 } ) - ;&prompt-start pstr + ;prompt-start pstr ~logger/info/prompt.tal - ;&prompt-end pstr + ;prompt-end pstr pstr: \CSI "m \CSI "48;2;51;00;34m \CSI "38;2;170;170;170m \0 JMP2r - &prompt-start [ "փ \s \0 ] - &prompt-end [ "> \s \0 ] - @ ( -- ) ;ok !pstr diff --git a/src/repl/routines.talp b/src/repl/routines.talp new file mode 100644 index 0000000..3a7fb2d --- /dev/null +++ b/src/repl/routines.talp @@ -0,0 +1,259 @@ +( +@|repl/routines ) + +@REPL ( -> ) + ( + @|Read ) + .Console/read DEI + ( <\n> + ;&in-csi LDA phex/byte <\n> DUP phex/byte LIT ": \emit <\s> ) + [ LIT &comment 01 ] ?{ + DUP #29 NEQ ?{ #01 ;&comment STA } + \emit BRK } + + DUP #28 NEQ ?{ + #00 ;&comment STA \emit BRK } + + DUP #7f NEQ ?{ ( DELETE ) + ;input ;input-ptr LDA2 NEQ2 ?{ + #0718 DEO POP BRK } + + #08 \emit + <\s> + #08 \emit + ;input-ptr LDA2 #0001 SUB2 DUP2 + #00 ROT ROT STA + ;input-ptr STA2 + POP BRK } + + ( \CSI 201~ ^[[201~ End of braketed paste off ) + DUP LIT "~ NEQ [ LIT &in-csi-201 01 ] ORA ?{ + ;&multiline LDA #00 EQU ;&multiline STA + #01 ,&in-csi-201 STR + POP BRK } + + ( \CSI 201 ^[[201 Stage 3 of braketed paste off ) + DUP LIT "1 NEQ ,&in-csi-20 LDR ORA ?{ + #00 ,&in-csi-201 STR + #01 ,&in-csi-20 STR + POP BRK } + + ( \CSI 200~ ^[[200~ End of braketed paste on ) + DUP LIT "~ NEQ [ LIT &in-csi-200 01 ] ORA ?{ + ;&multiline LDA #00 EQU ;&multiline STA + #01 ,&in-csi-200 STR + POP BRK } + + ( \CSI 200 ^[[200 Stage 3 of braketed paste on ) + DUP LIT "0 NEQ [ LIT &in-csi-20 01 ] ORA ?{ + #00 ,&in-csi-200 STR + #01 ,&in-csi-20 STR + POP BRK } + + ( \CSI 20 ^[[20 Stage 2 of braketed paste ) + DUP LIT "0 NEQ [ LIT &in-csi-2 01 ] ORA ?{ + #00 ,&in-csi-20 STR + #01 ,&in-csi-2 STR + POP BRK } + + [ LIT &in-csi 01 ] ?{ + #01 ,&in-csi STR + + DUP LIT "2 NEQ ?{ ( \CSI 2 ^[[2 Start of braketed paste ) + #00 ,&in-csi-2 STR + POP BRK } + + DUP LIT "A NEQ ?{ ( \CSI 41 ^[[A UP ) + pstr: \console-cursor-up \0 + POP BRK } + + DUP LIT "B NEQ ?{ ( \CSI 42 ^[[B DOWN ) + pstr: \console-cursor-down \0 + POP BRK } + + DUP LIT "C NEQ ?{ ( \CSI 43 ^[[D RIGHT ) + pstr: \console-cursor-right \0 + POP BRK } + + DUP LIT "D NEQ ?{ ( \CSI 44 ^[[C LEFT ) + pstr: \console-cursor-left \0 + POP BRK } } + + DUP #5b NEQ ;&in-esc LDA ORA ?{ ( \CSI ^[[ CSI ) + #00 ;&in-csi STA + #01 ;&in-esc STA + POP BRK } + + DUP #1b NEQ ?{ ( 1b \e ^[ ^3 ESC -> ESCAPE ) + #00 ;&in-esc STA + POP BRK } + + ( DUP SP NEQ ?{ POP BRK ( ignore ) } ) + + DUP #03 NEQ ?{ ( 03 ^C -> ETX END-OF-TEXT ) + #01 exit } + + DUP #04 NEQ ?{ ( 04 ^D -> EOT END-OF-TRANSMIT ) + bye } + + DUP #0c NEQ ?{ ( 0c ^L -> FF FORM-FEED ) + pstr: \clear-console-screen \reset-console-cursor \0 + + POP BRK } + + DUP #13 NEQ ?{ ( 0c ^S -> DEVICE-CONTROL-3 ) + pstr: \reset-console-style \bg-0 \fg-2 \bold \0 + POP #010e DEO + pstr: \reset-console-style \bg-0 \fg-1 \0 + LIT \n } + + DUP #0e NEQ ?{ ( 0c ^N -> SO SHIFT-OUT ) + ;&shell-mode LDA #00 EQU ;&shell-mode STA POP + + ;&shell-mode LDA ?{ + ;shell-prompt pstr + BRK } + + ;prompt pstr + BRK } + + DUP LIT "@ NEQ ?{ #01 ;&expression STA } + + [ LIT &in-esc 01 ] ?{ + #01 ,&in-esc STR + + DUPk LIT \r NEQ SWP LIT \n NEQ AND ?{ + ,&multiline LDR #00 EQU ,&multiline STR } } + + DUPk LIT \r NEQ SWP LIT \n NEQ AND ?{ + [ LIT &multiline 01 ] ?{ + pstr: \reset-console-style \bold \bg-0 \fg-3 \0 + ~logger/info/multiline-prompt.tal + ;multiline-prompt + + &multiline-continue ( -- ) + pstr + pstr: \reset-console-style \bg-0 \fg-1 \0 + !&multiline-end } + + #01 ,&break STR + POP LIT \0 } + + DUP \emit + + &multiline-end + ;input-ptr LDA2 STA + ;input-ptr LDA2 INC2 ;input-ptr STA2 + + [ LIT &break 00 ] ?{ BRK } + #00 ,&break STR + + #0000 ;length STA2 + ~debugger/routines/before-eval.tal + + POP ( consume newline) + + ( + @|Eval ) + [ LIT &shell-mode 01 ] ?{ + #01 ,&shell-mode STR + ;input syscall-sync + + POP !&shell-return } + + ;head-ptr LDA2 DUP2 ;prev-head STA2 STH2 ( | +prev-head* ) + ;abort LDA ?&expr-abort + ~logger/info/summary.tal + + + [ LIT &expression $1 ] ?{ + ( assemble expr return jump ) + ;head-ptr LDA2 STH2 ( | prev-head* +head* ) + [ LIT LIT2 ] STH2kr STA ( | prev-head* head* ) + ;REPL/expr-return STH2kr INC2 STA2 ( | prev-head* -head* ) + [ LIT JMP2 ] STH2r INC2 INC2 INC2 STA ( | prev-head* ) + ( reset head-ptr ) + STH2kr ;head-ptr STA2 ( | prev-head* ) + ;&on-eval .Console/vector DEO2 + STH2r JMP2 } ( | -prev-head* ) + + POP2r ( | -prev-head* ) + + &expr-return ( -- ) + ;REPL .Console/vector DEO2 + #00 ,&expression STR + + &shell-return + #0400 #0000 ;input mzero + + ( + @|Print ) + + ~debugger/routines/after-eval.tal + ~logger/info/stacks.tal + + ( + @|Loop ) + BRK + +&expr-abort ( | prev-head* -- ) + ~logger/warn/abort.tal + ( POP2r ( | -prev-head* ) ) + <>! + #00 ;abort STA + !REPL/expr-return + +&on-eval ( -! ) + .Console/read DEI LIT \r NEQ ?{ + [ LIT &count $1 ] INCk ,&count STR ( +count | ) + + #02 NEQ ?{ ( -count | ) + #00 ,&count STR + !&expr-abort } + + BRK } + ( reset ) #00 ,&count STR + BRK + +@ ( -- ) + ;REPL/shell-mode ?{ + + JMP2r } + + pstr: \CSI "m \bold \bg-0 \fg-3 \0 + + + ( ;input ;input-ptr LDA2 NEQ2 ?{ + pstr: \console-cursor-up \0 } ) + + ;&prompt-start pstr + ~logger/info/prompt.tal + ;&prompt-end pstr + pstr: \CSI "m \CSI "48;2;51;00;34m \CSI "38;2;170;170;170m \0 + JMP2r + + #ifdef ANSI + &prompt-start [ "փ \s \0 ] + #else + &prompt-start [ "uxn \0 ] + #endif + + &prompt-end [ "> \s \0 ] + +@ ( -- ) + ;ok !pstr + +@ + ;banner !pstr + +@help ( -- ) + +@toogle-shell ( -- ) + +@syscall-sync ( cmd* -- ) + .Console/addr DEO2 + #01 .Console/exec DEO + + &sync + .Console/live DEI #ff NEQ ?&sync + JMP2r diff --git a/src/talos/macros.tal b/src/talos/macros.tal index 09f4644..ac24295 100644 --- a/src/talos/macros.tal +++ b/src/talos/macros.tal @@ -1,8 +1,6 @@ ( @|talos/macros ) - %VERSION { "0.12 } %DATE { "18Q06 } - %NAME { "TalOS } %DESCRIPTION { "A \s "Varvara \s "operating \s "system. } -%AUTHOR { "Ismael \s "Venegas \s "Castelló } + %AUTHOR { "Ismael \s "Venegas \s "Castello } diff --git a/src/talos/macros.talp b/src/talos/macros.talp new file mode 100644 index 0000000..88a0dce --- /dev/null +++ b/src/talos/macros.talp @@ -0,0 +1,13 @@ +( +@|talos/macros ) + +%VERSION { "0.12 } %DATE { "18Q06 } + +%NAME { "TalOS } +%DESCRIPTION { "A \s "Varvara \s "operating \s "system. } + +#ifdef ANSI + %AUTHOR { "Ismael \s "Venegas \s "Castelló } +#else + %AUTHOR { "Ismael \s "Venegas \s "Castello } +#endif \ No newline at end of file diff --git a/src/talos/main.tal b/src/talos/main.tal index 9b83045..ca80b87 100644 --- a/src/talos/main.tal +++ b/src/talos/main.tal @@ -1,50 +1,34 @@ ( @|talos/main ) - @Main ( -> ) - ( - @|setup ) - - ( - &|metadata ) - ;meta #06 DEO2 - - ( - &|symbols ) - ( Move the symbols before the input buffer. ) - ;tail/end ;tail SUB2 STH2k #0000 ;head #0000 ( | len* ) - ;syms STH2kr SUB2 STH2k mcpyl ( | len* dst* ) - SWP2r STH2r #0000 ;head mzero ( | dst* ) - - ( - &|pointers ) - STH2r ;tail-ptr STA2 ( | ) - ;head ;head-ptr STA2 - ;input ;input-ptr STA2 - - ( - &|theme ) - \RED .System/r DEO2 - \GREEN .System/g DEO2 - \BLUE .System/b DEO2 - - pstr: [ - \bg-0 \fg-1 \clear-console-screen-right \n \n \n \n \n \n - \console-cursor-up \console-cursor-up \console-cursor-up - \console-cursor-up \console-cursor-up \console-cursor-up \0 ] - - ( - @|startup ) - .PRINT-BANNER ?{ - } - pstr: \italic \underline \bold \fg-3 \0 - free - pstr: \reset-console-style \bg-0 \fg-1 \n \0 - - ~../config/startup.tal - - - &no-first-prompt - pstr: \enable-braketed-paste \0 - ;REPL .Console/vector DEO2 - BRK + ( + @|setup ) + ( + &|metadata ) + ;meta #06 DEO2 + ( + &|symbols ) + ( Move the symbols before the input buffer. ) + ;tail/end ;tail SUB2 STH2k #0000 ;head #0000 ( | len* ) + ;syms STH2kr SUB2 STH2k mcpyl ( | len* dst* ) + SWP2r STH2r #0000 ;head mzero ( | dst* ) + ( + &|pointers ) + STH2r ;tail-ptr STA2 ( | ) + ;head ;head-ptr STA2 + ;input ;input-ptr STA2 + ( + &|theme ) + \RED .System/r DEO2 + \GREEN .System/g DEO2 + \BLUE .System/b DEO2 + ( + @|startup ) + .PRINT-BANNER ?{ + } + free + ~../config/startup.tal + + &no-first-prompt + ;REPL .Console/vector DEO2 + BRK diff --git a/src/talos/main.talp b/src/talos/main.talp new file mode 100644 index 0000000..bc87cb5 --- /dev/null +++ b/src/talos/main.talp @@ -0,0 +1,61 @@ +( +@|talos/main ) + +@Main ( -> ) + ( + @|setup ) + + ( + &|metadata ) + ;meta #06 DEO2 + + ( + &|symbols ) + ( Move the symbols before the input buffer. ) + ;tail/end ;tail SUB2 STH2k #0000 ;head #0000 ( | len* ) + ;syms STH2kr SUB2 STH2k mcpyl ( | len* dst* ) + SWP2r STH2r #0000 ;head mzero ( | dst* ) + + ( + &|pointers ) + STH2r ;tail-ptr STA2 ( | ) + ;head ;head-ptr STA2 + ;input ;input-ptr STA2 + + ( + &|theme ) + \RED .System/r DEO2 + \GREEN .System/g DEO2 + \BLUE .System/b DEO2 + + #ifdef ANSI + pstr: [ + \bg-0 \fg-1 \clear-console-screen-right \n \n \n \n \n \n + \console-cursor-up \console-cursor-up \console-cursor-up + \console-cursor-up \console-cursor-up \console-cursor-up \0 ] + #endif + + ( + @|startup ) + .PRINT-BANNER ?{ + } + + #ifdef ANSI + pstr: \italic \underline \bold \fg-3 \0 + #endif + + free + + #ifdef ANSI + pstr: \reset-console-style \bg-0 \fg-1 \n \0 + #endif + + ~../config/startup.tal + + + &no-first-prompt + #ifdef ANSI + pstr: \enable-braketed-paste \0 + #endif + ;REPL .Console/vector DEO2 + BRK