Skip to content

Commit 3efb9d6

Browse files
committed
creating super classes
1 parent 37fbbc1 commit 3efb9d6

File tree

5 files changed

+115
-36
lines changed

5 files changed

+115
-36
lines changed

src/jvm/class.fs

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -341,29 +341,56 @@ defer jvm_stack.invokeStaticInitializer()
341341
\ NOTE loader is a value to identify loaders
342342

343343
\ get this class
344-
addr_cf jvm_cf_constpool_addr dup ( addr_cp addr_cp )
345-
addr_cf jvm_cf_this_class ( addr_cp addr_cp idx1 )
346-
jvm_constpool.getClassname_idx() ( scl_addr )
347-
jvm_cp_utf8_c-ref ( scl_str n )
348-
s" java/lang/Object" str= invert IF
344+
\ addr_cf jvm_cf_constpool_addr dup ( addr_cp addr_cp )
345+
\ addr_cf jvm_cf_this_class ( addr_cp addr_cp idx1 )
346+
\ jvm_constpool.getClassname_idx() ( scl_addr )
347+
\ jvm_cp_utf8_c-ref ( scl_str n )
348+
\ FIXME cleanup
349+
\ 2drop
350+
\ s" java/lang/Object" str= invert IF
349351
\ get ref to superclass
350-
addr_cf jvm_cf_constpool_addr dup ( addr_cp addr_cp )
351-
addr_cf jvm_cf_super_class ( addr_cp idx1 )
352-
jvm_constpool.getClassname_idx() ( scl_addr )
353-
jvm_cp_utf8_c-ref ( scl_str n )
354-
2dup ( scl_str n scl_str n )
355-
jvm_stack.newClass() ( scl_str n )
356-
jvm_stack.findAndInitClass() throw ( addr_super_class )
357-
dup ( addr_super_class addr_super_class )
358-
addr_cl jvm_class.super + ! ( addr_super_class )
352+
353+
addr_cf jvm_cf_constpool_addr
354+
( addr_cp )
355+
\ ." STACK PREPREIF: " .s CR
356+
addr_cf jvm_cf_super_class
357+
( addr_cp idx1 )
358+
\ ." STACK PREIF: " .s CR
359+
dup 0<> IF
360+
\ ." STACK IF: " .s CR
361+
jvm_constpool.getClassname_idx()
362+
( scl_addr )
363+
jvm_cp_utf8_c-ref
364+
( scl_str n )
365+
\ debug
366+
\ 2dup ." Superclass: " type CR
367+
\ end debug
368+
2dup
369+
( scl_str n scl_str n )
370+
jvm_stack.newClass()
371+
( scl_str n )
372+
jvm_stack.findAndInitClass() throw
373+
( addr_super_class )
374+
dup
375+
( addr_super_class addr_super_class )
376+
addr_cl jvm_class.super + !
377+
( addr_super_class )
359378

360379
\ set field length from superclass
361380
jvm_class.getField_length() ( length )
362381
addr_cl jvm_class.incField_length()
382+
ELSE
383+
\ ." STACK ELSE: " .s CR
384+
2drop
363385
ENDIF
364-
386+
\ ." STACK POSTIF: " .s CR
387+
365388
\ create runtime constant pool
366-
addr_cf jvm_rtcp.new() addr_cl jvm_class.rtcp + !
389+
addr_cf jvm_rtcp.new()
390+
\ debug
391+
\ ." RTCP: " .s CR
392+
\ end debug
393+
addr_cl jvm_class.rtcp + !
367394
\ TODO add super class
368395

369396
\ create static fields
@@ -383,12 +410,12 @@ defer jvm_stack.invokeStaticInitializer()
383410
( addr_md addr_md name_idx desc_idx )
384411
addr_cf -rot jvm_cp_nametype_identifier
385412
\ 2dup ." Method: " type CR
386-
addr_cl jvm_class.getMethodList()
413+
addr_cl jvm_class.getMethodList()
387414
\ ." pre add word " .s CR
388415
jvm_add_word
389416
dup jvm_md_size +
390417
LOOP
391-
drop
418+
drop
392419

393420
jvm_class.STATUS:PREPARED addr_cl jvm_class.status + ! \ store status
394421
loader addr_cl jvm_class.init_loader + ! \ store loader
@@ -397,8 +424,29 @@ defer jvm_stack.invokeStaticInitializer()
397424

398425
: jvm_class.init() { addr_cl -- wior }
399426
\ *G initialaze class
427+
400428
\ TODO init superclass
401-
\ TODO call static initialazer
429+
addr_cl jvm_class.getRTCP()
430+
dup jvm_rtcp.getSuperClassIdx()
431+
dup 0<> IF
432+
( rtcp idx )
433+
jvm_rtcp.getClassName()
434+
( c-addr n )
435+
jvm_stack.findAndInitClass()
436+
drop
437+
ELSE
438+
2drop
439+
ENDIF
440+
441+
\ TODO init interfaces
442+
443+
\ debug
444+
addr_cl jvm_class.getRTCP()
445+
jvm_rtcp.getThisClass()
446+
." initializing: " type CR
447+
\ end debug
448+
449+
\ call static initializer
402450
dup jvm_class.STATUS:INIT addr_cl jvm_class.status + ! \ store status
403451
jvm_stack.invokeStaticInitializer() throw
404452
0

src/jvm/classfile.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,12 @@ variable jvm_p_attributes_addr \ stores the pointer to the first field
10311031
." Super Class: "
10321032
addr jvm_cf_constpool_addr \ get start of the constpool
10331033
addr jvm_cf_super_class
1034-
jvm_constpool_print_classname_idx CR
1034+
dup 0<> IF
1035+
jvm_constpool_print_classname_idx CR
1036+
ELSE
1037+
2 drop
1038+
." <no superclass>" CR
1039+
ENDIF
10351040
;
10361041

10371042
: jvm_cf_interfaces_count_print ( addr -- )

src/jvm/classloader.fs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
\ You should have received a copy of the GNU General Public License
1919
\ along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
\ this file implements functionality that is needed to read class files
21-
\ this file contains the implementaion of the class loader
21+
\ this file contains the implementaion of the class loader
2222

2323
require exception.fs
2424
require util.fs
@@ -91,6 +91,12 @@ variable jvm_classpath_list
9191
s" .class"
9292
strcat
9393
( c-addr n -- )
94+
95+
\ debug
96+
\ ." trying: "
97+
\ 2dup type CR
98+
\ end debug
99+
94100
try
95101
jvm_read_classfile
96102
iferror
@@ -113,6 +119,9 @@ variable jvm_classpath_list
113119
0= IF
114120
JVM_CLASSNOTFOUND_EXCEPTION throw
115121
ELSE
122+
\ debug
123+
\ ." class found " CR
124+
\ end debug
116125
0
117126
ENDIF
118127
ENDIF

src/jvm/rtconstpool.fs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
\ ========
2323
\ *! rtconstpool
2424
\ *T Runtime Constant Pool
25-
\
26-
\ *P This file contains the implentation of the Runtime Constant Pool
25+
26+
\ *P This file contains the implentation of the Runtime Constant Pool
2727
\ ** as specified in the JVM specification §5.1 and §5.3.
2828
\ ========
2929

@@ -33,7 +33,7 @@ require classfile.fs
3333
\ ========
3434
\ *S Runtime Constant Pool Struct
3535
\ ========
36-
\
36+
3737
\ *E runtime_constant_ool {
3838
\ ** ClassFile classfile;
3939
\ ** addr constpool_table;
@@ -46,7 +46,7 @@ require classfile.fs
4646
\ ** addr long_info_table;
4747
\ ** addr double_info_table;
4848
\ ** }
49-
\
49+
5050

5151
0 cells constant jvm_rtcp.classfile
5252
1 cells constant jvm_rtcp.constpool_table
@@ -83,20 +83,36 @@ require classfile.fs
8383
( class_addr)
8484
jvm_cp_class_name_idx
8585
( name_idx)
86-
addr swap
86+
addr swap
8787
( addr_rtcp name_idx)
8888
jvm_rtcp.getConstpoolByIdx()
8989
( addr_utf8)
9090
jvm_cp_utf8_c-ref
9191
;
9292
\ FIXME other name?
9393

94+
: jvm_rtcp.getThisClassIdx() ( addr -- idx )
95+
\ *G get the constant pool index of this class
96+
jvm_rtcp.getClassfile() jvm_cf_this_class
97+
;
98+
99+
: jvm_rtcp.getThisClass() ( addr -- c-addr n )
100+
\ *G get the this class
101+
dup jvm_rtcp.getThisClassIdx()
102+
jvm_rtcp.getClassName()
103+
;
104+
105+
: jvm_rtcp.getSuperClassIdx() ( addr -- idx )
106+
\ *G get the constant pool index of the super class
107+
jvm_rtcp.getClassfile() jvm_cf_super_class
108+
;
109+
94110
: jvm_rtcp.getNameAndType() { addr idx -- c-addr n }
95111
addr idx jvm_rtcp.getConstpoolByIdx()
96112
( nametype_addr)
97113
dup jvm_cp_nametype_name_idx
98114
( nametype_addr name_idx)
99-
addr swap
115+
addr swap
100116
( nametype addr_rtcp name_idx)
101117
jvm_rtcp.getConstpoolByIdx()
102118
( nametype addr_utf8)
@@ -108,7 +124,7 @@ require classfile.fs
108124
( c-addr n nametype)
109125
jvm_cp_nametype_desc_idx
110126
( c-addr n desc_idx)
111-
addr swap
127+
addr swap
112128
( c-addr n addr_rtcp desc_idx)
113129
jvm_rtcp.getConstpoolByIdx()
114130
( c-addr n addr_utf8)
@@ -188,8 +204,8 @@ require classfile.fs
188204
jvm_rtcp.size() allocate throw
189205
\ dup ." new addr: " . dup ." - " hex. cr
190206
dup addr swap ( jvm_rtcp.classfile +) ! \ store classfile reference
191-
addr jvm_rtcp.createConstPoolTable()
192-
over jvm_rtcp.constpool_table + !
207+
addr jvm_rtcp.createConstPoolTable()
208+
over jvm_rtcp.constpool_table + !
193209
wordlist over jvm_rtcp.class_info + ! \ store class_info wordlist
194210
wordlist over jvm_rtcp.fieldref_info + ! \ store fieldref_info wordlist
195211
wordlist over jvm_rtcp.methodref_info + ! \ store methodref_info wordlist

src/jvm/stack.fs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
\ You should have received a copy of the GNU General Public License
1919
\ along with this program. If not, see <http://www.gnu.org/licenses/>.
20-
\ this file implements functionality that is needed to read class files
20+
2121
\ this file contains the implementaion of the JVM Stack
22-
\ of jvm stack frames
2322

2423
\ ========
2524
\ *! stack
@@ -128,12 +127,12 @@ jvm_stack.new() constant jvm_stack
128127

129128
\ : jvm_stack.newClass() { c-addr n -- }
130129
:noname { c-addr n -- }
131-
\ ." newClass: " c-addr n type space .s CR
132130
TRY
133131
c-addr n jvm_stack.findClass()
134132
nip \ delete class address
135133
\ ." class already found: " c-addr n type space .s CR
136134
IFERROR
135+
." newClass: " c-addr n type CR
137136
dup
138137
JVM_WORDNOTFOUND_EXCEPTION = IF
139138
drop
@@ -182,24 +181,26 @@ jvm_stack.new() constant jvm_stack
182181
\ jvm_stack.findAndInitClass() { c-addr n -- addr2 woir }
183182
:noname { c-addr n -- addr2 woir }
184183
\ *G search for a class an initialize it if needed
185-
\ ." jvm_stack.findAndInitClass() " c-addr n type space .s CR
184+
." findAndInitClass: " c-addr n type CR
186185
c-addr n jvm_stack.findClass() throw
187186
\ ." jvm_stack.findAndInitClass() begin " .s CR
188187
dup jvm_class.getStatus()
189188
\ ." jvm_stack.findAndInitClass() pre case " .s CR
190189
CASE
191190
( addr_cl )
192191
jvm_class.STATUS:UNINIT OF
193-
\ ." class " c-addr n type ." not prepared: prepare and init" cr
192+
." findAndInitClass " c-addr n type
193+
." not prepared: prepare and init" CR
194194
\ .s cr
195195
dup
196196
dup
197197
jvm_default_loader
198198
c-addr n jvm_search_classpath throw
199199
\ ." search classpath" .s cr
200200
jvm_class.prepare() throw
201-
jvm_stack.loadClasses()
202201
\ ." class prepare" .s cr
202+
jvm_stack.loadClasses()
203+
\ ." class loadClasses" .s cr
203204
dup
204205
jvm_class.init()
205206
\ ." throw" .s cr

0 commit comments

Comments
 (0)