Skip to content

Commit ddd564b

Browse files
committed
merge apis for (optional) simpler vineflower decompilation
1 parent 932fe06 commit ddd564b

File tree

6 files changed

+269
-280
lines changed

6 files changed

+269
-280
lines changed

src/main/java/oscript/data/BasicScope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ protected Value get()
288288
public Value createMember( int id, int attr )
289289
{
290290
int idx = smit.create(id);
291-
members.ensureCapacity(idx);
291+
members.ensureCapacity(idx);
292292
Reference ref = members.referenceAt(idx);
293293
ref.reset(attr);
294294
return ref;

src/main/java/oscript/data/OArray.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
* @author Rob Clark ([email protected])
3232
*/
3333
public class OArray
34-
extends OObject
35-
implements java.io.Externalizable, MemberTable
34+
extends Value implements MemberTable,java.io.Externalizable
3635
{
3736

3837
/*=======================================================================*/
@@ -1019,27 +1018,31 @@ public MemberTable safeCopy()
10191018
// no-op... OArray is always safe
10201019
return this;
10211020
}
1022-
1021+
1022+
@Override
10231023
public void push1( Value val )
10241024
{
10251025
int idx = length();
10261026
ensureCapacity(idx);
10271027
referenceAt(idx).reset(val);
10281028
}
10291029

1030+
@Override
10301031
public void push2( Value val1, Value val2 )
10311032
{
10321033
push1(val1);
10331034
push1(val2);
10341035
}
10351036

1037+
@Override
10361038
public void push3( Value val1, Value val2, Value val3 )
10371039
{
10381040
push1(val1);
10391041
push1(val2);
10401042
push1(val3);
10411043
}
10421044

1045+
@Override
10431046
public void push4( Value val1, Value val2, Value val3, Value val4 )
10441047
{
10451048
push1(val1);

src/main/java/oscript/data/Value.java

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
*
3535
* @author Rob Clark ([email protected])
3636
*/
37-
public abstract class Value
38-
implements java.io.Serializable
39-
{
37+
public abstract class Value implements MemberTable {
4038
/**
4139
* Various and asundry special values. UNDEFINED is different from
4240
* NULL in that it is used for un-initialized variables or array
@@ -772,11 +770,17 @@ public void opAssign( Value val )
772770
* @throws PackagedScriptObjectException
773771
* @see Function
774772
*/
775-
public Value callAsFunction( StackFrame sf, MemberTable args )
776-
throws PackagedScriptObjectException
773+
public Value callAsFunction( StackFrame sf, MemberTable args ) throws PackagedScriptObjectException
777774
{
778775
return OscriptHost.me.callValueAsFunction(this,sf,args);
779776
}
777+
778+
public Value callAsConstructor( StackFrame sf, MemberTable args )
779+
throws PackagedScriptObjectException
780+
{
781+
throw PackagedScriptObjectException.makeExceptionWrapper( new OUnsupportedOperationException("can't call as constructor") );
782+
}
783+
780784
public final Value callAsFunction( Value oneArg) {
781785
Value[] t = new Value[1];
782786
t[0]=oneArg;
@@ -788,12 +792,6 @@ public final Value callAsFunction( Value[] args )
788792
{
789793
return callAsFunction( StackFrame.currentStackFrame(), new OArray(args) );
790794
}
791-
/** @deprecated */
792-
public final Value callAsFunction( StackFrame sf, Value[] args )
793-
{
794-
throw new ProgrammingErrorException("shouldn't get here!!");
795-
}
796-
797795
/*=======================================================================*/
798796
/**
799797
* Call this object as a constructor.
@@ -804,22 +802,11 @@ public final Value callAsFunction( StackFrame sf, Value[] args )
804802
* @throws PackagedScriptObjectException
805803
* @see Function
806804
*/
807-
public Value callAsConstructor( StackFrame sf, MemberTable args )
808-
throws PackagedScriptObjectException
809-
{
810-
throw PackagedScriptObjectException.makeExceptionWrapper( new OUnsupportedOperationException("can't call as constructor") );
811-
}
812805
public final Value callAsConstructor( Value[] args )
813806
throws PackagedScriptObjectException
814807
{
815808
return callAsConstructor( StackFrame.currentStackFrame(), new OArray(args) );
816809
}
817-
/** @deprecated */
818-
public final Value callAsConstructor( StackFrame sf, Value[] args )
819-
{
820-
throw new ProgrammingErrorException("shouldn't get here!!");
821-
}
822-
823810
/*=======================================================================*/
824811
/**
825812
* Call this object as a parent class constructor.
@@ -1079,21 +1066,64 @@ public boolean castToBooleanSoft() throws PackagedScriptObjectException
10791066
{
10801067
return !(this.bopEquals(Value.NULL).castToBoolean());
10811068
}
1082-
1083-
}
10841069

1070+
//--------------------------------------------
1071+
@Override
1072+
public void push1( Value val )
1073+
{
1074+
throw noSuchMember("push1");
1075+
}
1076+
1077+
@Override
1078+
public void push2( Value val1, Value val2 )
1079+
{
1080+
throw noSuchMember("push2");
1081+
}
1082+
1083+
@Override
1084+
public void push3( Value val1, Value val2, Value val3 )
1085+
{
1086+
throw noSuchMember("push3");
1087+
}
1088+
1089+
@Override
1090+
public void push4( Value val1, Value val2, Value val3, Value val4 )
1091+
{
1092+
throw noSuchMember("push4");
1093+
}
1094+
1095+
@Override
1096+
public void reset()
1097+
{
1098+
throw noSuchMember("reset");
1099+
}
1100+
@Override
1101+
public void free()
1102+
{
1103+
throw noSuchMember("free");
1104+
}
1105+
@Override
1106+
public MemberTable safeCopy()
1107+
{
1108+
throw noSuchMember("safeCopy");
1109+
}
1110+
@Override
1111+
public void ensureCapacity(int sz)
1112+
{
1113+
throw noSuchMember("ensureCapacity");
1114+
}
1115+
1116+
@Override
1117+
public void reinit(int sz)
1118+
{
1119+
throw noSuchMember("reinit");
1120+
}
1121+
1122+
@Override
1123+
public Reference referenceAt(final int idx)
1124+
{
1125+
throw noSuchMember("referenceAt");
1126+
}
10851127

1086-
/*
1087-
* Local Variables:
1088-
* tab-width: 2
1089-
* indent-tabs-mode: nil
1090-
* mode: java
1091-
* c-indentation-style: java
1092-
* c-basic-offset: 2
1093-
* eval: (c-set-offset 'substatement-open '0)
1094-
* eval: (c-set-offset 'case-label '+)
1095-
* eval: (c-set-offset 'inclass '+)
1096-
* eval: (c-set-offset 'inline-open '0)
1097-
* End:
1098-
*/
1128+
}
10991129

src/main/java/oscript/util/MemberTable.java

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -15,128 +15,23 @@
1515
* License along with this library; if not, write to the Free Software
1616
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717
*/
18-
19-
2018
package oscript.util;
2119

22-
import oscript.data.*;
20+
import oscript.data.Reference;
21+
import oscript.data.Value;
2322

24-
25-
/**
26-
* A member table is a special array, with some special methods that don't
27-
* need to exist for regular script arrays:
28-
* <ul>
29-
* <li> direct access to the Reference
30-
* <li> pushN() methods
31-
* </ul>
32-
* Since the member table is used by scope and to pass args to a function/
33-
* constructor, performance is critical, which is the reason for some of these
34-
* methods.
35-
*
36-
* @author Rob Clark ([email protected])
37-
* @version 1
38-
*/
39-
public interface MemberTable
23+
public interface MemberTable
4024
{
41-
/**
42-
* Return the reference at the specified index. This does not necessarily
43-
* grow the array, so the user should be sure to use
44-
* {@link #ensureCapacity(int)} to ensure the array has sufficient capacity
45-
* before dereferencing an index into the table which is not known to exist.
46-
*
47-
* @param idx an index into the member-table
48-
* @return a reference
49-
*/
50-
public Reference referenceAt( int idx );
51-
52-
/**
53-
* Ensure that the member-table has sufficient capacity to accomodate the
54-
* index <code>sz</code>. Grow the array, if necessary.
55-
*
56-
* @param sz the requested table size
57-
*/
58-
public void ensureCapacity( int sz );
59-
60-
/**
61-
* Indication to the member-table that a "safe" copy is required. This
62-
* means that the table may need to outlive the stack-frame that it was
63-
* (possibly) allocated from. What it means to convert this table into
64-
* a "safe" copy depends on the implementation of the table. A safe
65-
* copy is still valid after {@link #free()} is called.
66-
* @return a safe copy of this table
67-
*/
68-
public MemberTable safeCopy();
69-
70-
/**
71-
* Push a single parameter into the table.
72-
* @param val the value to push
73-
*/
74-
public void push1( Value val );
75-
76-
/**
77-
* Push two values into the table.
78-
*
79-
* @param val1 the value to push
80-
* @param val2 the value to push
81-
*/
82-
public void push2( Value val1, Value val2 );
83-
84-
/**
85-
* Push three values into the table.
86-
*
87-
* @param val1 the value to push
88-
* @param val2 the value to push
89-
* @param val3 the value to push
90-
*/
91-
public void push3( Value val1, Value val2, Value val3 );
92-
93-
/**
94-
* Push four values into the table.
95-
*
96-
* @param val1 the value to push
97-
* @param val2 the value to push
98-
* @param val3 the value to push
99-
* @param val4 the value to push
100-
*/
101-
public void push4( Value val1, Value val2, Value val3, Value val4 );
102-
103-
/**
104-
* An indication from the creator of the member-table that, while the table
105-
* itself is still required, the references referred to by the table are
106-
* no longer required and can be freed.
107-
*/
108-
public void reset();
109-
110-
/**
111-
* Indication from creator of member-table that resources allocated from
112-
* the stack are no longer needed and should be released. (If the member
113-
* table is needed after this point, a safe copy should have already been
114-
* obtained by calling {@link #safeCopy()}.)
115-
*/
116-
public void free();
117-
118-
/**
119-
* Get the current size of the member-table. The maximum index which
120-
* can be referenced via {@link #referenceAt(int)} is <code>length()-1</code>
121-
*
122-
* @return the current size
123-
*/
124-
public int length();
25+
public void reset();
26+
public void free();
27+
public void reinit(int len);
28+
public Reference referenceAt(final int idx);
29+
public int length();
30+
public MemberTable safeCopy();
31+
public void push1(Value val);
32+
public void push2(Value val1, Value val2);
33+
public void push3(Value val1, Value val2, Value val3);
34+
public void push4(Value val1, Value val2, Value val3, Value val4);
35+
public void ensureCapacity(int nsz);
12536
}
12637

127-
128-
129-
/*
130-
* Local Variables:
131-
* tab-width: 2
132-
* indent-tabs-mode: nil
133-
* mode: java
134-
* c-indentation-style: java
135-
* c-basic-offset: 2
136-
* eval: (c-set-offset 'substatement-open '0)
137-
* eval: (c-set-offset 'case-label '+)
138-
* eval: (c-set-offset 'inclass '+)
139-
* eval: (c-set-offset 'inline-open '0)
140-
* End:
141-
*/
142-

0 commit comments

Comments
 (0)