forked from preda/arithmetic
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
11,224 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,22 @@ | ||
"Arity" arithmetic engine. | ||
|
||
Copyright (C) 2007-2009 Mihai Preda. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
|
||
Use: | ||
|
||
python build.py | ||
java -jar rel/arity-2.0.0.jar | ||
java -jar rel/arity-2.0.0.jar "1+2" |
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,143 @@ | ||
#!/usr/bin/python | ||
|
||
# Copyright (C) 2007-2009 Mihai Preda. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
bytecodesStr = '''RESERVED 0 | ||
CONST 0 | ||
CALL -1 | ||
ADD 2 | ||
SUB 2 | ||
MUL 2 | ||
DIV 2 | ||
MOD 2 | ||
RND 0 | ||
UMIN 1 | ||
POWER 2 | ||
FACT 1 | ||
PERCENT 1 | ||
SQRT 1 | ||
CBRT 1 | ||
EXP 1 | ||
LN 1 | ||
SIN 1 | ||
COS 1 | ||
TAN 1 | ||
ASIN 1 | ||
ACOS 1 | ||
ATAN 1 | ||
SINH 1 | ||
COSH 1 | ||
TANH 1 | ||
ASINH 1 | ||
ACOSH 1 | ||
ATANH 1 | ||
ABS 1 | ||
FLOOR 1 | ||
CEIL 1 | ||
SIGN 1 | ||
MIN 2 | ||
MAX 2 | ||
GCD 2 | ||
COMB 2 | ||
PERM 2 | ||
LOAD0 0 | ||
LOAD1 0 | ||
LOAD2 0 | ||
LOAD3 0 | ||
LOAD4 0 | ||
REAL 1 | ||
IMAG 1''' | ||
|
||
builtins = """rnd sqrt cbrt | ||
sin cos tan asin acos atan | ||
sinh cosh tanh asinh acosh atanh | ||
exp ln | ||
abs floor ceil sign min max | ||
gcd comb perm mod real imag""" | ||
|
||
template = '''// This file is automatically generated by the build.py script. Do not edit! | ||
/* | ||
* Copyright (C) 2008-2009 Mihai Preda. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.javia.arity; | ||
class VM { | ||
static final byte | ||
%(bytecodes)s; | ||
static final String[] opcodeName = {%(names)s}; | ||
static final byte[] arity = {%(arity)s}; | ||
static final byte[] builtins = {%(builtins)s}; | ||
} | ||
''' | ||
|
||
def genVM(): | ||
bytecodes = [(y[0].lower(), int(y[1])) for y in (x.split() for x in bytecodesStr.split('\n'))] | ||
str1 = ',\n'.join(['%s = %d' % (name[0].upper(), id) for (name, id) in zip(bytecodes, xrange(256))]) | ||
names = ', '.join(['"%s"' % name[0] for name in bytecodes]) | ||
arity = ', '.join(['%d'%bc[1] for bc in bytecodes]) | ||
builtinsStr = ', '.join([s.upper() for s in builtins.split()]) | ||
|
||
fo = open('src/org/javia/arity/VM.java', 'w') | ||
fo.write(template % dict(bytecodes=str1, names=names, arity=arity, builtins=builtinsStr)) | ||
fo.close() | ||
|
||
genVM() | ||
|
||
import sys, os | ||
from os import path | ||
import shutil | ||
import glob | ||
|
||
def run(cmd): | ||
#print cmd | ||
parts = cmd.split() | ||
err = os.spawnvp(os.P_WAIT, parts[0], parts) | ||
assert not err, cmd | ||
|
||
def mkdir(*dirs): | ||
for path in dirs: | ||
try: | ||
os.makedirs(path) | ||
except OSError: | ||
pass | ||
|
||
VER='2.1.6' | ||
|
||
mkdir('tmp/class', 'rel') | ||
|
||
run('rm -rf tmp/class/org') | ||
name = 'rel/arity-'+VER+'' | ||
run("javac -sourcepath src -d tmp/class src/org/javia/arity/UnitTest.java") | ||
run("jar cfe %(name)s.jar org.javia.arity.UnitTest -C tmp/class ." % dict(name=name)) | ||
#run("javadoc -notimestamp -nodeprecatedlist -notree -noindex -nohelp -noqualifier java.lang -d javadoc -sourcepath src org.javia.arity") |
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,51 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<!--NewPage--> | ||
<HTML> | ||
<HEAD> | ||
<TITLE> | ||
All Classes | ||
</TITLE> | ||
|
||
|
||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> | ||
|
||
|
||
</HEAD> | ||
|
||
<BODY BGCOLOR="white"> | ||
<FONT size="+1" CLASS="FrameHeadingFont"> | ||
<B>All Classes</B></FONT> | ||
<BR> | ||
|
||
<TABLE BORDER="0" WIDTH="100%" SUMMARY=""> | ||
<TR> | ||
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="org/javia/arity/ArityException.html" title="class in org.javia.arity" target="classFrame">ArityException</A> | ||
<BR> | ||
<A HREF="org/javia/arity/CompiledFunction.html" title="class in org.javia.arity" target="classFrame">CompiledFunction</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Complex.html" title="class in org.javia.arity" target="classFrame">Complex</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Constant.html" title="class in org.javia.arity" target="classFrame">Constant</A> | ||
<BR> | ||
<A HREF="org/javia/arity/EvalContext.html" title="class in org.javia.arity" target="classFrame">EvalContext</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Function.html" title="class in org.javia.arity" target="classFrame">Function</A> | ||
<BR> | ||
<A HREF="org/javia/arity/FunctionAndName.html" title="class in org.javia.arity" target="classFrame">FunctionAndName</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Symbol.html" title="class in org.javia.arity" target="classFrame">Symbol</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Symbols.html" title="class in org.javia.arity" target="classFrame">Symbols</A> | ||
<BR> | ||
<A HREF="org/javia/arity/SyntaxException.html" title="class in org.javia.arity" target="classFrame">SyntaxException</A> | ||
<BR> | ||
<A HREF="org/javia/arity/UnitTest.html" title="class in org.javia.arity" target="classFrame">UnitTest</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Util.html" title="class in org.javia.arity" target="classFrame">Util</A> | ||
<BR> | ||
</FONT></TD> | ||
</TR> | ||
</TABLE> | ||
|
||
</BODY> | ||
</HTML> |
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,51 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<!--NewPage--> | ||
<HTML> | ||
<HEAD> | ||
<TITLE> | ||
All Classes | ||
</TITLE> | ||
|
||
|
||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> | ||
|
||
|
||
</HEAD> | ||
|
||
<BODY BGCOLOR="white"> | ||
<FONT size="+1" CLASS="FrameHeadingFont"> | ||
<B>All Classes</B></FONT> | ||
<BR> | ||
|
||
<TABLE BORDER="0" WIDTH="100%" SUMMARY=""> | ||
<TR> | ||
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="org/javia/arity/ArityException.html" title="class in org.javia.arity">ArityException</A> | ||
<BR> | ||
<A HREF="org/javia/arity/CompiledFunction.html" title="class in org.javia.arity">CompiledFunction</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Complex.html" title="class in org.javia.arity">Complex</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Constant.html" title="class in org.javia.arity">Constant</A> | ||
<BR> | ||
<A HREF="org/javia/arity/EvalContext.html" title="class in org.javia.arity">EvalContext</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Function.html" title="class in org.javia.arity">Function</A> | ||
<BR> | ||
<A HREF="org/javia/arity/FunctionAndName.html" title="class in org.javia.arity">FunctionAndName</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Symbol.html" title="class in org.javia.arity">Symbol</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Symbols.html" title="class in org.javia.arity">Symbols</A> | ||
<BR> | ||
<A HREF="org/javia/arity/SyntaxException.html" title="class in org.javia.arity">SyntaxException</A> | ||
<BR> | ||
<A HREF="org/javia/arity/UnitTest.html" title="class in org.javia.arity">UnitTest</A> | ||
<BR> | ||
<A HREF="org/javia/arity/Util.html" title="class in org.javia.arity">Util</A> | ||
<BR> | ||
</FONT></TD> | ||
</TR> | ||
</TABLE> | ||
|
||
</BODY> | ||
</HTML> |
Oops, something went wrong.