Part of it is that I'm using only a small portion of 64k for my heap.
And part of it is that my first stab at compiling if's actually
compiles the true and false clauses twice each - once to get the size
and once to emit the machine code.  And both cases end up consing the
same amount.

That's why I recommended taking care of either patching in a loader or labels in a linker, before getting to the compiler layer.

If you have either of those[0] then the compiler can be a very simple iterative reduction, streaming source in and object out.

(although if one really wished to be recursive, it's certainly possible to generate code on the way down then splice in offsets on the way back up)

In http://canonical.org/~kragen/sw/urscheme/ I still haven't implemented
the garbage collector.  But I think it only allocates a meg or two of
memory before it finishes compiling itself, which isn't a big deal on
modern machines.  It might be a problem in MS-DOS, though.

Especially 64k .com files :)

IIRC, windows (and dos extenders) used to routinely get into flat protected mode from .com/.exe files.

It shouldn't take much.  The following[1] won't be too far off:
0000110: fa2e 0f01 1630 7d0f 20c0 0d01 000f 22c0  .....0}. .....".
0000120: ba10 008e c28e da8e d2ea 00c0 1800 cccc  ................
0000130: 2000 d07d 0000 0000 0000 0000 0000 0000   ..}............
0000140: ffff 0000 0092 cf00 ffff 0000 009a cf00  ................
after which you should be able to limp across the finish line with megs to spare.

I ended up doing things mostly stack-based, but mostly sticking to the
principle you discovered, "Start with the simplest thing that could
possibly work", so it's all ugly hacks just meant to limp across the
finish line to the next higher-level language that would be easy to
work with.

Anything worth doing is worth doing poorly at first :-)

-Dave

And quite often, you find yourself overreaching, trying to do too
much.  In this way, your stage N implemented with stage N-1 never
materializes and you need to fall back to stage N-1 and rethink stage
N to be less ambitious.


If you lose traction, downshift. If downshifting fails, go to low gears. When in doubt, lock the differential.

:: :: ::
[0] or if you had vectors in your scheme, you could even play games with keeping undefined references on a linked list in the object vector, fixing them up via random access as they resolve... [1] bytes 0x40-0x110 and 0x150-0x15c of this block do the hard work of groveling around in a FAT filesystem; this code to jump into a flat protected mode is only 64 bytes. You might eventually need to also mess with the A20 line, but that probably doesn't take as much space as the (unused) second entry in this GDT.

align 10,90
; == enter protected mode ==
cli                             ; turn off interrupts
                                ; load GDT (using CS override)
db 2e
lgdt gdt
                                ; set pmode bit in cr0
db 0f, 20, c0
or ax,1
db 0f, 22, c0
; load 32-bit data segment registers, and...
mov dx,10
mov es,dx
mov ds,dx
mov ss,dx
; ...far jump to load 32-bit code segment
jmp 18:c000

align 10
; // GDT //
l gdt
db 20, 00, d0, 7d, 00, 00, 00, 00
db 00, 00, 00, 00, 00, 00, 00, 00
db ff, ff, 00, 00, 00, 92, cf, 00
db ff, ff, 00, 00, 00, 9a, cf, 00


--
To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-discuss

Reply via email to