Thread: [Assorted-commits] SF.net SVN: assorted: [263] sandbox/trunk/src
Brought to you by:
yangzhang
|
From: <yan...@us...> - 2008-01-20 06:41:46
|
Revision: 263
http://assorted.svn.sourceforge.net/assorted/?rev=263&view=rev
Author: yangzhang
Date: 2008-01-19 22:41:51 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
added stuff to sandbox
Added Paths:
-----------
sandbox/trunk/src/bash/zombie-processes/
sandbox/trunk/src/bash/zombie-processes/README
sandbox/trunk/src/bash/zombie-processes/child
sandbox/trunk/src/bash/zombie-processes/parent
sandbox/trunk/src/hs/PiCalc.hs
sandbox/trunk/src/hs/compilation/
sandbox/trunk/src/hs/compilation/HelloWorld.hs
sandbox/trunk/src/hs/compilation/Makefile
sandbox/trunk/src/tex/code-figure.tex
Added: sandbox/trunk/src/bash/zombie-processes/README
===================================================================
--- sandbox/trunk/src/bash/zombie-processes/README (rev 0)
+++ sandbox/trunk/src/bash/zombie-processes/README 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,5 @@
+Run `parent &` which forks `child` then becomes `sleep`. Keep an eye on `ps f`.
+
+`child` exits first, but since the `sleep` in `parent` does not query for its
+status (via `wait` or `waitpid`), `child` is left hanging as a `zombie` (until
+`parent` exits)
Added: sandbox/trunk/src/bash/zombie-processes/child
===================================================================
--- sandbox/trunk/src/bash/zombie-processes/child (rev 0)
+++ sandbox/trunk/src/bash/zombie-processes/child 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+exec sleep 5
Property changes on: sandbox/trunk/src/bash/zombie-processes/child
___________________________________________________________________
Name: svn:executable
+ *
Added: sandbox/trunk/src/bash/zombie-processes/parent
===================================================================
--- sandbox/trunk/src/bash/zombie-processes/parent (rev 0)
+++ sandbox/trunk/src/bash/zombie-processes/parent 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+./child &
+exec sleep 10
Property changes on: sandbox/trunk/src/bash/zombie-processes/parent
___________________________________________________________________
Name: svn:executable
+ *
Added: sandbox/trunk/src/hs/PiCalc.hs
===================================================================
--- sandbox/trunk/src/hs/PiCalc.hs (rev 0)
+++ sandbox/trunk/src/hs/PiCalc.hs 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,224 @@
+{-# OPTIONS -fglasgow-exts #-}
+module Main (main) where
+
+{-
+I didn't write this. Someone on #haskell dug up an old pi calc impl of
+theirs.
+-}
+
+import Control.Concurrent hiding (forkIO)
+import Control.Concurrent.MVar
+import Control.Concurrent.Chan
+import Control.Exception
+import Prelude hiding (putStrLn,(||),catch)
+import qualified Control.Concurrent (forkIO)
+import qualified Prelude (putStrLn)
+import System.IO.Unsafe (unsafePerformIO)
+import Data.Dynamic
+import Control.Monad (liftM)
+
+main = return ()
+
+globalLock :: MVar ()
+globalLock = unsafePerformIO $ newMVar ()
+
+putStrLn :: String -> IO ()
+putStrLn s = do
+ takeMVar globalLock
+ threadDelay 100
+ Prelude.putStrLn s
+ putMVar globalLock ()
+
+children :: MVar [MVar ()]
+children = unsafePerformIO (newMVar [])
+
+forkIO io = do
+ mvar <- newEmptyMVar
+ tID <- Control.Concurrent.forkIO (io `finally` putMVar mvar ())
+ childs <- takeMVar children
+ putMVar children (mvar:childs)
+ return tID
+
+waitForChildren = do
+ (mvar:mvars) <- takeMVar children
+ putMVar children mvars
+ takeMVar mvar
+ waitForChildren
+
+type Channel = Chan Dynamic
+
+{-# NOINLINE chanTyCon #-}
+chanTyCon = mkTyCon "Chan"
+
+{-# NOINLINE rationalTyCon #-}
+rationalTyCon = mkTyCon "Rational"
+
+instance Typeable Channel where
+ typeOf _ = mkAppTy chanTyCon [typeOf (undefined :: Dynamic)]
+
+instance Typeable Rational where
+ typeOf _ = mkAppTy rationalTyCon []
+
+instance Eq Dynamic where
+ a == b | Just (a :: Integer) <- fromDynamic a, Just b <- fromDynamic b = a == b
+ | Just (a :: Rational) <- fromDynamic a, Just b <- fromDynamic b = a == b
+ | otherwise = False
+
+instance Num Dynamic where
+ a + b = toDyn $ fromD a + (fromD b :: Integer)
+ a - b = toDyn $ fromD a - (fromD b :: Integer)
+ a * b = toDyn $ fromD a * (fromD b :: Integer)
+ negate a = toDyn $ negate (fromD a :: Integer)
+ signum a = toDyn $ signum (fromD a :: Integer)
+ abs a = toDyn $ abs (fromD a :: Integer)
+ fromInteger = toDyn
+
+instance Fractional Dynamic where
+ a / b = toDyn $ fromD a / (fromD b :: Rational)
+ recip a = toDyn $ recip (fromD a :: Rational)
+ fromRational = toDyn
+
+q :: Typeable a => a -> Dynamic
+q = toDyn
+
+
+p :: Typeable a => Dynamic -> a
+p = fromD
+
+(&) :: Typeable a => a -> [Dynamic] -> [Dynamic]
+infixr 9 &
+x & xs = toDyn x : xs
+
+fromD :: Typeable a => Dynamic -> a
+fromD d = case fromDynamic d of
+ Just a -> a
+ Nothing -> error ("type error: "++show d)
+
+newPrim :: ([Dynamic] -> IO a) -> IO Dynamic
+newPrim prim = do
+ chan <- newChan
+ forkIO (getChanContents chan >>= mapM_ (prim . fromD))
+ return (toDyn chan)
+
+newBinPrim :: (Typeable a, Typeable b, Typeable c) =>
+ (a -> b -> c) -> IO Dynamic
+newBinPrim (op :: a -> b -> c) = do
+ chan <- newChan
+ forkIO (getChanContents chan >>= mapM_ (prim . fromD))
+ return (toDyn chan)
+ where prim [a, b, out] = do
+ let x = (fromD a :: a) `op` (fromD b :: b) :: c
+ out![toDyn x]
+
+startOpsServices = do
+ add <- newBinPrim ((+) :: Integer -> Integer -> Integer)
+ sub <- newBinPrim ((-) :: Integer -> Integer -> Integer)
+ mul <- newBinPrim ((*) :: Integer -> Integer -> Integer)
+ div <- newBinPrim (div :: Integer -> Integer -> Integer)
+ return (add,sub,mul,div)
+
+startPrintService :: IO Dynamic -- print
+startPrintService = newPrim (\[s] -> putStrLn (fromD s))
+
+startPrintIntegerService :: Dynamic -> IO Dynamic -- printInteger
+startPrintIntegerService print
+ = liftM head $ new $ \printInteger -> printInteger?* \[i] -> print![q (show (p i :: Integer))]
+
+startEitherServices :: IO [Dynamic] -- [either,left,right]
+startEitherServices = new $ \either left right ->
+ (either?* \[l,r,lr] -> lr![l,r]) ||
+ (left?* \[v,out] -> new $ \l' -> (l'?* \[l,r] -> l![v]) || out![l']) ||
+ (right?* \[v,out] -> new $ \r' -> (r'?* \[l,r] -> r![v]) || out![r'])
+
+startRefServices :: IO [Dynamic] -- [newRef,emptyRef]
+startRefServices = new $ \newRef emptyRef ->
+ (newRef?* \[v,out] -> new $ \r ack ->
+ (r? \m@[get,put] -> put![v,ack] || ack? \[] -> out!m) ||
+ emptyRef![r]) ||
+ (emptyRef?* \[out] -> new $ \get put cell ->
+ (get?* \[out] -> cell? \[v] -> cell![v] || out![v]) ||
+ (put? \[v,ack] -> cell![v] || ack![] ||
+ (put?* \[v,ack] -> cell? \_ -> cell![v] || ack![])) ||
+ out![get,put])
+
+captureChannels :: (Dynamic -> IO a) -> IO [Dynamic]
+captureChannels p = do
+ chan <- newChan
+ forkIO (p (toDyn chan) >> return ())
+ cs <- readChan chan
+ return (fromD cs)
+
+-- P | Q
+-- use like p || q
+infixr 0 ||
+(||) :: IO a -> IO b -> IO ()
+p || q = forkIO (q >> return()) >> p >> return ()
+-- p || q = forkIO (p >> return()) >> forkIO (q >> return()) >> return ()
+
+-- new chan
+-- use like new $ \chan -> ...
+-- new :: (Channel -> IO a) -> IO Channel
+-- new p = do chan <- newChan; p chan; return chan
+
+--------------------------------------------------------------------------------
+{-
+
+ --Tips--
+
+ Functional Processes
+
+ let (x,y) = F(a,b) in P ==>
+ new $ \r -> (f![a,b,q r]) || (r? \[x,y] -> P)
+ e.g.
+ let x = add (a,b) in p![x]
+ new $ \r -> (add![a,b,r]) || (r? \[x] -> p![x])
+ or simplifying (tail-calling of sorts)
+ add![a,b,p]
+
+ Encoding Recursion
+
+ def X(a) = P;Y(b) = Q in W ==>
+ new $ \x y -> (x?* \[a] -> P) || (y?* \[b] -> Q) || W
+ e.g.
+ def inc(x) = printInteger![x] >> inc(x+1) in inc(0)
+ new $ \inc -> (inc?* \[x] -> printInteger![x] >> add![1,x,q inc]) ||
+ (inc![0])
+
+ "Higher-Order Processes"
+
+ x![P] || x? \[P] -> Q
+ (new $ \w -> (x![w]) || (w? \x -> P)) || (x? \[w] -> Q)
+ e.g.
+ x![new $ \y -> y? \x -> print!x] || (x? \[z] -> p z![q "foo"])
+ (new $ \y -> x![y] || y? \x -> print!x) || (x? \[z] -> p z[q "foo"]
+-}
+
+class NewChannel a where
+ new :: a -> IO [Dynamic]
+
+instance NewChannel (IO a) where
+ new p = forkIO (p >> return ()) >> return []
+
+instance (NewChannel a) => NewChannel (Dynamic -> a) where
+ new p = do chan <- newChan; chans <- new (p (toDyn (chan :: Channel))); return (toDyn chan:chans)
+
+-- f![arg1 arg2]
+-- use like f![q arg1, q arg2]
+infix 8 !
+(!) :: Dynamic -> [Dynamic] -> IO ()
+chan ! x = writeChan (fromD chan) (toDyn x)
+
+-- f?x = e
+-- use like chan? \x -> e
+infix 8 ?
+(?) :: Dynamic -> ([Dynamic] -> IO a) -> IO ()
+chan ? p = do v <- readChan (fromD chan); p (fromD v); return ()
+
+-- f?*x = e
+-- use like chan?* \x -> e
+infix 8 ?*
+(?*) :: Dynamic -> ([Dynamic] -> IO a) -> IO ()
+chan ?* p = getChanContents (fromD chan) >>= mapM_ (\x -> forkIO (p (fromD x) >> return()))
+
+--------------------------------------------------------------------------------
+
Added: sandbox/trunk/src/hs/compilation/HelloWorld.hs
===================================================================
--- sandbox/trunk/src/hs/compilation/HelloWorld.hs (rev 0)
+++ sandbox/trunk/src/hs/compilation/HelloWorld.hs 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,2 @@
+module Main where
+main = putStrLn "hello world!"
Added: sandbox/trunk/src/hs/compilation/Makefile
===================================================================
--- sandbox/trunk/src/hs/compilation/Makefile (rev 0)
+++ sandbox/trunk/src/hs/compilation/Makefile 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,14 @@
+all: HelloWorld
+ ghc -ddump-ds HelloWorld.hs
+
+HelloWorld: HelloWorld.hs
+ ghc -o HelloWorld HelloWorld.hs
+
+HelloWorld.s: HelloWorld.hs
+ ghc -S -o HelloWorld.s HelloWorld.hs
+
+HelloWorld.hc: HelloWorld.hs
+ ghc -C -o HelloWorld.hc HelloWorld.hs
+
+clean:
+ rm *.hi *.o *.out *.s *.hc HelloWorld
Added: sandbox/trunk/src/tex/code-figure.tex
===================================================================
--- sandbox/trunk/src/tex/code-figure.tex (rev 0)
+++ sandbox/trunk/src/tex/code-figure.tex 2008-01-20 06:41:51 UTC (rev 263)
@@ -0,0 +1,198 @@
+\documentclass{article}
+
+\usepackage{algorithm}
+\usepackage{amsmath}
+\usepackage{algorithmicx,algpseudocode}
+\usepackage{fancyvrb}
+\usepackage{listings}
+\usepackage{setspace}
+
+\newcommand{\proc}[1]{{\textsc{#1}}}
+\newcommand{\var}[1]{{\emph{#1}}}
+
+\begin{document}
+
+\subsection{Fancy Verbs}
+
+A demo of using fancy verbs.
+
+\SaveVerb{x}=another=
+This is a \Verb|fancy_vrb|. Here's \UseVerb{x}.
+
+\DefineShortVerb{\|}
+The function |camera_global_prioritization|.
+
+Fancier features:
+\begin{Verbatim}[frame=single, commandchars=\\\{\},
+ codes={\catcode`$=3 \catcode`^=7} %$
+]
+Simple math is fine, $ \frac{1}{\sqrt{z}}, but math becomes quirky!$
+\end{Verbatim}
+
+
+\begin{SaveVerbatim}{sql}
+SELECT a, b
+EVERY n [SECONDS]
+BUFFER IN buffername
+\end{SaveVerbatim}
+
+\UseVerbatim{sql}
+
+\begin{Verbatim}
+select * from r where a = 0;
+\end{Verbatim}
+
+%% The following don't work, despite the indirections of saving verbs
+%% and saving boxes.
+%%
+%% \fbox{\UseVerbatim{sql}}
+%%
+%% \newsavebox{\mybox}
+%%
+%% \begin{lrbox}{\mybox}
+%% \UseVerbatim{sql}
+%% \end{lrbox}
+%%
+%% \fbox{\usebox{\mybox}}
+
+\setbox0=\vbox{
+%\begin{minipage}
+\begin{verbatim}
+verbatim stuff
+\end{verbatim}
+%\end{minipage}
+}
+
+\fbox{\box0}
+
+\subsection{Math}
+
+Minipages in math:
+\begin{align}
+x = \begin{minipage}{1in}
+I'm in a minipage.
+\end{minipage}
+\end{align}
+
+\subsection{Algorithms}
+
+|algorithmicx| obsoletes |algorithmic|, and is the one I currently
+default to. Another worth considering is |algorithm2e|.
+
+See example figures.
+
+\begin{figure}
+\caption{Pseudocode for a global prioritization scheme.}
+\label{f:global}
+\fbox{
+\begin{minipage}{\textwidth}
+\begin{algorithmic}[1]
+\Procedure{CameraGlobalPrioritization}{\var{query points},
+ \var{summary grids}}
+\ForAll{$g \in \var{summary grids}$}
+\State $\var{scores}[g] \leftarrow
+\begin{cases}
+ 1, & \begin{minipage}{3in}
+ $\forall q \in \var{query points}$, no car previously
+ answered $q$ and $\proc{Distance}(\var{g.center}, q) < \var{threshold}$
+ \end{minipage} \\
+ 0, & \text{otherwise}
+\end{cases}$
+\EndFor \\
+\Return \var{summary grids}
+\EndProcedure
+\end{algorithmic}
+\end{minipage}
+}
+\end{figure}
+
+\begin{figure}
+\fbox{
+\begin{minipage}{\textwidth}
+\begin{algorithmic}[1]
+\Procedure{Bisect}{\var{tuples}}
+
+\State $\var{segs} \leftarrow \text{empty priority queue of segments,
+ ordered by segment length}$
+
+\State push \proc{New-Segment}(\var{tuples} sorted by time) onto
+\var{segs}
+
+\While{\proc{Not-Empty}(\var{segs})}
+
+\State $\var{seg} \leftarrow \proc{Pop-Min}(\var{segs})$
+
+\State add \proc{Midpoint}(\var{seg}) to output buffer
+
+\If{$\proc{Num-Tuples}(\var{seg}) > 1$}
+
+\State push \proc{Left}(\var{seg}) and \proc{Right}(\var{seg}) onto
+\var{segs}
+
+\EndIf
+\EndWhile
+\EndProcedure
+\end{algorithmic}
+\end{minipage}
+}
+\caption{Pseudocode for \texttt{bisect} delivery function.}
+\label{f:bisect}
+\end{figure}
+
+\subsection{Listings}
+
+I don't know how to change the font to something less ugly, escape to
+TeX, etc.
+
+\lstset{language=sql}
+
+\begin{lstlisting}
+SELECT * FROM r WHERE a = 0;
+\end{lstlisting}
+
+%\DeclareOption{singlespace}{
+% \typeout{Single spaced}
+% \def\mystretch{1}}
+%
+\newcommand{\sqlquery}[1]{{
+ % \setlength\baselinestretch{1.0}
+ \begin{samepage}
+ % \setlength\parskip{.1\baselineskip}
+ % \small
+ %
+ % \renewcommand\baselinestretch{1.0}
+ \hspace{0in}\parbox{\textwidth}{
+ \begin{singlespace}
+ \setlength\parindent{-.2in}
+ \texttt{#1}
+ \end{singlespace}
+ }
+ % \normalsize
+ % \renewcommand\baselinestretch{1.0}
+ \end{samepage}
+}}
+
+\sqlquery{
+SELECT * \\
+FROM my\_table \\
+WHERE ;
+}
+
+\subsection{Simple demo}
+
+This figure seems to work, but you better not uncomment the fbox!
+
+\begin{figure}
+% \fbox{
+\begin{minipage}{\textwidth}
+\begin{Verbatim}[frame=single, commandchars=\\\{\},
+ codes={\catcode`$=3\catcode`^=7}]
+hello, world! $ \forall x$
+\end{Verbatim}
+\end{minipage}
+% }
+\caption{Pseudocode for a global prioritization scheme.}
+\label{f:global}
+\end{figure}
+
+\end{document}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-03-10 19:52:12
|
Revision: 618
http://assorted.svn.sourceforge.net/assorted/?rev=618&view=rev
Author: yangzhang
Date: 2008-03-10 12:52:06 -0700 (Mon, 10 Mar 2008)
Log Message:
-----------
added some lazy c++ tests
Added Paths:
-----------
sandbox/trunk/src/lzz/
sandbox/trunk/src/lzz/A.lzz
sandbox/trunk/src/lzz/Makefile
sandbox/trunk/src/lzz/test.lzz
Added: sandbox/trunk/src/lzz/A.lzz
===================================================================
--- sandbox/trunk/src/lzz/A.lzz (rev 0)
+++ sandbox/trunk/src/lzz/A.lzz 2008-03-10 19:52:06 UTC (rev 618)
@@ -0,0 +1,14 @@
+#hdr
+#include <iostream>
+using namespace std;
+#end
+
+class A
+{
+ public:
+ inline void f(int i) { cout << "hello"; }
+ void g(int j = 0) { cout << "world"; }
+};
+bool operator ==(A const & a1, A const & a2) { return true; }
+
+// vim:ft=cpp:et:sw=2:ts=2
Added: sandbox/trunk/src/lzz/Makefile
===================================================================
--- sandbox/trunk/src/lzz/Makefile (rev 0)
+++ sandbox/trunk/src/lzz/Makefile 2008-03-10 19:52:06 UTC (rev 618)
@@ -0,0 +1,6 @@
+all: lzztest
+lzztest: $(wildcard *.lzz)
+ lzz *.lzz
+ g++ -Wall *.cpp -o lzztest
+clean:
+ rm -f *.cpp *.h lzztest
Added: sandbox/trunk/src/lzz/test.lzz
===================================================================
--- sandbox/trunk/src/lzz/test.lzz (rev 0)
+++ sandbox/trunk/src/lzz/test.lzz 2008-03-10 19:52:06 UTC (rev 618)
@@ -0,0 +1,16 @@
+#hdr
+#include <iostream>
+#include "A.h"
+using namespace std;
+#end
+
+int
+main()
+{
+ A a;
+ a.g();
+ cout << "hello, world!" << endl;
+ return 0;
+}
+
+// vim:ft=cpp:et:sw=2:ts=2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-06-02 00:17:03
|
Revision: 835
http://assorted.svn.sourceforge.net/assorted/?rev=835&view=rev
Author: yangzhang
Date: 2008-06-01 17:16:49 -0700 (Sun, 01 Jun 2008)
Log Message:
-----------
added a bunch of sandbox stuff
Added Paths:
-----------
sandbox/trunk/src/c/euclid.c
sandbox/trunk/src/c/hello.c
sandbox/trunk/src/cc/hello.cc
sandbox/trunk/src/cc/privacy.cc
sandbox/trunk/src/java/ClassLoadingThread.java
Added: sandbox/trunk/src/c/euclid.c
===================================================================
--- sandbox/trunk/src/c/euclid.c (rev 0)
+++ sandbox/trunk/src/c/euclid.c 2008-06-02 00:16:49 UTC (rev 835)
@@ -0,0 +1,3 @@
+#include <stdio.h>
+int gcd(int a, int b) { return ( b != 0 ? gcd(b, a % b) : a ); }
+int main() { printf("%d %d\n", gcd(6,4), gcd(4,6)); return 0; }
Added: sandbox/trunk/src/c/hello.c
===================================================================
--- sandbox/trunk/src/c/hello.c (rev 0)
+++ sandbox/trunk/src/c/hello.c 2008-06-02 00:16:49 UTC (rev 835)
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+main()
+{
+ printf("hello, world!\n");
+ return 0;
+}
Added: sandbox/trunk/src/cc/hello.cc
===================================================================
--- sandbox/trunk/src/cc/hello.cc (rev 0)
+++ sandbox/trunk/src/cc/hello.cc 2008-06-02 00:16:49 UTC (rev 835)
@@ -0,0 +1,15 @@
+// A simple hello world application.
+//
+// Try compiling this on a 64-bit machine for a 32-bit target with `g++ -m32
+// hello.cc`.
+
+#include <iostream>
+
+using namespace std;
+
+int
+main()
+{
+ cout << "hello, world!" << endl;
+ return 0;
+}
Added: sandbox/trunk/src/cc/privacy.cc
===================================================================
--- sandbox/trunk/src/cc/privacy.cc (rev 0)
+++ sandbox/trunk/src/cc/privacy.cc 2008-06-02 00:16:49 UTC (rev 835)
@@ -0,0 +1,29 @@
+/**
+ * Is there any way at all to allow another class (such as testing) to peer
+ * into the protected state of an instance of c (that isn't `this`)?
+ *
+ * Probably not, since that would be asking for nothing short of
+ */
+
+#include <stdlib.h>
+
+#define check(x) if (!(x)) { exit(1); }
+
+class c {
+ public: c() : x(0) {}
+ protected: int x;
+};
+
+class tester : public c {
+ public:
+ void test(c& c) {
+ if (c.x != 0) exit(1);
+ }
+};
+
+int main() {
+ c c;
+ tester t;
+ t.test(c);
+ return 0;
+}
Added: sandbox/trunk/src/java/ClassLoadingThread.java
===================================================================
--- sandbox/trunk/src/java/ClassLoadingThread.java (rev 0)
+++ sandbox/trunk/src/java/ClassLoadingThread.java 2008-06-02 00:16:49 UTC (rev 835)
@@ -0,0 +1,27 @@
+// From http://www.drmaciver.com/2008/04/object-main-extends-application-considered-harmful/:
+//
+// Because the initialization of the Main$ class depends on the construction of
+// the Main object, Main$ will not be fully initialized until the constructor
+// has exited. The JVM semantics guarantee that class loading is single
+// threaded and that other threads cannot access the class until it has
+// finished loading. Hence the observed problem.
+//
+// However, I (Yang) couldn't repro this! XXX
+
+public class ClassLoadingThread {
+ static {
+ System.out.println("hello");
+ final ClassLoadingThread x = new ClassLoadingThread();
+ Runnable r = new Runnable() {
+ public void run() {
+ synchronized(x) { x.notify(); }
+ }
+ };
+ new Thread(r).start();
+ try { synchronized(x) { x.wait(); } }
+ catch (Exception ex) { throw new RuntimeException(ex); }
+ }
+ public static void main(String[] args) {
+ System.out.println("world");
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-06-02 00:26:06
|
Revision: 843
http://assorted.svn.sourceforge.net/assorted/?rev=843&view=rev
Author: yangzhang
Date: 2008-06-01 17:26:13 -0700 (Sun, 01 Jun 2008)
Log Message:
-----------
added stuff to sandbox
Added Paths:
-----------
sandbox/trunk/src/cc/stringsplitting.cc
sandbox/trunk/src/hs/BlockingIo.hs
sandbox/trunk/src/hs/Introspection.hs
sandbox/trunk/src/hs/Signals.hs
sandbox/trunk/src/hs/ThreadPool.hs
sandbox/trunk/src/py/af/sockcancel.py
sandbox/trunk/src/scala/SetsIntersectionBug.scala
Added: sandbox/trunk/src/cc/stringsplitting.cc
===================================================================
--- sandbox/trunk/src/cc/stringsplitting.cc (rev 0)
+++ sandbox/trunk/src/cc/stringsplitting.cc 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,26 @@
+// Simple string splitter. How does this work? istream_iterator<T> reads
+// objects of type T in from the given istream and yields them as an iterator.
+
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <iterator>
+#include <vector>
+using namespace std;
+
+std::vector<std::string> split(const std::string& s)
+{
+ std::istringstream is(s);
+ return std::vector<string>(std::istream_iterator<std::string>(is),
+ std::istream_iterator<std::string>());
+}
+
+int main() {
+ vector<string> words = split(string("hello world"));
+ for (vector<string>::const_iterator word = words.begin();
+ word != words.end();
+ word++) {
+ cout << *word << endl;
+ }
+ return 0;
+}
Added: sandbox/trunk/src/hs/BlockingIo.hs
===================================================================
--- sandbox/trunk/src/hs/BlockingIo.hs (rev 0)
+++ sandbox/trunk/src/hs/BlockingIo.hs 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,28 @@
+module Main where
+
+-- Simple demo of the interaction between blocking IO and lightweight
+-- threads. Haskell is smart and creates real threads on demand.
+
+import Control.Concurrent
+import Network.FTP.Client
+
+main = do
+-- installHandler
+ tid <- myThreadId
+ forkIO $ watchdog tid
+ beta
+
+watchdog tid = do
+ threadDelay 1000000
+ putStrLn "killing"
+ killThread tid
+
+beta = do
+ enableFTPDebugging
+ h <- easyConnectFTP "1.1.1.1" -- "ftp.kernel.org"
+ loginAnon h
+ cwd h "/pub/linux/kernel/Historic"
+ nlst h Nothing >>= putStrLn . unlines
+ getbinary h "linux-0.01.tar.gz.sign" >>= putStrLn . fst
+ dir h Nothing >>= putStrLn . unlines
+ quit h
Added: sandbox/trunk/src/hs/Introspection.hs
===================================================================
--- sandbox/trunk/src/hs/Introspection.hs (rev 0)
+++ sandbox/trunk/src/hs/Introspection.hs 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,9 @@
+module Main where
+
+import Data.Generics.Text
+
+data T a = B (T a) (T a) | L a
+
+-- http://www.defmacro.org/ramblings/haskell-web.html
+
+main = print (gshow (L 3))
\ No newline at end of file
Added: sandbox/trunk/src/hs/Signals.hs
===================================================================
--- sandbox/trunk/src/hs/Signals.hs (rev 0)
+++ sandbox/trunk/src/hs/Signals.hs 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,29 @@
+module Main where
+
+-- summary: signals are handled in separate threads and don't
+-- interrupt syscalls
+
+import Control.Concurrent
+import System.IO
+import System.Process
+import System.Posix.Signals
+
+hGetContents' h = do
+ c <- hGetContents h
+ length c `seq` return c
+
+main = do
+ let handler = do
+ tid <- myThreadId
+ putStrLn $ "handling in " ++ show tid
+ tid <- myThreadId
+ putStrLn $ "thread " ++ show tid
+ installHandler sigUSR1 (Catch handler) Nothing
+ putStrLn "spawning"
+ (inp,out,err,pid) <- runInteractiveCommand "echo hello; sleep 5; echo world; exit 1"
+ putStrLn "reading"
+ res <- hGetContents' out
+ putStrLn "waiting"
+ status <- waitForProcess pid
+ putStrLn $ "exited with " ++ show status
+ putStrLn $ "read " ++ res
Added: sandbox/trunk/src/hs/ThreadPool.hs
===================================================================
--- sandbox/trunk/src/hs/ThreadPool.hs (rev 0)
+++ sandbox/trunk/src/hs/ThreadPool.hs 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,42 @@
+module Main where
+
+import Control.Monad
+import Control.Concurrent
+import Control.Exception as E
+import Control.Concurrent.STM
+
+type Work = IO ()
+
+type SendWork = Work -> STM ()
+
+spawnWorkers :: Int -> IO (SendWork,IO ())
+spawnWorkers i | i <= 0 = error "Need positive number of workers"
+ | otherwise = do
+
+ workChan <- atomically newTChan
+ runCount <- atomically (newTVar i)
+
+ let stop = atomically (writeTVar runCount . pred =<< readTVar runCount)
+ die e = do id <- myThreadId
+ print ("Thread "++show id++" died with exception "++show e)
+ stop
+ work = do mJob <- atomically (readTChan workChan)
+ case mJob of Nothing -> stop
+ Just job -> E.catch job die >> work
+ replicateM_ i (forkIO work)
+
+ let stopCommand = do atomically (replicateM_ i (writeTChan workChan Nothing))
+ atomically (do running <- readTVar runCount
+ when (running>0) retry)
+
+ return (writeTChan workChan . Just,stopCommand)
+
+printJob i = do threadDelay (1000 * i)
+ id <- myThreadId
+ print ("printJob took "++show i++" ms in thread "++show id)
+
+demo = do
+ (submit,stop) <- spawnWorkers 4
+ mapM_ (atomically . submit . printJob) (take 40 (cycle [100,200,300,400]))
+ atomically $ submit (error "Boom")
+ stop
Added: sandbox/trunk/src/py/af/sockcancel.py
===================================================================
--- sandbox/trunk/src/py/af/sockcancel.py (rev 0)
+++ sandbox/trunk/src/py/af/sockcancel.py 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# vim:et:sw=2:ts=2
+
+"""
+Shows that socket.read_some()'s cancel-handling is broken.
+"""
+
+from __future__ import generators
+
+import af
+import afx.all as afx
+
+@af.task
+def main(argv):
+ s = yield af.socket.connect('localhost',9876)
+ u = afx.socket_unpickler(s)
+ while True:
+ res = yield u.read() | af.timeout(1)
+ print res
+
+afx.run_main()
Property changes on: sandbox/trunk/src/py/af/sockcancel.py
___________________________________________________________________
Name: svn:executable
+ *
Added: sandbox/trunk/src/scala/SetsIntersectionBug.scala
===================================================================
--- sandbox/trunk/src/scala/SetsIntersectionBug.scala (rev 0)
+++ sandbox/trunk/src/scala/SetsIntersectionBug.scala 2008-06-02 00:26:13 UTC (rev 843)
@@ -0,0 +1,8 @@
+import scala.collection.mutable._
+object SetsIntersectionBug extends Application {
+ val m1,m2 = new HashMap[Int,Int]
+ // This yields a build error, which seems like a compiler bug, since this
+ // works in the REPL.
+ val s = m1.keySet ** m2.keySet
+ println(s)
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-06-02 20:37:48
|
Revision: 845
http://assorted.svn.sourceforge.net/assorted/?rev=845&view=rev
Author: yangzhang
Date: 2008-06-02 13:37:15 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
playing with bison
Added Paths:
-----------
sandbox/trunk/src/bison/
sandbox/trunk/src/bison/calc/
sandbox/trunk/src/bison/calc/Makefile
sandbox/trunk/src/bison/calc/calc.lex
sandbox/trunk/src/bison/calc/calc.y
sandbox/trunk/src/bison/calc/heading.h
sandbox/trunk/src/bison/calc/main.cc
sandbox/trunk/src/bison/calc/url
Added: sandbox/trunk/src/bison/calc/Makefile
===================================================================
--- sandbox/trunk/src/bison/calc/Makefile (rev 0)
+++ sandbox/trunk/src/bison/calc/Makefile 2008-06-02 20:37:15 UTC (rev 845)
@@ -0,0 +1,34 @@
+# Makefile
+
+OBJS = bison.o lex.o main.o
+
+CC = g++
+CFLAGS = -g -Wall -ansi -pedantic
+
+calc: $(OBJS)
+ $(CC) $(CFLAGS) $(OBJS) -o calc -lfl
+
+lex.o: lex.c
+ $(CC) $(CFLAGS) -c lex.c -o lex.o
+
+lex.c: calc.lex
+ flex calc.lex
+ cp lex.yy.c lex.c
+
+bison.o: bison.c
+ $(CC) $(CFLAGS) -c bison.c -o bison.o
+
+bison.c: calc.y
+ bison -d -v calc.y
+ cp calc.tab.c bison.c
+ cmp -s calc.tab.h tok.h || cp calc.tab.h tok.h
+
+main.o: main.cc
+ $(CC) $(CFLAGS) -c main.cc -o main.o
+
+lex.o yac.o main.o : heading.h
+lex.o main.o : tok.h
+
+clean:
+ rm -f *.o *~ lex.c lex.yy.c bison.c tok.h calc.tab.c calc.tab.h calc.output calc
+
Added: sandbox/trunk/src/bison/calc/calc.lex
===================================================================
--- sandbox/trunk/src/bison/calc/calc.lex (rev 0)
+++ sandbox/trunk/src/bison/calc/calc.lex 2008-06-02 20:37:15 UTC (rev 845)
@@ -0,0 +1,24 @@
+/* Mini Calculator */
+/* calc.lex */
+
+%{
+#include "heading.h"
+#include "tok.h"
+int yyerror(char *s);
+int yylineno = 1;
+%}
+
+digit [0-9]
+int_const {digit}+
+
+%%
+
+{int_const} { yylval.int_val = atoi(yytext); return INTEGER_LITERAL; }
+"+" { yylval.op_val = new std::string(yytext); return PLUS; }
+"*" { yylval.op_val = new std::string(yytext); return MULT; }
+
+[ \t]* {}
+[\n] { yylineno++; }
+
+. { std::cerr << "SCANNER "; yyerror(""); exit(1); }
+
Added: sandbox/trunk/src/bison/calc/calc.y
===================================================================
--- sandbox/trunk/src/bison/calc/calc.y (rev 0)
+++ sandbox/trunk/src/bison/calc/calc.y 2008-06-02 20:37:15 UTC (rev 845)
@@ -0,0 +1,50 @@
+/* Mini Calculator */
+/* calc.y */
+
+%{
+#include "heading.h"
+int yyerror(char *s);
+int yylex(void);
+%}
+
+%union{
+ int int_val;
+ string* op_val;
+}
+
+%start input
+
+%token <int_val> INTEGER_LITERAL
+%type <int_val> exp
+%left PLUS
+%left MULT
+
+%%
+
+input: /* empty */
+ | exp { cout << "Result: " << $1 << endl; }
+ ;
+
+exp: INTEGER_LITERAL { $$ = $1; }
+ | exp PLUS exp { $$ = $1 + $3; }
+ | exp MULT exp { $$ = $1 * $3; }
+ ;
+
+%%
+
+int yyerror(string s)
+{
+ extern int yylineno; // defined and maintained in lex.c
+ extern char *yytext; // defined and maintained in lex.c
+
+ cerr << "ERROR: " << s << " at symbol \"" << yytext;
+ cerr << "\" on line " << yylineno << endl;
+ exit(1);
+}
+
+int yyerror(char *s)
+{
+ return yyerror(string(s));
+}
+
+
Added: sandbox/trunk/src/bison/calc/heading.h
===================================================================
--- sandbox/trunk/src/bison/calc/heading.h (rev 0)
+++ sandbox/trunk/src/bison/calc/heading.h 2008-06-02 20:37:15 UTC (rev 845)
@@ -0,0 +1,10 @@
+/* heading.h */
+
+#define YY_NO_UNPUT
+
+using namespace std;
+
+#include <iostream>
+#include <stdio.h>
+#include <string>
+
Added: sandbox/trunk/src/bison/calc/main.cc
===================================================================
--- sandbox/trunk/src/bison/calc/main.cc (rev 0)
+++ sandbox/trunk/src/bison/calc/main.cc 2008-06-02 20:37:15 UTC (rev 845)
@@ -0,0 +1,20 @@
+/* main.cc */
+
+#include "heading.h"
+
+// prototype of bison-generated parser function
+int yyparse();
+
+int main(int argc, char **argv)
+{
+ if ((argc > 1) && (freopen(argv[1], "r", stdin) == NULL))
+ {
+ cerr << argv[0] << ": File " << argv[1] << " cannot be opened.\n";
+ exit( 1 );
+ }
+
+ yyparse();
+
+ return 0;
+}
+
Added: sandbox/trunk/src/bison/calc/url
===================================================================
--- sandbox/trunk/src/bison/calc/url (rev 0)
+++ sandbox/trunk/src/bison/calc/url 2008-06-02 20:37:15 UTC (rev 845)
@@ -0,0 +1 @@
+http://www.cs.ucr.edu/~lgao/teaching/bison.html
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-06-03 01:50:44
|
Revision: 846
http://assorted.svn.sourceforge.net/assorted/?rev=846&view=rev
Author: yangzhang
Date: 2008-06-02 18:50:46 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
going through flex/bison tutorial
Added Paths:
-----------
sandbox/trunk/src/flex/
sandbox/trunk/src/flex/ex1/
sandbox/trunk/src/flex/ex1/Makefile
sandbox/trunk/src/flex/ex1/ex1.l
sandbox/trunk/src/flex/ex2/
sandbox/trunk/src/flex/ex2/ex2.l
sandbox/trunk/src/flex/ex3/
sandbox/trunk/src/flex/ex3/ex3.l
sandbox/trunk/src/flex/ex4/
sandbox/trunk/src/flex/ex4/Makefile
sandbox/trunk/src/flex/ex4/ex4.l
sandbox/trunk/src/flex/ex4/ex4.y
sandbox/trunk/src/flex/ex5/
sandbox/trunk/src/flex/ex5/Makefile
sandbox/trunk/src/flex/ex5/ex5.l
sandbox/trunk/src/flex/ex5/ex5.y
Added: sandbox/trunk/src/flex/ex1/Makefile
===================================================================
--- sandbox/trunk/src/flex/ex1/Makefile (rev 0)
+++ sandbox/trunk/src/flex/ex1/Makefile 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,8 @@
+all: ex1
+
+%: %.yy.c
+ gcc -Wall -o $@ $< -ll
+ # libl contains a `main` function.
+
+%.yy.c: %.l
+ flex -o $@ $<
Added: sandbox/trunk/src/flex/ex1/ex1.l
===================================================================
--- sandbox/trunk/src/flex/ex1/ex1.l (rev 0)
+++ sandbox/trunk/src/flex/ex1/ex1.l 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,8 @@
+%{
+#include <stdio.h>
+%}
+
+%%
+stop printf("Stop command received\n");
+start printf("Start command received\n");
+%%
Added: sandbox/trunk/src/flex/ex2/ex2.l
===================================================================
--- sandbox/trunk/src/flex/ex2/ex2.l (rev 0)
+++ sandbox/trunk/src/flex/ex2/ex2.l 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,8 @@
+%{
+#include <stdio.h>
+%}
+
+%%
+[0123456789]+ printf("NUMBER\n");
+[a-zA-Z][a-zA-Z0-9]* printf("WORD\n");
+%%
Added: sandbox/trunk/src/flex/ex3/ex3.l
===================================================================
--- sandbox/trunk/src/flex/ex3/ex3.l (rev 0)
+++ sandbox/trunk/src/flex/ex3/ex3.l 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,14 @@
+%{
+#include <stdio.h>
+%}
+
+%%
+[a-zA-Z][a-zA-Z0-9]* printf("WORD ");
+[a-zA-Z0-9\/.-]+ printf("FILENAME ");
+\" printf("QUOTE ");
+\{ printf("OBRACE ");
+\} printf("EBRACE ");
+; printf("SEMICOLON ");
+\n printf("\n");
+[ \t]+ /* ignore whitespace */;
+%%
Added: sandbox/trunk/src/flex/ex4/Makefile
===================================================================
--- sandbox/trunk/src/flex/ex4/Makefile (rev 0)
+++ sandbox/trunk/src/flex/ex4/Makefile 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,13 @@
+all: ex4
+
+%: %.tab.c %.yy.c
+ gcc -Wall -o $@ $^
+
+%.yy.c: %.l %.tab.h
+ flex -o $@ $<
+
+%.tab.c: %.y
+ bison -d $<
+
+%.tab.h: %.y
+ bison -d $<
Added: sandbox/trunk/src/flex/ex4/ex4.l
===================================================================
--- sandbox/trunk/src/flex/ex4/ex4.l (rev 0)
+++ sandbox/trunk/src/flex/ex4/ex4.l 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,14 @@
+%{
+#include <stdio.h>
+#include "ex4.tab.h"
+%}
+%option nounput
+%%
+[0-9]+ return NUMBER;
+heat return TOKHEAT;
+on|off return STATE;
+target return TOKTARGET;
+temperature return TOKTEMPERATURE;
+\n /* ignore end of line */;
+[ \t]+ /* ignore whitespace */;
+%%
Added: sandbox/trunk/src/flex/ex4/ex4.y
===================================================================
--- sandbox/trunk/src/flex/ex4/ex4.y (rev 0)
+++ sandbox/trunk/src/flex/ex4/ex4.y 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,53 @@
+%{
+#include <stdio.h>
+#include <string.h>
+
+int yylex(void);
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+%}
+
+%token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE
+
+%%
+
+commands: /* empty */
+ | commands command
+ ;
+
+command:
+ heat_switch
+ |
+ target_set
+ ;
+
+heat_switch:
+ TOKHEAT STATE
+ {
+ printf("\tHeat turned on or off\n");
+ }
+ ;
+
+target_set:
+ TOKTARGET TOKTEMPERATURE NUMBER
+ {
+ printf("\tTemperature set\n");
+ }
+ ;
+
+%%
+
+int main()
+{
+ yyparse();
+ return 0;
+}
Added: sandbox/trunk/src/flex/ex5/Makefile
===================================================================
--- sandbox/trunk/src/flex/ex5/Makefile (rev 0)
+++ sandbox/trunk/src/flex/ex5/Makefile 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,13 @@
+all: ex5
+
+%: %.tab.c %.yy.c
+ gcc -Wall -o $@ $^
+
+%.yy.c: %.l %.tab.h
+ flex -o $@ $<
+
+%.tab.c: %.y
+ bison -d $<
+
+%.tab.h: %.y
+ bison -d $<
Added: sandbox/trunk/src/flex/ex5/ex5.l
===================================================================
--- sandbox/trunk/src/flex/ex5/ex5.l (rev 0)
+++ sandbox/trunk/src/flex/ex5/ex5.l 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,14 @@
+%{
+#include <stdio.h>
+#include "ex5.tab.h"
+%}
+%option nounput
+%%
+[0-9]+ yylval=atoi(yytext); return NUMBER;
+heat return TOKHEAT;
+on|off yylval=!strcmp(yytext,"on"); return STATE;
+target return TOKTARGET;
+temperature return TOKTEMPERATURE;
+\n /* ignore end of line */;
+[ \t]+ /* ignore whitespace */;
+%%
Added: sandbox/trunk/src/flex/ex5/ex5.y
===================================================================
--- sandbox/trunk/src/flex/ex5/ex5.y (rev 0)
+++ sandbox/trunk/src/flex/ex5/ex5.y 2008-06-03 01:50:46 UTC (rev 846)
@@ -0,0 +1,53 @@
+%{
+#include <stdio.h>
+#include <string.h>
+
+int yylex(void);
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+%}
+
+%token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE
+
+%%
+
+commands: /* empty */
+ | commands command
+ ;
+
+command:
+ heat_switch
+ |
+ target_set
+ ;
+
+heat_switch:
+ TOKHEAT STATE
+ {
+ printf("\tHeat turned %s\n", $2 ? "on" : "off");
+ }
+ ;
+
+target_set:
+ TOKTARGET TOKTEMPERATURE NUMBER
+ {
+ printf("\tTemperature set to %d\n", $3);
+ }
+ ;
+
+%%
+
+int main()
+{
+ yyparse();
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-06-03 01:51:14
|
Revision: 847
http://assorted.svn.sourceforge.net/assorted/?rev=847&view=rev
Author: yangzhang
Date: 2008-06-02 18:51:23 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
renamed flex to flex-bison
Added Paths:
-----------
sandbox/trunk/src/flex-bison/
Removed Paths:
-------------
sandbox/trunk/src/flex/
Copied: sandbox/trunk/src/flex-bison (from rev 846, sandbox/trunk/src/flex)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-06-03 01:55:06
|
Revision: 848
http://assorted.svn.sourceforge.net/assorted/?rev=848&view=rev
Author: yangzhang
Date: 2008-06-02 18:55:13 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
reorganized flex/bison files
Added Paths:
-----------
sandbox/trunk/src/flex-bison/calc/
sandbox/trunk/src/flex-bison/lex-yacc-howto/
sandbox/trunk/src/flex-bison/lex-yacc-howto/ex1/
sandbox/trunk/src/flex-bison/lex-yacc-howto/ex2/
sandbox/trunk/src/flex-bison/lex-yacc-howto/ex3/
sandbox/trunk/src/flex-bison/lex-yacc-howto/ex4/
sandbox/trunk/src/flex-bison/lex-yacc-howto/ex5/
Removed Paths:
-------------
sandbox/trunk/src/bison/
sandbox/trunk/src/flex-bison/ex1/
sandbox/trunk/src/flex-bison/ex2/
sandbox/trunk/src/flex-bison/ex3/
sandbox/trunk/src/flex-bison/ex4/
sandbox/trunk/src/flex-bison/ex5/
Copied: sandbox/trunk/src/flex-bison/calc (from rev 845, sandbox/trunk/src/bison/calc)
Copied: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex1 (from rev 847, sandbox/trunk/src/flex-bison/ex1)
Copied: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex2 (from rev 847, sandbox/trunk/src/flex-bison/ex2)
Copied: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex3 (from rev 847, sandbox/trunk/src/flex-bison/ex3)
Copied: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex4 (from rev 847, sandbox/trunk/src/flex-bison/ex4)
Copied: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex5 (from rev 847, sandbox/trunk/src/flex-bison/ex5)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yan...@us...> - 2008-07-07 21:37:07
|
Revision: 877
http://assorted.svn.sourceforge.net/assorted/?rev=877&view=rev
Author: yangzhang
Date: 2008-07-07 14:37:10 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
more sandbox
Modified Paths:
--------------
sandbox/trunk/src/cc/longlongint.cc
Added Paths:
-----------
sandbox/trunk/src/java/TypedFactory.java
Modified: sandbox/trunk/src/cc/longlongint.cc
===================================================================
--- sandbox/trunk/src/cc/longlongint.cc 2008-07-07 21:36:37 UTC (rev 876)
+++ sandbox/trunk/src/cc/longlongint.cc 2008-07-07 21:37:10 UTC (rev 877)
@@ -32,3 +32,22 @@
cout << typeid(string).name() << endl;
return 0;
}
+
+/**
+ * on 64-bit machines:
+ *
+ * 32
+ * 32
+ * 8
+ * 8
+ * 8
+ * 8
+ * 8
+ * 8
+ * l
+ * x
+ * Ss
+ *
+ * on 32-bit machines:
+ *
+ */
Added: sandbox/trunk/src/java/TypedFactory.java
===================================================================
--- sandbox/trunk/src/java/TypedFactory.java (rev 0)
+++ sandbox/trunk/src/java/TypedFactory.java 2008-07-07 21:37:10 UTC (rev 877)
@@ -0,0 +1,25 @@
+//class Consumer<T> {
+// public Consumer(TypedFactory factory) { this.factory = factory; }
+// public T consume() { return factory.create<T>(); }
+// private TypedFactory factory;
+//}
+
+public class TypedFactory {
+ public static void main(String[] args) {
+ TypedFactory factory = new TypedFactory();
+ //Consumer<String> consumer = new Consumer<String>(factory);
+ //String string = consumer.consume();
+
+ // Explicitly specifying the type is not allowed; it must be possible to
+ // determine T from a parameter.
+ // factory.create<String>();
+ factory.create(String.class);
+ }
+
+ public <T> T create(Class<T> cls) {
+ if (cls.equals(String.class)) return (T) "hello!";
+ else throw new Exception("unknown type");
+ }
+}
+
+// vim:et:sw=2:ts=2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|