Skip to content

Commit f7d304e

Browse files
committed
jvm: refactoring (minor renaming)
1 parent adfb8cc commit f7d304e

File tree

6 files changed

+65
-53
lines changed

6 files changed

+65
-53
lines changed

src/jvm-test.fs

+8
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@ include jvm/jvm.fs \ include the jvm
44
: RunDemo ( -- )
55
s" testfiles/" jvm_classpath.add()
66
s" Main" jvm_java
7+
\ show static values
8+
jvm_stack.getCurrentFrame()
9+
jvm_frame.getClass()
10+
dup s" foo|I"
11+
jvm_class.getStatic() throw
12+
." Main.foo: " hex. CR
13+
s" bar|I" jvm_class.getStatic() throw
14+
." Main.bar: " hex. CR
715
;
816

src/jvm/class.fs

+47-44
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,21 @@ require rtconstpool.fs
7474
\ ========
7575
\
7676
\ *C jvm_class {
77-
\ ** addr rtcp; \ runtime constant pool
78-
\ ** wid fd_idx; \ static field index wordlist
79-
\ ** addr fd_table; \ static field table
77+
\ ** addr status; \ status of the class
78+
\ ** addr init_loader; \ initial loader
79+
\ ** addr rtcp; \ runtime constant pool
80+
\ ** addr super; \ link to super class
81+
\ ** wid filed_offset; \ static field offset wordlist
82+
\ ** addr field_table; \ static field table
8083
\ ** }
8184
\
8285

8386
0 cells constant jvm_class.status
8487
1 cells constant jvm_class.init_loader
8588
2 cells constant jvm_class.rtcp
8689
3 cells constant jvm_class.super
87-
4 cells constant jvm_class.fd_idx
88-
5 cells constant jvm_class.fd_table
90+
4 cells constant jvm_class.field_offset
91+
5 cells constant jvm_class.field_table
8992

9093
6 cells constant jvm_class.size()
9194

@@ -112,58 +115,58 @@ require rtconstpool.fs
112115
\ *G get the address of the super class
113116
jvm_class.super + @
114117
;
115-
\ FIXME change idx to offset!
116-
: jvm_class.getFd_idx_wid() ( addr -- wid )
117-
\ *G get the wordlist id for the static field index translation
118-
jvm_class.fd_idx + @
118+
119+
: jvm_class.getField_offset_wid() ( addr -- wid )
120+
\ *G get the wordlist id for the static field offset translation
121+
jvm_class.field_offset + @
119122
;
120123

121-
: jvm_class.getFd_idx() { addr c-addr n -- idx woir }
122-
\ *G get the index of a static field
123-
addr jvm_class.getFd_idx_wid()
124+
: jvm_class.getField_offset() { addr c-addr n -- off woir }
125+
\ *G get the offset of a static field
126+
addr jvm_class.getField_offset_wid()
124127
c-addr n rot
125128
jvm_find_word throw
126129
0
127130
;
128131

129-
: jvm_class.getStaticIdx() { addr idx -- value }
130-
\ *G get the value of a static field (32bit) by index
131-
addr jvm_class.fd_table + idx cells + jvm_field_@
132+
: jvm_class.getStaticOffset() { addr off -- value }
133+
\ *G get the value of a static field (32bit) by offset
134+
addr jvm_class.field_table + off cells + jvm_field_@
132135
;
133136

134137
: jvm_class.getStatic() { addr c-addr n -- value woir }
135138
\ *G get the value of a static field (32bit) by name
136139
\ ." trying to get " c-addr n type CR
137-
addr c-addr n jvm_class.getFd_idx() throw
138-
\ ." index: " dup . CR
139-
addr swap jvm_class.getStaticIdx() 0
140+
addr c-addr n jvm_class.getField_offset() throw
141+
\ ." offset: " dup . CR
142+
addr swap jvm_class.getStaticOffset() 0
140143
;
141144

142-
: jvm_class.setStaticIdx() { addr val idx -- }
143-
\ *G set the value of a static field (32bit) by index
144-
val addr jvm_class.fd_table + idx cells +
145+
: jvm_class.setStaticOffset() { addr val off -- }
146+
\ *G set the value of a static field (32bit) by offset
147+
val addr jvm_class.field_table + off cells +
145148
jvm_field_!
146149
;
147150

148151
: jvm_class.setStatic() { addr val c-addr n -- woir }
149152
\ *G get the value of a static field (32bit) by name
150153
\ ." trying to set " c-addr n type ." to " val . CR
151154
addr val
152-
over c-addr n jvm_class.getFd_idx() throw \ get idx
153-
\ ." index: " dup . CR
154-
jvm_class.setStaticIdx()
155+
over c-addr n jvm_class.getField_offset() throw \ get off
156+
\ ." offset: " dup . CR
157+
jvm_class.setStaticOffset()
155158
0
156159
;
157160

158-
: jvm_class.getStatic2Idx() { addr idx -- lsb-value msb-value }
159-
\ *G get the value of a static field (64bit) by index
160-
addr jvm_class.fd_table + idx cells + jvm_field_2@
161+
: jvm_class.getStatic2Offset() { addr off -- lsb-value msb-value }
162+
\ *G get the value of a static field (64bit) by offset
163+
addr jvm_class.field_table + off cells + jvm_field_2@
161164
;
162165

163166
: jvm_class.getStatic2() { addr c-addr n -- lsb-value msb-value wior }
164167
\ *G get the value of a static field (64bit) by name
165-
addr c-addr n jvm_class.getFd_idx() throw
166-
addr swap jvm_class.getStatic2Idx() 0
168+
addr c-addr n jvm_class.getField_offset() throw
169+
addr swap jvm_class.getStatic2Offset() 0
167170
;
168171

169172
: jvm_class.new() ( -- addr)
@@ -173,8 +176,8 @@ require rtconstpool.fs
173176
jvm_class.STATUS:UNINIT over ( jvm_class.status + ) !
174177
\ 0 over jvm_class.init_loader + !
175178
\ 0 over jvm_class.rtcp + !
176-
wordlist over jvm_class.fd_idx + !
177-
\ 0 over jvm_class.fd_table + !
179+
wordlist over jvm_class.field_offset + !
180+
\ 0 over jvm_class.field_table + !
178181
;
179182

180183
: jvm_class.prepare() { addr_cl loader addr_cf -- wior }
@@ -190,28 +193,28 @@ require rtconstpool.fs
190193
addr_cf jvm_cf_fields_addr
191194
addr_cf jvm_cf_fields_count
192195
0 ?DO
193-
( idx addr )
194-
\ idx next free index of the table
196+
( off addr )
197+
\ off next free offset of the table
195198
\ addr address of the field entry
196199
dup ACC_STATIC jvm_fd_?flags IF
197200
addr_cf over jvm_fd_identifier
198-
( idx addr c-addr n )
201+
( off addr c-addr n )
199202
addr_cf jvm_cf_constpool_addr
200-
( idx addr c-addr n addr2 )
203+
( off addr c-addr n addr2 )
201204
3 pick jvm_fd_desc_idx
202-
( idx addr c-addr n addr2 idx2 )
205+
( off addr c-addr n addr2 idx2 )
203206
jvm_constpool_idx
204-
( idx addr c-addr n addr3 )
207+
( off addr c-addr n addr3 )
205208
jvm_cp_utf8_c-ref
206-
( idx addr c-addr n c-addr2 n2 )
209+
( off addr c-addr n c-addr2 n2 )
207210
jvm_field_desc_size -rot
208-
( idx addr size c-addr n )
211+
( off addr size c-addr n )
209212
4 pick -rot
210-
( idx addr size idx c-addr n )
211-
addr_cl jvm_class.getFd_idx_wid()
212-
( idx addr size idx c-addr n wid )
213+
( off addr size off c-addr n )
214+
addr_cl jvm_class.getField_offset_wid()
215+
( off addr size off c-addr n wid )
213216
jvm_add_word
214-
( idx addr size )
217+
( off addr size )
215218
rot + swap
216219
ENDIF
217220

@@ -222,7 +225,7 @@ require rtconstpool.fs
222225
allocate throw \ allocate static table memory
223226
\ TODO Initial values §5.4.2, 1st paragraph
224227

225-
addr_cl jvm_class.fd_table + ! \ store table
228+
addr_cl jvm_class.field_table + ! \ store table
226229

227230
jvm_class.STATUS:PREPARED addr_cl jvm_class.status + ! \ store status
228231
loader addr_cl jvm_class.init_loader + ! \ store loader

src/jvm/execute.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ require exception.fs
364364
dup
365365
rot
366366
( addr_rtcp addr_rtcp idx )
367-
jvm_rtcp.getConstpool()
367+
jvm_rtcp.getConstpoolByIdx()
368368
( addr_rtcp addr_fd )
369369
over -rot
370370
( addr_rtcp addr_rtcp addr_fd )
@@ -884,7 +884,7 @@ require exception.fs
884884
dup
885885
rot
886886
( addr_rtcp addr_rtcp idx )
887-
jvm_rtcp.getConstpool()
887+
jvm_rtcp.getConstpoolByIdx()
888888
( addr_rtcp addr_fd )
889889
over -rot
890890
( addr_rtcp addr_rtcp addr_fd )

src/jvm/rtconstpool.fs

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require classfile.fs
4848
( jvm_rtcp.classfile + ) @
4949
;
5050

51-
: jvm_rtcp.getConstpool() { addr idx -- addr2 }
51+
: jvm_rtcp.getConstpoolByIdx() { addr idx -- addr2 }
5252
\ *G get the address of the constant pool entry denoted by idx
5353
\ NOTE no sanity checks (e.g. 0 < idx < constant_pool_count)
5454
addr jvm_rtcp.constpool_table + @ idx 1- cells + @
@@ -57,26 +57,26 @@ require classfile.fs
5757
\ FIXME other name?
5858
: jvm_rtcp.getClassName() { addr idx -- c-addr n }
5959
\ *G get the qualified classname from a class idx
60-
addr idx jvm_rtcp.getConstpool()
60+
addr idx jvm_rtcp.getConstpoolByIdx()
6161
( class_addr)
6262
jvm_cp_class_name_idx
6363
( name_idx)
6464
addr swap
6565
( addr_rtcp name_idx)
66-
jvm_rtcp.getConstpool()
66+
jvm_rtcp.getConstpoolByIdx()
6767
( addr_utf8)
6868
jvm_cp_utf8_c-ref
6969
;
7070
\ FIXME other name?
7171
: jvm_rtcp.getNameType() { addr idx -- c-addr n }
7272
\ *G get the qualified NameType from a class idx
73-
addr idx jvm_rtcp.getConstpool()
73+
addr idx jvm_rtcp.getConstpoolByIdx()
7474
( nametype_addr)
7575
dup jvm_cp_nametype_name_idx
7676
( nametype_addr name_idx)
7777
addr swap
7878
( nametype addr_rtcp name_idx)
79-
jvm_rtcp.getConstpool()
79+
jvm_rtcp.getConstpoolByIdx()
8080
( nametype addr_utf8)
8181
jvm_cp_utf8_c-ref
8282
( nametype c-addr n)
@@ -88,7 +88,7 @@ require classfile.fs
8888
( c-addr n desc_idx)
8989
addr swap
9090
( c-addr n addr_rtcp desc_idx)
91-
jvm_rtcp.getConstpool()
91+
jvm_rtcp.getConstpoolByIdx()
9292
( c-addr n addr_utf8)
9393
jvm_cp_utf8_c-ref
9494
( c-addr n c-addr2 n2)

src/jvm/stack.fs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ jvm_stack.new() constant jvm_stack
148148
: jvm_stack.invokeInitial() { c-addr n -- wior }
149149
\ *G Start the execution by invoking public static void main(String[] args)
150150
\ ." : jvm_stack.invokeInitial() { c-addr n -- wior } " .s CR
151+
\ FIXME we need to initialize the super class/interface as well (somewhere)
151152
assert( depth 0 = )
152153
c-addr n jvm_stack.findClass() throw
153154
dup jvm_class.getStatus()

src/unittests/rtconstpool_test.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ include ../jvm/rtconstpool.fs
2727
s" Test.class" jvm_read_classfile throw
2828
dup jvm_rtcp.new()
2929
tuck
30-
1 jvm_rtcp.getConstpool()
30+
1 jvm_rtcp.getConstpoolByIdx()
3131
swap jvm_cf_constpool_addr
3232
assert( = )
3333
\ TODO jvm_rtcp.getClass_info() >order

0 commit comments

Comments
 (0)