Skip to content

Commit

Permalink
Bool.not(), set id not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Jan 16, 2018
1 parent 9da5e60 commit 825caae
Show file tree
Hide file tree
Showing 17 changed files with 625 additions and 551 deletions.
7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

804 changes: 373 additions & 431 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/com/devbaltasarq/pooi/core/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AppInfo {
public static final String Name = "Pooi";
public static final String Email = "jbgarcia@uvigo.es";
public static final String Author = "Baltasar García Perez-Schofield";
public static final String Version = "1.9 20160629";
public static final String Version = "2.0 20180116";
public static final String License = "MIT License: https://opensource.org/licenses/MIT";
public static final String SessionFileExt = ".txt";
public static final String ScriptFileExt = ".poi";
Expand Down
46 changes: 24 additions & 22 deletions src/com/devbaltasarq/pooi/core/ObjectBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ public class ObjectBag {
* Its objective is to wrap a method in the list of available methods in this object.
*/
public static class Slot {
public Slot(Method mth) {
public Slot(Method mth)
{
this.mth = mth;
}

public Method getMethod() {
public Method getMethod()
{
return mth;
}

public void setMethod(Method mth) {
public void setMethod(Method mth)
{
this.mth = mth;
}

Expand Down Expand Up @@ -582,7 +585,7 @@ public void set(String name, ObjectBag obj) throws InterpretError
obj.setName( name );
}

// Change the container of the pointed object, if apropriated
// Change the container of the pointed object, if appropriated
if ( !isParent
&& obj instanceof ValueObject )
{
Expand Down Expand Up @@ -612,26 +615,23 @@ public void embed(String name, ObjectBag obj) throws InterpretError
*/
public void set(String name, Method mth) throws InterpretError
{
this.chkIdentifierForMemberName( name );
this.setMethod( name, mth );
this.set( name, mth, Check );
}

/**
* Returns a member, local to this object, given a name.
* @param id A String containing the name.
* @return The member corresponding to that id, or null.
/** Adds a new method to the list of methods of this object
* @param name The name of this new method
* @param mth The Method itself
* @throws com.devbaltasarq.pooi.core.Interpreter.InterpretError if name is not valid
*/
public Member localLookUpMember(String id) {
Member toret = localLookUpAttribute( id );

if ( toret == null ) {
toret = localLookUpMethod( id );
public void set(String name, Method mth, boolean check) throws InterpretError
{
if ( check ) {
this.chkIdentifierForMemberName(name);
}

return toret;
this.setMethod( name, mth );
}

protected final void setMethod(String name, Method mth) throws InterpretError
protected final void setMethod(String name, Method mth)
{
final Slot slot = this.lookUpSlot( name );

Expand All @@ -648,7 +648,6 @@ protected final void setMethod(String name, Method mth) throws InterpretError
protected final void setAttribute(String name, ObjectBag obj) throws InterpretError
{
boolean isParent = name.equals( ParentAttribute.ParentAttributeName );
final Runtime rt = this.getRuntime();
Attribute atr = localLookUpAttribute( name );

// Chk cycles in parent graph
Expand Down Expand Up @@ -721,7 +720,8 @@ public void renameMember(String oldName, String newName) throws InterpretError
return;
}

public void renameMethod(String oldName, String newName) throws InterpretError {
public void renameMethod(String oldName, String newName) throws InterpretError
{
final Slot slot = this.lookUpSlot( oldName );

if ( slot != null ) {
Expand Down Expand Up @@ -750,7 +750,8 @@ public void renameMethod(String oldName, String newName) throws InterpretError {
return;
}

public void renameAttribute(String oldName, String newName) throws InterpretError {
public void renameAttribute(String oldName, String newName) throws InterpretError
{
final Attribute attr = this.localLookUpAttribute( oldName );
ObjectBag ref = null;

Expand Down Expand Up @@ -846,7 +847,8 @@ public Method localLookUpMethod(String mthName)
* @param mthName The name of the method.
* @return A Slot object pointing to the method, null otherwise.
*/
public Slot lookUpSlot(String mthName) {
public Slot lookUpSlot(String mthName)
{
return this.methods.get( mthName );
}

Expand Down
1 change: 0 additions & 1 deletion src/com/devbaltasarq/pooi/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private static String getMessageId(Lexer lex)
{
char ch;
String toret = "";
Lexer.TokenType tokenType;

// Decide which kind of message, native: *,+,-... or average
lex.skipSpaces();
Expand Down
5 changes: 5 additions & 0 deletions src/com/devbaltasarq/pooi/core/Reserved.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public class Reserved {

public static final String ParentAttribute = "parent";
public static final String SetMethod = "set";


public static final String RootObject = "Root";
public static final String LibObject = "Lib";
Expand All @@ -17,6 +19,7 @@ public class Reserved {
public static final String BoolObject = "Bool";
public static final String RealObject = "Real";
public static final String StrObject = "Str";
public static final String DateTimeObject = "DateTime";
public static final String SelfRef = "self";
public static final String AssignmentOperator = "=";
public static final String AllowedSymbolsInMethodName = "!<>+-*/=?^";
Expand All @@ -31,6 +34,8 @@ public class Reserved {
+ ' ' + RealObject + ' '
+ ' ' + StrObject + ' '
+ ' ' + AssignmentOperator + ' '
+ ' ' + DateTimeObject + ' '
+ ' ' + SetMethod + ' '
;

public static boolean isReservedForObjects(String id)
Expand Down
6 changes: 5 additions & 1 deletion src/com/devbaltasarq/pooi/core/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private Runtime() throws InterpretError
this.getLiteralsContainer().clear( false );
}

public void addMethodsToRuntimeObjects() throws InterpretError
private void addMethodsToRuntimeObjects() throws InterpretError
{
// Int
this.integer.set( NativeMethodIntSum.EtqMthIntSum, new NativeMethodIntSum( this ) );
Expand Down Expand Up @@ -116,6 +116,10 @@ public void addMethodsToRuntimeObjects() throws InterpretError
this.real.set( NativeMethodRealInt.EtqMthInt, new NativeMethodRealInt( this ) );
this.real.set( NativeMethodRealRound.EtqMthRound, new NativeMethodRealRound( this ) );

// Bool
this.bool.set( NativeMethodBoolNot.EtqMthBoolNot, new NativeMethodBoolNot( this ) );
this.bool.set( NativeMethodBoolIsTrue.EtqMthBoolIsTrue, new NativeMethodBoolIsTrue( this ) );

// Str
this.str.set( NativeMethodStrConcat.EtqMthStrConcat, new NativeMethodStrConcat( this ) );
this.str.set( NativeMethodStrConcatAssign.EtqMthStrConcatAssign, new NativeMethodStrConcatAssign( this ) );
Expand Down
5 changes: 4 additions & 1 deletion src/com/devbaltasarq/pooi/core/evaluables/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public String getFormalParametersAsString() {
return toret.toString().trim();
}

/** @return Gets the body of the method as a representation in text */
/** @return Gets the body of the method as a representation in text
* Native methods return with something like "{: }", which is enough.
* Interpreted methods must be represented accurately.
*/
public abstract String getMethodBodyAsString();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
import java.util.HashMap;
import java.util.Stack;

/**
* Method holding interpreted code.
* User: baltasarq
* Date: 11/19/12
*/
/** Method holding interpreted code. */
public class InterpretedMethod extends Method {
public static final String DefaultMethodId = "__mth_";

Expand Down Expand Up @@ -113,14 +109,15 @@ public void addCmds(String cmd) throws InterpretError
this.stackCmds.addAll( Arrays.asList( Parser.parseOrder( this.getRuntime(), cmd ) ) );
}

@Override
public InterpretedMethod copy()
{
InterpretedMethod toret = new InterpretedMethod( this.getRuntime(), this.getName() );

// Commands
toret.stackCmds.addAll( Arrays.asList( this.getCmds() ) );

// Formal paramenters
// Formal parameters
toret.formalParams = this.formalParams.clone();

// Slots for real parameters
Expand Down Expand Up @@ -153,60 +150,68 @@ public String[] getFormalParameters()
}

@Override
public String getMethodBodyAsString() {
Stack<String> stack = new Stack<>();
public String getMethodBodyAsString()
{
StringBuilder toret = new StringBuilder();

toret.append( "{" );
Stack<String> stack = new Stack<>();
ArrayList<Integer> positions = new ArrayList<>();

// Add params
for(String param: this.getFormalParameters()) {
toret.append( param );
toret.append( ' ' );
}

toret.append( "{ " );
toret.append( this.getFormalParametersAsString() );
toret.append( ": " );

// Add commands
for(Command cmd: this.getCmds()) {
String replaceCmd = "";
toret.append( cmd.toString() );
toret.append( "; " );
}
/*
// Add commands
for(Command cmd: this.getCmds()) {
String replaceCmd;
String cmdAsStr = cmd.toString();
int pos = cmdAsStr.indexOf( Parser.PopTask );
if ( pos >= 0 ) {
// Process the reference
if ( cmd.getReference().toString().equals( Parser.PopTask ) ) {
replaceCmd = stack.pop();
cmdAsStr = cmdAsStr.substring( 0, pos )
+ replaceCmd
+ cmdAsStr.substring( pos + Parser.PopTask.length(), cmdAsStr.length() );
// Find all POP occurrences
positions.clear();
int popPos = cmdAsStr.lastIndexOf( Parser.PopTask );
do {
while( popPos > -1 ) {
positions.add( popPos );
cmdAsStr.lastIndexOf( Parser.PopTask, popPos - Parser.PopTask.length() );
}
// Process possible targets
pos += replaceCmd.length();
pos = cmdAsStr.indexOf( Parser.PopTask, pos );
while( pos >= 0 ) {
for(int pos: positions) {
// Process possible targets
// pos += replaceCmd.length();
// pos = cmdAsStr.indexOf( Parser.PopTask, pos );
replaceCmd = stack.pop();
cmdAsStr = cmdAsStr.substring( 0, pos )
+ replaceCmd
+ cmdAsStr.substring( pos + Parser.PopTask.length(), cmdAsStr.length() );

// Next?
pos += replaceCmd.length();
pos = cmdAsStr.indexOf( Parser.PopTask, pos );
}
}
popPos = cmdAsStr.lastIndexOf( Parser.PopTask );
} while( popPos > -1 );
/*
// Process the reference
if ( cmd.getReference().toString().equals( Parser.PopTask ) ) {
replaceCmd = stack.pop();
cmdAsStr = cmdAsStr.substring( 0, popPos )
+ replaceCmd
+ cmdAsStr.substring( popPos + Parser.PopTask.length(), cmdAsStr.length() );
}
*/
/*
// Push command
stack.push( cmdAsStr );
}
// Dump the remaining
// Dump the remaining in natural order (nearly never executed)
for(String strCmd: stack) {
toret.append( strCmd );
toret.append( "; " );
}

*/
toret.append( "}" );
return toret.toString();
}
Expand All @@ -221,6 +226,7 @@ public static String createNewMethodId()
return toret;
}

@Override
public int getNumParams() {
return this.formalParams.length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
* Representing available methods in the interpreter
* @author baltasarq
/** Representing available methods in the interpreter
* @author baltasarq
*/
public abstract class NativeMethod extends Method {

Expand All @@ -26,9 +25,8 @@ public NativeMethod(com.devbaltasarq.pooi.core.Runtime rt, String name)
public abstract ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
throws InterpretError;

/**
* Copy the needed NativeMethod by means of reflection
* @return The copied method, as a Method object.
/** Copy the needed NativeMethod by means of reflection
* @return The copied method, as a Method object.
*/
@Override
public NativeMethod copy()
Expand All @@ -48,8 +46,12 @@ public NativeMethod copy()
return toret;
}

/** Return A textual representation of the method
* @return A string describing the method.
*/
@Override
public String getMethodBodyAsString() {
return "{: }";
public String getMethodBodyAsString()
{
return "{ " + this.getFormalParametersAsString() + ": }";
}
}
Loading

0 comments on commit 825caae

Please sign in to comment.