Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial checkin of stdfunctions for String intrinsic support.
- Loading branch information
Showing
8 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
||
|
Oops, something went wrong.