Last active
November 5, 2017 00:48
-
-
Save icasdri/94dac71eedde0bbababf20fe78ff8f2e to your computer and use it in GitHub Desktop.
Write Java with only a C compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hello { | |
public static void main(String args[]) { | |
System.out.println("Hello World!"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef JAVA_H | |
#define JAVA_H | |
int puts(char *); | |
struct out_struct { | |
int (*println)(char *); | |
}; | |
struct system_struct { | |
struct out_struct out; | |
}; | |
struct system_struct System = { | |
.out = { .println = &puts } | |
}; | |
#define public | |
#define class int | |
#define Hello Hello() | |
#define static } | |
#define void int | |
#define String int argc, char * | |
#define println(s) println(s); { | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = gcc | |
JAVAC = javac | |
SRCS = Hello.java | |
.PHONY: all run clean | |
all: hello Hello.class | |
hello: java.h $(SRCS) | |
$(CC) -x c -o $@ -include $^ | |
Hello.class: $(SRCS) | |
$(JAVAC) $< | |
run: all | |
./hello | |
java Hello | |
clean: | |
rm -f hello Hello.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment