[guru-lang] r531 committed - I split the release function into release_clear (could be in a cycle i...

1 view
Skip to first unread message

guru...@googlecode.com

unread,
Aug 14, 2011, 1:38:03 PM8/14/11
to guru...@googlegroups.com
Revision: 531
Author: aaron.stump
Date: Sun Aug 14 10:36:45 2011
Log: I split the release function into release_clear (could be in a
cycle in the call graph) and release_no_clear (cannot be in such a cycle),
and pushed the compiler to inline the calls to release_no_clear; this
resulted in about a 30 percent speedup on the eq.atree.braun.7.unsat.cnf
medium-level benchmark
http://code.google.com/p/guru-lang/source/detail?r=531

Modified:
/branches/1.0/guru/Compile.java
/branches/1.0/guru/carraway/Command.java
/branches/1.0/guru/carraway/Context.java
/branches/1.0/guru/carraway/Datatype.java
/branches/1.0/guru/carraway/Include.java
/branches/1.0/guru/carraway/Main.java
/branches/1.0/guru/carraway/Parser.java
/branches/1.0/guru/carraway/ResourceType.java
/branches/1.0/lib/unique.g
/branches/1.0/lib/unowned.g

=======================================
--- /branches/1.0/guru/Compile.java Thu Apr 21 19:37:47 2011
+++ /branches/1.0/guru/Compile.java Sun Aug 14 10:36:45 2011
@@ -456,7 +456,7 @@

copy_needed_init_cmds(ctxt,trans_ctxt);

- guru.carraway.Context cctxt = new guru.carraway.Context(".g");
+ guru.carraway.Context cctxt = new guru.carraway.Context();
trans_ctxt.carraway_ctxt = cctxt;
cctxt.copyFlags(trans_ctxt);

@@ -475,7 +475,7 @@

Collection resource_decls = cmds_for_resource_types(trans_ctxt, cctxt);

- cctxt.setFile(ifile);
+ cctxt.initOutputFiles(ifile);

guru.carraway.Command cmd;

=======================================
--- /branches/1.0/guru/carraway/Command.java Fri Jun 19 12:18:59 2009
+++ /branches/1.0/guru/carraway/Command.java Sun Aug 14 10:36:45 2011
@@ -12,7 +12,7 @@

public static final int SET = 6;
public static final int UNSET = 7;
- public static final int INCLUDE = 8;
+ //public static final int INCLUDE = 8;
public static final int INIT = 9;
public static final int TYPEDEF = 10;

=======================================
--- /branches/1.0/guru/carraway/Context.java Thu Apr 21 19:37:47 2011
+++ /branches/1.0/guru/carraway/Context.java Sun Aug 14 10:36:45 2011
@@ -28,17 +28,14 @@
protected HashMap dels;
protected HashSet not_consumed;

-
protected HashMap refs;
protected Vector changed_refs;
protected Stack refs_stack;
protected Stack changed_refs_stack;
protected int refnum;

- public PrintStream cw;
- public String file_suffix;
- public Stack open_files;
-
+ public PrintStream cw; // for main output
+ public PrintStream cw2; // for output related to release_no_clear
Sym voidref;
Sym returnf;
Sym zerof;
@@ -54,8 +51,7 @@

protected Vector new_typedefs;

- public Context(String file_suffix) {
- this.file_suffix = file_suffix;
+ public Context() {
consts = new HashMap(256);
vars = new HashMap(256);
globals = new HashMap(256);
@@ -90,7 +86,6 @@
global_inits = new Vector();

cw = null;
- open_files = new Stack();

stage = 0;
type_num = 1; // we assume elsewhere that this is 1
@@ -98,71 +93,22 @@
new_typedefs = new Vector();
}

- // set the file for emitted code. Do not mix with pushFile().
- public String setFile(java.io.File f) {
+ public String initOutputFiles(java.io.File f) {
+ java.io.File r = new java.io.File(f.getParentFile()
+ "/release_no_clear.c");
try {
cw = new PrintStream(new BufferedOutputStream(new
FileOutputStream(f)));
+ cw2 = new PrintStream(new BufferedOutputStream(new
FileOutputStream(r)));
}
catch(FileNotFoundException e) {
- return new String("Could not open the included file.");
- }
- if (getFlag("output_ocaml"))
- cw.println("(* produced by carraway *)\n");
- else {
- cw.println("// produced by carraway\n");
- cw.println("#include <stdio.h>\n");
- cw.println("#include <stdlib.h>\n");
- }
- return null;
- }
-
-
- // return an error message if there was a problem opening the compiler
output file determined by f.
- public String pushFile(String f) {
- if (f.length() < 3)
- return new String("The included file name is too short.");
- String suf = f.substring(f.length() - 2, f.length());
- if (!suf.equals(file_suffix))
- return new String("The included file does not end with the expected
suffix."
- +"\n\n1. the expected suffix: "+file_suffix
- +"\n\n2. the file name: "+f);
-
- String new_suf = (getFlag("output_ocaml") ? ".ml" : ".c");
- String n = f.substring(0, f.length() - 2) + new_suf;
-
- if (cw != null) {
- if (getFlag("output_ocaml"))
- cw.println("(* Including "+n+" *)");
- else
- cw.println("#include \""+n+"\"");
- cw.flush();
- }
- if (!getFlag("output_ocaml") || cw == null) {
- open_files.push(cw);
- try {
- cw = new PrintStream(new BufferedOutputStream(new FileOutputStream(n)));
- }
- catch(FileNotFoundException e) {
- return new String("Could not open the included file.");
- }
- if (getFlag("output_ocaml"))
- cw.println("(* produced by carraway *)\n");
- else {
- cw.println("// produced by carraway\n");
- cw.println("#include <stdio.h>\n");
- cw.println("#include <stdlib.h>\n");
- }
- }
-
+ return new String("Could not open files for writing during
compilation.");
+ }
+
+ cw.println("// produced by carraway\n");
+ cw.println("#include <stdio.h>\n");
+ cw.println("#include <stdlib.h>\n");
+
return null;
}
-
- public void popFile() {
- if (!getFlag("output_ocaml")) {
- cw.close();
- cw = (PrintStream)open_files.pop();
- }
- }

public void commentBox(String s) {
if (getFlag("output_ocaml"))
=======================================
--- /branches/1.0/guru/carraway/Datatype.java Sat Aug 13 19:26:21 2011
+++ /branches/1.0/guru/carraway/Datatype.java Sun Aug 14 10:36:45 2011
@@ -66,7 +66,9 @@
ctxt.stage = 3;

if (!ctxt.getFlag("output_ocaml"))
- ctxt.cw.println("#define "+tp.toString(ctxt)+" "+(new
Integer(ctxt.type_num++)).toString()+"\n");
+ // this goes in the release_no_clear.c file because both
release_no_clear dependents and
+ // release dependents need it
+ ctxt.cw2.println("#define "+tp.toString(ctxt)+" "+(new
Integer(ctxt.type_num++)).toString()+"\n");

if (del == null) {

@@ -106,19 +108,20 @@
// emit definition of tags for ctors

for (int i = 0; i < num_ctors; i++)
- ctxt.cw.println("#define
op_"+ctors[i].toString(ctxt)+" "+(new Integer(i)).toString()+"\n");
+ ctxt.cw2.println("#define
op_"+ctors[i].toString(ctxt)+" "+(new Integer(i)).toString()+"\n");

if (num_untracked == num_ctors) {
// this is a special case, since we do no allocation
or deallocation

for (int i = 0; i < num_ctors; i++) {
String ctr = ctors[i].toString(ctxt);
- ctxt.cw.println("#define "+ctr+"() op_"+ctr);
- ctxt.cw.println("#define
clear_"+tpstr+"_"+ctr+"(x) \n");
+ ctxt.cw2.println("#define "+ctr+"() op_"+ctr);
+ ctxt.cw2.println("#define
clear_"+tpstr+"_"+ctr+"(x) \n");
}

- ctxt.cw.println("#define delete_"+tpstr+"(x,clear)
\n");
- ctxt.cw.flush();
+ ctxt.cw.println("#define delete_"+tpstr+"_clear(x)
\n");
+ ctxt.cw2.println("#define delete_"+tpstr+"_no_clear(x)
\n");
+ ctxt.cw2.flush();
return;
}

@@ -138,26 +141,26 @@
process_new_typedefs(ctxt);
jend = R.vars.length;
}
- ctxt.cw.println("typedef struct {");
- ctxt.cw.println(" int opval;");
+ ctxt.cw2.println("typedef struct {");
+ ctxt.cw2.println(" int opval;");

if (R != null)
for (int j = 0; j < jend; j++) {
- F.types[j].print(ctxt.cw,ctxt);
-
ctxt.cw.println(" "+R.vars[j].toString(ctxt)+";");
+ F.types[j].print(ctxt.cw2,ctxt);
+
ctxt.cw2.println(" "+R.vars[j].toString(ctxt)+";");
}

String ctor_tp = tpstr+"_"+ctors[i].toString(ctxt);
- ctxt.cw.println("} "+ctor_tp+";\n");
+ ctxt.cw2.println("} "+ctor_tp+";\n");

// emit selectors for the ctor's struct

if (R != null) {
for (int j = 0; j < jend; j++) {
- ctxt.cw.print("#define
select_"+tp.name+"_"+ctors[i].name+"_"+R.vars[j].name+"(x) ");
- ctxt.cw.println("((("+ctor_tp+"
*)x)->"+R.vars[j].toString(ctxt)+")");
- }
- ctxt.cw.println("");
+ ctxt.cw2.print("#define
select_"+tp.name+"_"+ctors[i].name+"_"+R.vars[j].name+"(x) ");
+ ctxt.cw2.println("((("+ctor_tp+"
*)x)->"+R.vars[j].toString(ctxt)+")");
+ }
+ ctxt.cw2.println("");
}

String fl = "free_"+ctor_tp;
@@ -167,7 +170,7 @@

if (R == null)
// nothing to clear for 0-ary ctor
- ctxt.cw.println("#define clear_"+ctor_tp+"(x) \n");
+ ctxt.cw2.println("#define clear_"+ctor_tp+"(x)
\n");
else {
ctxt.cw.println("inline void
clear_"+ctor_tp+"(void *_x) {");
ctxt.cw.println(" "+ctor_tp+" *x = ("+ctor_tp+"
*)_x;");
@@ -187,37 +190,36 @@
ctxt.cw.println("}\n");
}

- // emit the free list and delete function
-
- ctxt.cw.println("int "+fl+"_len = 0;");
- ctxt.cw.println("void *"+fl+" = (void *)0;\n");
+ // emit the free list and delete functions
(delete_clear and delete_no_clear)
+
ctxt.cw.println("int "+cfl+"_len = 0;");
ctxt.cw.println("void *"+cfl+" = (void *)0;\n");
- ctxt.cw.println("void delete_"+ctor_tp+"(void *_x, int
clear) {");
- ctxt.cw.println(" if (clear) {");
- ctxt.cw.println(" if ("+cfl+"_len
> "+FREE_LIST_MAX+") {");
- ctxt.cw.println(" clear_"+ctor_tp+"(_x);");
- ctxt.cw.println(" carraway_free(_x);");
- ctxt.cw.println(" }");
- ctxt.cw.println(" else {");
- ctxt.cw.println(" void **x = (void **)_x;");
- ctxt.cw.println(" x[0] = "+cfl+";");
- ctxt.cw.println(" "+cfl+" = x;");
- ctxt.cw.println(" "+cfl+"_len++;");
- ctxt.cw.println(" }");
+ ctxt.cw.println("void delete_"+ctor_tp+"_clear(void
*_x) {");
+ ctxt.cw.println(" if ("+cfl+"_len
> "+FREE_LIST_MAX+") {");
+ ctxt.cw.println(" clear_"+ctor_tp+"(_x);");
+ ctxt.cw.println(" carraway_free(_x);");
ctxt.cw.println(" }");
ctxt.cw.println(" else {");
- ctxt.cw.println(" if ("+fl+"_len
> "+FREE_LIST_MAX+") ");
- ctxt.cw.println(" carraway_free(_x);");
- ctxt.cw.println(" else {");
- ctxt.cw.println(" void **x = (void **)_x;");
- ctxt.cw.println(" x[0] = "+fl+";");
- ctxt.cw.println(" "+fl+" = x;");
- ctxt.cw.println(" "+fl+"_len++;");
- ctxt.cw.println(" }");
+ ctxt.cw.println(" void **x = (void **)_x;");
+ ctxt.cw.println(" x[0] = "+cfl+";");
+ ctxt.cw.println(" "+cfl+" = x;");
+ ctxt.cw.println(" "+cfl+"_len++;");
ctxt.cw.println(" }");
ctxt.cw.println("}\n");

+ ctxt.cw2.println("int "+fl+"_len = 0;");
+ ctxt.cw2.println("void *"+fl+" = (void *)0;\n");
+ ctxt.cw2.println("void
delete_"+ctor_tp+"_no_clear(void *_x) {");
+ ctxt.cw2.println(" if ("+fl+"_len
> "+FREE_LIST_MAX+") ");
+ ctxt.cw2.println(" carraway_free(_x);");
+ ctxt.cw2.println(" else {");
+ ctxt.cw2.println(" void **x = (void **)_x;");
+ ctxt.cw2.println(" x[0] = "+fl+";");
+ ctxt.cw2.println(" "+fl+" = x;");
+ ctxt.cw2.println(" "+fl+"_len++;");
+ ctxt.cw2.println(" }");
+ ctxt.cw2.println("}\n");
+
// emit function to build data

ctxt.cw.print("void *"+ctors[i].toString(ctxt)+"(");
@@ -259,22 +261,32 @@

}

- // now emit the delete function for the datatype
-
- ctxt.cw.println("void delete_"+tpstr+"(void *x, int clear)
{");
- ctxt.cw.println(" switch ctor(x) {");
- for (int i = 0; i < num_ctors; i++) {
- String ctr = ctors[i].toString(ctxt);
- ctxt.cw.println(" case op_"+ctr+": ");
- ctxt.cw.println("
delete_"+tpstr+"_"+ctr+"(x,clear);");
- ctxt.cw.println(" break;\n");
- }
- ctxt.cw.println("}");
- ctxt.cw.println("}\n");
+ // now emit the delete functions for the datatype
+
+ emitDeleteFunction(ctxt,tpstr,true);
+ emitDeleteFunction(ctxt,tpstr,false);
}
ctxt.cw.flush();
}
}
+
+ protected void emitDeleteFunction(Context ctxt, String tpstr, boolean
clear) {
+ java.io.PrintStream cw = clear ? ctxt.cw : ctxt.cw2;
+
+ String clear_str = clear ? "_clear" : "_no_clear";
+
+ cw.println("void delete_"+tpstr+clear_str+"(void *x) {");
+ cw.println(" switch ctor(x) {");
+ for (int i = 0, num_ctors = ctors.length; i < num_ctors; i++) {
+ String ctr = ctors[i].toString(ctxt);
+ cw.println(" case op_"+ctr+": ");
+ cw.println(" delete_"+tpstr+"_"+ctr+clear_str+"(x);");
+ cw.println(" break;\n");
+ }
+ cw.println("}");
+ cw.println("}\n");
+ cw.flush();
+ }

public void print(java.io.PrintStream w, Context ctxt) {
w.print("Datatype ");
=======================================
--- /branches/1.0/guru/carraway/Include.java Sat Aug 13 19:26:21 2011
+++ /branches/1.0/guru/carraway/Include.java Sun Aug 14 10:36:45 2011
@@ -7,80 +7,99 @@
import java.util.Collection;
import java.util.Iterator;

-public class Include extends Command {
- protected IncludeHelper h;
- public boolean the_cmd_line_file;
-
+public class Include {
public static int MAX_RELEASE_CALL_DEPTH = 1024;

- public Include(String filename, boolean the_cmd_line_file) {
- super(INCLUDE);
- h = new IncludeHelper(filename);
- this.the_cmd_line_file = the_cmd_line_file;
- }
-
- public Include(File f, File root) {
- super(INCLUDE);
- h = new IncludeHelper(f,root);
- the_cmd_line_file = false;
- }
-
public static void start_emit(Context ctxt) {
- ctxt.cw.println("void release(int tp, void *x, int clear);\n");
ctxt.cw.println("void *carraway_malloc(int x) { return malloc(x); }");
ctxt.cw.println("void carraway_free(void *x) { free(x); }");
ctxt.cw.println("#define guru_malloc(x) carraway_malloc(x)");
ctxt.cw.println("#define guru_free(x) carraway_free(x)");
-
+ ctxt.cw.println("void release_clear(int tp, void *x);\n\n");
+
+ if (!ctxt.getFlag("output_ocaml"))
+ ctxt.cw.println("#include <limits.h>\n\n"
+ +"#define ctor(x) (*((int *)x) & 255)\n"
+ +"#define op(x) (*((int *)x))\n\n"
+ +"void inc(void *x) {\n"
+ +" unsigned tmp = *((int *)x) | 255;\n"
+ +" if (tmp != UINT_MAX) *((int *)x) = *((int *)x) + 256;\n"
+ +"}\n\n"
+ +"void dec(void *x) {\n"
+ +" unsigned tmp = *((int *)x) | 255;\n"
+ +" if (tmp != UINT_MAX) *((int *)x) = *((int *)x) - 256;\n"
+ +"}\n");
+
+ ctxt.cw.println("#include \"release_no_clear.c\"\n\n");
+
ctxt.cw.flush();
}
+
+ protected static void emit_release_switch_statement(Context ctxt,
boolean clear, String eol) {
+ java.io.PrintStream cw = clear ? ctxt.cw : ctxt.cw2;
+
+ String clear_str = clear ? "_clear" : "_no_clear";
+
+ Collection opaque_dtps = ctxt.getOpaqueDatatypes();
+ Collection ind_dtps = ctxt.getInductiveDatatypes();
+
+ cw.println("switch (tp) {"+eol);
+
+ Iterator it = null;
+
+ if (clear) {
+ it = opaque_dtps.iterator();
+ while (it.hasNext()) {
+ Sym tp = (Sym)it.next();
+ cw.println("
case "+tp.toString(ctxt)+": "+ctxt.getDeleteFunction(tp).toString(ctxt)+"(x);
break;"+eol);
+ }
+ }
+ // we do not delete primitive types when releasing but not clearing
+
+ it = ind_dtps.iterator();
+ while (it.hasNext()) {
+ Sym tp = (Sym)it.next();
+ String tpstr = tp.toString(ctxt);
+ cw.println(" case "+tpstr+": delete_"+tpstr+clear_str+"(x);
break;"+eol);
+ }
+ cw.println("}"+eol);
+ cw.flush();
+ }

public static void finish_emit(Context ctxt) {
- // define release()
+ // define release() and release_no_clear()

ctxt.stage = 3;

- Collection opaque_dtps = ctxt.getOpaqueDatatypes();
- Collection ind_dtps = ctxt.getInductiveDatatypes();
+ // ctxt.cw2.println("inline void release_no_clear(int tp, void *x) {\n");
+ ctxt.cw2.println("#define release_no_clear(tp, x) do {\\");
+ emit_release_switch_statement(ctxt,false,"\\");
+ ctxt.cw2.println("} while(0)\n\n");

ctxt.cw.println("void **release_worklist = 0;");
ctxt.cw.println("int release_call_depth = 0;");
ctxt.cw.println("");
- ctxt.cw.println("void release(int tp, void *x, int clear) {");
+ ctxt.cw.println("void release_clear(int tp, void *x) {");
ctxt.cw.println("int worklist_initially_empty;\n"+
"void **node;\n"+
"if (release_call_depth > "+MAX_RELEASE_CALL_DEPTH+") {\n"+
" // we must queue this release request\n"+
- " node = guru_malloc(4*sizeof(void *));\n"+
+ " node = guru_malloc(3*sizeof(void *));\n"+
" node[0] = tp;\n"+
- " node[1] = clear;\n"+
- " node[2] = x;\n"+
- " node[3] = release_worklist;\n"+
+ " node[1] = x;\n"+
+ " node[2] = release_worklist;\n"+
" release_worklist = node;\n"+
" return;\n"+
"}\n"+
"\n"+
"release_call_depth++;\n"+
"do {\n");
- ctxt.cw.println("switch (tp) {");
- Iterator it = opaque_dtps.iterator();
- while (it.hasNext()) {
- Sym tp = (Sym)it.next();
- ctxt.cw.println("
case "+tp.toString(ctxt)+": "+ctxt.getDeleteFunction(tp).toString(ctxt)+"(x);
break;");
- }
- it = ind_dtps.iterator();
- while (it.hasNext()) {
- Sym tp = (Sym)it.next();
- String tpstr = tp.toString(ctxt);
- ctxt.cw.println(" case "+tpstr+": delete_"+tpstr+"(x,clear);
break;");
- }
- ctxt.cw.println("}");
+ emit_release_switch_statement(ctxt,true,"");
ctxt.cw.println("if (release_worklist) {\n"+
" node = release_worklist;\n"+
" tp = node[0];\n"+
- " clear = node[1];\n"+
- " x = node[2];\n"+
- " release_worklist = node[3];\n"+
+ " x = node[1];\n"+
+ " release_worklist = node[2];\n"+
" carraway_free(node);\n"+
"}\n"+
"else\n"+
@@ -92,7 +111,7 @@
// write main() to call all the inits.

Collection inits = ctxt.getGlobalInits();
- it = inits.iterator();
+ Iterator it = inits.iterator();
ctxt.cw.println("int main(int argc, char **argv) {");

while(it.hasNext()) {
@@ -102,68 +121,8 @@
ctxt.cw.println("return 0;");
ctxt.cw.println("}\n");
ctxt.cw.flush();
+ ctxt.cw2.flush();
}

- public void process(Context ctxt) {
- String err = h.process(ctxt);
-
- if (err != null)
- handleError(ctxt,err);
-
- pos = new Position(0,0,h.f.getName());
-
- if (h.included)
- // we have already included this file
- return;
-
- Parser P = new Parser(false);
-
- try {
- String s = h.ifile.getPath();
- P.openFile(s);
- String err1 = ctxt.pushFile(s);
- if (err1 != null)
- handleError(ctxt, err1);
- }
- catch (Exception e) {
- handleError(ctxt, "Error opening file:\n"+e.toString());
- }
- P.setContext(ctxt);
-
- Command c = null;
-
- // initial declarations go in the top-level output file
-
- if (the_cmd_line_file && !ctxt.getFlag("output_ocaml"))
- start_emit(ctxt);
-
- while(true) {
- try {
- c = P.readCommand();
- }
- catch (Exception e) {
- e.printStackTrace();
- handleError(ctxt, "Error reading file:\n"+e.toString());
- }
-
- if (c == null)
- break;
- c.process(ctxt);
- if (ctxt.getFlag("print_parsed")) {
- c.print(ctxt.w, ctxt);
- ctxt.w.println("");
- ctxt.w.flush();
- }
- }
- if (the_cmd_line_file)
- finish_emit(ctxt);
-
- ctxt.popFile();
- h.finished(ctxt);
- }
-
- public void print(java.io.PrintStream w,
- Context ctxt) {
- if (h.included) w.println("Include \"" + h.ifile.getPath() + "\".");
- }
-}
+
+}
=======================================
--- /branches/1.0/guru/carraway/Main.java Wed Apr 1 14:01:16 2009
+++ /branches/1.0/guru/carraway/Main.java Sun Aug 14 10:36:45 2011
@@ -6,7 +6,7 @@

public static void main(String[] args)
{
- Context ctxt = new Context(".w");
+ Context ctxt = new Context();

boolean processed_one = false;

@@ -22,8 +22,10 @@
System.out.println("Command-line error: multiple input files were
given on the command line.\n");
System.exit(1);
}
- Include cmd = new Include(args[i], true);
- cmd.process(ctxt);
+ // Include cmd = new Include(args[i], true);
+ // cmd.process(ctxt);
+ System.out.println("Direct compilation for carraway is currently
disabled. Please go through Guru.\n");
+ System.exit(1);
}
}
}
=======================================
--- /branches/1.0/guru/carraway/Parser.java Tue Sep 8 07:28:12 2009
+++ /branches/1.0/guru/carraway/Parser.java Sun Aug 14 10:36:45 2011
@@ -54,8 +54,8 @@
c = readSet();
else if (tryToEat("Unset"))
c = readUnset();
- else if (tryToEat("Include"))
- c = readInclude();
+ /* else if (tryToEat("Include"))
+ c = readInclude(); */
else
handleError("Unexpected start of a command.");
c.pos = pos;
@@ -177,14 +177,14 @@
return s;
}

- protected Include readInclude() throws IOException
+ /*protected Include readInclude() throws IOException
{
if (!eat_ws())
handleError("Unexpected end of input parsing a Include.");
Include cmd = new Include(new File(readString()), root);
eat(".", "Include");
return cmd;
- }
+ }*/

static public Sym[] toSymArray(ArrayList a) {
int iend = a.size();
=======================================
--- /branches/1.0/guru/carraway/ResourceType.java Mon Jan 11 18:23:37 2010
+++ /branches/1.0/guru/carraway/ResourceType.java Sun Aug 14 10:36:45 2011
@@ -5,8 +5,6 @@

public Primitive drop;

- protected static boolean first_attribute = true;
-
public ResourceType() {
super(ATTRIBUTE);
}
@@ -51,23 +49,6 @@
else
ctxt.addResourceType(s);

- if (first_attribute) {
- if (!ctxt.getFlag("output_ocaml")) {
- ctxt.cw.println("#include <limits.h>\n\n"
- +"#define ctor(x) (*((int *)x) & 255)\n"
- +"#define op(x) (*((int *)x))\n\n"
- +"void inc(void *x) {\n"
- +" unsigned tmp = *((int *)x) | 255;\n"
- +" if (tmp != UINT_MAX) *((int *)x) = *((int *)x) + 256;\n"
- +"}\n\n"
- +"void dec(void *x) {\n"
- +" unsigned tmp = *((int *)x) | 255;\n"
- +" if (tmp != UINT_MAX) *((int *)x) = *((int *)x) - 256;\n"
- +"}\n");
- ctxt.cw.flush();
- }
- first_attribute = false;
- }
if (drop != null)
drop.process(ctxt);
}
=======================================
--- /branches/1.0/lib/unique.g Fri Aug 12 06:47:43 2011
+++ /branches/1.0/lib/unique.g Sun Aug 14 10:36:45 2011
@@ -4,12 +4,12 @@
Define primitive consume_unique : Fun(A:type)(^#unique x:A).void
:= fun(A:type)(x:A).voidi <<END
inline void gconsume_unique(int A, void *x) {
- release(A,x,1);
+ release_clear(A,x);
}

- inline void gconsume_unique__match(int A, void *x) {
- release(A,x,0); // we have already taken ownership of subdata when
pattern-matching
- }
+ #define gconsume_unique__match(A, x) release_no_clear(A,x)
+ // we have already taken ownership of subdata when pattern-matching
+
END.

% for unique things consuming no memory
=======================================
--- /branches/1.0/lib/unowned.g Sat Aug 13 19:26:21 2011
+++ /branches/1.0/lib/unowned.g Sun Aug 14 10:36:45 2011
@@ -15,7 +15,7 @@
dec(r);
// fprintf(stdout,"gdec(%x) = %d\n", r, op(r) >> 8);
if (op(r) < 256)
- release(A,r,1);
+ release_clear(A,r);
}

inline void gconsume_unowned__match(int A, void *r) {
gconsume_unowned(A,r); }

Reply all
Reply to author
Forward
0 new messages