Skip to content

Commit

Permalink
Tag refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 1, 2024
1 parent 540defd commit 4b2f6df
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
3 changes: 1 addition & 2 deletions convex-core/src/main/java/convex/core/cvm/AFn.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import convex.core.data.ACell;
import convex.core.data.Cells;
import convex.core.data.IRefFunction;
import convex.core.data.Tag;
import convex.core.data.type.AType;
import convex.core.data.type.Types;

Expand Down Expand Up @@ -50,7 +49,7 @@ public boolean supportsArgs(ACell[] args) {

@Override
public byte getTag() {
return Tag.FN;
return CVMTag.FN;
}


Expand Down
3 changes: 1 addition & 2 deletions convex-core/src/main/java/convex/core/cvm/AOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import convex.core.data.Cells;
import convex.core.data.Format;
import convex.core.data.IRefFunction;
import convex.core.data.Tag;
import convex.core.data.type.AType;
import convex.core.data.type.Types;

Expand Down Expand Up @@ -87,7 +86,7 @@ public int encodeRaw(byte[] bs, int pos) {

@Override
public byte getTag() {
return Tag.OP;
return CVMTag.OP;
}

@Override
Expand Down
10 changes: 9 additions & 1 deletion convex-core/src/main/java/convex/core/cvm/CVMTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class CVMTag {
*/
public static final byte ADDRESS = (byte) 0xEA;


public static final byte SYNTAX = (byte) 0x88;

// ==========================================
Expand Down Expand Up @@ -75,5 +74,14 @@ public class CVMTag {
public static final byte CORE_DEF = (byte) 0xED;


// CVM Code
public static final byte OP = (byte) 0xC0;


public static final byte FN = (byte) 0xCF;

public static final byte FN_MULTI = (byte) 0xCB;



}
6 changes: 3 additions & 3 deletions convex-core/src/main/java/convex/core/data/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ private static <T extends ACell> T readDataStructure(byte tag, Blob b, int pos)
private static ACell readCode(byte tag, Blob b, int pos) throws BadFormatException {


if (tag == Tag.OP) return Ops.read(b, pos);
if (tag == CVMTag.OP) return Ops.read(b, pos);


if (tag == Tag.FN_MULTI) {
if (tag == CVMTag.FN_MULTI) {
AFn<?> fn = MultiFn.read(b,pos);
return fn;
}

if (tag == Tag.FN) {
if (tag == CVMTag.FN) {
AFn<?> fn = Fn.read(b,pos);
return fn;
}
Expand Down
7 changes: 0 additions & 7 deletions convex-core/src/main/java/convex/core/data/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public class Tag {
// Sparsely coded record (0xAx)
public static final byte SPARSE_RECORD_BASE = (byte) 0xA0;



//=========================
// Byte Flags (0xBx)

Expand All @@ -78,11 +76,6 @@ public class Tag {

public static final byte CODE_BASE = (byte) 0xC0;

// CVM Code
public static final byte OP = (byte) 0xC0;
public static final byte FN = (byte) 0xCF;
public static final byte FN_MULTI = (byte) 0xCB;

// ==========================================
// Densely coded record (0xDx)
public static final byte DENSE_RECORD_BASE = (byte) 0xD0;
Expand Down
4 changes: 2 additions & 2 deletions convex-core/src/main/java/convex/core/lang/impl/Fn.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.core.lang.impl;

import convex.core.cvm.AOp;
import convex.core.cvm.CVMTag;
import convex.core.cvm.Context;
import convex.core.cvm.Symbols;
import convex.core.data.ACell;
Expand All @@ -10,7 +11,6 @@
import convex.core.data.Format;
import convex.core.data.IRefFunction;
import convex.core.data.Ref;
import convex.core.data.Tag;
import convex.core.data.util.BlobBuilder;
import convex.core.exceptions.BadFormatException;
import convex.core.exceptions.InvalidDataException;
Expand Down Expand Up @@ -107,7 +107,7 @@ public boolean isCanonical() {

@Override
public int encode(byte[] bs, int pos) {
bs[pos++]=Tag.FN;
bs[pos++]=CVMTag.FN;
return encodeRaw(bs,pos);
}

Expand Down
4 changes: 2 additions & 2 deletions convex-core/src/main/java/convex/core/lang/impl/MultiFn.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.core.lang.impl;

import convex.core.cvm.AFn;
import convex.core.cvm.CVMTag;
import convex.core.cvm.Context;
import convex.core.data.ACell;
import convex.core.data.AVector;
Expand All @@ -9,7 +10,6 @@
import convex.core.data.Format;
import convex.core.data.IRefFunction;
import convex.core.data.Ref;
import convex.core.data.Tag;
import convex.core.data.util.BlobBuilder;
import convex.core.exceptions.BadFormatException;
import convex.core.exceptions.InvalidDataException;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void validateCell() throws InvalidDataException {

@Override
public int encode(byte[] bs, int pos) {
bs[pos++]=Tag.FN_MULTI;
bs[pos++]=CVMTag.FN_MULTI;
return encodeRaw(bs,pos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class AdversarialDataTest {
}

@Test public void testBadConstant() {
invalidEncoding(Tag.OP+Ops.CONSTANT,"");
invalidEncoding(CVMTag.OP+Ops.CONSTANT,"");
}

@Test public void testBadSymbols() {
Expand Down
4 changes: 2 additions & 2 deletions convex-core/src/test/java/convex/core/lang/OpsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testConstant() {
assertNull(c2.getResult());
doOpTest(op);

assertEquals(Blob.wrap(new byte[] {Tag.OP,Ops.CONSTANT,Tag.NULL}),op.getEncoding());
assertEquals(Blob.wrap(new byte[] {CVMTag.OP,Ops.CONSTANT,Tag.NULL}),op.getEncoding());
}

{// nested constant
Expand All @@ -95,7 +95,7 @@ public void testConstant() {
assertEquals(Constant.nil(),c2.getResult());
doOpTest(op);

assertEquals(Blob.wrap(new byte[] {Tag.OP,Ops.CONSTANT,Tag.OP,Ops.CONSTANT,Tag.NULL}),op.getEncoding());
assertEquals(Blob.wrap(new byte[] {CVMTag.OP,Ops.CONSTANT,CVMTag.OP,Ops.CONSTANT,Tag.NULL}),op.getEncoding());
}
}

Expand Down

0 comments on commit 4b2f6df

Please sign in to comment.