duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 6edf52ea71bbfd6f2f8f25796458e3ef25e823e2
parent 22a1770aff6c3bfc305dafc52311934e49a07c02
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed,  6 Jul 2022 14:47:10 -0400

Move autoloading code to boot

Also, leverage autoloading better by making each unit autoload the libraries it
needs locally.

Initially, before there was autoloading, I was geared towards central "loader"
units, but that pattern has no reason to exist now.

Diffstat:
Mfs/cc/ast.fs | 5++++-
Mfs/cc/cc.fs | 20+++++++++-----------
Dfs/cc/cc1.fs | 10----------
Mfs/cc/gen.fs | 4+++-
Mfs/cc/io.fs | 1+
Mfs/cc/tok.fs | 1+
Mfs/cc/type.fs | 3++-
Mfs/cc/vm.fs | 2+-
Mfs/fs/fat.fs | 1+
Mfs/init.fs | 2--
Mfs/lib/annotate.fs | 3++-
Mfs/sys/doc.fs | 2++
Mfs/sys/file.fs | 6------
Mfs/tests/fs/fat.fs | 1-
Mfs/xcomp/boothi.fs | 9+++++----
Mfs/xcomp/bootlo.fs | 5+++++
Mfs/xcomp/glue1.fs | 1+
Mfs/xcomp/glue2.fs | 1+
18 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -1,7 +1,10 @@ \ C compiler Abstract Syntax Tree -\ requires cc/tok cc/tree cc/type \ An abstract syntax tree, AST, is a hierarchical structure of nodes \ representing the nodes found in a C source file. See tree.fs for structure. +?f<< lib/wordtbl.fs +?f<< cc/tok.fs +?f<< cc/tree.fs +?f<< cc/type.fs \ Unary operators 7 const UOPSCNT diff --git a/fs/cc/cc.fs b/fs/cc/cc.fs @@ -1,15 +1,13 @@ +\ C compiler require sys/scratch.fs require sys/xhere.fs 1 value _debug -?f<< lib/str.fs -?f<< lib/wordtbl.fs -?f<< lib/xdict.fs -?f<< asm.fs -?f<< cc/io.fs -?f<< cc/vm.fs -?f<< cc/tok.fs -?f<< cc/type.fs -?f<< cc/tree.fs -?f<< cc/ast.fs ?f<< cc/gen.fs -?f<< cc/cc1.fs + +\ Compiles input coming from the stdin alias and writes the +\ result to here. Aborts on error. +: cc1, ( -- ) + xhere$ xhere[ parseast curunit _debug if dup printast nl> then ]xhere + gennode ; + +: cc1<< ( -- ) word fopen dup [f<] to stdin cc1, fclose ; diff --git a/fs/cc/cc1.fs b/fs/cc/cc1.fs @@ -1,10 +0,0 @@ -\ C compiler stage 1 -\ Requires cc/gen.fs, cc/ast.fs, asm.fs and wordtbl.fs - -\ Compiles input coming from the stdin alias and writes the -\ result to here. Aborts on error. -: cc1, ( -- ) - xhere$ xhere[ parseast curunit _debug if dup printast nl> then ]xhere - gennode ; - -: cc1<< ( -- ) word fopen dup [f<] to stdin cc1, fclose ; diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs @@ -1,5 +1,4 @@ \ C compiler code generation -\ Requires wordtbl cc/vm cc/ast \ Code generation @@ -45,6 +44,9 @@ \ 5. restore the result to Op1. \ cc/vm abstracts away the save/restore mechanism through oppush/oppop. +?f<< lib/wordtbl.fs +?f<< cc/vm.fs +?f<< cc/ast.fs : _err ( -- ) abort" gen error" ; : _assert ( f -- ) not if _err then ; diff --git a/fs/cc/io.fs b/fs/cc/io.fs @@ -1,4 +1,5 @@ \ C compiler I/O words +?f<< lib/io.fs alias stdin cc< 0 value putback diff --git a/fs/cc/tok.fs b/fs/cc/tok.fs @@ -4,6 +4,7 @@ \ TODO: actually implement this. As of now, tok is the string that was read. \ 1b token type id \ xb string having been read +?f<< cc/io.fs 0 const TOK_KEYWORD 1 const TOK_IDENTIFIER diff --git a/fs/cc/type.fs b/fs/cc/type.fs @@ -1,5 +1,6 @@ \ C compiler types -\ Requires lib/str cc/tok +?f<< lib/str.fs +?f<< cc/tok.fs \ All information related to a basic type fits in a 32b integer, so that's \ how "type" is passed around. Structure: diff --git a/fs/cc/vm.fs b/fs/cc/vm.fs @@ -1,5 +1,4 @@ \ C compiler virtual machine -\ Requires asm \ The goal of this VM is to provide a unified API for code generation of a C \ AST across CPU architecture. @@ -40,6 +39,7 @@ \ error. To set the operand when it's not None is also an error. \ For usage example, see tests/cc/vm.fs +?f<< asm.fs : _err abort" vm error" ; : _assert not if _err then ; diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs @@ -10,6 +10,7 @@ \ For now, this FS only supports FAT16 and FAT12. \ Like any filesystem in Dusk, path separator char is "/". +?f<< fs/fatlo.fs $ffff const EOC diff --git a/fs/init.fs b/fs/init.fs @@ -1,6 +1,4 @@ \ Initialization layer. Called at the end of boot.fs -f<< lib/dict.fs -f<< lib/annotate.fs f<< sys/doc.fs f<< lib/io.fs f<< sys/scratch.fs diff --git a/fs/lib/annotate.fs b/fs/lib/annotate.fs @@ -1,5 +1,6 @@ \ Annotations -\ requires lib/dict +?f<< lib/dict.fs + : (annotate) ( w -- w' ) current dup preventry to current >r dup preventry r@ preventry! diff --git a/fs/sys/doc.fs b/fs/sys/doc.fs @@ -1,3 +1,5 @@ +?f<< lib/annotate.fs + create doc-magic 2 c, 127 c, 'D' c, : _ doc-magic entry begin in< dup c, LF = until ; diff --git a/fs/sys/file.fs b/fs/sys/file.fs @@ -23,11 +23,5 @@ : [f<] ( curfd -- word ) scratch[ litn compile fgetc exit, ]scratch ; -\ Autoloading - -: floaded? ( str -- f ) - floaded begin dup while 2dup 4 + - s= if 2drop 1 exit then @ repeat 2drop 0 ; : .floaded floaded begin dup while dup 4 + stype nl> @ repeat drop ; -: ?f<< word dup floaded? if drop else fload then ; : require word dup floaded? not if stype abort" required" else drop then ; diff --git a/fs/tests/fs/fat.fs b/fs/tests/fs/fat.fs @@ -4,7 +4,6 @@ \ 3. It has only one FAT (no backup FAT) \ 4. It has a 512 sector size ?f<< tests/harness.fs -?f<< fs/fatlo.fs ?f<< fs/fat.fs : readN ( fcursor n -- ) >r begin dup fatgetc drop next drop ; testbegin diff --git a/fs/xcomp/boothi.fs b/fs/xcomp/boothi.fs @@ -1,14 +1,15 @@ 0 value curfd \ file descriptor of the file currently being read -0 value floaded \ address of the current "loaded file" structure 0 value fecho : f< ( -- c ) curfd fgetc fecho if dup emit then ; : fload ( fname -- ) - floaded here to floaded , ( fname ) - dup c@ 1+ move, ( ) - curfd >r + floaded, curfd >r floaded 4 + fopen to curfd to' in< @ >r ['] f< to in< begin maybeword ?dup if runword 0 else 1 then until r> to in< curfd fclose r> to curfd ; : f<< word fload ; +: floaded? ( str -- f ) + floaded begin dup while 2dup 4 + + s= if 2drop 1 exit then @ repeat 2drop 0 ; +: ?f<< word dup floaded? if drop else fload then ; f<< init.fs diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -100,5 +100,10 @@ alias else endof immediate \ Return whether strings s1 and s2 are equal : s= ( s1 s2 -- f ) over c@ 1+ []= ; +\ Autoloading +0 value floaded \ address of the current "loaded file" structure +: floaded, ( fname -- ) + floaded here to floaded , ( fname ) dup c@ 1+ move, ; + \ doc comment placeholder alias \ \\ diff --git a/fs/xcomp/glue1.fs b/fs/xcomp/glue1.fs @@ -1,4 +1,5 @@ \ Glue code between the storage driver and the FS handler +S" drv/ramdrive.fs" floaded, fatfs( to ramdrv( RAMDRVSECSZ const drvblksz alias ramdrv@ (drv@) diff --git a/fs/xcomp/glue2.fs b/fs/xcomp/glue2.fs @@ -1,4 +1,5 @@ \ Glue code that goes between the filesystem part and boothi +S" fs/fatlo.fs" floaded, alias fatopen fopen alias fatgetc fgetc alias fatclose fclose