duskos

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

commit 433fcb16aab9e245e2edd1d105b76d91cf6768a2
parent d560889338cf6aa43162dd3a9b24264e2ef30114
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed,  1 Jun 2022 13:51:41 -0400

Add parse

Diffstat:
Maliases.txt | 27++++++---------------------
Mdusk.asm | 51++++++++++++++++++++++++++++++++++++++++-----------
Mf2asm.py | 18+++++++++++++-----
Mxcomp2.txt | 18++++++++++++++++++
4 files changed, 77 insertions(+), 37 deletions(-)

diff --git a/aliases.txt b/aliases.txt @@ -4,29 +4,16 @@ r@ rsget r~ rsdrop + add - sub -A>r a2rs -r>A rs2a +* mul +A>r A2rs +r>A rs2A rot> rotr ->A aset -A> aget -Ac@ acfetch -Ac! acstore -A+ ainc -A- adec -Ac@+ acfetchplus -Ac!+ acstoreplus +>A Aset +A> Aget in> inptr 'curword curwordaddr 1+ inc 1- dec -c@ cfetch -c! cstore -@ fetch -! store -c@+ cfetchplus -c!+ cstoreplus -, write -c, cwrite = eq < lt > gt @@ -40,9 +27,7 @@ c, cwrite << shl >> shr move, movewr -?dup cdup -ws? wsc boot< bootrd in<? inrdc in< inrd -word! wordset +[c]? findchar diff --git a/dusk.asm b/dusk.asm @@ -47,6 +47,9 @@ pop dword [ebp] %define rsdrop pop eax +%define A2rs push dword [areg] +%define rs2A pop dword [areg] + %macro _begin_ 0 %push begin %$begin: @@ -152,7 +155,11 @@ defword 'bye', 3, word_bye, 0 mov ebx,0 ; exit with error code 0 int 80h ; call the kernel -defword 'emit', 4, word_emit, word_bye +defword 'exit', 4, word_exit, word_bye + pop eax + ret + +defword 'emit', 4, word_emit, word_exit mov eax,4 ; 'write' syscall mov ebx,1 ; stdout mov ecx,ebp ; top of PS, little endian @@ -171,11 +178,11 @@ defword 'dup', 3, word_dup, word_drop mov [ebp], eax ret -defword '?dup', 4, word_cdup, word_drop +defword '?dup', 4, word_conddup, word_drop test dword [ebp], -1 jnz word_dup -defword 'swap', 4, word_swap, word_cdup +defword 'swap', 4, word_swap, word_conddup mov eax, [ebp] mov ebx, [ebp+4] mov [ebp], ebx @@ -197,37 +204,37 @@ defword 'rot', 3, word_rot, word_over mov [ebp+8], ebx ret -defword '>A', 2, word_aset, word_rot +defword '>A', 2, word_Aset, word_rot pspop eax mov [areg], eax ret -defword 'A>', 2, word_aget, word_aset +defword 'A>', 2, word_Aget, word_Aset mov eax, [areg] pspush eax ret -defword 'Ac@', 3, word_acfetch, word_aget +defword 'Ac@', 3, word_Acfetch, word_Aget mov eax, [areg] mov eax, [eax] pspush eax ret -defword 'Ac!', 3, word_acstore, word_acfetch +defword 'Ac!', 3, word_Acstore, word_Acfetch pspop eax mov eax, [areg] mov [eax], eax ret -defword 'A+', 2, word_ainc, word_acstore +defword 'A+', 2, word_Ainc, word_Acstore inc dword [areg] ret -defword 'A-', 2, word_adec, word_ainc +defword 'A-', 2, word_Adec, word_Ainc dec dword [areg] ret -defword 'to', 2, word_to, word_adec +defword 'to', 2, word_to, word_Adec mov byte [toflag], 1 ret @@ -274,7 +281,29 @@ defword '-', 1, word_sub, word_add sub [ebp], eax ret -defword 'not', 3, word_not, word_sub +defword '*', 1, word_mul, word_sub + pspop eax + mov ebx, [ebp] + mul ebx + mov [ebp], eax + ret + +defword 'and', 3, word_and, word_mul + pspop eax + and [ebp], eax + ret + +defword 'or', 2, word_or, word_and + pspop eax + or [ebp], eax + ret + +defword 'xor', 3, word_xor, word_or + pspop eax + xor [ebp], eax + ret + +defword 'not', 3, word_not, word_xor word_asmlast: sub dword [ebp],1 ; carry=1 if 0 set_PS_to_carry: ; set PS top to 0 or one depending on CF diff --git a/f2asm.py b/f2asm.py @@ -7,7 +7,7 @@ import struct fp = open(sys.argv[1], 'r') prevword = 'asmlast' -nasmmacros = {'ps2rs', 'rs2ps', 'rsget', 'rsdrop', 'a2rs', 'rs2a'} +nasmmacros = {'ps2rs', 'rs2ps', 'rsget', 'rsdrop', 'A2rs', 'rs2A'} anoncount = 0 # avoid label redefinitions pairs = (line.split() for line in open('aliases.txt', 'r').read().splitlines()) aliases = {name: alias for name, alias in pairs} @@ -27,6 +27,15 @@ def litparse(s): pass return None +def getalias(name): + if name in aliases: + return aliases[name] + if name.isalnum(): + return name + for c, repl in (('@', 'fetch'), ('!', 'store'), ('+', 'inc'), ('-', 'dec'), (',', 'write'), ('?', 'cond')): + name = name.replace(c, repl) + return name + def nextt(): r = '' c = fp.read(1) @@ -45,7 +54,7 @@ def newword(name=None, imm=False): count = len(name) if imm: count |= 0x80 - alias = aliases.get(name, name) + alias = getalias(name) if alias == '_': anoncount += 1 alias = f'_{anoncount}' @@ -128,8 +137,7 @@ def _syscell_(): def _alias_(): newword() out('call aliasword\n') - t = nextt() - initial_tgt = aliases.get(t, t) + initial_tgt = getalias(nextt()) out(f'dd word_{initial_tgt}\n') def _opwriter_(): @@ -176,7 +184,7 @@ while t: else: n = litparse(t) if n is None: - name = aliases.get(t, t) + name = getalias(t) if name in nasmmacros: out(f'{name}\n') else: diff --git a/xcomp2.txt b/xcomp2.txt @@ -40,4 +40,22 @@ alias in< boot< toword in> 1- 0 ( sa sl ) begin 1+ in<? ws? until then ( sa sl ) 2dup 0 rot> _ ; : word! 1 rot> _ ; +: [c]? ( c a u -- i ) \ Guards A + ?dup not if 2drop -1 exit then A>r over >r >r >A ( c ) + begin dup Ac@+ = if leave then next ( c ) + A- Ac@ = if A> r> - ( i ) else r~ -1 then r>A ; +: _ ( sl -- n? f ) \ parse unsigned decimal + >r 0 begin ( r ) + 10 * Ac@+ ( r c ) '0' - dup 9 > if + 2drop r~ 0 exit then + next ( r ) 1 ; +create tbl-0-f ," 0123456789abcdef" +: parse ( sa sl -- n? f ) \ *A* + over c@ ''' = if ( sa sl ) + 3 = if 1+ dup 1+ c@ ''' = if c@ 1 exit then then + drop 0 exit then ( sa sl ) + over c@ '$' = if ( sa sl ) 1- >r 1+ >A 0 begin ( r ) + 16 * Ac@+ ( r c ) $20 or tbl-0-f $10 [c]? + dup 0< if 2drop r~ 0 exit then + next ( r ) 1 exit then + swap >A dup 1 > Ac@ '-' = and if ( sl ) + A+ 1- _ if 0 -^ 1 else 0 then else _ then ; : boot S" Dusk OS" stype bye ;