Strings are now 2 bytes per character
This commit is contained in:
parent
73012dc048
commit
332344073a
@ -409,7 +409,7 @@ void vm_exception(struct vm * vm, struct objectref * objectref)
|
||||
printc(')');
|
||||
prints("\n ");
|
||||
struct arrayref * arrayref = string_objectref->aref[0];
|
||||
print__string(arrayref->u8, arrayref->length);
|
||||
print_chars(arrayref->u16, arrayref->length);
|
||||
printc('\n');
|
||||
}
|
||||
}
|
||||
|
16
c/native.c
16
c/native.c
@ -88,9 +88,21 @@ const static struct native_method native_method[] = {
|
||||
},
|
||||
{
|
||||
.class_name = "java/io/PrintStream",
|
||||
.method_name = "write",
|
||||
.method_name = "_write",
|
||||
.method_descriptor = "([B)V",
|
||||
.func = native_java_io_printstream_write_1,
|
||||
.func = native_java_io_printstream_write_ba_1,
|
||||
},
|
||||
{
|
||||
.class_name = "java/io/PrintStream",
|
||||
.method_name = "_write",
|
||||
.method_descriptor = "([C)V",
|
||||
.func = native_java_io_printstream_write_ca_1,
|
||||
},
|
||||
{
|
||||
.class_name = "java/io/PrintStream",
|
||||
.method_name = "_write",
|
||||
.method_descriptor = "(Ljava/lang/String;)V",
|
||||
.func = native_java_io_printstream_write_s_1,
|
||||
},
|
||||
{
|
||||
.class_name = "jvm/internal/Loader",
|
||||
|
@ -2,8 +2,21 @@
|
||||
#include "printstream.h"
|
||||
#include "printf.h"
|
||||
|
||||
void native_java_io_printstream_write_1(struct vm * vm, uint32_t * args)
|
||||
void native_java_io_printstream_write_ba_1(struct vm * vm, uint32_t * args)
|
||||
{
|
||||
struct arrayref * arrayref = (struct arrayref *)args[0];
|
||||
print_string((const char *)arrayref->u8, arrayref->length);
|
||||
print_bytes(arrayref->u8, arrayref->length);
|
||||
}
|
||||
|
||||
void native_java_io_printstream_write_ca_1(struct vm * vm, uint32_t * args)
|
||||
{
|
||||
struct arrayref * arrayref = (struct arrayref *)args[0];
|
||||
print_chars(arrayref->u16, arrayref->length);
|
||||
}
|
||||
|
||||
void native_java_io_printstream_write_s_1(struct vm * vm, uint32_t * args)
|
||||
{
|
||||
struct objectref * objectref = (struct objectref *)args[0];
|
||||
struct arrayref * arrayref = objectref->aref[0];
|
||||
print_chars(arrayref->u16, arrayref->length);
|
||||
}
|
||||
|
@ -4,4 +4,6 @@
|
||||
|
||||
#include "frame.h"
|
||||
|
||||
void native_java_io_printstream_write_1(struct vm * vm, uint32_t * args);
|
||||
void native_java_io_printstream_write_ba_1(struct vm * vm, uint32_t * args);
|
||||
void native_java_io_printstream_write_ca_1(struct vm * vm, uint32_t * args);
|
||||
void native_java_io_printstream_write_s_1(struct vm * vm, uint32_t * args);
|
||||
|
14
c/printf.c
14
c/printf.c
@ -78,6 +78,20 @@ void print_string(const char * s, int length)
|
||||
}
|
||||
}
|
||||
|
||||
void print_bytes(const uint8_t * s, int length)
|
||||
{
|
||||
for (int i = 0; i < length; i++) {
|
||||
print_char(s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void print_chars(const uint16_t * s, int length)
|
||||
{
|
||||
for (int i = 0; i < length; i++) {
|
||||
print_char(s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void print_cstring(const char * s)
|
||||
{
|
||||
while (*s != 0) {
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -20,6 +22,8 @@ static inline void print_char(char c)
|
||||
}
|
||||
|
||||
void print_string(const char * s, int length);
|
||||
void print_bytes(const uint8_t * s, int length);
|
||||
void print_chars(const uint16_t * s, int length);
|
||||
void print_cstring(const char * s);
|
||||
|
||||
void _printf(const char * format, ...);
|
||||
|
@ -10,94 +10,94 @@ public class PrintStream
|
||||
|
||||
private static final byte[] newline = {'\n'};
|
||||
|
||||
public static native void write(byte[] buf);
|
||||
private static native void _write(byte[] buf);
|
||||
|
||||
public static void write(String s) {
|
||||
write(s.getBytes());
|
||||
}
|
||||
private static native void _write(char[] buf);
|
||||
|
||||
private static native void _write(String s);
|
||||
|
||||
public void print(byte[] buf) {
|
||||
write(buf);
|
||||
_write(buf);
|
||||
}
|
||||
|
||||
public void print(boolean b) {
|
||||
write(String.valueOf(b));
|
||||
_write(String.valueOf(b));
|
||||
}
|
||||
|
||||
public void print(char c) {
|
||||
write(String.valueOf(c));
|
||||
_write(String.valueOf(c));
|
||||
}
|
||||
|
||||
public void print(int i) {
|
||||
write(String.valueOf(i));
|
||||
_write(String.valueOf(i));
|
||||
}
|
||||
|
||||
public void print(long l) {
|
||||
write(String.valueOf(l));
|
||||
_write(String.valueOf(l));
|
||||
}
|
||||
|
||||
public void print(float f) {
|
||||
write(String.valueOf(f));
|
||||
_write(String.valueOf(f));
|
||||
}
|
||||
|
||||
public void print(double d) {
|
||||
write(String.valueOf(d));
|
||||
_write(String.valueOf(d));
|
||||
}
|
||||
|
||||
public void print(Object obj) {
|
||||
write(String.valueOf(obj));
|
||||
_write(String.valueOf(obj));
|
||||
}
|
||||
|
||||
public void print(String s) {
|
||||
write(String.valueOf(s));
|
||||
_write(String.valueOf(s));
|
||||
}
|
||||
|
||||
public void println() {
|
||||
write(newline);
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(byte[] buf) {
|
||||
write(buf);
|
||||
write(newline);
|
||||
_write(buf);
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(boolean b) {
|
||||
write(String.valueOf(b));
|
||||
write(newline);
|
||||
_write(String.valueOf(b));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(char c) {
|
||||
write(String.valueOf(c));
|
||||
write(newline);
|
||||
_write(String.valueOf(c));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(int i) {
|
||||
write(String.valueOf(i));
|
||||
write(newline);
|
||||
_write(String.valueOf(i));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(long l) {
|
||||
write(String.valueOf(l));
|
||||
write(newline);
|
||||
_write(String.valueOf(l));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(float f) {
|
||||
write(String.valueOf(f));
|
||||
write(newline);
|
||||
_write(String.valueOf(f));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(double d) {
|
||||
write(String.valueOf(d));
|
||||
write(newline);
|
||||
_write(String.valueOf(d));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(Object obj) {
|
||||
write(String.valueOf(obj));
|
||||
write(newline);
|
||||
_write(String.valueOf(obj));
|
||||
_write(newline);
|
||||
}
|
||||
|
||||
public void println(String s) {
|
||||
write(String.valueOf(s));
|
||||
write(newline);
|
||||
_write(String.valueOf(s));
|
||||
_write(newline);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user