Skip to content

Commit

Permalink
Finally remove LibFunction.opcode
Browse files Browse the repository at this point in the history
 - Change unpack to be indentical to table.unpack. Lua 5.1's unpack
   doesn't __len/__index (and so only works on tables, rather than
   userdata), but I don't think will break any existing code.

 - Make some of the platform code less flexible. This code only exists
   for passing the Lua tests really - we don't need it in CC, so no
   sense making it customisable.
  • Loading branch information
SquidDev committed Feb 25, 2023
1 parent 0ffcdad commit 2001ac3
Show file tree
Hide file tree
Showing 193 changed files with 1,491 additions and 2,841 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
дюююююВВВВг г с с с с с ю с с с
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
������
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ﵯ�앯읯읯쑯앯읯읯읯퍯흯쥯�홯홯홯홯홯홯쥯콯�쥯�홯홯홯칱칱�홯홯쉲푯ッ퍵�칲�쑵쥯쥯쥯쥯�홹썵썵썵����﹮텭텭텭텭칪텭텭텭
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
���� � � �
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
бяяяЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖОКыьВ В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В В ффффффррррппнннннуннн
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
304
0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
졆퉑푊쉃צּ�슣Ƿ䋝᷵ᣚ᧹᧕⫋⇳᧌᫼᧷ᯛỶᣙᧁ㏏Ⓧᓍ៓ᓄᓄᓁᛌᓌᓓᓸᓜᓰᓦ៣⷏⏠ዦჟჟჿჵჟჄᇽヽ⋃᧘ᗃᏕᇝᇤⷂ㛔⫙⏽ჴჂᇜᣬዳῼ៽ロ㫆ⷥ⏱ჄᇺჲჲჲჲაᏗᛮ㳣⓻ዦ㧗⋦ᇚ᫷⿉ᷪᷢ⋹ᇾᗪᇅᇅᇜᏯ዆ᇔᇦዼჃ`᧌ዌᇙᛉᣁᓜ㫫⏨ᣜ᧩峋可埗毒淡囙团囓囓囓囓囓囓囀姷四囗壤壃壺埩揀巗翻峬磣秋篘燊淤櫇烞濙滘櫞症狲珿燭燃狩盍瓧濷濔狾毎烾篒翴竽竕狩濼竣糢秄糩磔泘泒泤泛痯病矎毐櫴竡磈秥滚毸泝燙濐書旓棟曐曐曐曵棰每毿櫥曏騁�ǫ茁힍Ǧ萁ǧ訁쪔DŽ谁삐Ǯ츁ﻉDZ쀁좶ǡ뤁좺ǵ괁�ǔ褁쁪핬ﱫ�쵛Ǩ送쵵졲ǀ珶狿狖鬁Ǫ褁梁흹썻퍽Ǜ翌糥�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/java/main/cc/squiddev/cobalt/coroutine/lib/Demo.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/java/main/cc/squiddev/cobalt/coroutine/lib/Pause.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/java/main/cc/squiddev/cobalt/coroutine/lib/StateL1O0.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block$Companion.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block$DefaultImpls.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block$dumpInstructions$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block$iterator$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block$reversed$1$iterator$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block$reversed$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Block.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/BlockKt$extractBlocks$createBlock$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/BlockKt.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/DefinedValue.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition$Argument.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition$GetField.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition$Load.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition$Phi.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition$Unset.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition$Value.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/Definition.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/DefinitionData.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/DefinitionInterpreter.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/DefinitionScanner$DefinitionScanner.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/DefinitionScanner$Desc.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/DefinitionScanner.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/ExtensionsKt$asDebugString$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/ExtensionsKt.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/LocalValue$Default.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/LocalValue$Saved.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/LocalValue$Skip.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/LocalValue.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/MainKt.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/MethodRewriter.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/MethodRewriterKt.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/MutableBlock.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/PauseInstrumentation$visitMethod$1.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/PauseInstrumentation.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/StackValue$Constant.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/StackValue$Default.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/StackValue$Field.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/StackValue$Local.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/StackValue.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/StateClass.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/YieldPoint.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/YieldPointImpl.class:/home/squid/Documents/software/Cobalt/coroutine-transform/build/classes/kotlin/main/cc/squiddev/cobalt/coroutine/YieldPointKt.class
5 changes: 5 additions & 0 deletions src/main/java/org/squiddev/cobalt/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public class Constants {
*/
public static final LuaString EMPTYSTRING = valueOf("");

/**
* The global loaded package table.
*/
public static final LuaString LOADED = valueOf("_LOADED");

/**
* Constant limiting metatag loop processing
*/
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/squiddev/cobalt/GlobalRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.squiddev.cobalt;

/**
* The global registry, a store of Lua values
*/
public final class GlobalRegistry {
private final LuaTable table = new LuaTable();

GlobalRegistry() {
}

/**
* Get the underlying registry table.
*
* @return The global debug registry.
*/
public LuaTable get() {
return table;
}

/**
* Get a subtable in the global {@linkplain #get()} registry table}. If the key exists but is not a table, then
* it will be overridden.
*
* @param name The name of the registry table.
* @return The subentry.
*/
public LuaTable getSubTable(LuaString name) {
LuaValue value = table.rawget(name);
if (value.isTable()) return (LuaTable) value;

LuaTable newValue = new LuaTable();
table.rawset(name, newValue);
return newValue;
}
}
179 changes: 12 additions & 167 deletions src/main/java/org/squiddev/cobalt/LuaState.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
import org.squiddev.cobalt.compiler.LuaC;
import org.squiddev.cobalt.debug.DebugHandler;
import org.squiddev.cobalt.debug.DebugHelpers;
import org.squiddev.cobalt.lib.platform.FileResourceManipulator;
import org.squiddev.cobalt.lib.platform.ResourceManipulator;

import java.io.InputStream;
import java.io.PrintStream;
import java.util.TimeZone;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -44,16 +39,6 @@
* Global lua state
*/
public final class LuaState {
/**
* The active input stream
*/
public InputStream stdin;

/**
* The active output stream
*/
public PrintStream stdout;

/**
* The metatable for all strings
*/
Expand Down Expand Up @@ -84,16 +69,6 @@ public final class LuaState {
*/
public LuaTable threadMetatable;

/**
* Lookup of loaded packages
*/
public final LuaTable loadedPackages = new LuaTable();

/**
* The active resource manipulator
*/
public final ResourceManipulator resourceManipulator;

/**
* The compiler for this threstate
*/
Expand All @@ -104,11 +79,6 @@ public final class LuaState {
*/
public final DebugHandler debug;

/**
* The timezone for this state, as used by {@code os}.
*/
public final TimeZone timezone;

/**
* The currently executing thread
*/
Expand Down Expand Up @@ -136,29 +106,31 @@ public final class LuaState {
*/
private final ErrorReporter reportError;

private final GlobalRegistry registry = new GlobalRegistry();

public LuaState() {
this(new LuaState.Builder());
}

private LuaState(Builder builder) {
stdin = builder.stdin;
stdout = builder.stdout;
stringMetatable = builder.stringMetatable;
booleanMetatable = builder.booleanMetatable;
numberMetatable = builder.numberMetatable;
nilMetatable = builder.nilMetatable;
functionMetatable = builder.functionMetatable;
threadMetatable = builder.threadMetatable;
resourceManipulator = builder.resourceManipulator;
compiler = builder.compiler;
debug = builder.debug;
timezone = builder.timezone;
threader = new YieldThreader(builder.coroutineExecutor);
reportError = builder.reportError;

mainThread = currentThread = new LuaThread(this, new LuaTable());
}

/**
* Get the global registry, a Lua table used to store Lua values.
*
* @return The global debug registry.
*/
public GlobalRegistry registry() {
return registry;
}


/**
* Abandon this state, instructing any pending thread to terminate.
*/
Expand Down Expand Up @@ -247,18 +219,8 @@ public static class Builder {
return thread;
});

private InputStream stdin = System.in;
private PrintStream stdout = System.out;
private LuaTable stringMetatable;
private LuaTable booleanMetatable;
private LuaTable numberMetatable;
private LuaTable nilMetatable;
private LuaTable functionMetatable;
private LuaTable threadMetatable;
private ResourceManipulator resourceManipulator = new FileResourceManipulator();
private LoadState.LuaCompiler compiler = LuaC.INSTANCE;
private DebugHandler debug = DebugHandler.INSTANCE;
private TimeZone timezone = TimeZone.getDefault();
private Executor coroutineExecutor = defaultCoroutineExecutor;
private ErrorReporter reportError;

Expand All @@ -271,111 +233,6 @@ public LuaState build() {
return new LuaState(this);
}

/**
* Set the initial standard input for this Lua state. This defaults to {@link System#in}.
*
* @param stdin The new standard input
* @return This builder
* @see LuaState#stdin
*/
public Builder stdin(InputStream stdin) {
if (stdin == null) throw new NullPointerException("stdin cannot be null");
this.stdin = stdin;
return this;
}

/**
* Set the initial standard output for this Lua state. This defaults to {@link System#out}.
*
* @param stdout The new standard output
* @return This builder
* @see LuaState#stdout
*/
public Builder stdout(PrintStream stdout) {
if (stdout == null) throw new NullPointerException("stdout cannot be null");
this.stdout = stdout;
return this;
}

/**
* Set the initial metatable for string values within this Lua State. This defaults to {@code null}.
*
* @param metatable The initial metatable
* @return This builder
*/
public Builder stringMetatable(LuaTable metatable) {
stringMetatable = metatable;
return this;
}

/**
* Set the initial metatable for boolean values within this Lua State. This defaults to {@code null}.
*
* @param metatable The initial metatable
* @return This builder
*/
public Builder booleanMetatable(LuaTable metatable) {
booleanMetatable = metatable;
return this;
}

/**
* Set the initial metatable for numeric values within this Lua State. This defaults to {@code null}.
*
* @param metatable The initial metatable
* @return This builder
*/
public Builder numberMetatable(LuaTable metatable) {
numberMetatable = metatable;
return this;
}

/**
* Set the initial metatable for nil values within this Lua State. This defaults to {@code null}.
*
* @param metatable The initial metatable
* @return This builder
*/
public Builder nilMetatable(LuaTable metatable) {
nilMetatable = metatable;
return this;
}

/**
* Set the initial metatable for functions within this Lua State. This defaults to {@code null}.
*
* @param metatable The initial metatable
* @return This builder
*/
public Builder functionMetatable(LuaTable metatable) {
functionMetatable = metatable;
return this;
}

/**
* Set the initial metatable for threads within this Lua State. This defaults to {@code null}.
*
* @param metatable The initial metatable
* @return This builder
*/
public Builder threadMetatable(LuaTable metatable) {
threadMetatable = metatable;
return this;
}

/**
* Set the resource manipulator that the {@code os} and {@code io} libraries will use. This defaults to a
* {@link FileResourceManipulator}, which uses the default file system.
*
* @param resourceManipulator The new resource manipulator
* @return This builder
*/
public Builder resourceManipulator(ResourceManipulator resourceManipulator) {
if (this.resourceManipulator == null) throw new NullPointerException("resourceManipulator cannot be null");
this.resourceManipulator = resourceManipulator;
return this;
}

/**
* Set the compiler for this Lua state. This defaults to using the {@link LuaC} compiler.
*
Expand All @@ -400,18 +257,6 @@ public Builder debug(DebugHandler debug) {
return this;
}

/**
* Set the timezone for this Lua state.
*
* @param zone The new timezone
* @return This builder
*/
public Builder timezone(TimeZone zone) {
if (zone == null) throw new NullPointerException("zone cannot be null");
timezone = zone;
return this;
}

/**
* Set the coroutine executor for this state.
*
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/squiddev/cobalt/LuaTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
package org.squiddev.cobalt;

import org.squiddev.cobalt.function.LuaFunction;
import org.squiddev.cobalt.lib.LuaLibrary;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -716,19 +713,6 @@ public LuaValue[] keys() throws LuaError {
return l.toArray(new LuaValue[l.size()]);
}

/**
* Load a library instance by setting its environment to {@code this}
* and calling it, which should initialize the library instance and
* install itself into this instance.
*
* @param state The current lua state
* @param library The callable {@link LuaFunction} to load into {@code this}
* @return {@link LuaValue} containing the result of the initialization call.
*/
public LuaValue load(LuaState state, LuaLibrary library) {
return library.add(state, this);
}

//region Resizing

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/squiddev/cobalt/LuaThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.squiddev.cobalt.debug.DebugState;
import org.squiddev.cobalt.function.LuaFunction;
import org.squiddev.cobalt.lib.CoroutineLib;
import org.squiddev.cobalt.lib.jse.JsePlatform;
import org.squiddev.cobalt.lib.CoreLibraries;

import java.lang.ref.WeakReference;
import java.util.Objects;
Expand All @@ -45,7 +45,7 @@
* A LuaThread is typically created in response to a scripted call to
* {@code coroutine.create()}
* <p>
* The utility class {@link JsePlatform}
* The utility class {@link CoreLibraries}
* sees to it that this initialization is done properly.
* For this reason it is highly recommended to use one of these classes
* when initializing globals.
Expand All @@ -55,7 +55,7 @@
* to manage call state, it is possible to yield from anywhere in luaj.
*
* @see LuaValue
* @see JsePlatform
* @see CoreLibraries
* @see CoroutineLib
*/
public class LuaThread extends LuaValue {
Expand Down
Loading

0 comments on commit 2001ac3

Please sign in to comment.