Skip to content

Commit

Permalink
Samples, polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Jan 15, 2018
1 parent 567c932 commit 9da5e60
Show file tree
Hide file tree
Showing 14 changed files with 1,305 additions and 1,398 deletions.
363 changes: 135 additions & 228 deletions .idea/workspace.xml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Building POOI
=============

**Pooi** was written using *IntelliJ IDEA*. The preferred method for building
the system is therefore using the IDE.
Building POOI
=============

**Pooi** was written using *IntelliJ IDEA*. The preferred method for building
the system is therefore using the IDE.
20 changes: 10 additions & 10 deletions samples/complex.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
> (anObject copy) rename "TraitsComplex"
> (anObject copy) rename "Complex"
> Complex.real = 0.0
> Complex.img = 0.0
> Complex.parent = TraitsComplex
> TraitsComplex.str = {: (((self.real str) + " + ") + (self.img str)) + "i" }
> TraitsComplex.isReal = {: self.img == 0.0 }
> TraitsComplex.add = {c: self.real = (self.real + c.real); self.img = (self.img + c.img) }
> TraitsComplex.sub = {c: self.real = (self.real - c.real); self.img = (self.img - c.img) }
> TraitsComplex.mul = {c: self.real = ((self.real * c.real) - (self.img * c.img)); self.img = ((self.img * c.real) + (self.real * c.img)) }
> (anObject copy) rename "TraitsComplex"
> (anObject copy) rename "Complex"
> Complex.real = 0.0
> Complex.img = 0.0
> Complex.parent = TraitsComplex
> TraitsComplex.str = {: (((self.real str) + " + ") + (self.img str)) + "i" }
> TraitsComplex.isReal = {: self.img == 0.0 }
> TraitsComplex.add = {c: self.real = (self.real + c.real); self.img = (self.img + c.img) }
> TraitsComplex.sub = {c: self.real = (self.real - c.real); self.img = (self.img - c.img) }
> TraitsComplex.mul = {c: self.real = ((self.real * c.real) - (self.img * c.img)); self.img = ((self.img * c.real) + (self.real * c.img)) }
130 changes: 65 additions & 65 deletions samples/init.txt
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
Pooi [Prototype-based, object-oriented interpreter]

type in your message
try "Root list", "help" or "about" to start


> (anObject copy) rename "Point"
anObject was copied into Root as 'Root.anObject1'
Root.anObject1 renamed to Root.Point


> (anObject copy) rename "TraitsPoint"
anObject was copied into Root as 'Root.anObject2'
Root.anObject2 renamed to Root.TraitsPoint


> Point.x = 0
'x' set in Root.Point


> Point.y = 0
'y' set in Root.Point


> (anObject copy) rename "Persona"
anObject was copied into Root as 'Root.anObject3'
Root.anObject3 renamed to Root.Persona


> Point.parent = TraitsPoint
'parent' set in Root.Point


> Persona.edad = 42
'edad' set in Root.Persona


> persona.nombre = "Baltasar Garc�a Perez-Schofield"
Error: Attribute not found: 'persona' in 'Root'

> Persona.nombre = "Baltasar Garc�a Perez-Schofield"
'nombre' set in Root.Persona


> (anObject copy) rename "TraitsPersona"
anObject was copied into Root as 'Root.anObject4'
Root.anObject4 renamed to Root.TraitsPersona


> Persona.parent = TraitsPersona
'parent' set in Root.Persona


> TraitsPoint.shift = {d: self.x = (self.x + d); self.y = (self.y + d)}
'shift' set in Root.TraitsPoint


> Point shift 5
Root.Point.x and Root.bin.lit16 added, giving 5
'x' set in Root.Point
Root.Point.y and Root.bin.lit19 added, giving 5
'y' set in Root.Point



Pooi [Prototype-based, object-oriented interpreter]
type in your message
try "Root list", "help" or "about" to start
> (anObject copy) rename "Point"
anObject was copied into Root as 'Root.anObject1'
Root.anObject1 renamed to Root.Point
> (anObject copy) rename "TraitsPoint"
anObject was copied into Root as 'Root.anObject2'
Root.anObject2 renamed to Root.TraitsPoint
> Point.x = 0
'x' set in Root.Point
> Point.y = 0
'y' set in Root.Point
> (anObject copy) rename "Persona"
anObject was copied into Root as 'Root.anObject3'
Root.anObject3 renamed to Root.Persona
> Point.parent = TraitsPoint
'parent' set in Root.Point
> Persona.edad = 42
'edad' set in Root.Persona
> persona.nombre = "Baltasar Garc�a Perez-Schofield"
Error: Attribute not found: 'persona' in 'Root'
> Persona.nombre = "Baltasar Garc�a Perez-Schofield"
'nombre' set in Root.Persona
> (anObject copy) rename "TraitsPersona"
anObject was copied into Root as 'Root.anObject4'
Root.anObject4 renamed to Root.TraitsPersona
> Persona.parent = TraitsPersona
'parent' set in Root.Persona
> TraitsPoint.shift = {d: self.x = (self.x + d); self.y = (self.y + d)}
'shift' set in Root.TraitsPoint
> Point shift 5
Root.Point.x and Root.bin.lit16 added, giving 5
'x' set in Root.Point
Root.Point.y and Root.bin.lit19 added, giving 5
'y' set in Root.Point
10 changes: 5 additions & 5 deletions samples/math.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
> (anObject copy) rename "Math"
> Math.PI = 3.1416
> Math.sqr = {x: x * x }
> Math.sqrt = {x: x * x }
>
> (anObject copy) rename "Math"
> Math.PI = 3.1416
> Math.sqr = {x: x * x }
> Math.sqrt = {x: x * x }
>
6 changes: 3 additions & 3 deletions samples/pair.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
> (anObject copy) rename "Pair"
> Pair.first = anObject
> Pair.second = anObject
> (anObject copy) rename "Pair"
> Pair.first = anObject
> Pair.second = anObject
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.Interpreter.InterpretError;

/**
* A method that extracts the time and stores it in a DateTime object.
* Created by Baltasar on 30/01/2016.
*/
public class NativeMethodOsExit extends NativeMethod {
public static final String EtqMthOsExit = "exit";

public NativeMethodOsExit(Runtime rt) {
super( rt, EtqMthOsExit );
}

@Override
public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
throws InterpretError
{
System.exit( 0 );
return null;
}

public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.Interpreter.InterpretError;

/**
* A method that extracts the time and stores it in a DateTime object.
* Created by Baltasar on 30/01/2016.
*/
public class NativeMethodOsExit extends NativeMethod {
public static final String EtqMthOsExit = "exit";

public NativeMethodOsExit(Runtime rt) {
super( rt, EtqMthOsExit );
}

@Override
public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
throws InterpretError
{
System.exit( 0 );
return null;
}

public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.Interpreter.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectDateTime;

import java.util.Calendar;

/**
* A method that extracts the time and stores it in a DateTime object.
* Created by Baltasar on 30/01/2016.
*/
public class NativeMethodOsNow extends NativeMethod {
public static final String EtqMthOsNow = "now";

public NativeMethodOsNow(Runtime rt) {
super( rt, EtqMthOsNow );
}

@Override
public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
throws InterpretError
{
final Calendar now = Calendar.getInstance();
final Runtime rt = this.getRuntime();

chkParametersNumber( 0, params );

// Create date-time object
final ObjectDateTime toret = rt.createDateTime(
now.get( Calendar.DAY_OF_MONTH ),
now.get( Calendar.MONTH ) + 1,
now.get( Calendar.YEAR ),
now.get( Calendar.HOUR ),
now.get( Calendar.MINUTE ),
now.get( Calendar.SECOND )
);

msg.append( "Obtained current date and time" );
return toret;
}

public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.Interpreter.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectDateTime;

import java.util.Calendar;

/**
* A method that extracts the time and stores it in a DateTime object.
* Created by Baltasar on 30/01/2016.
*/
public class NativeMethodOsNow extends NativeMethod {
public static final String EtqMthOsNow = "now";

public NativeMethodOsNow(Runtime rt) {
super( rt, EtqMthOsNow );
}

@Override
public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
throws InterpretError
{
final Calendar now = Calendar.getInstance();
final Runtime rt = this.getRuntime();

chkParametersNumber( 0, params );

// Create date-time object
final ObjectDateTime toret = rt.createDateTime(
now.get( Calendar.DAY_OF_MONTH ),
now.get( Calendar.MONTH ) + 1,
now.get( Calendar.YEAR ),
now.get( Calendar.HOUR ),
now.get( Calendar.MINUTE ),
now.get( Calendar.SECOND )
);

msg.append( "Obtained current date and time" );
return toret;
}

public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Loading

0 comments on commit 9da5e60

Please sign in to comment.