summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 757bfb9)
raw | patch | inline | side by side (parent: 757bfb9)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 13 Aug 2017 18:49:53 +0000 (21:49 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 13 Aug 2017 18:49:53 +0000 (21:49 +0300) |
Test.obn | patch | blob | history | |
notes | patch | blob | history | |
obn-compile.sh | patch | blob | history | |
proguard.conf | [new file with mode: 0644] | patch | blob |
rtl/Launcher.java | patch | blob | history | |
rtl/Out.java | patch | blob | history | |
src/backends/jvm/generator-jvm.c | patch | blob | history |
diff --git a/Test.obn b/Test.obn
index f76917867cb0d1bcb880b7e0cf655f116919947f..8249fb77223116fd24082f63a7dba78821d98fe1 100644 (file)
--- a/Test.obn
+++ b/Test.obn
MODULE Test;
-VAR
- i : SHORTINT;
- s : SET;
-
-PROCEDURE X;
-END X;
+IMPORT Out;
BEGIN
- i := SHORT(12345);
+ Out.Open;
+ Out.String("Hello World!"); Out.Ln;
END Test.
index 191dfc91c615a73869b09d6aec434b678a113a58..71ec669ef5ea5c935cc40c1546383407d7a2ec6e 100644 (file)
--- a/notes
+++ b/notes
-- JVM: Импортируемые модули не инициализируются
- Нет счёта строк / столбцов
- Сделать проверку повторов в CASE.
diff --git a/obn-compile.sh b/obn-compile.sh
index c02d17844da1710aead79959c210e33962572e5c..85b71c5cd77a31745dd068269b2181989469303d 100755 (executable)
--- a/obn-compile.sh
+++ b/obn-compile.sh
javac -d classes rtl/*.java
-proguard -injars classes \
- -libraryjars /usr/lib/jvm/java-8-openjdk/jre/lib/rt.jar \
- -dontshrink -dontobfuscate -keep class $1 -keep class Launcher
+proguard -injars classes -libraryjars /usr/lib/jvm/java-8-openjdk/jre/lib/rt.jar @proguard.conf
diff --git a/proguard.conf b/proguard.conf
--- /dev/null
+++ b/proguard.conf
@@ -0,0 +1,4 @@
+-dontshrink
+-dontobfuscate
+-dontoptimize
+-keep class ** { void BEGIN(); }
diff --git a/rtl/Launcher.java b/rtl/Launcher.java
index 220f671f5dde0d0efeb9f61f29dd4878be32ff29..5077fa884a1620022ba77acc0ca4f32b1d7467a2 100644 (file)
--- a/rtl/Launcher.java
+++ b/rtl/Launcher.java
-class Launcher {
+import java.lang.reflect.*;
+
+class Launcher
+{
public static void main(String[] args)
- throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- Class.forName(args[0]).newInstance();;
+ throws
+ ClassNotFoundException,
+ InstantiationException,
+ IllegalAccessException,
+ NoSuchMethodException,
+ InvocationTargetException
+ {
+ Class<?> module = Class.forName(args[0]);
+ Method begin = module.getMethod("BEGIN");
+ begin.invoke(null);
}
}
diff --git a/rtl/Out.java b/rtl/Out.java
index 99899776c45ad838e94f8649f1d6fe9bd2049e54..68a7375ef2f54c956ee164e725e050940afbe51c 100644 (file)
--- a/rtl/Out.java
+++ b/rtl/Out.java
{
public static void Open()
{
-
+ // Сюда можно что-нибудь затолкать...
+ // Например открытие окошка и высер в него
}
public static void Char(byte ch)
{
System.out.println();
}
+
+ public static void BEGIN()
+ {
+ // Функция выполняется каждый раз когда модуль импортируется.
+ // Модуль должен сам проверять, импортировался ли он ранее.
+ }
}
index 2456aa79cd9bafd5a6b4e71f26c5715ea250e9e8..bf5200bd786daafe7cff702b2731eb2b0552343a 100644 (file)
fprintf(class -> fp, ".class %s\n", mod -> name);
fprintf(class -> fp, ".super java/lang/Object\n\n");
+ fprintf(class -> fp, ".field private static $INITIALIZED$ Z\n\n");
+
m -> class = class;
c -> current_m = m;
void
oberon_generate_begin_module(oberon_context_t * ctx)
{
- struct gen_class * class = ctx -> mod -> gen_mod -> class;
- gen_proc_t * p = jvm_create_proc(class);
+ gen_proc_t * p;
+ int label_cont;
+ struct gen_class * class;
- jvm_generate_function_header(p, "public", "<init>", "()V");
- jvm_alloc_register_untyped(p -> rf, false);
- jvm_generate(p, 0, 1, "aload_0");
- jvm_generate(p, 1, 0, "invokespecial java/lang/Object/<init>()V");
+ class = ctx -> mod -> gen_mod -> class;
+
+ p = jvm_create_proc(class);
+ jvm_generate_function_header(p, "public static", "BEGIN", "()V");
+
+ label_cont = jvm_new_label_id(p);
+ jvm_generate(p, 0, 1, "getstatic %s/$INITIALIZED$ Z", class -> full_name);
+ jvm_generate(p, 1, 0, "ifeq L%i", label_cont);
+ jvm_generate(p, 0, 0, "return");
+ jvm_generate_label(p, label_cont);
+
+ jvm_generate(p, 0, 1, "iconst_1");
+ jvm_generate(p, 1, 0, "putstatic %s/$INITIALIZED$ Z", class -> full_name);
/* Инициализация переменных объявленных в модуле */
oberon_object_t * x = ctx -> mod -> decl -> list -> next;
while(x != NULL)
{
- if(x -> class == OBERON_CLASS_VAR)
+ if(x -> class == OBERON_CLASS_MODULE)
+ {
+ jvm_generate(p, 0, 0, "invokestatic %s/BEGIN()V", x -> module -> gen_mod -> class -> full_name);
+ }
+ else if(x -> class == OBERON_CLASS_VAR)
{
jvm_generate_var_initialization(p, x -> gen_var);
if(x -> type -> class == OBERON_TYPE_ARRAY
jvm_generate(p, 0, 0, "return");
jvm_generate_function_end(class -> p);
+
+ p = jvm_create_proc(class);
+ jvm_generate_function_header(p, "private", "<init>", "()V");
+ jvm_alloc_register_untyped(p -> rf, false);
+ jvm_generate(p, 0, 1, "aload_0");
+ jvm_generate(p, 1, 0, "invokespecial java/lang/Object/<init>()V");
+ jvm_generate(p, 0, 0, "return");
+ jvm_generate_function_end(class -> p);
}
/*