Skip to content

Commit a02b87b

Browse files
committed
Push source
1 parent c1aaa48 commit a02b87b

11 files changed

Lines changed: 271 additions & 1 deletion

File tree

.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
# Test output
26+
*.exe
27+
data.txt
28+
/*.v
29+
.settings/
30+
31+
32+
#
33+
# Currently in development, main transpiler source hidden.
34+
src/
35+

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>MDTest</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Java2V Transpiler (J2V) provides the ability to transpile Java source into human-readable V that can be compiled using V's C, or Javascript backends.
33
A subset of the Java Class Library is also implemented for use.
44

5+
[See Downloads](https://github.com/IsaiahPatton/java2v/releases)
6+
57
## Example
68

79
Input:
@@ -12,7 +14,7 @@ public static void main(String[] args) {
1214

1315
List<String> content = Files.readAllLines(file.toPath());
1416
for (String line : content) {
15-
System.out.println(line);
17+
System.out.println(line);
1618
}
1719
}
1820
```
@@ -29,3 +31,10 @@ fn main() {
2931
}
3032
}
3133
```
34+
35+
## Repo Structure
36+
37+
There are two modules in this repository.
38+
39+
- ``jcl/`` - Classes from the [Java Class Library](https://docs.oracle.com/javase/8/docs/api/) reimplemented in V.
40+
- ``src/`` - Main transpiler source. Currently in early development and needs polishing before public source release.

jcl/io/File.v

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// J2V Classlib - jcl.io.File
2+
module jcl_io
3+
4+
import os
5+
6+
pub const path_separator = ';'
7+
pub const file_separator = '/'
8+
9+
struct File {
10+
name string
11+
path string
12+
}
13+
14+
pub fn file(name string) File {
15+
return File{
16+
name: name
17+
path: name
18+
}
19+
}
20+
21+
pub fn file2(name string, path string) File {
22+
return File{
23+
name: name
24+
path: path
25+
}
26+
}
27+
28+
/**
29+
* Return the name of the File
30+
*/
31+
pub fn (f File) get_name() string {
32+
return f.name
33+
}
34+
35+
pub fn (f File) to_path() File {
36+
return f
37+
}
38+
39+
pub fn (f File) get_path() string {
40+
return f.path
41+
}
42+
43+
/**
44+
* Retrieve an array of strings of the files
45+
* and directories currently in this path.
46+
*/
47+
pub fn (f File) list() []string {
48+
return os.ls(f.get_path()) or { panic(err) }
49+
}
50+
51+
/**
52+
* Retrieve an array of Files of the files
53+
* and directories currently in this path.
54+
*/
55+
pub fn (f File) list_files() []File {
56+
mut a := f.list()
57+
mut b := []File{}
58+
for str in a {
59+
b << file2(str, f.get_parent() + file_separator + str)
60+
}
61+
return b
62+
}
63+
64+
/**
65+
*/
66+
pub fn (f File) get_absolute_path() string {
67+
return os.real_path(f.get_path())
68+
}
69+
70+
/**
71+
*/
72+
pub fn (f File) get_parent() string {
73+
return f.get_absolute_path().replace( os.file_ext(f.get_absolute_path()), "")
74+
}
75+
76+
/**
77+
* Tests whether the file denoted by this
78+
* name is a directory or not.
79+
*/
80+
pub fn (f File) is_directory() bool {
81+
return os.is_dir(f.get_path())
82+
}

jcl/license.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org/>

jcl/nio/Files.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module jcl_nio
2+
3+
import jcl.io
4+
import os
5+
6+
pub fn read_all_lines(f io.File) []string {
7+
return os.read_lines(f.get_absolute_path()) or { [""] }
8+
}
9+
10+
pub fn write(arg0 io.File, b []byte) {
11+
mut str := unsafe { tos(b.data, b.len) }
12+
os.write_file(arg0.get_name(), str) or {}
13+
}
14+
15+
pub fn copy(from io.File, to io.File) {
16+
mut from_bytes := os.read_bytes(from.get_name()) or { panic(err) }
17+
write(to, from_bytes)
18+
}

jcl/util/Base64.v

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module jcl_util
2+
3+
import encoding.base64
4+
5+
struct Base64_Decoder {
6+
}
7+
8+
struct Base64_Encoder {
9+
}
10+
11+
pub fn get_decoder() Base64_Decoder {
12+
return Base64_Decoder{
13+
}
14+
}
15+
16+
pub fn get_encoder() Base64_Encoder {
17+
return Base64_Encoder{
18+
}
19+
}
20+
21+
/**
22+
* Decodes all bytes from input array using Base64,
23+
* writing results into a new output byte array
24+
*/
25+
pub fn (b Base64_Decoder) decode(src []byte) []byte {
26+
mut str := unsafe { tos(src.data, src.len) }
27+
return base64.decode(str)
28+
}
29+
30+
/**
31+
* Encode all bytes from input array using Base64,
32+
* writing results into a new output byte array
33+
*/
34+
pub fn (b Base64_Encoder) encode(src []byte) []byte {
35+
mut str := unsafe { tos(src.data, src.len) }
36+
return base64.decode(str)
37+
}

jcl/util/SystemProperty.v

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module jcl_util
2+
3+
import os
4+
5+
pub fn get_system_property(key string) string {
6+
if key == "java.version" {
7+
return "1.8.0_302"
8+
}
9+
if key == "java.vendor" {
10+
return "OpenJDK"
11+
}
12+
if key == "java.vendor.url" {
13+
return "https://example.com"
14+
}
15+
if key == "java.home" {
16+
return "C:\\Fake\\Path"
17+
}
18+
if key == "java.vm.version" {
19+
return "Java2V indev"
20+
}
21+
if key == "os.name" {
22+
os := $if windows { "Windows 10" } $else $if macos { "Mac OS X" }
23+
$else $if ios || android { "Android" } $else { "Linux" }
24+
return os
25+
}
26+
if key == "java.io.tmpdir" {
27+
return os.temp_dir()
28+
}
29+
if key == "user.home" {
30+
return os.home_dir()
31+
}
32+
return key
33+
}

jcl/util/UUID.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module jcl_util
2+
3+
import rand
4+
5+
struct UUID {
6+
value string
7+
}
8+
9+
pub fn random_uuid() UUID {
10+
return UUID{
11+
value: rand.uuid_v4()
12+
}
13+
}
14+
15+
pub fn (u UUID) str() string {
16+
return u.value
17+
}

0 commit comments

Comments
 (0)