Skip to content

Commit

Permalink
Initial checkin of stdfunctions for String intrinsic support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 4, 2001
1 parent 5eeceda commit 5b742a4
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 0 deletions.
53 changes: 53 additions & 0 deletions last/toby/interpreter/stdfunctions/DrawString.java
@@ -0,0 +1,53 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class DrawString extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__drawString");
} // getFuncName

protected final int getParamCountImpl()
{
return(1);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str = globalContext.localFromTopOfStack(0).getStringValue();
tspace.drawString(str);
// _D("stdFuncExecuteImpl", "added turtle #(" + rc + ")...");
return(NothingIntrinsic.nothing);
} // executeImpl
} // DrawString

// end of DrawString.java ...


54 changes: 54 additions & 0 deletions last/toby/interpreter/stdfunctions/StrCat.java
@@ -0,0 +1,54 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.util.TobyLanguage;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class StrCat extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__strCat");
} // getFuncName

protected final int getParamCountImpl()
{
return(2);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str0 = globalContext.localFromTopOfStack(0).getStringValue();
String str1 = globalContext.localFromTopOfStack(1).getStringValue();

return(new StringIntrinsic(str0 + str1));
} // executeImpl
} // StrCat

// end of StrCat.java ...


57 changes: 57 additions & 0 deletions last/toby/interpreter/stdfunctions/StrLeft.java
@@ -0,0 +1,57 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.util.TobyLanguage;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class StrLeft extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__strLeft");
} // getFuncName

protected final int getParamCountImpl()
{
return(2);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str = globalContext.localFromTopOfStack(0).getStringValue();
int size = globalContext.localFromTopOfStack(1).getIntValue();

if ( (size < 0) || (size >= str.length()) )
ExecException._throw(TobyLanguage.OUT_OF_RANGE);

return(new StringIntrinsic(str.substring(0, size)));
} // stdFuncExecuteImpl
} // StrLeft

// end of StrLeft.java ...


53 changes: 53 additions & 0 deletions last/toby/interpreter/stdfunctions/StrLen.java
@@ -0,0 +1,53 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.util.TobyLanguage;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class StrLen extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__strLen");
} // getFuncName

protected final int getParamCountImpl()
{
return(1);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str = globalContext.localFromTopOfStack(0).getStringValue();

return(new NumberIntrinsic(str.length()));
} // stdFuncExecuteImpl
} // StrLen

// end of StrLen.java ...


52 changes: 52 additions & 0 deletions last/toby/interpreter/stdfunctions/StrLower.java
@@ -0,0 +1,52 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.util.TobyLanguage;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class StrLower extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__strLower");
} // getFuncName

protected final int getParamCountImpl()
{
return(1);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str = globalContext.localFromTopOfStack(0).getStringValue();
return(new StringIntrinsic(str.toLowerCase()));
} // stdFuncExecuteImpl
} // StrLower

// end of StrLower.java ...


57 changes: 57 additions & 0 deletions last/toby/interpreter/stdfunctions/StrRight.java
@@ -0,0 +1,57 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.util.TobyLanguage;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class StrRight extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__strRight");
} // getFuncName

protected final int getParamCountImpl()
{
return(2);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str = globalContext.localFromTopOfStack(0).getStringValue();
int size = globalContext.localFromTopOfStack(1).getIntValue();

if ( (size < 0) || (size >= str.length()) )
ExecException._throw(TobyLanguage.OUT_OF_RANGE);

return(new StringIntrinsic(str.substring(str.length() - size)));
} // stdFuncExecuteImpl
} // StrRight

// end of StrRight.java ...


52 changes: 52 additions & 0 deletions last/toby/interpreter/stdfunctions/StrUpper.java
@@ -0,0 +1,52 @@
/*
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package last.toby.interpreter.stdfunctions;

import last.toby.turtlespace.TurtleSpace;
import last.toby.util.TobyLanguage;
import last.toby.interpreter.*;
import last.toby.exceptions.*;

/**
* !!! comment me!
* @author Ryan C. Gordon.
*/
public class StrUpper extends StdFuncLogicContext
{
protected final String getFuncNameImpl()
{
return("__$STDFUNC$__strUpper");
} // getFuncName

protected final int getParamCountImpl()
{
return(1);
} // getFuncName

protected Intrinsic stdFuncExecuteImpl() throws FlowException
{
String str = globalContext.localFromTopOfStack(0).getStringValue();
return(new StringIntrinsic(str.toUpperCase()));
} // stdFuncExecuteImpl
} // StrUpper

// end of StrUpper.java ...


0 comments on commit 5b742a4

Please sign in to comment.