├── .gitignore ├── LICENSE ├── README.md ├── jvm ├── class.lua ├── classLoader.lua ├── jit_freqs.lua ├── native.lua ├── nativeDefault.lua ├── thread.lua └── type.lua ├── lukyt-oc.lua ├── lukyt.lua ├── std ├── bin │ ├── cil │ │ └── li │ │ │ └── oc │ │ │ ├── Component.class │ │ │ ├── ComponentProxy.class │ │ │ ├── Components.class │ │ │ ├── Utils.class │ │ │ └── proxies │ │ │ └── GPUProxy.class │ ├── java │ │ ├── awt │ │ │ └── Color.class │ │ ├── io │ │ │ ├── BufferedReader.class │ │ │ ├── Closeable.class │ │ │ ├── ConsoleInputStream.class │ │ │ ├── ConsolePrintStream.class │ │ │ ├── File.class │ │ │ ├── FileDescriptor.class │ │ │ ├── FileInputStream.class │ │ │ ├── FileOutputStream.class │ │ │ ├── FilterOutputStream.class │ │ │ ├── Flushable.class │ │ │ ├── IOException.class │ │ │ ├── InputStream.class │ │ │ ├── InputStreamReader.class │ │ │ ├── OutputStream.class │ │ │ ├── OutputStreamWriter.class │ │ │ ├── PrintStream.class │ │ │ ├── PrintWriter.class │ │ │ ├── Reader.class │ │ │ ├── Serializable.class │ │ │ └── Writer.class │ │ ├── lang │ │ │ ├── Appendable.class │ │ │ ├── ArithmeticException.class │ │ │ ├── ArrayIndexOutOfBoundsException.class │ │ │ ├── ArrayMethods.class │ │ │ ├── AutoCloseable.class │ │ │ ├── Boolean.class │ │ │ ├── CharSequence.class │ │ │ ├── Character.class │ │ │ ├── Class.class │ │ │ ├── ClassCastException.class │ │ │ ├── ClassLoader$1.class │ │ │ ├── ClassLoader$SystemClassLoader.class │ │ │ ├── ClassLoader.class │ │ │ ├── ClassNotFoundException.class │ │ │ ├── CloneNotSupportedException.class │ │ │ ├── Cloneable.class │ │ │ ├── Comparable.class │ │ │ ├── Deprecated.class │ │ │ ├── Double.class │ │ │ ├── Enum.class │ │ │ ├── Error.class │ │ │ ├── Exception.class │ │ │ ├── FunctionalInterface.class │ │ │ ├── IllegalArgumentException.class │ │ │ ├── IncompatibleClassChangeError.class │ │ │ ├── IndexOutOfBoundsException.class │ │ │ ├── Integer.class │ │ │ ├── Iterable.class │ │ │ ├── LinkageError.class │ │ │ ├── Long.class │ │ │ ├── Math.class │ │ │ ├── NoClassDefException.class │ │ │ ├── NoSuchFieldError.class │ │ │ ├── NoSuchMethodError.class │ │ │ ├── NullPointerException.class │ │ │ ├── Number.class │ │ │ ├── NumberFormatException.class │ │ │ ├── Object.class │ │ │ ├── Override.class │ │ │ ├── Process.class │ │ │ ├── Runnable.class │ │ │ ├── Runtime$RuntimeProcess.class │ │ │ ├── Runtime.class │ │ │ ├── RuntimeException.class │ │ │ ├── StackTraceElement.class │ │ │ ├── String.class │ │ │ ├── StringBuffer.class │ │ │ ├── StringBuilder.class │ │ │ ├── System.class │ │ │ ├── Thread.class │ │ │ ├── Throwable.class │ │ │ ├── TypeNotPresentException.class │ │ │ ├── UnsatisfiedLinkError.class │ │ │ ├── UnsupportedOperationException.class │ │ │ └── annotation │ │ │ │ ├── Annotation.class │ │ │ │ ├── Documented.class │ │ │ │ ├── ElementType.class │ │ │ │ ├── Retention.class │ │ │ │ ├── RetentionPolicy.class │ │ │ │ └── Target.class │ │ └── util │ │ │ ├── AbstractCollection.class │ │ │ ├── AbstractList$AbstractListIterator.class │ │ │ ├── AbstractList$AbstractSubList.class │ │ │ ├── AbstractList.class │ │ │ ├── AbstractSet.class │ │ │ ├── ArrayDeque$ArrayDequeIterator.class │ │ │ ├── ArrayDeque.class │ │ │ ├── ArrayList.class │ │ │ ├── Collection.class │ │ │ ├── Comparator.class │ │ │ ├── ConcurrentModificationException.class │ │ │ ├── Date.class │ │ │ ├── Deque.class │ │ │ ├── Enumeration.class │ │ │ ├── EventListener.class │ │ │ ├── EventObject.class │ │ │ ├── Formatter.class │ │ │ ├── Iterator.class │ │ │ ├── LinkedList.class │ │ │ ├── List.class │ │ │ ├── ListIterator.class │ │ │ ├── Map$Entry.class │ │ │ ├── Map.class │ │ │ ├── NoSuchElementException.class │ │ │ ├── Objects.class │ │ │ ├── Optional.class │ │ │ ├── Queue.class │ │ │ ├── RandomAccess.class │ │ │ ├── Set.class │ │ │ └── function │ │ │ ├── Consumer.class │ │ │ ├── Function.class │ │ │ ├── Predicate.class │ │ │ └── Supplier.class │ └── lukyt │ │ ├── ChildNotFoundException.class │ │ ├── LuaInputStream.class │ │ ├── LuaObject.class │ │ ├── OS.class │ │ └── Os.class ├── build └── src │ ├── .vscode │ └── settings.json │ ├── cil │ └── li │ │ └── oc │ │ ├── ComponentProxy.java │ │ ├── Components.java │ │ ├── Utils.java │ │ ├── awt │ │ ├── GPUDrawer.java │ │ ├── GPUGraphics2D.java │ │ ├── GPUToolkit.java │ │ ├── SemiBrailleGPUDrawer.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── proxies │ │ └── GPUProxy.java │ ├── java │ ├── awt │ │ ├── AWTEvent.java │ │ ├── AWTEventMulticaster.java │ │ ├── Color.java │ │ ├── Component.java │ │ ├── Container.java │ │ ├── Dimension.java │ │ ├── EventObject.java │ │ ├── EventQueue.java │ │ ├── Frame.java │ │ ├── GraphicsConfiguration.java │ │ ├── GraphicsEnvironment.java │ │ ├── HeadlessException.java │ │ ├── Point.java │ │ ├── Shape.java │ │ ├── Toolkit.java │ │ ├── Window.java │ │ ├── event │ │ │ ├── AWTEventListener.java │ │ │ ├── ComponentEvent.java │ │ │ ├── ComponentListener.java │ │ │ ├── InputEvent.java │ │ │ ├── KeyEvent.java │ │ │ └── KeyListener.java │ │ ├── geom │ │ │ ├── Dimension2D.java │ │ │ ├── PathIterator.java │ │ │ ├── Point2D.java │ │ │ ├── Rectangle2D.java │ │ │ └── RectangularShape.java │ │ ├── package-info.java │ │ └── peer │ │ │ ├── ComponentPeer.java │ │ │ ├── ContainerPeer.java │ │ │ └── FramePeer.java │ ├── io │ │ ├── BufferedReader.java │ │ ├── Closeable.java │ │ ├── ConsoleInputStream.java │ │ ├── File.java │ │ ├── FileDescriptor.java │ │ ├── FileInputStream.java │ │ ├── FileOutputStream.java │ │ ├── FilterOutputStream.java │ │ ├── Flushable.java │ │ ├── IOException.java │ │ ├── InputStream.java │ │ ├── InputStreamReader.java │ │ ├── OutputStream.java │ │ ├── OutputStreamWriter.java │ │ ├── PrintStream.java │ │ ├── PrintWriter.java │ │ ├── Reader.java │ │ ├── Serializable.java │ │ └── Writer.java │ ├── lang │ │ ├── Appendable.java │ │ ├── ArithmeticException.java │ │ ├── ArrayIndexOutOfBoundsException.java │ │ ├── ArrayMethods.java │ │ ├── AutoCloseable.java │ │ ├── Boolean.java │ │ ├── CharSequence.java │ │ ├── Character.java │ │ ├── Class.java │ │ ├── ClassCastException.java │ │ ├── ClassLoader.java │ │ ├── ClassNotFoundException.java │ │ ├── CloneNotSupportedException.java │ │ ├── Cloneable.java │ │ ├── Comparable.java │ │ ├── Deprecated.java │ │ ├── Double.java │ │ ├── Enum.java │ │ ├── Error.java │ │ ├── Exception.java │ │ ├── FunctionalInterface.java │ │ ├── IllegalArgumentException.java │ │ ├── IncompatibleClassChangeError.java │ │ ├── IndexOutOfBoundsException.java │ │ ├── Integer.java │ │ ├── Iterable.java │ │ ├── LinkageError.java │ │ ├── Long.java │ │ ├── Math.java │ │ ├── NoClassDefException.java │ │ ├── NoSuchFieldError.java │ │ ├── NoSuchMethodError.java │ │ ├── NullPointerException.java │ │ ├── Number.java │ │ ├── NumberFormatException.java │ │ ├── Object.java │ │ ├── Override.java │ │ ├── Process.java │ │ ├── Runnable.java │ │ ├── Runtime.java │ │ ├── RuntimeException.java │ │ ├── StackTraceElement.java │ │ ├── String.java │ │ ├── StringBuffer.java │ │ ├── StringBuilder.java │ │ ├── System.java │ │ ├── Thread.java │ │ ├── Throwable.java │ │ ├── TypeNotPresentException.java │ │ ├── UnsatisfiedLinkError.java │ │ ├── UnsupportedOperationException.java │ │ ├── annotation │ │ │ ├── Annotation.java │ │ │ ├── Documented.java │ │ │ ├── ElementType.java │ │ │ ├── Retention.java │ │ │ ├── RetentionPolicy.java │ │ │ └── Target.java │ │ └── reflect │ │ │ ├── AccessibleObject.java │ │ │ └── AnnotatedElement.java │ ├── nio │ │ ├── Buffer.java │ │ ├── BufferOverflowException.java │ │ ├── BufferUnderflowException.java │ │ ├── ByteBuffer.java │ │ ├── ByteOrder.java │ │ ├── ReadOnlyBufferException.java │ │ ├── charset │ │ │ ├── Charset.java │ │ │ └── StandardCharsets.java │ │ └── impl │ │ │ ├── AbstractByteBufferImpl.java │ │ │ ├── ArrayByteBufferImpl.java │ │ │ └── DirectByteBufferImpl.java │ └── util │ │ ├── AbstractCollection.java │ │ ├── AbstractList.java │ │ ├── AbstractSet.java │ │ ├── ArrayDeque.java │ │ ├── ArrayList.java │ │ ├── Collection.java │ │ ├── Comparator.java │ │ ├── ConcurrentModificationException.java │ │ ├── Date.java │ │ ├── Deque.java │ │ ├── Enumeration.java │ │ ├── EventListener.java │ │ ├── EventObject.java │ │ ├── Formatter.java │ │ ├── Iterator.java │ │ ├── LinkedList.java │ │ ├── List.java │ │ ├── ListIterator.java │ │ ├── Map.java │ │ ├── NoSuchElementException.java │ │ ├── Objects.java │ │ ├── Optional.java │ │ ├── Queue.java │ │ ├── RandomAccess.java │ │ ├── Set.java │ │ └── function │ │ ├── Consumer.java │ │ ├── Function.java │ │ ├── Predicate.java │ │ └── Supplier.java │ └── lukyt │ ├── ChildNotFoundException.java │ ├── LuaInputStream.java │ ├── LuaObject.java │ ├── Os.java │ └── awt │ └── iup │ ├── IUP.java │ ├── IUPGraphics2D.java │ ├── IUPToolkit.java │ ├── package-info.java │ └── peer │ └── IUPComponentPeer.java └── test ├── ComponentTest.class ├── ComponentTest.java ├── CosineTest.class ├── CosineTest.java ├── HelloWorld$1.class ├── HelloWorld.class ├── HelloWorld.java ├── JavaShell$CommandNotFoundException.class ├── JavaShell.class ├── JavaShell.java ├── StargazerTest.class ├── StargazerTest.java ├── ThreadTest$1.class ├── ThreadTest$2.class ├── ThreadTest.class ├── ThreadTest.java ├── build └── bulid.bat /.gitignore: -------------------------------------------------------------------------------- 1 | jexer 2 | gnucp 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Zen1th 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lukyt 2 | Lukyt is a toy project, a small JVM made in Lua supporting Java 6. 3 | The most important reason i made it (other than being a toy project) was to run it on the [OpenComputers](https://github.com/MightyPirates/OpenComputers) mod. I am currently porting AWT to it to use Java software on OpenComputers. 4 | 5 | This also supports a OpenComputers Java API shared with OCJ (link to come, will be released by [@TYKUHN2](https://github.com/TYKUHN2)), this way programs are compatible for both way of running Java on OC, its javadoc is available on [my website](https://bwsecondary.ddns.net/jd/cil/li/oc/package-summary.html), Lukyt also have a Lua interop, which also haves a [javadoc](https://bwsecondary.ddns.net/jd/lukyt/package-summary.html). 6 | 7 | Note that unlike Luje, this is aimed towards features: OC and Lua interoptability. 8 | 9 | [Roadmap](https://github.com/zenith391/lukyt/projects/1) 10 | 11 | ## How to use? 12 | The JVM itself can be used by any program and is independent from the command-line program. 13 | 14 | The command line program allows to execute classes. 15 | 16 | To launch the HelloWorld test, just do: 17 | ```sh 18 | lua lukyt.lua --classpath=test HelloWorld 19 | ``` 20 | 21 | ## Examples 22 | 23 | Here is an example of the OC integration: 24 | ```java 25 | import cil.li.oc.Components; 26 | import cil.li.oc.proxies.GPUProxy; 27 | 28 | public class ComponentTest { 29 | 30 | public static void main(String[] args) { 31 | GPUProxy gpu = Components.getPrimary("gpu"); 32 | gpu.setBackground(0x2D2D2D); 33 | gpu.fill(1, 1, 160, 50, ' '); 34 | System.out.println("Filled screen with color 0x2D2D2D"); 35 | } 36 | 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /jvm/classLoader.lua: -------------------------------------------------------------------------------- 1 | local classLoader = {} 2 | local classCache = {} 3 | local initedClasses = {} 4 | classLoader.classReferences = {} 5 | classLoader.classpath = {} 6 | local class = require("class") 7 | local types = require("type") 8 | 9 | function classLoader.getReferencedClass(ref) 10 | return classLoader.classReferences[ref] 11 | end 12 | 13 | function classLoader.classObject(class, thread) 14 | local ref = -1 15 | for k, v in pairs(classLoader.classReferences) do 16 | if v == class then 17 | ref = k 18 | end 19 | end 20 | local classClass = classLoader.loadClass("java/lang/Class", true) 21 | return thread:instantiateClass(classClass, {types.new("long", ref)}, true, "(J)V") 22 | end 23 | 24 | function classLoader.loadClass(path, init) 25 | local cl, err 26 | for _, v in pairs(classLoader.classpath) do 27 | cl, err = classLoader.loadExternalClass(v .. path .. ".class") 28 | if not cl and err ~= "not found" then error(err) end 29 | if cl then 30 | break 31 | end 32 | end 33 | if cl then 34 | local contains = false 35 | for k, v in pairs(classLoader.classReferences) do 36 | if v == cl then 37 | contains = true 38 | end 39 | end 40 | if not contains then 41 | table.insert(classLoader.classReferences, cl) 42 | end 43 | end 44 | if cl and init and not initedClasses[path] then 45 | initedClasses[path] = true 46 | local clInit 47 | for _,v in pairs(cl.methods) do 48 | local isStatic = (v.accessFlags & 0x8) == 0x8 49 | --print(v.class.name .. ": " .. v.name .. ": " .. string.format("0x%x", v.accessFlags)) 50 | if v.name == "" then 51 | clInit = v 52 | end 53 | end 54 | for _,v in pairs(cl.fields) do 55 | if v.staticValue[1] == "defer" then 56 | v.staticValue = require("native").luaToString(v.staticValue[2], mainThread) 57 | end 58 | end 59 | local classReference = types.referenceForClass(cl) 60 | if clInit then 61 | local throwable = mainThread:executeMethod(cl, clInit, {}) 62 | if throwable then 63 | local throwedClass = throwable[2].class[2].class 64 | mainThread:executeMethod(throwedClass, mainThread:findMethod(throwedClass, "printStackTrace", "()V"), {throwable}) 65 | end 66 | end 67 | end 68 | return cl, err 69 | end 70 | 71 | function classLoader.loadExternalClass(path) 72 | if classCache[path] then 73 | return classCache[path] 74 | else 75 | local stream = io.open(path, "rb") 76 | if not stream then 77 | return nil, "not found" 78 | end 79 | local cl = class.read(stream) 80 | classCache[path] = cl 81 | stream:close() 82 | return cl 83 | end 84 | end 85 | 86 | return classLoader 87 | -------------------------------------------------------------------------------- /jvm/native.lua: -------------------------------------------------------------------------------- 1 | -- API for Lua <-> Java integration 2 | local native = {} 3 | local classLoader = require("classLoader") 4 | local types = require("type") 5 | 6 | -- Transforms a Java string to a Lua string 7 | function native.stringToLua(obj) 8 | if obj[2].type == "null" then 9 | error("null string") 10 | end 11 | local chars = obj[2].object["chars"] 12 | local array = chars[2].array 13 | local str = "" 14 | local toChar = (utf8 and utf8.char) or string.char -- use utf8 if available 15 | 16 | for k, v in ipairs(array) do 17 | str = str .. toChar(v[2]) 18 | end 19 | 20 | return str 21 | end 22 | 23 | function native.luaToString(str, thread) 24 | local objectClass, err = classLoader.loadClass("java/lang/String", true) 25 | if not objectClass then 26 | error("could not import java/lang/String !!! " .. err) 27 | end 28 | local array = {} 29 | local toByte = (utf8 and utf8.codepoint) or string.byte -- use utf8 if available 30 | for i=1, #str do 31 | -- TODO: support characters with code point above 65,535 32 | table.insert(array, types.new("char", toByte(str:sub(i,i)))) 33 | end 34 | local object = thread:instantiateClass(objectClass, {types.referenceForArray(array)}, true, "([C)V") 35 | return object 36 | end 37 | 38 | function native.byteBufferGet(buf, idx, thread) 39 | 40 | end 41 | 42 | return native 43 | -------------------------------------------------------------------------------- /jvm/type.lua: -------------------------------------------------------------------------------- 1 | local lib = {} 2 | local typeMapping = { -- use short types for less memory usage 3 | byte = "B", 4 | int = "I", 5 | short = "S", 6 | long = "J", 7 | char = "C", 8 | double = "D", 9 | float = "F", 10 | object = "O", 11 | reference = "R", 12 | returnAddress = "A" 13 | } 14 | 15 | function lib.nullReference() 16 | return lib.new("reference", { 17 | type = "null" -- null reference type 18 | }) 19 | end 20 | 21 | function lib.referenceForArray(array) 22 | return lib.new("reference", { 23 | type = "array", 24 | array = array 25 | }) 26 | end 27 | 28 | function lib.referenceForClass(class) 29 | return lib.new("reference", { 30 | type = "class", 31 | class = class 32 | }) 33 | end 34 | 35 | function lib.readFieldDescriptor(descriptor) 36 | local t = descriptor:sub(1,1) 37 | if t == "I" then 38 | return { 39 | type = "int" 40 | }, 2 41 | elseif t == "B" then 42 | return { 43 | type = "byte" 44 | }, 2 45 | elseif t == "C" then 46 | return { 47 | type = "char" 48 | }, 2 49 | elseif t == "D" then 50 | return { 51 | type = "double" 52 | }, 2 53 | elseif t == "F" then 54 | return { 55 | type = "float" 56 | }, 2 57 | elseif t == "J" then 58 | return { 59 | type = "long" 60 | }, 2 61 | elseif t == "S" then 62 | return { 63 | type = "short" 64 | }, 2 65 | elseif t == "Z" then 66 | return { 67 | type = "boolean" 68 | }, 2 69 | elseif t == "L" then 70 | local classNameEnd = descriptor:find(";") - 1 71 | local className = descriptor:sub(2, classNameEnd) 72 | return { 73 | type = "object", 74 | className = className 75 | }, 2+classNameEnd 76 | elseif t == "[" then 77 | local component, cpSubIndex = lib.readFieldDescriptor(descriptor:sub(2)) 78 | return { 79 | type = "array", 80 | component = component 81 | }, 1 + cpSubIndex 82 | end 83 | error("unknown type: '" .. t .. "'") 84 | end 85 | 86 | function lib.readMethodDescriptor(descriptor) 87 | local parameters = {} 88 | local endParam = descriptor:find(")") 89 | local paramDesc = descriptor:sub(2, endParam-1) 90 | if paramDesc:len() > 0 then 91 | while true do 92 | local param, subIndex = lib.readFieldDescriptor(paramDesc) 93 | table.insert(parameters, param) 94 | paramDesc = paramDesc:sub(subIndex) 95 | if paramDesc:len() == 0 then 96 | break 97 | end 98 | end 99 | end 100 | return { 101 | params = parameters 102 | } 103 | end 104 | 105 | function lib.new(v, t) 106 | return {typeMapping[v], t} 107 | end 108 | 109 | function lib.type(obj) 110 | for k, v in pairs(typeMapping) do 111 | if v == obj[1] then 112 | return k 113 | end 114 | end 115 | end 116 | 117 | return lib -------------------------------------------------------------------------------- /lukyt-oc.lua: -------------------------------------------------------------------------------- 1 | local oldPath = package.path 2 | local oldLoaded = package.loaded 3 | package.path = "./jvm/?.lua" 4 | package.loaded["thread"] = nil 5 | package.loaded["classLoader"] = nil 6 | local doDebug = false 7 | function printDebug(...) 8 | if doDebug then 9 | print(...) 10 | end 11 | end 12 | 13 | local file = nil 14 | local args = table.pack(...) 15 | local printHelp = true 16 | local cp = "./" 17 | local bcp = "./std/bin/" -- bootstrap class path 18 | systemProperties = { 19 | ["java.version"] = "6", 20 | ["java.vendor"] = "Lukyt", 21 | ["java.vendor.url"] = "https://github.com/zenith391/lukyt", 22 | ["java.vm.specification.version"] = "6", 23 | ["java.vm.specification.vendor"] = "Oracle?", 24 | ["java.vm.specification.name"] = "Mustang", 25 | ["java.vm.version"] = "6", 26 | ["java.vm.vendor"] = "Lukyt", 27 | ["java.vm.name"] = "Lukyt", 28 | ["java.class.version"] = "50.0", 29 | ["java.class.path"] = "", -- TODO 30 | ["java.library.path"] = "/;./", 31 | ["java.io.tmpdir"] = "/tmp", 32 | ["java.compiler"] = "no jit", 33 | ["os.name"] = _OSVERSION:sub(1, _OSVERSION:find(" ")), 34 | ["os.arch"] = _VERSION, 35 | ["os.version"] = _OSVERSION:sub(8), 36 | ["file.separator"] = "/", 37 | ["line.separator"] = "\n", 38 | ["path.separator"] = ":", 39 | ["user.name"] = os.getenv("USER") or "Unknown", 40 | ["user.home"] = os.getenv("HOME"), 41 | ["user.dir"] = os.getenv("PWD") or "PWD not detected" 42 | } 43 | 44 | for k, v in ipairs(args) do 45 | if v == "--debug" then 46 | doDebug = true 47 | elseif v == "--help" then 48 | break 49 | elseif v:sub(1,6) == "--jit=" then 50 | local jitName = v:sub(7) 51 | if jitName == "none" then 52 | _G.jitEngine = nil 53 | else 54 | _G.jitEngine = require("jit_" .. jitName) 55 | end 56 | elseif v:sub(1,12) == "--classpath=" then 57 | cp = v:sub(13) 58 | if cp:sub(#cp,#cp) ~= "/" then 59 | cp = cp .. "/" 60 | end 61 | elseif v:sub(1,5) == "--cp=" then 62 | cp = v:sub(6) 63 | if cp:sub(#cp,#cp) ~= "/" then 64 | cp = cp .. "/" 65 | end 66 | elseif v:sub(1,22) == "--bootstrap-classpath=" then 67 | bcp = v:sub(23) 68 | if bcp:sub(#bcp,#bcp) ~= "/" then 69 | bcp = bcp .. "/" 70 | end 71 | elseif v:sub(1,2) == "-D" then 72 | local equalsIndex = string.find(v, "=") 73 | equalsIndex = equalsIndex or v:len()+1 74 | local name = v:sub(3,equalsIndex-1) 75 | local value = v:sub(equalsIndex+1) 76 | if value:len() == 0 then 77 | value = "true" 78 | end 79 | systemProperties[name] = value 80 | elseif not file then 81 | file = v .. ".class" 82 | printHelp = false 83 | else 84 | error("unrecognized argument: " .. v) 85 | end 86 | end 87 | 88 | if printHelp then 89 | print("lukyt ") 90 | print(" --debug: Enable debug logging") 91 | print(" --jit=engine: Set the JIT engine.") 92 | print(" Default: none") 93 | print(" Available: freqs, none") 94 | print(" --classpath=path: Set the classpath to search non-bootstrap classes") 95 | print(" Default: ./") 96 | print(" --cp=path: Short for --classpath=path") 97 | print(" --bootstrap-classpath=path: Set the classpath to search bootstrap classes") 98 | print(" Default: ./std/bin/") 99 | print(" -Dname=value: Define Java system property") 100 | print(" ex: -Dos.name=JEternal") 101 | return 102 | end 103 | 104 | local class = require("class") 105 | local classLoader = require("classLoader") 106 | local thread = require("thread") 107 | local types = require("type") 108 | require("nativeDefault") -- default native functions 109 | 110 | table.insert(classLoader.classpath, bcp) 111 | table.insert(classLoader.classpath, cp) 112 | 113 | mainThread = thread.new() 114 | local cl = classLoader.loadClass(file:sub(1,file:len()-6), true) 115 | if not cl then 116 | error("Main class not found. Did you forgot classpath?") 117 | end 118 | 119 | local object = mainThread:instantiateClass(cl) 120 | 121 | local mainMethod = nil 122 | 123 | for k,v in pairs(cl.methods) do 124 | if v.name == "main" then 125 | mainMethod = v 126 | end 127 | end 128 | 129 | local argsArray = types.referenceForArray({}) 130 | printDebug("Calling main(String[])") 131 | local throwable = mainThread:executeMethod(cl, mainMethod, {object, argsArray}) 132 | 133 | if throwable then 134 | local throwedClass = throwable[2].class[2].class 135 | io.stdout:write("Exception in thread \"" .. mainThread.name .. "\" ") 136 | mainThread:executeMethod(throwedClass, thread.findMethod(throwedClass, "printStackTrace", "()V"), {throwable}) 137 | end 138 | 139 | package.path = oldPath 140 | package.loaded = oldLoaded 141 | -------------------------------------------------------------------------------- /std/bin/cil/li/oc/Component.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/cil/li/oc/Component.class -------------------------------------------------------------------------------- /std/bin/cil/li/oc/ComponentProxy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/cil/li/oc/ComponentProxy.class -------------------------------------------------------------------------------- /std/bin/cil/li/oc/Components.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/cil/li/oc/Components.class -------------------------------------------------------------------------------- /std/bin/cil/li/oc/Utils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/cil/li/oc/Utils.class -------------------------------------------------------------------------------- /std/bin/cil/li/oc/proxies/GPUProxy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/cil/li/oc/proxies/GPUProxy.class -------------------------------------------------------------------------------- /std/bin/java/awt/Color.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/awt/Color.class -------------------------------------------------------------------------------- /std/bin/java/io/BufferedReader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/BufferedReader.class -------------------------------------------------------------------------------- /std/bin/java/io/Closeable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/Closeable.class -------------------------------------------------------------------------------- /std/bin/java/io/ConsoleInputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/ConsoleInputStream.class -------------------------------------------------------------------------------- /std/bin/java/io/ConsolePrintStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/ConsolePrintStream.class -------------------------------------------------------------------------------- /std/bin/java/io/File.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/File.class -------------------------------------------------------------------------------- /std/bin/java/io/FileDescriptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/FileDescriptor.class -------------------------------------------------------------------------------- /std/bin/java/io/FileInputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/FileInputStream.class -------------------------------------------------------------------------------- /std/bin/java/io/FileOutputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/FileOutputStream.class -------------------------------------------------------------------------------- /std/bin/java/io/FilterOutputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/FilterOutputStream.class -------------------------------------------------------------------------------- /std/bin/java/io/Flushable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/Flushable.class -------------------------------------------------------------------------------- /std/bin/java/io/IOException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/IOException.class -------------------------------------------------------------------------------- /std/bin/java/io/InputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/InputStream.class -------------------------------------------------------------------------------- /std/bin/java/io/InputStreamReader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/InputStreamReader.class -------------------------------------------------------------------------------- /std/bin/java/io/OutputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/OutputStream.class -------------------------------------------------------------------------------- /std/bin/java/io/OutputStreamWriter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/OutputStreamWriter.class -------------------------------------------------------------------------------- /std/bin/java/io/PrintStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/PrintStream.class -------------------------------------------------------------------------------- /std/bin/java/io/PrintWriter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/PrintWriter.class -------------------------------------------------------------------------------- /std/bin/java/io/Reader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/Reader.class -------------------------------------------------------------------------------- /std/bin/java/io/Serializable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/Serializable.class -------------------------------------------------------------------------------- /std/bin/java/io/Writer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/io/Writer.class -------------------------------------------------------------------------------- /std/bin/java/lang/Appendable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Appendable.class -------------------------------------------------------------------------------- /std/bin/java/lang/ArithmeticException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ArithmeticException.class -------------------------------------------------------------------------------- /std/bin/java/lang/ArrayIndexOutOfBoundsException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ArrayIndexOutOfBoundsException.class -------------------------------------------------------------------------------- /std/bin/java/lang/ArrayMethods.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ArrayMethods.class -------------------------------------------------------------------------------- /std/bin/java/lang/AutoCloseable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/AutoCloseable.class -------------------------------------------------------------------------------- /std/bin/java/lang/Boolean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Boolean.class -------------------------------------------------------------------------------- /std/bin/java/lang/CharSequence.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/CharSequence.class -------------------------------------------------------------------------------- /std/bin/java/lang/Character.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Character.class -------------------------------------------------------------------------------- /std/bin/java/lang/Class.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Class.class -------------------------------------------------------------------------------- /std/bin/java/lang/ClassCastException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ClassCastException.class -------------------------------------------------------------------------------- /std/bin/java/lang/ClassLoader$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ClassLoader$1.class -------------------------------------------------------------------------------- /std/bin/java/lang/ClassLoader$SystemClassLoader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ClassLoader$SystemClassLoader.class -------------------------------------------------------------------------------- /std/bin/java/lang/ClassLoader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ClassLoader.class -------------------------------------------------------------------------------- /std/bin/java/lang/ClassNotFoundException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/ClassNotFoundException.class -------------------------------------------------------------------------------- /std/bin/java/lang/CloneNotSupportedException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/CloneNotSupportedException.class -------------------------------------------------------------------------------- /std/bin/java/lang/Cloneable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Cloneable.class -------------------------------------------------------------------------------- /std/bin/java/lang/Comparable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Comparable.class -------------------------------------------------------------------------------- /std/bin/java/lang/Deprecated.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Deprecated.class -------------------------------------------------------------------------------- /std/bin/java/lang/Double.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Double.class -------------------------------------------------------------------------------- /std/bin/java/lang/Enum.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Enum.class -------------------------------------------------------------------------------- /std/bin/java/lang/Error.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Error.class -------------------------------------------------------------------------------- /std/bin/java/lang/Exception.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Exception.class -------------------------------------------------------------------------------- /std/bin/java/lang/FunctionalInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/FunctionalInterface.class -------------------------------------------------------------------------------- /std/bin/java/lang/IllegalArgumentException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/IllegalArgumentException.class -------------------------------------------------------------------------------- /std/bin/java/lang/IncompatibleClassChangeError.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/IncompatibleClassChangeError.class -------------------------------------------------------------------------------- /std/bin/java/lang/IndexOutOfBoundsException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/IndexOutOfBoundsException.class -------------------------------------------------------------------------------- /std/bin/java/lang/Integer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Integer.class -------------------------------------------------------------------------------- /std/bin/java/lang/Iterable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Iterable.class -------------------------------------------------------------------------------- /std/bin/java/lang/LinkageError.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/LinkageError.class -------------------------------------------------------------------------------- /std/bin/java/lang/Long.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Long.class -------------------------------------------------------------------------------- /std/bin/java/lang/Math.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Math.class -------------------------------------------------------------------------------- /std/bin/java/lang/NoClassDefException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/NoClassDefException.class -------------------------------------------------------------------------------- /std/bin/java/lang/NoSuchFieldError.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/NoSuchFieldError.class -------------------------------------------------------------------------------- /std/bin/java/lang/NoSuchMethodError.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/NoSuchMethodError.class -------------------------------------------------------------------------------- /std/bin/java/lang/NullPointerException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/NullPointerException.class -------------------------------------------------------------------------------- /std/bin/java/lang/Number.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Number.class -------------------------------------------------------------------------------- /std/bin/java/lang/NumberFormatException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/NumberFormatException.class -------------------------------------------------------------------------------- /std/bin/java/lang/Object.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Object.class -------------------------------------------------------------------------------- /std/bin/java/lang/Override.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Override.class -------------------------------------------------------------------------------- /std/bin/java/lang/Process.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Process.class -------------------------------------------------------------------------------- /std/bin/java/lang/Runnable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Runnable.class -------------------------------------------------------------------------------- /std/bin/java/lang/Runtime$RuntimeProcess.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Runtime$RuntimeProcess.class -------------------------------------------------------------------------------- /std/bin/java/lang/Runtime.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Runtime.class -------------------------------------------------------------------------------- /std/bin/java/lang/RuntimeException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/RuntimeException.class -------------------------------------------------------------------------------- /std/bin/java/lang/StackTraceElement.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/StackTraceElement.class -------------------------------------------------------------------------------- /std/bin/java/lang/String.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/String.class -------------------------------------------------------------------------------- /std/bin/java/lang/StringBuffer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/StringBuffer.class -------------------------------------------------------------------------------- /std/bin/java/lang/StringBuilder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/StringBuilder.class -------------------------------------------------------------------------------- /std/bin/java/lang/System.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/System.class -------------------------------------------------------------------------------- /std/bin/java/lang/Thread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Thread.class -------------------------------------------------------------------------------- /std/bin/java/lang/Throwable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/Throwable.class -------------------------------------------------------------------------------- /std/bin/java/lang/TypeNotPresentException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/TypeNotPresentException.class -------------------------------------------------------------------------------- /std/bin/java/lang/UnsatisfiedLinkError.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/UnsatisfiedLinkError.class -------------------------------------------------------------------------------- /std/bin/java/lang/UnsupportedOperationException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/UnsupportedOperationException.class -------------------------------------------------------------------------------- /std/bin/java/lang/annotation/Annotation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/annotation/Annotation.class -------------------------------------------------------------------------------- /std/bin/java/lang/annotation/Documented.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/annotation/Documented.class -------------------------------------------------------------------------------- /std/bin/java/lang/annotation/ElementType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/annotation/ElementType.class -------------------------------------------------------------------------------- /std/bin/java/lang/annotation/Retention.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/annotation/Retention.class -------------------------------------------------------------------------------- /std/bin/java/lang/annotation/RetentionPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/annotation/RetentionPolicy.class -------------------------------------------------------------------------------- /std/bin/java/lang/annotation/Target.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/lang/annotation/Target.class -------------------------------------------------------------------------------- /std/bin/java/util/AbstractCollection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/AbstractCollection.class -------------------------------------------------------------------------------- /std/bin/java/util/AbstractList$AbstractListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/AbstractList$AbstractListIterator.class -------------------------------------------------------------------------------- /std/bin/java/util/AbstractList$AbstractSubList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/AbstractList$AbstractSubList.class -------------------------------------------------------------------------------- /std/bin/java/util/AbstractList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/AbstractList.class -------------------------------------------------------------------------------- /std/bin/java/util/AbstractSet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/AbstractSet.class -------------------------------------------------------------------------------- /std/bin/java/util/ArrayDeque$ArrayDequeIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/ArrayDeque$ArrayDequeIterator.class -------------------------------------------------------------------------------- /std/bin/java/util/ArrayDeque.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/ArrayDeque.class -------------------------------------------------------------------------------- /std/bin/java/util/ArrayList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/ArrayList.class -------------------------------------------------------------------------------- /std/bin/java/util/Collection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Collection.class -------------------------------------------------------------------------------- /std/bin/java/util/Comparator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Comparator.class -------------------------------------------------------------------------------- /std/bin/java/util/ConcurrentModificationException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/ConcurrentModificationException.class -------------------------------------------------------------------------------- /std/bin/java/util/Date.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Date.class -------------------------------------------------------------------------------- /std/bin/java/util/Deque.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Deque.class -------------------------------------------------------------------------------- /std/bin/java/util/Enumeration.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Enumeration.class -------------------------------------------------------------------------------- /std/bin/java/util/EventListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/EventListener.class -------------------------------------------------------------------------------- /std/bin/java/util/EventObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/EventObject.class -------------------------------------------------------------------------------- /std/bin/java/util/Formatter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Formatter.class -------------------------------------------------------------------------------- /std/bin/java/util/Iterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Iterator.class -------------------------------------------------------------------------------- /std/bin/java/util/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/LinkedList.class -------------------------------------------------------------------------------- /std/bin/java/util/List.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/List.class -------------------------------------------------------------------------------- /std/bin/java/util/ListIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/ListIterator.class -------------------------------------------------------------------------------- /std/bin/java/util/Map$Entry.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Map$Entry.class -------------------------------------------------------------------------------- /std/bin/java/util/Map.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Map.class -------------------------------------------------------------------------------- /std/bin/java/util/NoSuchElementException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/NoSuchElementException.class -------------------------------------------------------------------------------- /std/bin/java/util/Objects.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Objects.class -------------------------------------------------------------------------------- /std/bin/java/util/Optional.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Optional.class -------------------------------------------------------------------------------- /std/bin/java/util/Queue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Queue.class -------------------------------------------------------------------------------- /std/bin/java/util/RandomAccess.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/RandomAccess.class -------------------------------------------------------------------------------- /std/bin/java/util/Set.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/Set.class -------------------------------------------------------------------------------- /std/bin/java/util/function/Consumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/function/Consumer.class -------------------------------------------------------------------------------- /std/bin/java/util/function/Function.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/function/Function.class -------------------------------------------------------------------------------- /std/bin/java/util/function/Predicate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/function/Predicate.class -------------------------------------------------------------------------------- /std/bin/java/util/function/Supplier.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/java/util/function/Supplier.class -------------------------------------------------------------------------------- /std/bin/lukyt/ChildNotFoundException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/lukyt/ChildNotFoundException.class -------------------------------------------------------------------------------- /std/bin/lukyt/LuaInputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/lukyt/LuaInputStream.class -------------------------------------------------------------------------------- /std/bin/lukyt/LuaObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/lukyt/LuaObject.class -------------------------------------------------------------------------------- /std/bin/lukyt/OS.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/lukyt/OS.class -------------------------------------------------------------------------------- /std/bin/lukyt/Os.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/std/bin/lukyt/Os.class -------------------------------------------------------------------------------- /std/build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd src 3 | export JAVA_COMPILE="/usr/lib/jvm/java-8-openjdk-amd64/bin/javac -Xlint:-options -d ../bin -source 8 -target 8" 4 | $JAVA_COMPILE java/lang/*.java java/io/*.java java/util/*.java cil/li/oc/*.java java/awt/Color.java 5 | javadoc -keywords -d /usr/local/nginx/html/jd cil.li.oc lukyt 6 | cd .. 7 | -------------------------------------------------------------------------------- /std/src/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.classpath": true, 4 | "**/.project": true, 5 | "**/.settings": true, 6 | "**/.factorypath": true 7 | } 8 | } -------------------------------------------------------------------------------- /std/src/cil/li/oc/ComponentProxy.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc; 2 | 3 | /** 4 | Abstract class for component proxies. This is equivalent to component.proxy("xyz") and component.xyz on Lua 5 | **/ 6 | public abstract class ComponentProxy { 7 | 8 | public abstract String getAddress(); 9 | public abstract String getType(); 10 | 11 | } -------------------------------------------------------------------------------- /std/src/cil/li/oc/Components.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc; 2 | 3 | import lukyt.LuaObject; 4 | 5 | import cil.li.oc.proxies.*; 6 | 7 | /** 8 | Class used to access the component API. 9 | **/ 10 | public final class Components { 11 | 12 | private static final LuaObject inst = Utils.require.execute(LuaObject.fromString("component")); 13 | 14 | private Components() {} 15 | 16 | /** 17 | Returns the documentation string for the method with the specified name of the component 18 | with the specified address, if any.
19 | **/ 20 | public static String doc(String address, String method) { 21 | return inst.executeChild("doc", new LuaObject[] {LuaObject.fromString(address), LuaObject.fromString(method)}) 22 | .asString(); 23 | } 24 | 25 | /** 26 | Invoke component's method with specified component address and with arguments 27 | args
28 | 29 | This returns all the results of the call.
30 | If needed, objects are serialized to lua objects, in that case, Object can be one of: 31 |
37 | Functions are serialized to their java.util.function equivalent. 38 | That serialization is also applied to results. 39 | **/ 40 | public static Object[] invoke(String address, String method, Object... args) { 41 | LuaObject[] finalArgs = new LuaObject[args.length + 2]; 42 | finalArgs[0] = LuaObject.fromString(address); 43 | finalArgs[1] = LuaObject.fromString(method); 44 | for (int i = 0; i < args.length; i++) { 45 | finalArgs[i+2] = LuaObject.from(args[i]); 46 | } 47 | LuaObject[] result = inst.get("invoke").executeAll(finalArgs); 48 | Object[] ret = new Object[result.length]; 49 | for (int i = 0; i < result.length; i++) { 50 | ret[i] = result[i].asObject(); 51 | } 52 | return ret; 53 | } 54 | 55 | /** 56 | Get the primary component.
57 | Unlike Lua, this returns the address.
58 | @throws UnsupportedOperationException when the environment doesn't support getPrimary() (ex: no OS or the OS doesn't use that function). 59 | **/ 60 | public static String getPrimaryAddress(String type) { 61 | return inst.executeChild("getPrimary", new LuaObject[] {LuaObject.fromString(type)}) 62 | .get("address").asString(); 63 | } 64 | 65 | /** 66 | Gets the proxy for the primary component of the specified type.
67 | 68 | Throws an error if there is no primary component of the specified type. 69 | **/ 70 | public static T getPrimary(String type) { 71 | LuaObject l = inst.executeChild("getPrimary", new LuaObject[] {LuaObject.fromString(type)}); 72 | return luaToJavaProxy(l); 73 | } 74 | 75 | /** 76 | Gets a 'proxy' object for a component, this provides all methods the component provides so they can be called more directly (instead of via invoke). 77 | 78 | This is what's used to generate 'primaries' of the individual component types, i.e. what you get via {@link #getPrimary(String)} 79 | **/ 80 | public static T getProxy(String address) { 81 | LuaObject l = inst.executeChild("proxy", new LuaObject[] {LuaObject.fromString(address)}); 82 | return luaToJavaProxy(l); 83 | } 84 | 85 | private static T luaToJavaProxy(LuaObject proxy) { 86 | String type = proxy.get("type").asString(); 87 | if (type.equals("gpu")) { 88 | return (T) new GPUProxy(proxy); 89 | } else { 90 | throw new IllegalArgumentException("type not supported"); 91 | } 92 | } 93 | 94 | /** 95 | SPECIFIC TO LUKYT : should not actually be used, this was some support function 96 | for complex lua object types but shouldn't be used now. 97 | **/ 98 | public static LuaObject[] invoke(String address, String method, LuaObject[] args) { 99 | LuaObject[] nArgs = new LuaObject[args.length + 2]; 100 | nArgs[0] = LuaObject.fromString(address); 101 | nArgs[1] = LuaObject.fromString(method); 102 | for (int i = 0; i < args.length; i++) { 103 | nArgs[i+2] = args[i]; 104 | } 105 | return inst.get("invoke").executeAll(nArgs); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /std/src/cil/li/oc/Utils.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc; 2 | import lukyt.LuaObject; 3 | 4 | /** 5 | Implementation-specific (Lukyt) for OC integration classes. 6 | **/ 7 | class Utils { 8 | static final LuaObject require = LuaObject._ENV.get("require"); 9 | } 10 | -------------------------------------------------------------------------------- /std/src/cil/li/oc/awt/GPUDrawer.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc.awt; 2 | 3 | public interface GPUDrawer { 4 | 5 | public Dimension getResolution(); 6 | public void setGPUAddress(String address); 7 | public void horizontalLine(int x, int y, int width, int rgb); 8 | public void verticalLine(int x, int y, int height, int rgb); 9 | public void set(int x, int y, int rgb); 10 | public void fill(int x, int y, int width, int height, int rgb); 11 | 12 | } -------------------------------------------------------------------------------- /std/src/cil/li/oc/awt/GPUGraphics2D.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc.awt; 2 | 3 | import java.awt.*; 4 | import java.awt.geom.*; 5 | import java.util.*; 6 | 7 | /** 8 | Maps virtual screen (320x200) to physical screen (160x50) using braille characters. 9 | **/ 10 | public class GPUGraphics2D extends Graphics2D { 11 | 12 | private GPUDrawer drawer = new SemiBrailleGPUDrawer(); 13 | private AffineTransform at = new AffineTransform( 14 | 1, 0, 0, 15 | 0, 1, 0 16 | ); 17 | 18 | // Helper point methods 19 | protected Point2D.Float add(Point2D p0, Point2D p1) { 20 | return new Point2D.Float(p0.getX() + p1.getX(), p0.getY() + p1.getY()); 21 | } 22 | 23 | protected Point2D.Float sub(Point2D p0, Point2D p1) { 24 | return new Point2D.Float(p0.getX() - p1.getX(), p0.getY() - p1.getY()); 25 | } 26 | 27 | protected Point2D.Float mul(Point2D p, float scalar) { 28 | return new Point2D.Float(p.getX() * scalar, p.getY() * scalar); 29 | } 30 | 31 | // Precision for Bezier curves need to scale with the curve's size in order to not have unfilled dots between lines 32 | // Precision is the number of points. 33 | protected Point[] linearBezier(Point2D p0, Point2D p1, int precision) { 34 | Point[] points = new Point[precision]; 35 | for (int i = 0; i < precision; i++) { 36 | float t = (float) i / (float) precision; 37 | Point2D p2d = add(p0, mul(sub(p0, p1), t)); // = P0 + t*(P1-P0) 38 | points[i] = new Point((int) p2d.getX(), (int) p2d.getY()); 39 | } 40 | return points; 41 | } 42 | 43 | protected void drawLinearBezier(Point2D p0, Point2D p1) { 44 | Point[] points = linearBezier(p0, p1, 10); 45 | Point lastPoint = new Point(-1, -1); 46 | for (Point point : points) { 47 | if (!point.equals(lastPoint)) { 48 | drawer.set((int) point.getX(), (int) point.getY(), 0xFFFFFF); 49 | lastPoint = point; 50 | } 51 | } 52 | } 53 | 54 | public void drawRect(int x, int y, int width, int height) { 55 | draw(new Rectangle2D.Float(x, y, width, height)); 56 | } 57 | 58 | public void draw(Shape shape) { 59 | PathIterator iterator = shape.getPathIterator(at); 60 | float[] coords = new float[6]; 61 | Point2D p0 = new Point2D.Float(); 62 | Point2d lastMoveTo = p0; 63 | while (!iterator.isDone()) { 64 | int type = iterator.currentSegments(coords); 65 | if (type == PathIterator.SEG_MOVETO) { 66 | p0 = new Point2D.Float(coords[0], coords[1]); 67 | lastMoveTo = p0; 68 | } else if (type == PathIterator.SEG_LINETO) { 69 | Point2D p1 = new Point2D.Float(coords[0], coords[1]); 70 | drawLinearBezier(p0, p1); 71 | p0 = p1; 72 | } else if (type == PathIterator.SEG_CLOSE) { 73 | drawLinearBezier(p0, lastMoveTo); 74 | } 75 | iterator.next(); 76 | } 77 | } 78 | 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /std/src/cil/li/oc/awt/GPUToolkit.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc.awt; 2 | 3 | import java.awt.Dimension; 4 | 5 | import lukyt.oc.Component; 6 | 7 | public class GPUToolkit { 8 | private String gpu; 9 | 10 | public GPUToolkit() { 11 | gpu = Component.getPrimary("gpu"); 12 | } 13 | 14 | public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException { 15 | throw new UnsupportedOperationException(); 16 | } 17 | 18 | public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException { 19 | throw new UnsupportedOperationException(); 20 | } 21 | 22 | public Clipboard getSystemSelection() { 23 | return null; 24 | } 25 | 26 | public Clipboard getSystemClipboard() { 27 | return null; 28 | } 29 | 30 | protected EventQueue getSystemEventQueueImpl() { 31 | return null; 32 | } 33 | 34 | public Dimension getScreenSize() { 35 | Object[] size = Component.invoke(gpu, "getViewport", new Object[0]); 36 | Double width = (Double) size[0]; 37 | Double height = (Double) size[1]; 38 | return new Dimension(width.intValue(), height.intValue() * 2); 39 | } 40 | 41 | public void beep() { 42 | // TODO computer.beep 43 | LuaObject._ENV.get("computer").executeChild("beep", new LuaObject[] {LuaObject.fromLong(440), LuaObject.fromDouble(0.5D)}); 44 | } 45 | } -------------------------------------------------------------------------------- /std/src/cil/li/oc/awt/SemiBrailleGPUDrawer.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc.awt; 2 | 3 | import lukyt.oc.Component; 4 | 5 | public class SemiBrailleGPUDrawer implements GPUDrawer { 6 | 7 | private String addr; 8 | private static final SEMI_BRAILLE_CHAR = ' '; // fg = top, bg = bottom 9 | 10 | public void setGPUAddress(String addr) { 11 | this.addr = addr; 12 | } 13 | 14 | public Dimension getResolution() { 15 | return new Dimension(160, 100); 16 | } 17 | 18 | public void horizontalLine(int x, int y, int width, int rgb) { 19 | for (int i = 0; i < width; i++) { 20 | set(x+i, y, rgb); 21 | } 22 | } 23 | 24 | public void verticalLine(int x, int y, int height, int rgb) { 25 | for (int i = 0; i < height; i++) { 26 | set(x, y+i, rgb); 27 | } 28 | } 29 | 30 | public void set(int x, int y, int rgb) { 31 | x++; y++; // increase to correspond to the 1-based coordinate system 32 | Object[] rets = Component.invoke(addr, "get", new Object[] {x, y}); 33 | int fg = ((Double) rets[1]).intValue(); 34 | int bg = ((Double) rets[2]).intValue(); 35 | if (y % 2 == 0) { // bottom 36 | bg = rgb; 37 | } else { // top 38 | fg = rgb; 39 | } 40 | Component.invoke(addr, "setForeground", new Object[] {fg}); 41 | Component.invoke(addr, "setBackground", new Object[] {bg}); 42 | Component.invoke(addr, "set", new Object[] {x, y, SEMI_BRAILLE_CHAR}); 43 | } 44 | 45 | public void fill(int x, int y, int width, int height, int rgb) { 46 | for (int i = 0; i < width; i++) { 47 | for (int j = 0; j < height; j++) { 48 | set(x+i, y+j, rgb); 49 | } 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /std/src/cil/li/oc/awt/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | AWT for OC, specific to Lukyt. 3 | **/ 4 | package cil.li.oc.awt; -------------------------------------------------------------------------------- /std/src/cil/li/oc/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | Package containing binding classes to OpenComputers APIs 3 | **/ 4 | package cil.li.oc; 5 | -------------------------------------------------------------------------------- /std/src/cil/li/oc/proxies/GPUProxy.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc.proxies; 2 | 3 | import cil.li.oc.*; 4 | import lukyt.*; 5 | 6 | /** 7 | Component proxy of a GPU. 8 | **/ 9 | public class GPUProxy extends ComponentProxy { 10 | private LuaObject o; 11 | 12 | public GPUProxy(LuaObject o) { 13 | this.o = o; 14 | } 15 | 16 | public void fill(int x, int y, int width, int height, char ch) { 17 | o.executeChild("fill", new LuaObject[] { 18 | LuaObject.fromLong(x), LuaObject.fromLong(y), 19 | LuaObject.fromLong(width), LuaObject.fromLong(height), 20 | LuaObject.fromString(String.valueOf(ch))}); 21 | } 22 | 23 | public void setForeground(int rgb) { 24 | o.executeChild("setForeground", new LuaObject[] {LuaObject.fromLong(rgb)}); 25 | } 26 | 27 | public void setBackground(int rgb) { 28 | o.executeChild("setBackground", new LuaObject[] {LuaObject.fromLong(rgb)}); 29 | } 30 | 31 | public String getAddress() { 32 | return o.get("address").asString(); 33 | } 34 | 35 | public String getType() { 36 | return "gpu"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /std/src/java/awt/AWTEvent.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.util.EventObject; 4 | 5 | public class AWTEvent extends EventObject { 6 | 7 | protected int id; 8 | protected boolean consumed; 9 | 10 | public static final long COMPONENT_EVENT_MASK = 1L; 11 | public static final long CONTAINER_EVENT_MASK = 2L; 12 | public static final long FOCUS_EVENT_MASK = 4L; 13 | public static final long KEY_EVENT_MASK = 8L; 14 | public static final long MOUSE_EVENT_MASK = 16L; 15 | public static final long MOUSE_MOTION_EVENT_MASK = 32L; 16 | public static final long WINDOW_EVENT_MASK = 64L; 17 | public static final long ACTION_EVENT_MASK = 128L; 18 | public static final long ADJUSTMENT_EVENT_MASK = 256L; 19 | public static final long ITEM_EVENT_MASK = 512L; 20 | public static final long TEXT_EVENT_MASK = 1024L; 21 | public static final long INPUT_METHOD_EVENT_MASK = 2048L; 22 | public static final long PAINT_EVENT_MASK = 8192L; 23 | public static final long INVOCATION_EVENT_MASK = 16384L; 24 | public static final long HIERARCHY_EVENT_MASK = 32768L; 25 | public static final long HIERARCHY_BOUNDS_EVENT_MASK = 65536L; 26 | public static final long MOUSE_WHEEL_EVENT_MASK = 131072L; 27 | public static final long WINDOW_STATE_EVENT_MASK = 262144L; 28 | public static final long WINDOW_FOCUS_EVENT_MASK = 524288L; 29 | 30 | public AWTEvent(Object source, int id) { 31 | super(source); 32 | this.id = id; 33 | } 34 | 35 | protected void consume() { 36 | consumed = true; 37 | } 38 | 39 | protected boolean isConsumed() { 40 | return consumed; 41 | } 42 | 43 | public void setSource(Object source) { 44 | this.source = source; 45 | } 46 | 47 | public int getID() { 48 | return id; 49 | } 50 | 51 | public String paramString() { 52 | return ""; 53 | } 54 | 55 | public String toString() { 56 | return "java.awt.AWTEvent[source=" + source + ",id=" + id + ",consumed=" + consumed + "]"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /std/src/java/awt/AWTEventMulticaster.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.event.*; 4 | 5 | public class AWTEventMulticaster implements ComponentListener { 6 | protected final EventListener a; 7 | protected final EventListener b; 8 | 9 | protected AWTEventMulticaster(EventListener a, EventListener b) { 10 | this.a = a; 11 | this.b = b; 12 | } 13 | 14 | protected EventListener remove(EventListener old) { 15 | 16 | return this; 17 | } 18 | 19 | public static ComponentListener add(ComponentListener a, ComponentListener b) { 20 | return new AWTEventMulticaster(a, b); 21 | } 22 | 23 | public void componentHidden(ComponentEvent e) { 24 | if (a != null) { 25 | a.componentHidden(e); 26 | } 27 | b.componentHidden(e); 28 | } 29 | 30 | public void componentMoved(ComponentEvent e) { 31 | if (a != null) { 32 | a.componentMoved(e); 33 | } 34 | b.componentMoved(e); 35 | } 36 | 37 | public void componentResized(ComponentEvent e) { 38 | if (a != null) { 39 | a.componentResized(e); 40 | } 41 | b.componentResized(e); 42 | } 43 | 44 | public void componentShown(ComponentEvent e) { 45 | if (a != null) { 46 | a.componentShown(e); 47 | } 48 | b.componentShown(e); 49 | } 50 | } -------------------------------------------------------------------------------- /std/src/java/awt/Color.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public class Color { 4 | 5 | public int[] components; 6 | 7 | public static final Color BLACK = new Color(0, 0, 0); 8 | public static final Color WHITE = new Color(255, 255, 255); 9 | 10 | public Color(int r, int g, int b) { 11 | components = new int[] {r, g, b}; 12 | } 13 | 14 | public Color(int r, int g, int b, int a) { 15 | components = new int[] {r, g, b, a}; 16 | } 17 | 18 | public Color(int rgb) { 19 | this(rgb, false); 20 | } 21 | 22 | public Color(int argb, boolean hasAlpha) { 23 | components = new int[] { 24 | argb & 0x00FF0000, // red 25 | argb & 0x0000FF00, // green 26 | argb & 0x000000FF, // blue 27 | hasAlpha ? argb & 0xFF000000 : 255 28 | }; 29 | } 30 | 31 | public int getRed() { 32 | return components[0]; 33 | } 34 | 35 | public int getGreen() { 36 | return components[1]; 37 | } 38 | 39 | public int getBlue() { 40 | return components[2]; 41 | } 42 | 43 | public int getAlpha() { 44 | return components[3]; 45 | } 46 | 47 | public int getRGB() { 48 | return (components[0] << 16) | 49 | (components[1] << 8) | 50 | components[2]; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /std/src/java/awt/Component.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.event.*; 4 | import java.awt.peer.ComponentPeer; 5 | 6 | public class Component { 7 | 8 | protected Object treeLock = new Object(); 9 | Container parent; 10 | protected String name; 11 | protected ComponentPeer peer; 12 | protected boolean valid = true; 13 | protected boolean visible = true; 14 | 15 | private ComponentListener componentListener = null; 16 | private KeyListener keyListener = null; 17 | 18 | protected Component() {} 19 | 20 | public void addComponentListener(ComponentListener l) { 21 | componentListener = AWTEventMulticaster.add(componentListener, l); 22 | } 23 | 24 | public void addKeyListener(KeyListener l) { 25 | 26 | } 27 | 28 | public boolean isVisible() { 29 | return visible; 30 | } 31 | 32 | public void setVisible(boolean visible) { 33 | this.visible = visible; 34 | } 35 | 36 | public boolean isDisplayable() { 37 | return peer != null; 38 | } 39 | 40 | protected void processComponentEvent(ComponentEvent e) { 41 | if (componentListener != null) { 42 | int id = e.getId(); 43 | if (id == ComponentEvent.COMPONENT_SHOWN) { 44 | componentListener.componentShown(e); 45 | } else if (id == ComponentEvent.COMPONENT_HIDDEN) { 46 | componentListener.componentHidden(e); 47 | } else if (id == ComponentEvent.COMPONENT_RESIZED) { 48 | componentListener.componentResized(e); 49 | } else if (id == ComponentEvent.COMPONENT_MOVED) { 50 | componentListener.componentMoved(e); 51 | } 52 | } 53 | } 54 | 55 | protected void processEvent(AWTEvent e) { 56 | if (e instanceof ComponentEvent) { 57 | processComponentEvent((ComponentEvent) e); 58 | } 59 | } 60 | 61 | public final void dispatchEvent(AWTEvent e) { 62 | // TODO check if enabled before calling processEvent 63 | processEvent(e); 64 | } 65 | 66 | public Container getParent() { 67 | return parent; 68 | } 69 | 70 | public final Object getTreeLock() { 71 | return treeLock; 72 | } 73 | 74 | public String getName() { 75 | return name; 76 | } 77 | 78 | @Deprecated 79 | public ComponentPeer getPeer() { 80 | return peer; 81 | } 82 | 83 | public void setName(String name) { 84 | this.name = name; 85 | } 86 | 87 | public void invalidate() { 88 | valid = false; 89 | if (parent != null) { 90 | parent.invalidate(); 91 | } 92 | } 93 | 94 | public void validate() { 95 | valid = true; 96 | } 97 | 98 | public void addNotify() { 99 | throw new UnsupportedOperationException(); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /std/src/java/awt/Container.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.util.*; 4 | import java.awt.peer.ContainerPeer; 5 | 6 | public class Container { 7 | 8 | protected List childs = new ArrayList(); 9 | protected LayoutManager lm; 10 | 11 | public Container() {} 12 | 13 | public int getComponentCount() { 14 | return childs.size(); 15 | } 16 | 17 | public void addNotify() { 18 | if (peer == null) { 19 | peer = new ContainerPeer(); 20 | } 21 | for (Component child : childs) { 22 | if (!child.isDisplayable()) { 23 | child.addNotify(); 24 | } 25 | } 26 | } 27 | 28 | public Component getComponent(int n) { 29 | if (n < 0 || n > childs.size()) { 30 | throw new ArrayIndexOutOfBoundsException(); 31 | } 32 | return childs.get(n); 33 | } 34 | 35 | public Component[] getComponents() { 36 | return childs.toArray(new Component[childs.size()]); 37 | } 38 | 39 | public Component add(Component comp) { 40 | addImpl(comp, null, -1); 41 | } 42 | 43 | public Component add(Component comp, int index) { 44 | addImpl(comp, null, index); 45 | } 46 | 47 | public Component add(String name, Component comp) { 48 | addImpl(comp, name, -1); 49 | } 50 | 51 | public Component add(Component comp, Object constraints) { 52 | addImpl(comp, constraints, -1); 53 | } 54 | 55 | public Component add(Component comp, Object constraints, int index) { 56 | addImpl(comp, constraints, index); 57 | } 58 | 59 | public void remove(int index) { 60 | childs.remove(index); 61 | } 62 | 63 | public void remove(Component comp) { 64 | childs.remove(comp); 65 | } 66 | 67 | public void removeAll() { 68 | for (Component comp : childs) { 69 | remove(comp); 70 | } 71 | } 72 | 73 | public LayoutManager getLayout() { 74 | return lm; 75 | } 76 | 77 | public void setLayout(LayoutManager lm) { 78 | this.lm = lm; 79 | } 80 | 81 | public void doLayout() { 82 | if (lm != null) { 83 | lm.layoutContainer(this); 84 | } 85 | } 86 | 87 | public void validate() { 88 | synchronized (getTreeLock()) { 89 | if (!valid) { 90 | doLayout(); 91 | validateTree(); 92 | valid = true; 93 | } 94 | } 95 | } 96 | 97 | protected void validateTree() { 98 | for (Component comp : childs) { 99 | comp.validate(); 100 | } 101 | } 102 | 103 | protected void addImpl(Component comp, Object constraints, int index) { 104 | synchronized (getTreeLock()) { 105 | if (comp.getParent() != null) { 106 | comp.getParent().remove(comp); 107 | } 108 | 109 | if (index == -1) { 110 | childs.add(comp); 111 | } else { 112 | childs.add(index, comp); 113 | } 114 | 115 | if (peer != null && visible) { 116 | comp.addNotify(); 117 | } 118 | if (comp.peer != null) { 119 | comp.peer.setParent((ContainerPeer) peer); 120 | } 121 | 122 | comp.invalidate(); 123 | comp.parent = this; 124 | } 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /std/src/java/awt/Dimension.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.geom.Dimension2D; 4 | 5 | public class Dimension extends Dimension2D { 6 | public int width; 7 | public int height; 8 | 9 | public Dimension() {} 10 | 11 | public Dimension(Dimension dim) { 12 | width = dim.width; 13 | height = dim.height; 14 | } 15 | 16 | public Dimension(int width, int height) { 17 | this.width = width; 18 | this.height = height; 19 | } 20 | 21 | public boolean equals(Object obj) { 22 | if (obj instanceof Dimension) { 23 | Dimension dim = (Dimension) obj; 24 | return dim.width == width && dim.height == height; 25 | } 26 | return false; 27 | } 28 | 29 | public double getWidth() { 30 | return width; 31 | } 32 | 33 | public double getHeight() { 34 | return height; 35 | } 36 | 37 | public Dimension getSize() { 38 | return this; 39 | } 40 | 41 | public int hashCode() { 42 | return width * 75632 + height 43 | } 44 | 45 | public void setSize(Dimension dim) { 46 | width = dim.width; 47 | height = dim.height; 48 | } 49 | 50 | public void setSize(double width, double height) { 51 | setSize((int) width, (int) height); 52 | } 53 | 54 | public void setSize(int width, int height) { 55 | this.width = width; 56 | this.height = height; 57 | } 58 | 59 | public String toString() { 60 | return "java.awt.Dimension[width=" + width + ",height=" + height + "]"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /std/src/java/awt/EventObject.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public class EventObject { 4 | protected transient Object source; 5 | 6 | public EventObject(Object source) { 7 | this.source = source; 8 | } 9 | 10 | public Object getSource() { 11 | return source; 12 | } 13 | 14 | public String toString() { 15 | return "java.awt.EventObject[source=" + source + "]"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /std/src/java/awt/EventQueue.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public class EventQueue { 4 | 5 | private Deque events = new ArrayDeque(); 6 | private long initTime; 7 | 8 | public EventQueue() { 9 | initTime = System.currentTimeMillis(); 10 | } 11 | 12 | public void postEvent(AWTEvent evt) { 13 | if (evt.getSource() instanceof Component) { 14 | // TODO: check for Component.coalesceEvents condition 15 | } 16 | events.add(evt); 17 | } 18 | 19 | public AWTEvent getNextEvent() { 20 | return events.removeFirst(); 21 | } 22 | 23 | public AWTEvent peekEvent() { 24 | return events.peekFirst(); 25 | } 26 | 27 | public static long getMostRecentEventTime() { 28 | // TODO 29 | return initTime; 30 | } 31 | 32 | public static boolean isDispatchThread() { 33 | // TODO 34 | } 35 | 36 | public static void invokeLater(Runnable runnable) { 37 | // TODO 38 | } 39 | 40 | public static void invokeAndWait(Runnable runnable) { 41 | // TODO 42 | } 43 | 44 | protected void dispatchEvent(AWTEvent event) { 45 | if (event == null) { 46 | throw new NullPointerException(); 47 | } 48 | // TODO: Handle ActiveEvent and MenuComponent 49 | if (event.getSource() instanceof Component) { 50 | ((Component) event.getSource()).dispatchEvent(event); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /std/src/java/awt/Frame.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.peer.FramePeer; 4 | 5 | public class Window extends Frame { 6 | 7 | private Window owner; 8 | 9 | public Window(Window owner) { 10 | this.owner = owner; 11 | addNotify(); 12 | } 13 | 14 | public void addNotify() { 15 | peer = new WindowPeer(); 16 | for (Component child : childs) { 17 | if (!child.isDisplayable()) { 18 | child.addNotify(); 19 | } 20 | } 21 | } 22 | 23 | public void setTitle(String title) { 24 | ((FramePeer) peer).setTitle(title); 25 | } 26 | 27 | public void setResizable(boolean resizable) { 28 | ((FramePeer) peer).setResizable(resizable); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /std/src/java/awt/GraphicsConfiguration.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public abstract class GraphicsConfiguration { 4 | 5 | public abstract Rectangle getBounds(); 6 | public abstract boolean isTranslucencyCapable(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /std/src/java/awt/GraphicsEnvironment.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public abstract class GraphicsEnvironment { 4 | 5 | public static boolean isHeadless() { 6 | return false; 7 | } 8 | 9 | public boolean isHeadlessInstance() { 10 | return true; 11 | } 12 | 13 | public abstract GraphicsDevice[] getScreenDevices() throws HeadlessException; 14 | public abstract GraphicsDevice getDefaultScreenDevice() throws HeadlessException; 15 | 16 | public Point getCenterPoint() throws HeadlessException { 17 | if (isHeadless()) { 18 | throw new HeadlessException(); 19 | } 20 | return new Point(500, 500); // TODO 21 | } 22 | 23 | public Rectangle getMaximumWindowBounds() throws HeadlessException { 24 | if (isHeadless()) { 25 | throw new HeadlessException(); 26 | } 27 | return new Rectangle(1920, 1080); // TODO 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /std/src/java/awt/HeadlessException.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public class HeadlessException extends RuntimeException { 4 | 5 | public HeadlessException() { 6 | super(); 7 | } 8 | 9 | public HeadlessException(String s) { 10 | super(s); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /std/src/java/awt/Point.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.geom.Point2D; 4 | 5 | public class Point extends Point2D { 6 | public int x, y; 7 | 8 | public Point() {} 9 | 10 | public Point(int x, int y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | 15 | public Point(Point pt) { 16 | x = pt.x; 17 | y = pt.y; 18 | } 19 | 20 | public Point getLocation() { 21 | return this; 22 | } 23 | 24 | public double getX() { 25 | return (double) x; 26 | } 27 | 28 | public double getY() { 29 | return (double) y; 30 | } 31 | 32 | public void move(int x, int y) { 33 | this.x = x; 34 | this.y = y; 35 | } 36 | 37 | public void setLocation(double x, double y) { 38 | this.x = (int) x; 39 | this.y = (int) y; 40 | } 41 | 42 | public void setLocation(int x, int y) { 43 | this.x = x; 44 | this.y = y; 45 | } 46 | 47 | public void setLocation(Point pt) { 48 | x = pt.x; 49 | y = pt.y; 50 | } 51 | 52 | public void translate(int dx, int dy) { 53 | x += dx; 54 | y += dy; 55 | } 56 | 57 | public String toString() { 58 | return "java.awt.Point[x=" + x, + ",y" + y + "]"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /std/src/java/awt/Shape.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.geom.*; 4 | 5 | public interface Shape { 6 | 7 | public boolean contains(double x, double y); 8 | public boolean contains(double x, double y, double w, double h); 9 | public boolean contains(Point2D pt); 10 | public boolean contains(Rectangle2D r); 11 | 12 | public Rectangle getBounds(); 13 | public Rectangle2D getBounds2D(); 14 | 15 | public PathIterator getPathIterator(AffineTransform at); 16 | public PathIterator getPathIterator(AffineTransform at, double flatness); 17 | 18 | public boolean intersects(double x, double y, double w, double h); 19 | public boolean intersects(Rectangle2D r); 20 | } 21 | -------------------------------------------------------------------------------- /std/src/java/awt/Toolkit.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import cil.li.oc.awt.GPUToolkit; 4 | import lukyt.awt.iup.IUPToolkit; 5 | 6 | import java.awt.peer.*; 7 | 8 | public class Toolkit { 9 | 10 | protected static Toolkit defaultToolkit; 11 | 12 | public abstract Dimension getScreenSize(); 13 | public abstract int getScreenResolution(); 14 | public abstract void beep(); 15 | public abstract Clipboard getSystemSelection(); 16 | public abstract Clipboard getSystemClipboard(); 17 | public abstract boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException; 18 | public abstract void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException; 19 | 20 | public abstract ContainerPeer createContainer(Container target); 21 | 22 | public final EventQueue getSystemEventQueue() { 23 | return getSystemEventQueueImpl(); 24 | } 25 | 26 | public boolean areExtraMouseButtonsEnabled() { 27 | return false; 28 | } 29 | 30 | protected static Container getNativeContainer(Component comp) { 31 | return comp.getParent(); 32 | } 33 | 34 | protected abstract EventQueue getSystemEventQueueImpl(); 35 | 36 | public static Toolkit getDefaultToolkit() { 37 | if (Boolean.getBoolean("java.awt.headless")) { 38 | throw new HeadlessException(); // TODO: use an headless toolkit 39 | } 40 | if (defaultToolkit == null) { 41 | if (System.getProperty("os.name").contains("OpenOS")) { 42 | defaultToolkit = new GPUToolkit(); 43 | } else { 44 | if (System.getProperty("os.name").contains("Mac OS X")) { 45 | throw new HeadlessException("Lukyt doesn't support any Mac OS X render backend"); // TODO: use an headless toolkit 46 | } 47 | defaultToolkit = new IUPToolkit(); 48 | } 49 | } 50 | return new GPUToolkit(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /std/src/java/awt/Window.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | import java.awt.peer.WindowPeer; 4 | 5 | public class Window extends Container { 6 | 7 | private Window owner; 8 | 9 | public Window(Window owner) { 10 | this.owner = owner; 11 | addNotify(); 12 | } 13 | 14 | public void addNotify() { 15 | peer = new WindowPeer(); 16 | for (Component child : childs) { 17 | if (!child.isDisplayable()) { 18 | child.addNotify(); 19 | } 20 | } 21 | } 22 | 23 | public void setSize(int width, int height) { 24 | ((WindowPeer) peer).setSize(width, height); 25 | } 26 | 27 | public void setLocation(int x, int y) { 28 | ((WindowPeer) peer).setLocation(x, y); 29 | } 30 | 31 | public void setLocation(Point p) { 32 | setLocation(p.getX(), p.getY()); 33 | } 34 | 35 | public void setVisible(boolean b) { 36 | ((WindowPeer) peer).setVisible(b); 37 | } 38 | 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /std/src/java/awt/event/AWTEventListener.java: -------------------------------------------------------------------------------- 1 | package java.awt.event; 2 | 3 | import java.awt.AWTEvent; 4 | 5 | public interface AWTEventListener { 6 | 7 | public void eventDispatched(AWTEvent event); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /std/src/java/awt/event/ComponentEvent.java: -------------------------------------------------------------------------------- 1 | package java.awt.event; 2 | 3 | import java.awt.AWTEvent; 4 | 5 | public class ComponentEvent extends AWTEvent { 6 | 7 | public static final int COMPONENT_FIRST = 100; 8 | public static final int COMPONENT_LAST = 103; 9 | 10 | public static final int COMPONENT_MOVED = 100; 11 | public static final int COMPONENT_RESIZED = 101; 12 | public static final int COMPONENT_SHOWN = 102; 13 | public static final int COMPONENT_HIDDEN = 103; 14 | 15 | public ComponentEvent(Component c, int id) { 16 | super(c, id); 17 | } 18 | 19 | public Component getComponent() { 20 | return (Component) source; 21 | } 22 | 23 | public String paramString() { 24 | return source.toString(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /std/src/java/awt/event/ComponentListener.java: -------------------------------------------------------------------------------- 1 | package java.awt.event; 2 | 3 | import java.util.EventListener; 4 | 5 | public interface ComponentListener extends EventListener { 6 | public void componentHidden(ComponentEvent e); 7 | public void componentMoved(ComponentEvent e); 8 | public void componentResized(ComponentEvent e); 9 | public void componentShown(ComponentEvent e); 10 | } 11 | -------------------------------------------------------------------------------- /std/src/java/awt/event/InputEvent.java: -------------------------------------------------------------------------------- 1 | package java.awt.event; 2 | 3 | public class InputEvent extends ComponentEvent { 4 | 5 | public static final int SHIFT_MASK = 1; 6 | public static final int CTRL_MASK = 2; 7 | public static final int BUTTON3_MASK = 4; 8 | public static final int BUTTON2_MASK = 8; 9 | public static final int BUTTON1_MASK = 16; 10 | public static final int ALT_GRAPH_MASK = 32; 11 | public static final int SHIFT_DOWN_MASK = 64; 12 | public static final int CTRL_DOWN_MASK = 128; 13 | public static final int META_DOWN_MASK = 256; 14 | public static final int ALT_DOWN_MASK = 512; 15 | public static final int BUTTON1_DOWN_MASK = 1024; 16 | public static final int BUTTON2_DOWN_MASK = 2048; 17 | public static final int BUTTON3_DOWN_MASK = 4096; 18 | public static final int ALT_GRAPH_DOWN_MASK = 8192; 19 | 20 | public InputEvent(Component c, int id) { 21 | super(c, id); 22 | } 23 | 24 | public Component getComponent() { 25 | return (Component) source; 26 | } 27 | 28 | public String paramString() { 29 | return source.toString(); 30 | } 31 | 32 | public int isShiftDown() { 33 | return (getModifiers() & SHIFT_DOWN_MASK) == SHIFT_DOWN_MASK; 34 | } 35 | 36 | public int isAltDown() { 37 | return (getModifiers() & ALT_DOWN_MASK) == ALT_DOWN_MASK; 38 | } 39 | 40 | public int isAltGraphDown() { 41 | return (getModifiers() & ALT_GRAPH_DOWN_MASK) == ALT_GRAPH_DOWN_MASK; 42 | } 43 | 44 | public int isControlDown() { 45 | return (getModifiers() & CTRL_DOWN_MASK) == CTRL_DOWN_MASK; 46 | } 47 | 48 | public int isMetaDown() { 49 | return (getModifiers() & META_DOWN_MASK) == META_DOWN_MASK; 50 | } 51 | 52 | public int getModifiers() { 53 | return 0; 54 | } 55 | 56 | public long getWhen() { 57 | return 0; 58 | } 59 | 60 | public int getModifiersEx() { 61 | return 0; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /std/src/java/awt/event/KeyEvent.java: -------------------------------------------------------------------------------- 1 | package java.awt.event; 2 | 3 | import java.awt.AWTEvent; 4 | 5 | public class KeyEvent extends InputEvent { 6 | 7 | protected long when; 8 | protected int modifiers; 9 | protected int keyCode; 10 | protected char keyChar; 11 | protected int keyLocation; 12 | 13 | public static char CHAR_UNDEFINED = -1; 14 | 15 | public KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keychar, int keyLocation) { 16 | super(source, id); 17 | this.when = when; 18 | this.modifiers = modifiers; 19 | this.keyCode = keyCode; 20 | this.keyChar = keyChar; 21 | this.keyLocation = keyLocation; 22 | } 23 | 24 | public KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keyChar) { 25 | this(source, id, when, modifiers, keyCode, keyChar, -1); 26 | } 27 | 28 | public Component getComponent() { 29 | return (Component) source; 30 | } 31 | 32 | public String paramString() { 33 | return source.toString(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /std/src/java/awt/event/KeyListener.java: -------------------------------------------------------------------------------- 1 | package java.awt.event; 2 | 3 | import java.util.EventListener; 4 | 5 | public interface KeyListener extends EventListener { 6 | public void keyPressed(KeyEvent e); 7 | public void keyReleased(KeyEvent e); 8 | public void keyTyped(KeyEvent e); 9 | } 10 | -------------------------------------------------------------------------------- /std/src/java/awt/geom/Dimension2D.java: -------------------------------------------------------------------------------- 1 | package java.awt.geom; 2 | 3 | public abstract class Dimension2D { 4 | 5 | protected Dimension2D() {} 6 | 7 | public abstract double getWidth(); 8 | public abstract double getHeight(); 9 | public abstract void setSize(double width, double height); 10 | 11 | public void setSize(Dimension2D dim) { 12 | setSize(dim.getWidth(), dim.getHeight()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /std/src/java/awt/geom/PathIterator.java: -------------------------------------------------------------------------------- 1 | package java.awt.geom; 2 | 3 | public interface PathIterator { 4 | 5 | public static final int SEG_MOVETO = 0; 6 | public static final int SEG_LINETO = 1; 7 | public static final int SEG_QUADTO = 2; 8 | public static final int SEG_CUBICTO = 3; 9 | public static final int SEG_CLOSE = 4; 10 | 11 | public static final int WIND_EVEN_ODD = 0; 12 | public static final int WIND_NON_ZERO = 1; 13 | 14 | public int currentSegment(double[] coords); 15 | public int currentSegment(float[] coords); 16 | public int getWindingRule(); 17 | boolean isDone(); 18 | void next(); 19 | } 20 | -------------------------------------------------------------------------------- /std/src/java/awt/geom/Point2D.java: -------------------------------------------------------------------------------- 1 | package java.awt.geom; 2 | 3 | public abstract class Point2D { 4 | 5 | public static class Float extends Point2D { 6 | public float x, y; 7 | 8 | public Float() {} 9 | 10 | public Float(float x, float y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | 15 | public double getX() { 16 | return (double) x; 17 | } 18 | 19 | public double getY() { 20 | return (double) y; 21 | } 22 | 23 | public void setLocation(double x, double y) { 24 | this.x = (float) x; 25 | this.y = (float) y; 26 | } 27 | 28 | public void setLocation(float x, float y) { 29 | this.x = x; 30 | this.y = y; 31 | } 32 | 33 | public String toString() { 34 | return "java.awt.geom.Point2D.Float[x=" + x + ",y=" + y + "]"; 35 | } 36 | } 37 | 38 | public static class Double extends Point2D { 39 | public double x, y; 40 | 41 | public Double() {} 42 | 43 | public Double(double x, double y) { 44 | this.x = x; 45 | this.y = y; 46 | } 47 | 48 | public double getX() { 49 | return x; 50 | } 51 | 52 | public double getY() { 53 | return y; 54 | } 55 | 56 | public void setLocation(double x, double y) { 57 | this.x = x; 58 | this.y = y; 59 | } 60 | 61 | public String toString() { 62 | return "java.awt.geom.Point2D.Double[x=" + x + ",y=" + y + "]"; 63 | } 64 | } 65 | 66 | protected Point2D() {} 67 | 68 | public abstract double getX(); 69 | public abstract double getY(); 70 | public abstract void setLocation(double x, double y); 71 | 72 | public double distance(double px, double py) { 73 | return distance(getX(), getY(), px, py); 74 | } 75 | 76 | public double distance(Point2D pt) { 77 | return distance(getX(), getY(), pt.getX(), pt.getY()); 78 | } 79 | 80 | public double distanceSq(double px, double py) { 81 | return distanceSq(getX(), getY(), px, py); 82 | } 83 | 84 | public double distanceSq(Point2D pt) { 85 | return distanceSq(getX(), getY(), pt.getX(), pt.getY()); 86 | } 87 | 88 | public static double distance(double x1, double y1, double x2, double y2) { 89 | double v = x1+y1 - x2+y2; 90 | if (v < 0) v = -v; 91 | return v; 92 | } 93 | 94 | public static double distanceSq(double x1, double y1, double x2, double y2) { 95 | double v = distance(x1, y1, x2, y2); 96 | return v*v; 97 | } 98 | 99 | public boolean equals(Object obj) { 100 | if (obj instanceof Point2D) { 101 | return getX() == obj.getX() && getY() == obj.getY(); 102 | } 103 | return false; 104 | } 105 | 106 | public void setLocation(Point2D pt) { 107 | setLocation(pt.getX(), pt.getY()); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /std/src/java/awt/geom/Rectangle2D.java: -------------------------------------------------------------------------------- 1 | package java.awt.geom; 2 | 3 | public abstract class Rectangle2D extends RectangularShape { 4 | public static class Float extends Rectangle2D { 5 | 6 | public float x, y, width, height; 7 | 8 | public Float() {} 9 | 10 | public Float(float x, float y, float width, float height) { 11 | setRect(x, y, width, height); 12 | } 13 | 14 | public Rectangle2D getBounds2D() { 15 | return new Rectangle2D.Float(x, y, width, height); 16 | } 17 | 18 | public double getX() { 19 | return (double) x; 20 | } 21 | 22 | public double getY() { 23 | return (double) y; 24 | } 25 | 26 | public double getWidth() { 27 | return (double) width; 28 | } 29 | 30 | public double getHeight() { 31 | return (double) height; 32 | } 33 | 34 | public boolean isEmpty() { 35 | return width == 0 || height == 0; 36 | } 37 | 38 | public void setRect(Rectangle2D r) { 39 | setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); 40 | } 41 | 42 | public void setRect(double x, double y, double width, double height) { 43 | setRect((float) x, (float) y, (float) width, (float) height); 44 | } 45 | 46 | public void setRect(float x, float y, float width, float height) { 47 | this.x = x; 48 | this.y = y; 49 | this.width = width; 50 | this.height = height; 51 | } 52 | 53 | public String toString() { 54 | return "java.awt.geom.Rectangle2D.Float[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]"; 55 | } 56 | } 57 | 58 | public static class Double extends Rectangle2D { 59 | 60 | public double x, y, width, height; 61 | 62 | public Double() {} 63 | 64 | public Double(double x, double y, double width, double height) { 65 | setRect(x, y, width, height); 66 | } 67 | 68 | public Rectangle2D getBounds2D() { 69 | return new Rectangle2D.Double(x, y, width, height); 70 | } 71 | 72 | public double getX() { 73 | return (double) x; 74 | } 75 | 76 | public double getY() { 77 | return (double) y; 78 | } 79 | 80 | public double getWidth() { 81 | return (double) width; 82 | } 83 | 84 | public double getHeight() { 85 | return (double) height; 86 | } 87 | 88 | public boolean isEmpty() { 89 | return width == 0 || height == 0; 90 | } 91 | 92 | public void setRect(Rectangle2D r) { 93 | setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); 94 | } 95 | 96 | public void setRect(double x, double y, double width, double height) { 97 | this.x = x; 98 | this.y = y; 99 | this.width = width; 100 | this.height = height; 101 | } 102 | 103 | public String toString() { 104 | return "java.awt.geom.Rectangle2D.Double[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]"; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /std/src/java/awt/geom/RectangularShape.java: -------------------------------------------------------------------------------- 1 | package java.awt.geom; 2 | 3 | public abstract class RectangularShape implements Shape { 4 | protected RectangularShape() {} 5 | 6 | public abstract double getX(); 7 | public abstract double getY(); 8 | public abstract double getWidth(); 9 | public abstract double getHeight(); 10 | public abstract boolean isEmpty(); 11 | public abstract void setFrame(double x, double y, double w, double h); 12 | 13 | public double getMinX() { 14 | return getX(); 15 | } 16 | 17 | public double getMinY() { 18 | return getY(); 19 | } 20 | 21 | public double getMaxX() { 22 | return getX() + getWidth(); 23 | } 24 | 25 | public double getMaxY() { 26 | return getX() + getHeight(); 27 | } 28 | 29 | public double getCenterX() { 30 | return getX() + getWidth() / 2; 31 | } 32 | 33 | public double getCenterY() { 34 | return getY() + getHeight() / 2; 35 | } 36 | 37 | public Rectangle2D getFrame() { 38 | return new Rectangle2D(getX(), getY(), getWidth(), getHeight()); 39 | } 40 | 41 | public void setFrame(Point2D loc, Dimension2D size) { 42 | setFrame(loc.getX(), loc.getY(), size.getWidth(), size.getHeight()); 43 | } 44 | 45 | public void setFrame(Rectangle2D r) { 46 | setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight()); 47 | } 48 | 49 | public void setFrameFromDiagonal(double x1, double y1, double x2, double y2) { 50 | throw new UnsupportedOperationException("TODO"); 51 | } 52 | 53 | public void setFrameFromDiagonal(Point2D p1, Point2D p2) { 54 | setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY()); 55 | } 56 | 57 | public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) { 58 | throw new UnsupportedOperationException("TODO"); 59 | } 60 | 61 | public void setFrameFromCenter(Point2D center, Point2D corner) { 62 | setFrameFromCenter(center.getX(), center.getY(), corner.getX(), corner.getY()); 63 | } 64 | 65 | public boolean contains(Point2D pt) { 66 | return pt.getX() > getX() && pt.getY() > getY() && pt.getX() < getX() + getWidth() && pt.getY() < getY() + getHeight(); 67 | } 68 | 69 | public boolean intersects(Rectangle2D r) { 70 | throw new UnsupportedOperationException("TODO"); 71 | } 72 | 73 | public boolean contains(Rectangle2D r) { 74 | throw new UnsupportedOperationException("TODO"); 75 | } 76 | 77 | public Rectangle getBounds() { 78 | return new Rectangle(getX(), getY(), getWidth(), getHeight()); 79 | } 80 | 81 | public PathIterator getPathIterator(AffineTransform at, double flatness) { 82 | throw new UnsupportedOperationException("TODO"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /std/src/java/awt/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | Reimplementation of Java AWT (because OpenJDK StdLib is GPLv2 only and thus is not compatible with LGPLv3) 3 | for OpenComputers 4 | **/ 5 | package lukyt.oc; 6 | -------------------------------------------------------------------------------- /std/src/java/awt/peer/ComponentPeer.java: -------------------------------------------------------------------------------- 1 | package java.awt.peer; 2 | 3 | import java.awt.*; 4 | 5 | public interface ComponentPeer { 6 | 7 | public boolean setVisible(boolean visible); 8 | public boolean setEnabled(boolean visible); 9 | public void setBounds(int x, int y, int w, int h); 10 | public void setLocation(int x, int y); 11 | public void setSize(int w, int h); 12 | public void dispatchEvent(AWTEvent e); 13 | public Dimension getPreferredSize(); 14 | public Dimension getMinimumSize(); 15 | public Point getLocation(); 16 | public void dispose(); 17 | 18 | /** 19 | A purely heavyweight component can return null 20 | **/ 21 | public Graphics getGraphics(); 22 | 23 | public void setParent(ContainerPeer peer); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /std/src/java/awt/peer/ContainerPeer.java: -------------------------------------------------------------------------------- 1 | package java.awt.peer; 2 | 3 | public interface ContainerPeer extends ComponentPeer { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/awt/peer/FramePeer.java: -------------------------------------------------------------------------------- 1 | package java.awt; 2 | 3 | public interface FramePeer extends WindowPeer { 4 | public void setTitle(String title); 5 | public void setResizable(boolean resizable); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/io/BufferedReader.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class BufferedReader extends Reader { 4 | 5 | private Reader reader; 6 | 7 | public BufferedReader(Reader reader) { 8 | this.reader = reader; 9 | } 10 | 11 | public int read() throws IOException { 12 | return reader.read(); 13 | } 14 | 15 | public int read(char[] cbuf) throws IOException { 16 | return reader.read(cbuf); 17 | } 18 | 19 | public int read(char[] cbuf, int off, int len) throws IOException { 20 | return reader.read(cbuf, off, len); 21 | } 22 | 23 | public String readLine() { 24 | System.out.println("TODO READLINE"); 25 | return null; 26 | } 27 | 28 | public void close() throws IOException { 29 | reader.close(); 30 | } 31 | 32 | public long skip(long n) throws IOException { 33 | return reader.skip(n); 34 | } 35 | 36 | public boolean ready() throws IOException { 37 | return reader.ready(); 38 | } 39 | 40 | public boolean markSupported() { 41 | return reader.markSupported(); 42 | } 43 | 44 | public void mark(int readAheadLimit) throws IOException { 45 | reader.mark(readAheadLimit); 46 | } 47 | 48 | public void reset() throws IOException { 49 | reader.reset(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /std/src/java/io/Closeable.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public interface Closeable extends AutoCloseable { 4 | public void close() throws IOException; 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/io/ConsoleInputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class ConsoleInputStream extends InputStream { 4 | public native int read(); 5 | } -------------------------------------------------------------------------------- /std/src/java/io/File.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class File { 4 | public static char separatorChar = '/'; 5 | public static final String separator = System.getProperty("file.separator"); 6 | public static final char pathSeparatorChar = ':'; 7 | public static final String pathSeparator = System.getProperty("path.separator"); 8 | 9 | private String path; 10 | 11 | public File(String pathname) { 12 | path = pathname; 13 | } 14 | 15 | public File(String parent, String child) { 16 | if (parent == null || parent.isEmpty()) { 17 | parent = System.getProperty("user.dir"); 18 | } 19 | } 20 | 21 | public File(File parent, String child) { 22 | this(parent.getPath(), child); 23 | } 24 | 25 | public String getPath() { 26 | return path; 27 | } 28 | 29 | public String getName() { 30 | return ""; // TODO 31 | } 32 | 33 | public String getParent() { 34 | return ""; // TODO 35 | } 36 | 37 | public File getParentFile() { 38 | return new File(getParent()); 39 | } 40 | 41 | public String getAbsolutePath() { 42 | return path; 43 | } 44 | 45 | public File getAbsoluteFile() { 46 | return new File(getAbsolutePath()); 47 | } 48 | 49 | public String getCanonicalPath() { 50 | String path = getAbsolutePath(); 51 | // TODO 52 | return path; 53 | } 54 | 55 | public File getCanonicalFile() { 56 | return new File(getCanonicalPath()); 57 | } 58 | 59 | public native boolean canRead(); // would require LFS 60 | public native boolean canWrite(); // would require LFS 61 | public native boolean exists(); // would require LFS (or else it would return false is the file is a directory) 62 | public native boolean isDirectory(); // would require LFS 63 | public native long lastModified(); // would require LFS 64 | public native String[] list(); // again.. this would require LFS 65 | public native boolean mkdir(); // would require LFS 66 | public native boolean mkdirs(); // would require LFS 67 | 68 | public boolean delete() { // would require LFS 69 | return false; 70 | } 71 | 72 | public boolean renameTo(File dest) { 73 | // TODO: copy file over 74 | return false; 75 | } 76 | 77 | public File[] listFiles() { 78 | String[] list = list(); 79 | File[] files = new File[list.length]; 80 | for (int i = 0; i < files.length; i++) { 81 | files[i] = new File(this, list[i]); 82 | } 83 | return files; 84 | } 85 | 86 | public void deleteOnExit() {} 87 | 88 | public native boolean createNewFile(); 89 | 90 | public boolean isHidden() { 91 | if (System.getProperty("os.name").equals("Unix")) { 92 | return getName().charAt(0) == '.'; 93 | } else { 94 | return false; // TODO 95 | } 96 | } 97 | 98 | public boolean isFile() { 99 | return !isDirectory(); // todo check for system-dependent criterias: UNIX sockets, symbolic links, etc. 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /std/src/java/io/FileDescriptor.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class FileDescriptor { 4 | private long handle; 5 | 6 | private FileDescriptor() {} 7 | 8 | private FileDescriptor(int fd) { 9 | openStandard(fd); 10 | } 11 | 12 | public static final FileDescriptor in = new FileDescriptor(0); 13 | public static final FileDescriptor out = new FileDescriptor(1); 14 | public static final FileDescriptor err = new FileDescriptor(2); 15 | 16 | static final int MODE_R = 0; 17 | static final int MODE_W = 1; 18 | static final int MODE_A = 2; 19 | 20 | static FileDescriptor open(File file, int mode) { 21 | FileDescriptor fd = new FileDescriptor(); 22 | fd.open(file.getPath(), mode); 23 | return fd; 24 | } 25 | 26 | public boolean valid() { 27 | return handle != 0; 28 | } 29 | 30 | public void finalize() { 31 | if (handle != 0) { 32 | close(); 33 | } 34 | } 35 | 36 | native boolean open(String path, int mode); 37 | native boolean openStandard(int fd); // 0 = in, 1 = out, 2 = err 38 | 39 | public void sync() {} 40 | native int read(byte[] b, int off, int len); 41 | native void write(byte[] b, int off, int len); 42 | native void close(); 43 | native int size(); 44 | } 45 | -------------------------------------------------------------------------------- /std/src/java/io/FileInputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class FileInputStream extends InputStream { 4 | 5 | private FileDescriptor fd; 6 | private File file; 7 | private int pos; 8 | 9 | public FileInputStream(String path) { 10 | this(new File(path)); 11 | } 12 | 13 | public FileInputStream(File file) { 14 | this(FileDescriptor.open(file, FileDescriptor.MODE_R)); 15 | } 16 | 17 | public FileInputStream(FileDescriptor fd) { 18 | this.fd = fd; 19 | } 20 | 21 | public void close() throws IOException { 22 | fd.close(); 23 | } 24 | 25 | public FileDescriptor getFD() { 26 | return fd; 27 | } 28 | 29 | public int available() { 30 | return fd.size() - pos; 31 | } 32 | 33 | protected void finalize() { 34 | try { 35 | if (fd.valid()) { 36 | close(); 37 | } 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | public int read() throws IOException { 44 | byte[] b = new byte[1]; 45 | read(b, 0, 1); 46 | return (int) b[0]; 47 | } 48 | 49 | public int read(byte[] bytes, int off, int len) throws IOException { 50 | return fd.read(bytes, off, len); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /std/src/java/io/FileOutputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class FileOutputStream extends OutputStream { 4 | private FileDescriptor fd; 5 | 6 | public FileOutputStream(String path) { 7 | this(new File(path)); 8 | } 9 | 10 | public FileOutputStream(File file) { 11 | this(FileDescriptor.open(file, FileDescriptor.MODE_W)); 12 | } 13 | 14 | public FileOutputStream(FileDescriptor fd) { 15 | this.fd = fd; 16 | } 17 | 18 | public void close() throws IOException { 19 | fd.close(); 20 | } 21 | 22 | public FileDescriptor getFD() { 23 | return fd; 24 | } 25 | 26 | protected void finalize() { 27 | try { 28 | if (fd.valid()) { 29 | close(); 30 | } 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | public void write(int b) { 37 | fd.write(new byte[] {(byte) b}, 0, 1); 38 | } 39 | 40 | public void write(byte[] b) { 41 | fd.write(b, 0, b.length); 42 | } 43 | 44 | public void write(byte[] b, int off, int len) { 45 | fd.write(b, off, len); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /std/src/java/io/FilterOutputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class FilterOutputStream extends OutputStream { 4 | protected OutputStream out; 5 | 6 | public FilterOutputStream(OutputStream out) { 7 | this.out = out; 8 | } 9 | 10 | public void close() throws IOException { 11 | out.close(); 12 | } 13 | 14 | public void flush() throws IOException { 15 | out.flush(); 16 | } 17 | 18 | public void write(byte[] b) throws IOException { 19 | out.write(b); 20 | } 21 | 22 | public void write(byte[] b, int off, int len) throws IOException { 23 | out.write(b, off, len); 24 | } 25 | 26 | public void write(int b) throws IOException { 27 | out.write(b); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /std/src/java/io/Flushable.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public interface Flushable { 4 | public void flush() throws IOException; 5 | } -------------------------------------------------------------------------------- /std/src/java/io/IOException.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class IOException extends Exception { 4 | 5 | public IOException() { 6 | super(); 7 | } 8 | 9 | public IOException(String details) { 10 | super(details); 11 | } 12 | 13 | public IOException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public IOException(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/io/InputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public abstract class InputStream implements Closeable { 4 | 5 | public abstract int read() throws IOException; 6 | 7 | public int read(byte[] bytes, int off, int len) throws IOException { 8 | int end = off + len; 9 | int readed = 0; 10 | for (int i = off; i < end; i++) { 11 | int in = read(); 12 | if (in == -1) { 13 | break; 14 | } 15 | bytes[i] = (byte) in; 16 | ++readed; 17 | } 18 | return len; 19 | } 20 | 21 | public void close() throws IOException {} 22 | 23 | public long skip(long n) throws IOException { 24 | return 0; 25 | } 26 | 27 | public int available() throws IOException { 28 | return 0; 29 | } 30 | 31 | public int read(byte[] bytes) throws IOException { 32 | return read(bytes, 0, bytes.length); 33 | } 34 | 35 | public void reset() throws IOException {} 36 | 37 | public boolean markSupported() { 38 | return false; 39 | } 40 | 41 | public void mark(int readLimit) {} 42 | 43 | } -------------------------------------------------------------------------------- /std/src/java/io/InputStreamReader.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class InputStreamReader extends Reader { 4 | 5 | private InputStream in; 6 | private String encoding; 7 | 8 | public InputStreamReader(InputStream in) { 9 | this(in, "UTF-8"); 10 | } 11 | 12 | public InputStreamReader(InputStream in, String charsetName) { 13 | this.in = in; 14 | } 15 | 16 | public String getEncoding() { 17 | return encoding; 18 | } 19 | 20 | public int read() throws IOException { 21 | return in.read(); 22 | } 23 | 24 | public int read(char[] cbuf, int off, int len) throws IOException { 25 | byte[] buf = new byte[cbuf.length]; 26 | int l = in.read(buf, off, len); 27 | for (int i = 0; i < l; i++) { 28 | cbuf[i] = (char) buf[i]; 29 | } 30 | return l; 31 | } 32 | 33 | public boolean ready() throws IOException { 34 | return in.available() != 0; 35 | } 36 | 37 | public void close() throws IOException { 38 | in.close(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /std/src/java/io/OutputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public abstract class OutputStream implements Closeable, Flushable { 4 | 5 | public abstract void write(int b) throws IOException; 6 | 7 | public void write(byte[] bytes, int off, int len) throws IOException { 8 | int end = off + len; 9 | for (int i = off; i < end; i++) { 10 | write((int) bytes[i]); 11 | } 12 | } 13 | 14 | public void close() throws IOException {} 15 | public void flush() throws IOException {} 16 | 17 | public void write(byte[] bytes) throws IOException { 18 | write(bytes, 0, bytes.length); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /std/src/java/io/OutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class OutputStreamWriter extends Writer { 4 | 5 | private String encoding; 6 | private OutputStream out; 7 | 8 | public OutputStreamWriter(OutputStream out) { 9 | this(out, "UTF-8"); 10 | } 11 | 12 | public OutputStreamWriter(OutputStream out, String encoding) { 13 | this.out = out; 14 | this.encoding = encoding; 15 | } 16 | 17 | public String getEncoding() { 18 | return encoding; 19 | } 20 | 21 | public void write(int c) throws IOException { 22 | out.write(c); 23 | } 24 | 25 | public void write(char[] cbuf, int off, int len) throws IOException { 26 | byte[] buf = new byte[cbuf.length]; 27 | for (int i = 0; i < buf.length; i++) { 28 | buf[i] = (byte) cbuf[i]; 29 | } 30 | out.write(buf, off, len); 31 | } 32 | 33 | public void flush() throws IOException { 34 | out.flush(); 35 | } 36 | 37 | public void close() throws IOException { 38 | out.close(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /std/src/java/io/PrintStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class PrintStream extends FilterOutputStream implements Appendable { 4 | 5 | private boolean autoFlush; 6 | private boolean error; 7 | 8 | public PrintStream(File file) { 9 | this(new FileOutputStream(file)); 10 | } 11 | 12 | public PrintStream(OutputStream o) { 13 | this(o, false); 14 | } 15 | 16 | public PrintStream(OutputStream o, boolean autoFlush) { 17 | super(o); 18 | this.autoFlush = autoFlush; 19 | } 20 | 21 | public PrintStream append(char c) throws IOException { 22 | return append(String.valueOf(c)); 23 | } 24 | 25 | public PrintStream append(CharSequence sq) throws IOException { 26 | print(sq.toString()); 27 | return this; 28 | } 29 | 30 | public PrintStream append(CharSequence sq, int start, int end) throws IOException { 31 | return append(sq.subSequence(start, end)); 32 | } 33 | 34 | public void println(String str) { 35 | print(str); 36 | print('\n'); 37 | } 38 | 39 | public void println(int i) { 40 | println(Long.toString((long) i)); 41 | } 42 | 43 | public void println(boolean b) { 44 | println(String.valueOf(b)); 45 | } 46 | 47 | public void println() { 48 | print('\n'); 49 | } 50 | 51 | public void println(Object obj) { 52 | println(String.valueOf(obj)); 53 | } 54 | 55 | public void print(Object obj) { 56 | print(String.valueOf(obj)); 57 | } 58 | 59 | public void print(int i) { 60 | print(Long.toString((long) i)); 61 | } 62 | 63 | public void print(char c) { 64 | print(new char[] {c}); 65 | } 66 | 67 | public void print(boolean b) { 68 | print(String.valueOf(b)); 69 | } 70 | 71 | public void print(char[] chars) { 72 | // TODO encode using NIO Charset 73 | byte[] bytes = new byte[chars.length]; 74 | for (int i = 0; i < chars.length; i++) { 75 | bytes[i] = (byte) chars[i]; 76 | } 77 | try { 78 | write(bytes); 79 | } catch (IOException e) { 80 | setError(); 81 | } 82 | } 83 | 84 | public void print(String str) { 85 | str = str == null ? "null" : str; 86 | print(str.toCharArray()); 87 | } 88 | 89 | public void write(byte[] b) throws IOException { 90 | out.write(b); 91 | if (autoFlush) flush(); 92 | } 93 | 94 | public void write(byte[] b, int off, int len) throws IOException { 95 | out.write(b, off, len); 96 | if (autoFlush) flush(); 97 | } 98 | 99 | public void write(int b) throws IOException { 100 | out.write(b); 101 | if (autoFlush) flush(); 102 | } 103 | 104 | public boolean checkError() { 105 | try { 106 | flush(); 107 | } catch (IOException e) { 108 | setError(); 109 | } 110 | return error; 111 | } 112 | 113 | protected void setError() { 114 | error = true; 115 | } 116 | 117 | protected void clearError() { 118 | error = false; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /std/src/java/io/PrintWriter.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | import java.util.Formatter; 4 | 5 | public class PrintWriter extends Writer implements Appendable { 6 | 7 | private boolean autoFlush; 8 | private boolean error; 9 | private Formatter formatter; 10 | protected Writer out; 11 | 12 | /*public PrintWriter(File file) { 13 | this(new FileOutputStream(file)); 14 | }*/ 15 | 16 | public PrintWriter(Writer out) { 17 | this(out, false); 18 | } 19 | 20 | public PrintWriter(Writer out, boolean autoFlush) { 21 | this.out = out; 22 | this.autoFlush = autoFlush; 23 | this.formatter = new Formatter(this); 24 | } 25 | 26 | public PrintWriter append(char c) throws IOException { 27 | return append(String.valueOf(c)); 28 | } 29 | 30 | public PrintWriter append(CharSequence sq) throws IOException { 31 | print(sq.toString()); 32 | return this; 33 | } 34 | 35 | public PrintWriter append(CharSequence sq, int start, int end) throws IOException { 36 | return append(sq.subSequence(start, end)); 37 | } 38 | 39 | public void println(String str) { 40 | print(str); 41 | print('\n'); 42 | } 43 | 44 | public void println(int i) { 45 | println(Long.toString((long) i)); 46 | } 47 | 48 | public void println(boolean b) { 49 | println(String.valueOf(b)); 50 | } 51 | 52 | public void println() { 53 | print('\n'); 54 | } 55 | 56 | public void println(Object obj) { 57 | println(String.valueOf(obj)); 58 | } 59 | 60 | public void print(Object obj) { 61 | print(String.valueOf(obj)); 62 | } 63 | 64 | public void print(int i) { 65 | print(Long.toString((long) i)); 66 | } 67 | 68 | public void print(char c) { 69 | print(new char[] {c}); 70 | } 71 | 72 | public void print(boolean b) { 73 | print(String.valueOf(b)); 74 | } 75 | 76 | public void print(char[] chars) { 77 | try { 78 | write(chars); 79 | } catch (IOException e) { 80 | setError(); 81 | } 82 | } 83 | 84 | public PrintWriter format(String format, Object... args) { 85 | formatter.format(format, args); 86 | return this; 87 | } 88 | 89 | public PrintWriter printf(String fmt, Object... args) { 90 | return format(fmt, args); 91 | } 92 | 93 | public void print(String str) { 94 | str = str == null ? "null" : str; 95 | print(str.toCharArray()); 96 | } 97 | 98 | public void write(char[] b) throws IOException { 99 | out.write(b); 100 | if (autoFlush) flush(); 101 | } 102 | 103 | public void write(char[] b, int off, int len) throws IOException { 104 | out.write(b, off, len); 105 | if (autoFlush) flush(); 106 | } 107 | 108 | public void write(String s, int off, int len) throws IOException { 109 | out.write(s, off, len); 110 | } 111 | 112 | public void write(String s) throws IOException { 113 | out.write(s); 114 | } 115 | 116 | public void write(int b) throws IOException { 117 | out.write(b); 118 | if (autoFlush) flush(); 119 | } 120 | 121 | public void flush() throws IOException { 122 | out.flush(); 123 | } 124 | 125 | public void close() throws IOException { 126 | out.close(); 127 | } 128 | 129 | public boolean checkError() { 130 | try { 131 | flush(); 132 | } catch (IOException e) { 133 | setError(); 134 | } 135 | return error; 136 | } 137 | 138 | protected void setError() { 139 | error = true; 140 | } 141 | 142 | protected void clearError() { 143 | error = false; 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /std/src/java/io/Reader.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public abstract class Reader implements Closeable { 4 | 5 | protected Object lock; 6 | 7 | protected Reader() { 8 | lock = this; 9 | } 10 | 11 | protected Reader(Object lock) { 12 | this.lock = lock; 13 | } 14 | 15 | public int read() throws IOException { 16 | char[] buf = new char[1]; 17 | if (read(buf, 0, 1) == -1) return -1; 18 | else return buf[0]; 19 | } 20 | 21 | public int read(char[] cbuf) throws IOException { 22 | return read(cbuf, 0, cbuf.length); 23 | } 24 | 25 | public abstract int read(char[] cbuf, int off, int len) throws IOException; 26 | public abstract void close() throws IOException; 27 | 28 | public long skip(long n) throws IOException { 29 | throw new IOException(); 30 | } 31 | 32 | public boolean ready() throws IOException { 33 | return false; 34 | } 35 | 36 | public boolean markSupported() { 37 | return false; 38 | } 39 | 40 | public void mark(int readAheadLimit) throws IOException { 41 | throw new IOException(); 42 | } 43 | 44 | public void reset() throws IOException { 45 | throw new IOException(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /std/src/java/io/Serializable.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public interface Serializable {} 4 | -------------------------------------------------------------------------------- /std/src/java/io/Writer.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public abstract class Writer implements Appendable, Closeable, Flushable { 4 | protected Object lock; 5 | 6 | protected Writer() { 7 | lock = this; 8 | } 9 | 10 | protected Writer(Object lock) { 11 | this.lock = lock; 12 | } 13 | 14 | public abstract void write(char[] cbuf, int off, int len) throws IOException; 15 | public abstract void flush() throws IOException; 16 | public abstract void close() throws IOException; 17 | 18 | public void write(char[] cbuf) throws IOException { 19 | write(cbuf, 0, cbuf.length); 20 | } 21 | 22 | public void write(int c) throws IOException { 23 | write(new char[] {(char) c}, 0, 1); 24 | } 25 | 26 | public void write(String str) throws IOException { 27 | write(str.toCharArray()); 28 | } 29 | 30 | public void write(String str, int off, int len) throws IOException { 31 | if (len == 0) 32 | len = 1; 33 | append(str, off, off+len-1); 34 | } 35 | 36 | public Writer append(char c) throws IOException { 37 | write(new char[] {c}, 0, 1); 38 | return this; 39 | } 40 | 41 | public Writer append(CharSequence sq) throws IOException { 42 | write(sq.toString().toCharArray()); 43 | return this; 44 | } 45 | 46 | public Writer append(CharSequence sq, int start, int end) throws IOException { 47 | return append(sq.subSequence(start, end)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /std/src/java/lang/Appendable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.io.IOException; 4 | 5 | public interface Appendable { 6 | public Appendable append(char c) throws IOException; 7 | public Appendable append(CharSequence sq) throws IOException; 8 | public Appendable append(CharSequence sq, int start, int end) throws IOException; 9 | } 10 | -------------------------------------------------------------------------------- /std/src/java/lang/ArithmeticException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class ArithmeticException extends RuntimeException { 4 | 5 | public ArithmeticException() { 6 | super(); 7 | } 8 | 9 | public ArithmeticException(String details) { 10 | super(details); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /std/src/java/lang/ArrayIndexOutOfBoundsException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException { 4 | 5 | public ArrayIndexOutOfBoundsException() { 6 | super(); 7 | } 8 | 9 | public ArrayIndexOutOfBoundsException(int index) { 10 | super(Integer.toString(index)); 11 | } 12 | 13 | public ArrayIndexOutOfBoundsException(String s) { 14 | super(s); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /std/src/java/lang/ArrayMethods.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | class ArrayMethods { 4 | 5 | public static Object[] clone(Object[] src) { 6 | Object[] arr = new Object[src.length]; 7 | System.arraycopy(src, 0, arr, 0, src.length); 8 | return src; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /std/src/java/lang/AutoCloseable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public interface AutoCloseable { 4 | public void close() throws Exception; 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/lang/Boolean.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public final class Boolean { 4 | public static Boolean FALSE = new Boolean(false); 5 | public static Boolean TRUE = new Boolean(true); 6 | public static Class TYPE = Boolean.class; 7 | 8 | private boolean value; 9 | 10 | public Boolean(boolean b) { 11 | value = b; 12 | } 13 | 14 | public Boolean(String s) { 15 | value = s.equals("true"); 16 | } 17 | 18 | public boolean booleanValue() { 19 | return value; 20 | } 21 | 22 | public String toString() { 23 | return toString(value); 24 | } 25 | 26 | public static String toString(boolean b) { 27 | if (b == true) { 28 | return "true"; 29 | } else { 30 | return "false"; 31 | } 32 | } 33 | 34 | public int hashCode() { 35 | if (value == true) { 36 | return 1; 37 | } else { 38 | return 0; 39 | } 40 | } 41 | 42 | public static boolean parseBoolean(String s) { 43 | return s.equals("true"); 44 | } 45 | 46 | public static boolean getBoolean(String name) { 47 | return parseBoolean(System.getProperty(name, "false")); 48 | } 49 | 50 | public static Boolean valueOf(boolean b) { 51 | return new Boolean(b); 52 | } 53 | 54 | public static Boolean valueOf(String s) { 55 | return new Boolean(s); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /std/src/java/lang/CharSequence.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public interface CharSequence { 4 | public char charAt(int index); 5 | public int length(); 6 | public CharSequence subSequence(int start, int end); 7 | public String toString(); 8 | } 9 | -------------------------------------------------------------------------------- /std/src/java/lang/Character.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class Character { 4 | 5 | public static String toString(char c) { 6 | return String.valueOf(c); 7 | } 8 | 9 | public static char toUpperCase(char ch) { 10 | if (ch > 96 && ch <= 122) { 11 | ch &= 0b11011111; 12 | } 13 | return ch; 14 | } 15 | 16 | public static char toLowerCase(char ch) { 17 | if (ch > 64 && ch <= 90) { 18 | ch |= 0b00100000; 19 | } 20 | return ch; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /std/src/java/lang/Class.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class Class { 4 | private long ref; // class reference id 5 | private ClassLoader classLoader; 6 | 7 | public static Class forName(String name) { 8 | return forName(name, true, ClassLoader.getSystemClassLoader()); 9 | } 10 | 11 | public static Class forName(String name, boolean initialize, ClassLoader loader) { 12 | return loader.loadClass(name, initialize); 13 | } 14 | 15 | private Class(long ref) { 16 | this(ClassLoader.getSystemClassLoader(), ref); 17 | } 18 | 19 | private Class(ClassLoader classLoader, long ref) { 20 | this.ref = ref; 21 | this.classLoader = classLoader; 22 | } 23 | 24 | public ClassLoader getClassLoader() { 25 | return classLoader; 26 | } 27 | 28 | public T newInstance() { 29 | return newClassInstance(ref); 30 | } 31 | 32 | public String getName() { 33 | return getClassName(ref).replace('/', '.'); 34 | } 35 | 36 | public boolean isEnum() { 37 | return isEnum(ref); 38 | } 39 | 40 | public boolean desiredAssertionStatus() { 41 | return false; 42 | } 43 | 44 | private native static T newClassInstance(long ref); 45 | private native static String getClassName(long ref); 46 | private native static boolean isEnum(long ref); 47 | } 48 | -------------------------------------------------------------------------------- /std/src/java/lang/ClassCastException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class ClassCastException extends RuntimeException { 4 | 5 | public ClassCastException() { 6 | super(); 7 | } 8 | 9 | public ClassCastException(String details) { 10 | super(details); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /std/src/java/lang/ClassLoader.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class ClassLoader { 4 | 5 | protected ClassLoader parent; 6 | protected static ClassLoader systemClassLoader; 7 | 8 | protected ClassLoader() { 9 | this(getSystemClassLoader()); 10 | } 11 | 12 | protected ClassLoader(ClassLoader parent) { 13 | this.parent = parent; 14 | } 15 | 16 | public static ClassLoader getSystemClassLoader() { 17 | if (systemClassLoader == null) { 18 | systemClassLoader = new SystemClassLoader(); 19 | } 20 | return systemClassLoader; 21 | } 22 | 23 | public final ClassLoader getParent() { 24 | return parent; 25 | } 26 | 27 | public Class loadClass(String name) throws ClassNotFoundException { 28 | return loadClass(name, true); 29 | } 30 | 31 | protected static boolean registerAsParallelCapable() { 32 | // TODO 33 | return false; 34 | } 35 | 36 | protected Object getClassLoadingLock(String className) { 37 | return this; 38 | } 39 | 40 | protected final Class findLoadedClass(String name) { 41 | return null; // todo: cache using an hashmap 42 | } 43 | 44 | protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { 45 | //synchronized (getClassLoadingLock(name)) { 46 | Class cl = findLoadedClass(name); 47 | if (cl != null) { 48 | return cl; 49 | } 50 | if (parent != null) { 51 | try { 52 | return parent.loadClass(name, resolve); 53 | } catch (ClassNotFoundException e) { 54 | cl = findClass(name); 55 | if (cl != null) { 56 | throw new ClassNotFoundException(name); 57 | } else { 58 | return cl; 59 | } 60 | } 61 | } else { 62 | cl = findClass(name); 63 | if (cl != null) { 64 | throw new ClassNotFoundException(name); 65 | } else { 66 | return cl; 67 | } 68 | } 69 | //} 70 | } 71 | 72 | // Lukyt doesn't have linking as separeted step 73 | protected final void resolveClass(Class c) {} 74 | 75 | protected Class findSystemClass(String name) throws ClassNotFoundException { 76 | return getSystemClassLoader().findClass(name); 77 | } 78 | 79 | protected Class findClass(String name) throws ClassNotFoundException { 80 | throw new ClassNotFoundException(name); 81 | } 82 | 83 | protected native Class defineClass(String name, byte[] b, int off, int len); 84 | 85 | /*protected Class defineClass(String name, byte[] b, int off, int len, ProtectionDomain domain) { 86 | // TODO 87 | }*/ 88 | 89 | private static class SystemClassLoader extends ClassLoader { 90 | 91 | protected SystemClassLoader() { 92 | super(null); 93 | } 94 | 95 | protected Class findClass(String name) throws ClassNotFoundException { 96 | throw new ClassNotFoundException(name); 97 | } 98 | 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /std/src/java/lang/ClassNotFoundException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class ClassNotFoundException extends RuntimeException { 4 | 5 | public ClassNotFoundException() { 6 | super(); 7 | } 8 | 9 | public ClassNotFoundException(String details) { 10 | super(details); 11 | } 12 | 13 | public ClassNotFoundException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public ClassNotFoundException(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/CloneNotSupportedException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class CloneNotSupportedException extends RuntimeException { 4 | 5 | public CloneNotSupportedException() { 6 | super(); 7 | } 8 | 9 | public CloneNotSupportedException(String details) { 10 | super(details); 11 | } 12 | 13 | public CloneNotSupportedException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public CloneNotSupportedException(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/Cloneable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public interface Cloneable { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/lang/Comparable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public interface Comparable { 4 | public int compareTo(T other); 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/lang/Deprecated.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Retention(RetentionPolicy.RUNTIME) 6 | @Target({ElementType.CONSTRUCTOR, ElementType.FIELD, 7 | ElementType.LOCAL_VARIABLE, ElementType.METHOD, 8 | ElementType.PACKAGE, ElementType.PARAMETER, 9 | ElementType.TYPE}) 10 | public @interface Deprecated {} -------------------------------------------------------------------------------- /std/src/java/lang/Double.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public final class Double extends Number { 4 | public static long MAX_VALUE = 0; 5 | public static long MIN_VALUE = 0; 6 | public static int SIZE = 64; // depends on Lua 5.3 7 | 8 | private double value; 9 | 10 | public Double(double d) { 11 | this.value = d; 12 | } 13 | 14 | public static Double valueOf(double d) { 15 | return new Double(d); 16 | } 17 | 18 | public static Double parseDouble(String s) { 19 | return null; // TODO 20 | } 21 | 22 | public static native String toString(double i); 23 | 24 | public byte byteValue() { 25 | return (byte) value; 26 | } 27 | 28 | public int intValue() { 29 | return (int) value; 30 | } 31 | 32 | public long longValue() { 33 | return (long) value; 34 | } 35 | 36 | public short shortValue() { 37 | return (short) value; 38 | } 39 | 40 | public float floatValue() { 41 | return (float) value; 42 | } 43 | 44 | public double doubleValue() { 45 | return value; 46 | } 47 | } -------------------------------------------------------------------------------- /std/src/java/lang/Enum.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public abstract class Enum> { 4 | 5 | private String name; 6 | private int ordinal; 7 | 8 | protected Enum(String name, int ordinal) { 9 | this.name = name; 10 | this.ordinal = ordinal; 11 | } 12 | 13 | public static T valueOf(Class enumType, String s) { 14 | // TODO 15 | return null; 16 | } 17 | 18 | public final boolean equals(Object o) { 19 | return this == o; 20 | } 21 | 22 | public final int hashCode() { 23 | return super.hashCode(); 24 | } 25 | 26 | public String toString() { 27 | return name; 28 | } 29 | 30 | public final String name() { 31 | return name; 32 | } 33 | 34 | public int ordinal() { 35 | return ordinal; 36 | } 37 | 38 | public final Class getDeclaringClass() { 39 | return (Class) getClass(); 40 | } 41 | 42 | public final int compareTo(T e) { 43 | if (ordinal < e.ordinal()) { 44 | return -1; 45 | } else if (ordinal == e.ordinal()) { 46 | return 0; 47 | } else { 48 | return 1; 49 | } 50 | } 51 | 52 | protected final T clone() { 53 | throw new CloneNotSupportedException(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /std/src/java/lang/Error.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class Error extends Throwable { 4 | 5 | public Error() { 6 | super(); 7 | } 8 | 9 | public Error(String details) { 10 | super(details); 11 | } 12 | 13 | public Error(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public Error(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/Exception.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class Exception extends Throwable { 4 | 5 | public Exception() { 6 | super(); 7 | } 8 | 9 | public Exception(String details) { 10 | super(details); 11 | } 12 | 13 | public Exception(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public Exception(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/FunctionalInterface.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Target(ElementType.TYPE) 8 | public @interface FunctionalInterface {} 9 | -------------------------------------------------------------------------------- /std/src/java/lang/IllegalArgumentException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class IllegalArgumentException extends RuntimeException { 4 | 5 | public IllegalArgumentException() { 6 | super(); 7 | } 8 | 9 | public IllegalArgumentException(String details) { 10 | super(details); 11 | } 12 | 13 | public IllegalArgumentException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public IllegalArgumentException(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/IncompatibleClassChangeError.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class IncompatibleClassChangeError extends Error { 4 | 5 | public IncompatibleClassChangeError() { 6 | super(); 7 | } 8 | 9 | public IncompatibleClassChangeError(String s) { 10 | super(s); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/lang/IndexOutOfBoundsException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class IndexOutOfBoundsException extends RuntimeException { 4 | 5 | public IndexOutOfBoundsException() { 6 | super(); 7 | } 8 | 9 | public IndexOutOfBoundsException(String s) { 10 | super(s); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /std/src/java/lang/Integer.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public final class Integer extends Number { 4 | public static final int MAX_VALUE = 0x7FFFFFFF; 5 | public static final int MIN_VALUE = (-MAX_VALUE) - 1; 6 | public static final int SIZE = 32; // depends on Lua 5.3 7 | public static final int BYTES = 4; 8 | public static final Class TYPE = Integer.class; 9 | 10 | private int value; 11 | 12 | public Integer() { 13 | value = 0; 14 | } 15 | 16 | public Integer(int value) { 17 | this.value = value; 18 | } 19 | 20 | public static Integer valueOf(int i) { 21 | return new Integer(i); 22 | } 23 | 24 | public static int parseInt(String s, int radix) { 25 | return (int) Long.parseLong(s, radix); 26 | } 27 | 28 | public static String toString(int i, int radix) { 29 | return Long.toString((long) i, radix); 30 | } 31 | 32 | public static int parseInt(String s) { 33 | return parseInt(s, 10); 34 | } 35 | 36 | public static String toString(int i) { 37 | return toString(i, 10); 38 | } 39 | 40 | public byte byteValue() { 41 | return (byte) value; 42 | } 43 | 44 | public int intValue() { 45 | return value; 46 | } 47 | 48 | public long longValue() { 49 | return (long) value; 50 | } 51 | 52 | public short shortValue() { 53 | return (short) value; 54 | } 55 | 56 | public float floatValue() { 57 | return (float) value; 58 | } 59 | 60 | public double doubleValue() { 61 | return (double) value; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /std/src/java/lang/Iterable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.util.Iterator; 4 | 5 | public interface Iterable { 6 | public Iterator iterator(); 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/lang/LinkageError.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class LinkageError extends Error { 4 | 5 | public LinkageError() { 6 | super(); 7 | } 8 | 9 | public LinkageError(String s) { 10 | super(s); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/lang/Long.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public final class Long extends Number { 4 | public static long MAX_VALUE = 9223372036854775807L; 5 | public static long MIN_VALUE = -9223372036854775808L; 6 | public static int SIZE = 64; // depends on Lua 5.3 7 | public static int BYTES = 8; 8 | public static Class TYPE = Long.class; 9 | 10 | private long value; 11 | 12 | public Long(long l) { 13 | this.value = l; 14 | } 15 | 16 | public Long(String str) { 17 | this.value = parseLong(str); 18 | } 19 | 20 | private static long toDigit(char ch, int radix) { 21 | long l = ch; 22 | l -= 0x30; 23 | if (l < 0) { 24 | l = -1; 25 | } else if (l > 9) { 26 | l = ch - 0x61; 27 | } 28 | return l; 29 | } 30 | 31 | public static long parseLong(String s, int radix) { 32 | if (s == null || s.length() == 0) throw new NumberFormatException("null or empty string"); 33 | s = s.toLowerCase(); 34 | int j = 0; 35 | long l = 0; 36 | char sign = s.charAt(0); 37 | boolean hasSign = sign == '+' || sign == '-'; 38 | int start = hasSign ? 1 : 0; 39 | for (int i = s.length()-1; i > start; i--) { 40 | char ch = s.charAt(i); 41 | long digit = toDigit(ch, radix); 42 | if (digit == -1 || digit > radix) { 43 | throw new NumberFormatException(s); 44 | } 45 | l += digit * (j+1); 46 | j++; 47 | } 48 | if (sign == '-') 49 | l = -l; 50 | return l; 51 | } 52 | 53 | public static String toString(long i, long radix) { 54 | StringBuilder sb = new StringBuilder(); 55 | if (i == 0) { 56 | sb.append("0"); 57 | } else if (i < 0) { 58 | sb.append("-"); 59 | i = -i; 60 | } 61 | while (i > 0) { 62 | long digit = i % radix; 63 | char ch = (char) (digit + 0x30); 64 | if (digit > 9) { 65 | ch = (char) (digit + 0x61); 66 | } 67 | sb.insert(0, ch); 68 | i /= radix; 69 | } 70 | String s = sb.toString(); 71 | return s; 72 | } 73 | 74 | public static long parseLong(String s) { 75 | return parseLong(s, 10); 76 | } 77 | 78 | public static String toString(long i) { 79 | return toString(i, 10); 80 | } 81 | 82 | public byte byteValue() { 83 | return (byte) value; 84 | } 85 | 86 | public int intValue() { 87 | return (int) value; 88 | } 89 | 90 | public long longValue() { 91 | return value; 92 | } 93 | 94 | public short shortValue() { 95 | return (short) value; 96 | } 97 | 98 | public float floatValue() { 99 | return (float) value; 100 | } 101 | 102 | public double doubleValue() { 103 | return (double) value; 104 | } 105 | } -------------------------------------------------------------------------------- /std/src/java/lang/Math.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public final class Math { 4 | 5 | public static final double E = 2.718281828459045; 6 | public static final double PI = 3.141592653589793; 7 | private static final boolean preferNative = Boolean.parseBoolean(System.getProperty("lukyt.math.preferNative", "true")); 8 | 9 | public static double abs(double a) { 10 | if (a < 0) return -a; 11 | else return a; 12 | } 13 | 14 | public static float abs(float a) { 15 | if (a < 0) return -a; 16 | else return a; 17 | } 18 | 19 | public static int abs(int a) { 20 | if (a < 0) return -a; 21 | else return a; 22 | } 23 | 24 | public static long abs(long a) { 25 | if (a < 0) return -a; 26 | else return a; 27 | } 28 | 29 | public static double ceil(double a) { 30 | double decimal = a - (int) a; 31 | return a + (1 - decimal); 32 | } 33 | 34 | public static double signum(double d) { 35 | if (d > 0d) 36 | return 1d; 37 | else if (d < 0d) 38 | return -1d; 39 | else 40 | return 0d; 41 | } 42 | 43 | public static float signum(float f) { 44 | if (f > 0f) 45 | return 1f; 46 | else if (f < 0f) 47 | return -1f; 48 | else 49 | return 0f; 50 | } 51 | 52 | public static double pow(double a, double b) { 53 | double oa = a; 54 | if (b == 0) return 1; 55 | if (b > 0) { 56 | for (int i = 1; i < b; i++) { 57 | a = a * oa; 58 | } 59 | } else { 60 | for (int i = 0; i < 1/b; i++) { 61 | a = a / oa; 62 | } 63 | } 64 | return a; 65 | } 66 | 67 | private static final int[] factorials = new int[] { 68 | 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600}; 69 | private static int factorial(int n) { 70 | if (n < factorials.length) { // small pre-computed factorials 71 | return factorials[n]; 72 | } 73 | if (n == 0) return 1; 74 | else return n * factorial(n - 1); 75 | } 76 | 77 | public static double sin(double x) { 78 | return 1 - cos(x); 79 | } 80 | 81 | 82 | public static double cos(double x) { 83 | if (preferNative) return cos_native(x); 84 | x = x % (2*PI); 85 | if (x < -(PI/2)) { 86 | return -cos(PI+x); 87 | } else if (x > PI/2) { 88 | return -cos(PI-x); 89 | } 90 | int terms = 6; 91 | double num = 1; 92 | int j = 0; 93 | for (int i = 2; i < terms*2; i += 2) { 94 | double term = pow(x, i) / factorial(i); 95 | if (j % 2 == 0) num -= term; 96 | else num += term; 97 | j++; 98 | } 99 | return num; 100 | } 101 | 102 | public static native double cos_native(double x); 103 | 104 | public static double toDegrees(double rad) { 105 | return (rad / (PI / 2)) * 180; 106 | } 107 | 108 | public static long toIntExact(long value) { 109 | if (value > Integer.MAX_VALUE) { 110 | throw new ArithmeticException(); 111 | } 112 | return value; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /std/src/java/lang/NoClassDefException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class NoClassDefException extends LinkageError { 4 | 5 | public NoClassDefException() { 6 | super(); 7 | } 8 | 9 | public NoClassDefException(String details) { 10 | super(details); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /std/src/java/lang/NoSuchFieldError.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class NoSuchFieldError extends Error { 4 | 5 | public NoSuchFieldError() { 6 | super(); 7 | } 8 | 9 | public NoSuchFieldError(String s) { 10 | super(s); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/lang/NoSuchMethodError.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class NoSuchMethodError extends Error { 4 | 5 | public NoSuchMethodError() { 6 | super(); 7 | } 8 | 9 | public NoSuchMethodError(String s) { 10 | super(s); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/lang/NullPointerException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class NullPointerException extends RuntimeException { 4 | 5 | public NullPointerException() { 6 | super(); 7 | } 8 | 9 | public NullPointerException(String details) { 10 | super(details); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/lang/Number.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public abstract class Number { 4 | public abstract byte byteValue(); 5 | public abstract int intValue(); 6 | public abstract long longValue(); 7 | public abstract short shortValue(); 8 | public abstract float floatValue(); 9 | public abstract double doubleValue(); 10 | } 11 | -------------------------------------------------------------------------------- /std/src/java/lang/NumberFormatException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class NumberFormatException extends IllegalArgumentException { 4 | 5 | public NumberFormatException() { 6 | super(); 7 | } 8 | 9 | public NumberFormatException(String s) { 10 | super(s); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/lang/Object.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class Object { 4 | 5 | private Class thizClass; 6 | 7 | public boolean equals(Object other) { 8 | return this == other; 9 | } 10 | 11 | public String toString() { 12 | return getClass().getName() + "@" + hashCode(); 13 | } 14 | 15 | protected void finalize() throws Throwable {} 16 | 17 | public final native void notify(); 18 | public final native void notifyAll(); 19 | 20 | public final native void wait(long timeout) throws InterruptedException; 21 | 22 | public final void wait(long timeout, int nanos) throws InterruptedException { 23 | wait(timeout); 24 | } 25 | 26 | public final void wait() throws InterruptedException { 27 | wait(0); 28 | } 29 | 30 | public final Class getClass() { 31 | if (thizClass == null) { 32 | thizClass = newClass(); 33 | } 34 | return thizClass; 35 | } 36 | 37 | private native Class newClass(); 38 | public native int hashCode(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /std/src/java/lang/Override.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Retention(RetentionPolicy.SOURCE) 6 | @Target(ElementType.METHOD) 7 | public @interface Override {} 8 | -------------------------------------------------------------------------------- /std/src/java/lang/Process.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.io.*; 4 | 5 | public abstract class Process { 6 | // to get r/w, use write mode in popen and redirect output to a /tmp file (using > redirection operand) 7 | public int waitFor() { 8 | return 0; // if not alive call stream:close() and retrieve status code (3rd return) 9 | } 10 | 11 | public boolean isAlive() { 12 | return false; // must do read(*a) and return false if empty 13 | } 14 | 15 | public abstract OutputStream getOutputStream(); 16 | public abstract InputStream getInputStream(); 17 | public abstract InputStream getErrorStream(); 18 | 19 | //public abstract int waitFor() throws InterruptedException; 20 | public abstract int exitValue(); 21 | public abstract void destroy(); 22 | 23 | public Process destroyForcibly() { 24 | destroy(); 25 | return this; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /std/src/java/lang/Runnable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | @FunctionalInterface 4 | public interface Runnable { 5 | public void run(); 6 | } 7 | -------------------------------------------------------------------------------- /std/src/java/lang/Runtime.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import lukyt.*; 4 | 5 | import java.io.*; 6 | 7 | public class Runtime { 8 | 9 | private static Runtime runtime = null; 10 | 11 | public native void gc(); 12 | public native long freeMemory(); 13 | public native long maxMemory(); 14 | public native long totalMemory(); 15 | public native void halt(int status); 16 | public native void load(String filename); 17 | 18 | public void loadLibrary(String libname) { 19 | load(libname + ".lua"); 20 | } 21 | 22 | public void exit(int status) { 23 | halt(status); 24 | } 25 | 26 | public int availableProcessors() { 27 | return 1; // always executed on one core, as using coroutines 28 | } 29 | 30 | private static final LuaObject popen = LuaObject._G.get("io").get("popen"); 31 | 32 | public Process exec(String[] args) { 33 | StringBuilder cmd = new StringBuilder(); 34 | for (int i = 0; i < args.length; i++) { 35 | cmd.append(args[i]); 36 | if (i < args.length) { 37 | cmd.append(" "); 38 | } 39 | } 40 | 41 | LuaObject stream = popen.execute(new LuaObject[] { 42 | LuaObject.fromString(cmd.toString()), 43 | LuaObject.fromString("r") 44 | }); 45 | RuntimeProcess proc = new RuntimeProcess(stream); 46 | return proc; 47 | } 48 | 49 | public static Runtime getRuntime() { 50 | if (runtime == null) { 51 | runtime = new Runtime(); 52 | } 53 | return runtime; 54 | } 55 | 56 | static class RuntimeProcess extends Process { 57 | private LuaObject pStream; 58 | private LuaObject wrStream; 59 | private InputStream in; 60 | 61 | public RuntimeProcess(LuaObject pStream) { 62 | this.pStream = pStream; 63 | this.in = new LuaInputStream(pStream); 64 | } 65 | 66 | public InputStream getInputStream() { 67 | return in; 68 | } 69 | 70 | public InputStream getErrorStream() { 71 | return null; 72 | } 73 | 74 | public OutputStream getOutputStream() { 75 | return null; 76 | } 77 | 78 | public void destroy() {} 79 | 80 | public int exitValue() { 81 | return 0; 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /std/src/java/lang/RuntimeException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class RuntimeException extends Exception { 4 | 5 | public RuntimeException() { 6 | super(); 7 | } 8 | 9 | public RuntimeException(String details) { 10 | super(details); 11 | } 12 | 13 | public RuntimeException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public RuntimeException(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/StackTraceElement.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class StackTraceElement { 4 | private String declaringClass; 5 | private String methodName; 6 | private String fileName; 7 | private int lineNumber; 8 | private boolean nativeMethod; 9 | 10 | public StackTraceElement(String declaringClass, String methodName, String fileName, int lineNumber) { 11 | this(declaringClass, methodName, fileName, lineNumber, false); 12 | } 13 | 14 | public StackTraceElement(String declaringClass, String methodName, String fileName, int lineNumber, boolean nativeMethod) { 15 | this.declaringClass = declaringClass; 16 | this.methodName = methodName; 17 | this.fileName = fileName; 18 | this.lineNumber = lineNumber; 19 | this.nativeMethod = nativeMethod; 20 | } 21 | 22 | public String getClassName() { 23 | return declaringClass; 24 | } 25 | 26 | public String getFileName() { 27 | return fileName; 28 | } 29 | 30 | public int getLineNumber() { 31 | return lineNumber; 32 | } 33 | 34 | public String getMethodName() { 35 | return methodName; 36 | } 37 | 38 | public boolean isNativeMethod() { 39 | return nativeMethod; 40 | } 41 | 42 | public String toString() { 43 | StringBuilder sb = new StringBuilder(); 44 | sb.append(declaringClass); 45 | sb.append('.'); 46 | sb.append(getMethodName()); 47 | sb.append('('); 48 | if (fileName == null) { 49 | if (nativeMethod) { 50 | sb.append("Native Method"); 51 | } else { 52 | sb.append("Unknown Source"); 53 | } 54 | } else { 55 | sb.append(fileName); 56 | if (lineNumber > 0) { 57 | sb.append(':'); 58 | sb.append(lineNumber); 59 | } 60 | } 61 | sb.append(')'); 62 | return sb.toString(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /std/src/java/lang/StringBuffer.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class StringBuffer { 4 | 5 | public char[] chars; 6 | 7 | public StringBuffer() { 8 | chars = new char[0]; 9 | } 10 | 11 | public StringBuffer(String str) { 12 | chars = str.toCharArray(); 13 | } 14 | 15 | public StringBuffer append(char[] chars) { 16 | int orgLength = this.chars.length; 17 | if (this.chars.length < this.chars.length + chars.length) { 18 | char[] newChars = new char[orgLength + chars.length]; 19 | System.arraycopy(this.chars, 0, newChars, 0, orgLength); 20 | this.chars = newChars; 21 | } 22 | System.arraycopy(chars, 0, this.chars, orgLength, chars.length); 23 | return this; 24 | } 25 | 26 | public StringBuffer append(String str) { 27 | append(str.toCharArray()); 28 | return this; 29 | } 30 | 31 | public StringBuffer append(Object obj) { 32 | append(String.valueOf(obj)); 33 | return this; 34 | } 35 | 36 | public StringBuffer append(char c) { 37 | char[] array = new char[1]; 38 | array[0] = c; 39 | return append(array); 40 | } 41 | 42 | public StringBuffer append(long l) { 43 | return append(Long.toString(l)); 44 | } 45 | 46 | public StringBuffer append(int i) { 47 | return append((long) i); 48 | } 49 | 50 | public String toString() { 51 | return new String(chars); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /std/src/java/lang/StringBuilder.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class StringBuilder implements Appendable { 4 | 5 | public char[] chars; 6 | 7 | public StringBuilder() { 8 | chars = new char[0]; 9 | } 10 | 11 | public StringBuilder(String str) { 12 | chars = str.toCharArray(); 13 | } 14 | 15 | /* 16 | public StringBuilder append(char[] chars) { 17 | int orgLength = this.chars.length; 18 | char[] newChars = new char[orgLength + chars.length]; 19 | System.arraycopy(this.chars, 0, newChars, 0, orgLength); 20 | System.arraycopy(chars, 0, newChars, orgLength, chars.length); 21 | this.chars = newChars; 22 | return this; 23 | } 24 | */ 25 | 26 | public native StringBuilder append(char[] chars); 27 | 28 | public StringBuilder append(CharSequence sq) { 29 | return append(sq.toString()); 30 | } 31 | 32 | public StringBuilder append(CharSequence sq, int start, int end) { 33 | return append(sq.subSequence(start, end)); 34 | } 35 | 36 | public StringBuilder append(String str) { 37 | return append(str.toCharArray()); 38 | } 39 | 40 | public StringBuilder append(Object obj) { 41 | return append(String.valueOf(obj)); 42 | } 43 | 44 | public StringBuilder append(char c) { 45 | return append(new char[] {c}); 46 | } 47 | 48 | public StringBuilder append(double d) { 49 | return append(String.valueOf(d)); 50 | } 51 | 52 | public StringBuilder append(float f) { 53 | return append(String.valueOf(f)); 54 | } 55 | 56 | public StringBuilder append(long l) { 57 | return append(Long.toString(l)); 58 | } 59 | 60 | public StringBuilder append(int i) { 61 | return append((long) i); 62 | } 63 | 64 | public StringBuilder insert(int off, char[] chars) { 65 | int orgLength = this.chars.length; 66 | char[] newChars = new char[orgLength + chars.length]; 67 | System.arraycopy(this.chars, 0, newChars, 0, off); 68 | System.arraycopy(chars, 0, newChars, off, chars.length); 69 | System.arraycopy(this.chars, off, newChars, off+1, orgLength-off); 70 | this.chars = newChars; 71 | return this; 72 | } 73 | 74 | public StringBuilder insert(int off, char c) { 75 | return insert(off, new char[] {c}); 76 | } 77 | 78 | public StringBuilder insert(int off, String str) { 79 | return insert(off, str.toCharArray()); 80 | } 81 | 82 | public String toString() { 83 | return new String(chars); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /std/src/java/lang/System.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.io.*; 4 | import lukyt.Os; 5 | 6 | public class System { 7 | 8 | public static final PrintStream out = new PrintStream(new FileOutputStream(FileDescriptor.out)); 9 | public static final InputStream in = new ConsoleInputStream(); 10 | public static final PrintStream err = new PrintStream(new FileOutputStream(FileDescriptor.err)); 11 | 12 | public static native String getenv(String name); 13 | public static native String getProperty(String key); 14 | public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length); 15 | 16 | /** 17 | Note: the default Lua timer only haves second precision and thus, this function is NOT to be used for benchmarking 18 | **/ 19 | public static long currentTimeMillis() { 20 | return (long) (Os.time() * 1000); 21 | } 22 | 23 | /** 24 | Note: based on the CPU time to allow more precision 25 | **/ 26 | public static long nanoTime() { 27 | return (long) (Os.clock() * 1000000000); 28 | } 29 | 30 | public static String getProperty(String key, String def) { 31 | String value = getProperty(key); 32 | if (value == null) { 33 | return def; 34 | } else { 35 | return value; 36 | } 37 | } 38 | 39 | public static void load(String filename) { 40 | Runtime.getRuntime().load(filename); 41 | } 42 | 43 | public static void loadLibrary(String libname) { 44 | Runtime.getRuntime().loadLibrary(libname); 45 | } 46 | 47 | public static void gc() { 48 | Runtime.getRuntime().gc(); 49 | } 50 | 51 | public static void exit(int status) { 52 | Runtime.getRuntime().exit(status); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /std/src/java/lang/Thread.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.util.ArrayList; 4 | 5 | import lukyt.LuaObject; 6 | 7 | public class Thread { 8 | private long handle; 9 | private static ArrayList threads; 10 | private Runnable run; 11 | 12 | // MAX_PRIORITY-priority = number of opcodes executed between each yield 13 | public static int MAX_PRIORITY = 10; 14 | public static int NORM_PRIORITY = 5; 15 | public static int MIN_PRIORITY = 1; 16 | 17 | static { 18 | //threads.add(new Thread(getMainThreadHandle())); 19 | } 20 | 21 | public Thread() { 22 | this.handle = initNewHandle(); 23 | } 24 | 25 | private Thread(long handle) { 26 | this.handle = handle; 27 | } 28 | 29 | public Thread(Runnable run) { 30 | this(run, null); 31 | } 32 | 33 | public Thread(Runnable run, String name) { 34 | this(); 35 | this.run = run; 36 | if (name != null) { 37 | setName(name); 38 | } 39 | } 40 | 41 | public Thread(String name) { 42 | this(null, name); 43 | } 44 | 45 | public native void setName(String name); 46 | public native String getName(); 47 | 48 | public native int getPriority(); 49 | public native void setPriority(int priority); 50 | 51 | public native StackTraceElement[] getStackTrace(); 52 | 53 | private native long initNewHandle(); 54 | 55 | public static Thread currentThread() { 56 | long currHandle = getCurrentThreadHandle(); 57 | for (Thread t : threads) { 58 | if (t.handle == currHandle) { 59 | return t; 60 | } 61 | } 62 | throw new RuntimeException("Could not find current thread ?!"); 63 | } 64 | 65 | public static void yield() { // calls coroutine.yield() 66 | LuaObject coroutine = LuaObject._ENV.get("coroutine"); 67 | coroutine.executeChild("yield"); 68 | } 69 | 70 | public static native void sleep(long millis) throws InterruptedException; 71 | 72 | public static void sleep(long millis, int nanos) throws InterruptedException { 73 | sleep(millis); 74 | } 75 | 76 | public native void start(); 77 | 78 | public void run() { 79 | if (run != null) { 80 | run.run(); 81 | } 82 | } 83 | 84 | private static native long getCurrentThreadHandle(); 85 | private static native long getMainThreadHandle(); 86 | } 87 | -------------------------------------------------------------------------------- /std/src/java/lang/Throwable.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class Throwable { 6 | 7 | private String details; 8 | private Throwable cause; 9 | private StackTraceElement[] elements; 10 | 11 | public Throwable() { 12 | this(null, null); 13 | } 14 | 15 | public Throwable(String details) { 16 | this(details, null); 17 | } 18 | 19 | public Throwable(Throwable cause) { 20 | this(null, cause); 21 | } 22 | 23 | public Throwable(String details, Throwable cause) { 24 | this.details = details; 25 | this.cause = cause; 26 | fillInStackTrace(); 27 | } 28 | 29 | public Throwable initCause(Throwable throwable) { 30 | this.cause = throwable; 31 | return this; 32 | } 33 | 34 | public Throwable getCause() { 35 | return cause; 36 | } 37 | 38 | public String getMessage() { 39 | return details; 40 | } 41 | 42 | public String getLocalizedMessage() { 43 | return details; 44 | } 45 | 46 | private native StackTraceElement[] currentStackTrace(); 47 | 48 | public void printStackTrace() { 49 | printStackTrace(System.err); 50 | } 51 | 52 | public StackTraceElement[] getStackTrace() { 53 | return elements; 54 | } 55 | 56 | public void setStackTrace(StackTraceElement[] stackTrace) { 57 | elements = stackTrace; 58 | } 59 | 60 | public void printStackTrace(PrintStream s) { 61 | s.println(toString()); 62 | for (int i = 0; i < elements.length; i++) { 63 | StackTraceElement element = elements[i]; 64 | s.print("\t"); 65 | s.print(" at "); 66 | s.print(element.toString()); 67 | s.println(); 68 | } 69 | } 70 | 71 | public Throwable fillInStackTrace() { 72 | elements = currentStackTrace(); 73 | return this; 74 | } 75 | 76 | public String toString() { 77 | if (getLocalizedMessage() == null) { // todo actually class of the exception 78 | return getClass().getName(); 79 | } else { 80 | return getClass().getName() + ": " + getLocalizedMessage(); 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /std/src/java/lang/TypeNotPresentException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class TypeNotPresentException extends RuntimeException { 4 | 5 | private String typeName; 6 | 7 | public TypeNotPresentException(String typeName, Throwable cause) { 8 | super(typeName, cause); 9 | this.typeName = typeName; 10 | } 11 | 12 | public String typeName() { 13 | return typeName; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /std/src/java/lang/UnsatisfiedLinkError.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class UnsatisfiedLinkError extends LinkageError { 4 | 5 | public UnsatisfiedLinkError() { 6 | super(); 7 | } 8 | 9 | public UnsatisfiedLinkError(String details) { 10 | super(details); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /std/src/java/lang/UnsupportedOperationException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class UnsupportedOperationException extends RuntimeException { 4 | 5 | public UnsupportedOperationException() { 6 | super(); 7 | } 8 | 9 | public UnsupportedOperationException(String details) { 10 | super(details); 11 | } 12 | 13 | public UnsupportedOperationException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public UnsupportedOperationException(String details, Throwable cause) { 18 | super(details, cause); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /std/src/java/lang/annotation/Annotation.java: -------------------------------------------------------------------------------- 1 | package java.lang.annotation; 2 | 3 | public interface Annotation { 4 | 5 | public Class annotationType(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/lang/annotation/Documented.java: -------------------------------------------------------------------------------- 1 | package java.lang.annotation; 2 | 3 | import static java.lang.annotation.RetentionPolicy.*; 4 | import static java.lang.annotation.ElementType.*; 5 | 6 | @Documented 7 | @Retention(RUNTIME) 8 | @Target(ANNOTATION_TYPE) 9 | public @interface Documented {} 10 | -------------------------------------------------------------------------------- /std/src/java/lang/annotation/ElementType.java: -------------------------------------------------------------------------------- 1 | package java.lang.annotation; 2 | 3 | public enum ElementType { 4 | 5 | ANNOTATION_TYPE, 6 | CONSTRUCTOR, 7 | FIELD, 8 | LOCAL_VARIABLE, 9 | METHOD, 10 | PACKAGE, 11 | PARAMETER, 12 | TYPE, 13 | TYPE_PARAMETER, 14 | TYPE_USE; 15 | } 16 | -------------------------------------------------------------------------------- /std/src/java/lang/annotation/Retention.java: -------------------------------------------------------------------------------- 1 | package java.lang.annotation; 2 | 3 | import static java.lang.annotation.RetentionPolicy.*; 4 | import static java.lang.annotation.ElementType.*; 5 | 6 | @Documented 7 | @Retention(RUNTIME) 8 | @Target(ANNOTATION_TYPE) 9 | public @interface Retention { 10 | public RetentionPolicy value(); 11 | } 12 | -------------------------------------------------------------------------------- /std/src/java/lang/annotation/RetentionPolicy.java: -------------------------------------------------------------------------------- 1 | package java.lang.annotation; 2 | 3 | public enum RetentionPolicy { 4 | CLASS, 5 | RUNTIME, 6 | SOURCE; 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/lang/annotation/Target.java: -------------------------------------------------------------------------------- 1 | package java.lang.annotation; 2 | 3 | import static java.lang.annotation.RetentionPolicy.*; 4 | import static java.lang.annotation.ElementType.*; 5 | 6 | @Documented 7 | @Retention(RUNTIME) 8 | @Target(ANNOTATION_TYPE) 9 | public @interface Target { 10 | public ElementType[] value(); 11 | } 12 | -------------------------------------------------------------------------------- /std/src/java/lang/reflect/AccessibleObject.java: -------------------------------------------------------------------------------- 1 | package java.lang.reflect; 2 | 3 | public class AccessibleObject implements AnnotatedElement { 4 | 5 | protected boolean accessible = false; 6 | 7 | protected AccessibleObject() {} 8 | 9 | public boolean isAccessible() { 10 | return accessible; 11 | } 12 | 13 | public void setAccessible(boolean accessible) { 14 | this.accessible = accessible; 15 | } 16 | 17 | 18 | public static void setAccessible(AccessibleObject[] array, boolean flag) { 19 | for (AccessibleObject obj : array) { 20 | obj.setAccessible(flag); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /std/src/java/lang/reflect/AnnotatedElement.java: -------------------------------------------------------------------------------- 1 | package java.lang.reflect; 2 | 3 | public interface AnnotatedElement { 4 | 5 | public T getAnnotation(Class annotationClass); 6 | public Annotation[] getAnnotations(); 7 | public Annotation[] getDeclaredAnnotations(); 8 | 9 | public default T[] getAnnotationsByType(Class annotationClass) { 10 | ArrayList< 11 | } 12 | 13 | public default T getDeclaredAnnotation(Class annotationClass) { 14 | for (Annotation annot : getDeclaredAnnotations()) { 15 | if (annot.annotationType().equals(annotationClass)) { 16 | return annot; 17 | } 18 | } 19 | return (T) null; 20 | } 21 | 22 | public default boolean isAnnotationPresent(Class annotationClass) { 23 | return getANnotation(annotationClass) != null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /std/src/java/nio/Buffer.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public abstract class Buffer { 4 | 5 | protected int capacity; 6 | protected int position; 7 | protected int limit; 8 | protected int mark; 9 | 10 | public abstract boolean isReadOnly(); 11 | public abstract boolean hasArray(); 12 | public abstract Object array(); 13 | public abstract int arrayOffset(); 14 | public abstract boolean isDirect(); 15 | 16 | public final int capacity() { 17 | return capacity; 18 | } 19 | 20 | public final int position() { 21 | return position; 22 | } 23 | 24 | public final Buffer position(int pos) { 25 | position = pos; 26 | return this; 27 | } 28 | 29 | public final Buffer limit(int l) { 30 | limit = l; 31 | return this; 32 | } 33 | 34 | public final Buffer mark() { 35 | mark = position; 36 | return this; 37 | } 38 | 39 | public final Buffer reset() { 40 | position = mark; 41 | return this; 42 | } 43 | 44 | public final Buffer clear() { 45 | position = 0; 46 | limit = capacity; 47 | mark = -1; 48 | return this; 49 | } 50 | 51 | public final Buffer flip() { 52 | limit = position; 53 | position = 0; 54 | mark = -1; 55 | return this; 56 | } 57 | 58 | public final Buffer rewind() { 59 | position = 0; 60 | mark = -1; 61 | return this; 62 | } 63 | 64 | public final int remaining() { 65 | return limit - position; 66 | } 67 | 68 | public final boolean hasRemaining() { 69 | return remaining() != 0; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /std/src/java/nio/BufferOverflowException.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public class BufferOverflowException extends RuntimeException { 4 | 5 | public BufferOverflowException() {} 6 | 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/nio/BufferUnderflowException.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public class BufferUnderflowException extends RuntimeException { 4 | 5 | public BufferUnderflowException() {} 6 | 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/nio/ByteBuffer.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | import java.nio.impl.*; 4 | 5 | public abstract class ByteBuffer { 6 | 7 | protected ByteOrder order; 8 | 9 | public static ByteBuffer allocate(int capacity) { 10 | return new ArrayByteBufferImpl(capacity); 11 | } 12 | 13 | public static ByteBuffer allocateDirect(int capacity) { 14 | return new DirectByteBufferImpl(capacity); 15 | } 16 | 17 | public abstract CharBuffer asCharBuffer(); 18 | public abstract DoubleBuffer asDoubleBuffer(); 19 | public abstract FloatBuffer asFloatBuffer(); 20 | public abstract IntBuffer asIntBuffer(); 21 | public abstract LongBuffer asLongBuffer(); 22 | public abstract ShortBuffer asShortBuffer(); 23 | 24 | public abstract ByteBuffer asReadOnlyBuffer(); 25 | public abstract ByteBuffer compact(); 26 | public abstract ByteBuffer duplicate(); 27 | 28 | public abstract byte get(); 29 | public abstract byte get(int index); 30 | public abstract char getChar(); 31 | public abstract char getChar(int index); 32 | public abstract double getDouble(); 33 | public abstract double getDouble(int index); 34 | public abstract float getFloat(); 35 | public abstract float getFloat(int index); 36 | public abstract int getInt(); 37 | public abstract int getInt(int index); 38 | public abstract long getLong(); 39 | public abstract long getLong(int index); 40 | public abstract short getShort(); 41 | public abstract short getShort(int index); 42 | 43 | public abstract ByteBuffer put(byte b); 44 | public abstract ByteBuffer put(int index, byte b); 45 | public abstract ByteBuffer putChar(char b); 46 | public abstract ByteBuffer putChar(int index, char b); 47 | public abstract ByteBuffer putDouble(double b); 48 | public abstract ByteBuffer putDouble(int index, double b); 49 | public abstract ByteBuffer putFloat(float b); 50 | public abstract ByteBuffer putFloat(int index, float b); 51 | public abstract ByteBuffer putInt(int b); 52 | public abstract ByteBuffer putInt(int index, int b); 53 | public abstract ByteBuffer putLong(long b); 54 | public abstract ByteBuffer putLong(int index, long b); 55 | public abstract ByteBuffer putShort(short b); 56 | public abstract ByteBuffer putShort(int index, short b); 57 | 58 | public abstract boolean isDirect(); 59 | public abstract ByteBuffer slice(); 60 | 61 | public final ByteOrder order() { 62 | return order; 63 | } 64 | 65 | public final ByteBuffer order(ByteOrder o) { 66 | order = o; 67 | } 68 | 69 | public byte[] array() { 70 | return null; 71 | } 72 | 73 | public int arrayOffset() { 74 | return 0; 75 | } 76 | 77 | public boolean equals(Object o) { 78 | if (o instanceof ByteBuffer) { 79 | ByteBuffer buf = (ByteBuffer) o; 80 | if (buf.capacity() == capacity()) { 81 | byte[] array = new byte[buf.capacity()]; 82 | buf.get(array, 0, buf.capacity()); 83 | for (int i = 0; i < array.length; i++) { 84 | if (get(i) != buf.get(i)) { 85 | return false; 86 | } 87 | } 88 | return true; 89 | } 90 | } 91 | return false; 92 | } 93 | 94 | public ByteBuffer get(byte[] dst, int offset, int length) { 95 | if (remaining() < length) { 96 | throw new BufferUnderflowException(); 97 | } 98 | 99 | for (int i = 0; i < length; i++) { 100 | dst[i + offset] = get(); 101 | } 102 | } 103 | 104 | public ByteBuffer get(byte[] dst) { 105 | return get(dst, 0, dst.length); 106 | } 107 | 108 | public ByteBuffer put(ByteBuffer src) { 109 | if (isReadOnly()) { 110 | throw new ReadOnlyBufferException(); 111 | } 112 | if (src.remaining() > remaining()) { 113 | throw new BufferOverflowException(); 114 | } 115 | while (src.hasRemaining()) { 116 | put(src.get()); 117 | } 118 | } 119 | 120 | public ByteBuffer put(byte[] src, int offset, int length) { 121 | if (isReadOnly()) { 122 | throw new ReadOnlyBufferException(); 123 | } 124 | if (src.length > remaining()) { 125 | throw new BufferOverflowException(); 126 | } 127 | 128 | for (int i = 0; i < length; i++) { 129 | put(src[i + offset]); 130 | } 131 | } 132 | 133 | public ByteBuffer put(byte[] src) { 134 | put(src, 0, src.length); 135 | } 136 | 137 | public final boolean hasArray() { 138 | return true; 139 | } 140 | 141 | public int hashCode() { 142 | int x = remaining(); 143 | x += (int) get(limit() - 1); 144 | return x; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /std/src/java/nio/ByteOrder.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public final class ByteOrder { 4 | 5 | private String s; 6 | 7 | private ByteOrder(String s) { 8 | this.s = s; 9 | } 10 | 11 | public static final ByteOrder BIG_ENDIAN = new ByteOrder("BIG_ENDIAN"); 12 | public static final ByteOrder LITTLE_ENDIAN = new ByteOrder("LITTLE_ENDIAN"); 13 | 14 | public static ByteOrder nativeOrder() { 15 | return LITTLE_ENDIAN; // TODO: use Lua's string.pack to check and actually benefit performance gain 16 | } 17 | 18 | public String toString() { 19 | return s; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /std/src/java/nio/ReadOnlyBufferException.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public class ReadOnlyBufferException extends RuntimeException { 4 | 5 | public ReadOnlyBufferException() {} 6 | 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/nio/charset/Charset.java: -------------------------------------------------------------------------------- 1 | package java.nio.charset; 2 | 3 | public abstract class Charset { 4 | 5 | private static Charset[] charsets = new Charset[0]; 6 | 7 | private String name; 8 | private boolean canEncode; 9 | private boolean canEncodeSet; 10 | 11 | protected Charset(String canonicalName, String[] aliases) { 12 | name = canonicalName; 13 | } 14 | 15 | public final String name() { 16 | return name; 17 | } 18 | 19 | public String displayName() { 20 | return name; 21 | } 22 | 23 | public final boolean isRegistered() { 24 | return true; // TODO: more extensive checks 25 | } 26 | 27 | /*public String displayName(Locale locale) { 28 | return name; 29 | }*/ // TODO: Locale support 30 | 31 | public abstract CharsetDecoder newDecoder(); 32 | public abstract CharsetEncoder newEncoder(); 33 | public abstract boolean contains(Charset cs); 34 | 35 | public boolean canEncode() { 36 | if (!canEncodeSet) { 37 | canEncode = false; 38 | try { 39 | newEncoder(); 40 | } catch (UnsupportedOperationException e) { 41 | canEncode = false; 42 | } 43 | } 44 | return canEncode; 45 | } 46 | 47 | 48 | public static boolean isSupported(String charsetName) { 49 | return charsetName.equals("US-ASCII") || charsetName.equals("UTF-8"); 50 | } 51 | 52 | public static Charset forName(String charsetName) { 53 | for (Charset set : charsets) { 54 | if (set.name().equals(charsetName)) { 55 | return set; 56 | } 57 | } 58 | return null; // TODO: throw UnsupportedCharsetException 59 | } 60 | 61 | public static Charset defaultCharset() { 62 | return forName("UTF-8"); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /std/src/java/nio/charset/StandardCharsets.java: -------------------------------------------------------------------------------- 1 | package java.nio.charset; 2 | 3 | public final class StandardCharsets { 4 | 5 | public static final Charset US_ASCII = null; 6 | public static final Charset UTF_8 = null; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /std/src/java/nio/impl/AbstractByteBufferImpl.java: -------------------------------------------------------------------------------- 1 | package java.nio.impl; 2 | 3 | import java.nio.*; 4 | 5 | public abstract class DirectByteBufferImpl extends ByteBuffer { 6 | 7 | public abstract byte get(int index); 8 | public abstract ByteBuffer put(int index, byte b); 9 | 10 | public byte get() { 11 | return get(position++); 12 | } 13 | 14 | public ByteBuffer put(byte b) { 15 | return put(position++, b); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /std/src/java/nio/impl/ArrayByteBufferImpl.java: -------------------------------------------------------------------------------- 1 | package java.nio.impl; 2 | 3 | import java.nio.*; 4 | 5 | public class ArrayByteBufferImpl extends AbstractByteBuffer { 6 | 7 | private byte[] array; 8 | 9 | public ArrayByteBufferImpl(int capacity) { 10 | array = new byte[capacity]; 11 | this.capacity = capacity; 12 | this.limit = limit; 13 | } 14 | 15 | public byte get(int index) { 16 | if (index < 0 || index > limit) { 17 | throw new IndexOutOfBoundsException(); 18 | } 19 | return array[index]; 20 | } 21 | 22 | public ByteBuffer put(int index, byte b) { 23 | array[index] = b; 24 | return this; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /std/src/java/nio/impl/DirectByteBufferImpl.java: -------------------------------------------------------------------------------- 1 | package java.nio.impl; 2 | 3 | import java.nio.*; 4 | 5 | /** 6 | This class could have used LuaObjects, however they are expansive and thus a custom native handle system is used. 7 | **/ 8 | public class DirectByteBufferImpl extends AbstractByteBuffer { 9 | 10 | public byte get(int index) { 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /std/src/java/util/AbstractCollection.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public abstract class AbstractCollection implements Collection { 4 | public abstract Iterator iterator(); 5 | public abstract int size(); 6 | 7 | public boolean isEmpty() { 8 | return size() == 0; 9 | } 10 | 11 | public boolean contains(Object o) { 12 | Iterator iterator = iterator(); 13 | while (iterator.hasNext()) { 14 | if (o == null) { 15 | if (iterator.next() == null) 16 | return true; 17 | } else { 18 | if (iterator.next().equals(o)) 19 | return true; 20 | } 21 | } 22 | return false; 23 | } 24 | 25 | public Object[] toArray() { 26 | return toArray(new Object[size()]); 27 | } 28 | 29 | public T[] toArray(T[] array) { 30 | int size = size(); 31 | if (array.length < size) { 32 | array = (T[]) new Object[size]; 33 | } 34 | Iterator iterator = iterator(); 35 | for (int i = 0; i < size; i++) { 36 | array[i] = (T) iterator.next(); 37 | } 38 | return array; 39 | } 40 | 41 | public boolean add(E obj) { 42 | throw new UnsupportedOperationException(); 43 | } 44 | 45 | public void clear() { 46 | throw new UnsupportedOperationException(); 47 | } 48 | 49 | public boolean remove(Object obj) { 50 | Iterator iterator = iterator(); 51 | while (iterator.hasNext()) { 52 | if (obj == null) { 53 | if (iterator.next() == null) { 54 | iterator.remove(); 55 | return true; 56 | } 57 | } else { 58 | if (iterator.next().equals(obj)) { 59 | iterator.remove(); 60 | return true; 61 | } 62 | } 63 | } 64 | return false; 65 | } 66 | 67 | public boolean containsAll(Collection c) { 68 | Iterator iterator = c.iterator(); 69 | while (iterator.hasNext()) { 70 | if (!contains(iterator.next())) { 71 | return false; 72 | } 73 | } 74 | return true; 75 | } 76 | 77 | public boolean addAll(Collection c) { 78 | Iterator iterator = c.iterator(); 79 | boolean s = true; 80 | while (iterator.hasNext()) { 81 | add(iterator.next()); 82 | } 83 | return true; 84 | } 85 | 86 | public boolean removeAll(Collection c) { 87 | Iterator iterator = c.iterator(); 88 | while (iterator.hasNext()) { 89 | remove((E) iterator.next()); 90 | } 91 | return true; 92 | } 93 | 94 | public boolean retainAll(Collection c) { 95 | return false; // TODO 96 | } 97 | 98 | public String toString() { 99 | StringBuffer buf = new StringBuffer(); 100 | buf.append(getClass().getName()); 101 | buf.append('['); 102 | Iterator i = iterator(); 103 | for (Object o = null; i.hasNext(); o = i.next()) { 104 | buf.append(String.valueOf(o)); 105 | if (i.hasNext()) { 106 | buf.append(", "); 107 | } 108 | } 109 | buf.append(']'); 110 | return buf.toString(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /std/src/java/util/AbstractSet.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public abstract class AbstractSet extends AbstractCollection implements Set { 4 | 5 | protected AbstractSet() {} 6 | 7 | public boolean equals(Object obj) { 8 | if (obj == this) return true; 9 | if (obj instanceof Set) { 10 | Set set = (Set) obj; 11 | if (set.size() != size()) { 12 | return false; 13 | } 14 | return containsAll(set); 15 | } 16 | return false; 17 | } 18 | 19 | public int hashCode() { 20 | int sum = 0; 21 | for (E elem : this) { 22 | if (elem != null) { 23 | sum += elem.hashCode(); 24 | } 25 | } 26 | return sum; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /std/src/java/util/ArrayList.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public class ArrayList extends AbstractList implements RandomAccess { 4 | 5 | private Object[] array; 6 | private int size = 0; 7 | 8 | public ArrayList(int initialCapacity) { 9 | super(); 10 | array = new Object[initialCapacity]; 11 | } 12 | 13 | public ArrayList(Collection c) { 14 | this(c.size()); 15 | addAll(c); 16 | } 17 | 18 | public ArrayList() { 19 | this(10); 20 | } 21 | 22 | protected void increaseSize(int increment) { 23 | Object[] newArray = new Object[array.length + increment]; 24 | System.arraycopy(array, 0, newArray, 0, array.length); 25 | array = newArray; 26 | } 27 | 28 | public void trimToSize() { 29 | Object[] newArray = new Object[size]; 30 | System.arraycopy(array, 0, newArray, 0, size); 31 | array = newArray; 32 | } 33 | 34 | public E set(int index, E obj) { 35 | if (index < 0 || index >= size) { 36 | throw new IndexOutOfBoundsException(Integer.toString(index)); 37 | } 38 | array[index] = obj; 39 | modCount++; 40 | return obj; 41 | } 42 | 43 | public void add(int index, E obj) { 44 | if (index < 0 || index >= size) { 45 | throw new IndexOutOfBoundsException(Integer.toString(index)); 46 | } 47 | if (size + 1 > array.length) 48 | increaseSize(1); 49 | System.arraycopy(array, index, array, index+1, array.length-index-1); 50 | array[index] = obj; 51 | modCount++; 52 | size++; 53 | } 54 | 55 | public boolean add(E obj) { 56 | if (size + 1 > array.length) 57 | increaseSize(1); 58 | array[size] = obj; 59 | size++; 60 | return true; 61 | } 62 | 63 | public E remove(int index) { 64 | if (index < 0 || index > size) { 65 | throw new IndexOutOfBoundsException(Integer.toString(index)); 66 | } 67 | Object old = array[index]; 68 | System.arraycopy(array, index, array, index-1, array.length-index-1); 69 | modCount++; 70 | size--; 71 | return (E) old; 72 | } 73 | 74 | public E get(int index) { 75 | if (index < 0 || index > size) { 76 | throw new IndexOutOfBoundsException(Integer.toString(index)); 77 | } 78 | return (E) array[index]; 79 | } 80 | 81 | public int size() { 82 | return size; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /std/src/java/util/Collection.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Collection extends Iterable { 4 | public int size(); 5 | public boolean isEmpty(); 6 | public boolean contains(Object obj); 7 | public Iterator iterator(); 8 | public Object[] toArray(); 9 | public T[] toArray(T[] array); 10 | public boolean add(E obj); 11 | public boolean remove(Object o); 12 | public boolean containsAll(Collection c); 13 | public boolean addAll(Collection c); 14 | public boolean removeAll(Collection c); 15 | public boolean retainAll(Collection c); 16 | public void clear(); 17 | } 18 | -------------------------------------------------------------------------------- /std/src/java/util/Comparator.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Comparator { 4 | public int compare(T a, T b); 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/util/ConcurrentModificationException.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public class ConcurrentModificationException extends RuntimeException { 4 | 5 | public ConcurrentModificationException() { 6 | super(); 7 | } 8 | 9 | public ConcurrentModificationException(String message) { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /std/src/java/util/Date.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public class Date { 4 | 5 | private long epoch; 6 | 7 | public Date() { 8 | this.epoch = System.currentTimeMillis(); 9 | } 10 | 11 | public Date(long epoch) { 12 | this.epoch = epoch; 13 | } 14 | 15 | public boolean before(Date when) { 16 | return epoch < when.epoch; 17 | } 18 | 19 | public boolean after(Date when) { 20 | return epoch > when.epoch; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /std/src/java/util/Deque.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Deque extends Queue { 4 | public void addFirst(E e); 5 | public void addLast(E e); 6 | public boolean offerFirst(E e); 7 | public boolean offerLast(E e); 8 | public E removeFirst(); 9 | public E removeLast(); 10 | 11 | public E pollFirst(); 12 | public E pollLast(); 13 | public E peekFirst(); 14 | public E peekLast(); 15 | 16 | public E pop(); 17 | 18 | public E getFirst(); 19 | public E getLast(); 20 | 21 | public boolean removeFirstOccurence(Object o); 22 | public boolean removeLastOccurence(Object o); 23 | 24 | public Iterator descendingIterator(); 25 | } 26 | -------------------------------------------------------------------------------- /std/src/java/util/Enumeration.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Enumeration { 4 | public boolean hasMoreElements(); 5 | public Object nextElement(); 6 | } 7 | -------------------------------------------------------------------------------- /std/src/java/util/EventListener.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface EventListener {} 4 | -------------------------------------------------------------------------------- /std/src/java/util/EventObject.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public class EventObject { 4 | protected Object source; 5 | 6 | public EventObject(Object source) { 7 | this.source = source; 8 | } 9 | 10 | public Object getSource() { 11 | return source; 12 | } 13 | 14 | public String toString() { 15 | return "java.util.EventObject[source=" + source + "]"; 16 | } 17 | } -------------------------------------------------------------------------------- /std/src/java/util/Formatter.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | import java.io.*; 4 | 5 | public class Formatter implements Closeable, Flushable { 6 | 7 | private Appendable out; 8 | 9 | public Formatter() { 10 | this(new StringBuilder()); 11 | } 12 | 13 | public Formatter(Appendable a) { 14 | this.out = a; 15 | } 16 | 17 | public Appendable out() { 18 | return out; 19 | } 20 | 21 | public String toString() { 22 | return out.toString(); 23 | } 24 | 25 | public void flush() { 26 | try { 27 | if (out instanceof Flushable) { 28 | ((Flushable) out).flush(); 29 | } 30 | } catch (IOException e) { 31 | 32 | } 33 | } 34 | 35 | public void close() { 36 | try { 37 | if (out instanceof Closeable) { 38 | ((Closeable) out).close(); 39 | } 40 | } catch (IOException e) { 41 | 42 | } 43 | } 44 | 45 | public Formatter format(String format, Object... args) { 46 | StringBuilder str = new StringBuilder(); 47 | int argIndex = 0; 48 | boolean waitFormat = false; 49 | for (int i = 0; i < format.length(); i++) { 50 | char ch = format.charAt(i); 51 | if (waitFormat) { 52 | if (ch == 'S' || ch == 's') { 53 | String arg = (String) args[argIndex]; 54 | argIndex++; 55 | if (arg == null) { 56 | arg = "null"; 57 | } 58 | str.append(arg); 59 | } else if (ch == '%') { 60 | str.append(ch); 61 | } else if (ch == 'd') { 62 | int d = (int) args[argIndex]; 63 | argIndex++; 64 | str.append(d); 65 | } 66 | } else { 67 | if (ch == '%') waitFormat = true; 68 | else str.append(ch); 69 | } 70 | } 71 | try { 72 | out.append(str.toString()); 73 | } catch (IOException e) { 74 | e.printStackTrace(); 75 | } 76 | return this; 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /std/src/java/util/Iterator.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Iterator { 4 | public boolean hasNext(); 5 | public T next(); 6 | public void remove(); 7 | } 8 | -------------------------------------------------------------------------------- /std/src/java/util/LinkedList.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public class LinkedList extends ArrayList { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/util/List.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface List extends Collection { 4 | public boolean addAll(int index, Collection c); 5 | public E get(int index); 6 | public E set(int index, E obj); 7 | public void add(int index, E obj); 8 | public E remove(int index); 9 | public int indexOf(Object obj); 10 | public int lastIndexOf(Object obj); 11 | public ListIterator listIterator(); 12 | public ListIterator listIterator(int index); 13 | public List subList(int fromIndex, int toIndex); 14 | } 15 | -------------------------------------------------------------------------------- /std/src/java/util/ListIterator.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface ListIterator extends Iterator { 4 | public void add(E obj); 5 | public void set(E obj); 6 | public boolean hasPrevious(); 7 | public E previous(); 8 | public int nextIndex(); 9 | public int previousIndex(); 10 | public void remove(); 11 | } -------------------------------------------------------------------------------- /std/src/java/util/Map.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Map { 4 | 5 | public static interface Entry { 6 | K getKey(); 7 | V getValue(); 8 | V setValue(V value); 9 | } 10 | 11 | public boolean containsKey(Object key); 12 | public boolean containsValue(Object value); 13 | public void clear(); 14 | 15 | public V get(Object key); 16 | public V put(K key, V value); 17 | public void putAll(Map map); 18 | public V remove(Object key); 19 | 20 | public Set keySet(); 21 | public Collection values(); 22 | public Set> entrySet(); 23 | 24 | public int size(); 25 | public boolean isEmpty(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /std/src/java/util/NoSuchElementException.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public class NoSuchElementException extends RuntimeException { 4 | 5 | public NoSuchElementException() { 6 | super(); 7 | } 8 | 9 | public NoSuchElementException(String s) { 10 | super(s); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /std/src/java/util/Objects.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | import java.util.function.Supplier; 4 | 5 | public final class Objects { 6 | 7 | public static boolean equals(Object a, Object b) { 8 | if (a == null && b == null) { 9 | return true; 10 | } else if (a == null) { // && b != null is automatically implied by the above conditon 11 | return false; 12 | } else if (b == null) { // same as above 13 | return false; 14 | } 15 | return a.equals(b); 16 | } 17 | 18 | public static boolean deepEquals(Object a, Object b) { 19 | return equals(a, b); // TODO: actually do a deep check 20 | } 21 | 22 | public static int hashCode(Object o) { 23 | return o == null ? 0 : o.hashCode(); 24 | } 25 | 26 | public static int hash(Object... values) { 27 | int hash = 1; 28 | for (Object o : values) { 29 | hash = 31 * hash + hashCode(o); 30 | } 31 | return hash; 32 | } 33 | 34 | public static String toString(Object o) { 35 | return toString(o, "null"); 36 | } 37 | 38 | public static int compare(T a, T b, Comparator c) { 39 | if (a == b) { 40 | return 0; 41 | } else { 42 | return c.compare(a, b); 43 | } 44 | } 45 | 46 | public static T requireNonNull(T o) { 47 | if (o == null) { 48 | throw new NullPointerException(); 49 | } 50 | return o; 51 | } 52 | 53 | public static T requireNonNull(T o, String message) { 54 | if (o == null) { 55 | throw new NullPointerException(message); 56 | } 57 | return o; 58 | } 59 | 60 | public static T requireNonNull(T o, Supplier supplier) { 61 | if (o == null) { 62 | throw new NullPointerException(supplier.get()); 63 | } 64 | return o; 65 | } 66 | 67 | public static boolean isNull(Object obj) { 68 | return obj == null; 69 | } 70 | 71 | public static boolean nonNull(Object obj) { 72 | return obj != null; 73 | } 74 | 75 | public static String toString(Object o, String nullDefault) { 76 | if (o == null) { 77 | return nullDefault; 78 | } else { 79 | return o.toString(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /std/src/java/util/Optional.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | import java.util.function.*; 4 | 5 | public final class Optional { 6 | 7 | private T value; 8 | 9 | private Optional() { 10 | this.value = null; 11 | } 12 | 13 | private Optional(T value) { 14 | this.value = value; 15 | } 16 | 17 | public static Optional empty() { 18 | return new Optional(); 19 | } 20 | 21 | public static Optional of(T value) { 22 | return new Optional(Objects.requireNonNull(value, "value")); 23 | } 24 | 25 | public static Optional ofNullable(T value) { 26 | if (value == null) 27 | return empty(); 28 | else 29 | return of(value); 30 | } 31 | 32 | public T get() { 33 | if (value == null) 34 | throw new NoSuchElementException(); 35 | return value; 36 | } 37 | 38 | public boolean isPresent() { 39 | return value != null; 40 | } 41 | 42 | public void ifPresent(Consumer consumer) { 43 | if (value != null) { 44 | consumer = Objects.requireNonNull(consumer, "consumer"); 45 | consumer.accept(value); 46 | } 47 | } 48 | 49 | public Optional filter(Predicate predicate) { 50 | predicate = Objects.requireNonNull(predicate, "predicate"); 51 | if (value != null) { 52 | value = predicate.test(value) ? value : null; 53 | } 54 | return Optional.empty(); 55 | } 56 | 57 | public Optional map(Function mapper) { 58 | mapper = Objects.requireNonNull(mapper, "mapper"); 59 | if (value != null) { 60 | return ofNullable(mapper.apply(value)); 61 | } else { 62 | return empty(); 63 | } 64 | } 65 | 66 | public Optional flatMap(Function> mapper) { 67 | if (value != null) { 68 | return Objects.requireNonNull(mapper.apply(value), "mapper result is null"); 69 | } else { 70 | return Optional.empty(); 71 | } 72 | } 73 | 74 | public T orElse(T other) { 75 | return value == null ? other : value; 76 | } 77 | 78 | public T orElseGet(Supplier other) { 79 | if (value == null) { 80 | return Objects.requireNonNull(other.get()); 81 | } else { 82 | return value; 83 | } 84 | } 85 | 86 | public boolean equals(Object obj) { 87 | if (obj instanceof Optional) { 88 | Optional opt = (Optional) obj; 89 | if (value == null) { 90 | return opt.value == null; 91 | } else { 92 | return value.equals(opt.value); 93 | } 94 | } 95 | return false; 96 | } 97 | 98 | public int hashCode() { 99 | return value == null ? 0 : value.hashCode(); 100 | } 101 | 102 | public String toString() { 103 | if (value == null) { 104 | return "Optional[empty]"; 105 | } else { 106 | return "Optional[value=" + value.toString() + "]"; 107 | } 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /std/src/java/util/Queue.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Queue extends Collection { 4 | 5 | public boolean add(E e); 6 | public boolean offer(E e); 7 | public E remove(); 8 | public E poll(); 9 | public E element(); 10 | public E peek(); 11 | 12 | } -------------------------------------------------------------------------------- /std/src/java/util/RandomAccess.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface RandomAccess {} 4 | -------------------------------------------------------------------------------- /std/src/java/util/Set.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | public interface Set extends Collection { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /std/src/java/util/function/Consumer.java: -------------------------------------------------------------------------------- 1 | package java.util.function; 2 | 3 | @FunctionalInterface 4 | public interface Consumer { 5 | public void accept(T t); 6 | } 7 | -------------------------------------------------------------------------------- /std/src/java/util/function/Function.java: -------------------------------------------------------------------------------- 1 | package java.util.function; 2 | 3 | @FunctionalInterface 4 | public interface Function { 5 | public R apply(T t); 6 | } 7 | -------------------------------------------------------------------------------- /std/src/java/util/function/Predicate.java: -------------------------------------------------------------------------------- 1 | package java.util.function; 2 | 3 | @FunctionalInterface 4 | public interface Predicate { 5 | public boolean test(T t); 6 | } 7 | -------------------------------------------------------------------------------- /std/src/java/util/function/Supplier.java: -------------------------------------------------------------------------------- 1 | package java.util.function; 2 | 3 | @FunctionalInterface 4 | public interface Supplier { 5 | 6 | public T get(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /std/src/lukyt/ChildNotFoundException.java: -------------------------------------------------------------------------------- 1 | package lukyt; 2 | 3 | /** 4 | Exception thrown when no children with specified key has been found. 5 | **/ 6 | public class ChildNotFoundException extends RuntimeException { 7 | 8 | public ChildNotFoundException() { 9 | super(); 10 | } 11 | 12 | public ChildNotFoundException(String details) { 13 | super(details); 14 | } 15 | 16 | public ChildNotFoundException(Throwable cause) { 17 | super(cause); 18 | } 19 | 20 | public ChildNotFoundException(String details, Throwable cause) { 21 | super(details, cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /std/src/lukyt/LuaInputStream.java: -------------------------------------------------------------------------------- 1 | package lukyt; 2 | 3 | import java.io.InputStream; 4 | import java.io.IOException; 5 | 6 | public class LuaInputStream extends InputStream { 7 | 8 | private LuaObject stream; 9 | private boolean eof; 10 | private static final LuaObject stringByte = LuaObject._G.get("string").get("byte"); 11 | 12 | public LuaInputStream(LuaObject stream) { 13 | this.stream = stream; 14 | } 15 | 16 | public int read() throws IOException { 17 | LuaObject obj = stream.executeChild("read", new LuaObject[] {LuaObject.fromLong(1)}); 18 | if (obj.asString().length() == 1) { 19 | LuaObject ch = stringByte.execute(obj); 20 | return (int) ch.asLong(); 21 | } else { 22 | eof = true; 23 | return -1; 24 | } 25 | } 26 | 27 | public int available() { 28 | return eof ? 1 : 0; 29 | } 30 | 31 | public void close() throws IOException { 32 | stream.executeChild("close"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /std/src/lukyt/Os.java: -------------------------------------------------------------------------------- 1 | package lukyt; 2 | 3 | /** 4 | Binding class around Lua os API, it uses {@link LuaObject}. 5 | **/ 6 | public class Os { 7 | 8 | private static final LuaObject os = LuaObject._ENV.get("os"); 9 | 10 | /** 11 | Invoke `os.time()` and return the result as a double. 12 | **/ 13 | public static double time() { 14 | return os.executeChild("time").asDouble(); 15 | } 16 | 17 | /** 18 | Invoke `os.clock()` and return the result as a double. 19 | **/ 20 | public static double clock() { 21 | return os.executeChild("clock").asDouble(); 22 | } 23 | 24 | /** 25 | Invoke `os.execute()` which returns true if the shell is available. 26 | **/ 27 | public static boolean isShellAvailable() { 28 | return os.executeChild("execute").asBoolean(); 29 | } 30 | 31 | public static void execute(String command) { 32 | os.executeChild("execute", new LuaObject[] {LuaObject.fromString(command)}); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /std/src/lukyt/awt/iup/IUP.java: -------------------------------------------------------------------------------- 1 | package lukyt.awt.iup; 2 | 3 | public class IUP { 4 | 5 | public static LuaObject iup; 6 | 7 | static { 8 | iup = LuaObject._G.get("require").execute(LuaObject.fromString("iup")); // require("iup") 9 | } 10 | } -------------------------------------------------------------------------------- /std/src/lukyt/awt/iup/IUPGraphics2D.java: -------------------------------------------------------------------------------- 1 | package cil.li.oc.awt; 2 | 3 | import java.awt.*; 4 | import java.awt.geom.*; 5 | import java.util.*; 6 | 7 | public class IUPGraphics2D extends Graphics2D { 8 | 9 | private AffineTransform at = new AffineTransform( 10 | 1, 0, 0, 11 | 0, 1, 0 12 | ); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /std/src/lukyt/awt/iup/IUPToolkit.java: -------------------------------------------------------------------------------- 1 | package lukyt.awt.iup; 2 | 3 | import java.awt.Dimension; 4 | import lukyt.LuaObject; 5 | 6 | public class IUPToolkit { 7 | 8 | public IUPToolkit() {} 9 | 10 | public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException { 11 | throw new UnsupportedOperationException(); 12 | } 13 | 14 | public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException { 15 | throw new UnsupportedOperationException(); 16 | } 17 | 18 | public Clipboard getSystemSelection() { 19 | return null; 20 | } 21 | 22 | public Clipboard getSystemClipboard() { 23 | return null; 24 | } 25 | 26 | protected EventQueue getSystemEventQueueImpl() { 27 | return null; 28 | } 29 | 30 | public Dimension getScreenSize() { 31 | return new Dimension(1920, 1080); 32 | } 33 | 34 | public void beep() { 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /std/src/lukyt/awt/iup/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | Implementation of AWT using IUP's Lua binding 3 | **/ 4 | package cil.li.oc.awt; -------------------------------------------------------------------------------- /std/src/lukyt/awt/iup/peer/IUPComponentPeer.java: -------------------------------------------------------------------------------- 1 | package lukyt.awt.iup.peer; 2 | 3 | import java.awt.peer.ComponentPeer; 4 | 5 | import lukyt.LuaObject; 6 | 7 | import lukyt.awt.iup.IUP; 8 | 9 | public class IUPComponentPeer extends ComponentPeer { 10 | 11 | protected LuaObject handle; 12 | 13 | public Graphics getGraphics() { 14 | return null; 15 | } 16 | 17 | public boolean setVisible(boolean visible) { 18 | 19 | } 20 | 21 | protected void setAttribute(String name, LuaObject value) { 22 | IUP.iup.executeChild("SetAttribute", new LuaObject[] { 23 | handle, 24 | LuaObject.fromString(name), 25 | value 26 | }); 27 | } 28 | 29 | protected void setAttribute(String name, String value) { 30 | setAttribute(name, LuaObject.fromString(value)); 31 | } 32 | 33 | protected void setAttribute(String name, boolean value) { 34 | setAttribute(name, value ? "YES" : "NO"); 35 | } 36 | 37 | public boolean setEnabled(boolean enabled) { 38 | setAttribute("ACTIVE", enabled); 39 | } 40 | 41 | public boolean setVisible(boolean visible) { 42 | setAttribute("VISIBLE", enabled); 43 | } 44 | 45 | public void setBounds(int x, int y, int w, int h) { 46 | setAttribute("POSITION", x + "x" + y); 47 | setAttribute("RASTERSIZE", w + "x" + h); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /test/ComponentTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/ComponentTest.class -------------------------------------------------------------------------------- /test/ComponentTest.java: -------------------------------------------------------------------------------- 1 | import cil.li.oc.Components; 2 | import cil.li.oc.proxies.GPUProxy; 3 | 4 | public class ComponentTest { 5 | 6 | public static void main(String[] args) { 7 | GPUProxy gpu = Components.getPrimary("gpu"); 8 | gpu.setBackground(0x2D2D2D); 9 | gpu.fill(1, 1, 160, 50, ' '); 10 | System.out.println("Filled screen with color 0x2D2D2D"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /test/CosineTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/CosineTest.class -------------------------------------------------------------------------------- /test/CosineTest.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class CosineTest { 4 | 5 | public static void main(String[] args) throws Exception { 6 | int j = 0; 7 | File file = new File("cosine.csv"); 8 | FileOutputStream out = new FileOutputStream(file); 9 | System.out.println("Generating ~120 cosine values"); 10 | long start = System.nanoTime(); 11 | out.write("Radians,Cosine\n".getBytes()); 12 | for (double i = -2*Math.PI; i < 2*Math.PI; i += 0.1) { 13 | double cos = Math.cos(i); 14 | String str = i + "," + cos + "\n"; 15 | //System.out.print(str); 16 | out.write(str.getBytes()); 17 | j++; 18 | } 19 | long end = System.nanoTime(); 20 | System.out.println("Took " + ((end - start)/1000000) + "ms."); 21 | out.close(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /test/HelloWorld$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/HelloWorld$1.class -------------------------------------------------------------------------------- /test/HelloWorld.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/HelloWorld.class -------------------------------------------------------------------------------- /test/HelloWorld.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.util.ArrayList; 3 | import java.util.Iterator; 4 | 5 | public class HelloWorld { 6 | 7 | public static void main(String[] args) throws Exception { 8 | long start = System.nanoTime(); 9 | System.out.println("System.out: " + System.out); 10 | System.out.println("Hello, World!"); 11 | System.out.println("OS kind: " + System.getProperty("os.name")); 12 | 13 | if (System.getProperty("java.vendor").equals("Lukyt")) { 14 | System.out.println("I am running on Lukyt currently!"); 15 | } else { 16 | System.out.println("I am NOT running on Lukyt currently!"); 17 | } 18 | long end = System.nanoTime(); 19 | long total = end - start; 20 | System.out.println("Took: " + (total/1000000) + "ms"); 21 | 22 | start = System.nanoTime(); 23 | for (int i = 0; i < 10; i++) { 24 | System.out.println("Test " + (i+1)); 25 | } 26 | end = System.nanoTime(); 27 | total = end - start; 28 | System.out.println("Took: " + (total/1000000) + "ms"); 29 | 30 | ArrayList list = new ArrayList(); 31 | list.add("Hello"); 32 | list.add("World"); 33 | 34 | System.out.println("List content:"); 35 | for (String str : list) { 36 | System.out.println("- " + str); 37 | } 38 | System.out.println("String class: " + String.class.getName()); 39 | System.out.println("Welcome to this.. testing program?"); 40 | System.out.println("Type \"throw\" to throw an exception"); 41 | System.out.println("Type \"woops\" to throw a catched exception"); 42 | 43 | /*Thread th = new Thread() { 44 | public void run() { 45 | while (true) { 46 | System.out.println("test"); 47 | } 48 | } 49 | }; 50 | th.start();*/ 51 | 52 | while (true) { 53 | String str = ""; 54 | char c = 0; 55 | System.out.print("> "); 56 | while (c != 10) { 57 | try { 58 | c = (char) System.in.read(); 59 | } catch (IOException e) { 60 | e.printStackTrace(); 61 | } 62 | str = str + c; 63 | } 64 | System.out.print("You typed: " + str); 65 | if (str.equals("throw\n")) { 66 | throw new Exception("Test exception"); 67 | } else if (str.equals("woops\n")) { 68 | try { 69 | throw new Exception("Woops :/"); 70 | } catch (Exception e) { 71 | System.out.println("Caught exception"); 72 | e.printStackTrace(); 73 | } 74 | } else if (str.equals("exit\n")) { 75 | System.exit(0); 76 | } else if (str.equals("null\n")) { 77 | throw null; 78 | } else if (str.equals("gc\n")) { 79 | System.gc(); 80 | } 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /test/JavaShell$CommandNotFoundException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/JavaShell$CommandNotFoundException.class -------------------------------------------------------------------------------- /test/JavaShell.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/JavaShell.class -------------------------------------------------------------------------------- /test/JavaShell.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import lukyt.Os; 3 | 4 | public class JavaShell { 5 | 6 | private static final String CSI = ((char) 27) + "["; 7 | 8 | public static String sgr(String sgr) { 9 | return CSI + sgr + "m"; 10 | } 11 | 12 | public static String reset(String str) { 13 | return reset() + str; 14 | } 15 | 16 | public static String reset() { 17 | return sgr("0"); 18 | } 19 | 20 | public static String bold(String str) { 21 | return sgr("1") + str; 22 | } 23 | 24 | public static String bgColor(String str, int color) { 25 | return sgr(Integer.toString(40 + color)) + str; 26 | } 27 | 28 | public static String fgColor(String str, int color) { 29 | return sgr(Integer.toString(30 + color)) + str; 30 | } 31 | 32 | public static String bfgColor(String str, int color) { 33 | return sgr(Integer.toString(90 + color)) + str; 34 | } 35 | 36 | public static void main(String[] args) { 37 | while (true) { 38 | String str = ""; 39 | char c = 0; 40 | System.out.print(bold(bfgColor(System.getenv("PWD"), 4)) + reset("> ")); 41 | while (c != 10) { 42 | try { 43 | c = (char) System.in.read(); 44 | } catch (IOException e) { 45 | e.printStackTrace(); 46 | } 47 | if (c != 10) 48 | str = str + c; 49 | } 50 | try { 51 | if (str.equals("exit")) { 52 | System.exit(0); 53 | } else if (str.equals("gc")) { 54 | System.gc(); 55 | } else if (str.equals("debug throw")) { 56 | throw new RuntimeException(); 57 | } else { 58 | //throw new CommandNotFoundException(str); 59 | Os.execute(str); 60 | } 61 | } catch (CommandNotFoundException e) { 62 | System.err.println("CommandNotFoundException: " + e.getMessage()); 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | } 66 | } 67 | } 68 | 69 | static class CommandNotFoundException extends RuntimeException { 70 | 71 | public CommandNotFoundException(String command) { 72 | super(command); 73 | } 74 | 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /test/StargazerTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/StargazerTest.class -------------------------------------------------------------------------------- /test/StargazerTest.java: -------------------------------------------------------------------------------- 1 | public class StargazerTest { 2 | 3 | public static void main(String[] args) { 4 | boolean precise = false; 5 | for (int i = 0; i < 10; i++) { 6 | long ms = System.currentTimeMillis(); 7 | System.out.println("Wall clock time: " + ms); 8 | if (ms % 1000 != 0) { 9 | precise = true; 10 | } 11 | } 12 | if (precise) { 13 | System.out.println("The clock is precise!"); 14 | } else { 15 | System.out.println("The clock is unprecise!"); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /test/ThreadTest$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/ThreadTest$1.class -------------------------------------------------------------------------------- /test/ThreadTest$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/ThreadTest$2.class -------------------------------------------------------------------------------- /test/ThreadTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenith391/lukyt/7b2f3fcd6149302730463d66c44962067f7a8c12/test/ThreadTest.class -------------------------------------------------------------------------------- /test/ThreadTest.java: -------------------------------------------------------------------------------- 1 | public class ThreadTest { 2 | 3 | public static void main(String[] args) throws Exception { 4 | Thread t1 = new Thread(new Runnable() { // using runnable 5 | public void run() { 6 | while (true) { 7 | System.out.println("1"); 8 | } 9 | } 10 | }); 11 | t1.start(); 12 | 13 | Thread t2 = new Thread() { // using anonymous classes 14 | public void run() { 15 | while (true) { 16 | System.out.println("2"); 17 | } 18 | } 19 | }; 20 | //t2.start(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 3 | $JAVA_HOME/bin/javac -Xlint:-options -source 6 -target 6 HelloWorld.java 4 | $JAVA_HOME/bin/javac -g -Xlint:-options -source 6 -target 6 -cp ../std/bin ComponentTest.java 5 | $JAVA_HOME/bin/javac -g -Xlint:-options -source 6 -target 6 -cp ../std/bin StargazerTest.java 6 | $JAVA_HOME/bin/javac -g -Xlint:-options -source 6 -target 6 -cp ../std/bin JavaShell.java 7 | $JAVA_HOME/bin/javac -g -Xlint:-options -source 6 -target 6 -cp ../std/bin ThreadTest.java 8 | $JAVA_HOME/bin/javac -g -Xlint:-options -source 6 -target 6 -cp ../std/bin CosineTest.java 9 | -------------------------------------------------------------------------------- /test/bulid.bat: -------------------------------------------------------------------------------- 1 | rem A simple bat. file to compile your Java files. 2 | rem To compile a file, run it and specify .java file as an argument (>build HelloWorld.java) 3 | rem Or just drag and drop your file on it! 4 | "%JAVA_HOME%/bin/javac" -Xlint:-options -source 6 -target 6 %1 --------------------------------------------------------------------------------