meta: cosmetix
[urforth.git] / level1 / urforth.f
blobadde93a984f4da8a2d425e20fb1d035b05c80516
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level 1: self-hosting 32-bit Forth compiler
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
4 ;; GPLv3 ONLY
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 format ELF executable 3
8 $entry urforth_entry_point
10 ;; this is defined by the target compiler
11 ;;urforth_code_base_addr equ $
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 URFORTH_DEBUG equ URFORTH_DEBUGGER_ENABLED
15 URFORTH_EXTRA_STACK_CHECKS equ 0
17 ;; various compile-time options
18 WLIST_HASH_BITS equ 6
20 ;; size in items
21 DSTACK_SIZE equ 65536
22 RSTACK_SIZE equ 65536
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;; register usage:
27 ;; ebp: return stack
28 ;; esp: data stack
29 ;; esi: instruction pointer
30 ;; ecx: TOS
32 ;; direction flag must NOT be set!
33 db "Alice!"
35 ;; let it always be here
36 $if URFORTH_DEBUG
37 ;; universal dispatcher for "next" command
38 ;; debugger will patch jump to itself here
39 ;; when debugger is not active, this will be simple "jmp eax"
40 ;; startup code will patch it to "jmp eax"
41 ;; reserve 32 bytes for this, because why not?
42 $align 32,0
43 $label urforth_next
44 $asm db 0xff,0xe0
45 $asm rb 30
47 ;; breakpoint
48 $label urforth_next_ptr
49 dd urforth_next_normal
50 ;; normal next
51 $label urforth_next_normal
52 $asm jp eax
54 $endif
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 ;; some sanity checks
58 $if WLIST_HASH_BITS < 0
59 $error "invalid WLIST_HASH_BITS: should be [0..8]!"
60 $endif
62 $if WLIST_HASH_BITS > 8
63 $error "invalid WLIST_HASH_BITS: should be [0..8]"
64 $endif
66 ;; sorry! one day i'll implement shifts in asm evaluator
67 $if WLIST_HASH_BITS = 1
68 WLIST_HASH_MASK equ 0x01
69 WLIST_HASH_CELLS equ 2
70 $endif
72 $if WLIST_HASH_BITS = 2
73 WLIST_HASH_MASK equ 0x03
74 WLIST_HASH_CELLS equ 4
75 $endif
77 $if WLIST_HASH_BITS = 3
78 WLIST_HASH_MASK equ 0x07
79 WLIST_HASH_CELLS equ 8
80 $endif
82 $if WLIST_HASH_BITS = 4
83 WLIST_HASH_MASK equ 0x0f
84 WLIST_HASH_CELLS equ 16
85 $endif
87 $if WLIST_HASH_BITS = 5
88 WLIST_HASH_MASK equ 0x1f
89 WLIST_HASH_CELLS equ 32
90 $endif
92 $if WLIST_HASH_BITS = 6
93 WLIST_HASH_MASK equ 0x3f
94 WLIST_HASH_CELLS equ 64
95 $endif
97 $if WLIST_HASH_BITS = 7
98 WLIST_HASH_MASK equ 0x7f
99 WLIST_HASH_CELLS equ 128
100 $endif
102 $if WLIST_HASH_BITS = 8
103 WLIST_HASH_MASK equ 0xff
104 WLIST_HASH_CELLS equ 256
105 $endif
107 WLIST_HASH_BYTES equ WLIST_HASH_CELLS*4
110 ;; create "FORTH" vocabulary header first, because why not
111 $vocabheader "FORTH" forth_wordlist_vocid
113 $include 00_startup.f
114 $include 01_segfault_handler.f
115 $include 02_debugger.f
116 $include 03_do_codeblocks.f
117 $include 05_base_vars.f
118 $include 07_syscall.f
119 $include 08_termio_low.f
120 $include 10_litbase.f
121 $include 14_dstack.f
122 $include 15_rstack.f
123 $include 16_peekpoke.f
124 $include 17_dp.f
125 $include 18_simple_malloc.f
126 $include 19_dbg_info.f
127 $include 20_math_base.f
128 $include 21_math_compare.f
129 $include 22_math_muldiv.f
130 $include 24_math_double.f
131 $include 28_print_number.f
132 $include 30_count_str.f
133 $include 31_ur_str_ext.f
134 $include 32_str_hash_name.f
135 $include 34_str_hash_more.f
136 $include 36_str_ext_asm.f
137 $include 38_c4s_str.f
138 $include 39_c1s_str.f
139 $include 40_termio_high.f
140 $include 42_tib.f
141 $include 46_os_face.f
142 $include 50_error.f
143 $include 52_exceptions.f
144 $include 60_wordmisc.f
145 $include 61_wordfind_low.f
146 $include 62_create_vocbase.f
147 $include 63_wordfind_high.f
148 $include 64_voc_order.f
149 $include 66_voc_other.f
150 $include 68_parse.f
151 $include 70_compiler_helpers.f
152 $include 71_compiler_if_begin_do.f
153 $include 72_compiler_mid.f
154 $include 74_compiler_high.f
155 $include 76_compiler_override_enum.f
156 $include 78_compiler_sc_colon.f
157 $include 82_tload.f
158 $include 84_interpret.f
159 $include 86_save.f
160 $include 88_main_startup.f
161 $include 89_cond_comp.f
162 $include 90_misc.f
163 $include 92_use.f
164 $include 94_envquery.f
165 $include 96_prng.f
166 $include 98_ans_crap.f
168 $include 99_misc_tests.f
170 db "Miriel!"
172 ;; WARNING! it cannot be "equ"!
173 $label urforth_code_end