From 9330bc474a12944e4dcf668a60dac8d2244dc783 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 8 Jul 2004 23:02:59 +0000 Subject: [PATCH] new preproc work for int() et al on arrays.. routes through PApplet --- app/PdeCompiler.java | 2 +- app/PdePreprocessor.java | 19 ++++++------- build/shared/lib/preferences.txt | 28 +++++++++--------- core/.cvsignore | 1 + core/PApplet.java | 49 +++++++++++++++++++++++++++++++- todo.txt | 27 ++++++++++++++---- 6 files changed, 94 insertions(+), 32 deletions(-) create mode 100755 core/.cvsignore diff --git a/app/PdeCompiler.java b/app/PdeCompiler.java index c4b66557c..8b6dfbabb 100644 --- a/app/PdeCompiler.java +++ b/app/PdeCompiler.java @@ -88,7 +88,7 @@ public class PdeCompiler implements PdeMessageConsumer { // necessary to make output classes compatible with 1.1 // i.e. so that exported applets can work with ms jvm on the web "-target", - PdePreferences.get("compiler.jdk_version"), //"1.1", + PdePreferences.get("preproc.jdk_version"), //"1.1", // let the incompatability headache begin // used when run without a vm ("expert" mode) diff --git a/app/PdePreprocessor.java b/app/PdePreprocessor.java index 4581be406..76d5c9c56 100644 --- a/app/PdePreprocessor.java +++ b/app/PdePreprocessor.java @@ -59,11 +59,11 @@ public class PdePreprocessor { */ public PdePreprocessor() { defaultImports[JDK11] = - PApplet.split(PdePreferences.get("compiler.imports.jdk11"), ','); + PApplet.split(PdePreferences.get("preproc.imports.jdk11"), ','); defaultImports[JDK13] = - PApplet.split(PdePreferences.get("compiler.imports.jdk13"), ','); + PApplet.split(PdePreferences.get("preproc.imports.jdk13"), ','); defaultImports[JDK14] = - PApplet.split(PdePreferences.get("compiler.imports.jdk14"), ','); + PApplet.split(PdePreferences.get("preproc.imports.jdk14"), ','); } @@ -79,14 +79,13 @@ public class PdePreprocessor { */ public String write(String program, String buildPath, String name, String extraImports[]) throws java.lang.Exception { - // if the program ends with a comment, and no CR or LF - // an OutOfMemoryError will happen.. not gonna track down the - // bug now, so here's a hack for it: - if (program.endsWith("//")) { + // if the program ends with no CR or LF an OutOfMemoryError will happen. + // not gonna track down the bug now, so here's a hack for it: + if (program.charAt(program.length()-1) != '\n') { program += "\n"; } - if (PdePreferences.getBoolean("compiler.substitute_unicode")) { + if (PdePreferences.getBoolean("preproc.substitute_unicode")) { // check for non-ascii chars (these will be/must be in unicode format) char p[] = program.toCharArray(); int unicodeCount = 0; @@ -204,7 +203,7 @@ public class PdePreprocessor { // if desired, serialize the parse tree to an XML file. can // be viewed usefully with Mozilla or IE - if (PdePreferences.getBoolean("compiler.output_parse_tree")) { + if (PdePreferences.getBoolean("preproc.output_parse_tree")) { stream = new PrintStream(new FileOutputStream("parseTree.xml")); stream.println(""); @@ -244,7 +243,7 @@ public class PdePreprocessor { // emit standard imports (read from pde.properties) // for each language level that's being used. - String jdkVersionStr = PdePreferences.get("compiler.jdk_version"); + String jdkVersionStr = PdePreferences.get("preproc.jdk_version"); int jdkVersion = JDK11; // default if (jdkVersionStr.equals("1.3")) { jdkVersion = JDK13; }; diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt index 0cb392a4d..da77fe30c 100755 --- a/build/shared/lib/preferences.txt +++ b/build/shared/lib/preferences.txt @@ -169,40 +169,40 @@ history.recording = true export.library = false # may be useful when attempting to debug the preprocessor -compiler.save_build_files=false +preproc.save_build_files=false # allows various preprocessor features to be toggled # in case they are causing problems # preprocessor: pde.g -compiler.color_datatype = true -compiler.web_colors = true -compiler.enhanced_casting = true +preproc.color_datatype = true +preproc.web_colors = true +preproc.enhanced_casting = true # preprocessor: PdeEmitter.java -compiler.substitute_floats = true -compiler.substitute_image = false -compiler.substitute_font = false +preproc.substitute_floats = true +#preproc.substitute_image = false +#preproc.substitute_font = false # auto-convert non-ascii chars to unicode escape sequences -compiler.substitute_unicode = true +preproc.substitute_unicode = true -# PdeCompiler.java +# PdePreproc.java # writes out the parse tree as parseTree.xml, which can be usefully # viewed in (at least) Mozilla or IE. useful when debugging the preprocessor. -compiler.output_parse_tree = false +preproc.output_parse_tree = false # jdk version to use.. -compiler.jdk_version = 1.1 +preproc.jdk_version = 1.1 # base imports to include for java 1.1 (or higher) -compiler.imports.jdk11 = java.applet,java.awt,java.awt.image,java.awt.event,java.io,java.net,java.text,java.util,java.util.zip,netscape.javascript +preproc.imports.jdk11 = java.applet,java.awt,java.awt.image,java.awt.event,java.io,java.net,java.text,java.util,java.util.zip,netscape.javascript # additional imports when exporting to java 1.3 or higher -compiler.imports.jdk13 = javax.sound.midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi +preproc.imports.jdk13 = javax.sound.midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi # additional imports when exporting to java 1.4 or higher -compiler.imports.jdk14 = javax.xml.parsers,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stream,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers +preproc.imports.jdk14 = javax.xml.parsers,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stream,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers # set the browser to be used on linux browser.linux = mozilla \ No newline at end of file diff --git a/core/.cvsignore b/core/.cvsignore new file mode 100755 index 000000000..0c07f9a60 --- /dev/null +++ b/core/.cvsignore @@ -0,0 +1 @@ +processing diff --git a/core/PApplet.java b/core/PApplet.java index 152c2bbce..177e8b438 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -1534,9 +1534,13 @@ public class PApplet extends Applet * Wrapper for tedious Integer.parseInt function */ static public int toInt(String what) { - return toInt(what, 0); + try { + return Integer.parseInt(what); + } catch (NumberFormatException e) { } + return 0; } + /** * Wrapper for tedious Integer.parseInt function */ @@ -1562,6 +1566,7 @@ public class PApplet extends Applet return toInt(what, 0); } + /** * Make an array of int elements from an array of String objects. * If the String can't be parsed as a number, its entry in the @@ -1585,6 +1590,26 @@ public class PApplet extends Applet } + /** + * Cast a float to an int. + */ + static public int toInt(float what) { + return (int) what; + } + + + /** + * Create an array of ints that correspond to an array of floats. + */ + static public int[] toInt(float what[]) { + int inties[] = new int[what.length]; + for (int i = 0; i < what.length; i++) { + inties[i] = (int)what[i]; + } + return inties; + } + + /** * Wrapper for tedious new Float(string).floatValue(). */ @@ -1607,6 +1632,27 @@ public class PApplet extends Applet } + /** + * Cast an int to a float. + */ + static public float toFloat(int what) { + return (float)what; + } + + + /** + * Create an array of ints that correspond to an array of floats. + */ + static public float[] toFloat(int what[]) { + float floaties[] = new float[what.length]; + for (int i = 0; i < what.length; i++) { + //floaties[i] = (float)what[i]; + floaties[i] = what[i]; + } + return floaties; + } + + /** * Convert an array of Strings into an array of floats. * See the documentation for toInt(). @@ -1615,6 +1661,7 @@ public class PApplet extends Applet return toFloat(what, 0); } + /** * Convert an array of Strings into an array of floats. * See the documentation for toInt(). diff --git a/todo.txt b/todo.txt index 6421801f8..9dcab15b8 100644 --- a/todo.txt +++ b/todo.txt @@ -228,28 +228,39 @@ X ask creas about src or dest in image functions X finish imaging api X modify make.sh to build processing.core -040708 afternoon +040708 afternoon / early evening X lots of work on making packaged classes work X modify preproc to handle "void setup" -> "public void setup" o preproc bug: text(String.valueOf(i+1), left + i*20, top); o unexpected token "String" +X make more things public (i.e. pixels) +X get casting working properly.. int() maps to toInt()? +X what is performance hit for this thing? +X remove substitute_image/font +X remove String casting +X rename compiler.* to preproc.* +X OutOfMemoryError still showing up when no CR at end of app -OutOfMemoryError still showing up when no CR at end of app +040708 evening + +_ get export working again +_ make multiple jar files thing work.. blech -_ casting working properly.. int() maps to toInt()? -_ what is performance hit for this thing? _ processing.app -> PdeBase, PdeEditor.. _ processing.serial -> PSerial, [PUsb] _ processing.video -> PMovie (file), PCamera (capture) _ processing.net -> PClient, PServer _ rewrite video, net, serial libraries to be separate + +...................................................................... + +NOT REQUIRED FOR NEXT RELEASE + _ expand/subset for array operations (floats, ints, Strings) _ see if reflection will allow expand for all class types _ append/unappend (no push/pop), shift/unshift, _ slice, splice, reverse, concat, split - -not necessarily before release _ check into open-source paperwork for p5 _ prefs need to have a default _ otherwise old prefs and new p5 will cause trouble @@ -467,6 +478,10 @@ _ need curveTangent() code .................................................................. +TABLED FOR LATER (qasey's quagmires) +_ completeness of toInt/toFloat/toBoolean etc in preproc and PApplet + + LOWER (post beta tweaks, non-structural) 1 _ Ctrl-Z will undo, but the window will not scroll to where the 1 _ "undoing" is happening. This can lead the user to assume that