duskos

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

commit e2a4ed86a6c8fe824f538ca7b3684b0f237de1cc
parent cd7d534ad2ba92363e8b3d0806ea389404ea703b
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed,  1 Jun 2022 13:51:40 -0400

Add value and constant

Diffstat:
MMakefile | 3++-
Mdusk.asm | 33+++++++++++++++++++++++++++++++--
Mf2asm.py | 30++++++++++++++++++++++++------
Mword_macros.asm | 17+++++++++++++++++
Mwords/adec.asm | 2--
Mxcomp2.txt | 7++++++-
6 files changed, 80 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,8 @@ TARGETS = dusk WORDOBJS = xcomp.o $(addsuffix .o,$(addprefix words/, \ bye emit drop dup swap over rot \ - aset aget acfetch acstore ainc adec)) + aset aget acfetch acstore ainc adec \ + to)) all: $(TARGETS) diff --git a/dusk.asm b/dusk.asm @@ -1,14 +1,25 @@ ; PSP=ebp RSP=esp BITS 32 -%define PS_SZ 4096 -%define RS_SZ 4096 +%define PS_SZ 0x1000 +%define RS_SZ 0x1000 +%define MEMSIZE 0x40000 SECTION .bss GLOBAL areg areg: resd 1 +GLOBAL toflag +toflag: resb 1 resd RS_SZ +GLOBAL current +current: resd 1 +GLOBAL here +here: resd 1 +GLOBAL compiling +compiling: resd 1 rs_top: resd PS_SZ ps_top: +herestart: resb MEMSIZE + SECTION .text GLOBAL _start @@ -16,6 +27,10 @@ _start: cld mov esp, rs_top mov ebp, ps_top + mov byte [toflag], 0 + mov dword [here], herestart + EXTERN word_lastxcomp + mov dword [current], word_lastxcomp EXTERN word_boot jmp word_boot @@ -24,3 +39,17 @@ cellword: pop eax pspush eax ret + +GLOBAL to_is_set +to_is_set: ; eax=cell addr + mov byte [toflag], 0 + pspop ebx + mov [eax], ebx + ret + +GLOBAL aliasword +aliasword: + pop eax + test byte [toflag], 0xff + jnz to_is_set + jmp [eax] diff --git a/f2asm.py b/f2asm.py @@ -8,6 +8,7 @@ fp = open(sys.argv[1], 'r') prevword = 'asmlast' nasmmacros = {'ps2rs', 'rs2ps', 'rsget', 'rsdrop', 'a2rs', 'rs2a'} +anoncount = 0 # avoid label redefinitions aliases = { '>r': 'ps2rs', 'r>': 'rs2ps', @@ -54,6 +55,7 @@ def nextt(): def newword(name=None, imm=False): global prevword + global anoncount if not name: name = nextt() count = len(name) @@ -61,8 +63,12 @@ def newword(name=None, imm=False): count |= 0x80 alias = aliases.get(name, name) knownwords.add(alias) + if alias == '_': + anoncount += 1 + alias = f'_{anoncount}' out(f"defword '{name}', {count}, word_{alias}, word_{prevword}\n") prevword = alias + return alias def newwordimm(): newword(imm=True) @@ -117,17 +123,20 @@ def _create_(): newword() out('call cellword\n') -def _value_(): +def _sysval_(): + alias = newword() + out(f'sysval {alias}\n') + +def _const_(): newword() - out('call valword\n') - n = litparse(nextt()) - out(f'db {n}\n') + val = litparse(nextt()) + out(f'constant {val}\n') def _alias_(): newword() out('call aliasword\n') initial_tgt = nextt() - out(f'db word_{initial_tgt}\n') + out(f'dd word_{initial_tgt}\n') def _opwriter_(): out('TODO\n') @@ -157,7 +166,8 @@ special = { 'until': _until_, 'next': _next_, 'create': _create_, - 'value': _value_, + 'sysval': _sysval_, + 'const': _const_, 'alias': _alias_, 'opwriter': _opwriter_, 'callop': _callop_, @@ -167,6 +177,9 @@ special = { out("""; This file is autogenerated EXTERN cellword +EXTERN toflag +EXTERN to_is_set +EXTERN aliasword """) t = nextt() while t: @@ -182,9 +195,14 @@ while t: if name not in knownwords: out(f'EXTERN word_{name}\n') knownwords.add(name) + if name == '_': + name = f'_{anoncount}' out(f'call word_{name}\n') else: out(f'pspush {n}\n') t = nextt() fp.close() +newword('_') +out("EXTERN word_lastxcomp\n") +out("word_lastxcomp:\n") diff --git a/word_macros.asm b/word_macros.asm @@ -25,6 +25,21 @@ EXTERN %4 _word %1,%2,%3,%4 %endmacro +%macro sysval 1 ; lbl +EXTERN %1 +mov eax,%1 +test byte [toflag], 0xff +jnz to_is_set +mov eax,[eax] +pspush eax +ret +%endmacro + +%macro constant 1 ; val +pspush %1 +ret +%endmacro + %macro ps2rs 0 push dword [ebp] add ebp,4 @@ -34,3 +49,5 @@ add ebp,4 sub ebp,4 pop dword [ebp] %endmacro + +%define rsdrop pop eax diff --git a/words/adec.asm b/words/adec.asm @@ -1,6 +1,4 @@ defword 'A-', 2, word_adec, word_ainc -GLOBAL word_asmlast -word_asmlast: EXTERN areg dec dword [areg] ret diff --git a/xcomp2.txt b/xcomp2.txt @@ -1,3 +1,8 @@ +sysval current +sysval here +sysval compiling +const foo '!' + : 2drop drop drop ; : 2dup over over ; : nip swap drop ; @@ -7,4 +12,4 @@ : Ac@+ Ac@ A+ ; : Ac!+ Ac! A+ ; create _ ," foo" -: boot _ >A Ac@+ emit Ac@+ emit Ac@+ emit bye ; +: boot _ >A Ac@+ emit Ac@+ emit Ac@+ emit foo emit bye ;