add exported block sets (in konilo basic editor format)

This commit is contained in:
crc 2024-05-24 19:33:29 +02:00
parent 22436db22f
commit 2ad825803f
5 changed files with 1360 additions and 0 deletions

272
exported/bos.txt Normal file
View file

@ -0,0 +1,272 @@
0 (bos)
1
2 . BOS is a "block operating system". It's intended to provide a
3 . number of little utilities for working with the Konilo blocks.
4 .
5 . It is intended that this will eventually replace (nonix) with
6 . something less like Unix.
7
8
9
10
11
12
13
14
15
save next new
0 (bos)
1
2 . BOS follows my personal approach to blocks. In this the first
3 . line is the block title. This will have the block name as the
4 . first element, with optional text following. For code, these a
5 . setup as "(name) (comments)", and for data, they are done as
6 . "name comments".
7 .
8 . It's best to keep names short. I find that a max of 20 seems
9 . sufficient to provide unique names to the blocks but still be
10 . easy to type in.
11 .
12 . Multiple blocks with the same name are considered a block set.
13 . This might be similar to a file in more traditional operating
14 . systems.
15
save next new
0 (bos) (directory-listing)
1
2 . I am using a two column display. These pad the columns and
3 . add new lines as needed.
4
5 #1 '~NL var-n
6 :~nl @~NL #2 eq? [ nl #0 !~NL ] if &~NL v:inc ;
7 :~pad #32 block:name s:length n:sub &sp times ;
8
9 :bos:display block:name s:put ~pad ~nl ;
10
11 . Block sets for programs have names starting with a (
12
13 :bos:program? block:name #0 s:fetch $( eq? ;
14
15
save next new
0 (bos) (directory-listing)
1
2 . Display a program listing. This is a top-level combinator;
3 . pass in a quote to do the actual display operation.
4
5 :bos:dir (q-)
6 [ block:set:init #1 !NL
7 [ drop block:set:known?
8 [ block:set:add dup call ] -if ]
9 block:for-each drop nl ] gc ;
10
11
12
13
14
15
save next new
0 (bos) (directory-listing)
1
2 . Display all sets.
3
4 :dir:sets
5 [ bos:display ] bos:dir ;
6
7 :dir:programs
8 [ bos:program? &bos:display if ] bos:dir ;
9
10 :dir:text
11 [ bos:program? &bos:display -if ] bos:dir ;
12
13 :dir:t
14 [ block:name '.txt s:ends-with? &bos:display if ] bos:dir ;
15
save next new
0 (bos) (find-blocks-for-set)
1
2 :~match? (sa-sf) drop block:name over s:eq? ;
3 :~record (f-) [ @Block comma ] if ;
4 :~finish (as-a) drop here n:dec over n:sub over store a:temp ;
5
6 :bos:blocks-for (s-a)
7 [ s:keep here swap #0 comma
8 [ ~match? ~record ] block:for-each ~finish ] gc ;
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 (LOAD:bos)
1
2 '(bos) needs
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new

272
exported/drawing.txt Normal file
View file

@ -0,0 +1,272 @@
0 ilo + graphics extensions
1
2 ilo/g is an ilo with support for simple monochrome graphics.
3
4 This provides a monochrome, bitmap display with support for
5 the (termina) vocabulary. The extensions here provide a word
6 for drawing pixels, and later other shapes.
7
8 To load:
9
10 * crc:drawing
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 (crc:drawing) (interface-to-framebuffer)
1
2 :pixel (xyc-) #33 io ;
3 :get-pixel (xy-c) #34 io ;
4
5 :mouse (-xyb) #35 io ;
6
7
8
9
10
11
12
13
14
15
save next new
0 (crc:drawing) (simple-lines)
1
2 #1 'Color var-n
3 :set-color (n-) !Color ;
4
5 :hline (xyw-)
6 [ dup-pair @Color pixel &n:inc dip ] times drop-pair ;
7
8 :vline (xyh-)
9 [ dup-pair @Color pixel n:inc ] times drop-pair ;
10
11 :dline\ (xyl-)
12 [ dup-pair @Color pixel &n:inc bi@ ] times drop-pair ;
13
14 :dline/ (xyl-)
15 [ dup-pair @Color pixel &n:dec &n:inc bi* ] times drop-pair ;
save next new
0 (crc:drawing) (rect)
1
2 'X var 'Y var 'H var 'W var
3
4 :rect (xyhw-) !W !H !Y !X
5 @X @Y @W hline @X @Y @H n:add @W hline
6 @X @Y @H vline @X @W n:add @Y @H vline
7 ;
8
9
10
11
12
13
14
15
save next new
0 (crc:drawing) (circles)
1
2 'XC var 'YC var 'X var 'Y var
3
4 :octant (xc,yc,x,y)
5 !Y !X !YC !XC
6 @XC @X n:add @YC @Y n:add @Color pixel
7 @XC @X n:sub @YC @Y n:add @Color pixel
8 @XC @X n:add @YC @Y n:sub @Color pixel
9 @XC @X n:sub @YC @Y n:sub @Color pixel
10 @XC @Y n:add @YC @X n:add @Color pixel
11 @XC @Y n:sub @YC @X n:add @Color pixel
12 @XC @Y n:add @YC @X n:sub @Color pixel
13 @XC @Y n:sub @YC @X n:sub @Color pixel ;
14
15
save next new
0 (crc:drawing) (circles)
1
2 'XC var 'YC var 'X var 'Y var 'D var 'R var
3
4 :circle (xyr-)
5 !R !YC !XC #0 !X @R [ !Y ] [ !D ] bi
6 @XC @YC @X @Y octant
7 [ &X v:inc
8 @D n:strictly-positive?
9 [ &Y v:dec @X @Y n:sub @R n:mul #2 n:mul @D n:add !D ]
10 [ #2 @R n:mul @X n:mul @D n:add !D ] choose
11 @XC @YC @X @Y octant
12 @Y @X gteq? ] while ;
13
14
15
save next new
0 (crc:drawing) (line)
1
2 'X var 'Y var 'DX var 'DY var 'SX var 'SY var 'ROT var
3 'T var 'S var 'A var 'E var 'B var
4 'X1 var 'Y1 var 'X2 var 'Y2 var
5
6 :~setup (xy,xy-)
7 !Y2 !X2 !Y1 !X1 @X1 !X @Y1 !Y
8 @X2 @X1 n:sub n:abs !DX @Y2 @Y1 n:sub n:abs !DY
9 @X2 @X1 n:sub n:sign !SX
10 @Y2 @Y1 n:sub n:sign !SY
11 @DY @DX gt? n:abs !ROT
12 @ROT [ @DX !T @DY !S ] [ @DY !T @DX !S ] choose
13 @T #1 shift-left !A @A @S n:sub !E
14 @T @S n:sub #1 shift-left !B ;
15
save next new
0 (crc:drawing) (line)
1
2 :line (x1,y1,x2,y2-)
3 ~setup @X @Y @Color pixel
4 @S [
5 @E n:positive? [ @B ] [ @A ] choose @E n:add !E
6 @E n:positive? @ROT or [ @SY ] [ #0 ] choose @Y n:add !Y
7 @E n:positive? @ROT not or [ @SX ] [ #0 ] choose @X n:add !X
8 @X @Y @Color pixel
9 ] times ;
10
11
12
13
14
15
save next new
0 (crc:drawing) (triangle)
1
2 :triangle (x1,y1,x2,y2,x3,y3-)
3 'abcdef 'abcdefabcd reorder line
4 'abcdef 'abcdefefcd reorder line
5 'abcdef 'abef reorder line ;
6
7
8
9
10
11
12
13
14
15
save next new
0 (crc:turtle)
1
2 'X var 'Y var 'C var 'D var 'R var
3
4 :t:raise #0 !C ;
5 :t:lower #1 !C ;
6
7 :t:left [ &X v:dec ] !D ;
8 :t:right [ &X v:inc ] !D ;
9 :t:up [ &Y v:dec ] !D ;
10 :t:down [ &Y v:inc ] !D ;
11 :t:at (xy-) !Y !X ;
12 :t:forward (n-) [ @X @Y @C pixel @D call ] times ;
13
14 #320 #240 t:at t:lower t:right
15
save next new
0 (crc:turtle)
1
2 :t:down-right [ &Y v:inc &X v:inc ] !D ;
3 :t:down-left [ &Y v:inc &X v:dec ] !D ;
4 :t:up-left [ &Y v:dec &X v:dec ] !D ;
5 :t:up-right [ &Y v:dec &X v:inc ] !D ;
6
7 'Rotations d:create #8 comma
8 &t:right comma &t:down-right comma &t:down comma
9 &t:down-left comma &t:left comma &t:up-left comma
10 &t:up comma &t:up-right comma
11
12 :t:rotate
13 &R v:inc @R #8 eq? [ #0 !R ] if &Rotations @R a:fetch call ;
14
15
save next new
0 '(LOAD:crc:turtle)
1
2 '(crc:turtle) needs
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 (ilo/x)
1
2 #20 [ #0 #0 #300 #300 I #10 n:mul n:sub line ] indexed-times
3 #20 [ #639 #0 #300 #300 I #10 n:mul n:sub line ] indexed-times
4
5 #300 #240 #100 circle
6
7
8
9
10
11
12
13
14
15
save next new
0 (ilo/x)
1
2 #300 'X var-n #200 'Y var-n #50 'R var-n
3 :test
4 [ c:get #0 set-color
5 @X @Y @R circle
6 dup $c eq? [ &X v:dec ] if
7 dup $t eq? [ &X v:inc ] if
8 dup $h eq? [ &Y v:dec ] if
9 dup $n eq? [ &Y v:inc ] if
10 dup $. eq? [ restart ] if
11 dup $p eq? [ &R v:inc ] if
12 dup $y eq? [ &R v:dec ] if
13 drop #1 set-color @X @Y @R circle ] forever
14 ;
15
save next new
0 (LOAD:crc:drawing)
1
2 '(crc:drawing) needs
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new

272
exported/kaute.txt Normal file
View file

@ -0,0 +1,272 @@
0 (kaute)
1
2 'ss:Sheet var
3
4 :ss:rows (-n) @ss:Sheet fetch ;
5 :ss:cols (-n) @ss:Sheet n:inc fetch ;
6 :ss:load (a-) !ss:Sheet ;
7 :ss:size (-n) ss:rows ss:cols n:mul ;
8 :ss:new (rc-a) here !ss:Sheet swap comma comma
9 ss:size #2 n:mul [ #0 comma ] times
10 @ss:Sheet ;
11 :ss:create (rcs-) d:create ss:new drop ;
12 :ss:offset (rc-n) swap ss:cols n:mul n:add ;
13 :ss:data (rc-a) ss:offset @ss:Sheet n:add #2 n:add ;
14 :ss:types (rc-a) ss:data ss:size n:add ;
15
save next new
0 (kaute)
1
2 :ss:store-n (nrc-) dup-pair [ [ ss:data store ] dip ] dip
3 ss:types #0 swap store ;
4 :ss:store-s (src-) dup-pair
5 [ [ ss:data &s:keep dip store ] dip ] dip
6 ss:types #1 swap store ;
7 :ss:store-a (nrc-) dup-pair [ [ ss:data store ] dip ] dip
8 ss:types #2 swap store ;
9
10 :ss:fetch (arc-vt) ss:data &fetch sip ss:size n:add fetch ;
11
12 :ss:action (rc-nt) ss:fetch #2 eq?
13 [ call ] [ drop #0 #0 ] choose ;
14
15
save next new
0 (kaute)
1
2 :~name (vr-vrs) over I n:to-s s:append ;
3 :~define (r-r) &dtc compile:call
4 &internal:lit comma
5 dup comma
6 &internal:lit comma
7 I comma
8 #0 comma ;
9
10
11 :ss:make-fields (rcv-)
12 '_ [ #0 s:store ] sip roll
13 [ ~name d:create ~define ] indexed-times drop-pair ;
14
15
save next new
0 (kaute)
1
2 #0 #5 $A ss:make-fields #1 #5 $B ss:make-fields
3 #2 #5 $C ss:make-fields #3 #5 $D ss:make-fields
4 #4 #5 $E ss:make-fields #5 #5 $F ss:make-fields
5 #6 #5 $G ss:make-fields #7 #5 $H ss:make-fields
6 #8 #5 $I ss:make-fields #9 #5 $J ss:make-fields
7 #10 #5 $K ss:make-fields #11 #5 $L ss:make-fields
8 #12 #5 $M ss:make-fields #13 #5 $N ss:make-fields
9 #14 #5 $O ss:make-fields
10
11 . Quick fetches to guarantee return type validity
12
13 :ss:fetch-n (rc-n) ss:fetch n:-zero? [ drop #0 ] if ;
14 :ss:fetch-s (rc-s) ss:fetch #1 -eq? [ drop '_ ] if ;
15 :ss:fetch-a (rc-a) ss:fetch #2 -eq? [ drop [ ] ] if ;
save next new
0 (kaute)
1
2 :ss:NUMBER #0 ;
3 :ss:STRING #1 ;
4 :ss:ACTION #2 ;
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 kaute : a headless spreadsheet : overview
1
2 The kaute vocabulary provides support for creating and working
3 with data stored in a spreadsheet format. It primarily provides
4 functionality, not presentation.
5
6
7
8
9
10
11
12
13
14
15
save next new
0 kaute : a headless spreadsheet : data structure
1
2 In memory, a sheet is structured as:
3
4 rows
5 columns
6 ... ( rows cells * ) ... data
7 ... ( rows cells * ) ... types
8
9
10
11
12
13
14
15
save next new
0 kaute : a headless spreadsheet : data types
1
2 # Types
3
4 Kaute currently supports three types of data in a cell:
5
6 - numbers
7 - pointers to strings
8 - pointers to actions
9
10
11
12
13
14
15
save next new
0 kaute : a headless spreadsheet : actions
1
2 # Actions
3
4 Action cells are written as quotes, which return a value & type
5 pair. An example might look like:
6
7 [ A1 ss:fetch-n A2 ss:fetch-n n:mul ss:NUMBER ]
8
9
10
11
12
13
14
15
save next new
0 kaute : a headless spreadsheet : strings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 kaute : a headless spreadsheet : numbers
1
2 Most cells contain numbers. These are just standard numeric
3 values, and can be in any format that fits in a cell. I mostly
4 use simple integers, but do sometimes make use of scaled values.
5
6 It might be of interest to expand this, to separate out the use
7 of integers, scaled values, and dusk's fixed & floating point
8 values. I'm not going to work on this for now (May 2024).
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 (LOAD:kaute)
1
2 '(kaute) needs
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new

272
exported/teensy4.txt Normal file
View file

@ -0,0 +1,272 @@
0 Teensy 4.1 - I/O Extensions
1
2 . This vocabulary provides words for using the additional I/O
3 . on the Teensy 4.1 implementation of ilo.
4
5 . Currently this covers reading/writing the GPIO pins and the
6 . RTC. Other devices are expected to be added in the future.
7
8
9
10
11
12
13
14
15
save next new
0 (teensy4.1)
1
2 . These blocks add words for interacting with the i/o on the
3 . Teensy 4.1
4
5 :teensy:io (...n-) #100 io ;
6
7 :pin:high (n-) #1 teensy:io ;
8 :pin:low (n-) #2 teensy:io ;
9 :pin:mode (nm-) #3 teensy:io ;
10 :pin:read (n-m) #4 teensy:io ;
11
12 :delay/ms (n-) #10 teensy:io ;
13 :delay/us (n-) #11 teensy:io ;
14 :delay/ns (n-) #12 teensy:io ;
15
save next new
0 (teensy4.1)
1
2 . The Teensy has a real time clock. The words here allow you to
3 . make use of this.
4
5 :rtc:hour (-n) #20 teensy:io ;
6 :rtc:minute (-n) #21 teensy:io ;
7 :rtc:second (-n) #22 teensy:io ;
8 :rtc:day (-n) #23 teensy:io ;
9 :rtc:month (-n) #24 teensy:io ;
10 :rtc:year (-n) #25 teensy:io ;
11 :rtc:set (hmsdmy-) #26 teensy:io ;
12 :rtc:adjust (n-) #27 teensy:io ;
13
14
15
save next new
0 (teensy4.1)
1
2 &pin:high \pin:on
3 &pin:low \pin:off
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new

272
exported/x86.txt Normal file
View file

@ -0,0 +1,272 @@
0 (ilo:x86) (port_io,_physical_memory)
1
2 :pio:inb (n-c) #0 #100 io ;
3 :pio:inw (n-n) #1 #100 io ;
4 :pio:outb (vn-) #2 #100 io ;
5 :pio:outw (vn-) #3 #100 io ;
6
7 :mem:fetch-byte (a-c) #0 #101 io ;
8 :mem:store-byte (ca-) #1 #101 io ;
9 :mem:fetch (a-n) #2 #101 io ;
10 :mem:store (na-) #3 #101 io ;
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 (ilo:x86) (cmos,_rtc)
1
2 :CMOS:ADDRESS #112 ;
3 :CMOS:DATA #113 ;
4
5 :rtc:query CMOS:ADDRESS pio:outb CMOS:DATA pio:inb ;
6 :rtc:second #0 rtc:query ;
7 :rtc:minute #2 rtc:query ;
8 :rtc:hour #4 rtc:query ;
9 :rtc:day #7 rtc:query ;
10 :rtc:month #8 rtc:query ;
11 :rtc:year #9 rtc:query ;
12
13 :.time rtc:hour n:put $: c:put rtc:minute n:put nl ;
14
15
save next new
0 (ilo:x86) (serial)
1
2 :serial:COM1 #1016 ; :serial:COM2 #760 ;
3 :serial:COM3 #1000 ; :serial:COM4 #744 ;
4 serial:COM1 'serial:Port var-n
5
6 :serial:recv? @serial:Port #5 n:add pio:inb #1 and n:-zero? ;
7 :serial:empty? @serial:Port #5 n:add pio:inb #32 and n:-zero? ;
8 :serial:read (-c)
9 [ serial:recv? [ @serial:Port pio:inb #-1 ] [ #0 ] choose
10 until ;
11 :serial:write (c-)
12 [ serial:empty? [ @serial:Port pio:outb #-1 ] [ #0 ] choose ]
13 until ;
14 :serial:send (s-) [ serial:write ] s:for-each ;
15
save next new
0 (ilo:x86) (serial)
1
2 :serial:init
3 #0 @serial:Port #1 n:add pio:outb
4 #128 @serial:Port #3 n:add pio:outb
5 #3 @serial:Port pio:outb
6 #0 @serial:Port #1 n:add pio:outb
7 #3 @serial:Port #3 n:add pio:outb
8 #199 @serial:Port #2 n:add pio:outb
9 #11 @serial:Port #4 n:add pio:outb ;
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new
0 (LOAD:x86)
1
2 '(ilo:x86) needs
3
4
5
6
7
8
9
10
11
12
13
14
15
save next new