diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/RExpParser.java b/pmml-rexp/src/main/java/org/jpmml/rexp/RExpParser.java index bd8b763..98727fa 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/RExpParser.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/RExpParser.java @@ -215,7 +215,7 @@ private RFunctionCall readFunctionCall(int flags) throws IOException { RExp tag = readTag(flags); RExp function = readRExp(); - RExp arguments = readRExp(); + RPair arguments = (RPair)readRExp(); return new RFunctionCall(tag, function, arguments, attributes); } @@ -337,9 +337,9 @@ private RGenericVector readVector(int flags) throws IOException { private RExp readBytecode(int flags) throws IOException { int length = readInt(); - readBC1(); + RExp[] reps = new RExp[length]; - return null; + return readBC1(reps); } private RExp readExternalPointer(int flags) throws IOException { @@ -363,40 +363,46 @@ private RRaw readRaw(int flags) throws IOException { return new RRaw(value, readAttributes(flags)); } - private void readBC1() throws IOException { + private RExp readBC1(RExp[] reps) throws IOException { RExp code = readRExp(); - readBCConsts(); + RExp[] constants = readBCConsts(reps); + + return constants[0]; } - private void readBCConsts() throws IOException { + private RExp[] readBCConsts(RExp[] reps) throws IOException { int n = readInt(); + RExp[] pool = new RExp[n]; + for(int i = 0; i < n; i++){ int type = readInt(); switch(type){ case SExpTypes.LISTSXP: case SExpTypes.LANGSXP: - readBCLang(type); + pool[i] = readBCLang(type, reps); break; case SExpTypes.BCODESXP: - readBC1(); + pool[i] = readBC1(reps); break; case SerializationTypes.ATTRLISTSXP: case SerializationTypes.ATTRLANGSXP: case SerializationTypes.BCREPREF: case SerializationTypes.BCREPDEF: - readBCLang(type); + pool[i] = readBCLang(type, reps); break; default: - readRExp(); + pool[i] = readRExp(); break; } } + + return pool; } - private void readBCLang(int type) throws IOException { + private RExp readBCLang(int type, RExp[] reps) throws IOException { switch(type){ case SExpTypes.LISTSXP: @@ -410,26 +416,53 @@ private void readBCLang(int type) throws IOException { type = readInt(); } + RPair attributes; + switch(type){ case SerializationTypes.ATTRLISTSXP: case SerializationTypes.ATTRLANGSXP: - readAttributes(); + attributes = readAttributes(); break; default: + attributes = null; + break; + } + + RPair pair; + + switch(type){ + case SExpTypes.LISTSXP: + case SerializationTypes.ATTRLISTSXP: + pair = new RPair(null, null, attributes); break; + case SExpTypes.LANGSXP: + case SerializationTypes.ATTRLANGSXP: + pair = new RFunctionCall(null, null, null, attributes); + break; + default: + throw new UnsupportedOperationException(String.valueOf(type)); + } + + if(pos >= 0){ + reps[pos] = pair; } RExp tag = readRExp(); + pair.setTag(tag); - readBCLang(readInt()); - readBCLang(readInt()); - break; + RExp value = readBCLang(readInt(), reps); + pair.setValue(value); + + RPair next = (RPair)readBCLang(readInt(), reps); + if(next != null){ + pair.setNext(next); + } + + return pair; case SerializationTypes.BCREPREF: - readInt(); - break; + return reps[readInt()]; default: - readRExp(); - break; + return readRExp(); } } diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/RFunctionCall.java b/pmml-rexp/src/main/java/org/jpmml/rexp/RFunctionCall.java index b2eba2a..35a6bb7 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/RFunctionCall.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/RFunctionCall.java @@ -18,44 +18,19 @@ */ package org.jpmml.rexp; -public class RFunctionCall extends RExp { +public class RFunctionCall extends RPair { - private RExp tag = null; + public RFunctionCall(RExp tag, RExp function, RPair arguments, RPair attributes){ + super(tag, function, attributes); - private RExp function = null; - - private RExp arguments = null; - - - public RFunctionCall(RExp tag, RExp function, RExp arguments, RPair attributes){ - super(attributes); - - setTag(tag); - setFunction(function); - setArguments(arguments); - } - - public RExp getTag(){ - return this.tag; - } - - private void setTag(RExp tag){ - this.tag = tag; + setNext(arguments); } public RExp getFunction(){ - return this.function; - } - - private void setFunction(RExp function){ - this.function = function; - } - - public RExp getArguments(){ - return this.arguments; + return getValue(); } - private void setArguments(RExp arguments){ - this.arguments = arguments; + public RPair getArguments(){ + return getNext(); } } \ No newline at end of file diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/RPair.java b/pmml-rexp/src/main/java/org/jpmml/rexp/RPair.java index c7f38c3..c72c870 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/RPair.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/RPair.java @@ -65,7 +65,7 @@ public RExp getTag(){ return this.tag; } - private void setTag(RExp tag){ + void setTag(RExp tag){ this.tag = tag; } @@ -73,7 +73,7 @@ public RExp getValue(){ return this.value; } - private void setValue(RExp value){ + void setValue(RExp value){ this.value = value; }