mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-30 20:48:59 +08:00
add JavaScript Interpreter
This commit is contained in:
1 parent
7255137b0a
commit
121bb5fcdf
115 files changed
+29947
-13
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
Contributing
|
||||
===========
|
||||
|
||||
Thanks for thinking about contributing to Espruino! Anything you can add is hugely appreciated, but please can you follow a few simple rules:
|
||||
|
||||
* Keep the same coding style (See **Coding Style** below)
|
||||
* Ensure that you are not contributing someone else's code, and that you are willing to add your code under Espruino's MPL Licence
|
||||
* Make sure that what you do doesn't break the Espruino board or the other boards we build for. We can't check all the boards for every commit, so if you break something you'll annoy a whole bunch of people.
|
||||
* Be aware that Espruino is designed for Microcontrollers - with very low amounts of flash and memory. Both are at a premium so don't statically allocate variables or do other stuff that will use up memory.
|
||||
* Avoid randomly adding newlines, spaces, refactoring everything or renaming things to your own personal style (some things really could do with renaming, but please check first or we may reject your pull request)
|
||||
* Don't add a whole bunch of indirection/abstraction for the sake of it - it'll probably just use of more of our precious memory.
|
||||
* If you add a new API, try and make it familiar to Arduino/JavaScript users.
|
||||
|
||||
Target Areas
|
||||
-----------
|
||||
|
||||
We'll keep the outstanding issues in GitHub's issue list, but general stuff that would really help us is:
|
||||
|
||||
* Tests. If something doesn't work, please make a test for it. Even if you don't fix it it'll help others greatly. Bonus points if it's in a pull request :)
|
||||
* Documentation. Improving the documentation (either the EspruinoDocs project, or the auto-generated reference) would be fantastic.
|
||||
* Duplication. If the same code is used for multiple platforms, try and make sure it's shared, not duplicated.
|
||||
* Remove hard-coded stuff. Various things like the SPI filesystem are still hard-coded with ifdefs for each board - we want all that stuff to be generated from build_platform_info.py
|
||||
* Speed. There are a few areas this could be improved - but please benchmark what you're doing both before and afterwards on the Espruino board to check that what you've done helps
|
||||
* Memory Usage. Both RAM and Flash are at a premium. Ways of reducing this (including stack usage) and making usage more efficient are really appreciated.
|
||||
* JavaScript compliance (without affecting speed or memory usage too much).
|
||||
|
||||
Contributing
|
||||
-----------
|
||||
|
||||
* Please RUN THE TESTS to check that there are no regressions
|
||||
* Issue us a pull request to [www.github.com/espruino] via GitHub
|
||||
* Please keep each request small (just include one fix per request)
|
||||
|
||||
Coding Style
|
||||
-----------
|
||||
|
||||
The rough coding style is as follows, but you should get a good idea from the code. If we've missed anything obvious please let us know!
|
||||
|
||||
* 2 Spaces for indents
|
||||
* Open curly braces on the same line
|
||||
* No Tabs used
|
||||
* Use bool for booleans - not int
|
||||
* ```//``` comments for single lines, ```/* ... */``` for multiple lines
|
||||
* Half-hearted Doxygen compatibility: use ```///<``` for function declaration documentation (if on same line), and ```/** ... */``` if doing it right before a function
|
||||
* Use new lines sparingly (only where it really makes sense)
|
||||
|
||||
+515
File diff suppressed because it is too large.
Load diff
Vendored
+378
File diff suppressed because it is too large.
Load diff
+969
File diff suppressed because it is too large.
Load diff
+161
@@ -0,0 +1,161 @@
|
||||
Espruino JavaScript for Microcontrollers
|
||||
========================================
|
||||
<pre>
|
||||
_____ _
|
||||
| __|___ ___ ___ _ _|_|___ ___
|
||||
| __|_ -| . | _| | | | | . |
|
||||
|_____|___| _|_| |___|_|_|_|___|
|
||||
|_|
|
||||
</pre>
|
||||
http://www.espruino.com
|
||||
|
||||
**NOTE:** This software is beta and is provided as-is, and won't be considered even remotely final until we've released the Espruino Board. As such, don't expect support, and do expect it to change rapidly and without warning. Build your own documentation (see **Building**), as the API may be different from the one described on the Espruino website.
|
||||
|
||||
The KickStarter campaign said the Espruino Board will have some things which this repository does not yet have (like working CC3000 support). These are works in progress and should be done by the time you get your board (or will be available as a software update).
|
||||
|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
It'd probably help to read the [FAQ](http://www.espruino.com/FAQ), and specifically the page about [Performance](http://www.espruino.com/Performance) as it contains information about how Espruino itself works.
|
||||
|
||||
There's also the auto-generated [Reference](http://www.espruino.com/Reference) for JavaScript commands as well as the [Tutorials](http://www.espruino.com/Tutorials) on the website. However please note that this repository is under heavy development, and the documentation on the Espruino website will match the version [available for download](http://www.espruino.com/Download) but **not** the latest version from Git.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Please see the [LICENSE](LICENSE) file
|
||||
|
||||
|
||||
Found a Bug?
|
||||
------------
|
||||
|
||||
Please check that:
|
||||
* It hasn't [already been found](https://github.com/espruino/Espruino/issues) or [been covered on our forum](www.espruino.com/Forum)
|
||||
* You're not just looking at outdated documentation (See the [Building](#Building) section to see how to build documentation)
|
||||
|
||||
Please [submit bugs](https://github.com/espruino/Espruino/issues) with clear steps to reproduce them (and ideally a test case for the ```tests``` directory), and if at all possible try and include a patch to fix them. Please be aware that we have a whole bunch of outstanding issues (some quite large), so if you report something (especially if it doesn't contain a test or a pull request) it may not be fixed for quite some time.
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Please see [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
Current State
|
||||
-------------
|
||||
|
||||
You can download binaries from http://www.espruino.com/Download (these aren't the latest, but are more likely to work with your board)
|
||||
|
||||
Please note that this is BETA. We've been working hard on the Espruino Board support but we haven't had time to check the other boards properly.
|
||||
|
||||
* Espruino Board - working
|
||||
* Linux - working
|
||||
* STM32VLDISCOVERY - WORKING
|
||||
* STM32F3DISCOVERY - WORKING
|
||||
* STM32F4DISCOVERY - WORKING
|
||||
* STM32F429IDISCOVERY - not working, currently no LCD support
|
||||
* HY STM32 2.4" - NOT WORKING - appears to crash after startup
|
||||
* HY STM32 2.8" - WORKING, but screen is not black at startup
|
||||
* HY STM32 3.2" - WORKING
|
||||
* Olimexino - WORKING
|
||||
* Carambola - ?
|
||||
* Raspberry Pi - WORKING
|
||||
* Sony SmartWatch - USB VCP support still needed
|
||||
* MBed platforms - have not worked for a while - hardware wrapper still needed
|
||||
* Arduino - has never worked. Compiles but doesn't even get past init
|
||||
* LC-TECH STM32F103RBT6 - WORKING, but with some issues (LED inverted logic, BTN needs pullup to work)
|
||||
|
||||
Using
|
||||
-----
|
||||
|
||||
If you're using Espruino for your own personal projects - go ahead, we hope you have fun - and please let us know what you do with it on http://www.espruino.com/Forum!
|
||||
|
||||
However if you're planning on selling the Espruino software on your own board, please talk to us:
|
||||
|
||||
* Read the terms of the MPLv2 Licence that Espruino is distributed under, and make sure you comply with it
|
||||
* You won't be able to call your board 'Espruino' but you must explain clearly that it uses 'Espruino' internally (we own the trademark)
|
||||
* If you're profiting from Espruino without contributing anything back, we won't support you (or your users)
|
||||
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
Espruino is easy to build under Linux, and it is possible to build under MacOS. We'd strongly suggest that you DO NOT TRY AND BUILD UNDER WINDOWS, and instead use a Virtual Machine. There's a good post on this here: http://forum.espruino.com/conversations/151
|
||||
|
||||
We suggest that you use the CodeSourcery GCC compiler, but paths in Makefile may need changing...
|
||||
|
||||
``` BOARDNAME=1 RELEASE=1 make```
|
||||
|
||||
* See the top of Makefile for board names
|
||||
* Without `RELEASE=1`, assertions are kept in the code (which is good for debugging, bad for performance + code size)
|
||||
* `BOARDNAME=1 RELEASE=1 make serialflash` will flash to /dev/ttyUSB0 using the STM32 serial bootloader (what's needed for Espruino + HY boards)
|
||||
* `BOARDNAME=1 RELEASE=1 make flash` will flash using st-flash if discovery, or maple bootloader if using that board
|
||||
|
||||
You can build documentation by running:
|
||||
|
||||
``` python scripts/build_docs.py ```
|
||||
|
||||
This will create a file called ```functions.html```
|
||||
|
||||
Directories and Files
|
||||
---------------------
|
||||
|
||||
* `ChangeLog`: What's new
|
||||
* `TODO`: List of things to do
|
||||
* `boards/`: Information on boards, used to auto-generate a lot of the code
|
||||
* `code/`: Example JavaScript code
|
||||
* `gen/`: Auto-Generated Source Files
|
||||
* `libs/`: Optional libraries to include in Espruino (Math, Filesystem, Graphics, etc)
|
||||
* `linker/`: Linker files for various processors
|
||||
* `misc/`: random other stuff
|
||||
* `scripts/`: Scripts for generating files in gen, and for analysing code/compilation/etc
|
||||
* `src/`: Main source code
|
||||
* `targetlibs/`: Libraries for targeted architectures
|
||||
* `targets/`: Specific code for targeted architectures
|
||||
* `tests/`: JavaScript Testcases
|
||||
* `benchmark/`: JavaScript Benchmarks
|
||||
* `dist_*`: files to be copied into distribution zip file
|
||||
|
||||
Adding more devices
|
||||
-------------------
|
||||
|
||||
Currently there are a bunch of different files to modify. Eventually the plan is to fit everything into boards/BOARDNAME.py and to auto-generate the rest of the config files.
|
||||
|
||||
* Most build options handled in `Makefile`
|
||||
* Extra libraries like USB/LCD/filesystem in `Makefile`
|
||||
* Linker Scripts are in `linker/`
|
||||
* `boards/*.py` files handle loading the list of available pins so the relevant headers + docs can be created
|
||||
* Processor-specific code in `targets/stm32`, `targets/linux`, etc.
|
||||
* Processor-specific libs in `targetlibs/foo`
|
||||
* `src/jshardware.h` is effectively a simple abstraction layer for SPI/I2C/etc
|
||||
* `targets/stm32/jshardware.c` also has flash-size-specific defines
|
||||
* `libs/fat_sd` and `libs/lcd` still have some device-specific defines in too
|
||||
|
||||
Adding libraries
|
||||
-------------------
|
||||
|
||||
* Create `jswrap_mylib.c/h` in `libs/`
|
||||
* Create library functions (see examples in other jswrap files, also the comments in `scripts/common.py`)
|
||||
|
||||
|
||||
Arduino Compile (beta)
|
||||
----------------------
|
||||
* Ensure that `targets/arduino/utility` is symlinked to `src`
|
||||
* Symlink `...arduino_workspace/libraries/Espruino` to `targets/arduino`
|
||||
|
||||
Cross Compile for Raspberry Pi
|
||||
------------------------------
|
||||
```
|
||||
cd targetlibs
|
||||
mkdir raspberrypi
|
||||
cd raspberrypi
|
||||
git clone git://github.com/raspberrypi/tools.git
|
||||
sudo apt-get install ia32-libs
|
||||
```
|
||||
|
||||
Cross Compile for Carambola (OpenWRT)
|
||||
-------------------------------------
|
||||
* Follow instructions at <https://github.com/8devices/carambola> to set toolchain up in ```~/workspace/carambola```
|
||||
* Run ```CARAMBOLA=1 make```
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
这是从Espruino移植过来的javascript解释器。
|
||||
这个组件依赖newlib。需要在rtconfig.h中开启RT_USING_JS宏来开启此组件。
|
||||
+52
-13
@@ -1,19 +1,58 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
# source files
|
||||
src = Split('''
|
||||
''')
|
||||
path = [RTT_ROOT + r'/components/external/Espruino']
|
||||
path = path + [RTT_ROOT + r'/components/external/Espruino/src/']
|
||||
path = path + [RTT_ROOT + r'/components/external/Espruino/gen/']
|
||||
path = path + [RTT_ROOT + r'/components/external/Espruino/libs/']
|
||||
path = path + [RTT_ROOT + r'/components/external/Espruino/targets/rtthread/']
|
||||
|
||||
ESPRUINO_SRC_PATH = cwd + '/src'
|
||||
if GetDepend('RT_USING_JS') and not os.path.exists(ESPRUINO_SRC_PATH):
|
||||
print '================ERROR============================'
|
||||
print 'Please get espruino source files and put them under espruino folder'
|
||||
print '================================================='
|
||||
exit(0)
|
||||
src = Split("""
|
||||
src/jsdevices.c
|
||||
src/jslex.c
|
||||
src/jswrap_array.c
|
||||
src/jswrap_json.c
|
||||
src/jswrap_process.c
|
||||
src/jsutils.c
|
||||
src/jswrap_interactive.c
|
||||
src/jswrap_onewire.c
|
||||
src/jswrap_string.c
|
||||
src/jsparse.c
|
||||
src/jswrap_arraybuffer.c
|
||||
src/jswrap_modules.c
|
||||
src/jswrap_serial.c
|
||||
src/jsinteractive.c
|
||||
src/jsvar.c
|
||||
src/jswrap_io.c
|
||||
src/jswrap_pin.c
|
||||
src/jspin.c
|
||||
src/jswrap_functions.c
|
||||
src/jswrap_object.c
|
||||
src/jswrap_spi_i2c.c
|
||||
"""
|
||||
)
|
||||
|
||||
CPPPATH = [cwd + '/src', cwd + '/gen', cwd + '/libs', cwd + '/targets/rtthread']
|
||||
group = DefineGroup('Espruino', src, depend = ['RT_USING_JS'], CPPPATH = CPPPATH)
|
||||
gen = Split("""
|
||||
gen/jspininfo.c
|
||||
gen/jswrapper.c
|
||||
"""
|
||||
)
|
||||
|
||||
target = Split("""
|
||||
targets/rtthread/espruino.c
|
||||
targets/rtthread/jshardware.c
|
||||
"""
|
||||
)
|
||||
|
||||
libs = Split(
|
||||
"""
|
||||
libs/jswrap_math.c
|
||||
"""
|
||||
)
|
||||
|
||||
src += gen + target + libs
|
||||
|
||||
group = DefineGroup('Espruino', src, depend = ['RT_USING_JS', 'RT_USING_NEWLIB'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
Espruino uses a few libraries of code that have been generously given away for
|
||||
free. Their licences are included below.
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
FATFS
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module include file R0.07c (C)ChaN, 2009
|
||||
/----------------------------------------------------------------------------/
|
||||
/ FatFs module is an open source software to implement FAT file system to
|
||||
/ small embedded systems. This is a free software and is opened for education,
|
||||
/ research and commercial developments under license policy of following terms.
|
||||
/
|
||||
/ Copyright (C) 2009, ChaN, all right reserved.
|
||||
/
|
||||
/ * The FatFs module is a free software and there is NO WARRANTY.
|
||||
/ * No restriction on use. You can use, modify and redistribute it for
|
||||
/ personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
|
||||
/ * Redistributions of source code must retain the above copyright notice.*/
|
||||
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
FATFS to SPI bridge
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
/* Copyright (c) 2009, Martin Thomas, ChaN
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of the copyright holders nor the names of
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE. */
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
FATFS to SDIO bridge
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
/* author: ickle */ - No details given with source code. If you have
|
||||
anything you'd like to include, pleas e-mail us and let us know.
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
8x8 LCD Font
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
http://forum.osdev.org/viewtopic.php?f=2&t=22033
|
||||
|
||||
Created Sunday, May 23, 2010 by Quinn Evans
|
||||
Renamed and updated Monday 24, 2010
|
||||
|
||||
This font (Vincent) is released by me into the public domain. I claim no
|
||||
copyright, and hereby make this software available to the public for any use,
|
||||
at any time, free of restrictions, legal or otherwise.
|
||||
*/
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
CC3000 Host Driver Implementation.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
Neither the name of Texas Instruments Incorporated nor the names of
|
||||
its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
_____ _
|
||||
| __|___ ___ ___ _ _|_|___ ___
|
||||
| __|_ -| . | _| | | | | . |
|
||||
|_____|___| _|_| |___|_|_|_|___|
|
||||
|_|
|
||||
Copyright 2013 Gordon Williams
|
||||
|
||||
http://www.espruino.com
|
||||
|
||||
--------------------------------------------------------------
|
||||
|
||||
There are a few different binaries in this ZIP file, for different
|
||||
types of Microcontroller:
|
||||
|
||||
espruino_#v##_hystm32_24_ve.bin
|
||||
- 'HY'STM32F103VET6 ARM with 2.4" LCD display
|
||||
This is available from eBay
|
||||
|
||||
espruino_#v##_hystm32_28_rb.bin
|
||||
- 'HY'STM32F103RBT6 ARM with 2.8" LCD display
|
||||
This is available from eBay
|
||||
|
||||
espruino_#v##_hystm32_32_vc.bin
|
||||
- 'HY'STM32F103VCT6 ARM with 3.2" LCD display
|
||||
This is available from eBay
|
||||
|
||||
espruino_#v##_olimexino_stm32.bin
|
||||
- You will need to overwrite the Maple bootloader to install this.
|
||||
Espruino is now too large to fit in flash alongside it.
|
||||
- Olimexino-STM32 Arduino form factor board
|
||||
- Leaf Labs Maple Arduino form factor board
|
||||
|
||||
espruino_#v##_stm32vldiscovery.bin
|
||||
- STM32VLDISCOVERY board
|
||||
|
||||
espruino_#v##_stm32f3discovery.bin
|
||||
- STM32F3DISCOVERY board
|
||||
|
||||
espruino_#v##_stm32f4discovery.bin
|
||||
- STM32F4DISCOVERY board
|
||||
|
||||
espruino_#v##_raspberrypi
|
||||
- Raspberry Pi executable (just copy it to the device and run it)
|
||||
NOTE: There is GPIO support (which requires you to run Espruino as root)
|
||||
however there is no Serial, SPI, OneWire or I2C support at the moment so
|
||||
you're pretty limited!
|
||||
|
||||
For information on devices, and on how to flash these binary files on to
|
||||
each device, please see our website, http://www.espruino.com
|
||||
|
||||
NOTES:
|
||||
|
||||
* On the STM32F4DISCOVERY the default USART is USART2 (because
|
||||
USART1 shares some pins with USB). This means you must connect
|
||||
serial connections to PA2/PA3 NOT PA9/PA10 as you would for
|
||||
the STM32VLDISCOVERY.
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
This directory contains auto-generated files
|
||||
@@ -0,0 +1,7 @@
|
||||
// auto-generated pin info file
|
||||
// for board LINUX
|
||||
#include "jspininfo.h"
|
||||
|
||||
const JshPinInfo pinInfo[JSH_PIN_COUNT] = {
|
||||
};
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// auto-generated pin info file
|
||||
// for board LINUX
|
||||
#ifndef __JSPININFO_H_
|
||||
#define __JSPININFO_H_
|
||||
|
||||
#include "jspin.h"
|
||||
|
||||
#define JSH_PIN_COUNT 0
|
||||
|
||||
#define JSH_PORTA_COUNT 0
|
||||
#define JSH_PORTB_COUNT 0
|
||||
#define JSH_PORTC_COUNT 0
|
||||
#define JSH_PORTD_COUNT 0
|
||||
#define JSH_PORTE_COUNT 0
|
||||
#define JSH_PORTF_COUNT 0
|
||||
#define JSH_PORTG_COUNT 0
|
||||
#define JSH_PORTH_COUNT 0
|
||||
#define JSH_PORTA_OFFSET -1
|
||||
#define JSH_PORTB_OFFSET -1
|
||||
#define JSH_PORTC_OFFSET -1
|
||||
#define JSH_PORTD_OFFSET -1
|
||||
#define JSH_PORTE_OFFSET -1
|
||||
#define JSH_PORTF_OFFSET -1
|
||||
#define JSH_PORTG_OFFSET -1
|
||||
#define JSH_PORTH_OFFSET -1
|
||||
|
||||
#define JSH_PININFO_FUNCTIONS 0
|
||||
|
||||
typedef struct JshPinInfo {
|
||||
JsvPinInfoPort port;
|
||||
JsvPinInfoPin pin;
|
||||
JsvPinInfoAnalog analog; // TODO: maybe we don't need to store analogs separately
|
||||
JshPinFunction functions[JSH_PININFO_FUNCTIONS];
|
||||
} PACKED_FLAGS JshPinInfo;
|
||||
|
||||
extern const JshPinInfo pinInfo[JSH_PIN_COUNT];
|
||||
|
||||
#endif
|
||||
|
||||
+1203
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,53 @@
|
||||
|
||||
// Automatically generated header file for LINUX
|
||||
// Generated by scripts/build_platform_config.py
|
||||
|
||||
#ifndef _PLATFORM_CONFIG_H
|
||||
#define _PLATFORM_CONFIG_H
|
||||
#include <rtthread.h>
|
||||
|
||||
#define PC_BOARD_ID "LINUX"
|
||||
#define PC_BOARD_CHIP "LINUX"
|
||||
#define PC_BOARD_CHIP_FAMILY "LINUX"
|
||||
|
||||
|
||||
|
||||
// SYSTICK is the counter that counts up and that we use as the real-time clock
|
||||
// The smaller this is, the longer we spend in interrupts, but also the more we can sleep!
|
||||
#define SYSTICK_RANGE 0x1000000 // the Maximum (it is a 24 bit counter) - on Olimexino this is about 0.6 sec
|
||||
#define SYSTICKS_BEFORE_USB_DISCONNECT 2
|
||||
|
||||
#define DEFAULT_BUSY_PIN_INDICATOR (Pin)-1 // no indicator
|
||||
#define DEFAULT_SLEEP_PIN_INDICATOR (Pin)-1 // no indicator
|
||||
|
||||
// When to send the message that the IO buffer is getting full
|
||||
#define IOBUFFER_XOFF ((TXBUFFERMASK)*6/8)
|
||||
// When to send the message that we can start receiving again
|
||||
#define IOBUFFER_XON ((TXBUFFERMASK)*3/8)
|
||||
|
||||
|
||||
|
||||
#define RAM_TOTAL (-1*1024)
|
||||
#define FLASH_TOTAL (-1*1024)
|
||||
|
||||
#define RESIZABLE_JSVARS // Allocate variables in blocks using malloc
|
||||
|
||||
#define USARTS 0
|
||||
#define SPIS 1
|
||||
#define I2CS 0
|
||||
#define ADCS 0
|
||||
#define DACS 0
|
||||
|
||||
#define DEFAULT_CONSOLE_DEVICE EV_USBSERIAL
|
||||
|
||||
#define IOBUFFERMASK 31 // (max 255) amount of items in event buffer - events take ~9 bytes each
|
||||
#define TXBUFFERMASK 31 // (max 255)
|
||||
|
||||
|
||||
// definition to avoid compilation when Pin/platform config is not defined
|
||||
#define IS_PIN_USED_INTERNALLY(PIN) ((false))
|
||||
#define IS_PIN_A_LED(PIN) ((false))
|
||||
#define IS_PIN_A_BUTTON(PIN) ((false))
|
||||
|
||||
#endif // _PLATFORM_CONFIG_H
|
||||
|
||||
+233
File diff suppressed because it is too large.
Load diff
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Contains built-in functions for Maths
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsutils.h"
|
||||
#include "jsvar.h"
|
||||
|
||||
#ifdef ARM
|
||||
#include "mconf.h"
|
||||
#include "protos.h"
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
|
||||
JsVarInt jswrap_integer_valueOf(JsVar *v);
|
||||
JsVarFloat jswrap_math_abs(JsVarFloat x);
|
||||
double jswrap_math_pow(double x, double y);
|
||||
JsVarFloat jswrap_math_clip(JsVarFloat x, JsVarFloat min, JsVarFloat max);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
|
||||
This suite of C language elementary functions offers support for
|
||||
not-a-number (NaN) and infinity rules, subnormal numbers, and minus
|
||||
zero as described by IEEE standard 754 and the Numerical C Extensions
|
||||
Group (NCEG). For a variety of reasons, many computers cannot take
|
||||
advantage of these features. You can disable any or all of them by
|
||||
removing the corresponding preprocessor macros. Check the files
|
||||
mconf.h and const.c carefully to be sure they are appropriate for your
|
||||
system.
|
||||
|
||||
|
||||
|
||||
------------------------------------------
|
||||
|
||||
http://www.netlib.org/cephes/readme
|
||||
|
||||
Some software in this archive may be from the book _Methods and
|
||||
Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster
|
||||
International, 1989) or from the Cephes Mathematical Library, a
|
||||
commercial product. In either event, it is copyrighted by the author.
|
||||
What you see here may be used freely but it comes with no support or
|
||||
guarantee.
|
||||
|
||||
The two known misprints in the book are repaired here in the
|
||||
source listings for the gamma function and the incomplete beta
|
||||
integral.
|
||||
|
||||
|
||||
Stephen L. Moshier
|
||||
moshier@na-net.ornl.gov
|
||||
|
||||
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/* acosh.c
|
||||
*
|
||||
* Inverse hyperbolic cosine
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, acosh();
|
||||
*
|
||||
* y = acosh( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns inverse hyperbolic cosine of argument.
|
||||
*
|
||||
* If 1 <= x < 1.5, a rational approximation
|
||||
*
|
||||
* sqrt(z) * P(z)/Q(z)
|
||||
*
|
||||
* where z = x-1, is used. Otherwise,
|
||||
*
|
||||
* acosh(x) = log( x + sqrt( (x-1)(x+1) ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC 1,3 30000 4.2e-17 1.1e-17
|
||||
* IEEE 1,3 30000 4.6e-16 8.7e-17
|
||||
*
|
||||
*
|
||||
* ERROR MESSAGES:
|
||||
*
|
||||
* message condition value returned
|
||||
* acosh domain |x| < 1 NAN
|
||||
*
|
||||
*/
|
||||
|
||||
/* acosh.c */
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
|
||||
/* acosh(z) = sqrt(x) * R(x), z = x + 1, interval 0 < x < 0.5 */
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef UNK
|
||||
const static double P[] = {
|
||||
1.18801130533544501356E2,
|
||||
3.94726656571334401102E3,
|
||||
3.43989375926195455866E4,
|
||||
1.08102874834699867335E5,
|
||||
1.10855947270161294369E5
|
||||
};
|
||||
const static double Q[] = {
|
||||
/* 1.00000000000000000000E0,*/
|
||||
1.86145380837903397292E2,
|
||||
4.15352677227719831579E3,
|
||||
2.97683430363289370382E4,
|
||||
8.29725251988426222434E4,
|
||||
7.83869920495893927727E4
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef DEC
|
||||
static unsigned short P[] = {
|
||||
0041755,0115055,0144002,0146444,
|
||||
0043166,0132103,0155150,0150302,
|
||||
0044006,0057360,0003021,0162753,
|
||||
0044323,0021557,0175225,0056253,
|
||||
0044330,0101771,0040046,0006636
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0040200,0000000,0000000,0000000,*/
|
||||
0042072,0022467,0126670,0041232,
|
||||
0043201,0146066,0152142,0034015,
|
||||
0043750,0110257,0121165,0026100,
|
||||
0044242,0007103,0034667,0033173,
|
||||
0044231,0014576,0175573,0017472
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
static unsigned short P[] = {
|
||||
0x59a4,0xb900,0xb345,0x405d,
|
||||
0x1a18,0x7b4d,0xd688,0x40ae,
|
||||
0x3cbd,0x00c2,0xcbde,0x40e0,
|
||||
0xab95,0xff52,0x646d,0x40fa,
|
||||
0xc1b4,0x2804,0x107f,0x40fb
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0x0000,0x0000,0x0000,0x3ff0,*/
|
||||
0x0853,0xf5b7,0x44a6,0x4067,
|
||||
0x4702,0xda8c,0x3986,0x40b0,
|
||||
0xa588,0xf44e,0x1215,0x40dd,
|
||||
0xe6cf,0x6736,0x41c8,0x40f4,
|
||||
0x63e7,0xdf6f,0x232f,0x40f3
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
static unsigned short P[] = {
|
||||
0x405d,0xb345,0xb900,0x59a4,
|
||||
0x40ae,0xd688,0x7b4d,0x1a18,
|
||||
0x40e0,0xcbde,0x00c2,0x3cbd,
|
||||
0x40fa,0x646d,0xff52,0xab95,
|
||||
0x40fb,0x107f,0x2804,0xc1b4
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
0x4067,0x44a6,0xf5b7,0x0853,
|
||||
0x40b0,0x3986,0xda8c,0x4702,
|
||||
0x40dd,0x1215,0xf44e,0xa588,
|
||||
0x40f4,0x41c8,0x6736,0xe6cf,
|
||||
0x40f3,0x232f,0xdf6f,0x63e7,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
extern double log ( double );
|
||||
extern double sqrt ( double );
|
||||
#else
|
||||
double log(), sqrt(), polevl(), p1evl();
|
||||
#endif
|
||||
extern double LOGE2, INFINITY, NAN;
|
||||
|
||||
double acosh(x)
|
||||
double x;
|
||||
{
|
||||
double a, z;
|
||||
|
||||
if( x < 1.0 )
|
||||
{
|
||||
mtherr( "acosh", DOMAIN );
|
||||
return(NAN);
|
||||
}
|
||||
|
||||
if( x > 1.0e8 )
|
||||
{
|
||||
#ifdef INFINITIES
|
||||
if( x == INFINITY )
|
||||
return( INFINITY );
|
||||
#endif
|
||||
return( log(x) + LOGE2 );
|
||||
}
|
||||
|
||||
z = x - 1.0;
|
||||
|
||||
if( z < 0.5 )
|
||||
{
|
||||
a = sqrt(z) * (polevl(z, P, 4) / p1evl(z, Q, 5) );
|
||||
return( a );
|
||||
}
|
||||
|
||||
a = sqrt( z*(x+1.0) );
|
||||
return( log(x + a) );
|
||||
}
|
||||
+324
File diff suppressed because it is too large.
Load diff
+165
@@ -0,0 +1,165 @@
|
||||
/* asinh.c
|
||||
*
|
||||
* Inverse hyperbolic sine
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, asinh();
|
||||
*
|
||||
* y = asinh( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns inverse hyperbolic sine of argument.
|
||||
*
|
||||
* If |x| < 0.5, the function is approximated by a rational
|
||||
* form x + x**3 P(x)/Q(x). Otherwise,
|
||||
*
|
||||
* asinh(x) = log( x + sqrt(1 + x*x) ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC -3,3 75000 4.6e-17 1.1e-17
|
||||
* IEEE -1,1 30000 3.7e-16 7.8e-17
|
||||
* IEEE 1,3 30000 2.5e-16 6.7e-17
|
||||
*
|
||||
*/
|
||||
|
||||
/* asinh.c */
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef UNK
|
||||
const static double P[] = {
|
||||
-4.33231683752342103572E-3,
|
||||
-5.91750212056387121207E-1,
|
||||
-4.37390226194356683570E0,
|
||||
-9.09030533308377316566E0,
|
||||
-5.56682227230859640450E0
|
||||
};
|
||||
const static double Q[] = {
|
||||
/* 1.00000000000000000000E0,*/
|
||||
1.28757002067426453537E1,
|
||||
4.86042483805291788324E1,
|
||||
6.95722521337257608734E1,
|
||||
3.34009336338516356383E1
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef DEC
|
||||
static unsigned short P[] = {
|
||||
0136215,0173033,0110410,0105475,
|
||||
0140027,0076361,0020056,0164520,
|
||||
0140613,0173401,0160136,0053142,
|
||||
0141021,0070744,0000503,0176261,
|
||||
0140662,0021550,0073106,0133351
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/* 0040200,0000000,0000000,0000000,*/
|
||||
0041116,0001336,0034120,0173054,
|
||||
0041502,0065300,0013144,0021231,
|
||||
0041613,0022376,0035516,0153063,
|
||||
0041405,0115216,0054265,0004557
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
static unsigned short P[] = {
|
||||
0x1168,0x7221,0xbec3,0xbf71,
|
||||
0xdd2a,0x2405,0xef9e,0xbfe2,
|
||||
0xcacc,0x3c0b,0x7ee0,0xc011,
|
||||
0x7f96,0x8028,0x2e3c,0xc022,
|
||||
0xd6dd,0x0ec8,0x446d,0xc016
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/* 0x0000,0x0000,0x0000,0x3ff0,*/
|
||||
0x1ec5,0xc70a,0xc05b,0x4029,
|
||||
0x8453,0x02cc,0x4d58,0x4048,
|
||||
0xdac6,0xc769,0x649f,0x4051,
|
||||
0xa12e,0xcb16,0xb351,0x4040
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
static unsigned short P[] = {
|
||||
0xbf71,0xbec3,0x7221,0x1168,
|
||||
0xbfe2,0xef9e,0x2405,0xdd2a,
|
||||
0xc011,0x7ee0,0x3c0b,0xcacc,
|
||||
0xc022,0x2e3c,0x8028,0x7f96,
|
||||
0xc016,0x446d,0x0ec8,0xd6dd
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
0x4029,0xc05b,0xc70a,0x1ec5,
|
||||
0x4048,0x4d58,0x02cc,0x8453,
|
||||
0x4051,0x649f,0xc769,0xdac6,
|
||||
0x4040,0xb351,0xcb16,0xa12e
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
extern double sqrt ( double );
|
||||
extern double log ( double );
|
||||
#else
|
||||
double log(), sqrt(), polevl(), p1evl();
|
||||
#endif
|
||||
extern double LOGE2, INFINITY;
|
||||
|
||||
double asinh(xx)
|
||||
double xx;
|
||||
{
|
||||
double a, z, x;
|
||||
int sign;
|
||||
|
||||
#ifdef MINUSZERO
|
||||
if( xx == 0.0 )
|
||||
return(xx);
|
||||
#endif
|
||||
if( xx < 0.0 )
|
||||
{
|
||||
sign = -1;
|
||||
x = -xx;
|
||||
}
|
||||
else
|
||||
{
|
||||
sign = 1;
|
||||
x = xx;
|
||||
}
|
||||
|
||||
if( x > 1.0e8 )
|
||||
{
|
||||
#ifdef INFINITIES
|
||||
if( x == INFINITY )
|
||||
return(xx);
|
||||
#endif
|
||||
return( sign * (log(x) + LOGE2) );
|
||||
}
|
||||
|
||||
z = x * x;
|
||||
if( x < 0.5 )
|
||||
{
|
||||
a = ( polevl(z, P, 4)/p1evl(z, Q, 4) ) * z;
|
||||
a = a * x + x;
|
||||
if( sign < 0 )
|
||||
a = -a;
|
||||
return(a);
|
||||
}
|
||||
|
||||
a = sqrt( z + 1.0 );
|
||||
return( sign * log(x + a) );
|
||||
}
|
||||
+393
File diff suppressed because it is too large.
Load diff
+156
@@ -0,0 +1,156 @@
|
||||
/* atanh.c
|
||||
*
|
||||
* Inverse hyperbolic tangent
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, atanh();
|
||||
*
|
||||
* y = atanh( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns inverse hyperbolic tangent of argument in the range
|
||||
* MINLOG to MAXLOG.
|
||||
*
|
||||
* If |x| < 0.5, the rational form x + x**3 P(x)/Q(x) is
|
||||
* employed. Otherwise,
|
||||
* atanh(x) = 0.5 * log( (1+x)/(1-x) ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC -1,1 50000 2.4e-17 6.4e-18
|
||||
* IEEE -1,1 30000 1.9e-16 5.2e-17
|
||||
*
|
||||
*/
|
||||
|
||||
/* atanh.c */
|
||||
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright (C) 1987, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef UNK
|
||||
const static double P[] = {
|
||||
-8.54074331929669305196E-1,
|
||||
1.20426861384072379242E1,
|
||||
-4.61252884198732692637E1,
|
||||
6.54566728676544377376E1,
|
||||
-3.09092539379866942570E1
|
||||
};
|
||||
const static double Q[] = {
|
||||
/* 1.00000000000000000000E0,*/
|
||||
-1.95638849376911654834E1,
|
||||
1.08938092147140262656E2,
|
||||
-2.49839401325893582852E2,
|
||||
2.52006675691344555838E2,
|
||||
-9.27277618139601130017E1
|
||||
};
|
||||
#endif
|
||||
#ifdef DEC
|
||||
static unsigned short P[] = {
|
||||
0140132,0122235,0105775,0130300,
|
||||
0041100,0127327,0124407,0034722,
|
||||
0141470,0100113,0115607,0130535,
|
||||
0041602,0164721,0003257,0013673,
|
||||
0141367,0043046,0166673,0045750
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0040200,0000000,0000000,0000000,*/
|
||||
0141234,0101326,0015460,0134564,
|
||||
0041731,0160115,0116451,0032045,
|
||||
0142171,0153343,0000532,0167226,
|
||||
0042174,0000665,0077604,0000310,
|
||||
0141671,0072235,0031114,0074377
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
static unsigned short P[] = {
|
||||
0xb618,0xb17f,0x5493,0xbfeb,
|
||||
0xe73a,0xf520,0x15da,0x4028,
|
||||
0xf62c,0x7370,0x1009,0xc047,
|
||||
0xe2f7,0x20d5,0x5d3a,0x4050,
|
||||
0x697d,0xddb7,0xe8c4,0xc03e
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0x0000,0x0000,0x0000,0x3ff0,*/
|
||||
0x172f,0xc366,0x905a,0xc033,
|
||||
0x2685,0xb3a5,0x3c09,0x405b,
|
||||
0x5dd3,0x602b,0x3adc,0xc06f,
|
||||
0x8019,0xaff0,0x8036,0x406f,
|
||||
0x8f20,0xa649,0x2e93,0xc057
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
static unsigned short P[] = {
|
||||
0xbfeb,0x5493,0xb17f,0xb618,
|
||||
0x4028,0x15da,0xf520,0xe73a,
|
||||
0xc047,0x1009,0x7370,0xf62c,
|
||||
0x4050,0x5d3a,0x20d5,0xe2f7,
|
||||
0xc03e,0xe8c4,0xddb7,0x697d
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
0xc033,0x905a,0xc366,0x172f,
|
||||
0x405b,0x3c09,0xb3a5,0x2685,
|
||||
0xc06f,0x3adc,0x602b,0x5dd3,
|
||||
0x406f,0x8036,0xaff0,0x8019,
|
||||
0xc057,0x2e93,0xa649,0x8f20
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double fabs ( double );
|
||||
extern double log ( double x );
|
||||
extern double polevl ( double x, void *P, int N );
|
||||
extern double p1evl ( double x, void *P, int N );
|
||||
#else
|
||||
double fabs(), log(), polevl(), p1evl();
|
||||
#endif
|
||||
extern double INFINITY, NAN;
|
||||
|
||||
double atanh(x)
|
||||
double x;
|
||||
{
|
||||
double s, z;
|
||||
|
||||
#ifdef MINUSZERO
|
||||
if( x == 0.0 )
|
||||
return(x);
|
||||
#endif
|
||||
z = fabs(x);
|
||||
if( z >= 1.0 )
|
||||
{
|
||||
if( x == 1.0 )
|
||||
return( INFINITY );
|
||||
if( x == -1.0 )
|
||||
return( -INFINITY );
|
||||
mtherr( "atanh", DOMAIN );
|
||||
return( NAN );
|
||||
}
|
||||
|
||||
if( z < 1.0e-7 )
|
||||
return(x);
|
||||
|
||||
if( z < 0.5 )
|
||||
{
|
||||
z = x * x;
|
||||
s = x + x * z * (polevl(z, P, 4) / p1evl(z, Q, 5));
|
||||
return(s);
|
||||
}
|
||||
|
||||
return( 0.5 * log((1.0+x)/(1.0-x)) );
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/* cbrt.c
|
||||
*
|
||||
* Cube root
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, cbrt();
|
||||
*
|
||||
* y = cbrt( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns the cube root of the argument, which may be negative.
|
||||
*
|
||||
* Range reduction involves determining the power of 2 of
|
||||
* the argument. A polynomial of degree 2 applied to the
|
||||
* mantissa, and multiplication by the cube root of 1, 2, or 4
|
||||
* approximates the root to within about 0.1%. Then Newton's
|
||||
* iteration is used three times to converge to an accurate
|
||||
* result.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC -10,10 200000 1.8e-17 6.2e-18
|
||||
* IEEE 0,1e308 30000 1.5e-16 5.0e-17
|
||||
*
|
||||
*/
|
||||
/* cbrt.c */
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1991, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
const static double CBRT2 = 1.2599210498948731647672;
|
||||
const static double CBRT4 = 1.5874010519681994747517;
|
||||
const static double CBRT2I = 0.79370052598409973737585;
|
||||
const static double CBRT4I = 0.62996052494743658238361;
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double frexp ( double, int * );
|
||||
extern double ldexp ( double, int );
|
||||
extern int isnan ( double );
|
||||
extern int isfinite ( double );
|
||||
#else
|
||||
double frexp(), ldexp();
|
||||
int isnan(), isfinite();
|
||||
#endif
|
||||
|
||||
double cbrt(x)
|
||||
double x;
|
||||
{
|
||||
int e, rem, sign;
|
||||
double z;
|
||||
|
||||
#ifdef NANS
|
||||
if( isnan(x) )
|
||||
return x;
|
||||
#endif
|
||||
#ifdef INFINITIES
|
||||
if( !isfinite(x) )
|
||||
return x;
|
||||
#endif
|
||||
if( x == 0 )
|
||||
return( x );
|
||||
if( x > 0 )
|
||||
sign = 1;
|
||||
else
|
||||
{
|
||||
sign = -1;
|
||||
x = -x;
|
||||
}
|
||||
|
||||
z = x;
|
||||
/* extract power of 2, leaving
|
||||
* mantissa between 0.5 and 1
|
||||
*/
|
||||
x = frexp( x, &e );
|
||||
|
||||
/* Approximate cube root of number between .5 and 1,
|
||||
* peak relative error = 9.2e-6
|
||||
*/
|
||||
x = (((-1.3466110473359520655053e-1 * x
|
||||
+ 5.4664601366395524503440e-1) * x
|
||||
- 9.5438224771509446525043e-1) * x
|
||||
+ 1.1399983354717293273738e0 ) * x
|
||||
+ 4.0238979564544752126924e-1;
|
||||
|
||||
/* exponent divided by 3 */
|
||||
if( e >= 0 )
|
||||
{
|
||||
rem = e;
|
||||
e /= 3;
|
||||
rem -= 3*e;
|
||||
if( rem == 1 )
|
||||
x *= CBRT2;
|
||||
else if( rem == 2 )
|
||||
x *= CBRT4;
|
||||
}
|
||||
|
||||
|
||||
/* argument less than 1 */
|
||||
|
||||
else
|
||||
{
|
||||
e = -e;
|
||||
rem = e;
|
||||
e /= 3;
|
||||
rem -= 3*e;
|
||||
if( rem == 1 )
|
||||
x *= CBRT2I;
|
||||
else if( rem == 2 )
|
||||
x *= CBRT4I;
|
||||
e = -e;
|
||||
}
|
||||
|
||||
/* multiply by power of 2 */
|
||||
x = ldexp( x, e );
|
||||
|
||||
/* Newton iteration */
|
||||
x -= ( x - (z/(x*x)) )*0.33333333333333333333;
|
||||
#ifdef DEC
|
||||
x -= ( x - (z/(x*x)) )/3.0;
|
||||
#else
|
||||
x -= ( x - (z/(x*x)) )*0.33333333333333333333;
|
||||
#endif
|
||||
|
||||
if( sign < 0 )
|
||||
x = -x;
|
||||
return(x);
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/* chbevl.c
|
||||
*
|
||||
* Evaluate Chebyshev series
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* int N;
|
||||
* double x, y, coef[N], chebevl();
|
||||
*
|
||||
* y = chbevl( x, coef, N );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Evaluates the series
|
||||
*
|
||||
* N-1
|
||||
* - '
|
||||
* y = > coef[i] T (x/2)
|
||||
* - i
|
||||
* i=0
|
||||
*
|
||||
* of Chebyshev polynomials Ti at argument x/2.
|
||||
*
|
||||
* Coefficients are stored in reverse order, i.e. the zero
|
||||
* order term is last in the array. Note N is the number of
|
||||
* coefficients, not the order.
|
||||
*
|
||||
* If coefficients are for the interval a to b, x must
|
||||
* have been transformed to x -> 2(2x - b - a)/(b-a) before
|
||||
* entering the routine. This maps x from (a, b) to (-1, 1),
|
||||
* over which the Chebyshev polynomials are defined.
|
||||
*
|
||||
* If the coefficients are for the inverted interval, in
|
||||
* which (a, b) is mapped to (1/b, 1/a), the transformation
|
||||
* required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity,
|
||||
* this becomes x -> 4a/x - 1.
|
||||
*
|
||||
*
|
||||
*
|
||||
* SPEED:
|
||||
*
|
||||
* Taking advantage of the recurrence properties of the
|
||||
* Chebyshev polynomials, the routine requires one more
|
||||
* addition per loop than evaluating a nested polynomial of
|
||||
* the same degree.
|
||||
*
|
||||
*/
|
||||
/* chbevl.c */
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.0: April, 1987
|
||||
Copyright 1985, 1987 by Stephen L. Moshier
|
||||
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
||||
*/
|
||||
|
||||
double chbevl( x, array, n )
|
||||
double x;
|
||||
double array[];
|
||||
int n;
|
||||
{
|
||||
double b0, b1, b2, *p;
|
||||
int i;
|
||||
|
||||
p = array;
|
||||
b0 = *p++;
|
||||
b1 = 0.0;
|
||||
i = n - 1;
|
||||
|
||||
do
|
||||
{
|
||||
b2 = b1;
|
||||
b1 = b0;
|
||||
b0 = x * b1 - b2 + *p++;
|
||||
}
|
||||
while( --i );
|
||||
|
||||
return( 0.5*(b0-b2) );
|
||||
}
|
||||
+1043
File diff suppressed because it is too large.
Load diff
+461
File diff suppressed because it is too large.
Load diff
+252
File diff suppressed because it is too large.
Load diff
+83
@@ -0,0 +1,83 @@
|
||||
/* cosh.c
|
||||
*
|
||||
* Hyperbolic cosine
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, cosh();
|
||||
*
|
||||
* y = cosh( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns hyperbolic cosine of argument in the range MINLOG to
|
||||
* MAXLOG.
|
||||
*
|
||||
* cosh(x) = ( exp(x) + exp(-x) )/2.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC +- 88 50000 4.0e-17 7.7e-18
|
||||
* IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
|
||||
*
|
||||
*
|
||||
* ERROR MESSAGES:
|
||||
*
|
||||
* message condition value returned
|
||||
* cosh overflow |x| > MAXLOG MAXNUM
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* cosh.c */
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1985, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
#ifdef ANSIPROT
|
||||
extern double exp ( double );
|
||||
extern int isnan ( double );
|
||||
extern int isfinite ( double );
|
||||
#else
|
||||
double exp();
|
||||
int isnan(), isfinite();
|
||||
#endif
|
||||
extern double MAXLOG, INFINITY, LOGE2;
|
||||
|
||||
double cosh(x)
|
||||
double x;
|
||||
{
|
||||
double y;
|
||||
|
||||
#ifdef NANS
|
||||
if( isnan(x) )
|
||||
return(x);
|
||||
#endif
|
||||
if( x < 0 )
|
||||
x = -x;
|
||||
if( x > (MAXLOG + LOGE2) )
|
||||
{
|
||||
mtherr( "cosh", OVERFLOW );
|
||||
return( INFINITY );
|
||||
}
|
||||
if( x >= (MAXLOG - LOGE2) )
|
||||
{
|
||||
y = exp(0.5 * x);
|
||||
y = (0.5 * y) * y;
|
||||
return(y);
|
||||
}
|
||||
y = exp(x);
|
||||
y = 0.5 * (y + 1.0 / y);
|
||||
return( y );
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
CFLAGS= /DEBUG/NOLIST
|
||||
hfiles= mconf.h-
|
||||
|
||||
ofiles= acosh.obj-
|
||||
asin.obj-
|
||||
asinh.obj-
|
||||
atan.obj-
|
||||
atanh.obj-
|
||||
cbrt.obj-
|
||||
chbevl.obj-
|
||||
const.obj-
|
||||
cosh.obj-
|
||||
drand.obj-
|
||||
exp.obj-
|
||||
exp10.obj-
|
||||
fabs.obj-
|
||||
floor.obj-
|
||||
log.obj-
|
||||
log10.obj-
|
||||
polevl.obj-
|
||||
pow.obj-
|
||||
powi.obj-
|
||||
round.obj-
|
||||
sin.obj-
|
||||
sinh.obj-
|
||||
tan.obj-
|
||||
tanh.obj-
|
||||
unity.obj-
|
||||
sqrt.obj-
|
||||
floor.obj-
|
||||
polevl.obj-
|
||||
mtherr.obj
|
||||
|
||||
mtst.exe : $(ofiles)
|
||||
LINK mtst/option
|
||||
acosh.obj : acosh.c,$(HFILES)
|
||||
CC $(CFLAGS) acosh
|
||||
asin.obj : asin.c,$(HFILES)
|
||||
CC $(CFLAGS) asin
|
||||
asinh.obj : asinh.c,$(HFILES)
|
||||
CC $(CFLAGS) asinh
|
||||
atan.obj : atan.c,$(HFILES)
|
||||
CC $(CFLAGS) atan
|
||||
atan.obj : atan.c,$(HFILES)
|
||||
CC $(CFLAGS) atan
|
||||
atanh.obj : atanh.c,$(HFILES)
|
||||
CC $(CFLAGS) atanh
|
||||
cbrt.obj : cbrt.c,$(HFILES)
|
||||
CC $(CFLAGS) cbrt
|
||||
chbevl.obj : chbevl.c,$(HFILES)
|
||||
CC $(CFLAGS) chbevl
|
||||
const.obj : const.c,$(HFILES)
|
||||
CC $(CFLAGS) const
|
||||
cosh.obj : cosh.c,$(HFILES)
|
||||
CC $(CFLAGS) cosh
|
||||
drand.obj : drand.c,$(HFILES)
|
||||
CC $(CFLAGS) drand
|
||||
exp.obj : exp.c,$(HFILES)
|
||||
CC $(CFLAGS) exp
|
||||
exp10.obj : exp10.c,$(HFILES)
|
||||
CC $(CFLAGS) exp10
|
||||
fabs.obj : fabs.c,$(HFILES)
|
||||
CC $(CFLAGS) fabs
|
||||
floor.obj : floor.c,$(HFILES)
|
||||
CC $(CFLAGS) floor
|
||||
log.obj : log.c,$(HFILES)
|
||||
CC $(CFLAGS) log
|
||||
log10.obj : log10.c,$(HFILES)
|
||||
CC $(CFLAGS) log10
|
||||
polevl.obj : polevl.c,$(HFILES)
|
||||
CC $(CFLAGS) polevl
|
||||
pow.obj : pow.c,$(HFILES)
|
||||
CC $(CFLAGS) pow
|
||||
powi.obj : powi.c,$(HFILES)
|
||||
CC $(CFLAGS) powi
|
||||
round.obj : round.c,$(HFILES)
|
||||
CC $(CFLAGS) round
|
||||
sin.obj : sin.c,$(HFILES)
|
||||
CC $(CFLAGS) sin
|
||||
sinh.obj : sinh.c,$(HFILES)
|
||||
CC $(CFLAGS) sinh
|
||||
tan.obj : tan.c,$(HFILES)
|
||||
CC $(CFLAGS) tan
|
||||
tanh.obj : tanh.c,$(HFILES)
|
||||
CC $(CFLAGS) tanh
|
||||
unity.obj : unity.c,$(HFILES)
|
||||
CC $(CFLAGS) unity
|
||||
sqrt.obj : sqrt.c,$(HFILES)
|
||||
CC $(CFLAGS) sqrt
|
||||
mtherr.obj : mtherr.c,$(HFILES)
|
||||
CC $(CFLAGS) mtherr
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
/* drand.c
|
||||
*
|
||||
* Pseudorandom number generator
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double y, drand();
|
||||
*
|
||||
* drand( &y );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Yields a random number 1.0 <= y < 2.0.
|
||||
*
|
||||
* The three-generator congruential algorithm by Brian
|
||||
* Wichmann and David Hill (BYTE magazine, March, 1987,
|
||||
* pp 127-8) is used. The period, given by them, is
|
||||
* 6953607871644.
|
||||
*
|
||||
* Versions invoked by the different arithmetic compile
|
||||
* time options DEC, IBMPC, and MIEEE, produce
|
||||
* approximately the same sequences, differing only in the
|
||||
* least significant bits of the numbers. The UNK option
|
||||
* implements the algorithm as recommended in the BYTE
|
||||
* article. It may be used on all computers. However,
|
||||
* the low order bits of a double precision number may
|
||||
* not be adequately random, and may vary due to arithmetic
|
||||
* implementation details on different computers.
|
||||
*
|
||||
* The other compile options generate an additional random
|
||||
* integer that overwrites the low order bits of the double
|
||||
* precision number. This reduces the period by a factor of
|
||||
* two but tends to overcome the problems mentioned.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Three-generator random number algorithm
|
||||
* of Brian Wichmann and David Hill
|
||||
* BYTE magazine, March, 1987 pp 127-8
|
||||
*
|
||||
* The period, given by them, is (p-1)(q-1)(r-1)/4 = 6.95e12.
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
#ifdef ANSIPROT
|
||||
static int ranwh ( void );
|
||||
#else
|
||||
static int ranwh();
|
||||
#endif
|
||||
|
||||
static int sx = 1;
|
||||
static int sy = 10000;
|
||||
static int sz = 3000;
|
||||
|
||||
static union {
|
||||
double d;
|
||||
unsigned short s[4];
|
||||
} unkans;
|
||||
|
||||
/* This function implements the three
|
||||
* congruential generators.
|
||||
*/
|
||||
|
||||
static int ranwh()
|
||||
{
|
||||
int r, s;
|
||||
|
||||
/* sx = sx * 171 mod 30269 */
|
||||
r = sx/177;
|
||||
s = sx - 177 * r;
|
||||
sx = 171 * s - 2 * r;
|
||||
if( sx < 0 )
|
||||
sx += 30269;
|
||||
|
||||
|
||||
/* sy = sy * 172 mod 30307 */
|
||||
r = sy/176;
|
||||
s = sy - 176 * r;
|
||||
sy = 172 * s - 35 * r;
|
||||
if( sy < 0 )
|
||||
sy += 30307;
|
||||
|
||||
/* sz = 170 * sz mod 30323 */
|
||||
r = sz/178;
|
||||
s = sz - 178 * r;
|
||||
sz = 170 * s - 63 * r;
|
||||
if( sz < 0 )
|
||||
sz += 30323;
|
||||
/* The results are in static sx, sy, sz. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* drand.c
|
||||
*
|
||||
* Random double precision floating point number between 1 and 2.
|
||||
*
|
||||
* C callable:
|
||||
* drand( &x );
|
||||
*/
|
||||
|
||||
int drand( a )
|
||||
double *a;
|
||||
{
|
||||
unsigned short r;
|
||||
#ifdef DEC
|
||||
unsigned short s, t;
|
||||
#endif
|
||||
|
||||
/* This algorithm of Wichmann and Hill computes a floating point
|
||||
* result:
|
||||
*/
|
||||
ranwh();
|
||||
unkans.d = sx/30269.0 + sy/30307.0 + sz/30323.0;
|
||||
r = unkans.d;
|
||||
unkans.d -= r;
|
||||
unkans.d += 1.0;
|
||||
|
||||
/* if UNK option, do nothing further.
|
||||
* Otherwise, make a random 16 bit integer
|
||||
* to overwrite the least significant word
|
||||
* of unkans.
|
||||
*/
|
||||
#ifdef UNK
|
||||
/* do nothing */
|
||||
#else
|
||||
ranwh();
|
||||
r = sx * sy + sz;
|
||||
#endif
|
||||
|
||||
#ifdef DEC
|
||||
/* To make the numbers as similar as possible
|
||||
* in all arithmetics, the random integer has
|
||||
* to be inserted 3 bits higher up in a DEC number.
|
||||
* An alternative would be put it 3 bits lower down
|
||||
* in all the other number types.
|
||||
*/
|
||||
s = unkans.s[2];
|
||||
t = s & 07; /* save these bits to put in at the bottom */
|
||||
s &= 0177770;
|
||||
s |= (r >> 13) & 07;
|
||||
unkans.s[2] = s;
|
||||
t |= r << 3;
|
||||
unkans.s[3] = t;
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
unkans.s[0] = r;
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
unkans.s[3] = r;
|
||||
#endif
|
||||
|
||||
*a = unkans.d;
|
||||
return 0;
|
||||
}
|
||||
+543
File diff suppressed because it is too large.
Load diff
+203
File diff suppressed because it is too large.
Load diff
+223
File diff suppressed because it is too large.
Load diff
+183
@@ -0,0 +1,183 @@
|
||||
/* exp2.c
|
||||
*
|
||||
* Base 2 exponential function
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, exp2();
|
||||
*
|
||||
* y = exp2( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns 2 raised to the x power.
|
||||
*
|
||||
* Range reduction is accomplished by separating the argument
|
||||
* into an integer k and fraction f such that
|
||||
* x k f
|
||||
* 2 = 2 2.
|
||||
*
|
||||
* A Pade' form
|
||||
*
|
||||
* 1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )
|
||||
*
|
||||
* approximates 2**x in the basic range [-0.5, 0.5].
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* IEEE -1022,+1024 30000 1.8e-16 5.4e-17
|
||||
*
|
||||
*
|
||||
* See exp.c for comments on error amplification.
|
||||
*
|
||||
*
|
||||
* ERROR MESSAGES:
|
||||
*
|
||||
* message condition value returned
|
||||
* exp underflow x < -MAXL2 0.0
|
||||
* exp overflow x > MAXL2 MAXNUM
|
||||
*
|
||||
* For DEC arithmetic, MAXL2 = 127.
|
||||
* For IEEE arithmetic, MAXL2 = 1024.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef UNK
|
||||
const static double P[] = {
|
||||
2.30933477057345225087E-2,
|
||||
2.02020656693165307700E1,
|
||||
1.51390680115615096133E3,
|
||||
};
|
||||
const static double Q[] = {
|
||||
/* 1.00000000000000000000E0,*/
|
||||
2.33184211722314911771E2,
|
||||
4.36821166879210612817E3,
|
||||
};
|
||||
#define MAXL2 1024.0
|
||||
#define MINL2 -1024.0
|
||||
#endif
|
||||
|
||||
#ifdef DEC
|
||||
static unsigned short P[] = {
|
||||
0036675,0027102,0122327,0053227,
|
||||
0041241,0116724,0115412,0157355,
|
||||
0042675,0036404,0101733,0132226,
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0040200,0000000,0000000,0000000,*/
|
||||
0042151,0027450,0077732,0160744,
|
||||
0043210,0100661,0077550,0056560,
|
||||
};
|
||||
#define MAXL2 127.0
|
||||
#define MINL2 -127.0
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
static unsigned short P[] = {
|
||||
0xead3,0x549a,0xa5c8,0x3f97,
|
||||
0x5bde,0x9361,0x33ba,0x4034,
|
||||
0x7693,0x907b,0xa7a0,0x4097,
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0x0000,0x0000,0x0000,0x3ff0,*/
|
||||
0x5c3c,0x0ffb,0x25e5,0x406d,
|
||||
0x0bae,0x2fed,0x1036,0x40b1,
|
||||
};
|
||||
#define MAXL2 1024.0
|
||||
#define MINL2 -1022.0
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
static unsigned short P[] = {
|
||||
0x3f97,0xa5c8,0x549a,0xead3,
|
||||
0x4034,0x33ba,0x9361,0x5bde,
|
||||
0x4097,0xa7a0,0x907b,0x7693,
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
||||
0x406d,0x25e5,0x0ffb,0x5c3c,
|
||||
0x40b1,0x1036,0x2fed,0x0bae,
|
||||
};
|
||||
#define MAXL2 1024.0
|
||||
#define MINL2 -1022.0
|
||||
#endif
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
extern double floor ( double );
|
||||
extern double ldexp ( double, int );
|
||||
extern int isnan ( double );
|
||||
extern int isfinite ( double );
|
||||
#else
|
||||
double polevl(), p1evl(), floor(), ldexp();
|
||||
int isnan(), isfinite();
|
||||
#endif
|
||||
#ifdef INFINITIES
|
||||
extern double INFINITY;
|
||||
#endif
|
||||
extern double MAXNUM;
|
||||
|
||||
double exp2(x)
|
||||
double x;
|
||||
{
|
||||
double px, xx;
|
||||
short n;
|
||||
|
||||
#ifdef NANS
|
||||
if( isnan(x) )
|
||||
return(x);
|
||||
#endif
|
||||
if( x > MAXL2)
|
||||
{
|
||||
#ifdef INFINITIES
|
||||
return( INFINITY );
|
||||
#else
|
||||
mtherr( "exp2", OVERFLOW );
|
||||
return( MAXNUM );
|
||||
#endif
|
||||
}
|
||||
|
||||
if( x < MINL2 )
|
||||
{
|
||||
#ifndef INFINITIES
|
||||
mtherr( "exp2", UNDERFLOW );
|
||||
#endif
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
xx = x; /* save x */
|
||||
/* separate into integer and fractional parts */
|
||||
px = floor(x+0.5);
|
||||
n = px;
|
||||
x = x - px;
|
||||
|
||||
/* rational approximation
|
||||
* exp2(x) = 1 + 2xP(xx)/(Q(xx) - P(xx))
|
||||
* where xx = x**2
|
||||
*/
|
||||
xx = x * x;
|
||||
px = x * polevl( xx, P, 2 );
|
||||
x = px / ( p1evl( xx, Q, 2 ) - px );
|
||||
x = 1.0 + ldexp( x, 1 );
|
||||
|
||||
/* scale by power of 2 */
|
||||
x = ldexp( x, n );
|
||||
return(x);
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/* fabs.c
|
||||
*
|
||||
* Absolute value
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y;
|
||||
*
|
||||
* y = fabs( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns the absolute value of the argument.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "mconf.h"
|
||||
/* Avoid using UNK if possible. */
|
||||
#ifdef UNK
|
||||
#if BIGENDIAN
|
||||
#define MIEEE 1
|
||||
#else
|
||||
#define IBMPC 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
double fabs(x)
|
||||
double x;
|
||||
{
|
||||
union
|
||||
{
|
||||
double d;
|
||||
short i[4];
|
||||
} u;
|
||||
|
||||
u.d = x;
|
||||
#ifdef IBMPC
|
||||
u.i[3] &= 0x7fff;
|
||||
#endif
|
||||
#ifdef MIEEE
|
||||
u.i[0] &= 0x7fff;
|
||||
#endif
|
||||
#ifdef DEC
|
||||
u.i[3] &= 0x7fff;
|
||||
#endif
|
||||
#ifdef UNK
|
||||
if( u.d < 0 )
|
||||
u.d = -u.d;
|
||||
#endif
|
||||
return( u.d );
|
||||
}
|
||||
+453
File diff suppressed because it is too large.
Load diff
+289
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,17 @@
|
||||
fti
|
||||
y
|
||||
acosh airy asin asinh atan &
|
||||
atanh bdtr beta btdtr cbrt chbevl &
|
||||
chdtr clog cmplx const &
|
||||
cosh dawsn drand ellie ellik ellpe ellpk &
|
||||
ellpj exp exp2 exp10 expn fac &
|
||||
fdtr fresnl gamma gdtr &
|
||||
hyperg hyp2f1 incbet incbi igam igami isnan &
|
||||
iv i0 i1 jn jv j0 j1 k0 k1 kn log log2 log10 &
|
||||
mtherr nbdtr ndtr ndtri pdtr &
|
||||
polmisc polyn pow powi psi &
|
||||
rgamma round shichi sici sin sindg &
|
||||
sinh spence sqrt stdtr struve tan tandg &
|
||||
tanh unity yn zeta zetac floor fabs polevl
|
||||
fti.lst
|
||||
fti
|
||||
+237
File diff suppressed because it is too large.
Load diff
+341
File diff suppressed because it is too large.
Load diff
+250
File diff suppressed because it is too large.
Load diff
+348
File diff suppressed because it is too large.
Load diff
+199
@@ -0,0 +1,199 @@
|
||||
/* mconf.h
|
||||
*
|
||||
* Common include file for math routines
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* #include "mconf.h"
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* This file contains definitions for error codes that are
|
||||
* passed to the common error handling routine mtherr()
|
||||
* (which see).
|
||||
*
|
||||
* The file also includes a conditional assembly definition
|
||||
* for the type of computer arithmetic (IEEE, DEC, Motorola
|
||||
* IEEE, or UNKnown).
|
||||
*
|
||||
* For Digital Equipment PDP-11 and VAX computers, certain
|
||||
* IBM systems, and others that use numbers with a 56-bit
|
||||
* significand, the symbol DEC should be defined. In this
|
||||
* mode, most floating point constants are given as arrays
|
||||
* of octal integers to eliminate decimal to binary conversion
|
||||
* errors that might be introduced by the compiler.
|
||||
*
|
||||
* For little-endian computers, such as IBM PC, that follow the
|
||||
* IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE
|
||||
* Std 754-1985), the symbol IBMPC should be defined. These
|
||||
* numbers have 53-bit significands. In this mode, constants
|
||||
* are provided as arrays of hexadecimal 16 bit integers.
|
||||
*
|
||||
* Big-endian IEEE format is denoted MIEEE. On some RISC
|
||||
* systems such as Sun SPARC, double precision constants
|
||||
* must be stored on 8-byte address boundaries. Since integer
|
||||
* arrays may be aligned differently, the MIEEE configuration
|
||||
* may fail on such machines.
|
||||
*
|
||||
* To accommodate other types of computer arithmetic, all
|
||||
* constants are also provided in a normal decimal radix
|
||||
* which one can hope are correctly converted to a suitable
|
||||
* format by the available C language compiler. To invoke
|
||||
* this mode, define the symbol UNK.
|
||||
*
|
||||
* An important difference among these modes is a predefined
|
||||
* set of machine arithmetic constants for each. The numbers
|
||||
* MACHEP (the machine roundoff error), MAXNUM (largest number
|
||||
* represented), and several other parameters are preset by
|
||||
* the configuration symbol. Check the file const.c to
|
||||
* ensure that these values are correct for your computer.
|
||||
*
|
||||
* Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL
|
||||
* may fail on many systems. Verify that they are supposed
|
||||
* to work on your computer.
|
||||
*/
|
||||
/*
|
||||
Cephes Math Library Release 2.3: June, 1995
|
||||
Copyright 1984, 1987, 1989, 1995 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
|
||||
/* Define if the `long double' type works. */
|
||||
#define HAVE_LONG_DOUBLE 1
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if your processor stores words with the most significant
|
||||
byte first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Define if floating point words are bigendian. */
|
||||
/* #undef FLOAT_WORDS_BIGENDIAN */
|
||||
|
||||
/* The number of bytes in a int. */
|
||||
#define SIZEOF_INT 4
|
||||
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "cephes"
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "2.7"
|
||||
|
||||
/* Constant definitions for math error conditions
|
||||
*/
|
||||
|
||||
#define DOMAIN 1 /* argument domain error */
|
||||
#define SING 2 /* argument singularity */
|
||||
#define OVERFLOW 3 /* overflow range error */
|
||||
#define UNDERFLOW 4 /* underflow range error */
|
||||
#define TLOSS 5 /* total loss of precision */
|
||||
#define PLOSS 6 /* partial loss of precision */
|
||||
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
/* Complex numeral. */
|
||||
typedef struct
|
||||
{
|
||||
double r;
|
||||
double i;
|
||||
} cmplx;
|
||||
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
/* Long double complex numeral. */
|
||||
typedef struct
|
||||
{
|
||||
long double r;
|
||||
long double i;
|
||||
} cmplxl;
|
||||
#endif
|
||||
|
||||
|
||||
/* Type of computer arithmetic */
|
||||
|
||||
/* PDP-11, Pro350, VAX:
|
||||
*/
|
||||
/* #define DEC 1 */
|
||||
|
||||
/* Intel IEEE, low order words come first:
|
||||
*/
|
||||
/* #define IBMPC 1 */
|
||||
|
||||
/* Motorola IEEE, high order words come first
|
||||
* (Sun 680x0 workstation):
|
||||
*/
|
||||
/* #define MIEEE 1 */
|
||||
|
||||
/* UNKnown arithmetic, invokes coefficients given in
|
||||
* normal decimal format. Beware of range boundary
|
||||
* problems (MACHEP, MAXLOG, etc. in const.c) and
|
||||
* roundoff problems in pow.c:
|
||||
* (Sun SPARCstation)
|
||||
*/
|
||||
#define UNK 1
|
||||
|
||||
/* If you define UNK, then be sure to set BIGENDIAN properly. */
|
||||
#ifdef FLOAT_WORDS_BIGENDIAN
|
||||
#define BIGENDIAN 1
|
||||
#else
|
||||
#define BIGENDIAN 0
|
||||
#endif
|
||||
/* Define this `volatile' if your compiler thinks
|
||||
* that floating point arithmetic obeys the associative
|
||||
* and distributive laws. It will defeat some optimizations
|
||||
* (but probably not enough of them).
|
||||
*
|
||||
* #define VOLATILE volatile
|
||||
*/
|
||||
#define VOLATILE
|
||||
|
||||
/* For 12-byte long doubles on an i386, pad a 16-bit short 0
|
||||
* to the end of real constants initialized by integer arrays.
|
||||
*
|
||||
* #define XPD 0,
|
||||
*
|
||||
* Otherwise, the type is 10 bytes long and XPD should be
|
||||
* defined blank (e.g., Microsoft C).
|
||||
*
|
||||
* #define XPD
|
||||
*/
|
||||
#define XPD 0,
|
||||
|
||||
/* Define to support tiny denormal numbers, else undefine. */
|
||||
#define DENORMAL 1
|
||||
|
||||
/* Define to ask for infinity support, else undefine. */
|
||||
#define INFINITIES 1
|
||||
|
||||
/* Define to ask for support of numbers that are Not-a-Number,
|
||||
else undefine. This may automatically define INFINITIES in some files. */
|
||||
#define NANS 1
|
||||
|
||||
/* Define to distinguish between -0.0 and +0.0. */
|
||||
#define MINUSZERO 1
|
||||
|
||||
/* Define 1 for ANSI C atan2() function
|
||||
See atan.c and clog.c. */
|
||||
#define ANSIC 1
|
||||
|
||||
/* Get ANSI function prototypes, if you want them. */
|
||||
#if 1
|
||||
/* #ifdef __STDC__ */
|
||||
#define ANSIPROT 1
|
||||
int mtherr ( char *, int );
|
||||
#else
|
||||
int mtherr();
|
||||
#endif
|
||||
|
||||
/* Variable for error reporting. See mtherr.c. */
|
||||
extern int merror;
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/* Program to test range reduction of trigonometry functions
|
||||
*
|
||||
* -- Steve Moshier
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
#ifdef ANSIPROT
|
||||
extern double floor ( double );
|
||||
extern double ldexp ( double, int );
|
||||
extern double sin ( double );
|
||||
#else
|
||||
double floor(), ldexp(), sin();
|
||||
#endif
|
||||
|
||||
#define TPI 6.283185307179586476925
|
||||
|
||||
main()
|
||||
{
|
||||
char s[40];
|
||||
double a, n, t, x, y, z;
|
||||
int lflg;
|
||||
|
||||
x = TPI/4.0;
|
||||
t = 1.0;
|
||||
|
||||
loop:
|
||||
|
||||
t = 2.0 * t;
|
||||
|
||||
/* Stop testing at a point beyond which the integer part of
|
||||
* x/2pi cannot be represented exactly by a double precision number.
|
||||
* The library trigonometry functions will probably give up long before
|
||||
* this point is reached.
|
||||
*/
|
||||
if( t > 1.0e16 )
|
||||
exit(0);
|
||||
|
||||
/* Adjust the following to choose a nontrivial x
|
||||
* where test function(x) has a slope of about 1 or more.
|
||||
*/
|
||||
x = TPI * t + 0.5;
|
||||
|
||||
z = x;
|
||||
lflg = 0;
|
||||
|
||||
inlup:
|
||||
|
||||
/* floor() returns the largest integer less than its argument.
|
||||
* If you do not have this, or AINT(), then you may convert x/TPI
|
||||
* to a long integer and then back to double; but in that case
|
||||
* x will be limited to the largest value that will fit into a
|
||||
* long integer.
|
||||
*/
|
||||
n = floor( z/TPI );
|
||||
|
||||
/* Carefully subtract 2 pi n from x.
|
||||
* This is done by subtracting n * 2**k in such a way that there
|
||||
* is no arithmetic cancellation error at any step. The k are the
|
||||
* bits in the number 2 pi.
|
||||
*
|
||||
* If you do not have ldexp(), then you may multiply or
|
||||
* divide n by an appropriate power of 2 after each step.
|
||||
* For example:
|
||||
* a = z - 4*n;
|
||||
* a -= 2*n;
|
||||
* n /= 4;
|
||||
* a -= n; n/4
|
||||
* n /= 8;
|
||||
* a -= n; n/32
|
||||
* etc.
|
||||
* This will only work if division by a power of 2 is exact.
|
||||
*/
|
||||
|
||||
a = z - ldexp(n, 2); /* 4n */
|
||||
a -= ldexp( n, 1); /* 2n */
|
||||
a -= ldexp( n, -2 ); /* n/4 */
|
||||
a -= ldexp( n, -5 ); /* n/32 */
|
||||
a -= ldexp( n, -9 ); /* n/512 */
|
||||
a += ldexp( n, -15 ); /* add n/32768 */
|
||||
a -= ldexp( n, -17 ); /* n/131072 */
|
||||
a -= ldexp( n, -18 );
|
||||
a -= ldexp( n, -20 );
|
||||
a -= ldexp( n, -22 );
|
||||
a -= ldexp( n, -24 );
|
||||
a -= ldexp( n, -28 );
|
||||
a -= ldexp( n, -32 );
|
||||
a -= ldexp( n, -37 );
|
||||
a -= ldexp( n, -39 );
|
||||
a -= ldexp( n, -40 );
|
||||
a -= ldexp( n, -42 );
|
||||
a -= ldexp( n, -46 );
|
||||
a -= ldexp( n, -47 );
|
||||
|
||||
/* Subtract what is left of 2 pi n after all the above reductions.
|
||||
*/
|
||||
a -= 2.44929359829470635445e-16 * n;
|
||||
|
||||
/* If the test is extended too far, it is possible
|
||||
* to have chosen the wrong value of n. The following
|
||||
* will fix that, but at some reduction in accuracy.
|
||||
*/
|
||||
if( (a > TPI) || (a < -1e-11) )
|
||||
{
|
||||
z = a;
|
||||
lflg += 1;
|
||||
printf( "Warning! Reduction failed on first try.\n" );
|
||||
goto inlup;
|
||||
}
|
||||
if( a < 0.0 )
|
||||
{
|
||||
printf( "Warning! Reduced value < 0\n" );
|
||||
a += TPI;
|
||||
}
|
||||
|
||||
/* Compute the test function at x and at a = x mod 2 pi.
|
||||
*/
|
||||
y = sin(x);
|
||||
z = sin(a);
|
||||
printf( "sin(%.15e) error = %.3e\n", x, y-z );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/* mtherr.c
|
||||
*
|
||||
* Library common error handling routine
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* char *fctnam;
|
||||
* int code;
|
||||
* int mtherr();
|
||||
*
|
||||
* mtherr( fctnam, code );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* This routine may be called to report one of the following
|
||||
* error conditions (in the include file mconf.h).
|
||||
*
|
||||
* Mnemonic Value Significance
|
||||
*
|
||||
* DOMAIN 1 argument domain error
|
||||
* SING 2 function singularity
|
||||
* OVERFLOW 3 overflow range error
|
||||
* UNDERFLOW 4 underflow range error
|
||||
* TLOSS 5 total loss of precision
|
||||
* PLOSS 6 partial loss of precision
|
||||
* EDOM 33 Unix domain error code
|
||||
* ERANGE 34 Unix range error code
|
||||
*
|
||||
* The default version of the file prints the function name,
|
||||
* passed to it by the pointer fctnam, followed by the
|
||||
* error condition. The display is directed to the standard
|
||||
* output device. The routine then returns to the calling
|
||||
* program. Users may wish to modify the program to abort by
|
||||
* calling exit() under severe error conditions such as domain
|
||||
* errors.
|
||||
*
|
||||
* Since all error conditions pass control to this function,
|
||||
* the display may be easily changed, eliminated, or directed
|
||||
* to an error logging device.
|
||||
*
|
||||
* SEE ALSO:
|
||||
*
|
||||
* mconf.h
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.0: April, 1987
|
||||
Copyright 1984, 1987 by Stephen L. Moshier
|
||||
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
||||
*/
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include "mconf.h"
|
||||
|
||||
int merror = 0;
|
||||
|
||||
/* Notice: the order of appearance of the following
|
||||
* messages is bound to the error codes defined
|
||||
* in mconf.h.
|
||||
*/
|
||||
static char *ermsg[7] = {
|
||||
"unknown", /* error code 0 */
|
||||
"domain", /* error code 1 */
|
||||
"singularity", /* et seq. */
|
||||
"overflow",
|
||||
"underflow",
|
||||
"total loss of precision",
|
||||
"partial loss of precision"
|
||||
};
|
||||
|
||||
|
||||
int mtherr( name, code )
|
||||
char *name;
|
||||
int code;
|
||||
{
|
||||
#if 0
|
||||
/* Display string passed by calling program,
|
||||
* which is supposed to be the name of the
|
||||
* function in which the error occurred:
|
||||
*/
|
||||
printf( "\n%s ", name );
|
||||
|
||||
/* Set global error message word */
|
||||
merror = code;
|
||||
|
||||
/* Display error message defined
|
||||
* by the code argument.
|
||||
*/
|
||||
if( (code <= 0) || (code >= 7) )
|
||||
code = 0;
|
||||
printf( "%s error\n", ermsg[code] );
|
||||
#endif
|
||||
/* Return to calling
|
||||
* program
|
||||
*/
|
||||
return( 0 );
|
||||
}
|
||||
+518
File diff suppressed because it is too large.
Load diff
+30
@@ -0,0 +1,30 @@
|
||||
acosh.obj,-
|
||||
asin.obj,-
|
||||
asinh.obj,-
|
||||
atan.obj,-
|
||||
atanh.obj,-
|
||||
cbrt.obj,-
|
||||
chbevl.obj,-
|
||||
const.obj,-
|
||||
cosh.obj,-
|
||||
drand.obj,-
|
||||
exp.obj,-
|
||||
exp10.obj,-
|
||||
fabs.obj,-
|
||||
floor.obj,-
|
||||
log.obj,-
|
||||
log10.obj,-
|
||||
polevl.obj,-
|
||||
pow.obj,-
|
||||
powi.obj,-
|
||||
round.obj,-
|
||||
sin.obj,-
|
||||
sinh.obj,-
|
||||
tan.obj,-
|
||||
tanh.obj,-
|
||||
unity.obj,-
|
||||
sqrt.obj,-
|
||||
floor.obj,-
|
||||
polevl.obj,-
|
||||
mtherr.obj,-
|
||||
sys$library:vaxcrtl/lib
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
; Static Name Aliases
|
||||
;
|
||||
TITLE polevl
|
||||
|
||||
_TEXT SEGMENT BYTE PUBLIC 'CODE'
|
||||
_TEXT ENDS
|
||||
CONST SEGMENT WORD PUBLIC 'CONST'
|
||||
CONST ENDS
|
||||
_BSS SEGMENT WORD PUBLIC 'BSS'
|
||||
_BSS ENDS
|
||||
_DATA SEGMENT WORD PUBLIC 'DATA'
|
||||
_DATA ENDS
|
||||
DGROUP GROUP CONST, _BSS, _DATA
|
||||
ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
|
||||
PUBLIC _polevl
|
||||
PUBLIC _p1evl
|
||||
_DATA SEGMENT
|
||||
EXTRN __chkstk:NEAR
|
||||
EXTRN __fac:NEAR
|
||||
EXTRN __fltused:NEAR
|
||||
$T20001 DQ 0000000000H ; .0000000000000000
|
||||
ans DQ 0
|
||||
ctrlw DW 0
|
||||
_DATA ENDS
|
||||
_TEXT SEGMENT
|
||||
PUBLIC _polevl
|
||||
_polevl PROC NEAR
|
||||
push bp
|
||||
mov bp,sp
|
||||
mov ax,12
|
||||
call __chkstk
|
||||
push si
|
||||
mov si,[bp+12]
|
||||
; fstcw ctrlw
|
||||
; fwait
|
||||
; mov ax,ctrlw
|
||||
; or ax,00100h
|
||||
; mov ctrlw,ax
|
||||
; fldcw ctrlw
|
||||
|
||||
fldz
|
||||
fwait
|
||||
mov ax,[bp+14]
|
||||
inc ax
|
||||
mov [bp-12],ax
|
||||
$D15:
|
||||
fmul QWORD PTR [bp+4]
|
||||
add si,8
|
||||
fwait
|
||||
fadd QWORD PTR [si-8]
|
||||
fwait
|
||||
dec WORD PTR [bp-12]
|
||||
jne $D15
|
||||
fstp ans
|
||||
; fstcw ctrlw
|
||||
; fwait
|
||||
; mov ax,ctrlw
|
||||
; and ax,0feffh
|
||||
; mov ctrlw,ax
|
||||
; fldcw ctrlw
|
||||
|
||||
lea ax, ans
|
||||
fwait
|
||||
pop si
|
||||
mov sp,bp
|
||||
pop bp
|
||||
ret
|
||||
_polevl ENDP
|
||||
|
||||
PUBLIC _p1evl
|
||||
_p1evl PROC NEAR
|
||||
push bp
|
||||
mov bp,sp
|
||||
mov ax,12
|
||||
call __chkstk
|
||||
push si
|
||||
|
||||
; fstcw ctrlw
|
||||
; fwait
|
||||
; mov ax,ctrlw
|
||||
; or ax,00100h
|
||||
; mov ctrlw,ax
|
||||
; fldcw ctrlw
|
||||
|
||||
mov si,[bp+12]
|
||||
fld QWORD PTR [bp+4]
|
||||
add si,8
|
||||
fadd QWORD PTR [si-8]
|
||||
fwait
|
||||
mov ax,[bp+14]
|
||||
dec ax
|
||||
mov [bp-12],ax
|
||||
$D26:
|
||||
fmul QWORD PTR [bp+4]
|
||||
add si,8
|
||||
fadd QWORD PTR [si-8]
|
||||
fwait
|
||||
dec WORD PTR [bp-12]
|
||||
jne $D26
|
||||
fstp ans
|
||||
lea ax, ans
|
||||
; fstcw ctrlw
|
||||
; fwait
|
||||
; mov ax,ctrlw
|
||||
; and ax,0feffh
|
||||
; mov ctrlw,ax
|
||||
; fldcw ctrlw
|
||||
fwait
|
||||
pop si
|
||||
mov sp,bp
|
||||
pop bp
|
||||
ret
|
||||
_p1evl ENDP
|
||||
|
||||
_TEXT ENDS
|
||||
END
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/* polevl.c
|
||||
* p1evl.c
|
||||
*
|
||||
* Evaluate polynomial
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* int N;
|
||||
* double x, y, coef[N+1], polevl[];
|
||||
*
|
||||
* y = polevl( x, coef, N );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Evaluates polynomial of degree N:
|
||||
*
|
||||
* 2 N
|
||||
* y = C + C x + C x +...+ C x
|
||||
* 0 1 2 N
|
||||
*
|
||||
* Coefficients are stored in reverse order:
|
||||
*
|
||||
* coef[0] = C , ..., coef[N] = C .
|
||||
* N 0
|
||||
*
|
||||
* The function p1evl() assumes that coef[N] = 1.0 and is
|
||||
* omitted from the array. Its calling arguments are
|
||||
* otherwise the same as polevl().
|
||||
*
|
||||
*
|
||||
* SPEED:
|
||||
*
|
||||
* In the interest of speed, there are no checks for out
|
||||
* of bounds arithmetic. This routine is used by most of
|
||||
* the functions in the library. Depending on available
|
||||
* equipment features, the user may wish to rewrite the
|
||||
* program in microcode or assembly language.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.1: December, 1988
|
||||
Copyright 1984, 1987, 1988 by Stephen L. Moshier
|
||||
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
||||
*/
|
||||
|
||||
|
||||
double polevl( x, coef, N )
|
||||
double x;
|
||||
double coef[];
|
||||
int N;
|
||||
{
|
||||
double ans;
|
||||
int i;
|
||||
double *p;
|
||||
|
||||
p = coef;
|
||||
ans = *p++;
|
||||
i = N;
|
||||
|
||||
do
|
||||
ans = ans * x + *p++;
|
||||
while( --i );
|
||||
|
||||
return( ans );
|
||||
}
|
||||
|
||||
/* p1evl() */
|
||||
/* N
|
||||
* Evaluate polynomial when coefficient of x is 1.0.
|
||||
* Otherwise same as polevl.
|
||||
*/
|
||||
|
||||
double p1evl( x, coef, N )
|
||||
double x;
|
||||
double coef[];
|
||||
int N;
|
||||
{
|
||||
double ans;
|
||||
double *p;
|
||||
int i;
|
||||
|
||||
p = coef;
|
||||
ans = x + *p++;
|
||||
i = N-1;
|
||||
|
||||
do
|
||||
ans = ans * x + *p++;
|
||||
while( --i );
|
||||
|
||||
return( ans );
|
||||
}
|
||||
+756
File diff suppressed because it is too large.
Load diff
+186
@@ -0,0 +1,186 @@
|
||||
/* powi.c
|
||||
*
|
||||
* Real raised to integer power
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, powi();
|
||||
* int n;
|
||||
*
|
||||
* y = powi( x, n );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns argument x raised to the nth power.
|
||||
* The routine efficiently decomposes n as a sum of powers of
|
||||
* two. The desired power is a product of two-to-the-kth
|
||||
* powers of x. Thus to compute the 32767 power of x requires
|
||||
* 28 multiplications instead of 32767 multiplications.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic x domain n domain # trials peak rms
|
||||
* DEC .04,26 -26,26 100000 2.7e-16 4.3e-17
|
||||
* IEEE .04,26 -26,26 50000 2.0e-15 3.8e-16
|
||||
* IEEE 1,2 -1022,1023 50000 8.6e-14 1.6e-14
|
||||
*
|
||||
* Returns MAXNUM on overflow, zero on underflow.
|
||||
*
|
||||
*/
|
||||
|
||||
/* powi.c */
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
#ifdef ANSIPROT
|
||||
extern double log ( double );
|
||||
extern double frexp ( double, int * );
|
||||
extern int signbit ( double );
|
||||
#else
|
||||
double log(), frexp();
|
||||
int signbit();
|
||||
#endif
|
||||
extern double NEGZERO, INFINITY, MAXNUM, MAXLOG, MINLOG, LOGE2;
|
||||
|
||||
double powi( x, nn )
|
||||
double x;
|
||||
int nn;
|
||||
{
|
||||
int n, e, sign, asign, lx;
|
||||
double w, y, s;
|
||||
|
||||
/* See pow.c for these tests. */
|
||||
if( x == 0.0 )
|
||||
{
|
||||
if( nn == 0 )
|
||||
return( 1.0 );
|
||||
else if( nn < 0 )
|
||||
return( INFINITY );
|
||||
else
|
||||
{
|
||||
if( nn & 1 )
|
||||
return( x );
|
||||
else
|
||||
return( 0.0 );
|
||||
}
|
||||
}
|
||||
|
||||
if( nn == 0 )
|
||||
return( 1.0 );
|
||||
|
||||
if( nn == -1 )
|
||||
return( 1.0/x );
|
||||
|
||||
if( x < 0.0 )
|
||||
{
|
||||
asign = -1;
|
||||
x = -x;
|
||||
}
|
||||
else
|
||||
asign = 0;
|
||||
|
||||
|
||||
if( nn < 0 )
|
||||
{
|
||||
sign = -1;
|
||||
n = -nn;
|
||||
}
|
||||
else
|
||||
{
|
||||
sign = 1;
|
||||
n = nn;
|
||||
}
|
||||
|
||||
/* Even power will be positive. */
|
||||
if( (n & 1) == 0 )
|
||||
asign = 0;
|
||||
|
||||
/* Overflow detection */
|
||||
|
||||
/* Calculate approximate logarithm of answer */
|
||||
s = frexp( x, &lx );
|
||||
e = (lx - 1)*n;
|
||||
if( (e == 0) || (e > 64) || (e < -64) )
|
||||
{
|
||||
s = (s - 7.0710678118654752e-1) / (s + 7.0710678118654752e-1);
|
||||
s = (2.9142135623730950 * s - 0.5 + lx) * nn * LOGE2;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = LOGE2 * e;
|
||||
}
|
||||
|
||||
if( s > MAXLOG )
|
||||
{
|
||||
mtherr( "powi", OVERFLOW );
|
||||
y = INFINITY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
#if DENORMAL
|
||||
if( s < MINLOG )
|
||||
{
|
||||
y = 0.0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Handle tiny denormal answer, but with less accuracy
|
||||
* since roundoff error in 1.0/x will be amplified.
|
||||
* The precise demarcation should be the gradual underflow threshold.
|
||||
*/
|
||||
if( (s < (-MAXLOG+2.0)) && (sign < 0) )
|
||||
{
|
||||
x = 1.0/x;
|
||||
sign = -sign;
|
||||
}
|
||||
#else
|
||||
/* do not produce denormal answer */
|
||||
if( s < -MAXLOG )
|
||||
return(0.0);
|
||||
#endif
|
||||
|
||||
|
||||
/* First bit of the power */
|
||||
if( n & 1 )
|
||||
y = x;
|
||||
|
||||
else
|
||||
y = 1.0;
|
||||
|
||||
w = x;
|
||||
n >>= 1;
|
||||
while( n )
|
||||
{
|
||||
w = w * w; /* arg to the 2-to-the-kth power */
|
||||
if( n & 1 ) /* if that bit is set, then include in product */
|
||||
y *= w;
|
||||
n >>= 1;
|
||||
}
|
||||
|
||||
if( sign < 0 )
|
||||
y = 1.0/y;
|
||||
|
||||
done:
|
||||
|
||||
if( asign )
|
||||
{
|
||||
/* odd power of negative number */
|
||||
if( y == 0.0 )
|
||||
y = NEGZERO;
|
||||
else
|
||||
y = -y;
|
||||
}
|
||||
return(y);
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* This file was automatically generated by version 1.7 of cextract.
|
||||
* Manual editing not recommended.
|
||||
*
|
||||
* Created: Fri Mar 31 19:17:33 1995
|
||||
*/
|
||||
extern double acosh ( double x );
|
||||
extern int airy ( double, double *, double *, double *, double * );
|
||||
extern double asin ( double );
|
||||
extern double acos ( double );
|
||||
extern double asinh ( double x );
|
||||
extern double atan ( double );
|
||||
extern double atan2 ( double y, double x );
|
||||
extern double atanh ( double );
|
||||
extern double bdtrc ( int k, int n, double p );
|
||||
extern double bdtr ( int k, int n, double p );
|
||||
extern double bdtri ( int k, int n, double y );
|
||||
extern double beta ( double a, double b );
|
||||
extern double lbeta ( double a, double b );
|
||||
extern double btdtr ( double a, double b, double x );
|
||||
extern double cbrt ( double );
|
||||
extern double chbevl ( double, void *, int );
|
||||
extern double chdtrc ( double df, double x );
|
||||
extern double chdtr ( double df, double x );
|
||||
extern double chdtri ( double df, double y );
|
||||
//extern void clog ( cmplx *z, cmplx *w );
|
||||
//extern void cexp ( cmplx *z, cmplx *w );
|
||||
//extern void csin ( cmplx *z, cmplx *w );
|
||||
//extern void ccos ( cmplx *z, cmplx *w );
|
||||
//extern void ctan ( cmplx *z, cmplx *w );
|
||||
extern void ccot ( cmplx *z, cmplx *w );
|
||||
//extern void casin ( cmplx *z, cmplx *w );
|
||||
//extern void cacos ( cmplx *z, cmplx *w );
|
||||
//extern void catan ( cmplx *z, cmplx *w );
|
||||
extern void cadd ( cmplx *a, cmplx *b, cmplx *c );
|
||||
extern void csub ( cmplx *a, cmplx *b, cmplx *c );
|
||||
extern void cmul ( cmplx *a, cmplx *b, cmplx *c );
|
||||
extern void cdiv ( cmplx *a, cmplx *b, cmplx *c );
|
||||
extern void cmov ( void *a, void *b );
|
||||
extern void cneg ( cmplx *a );
|
||||
//extern double cabs ( cmplx *z );
|
||||
//extern void csqrt ( cmplx *z, cmplx *w );
|
||||
extern double hypot ( double, double );
|
||||
extern double cosh ( double );
|
||||
extern double dawsn ( double xx );
|
||||
extern void eigens ( double A[], double RR[], double E[], int N );
|
||||
extern double ellie ( double, double );
|
||||
extern double ellik ( double, double );
|
||||
extern double ellpe ( double );
|
||||
extern int ellpj ( double u, double m, double *sn, double *cn, double *dn, double *ph );
|
||||
extern double ellpk ( double );
|
||||
extern double exp10 ( double );
|
||||
extern double exp1m ( double );
|
||||
extern double exp2 ( double );
|
||||
extern double expn ( int n, double x );
|
||||
extern double fac ( int i );
|
||||
extern double fdtrc ( int ia, int ib, double x );
|
||||
extern double fdtr ( int ia, int ib, double x );
|
||||
extern double fdtri ( int ia, int ib, double y );
|
||||
extern int fftr ( double x[], int m0, double sine[] );
|
||||
extern double ceil ( double x );
|
||||
extern double fabs ( double );
|
||||
extern double floor ( double );
|
||||
extern double frexp ( double, int * );
|
||||
extern double ldexp ( double, int );
|
||||
extern int signbit ( double );
|
||||
extern int isnan ( double );
|
||||
extern int isfinite ( double );
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
extern double exp ( double );
|
||||
extern double log ( double );
|
||||
extern double sin ( double );
|
||||
extern double cos ( double );
|
||||
extern double sqrt ( double );
|
||||
extern int fresnl ( double xxa, double *ssa, double *cca );
|
||||
extern double gamma ( double );
|
||||
extern double lgam ( double );
|
||||
extern double gdtr ( double a, double b, double x );
|
||||
extern double gdtrc ( double a, double b, double x );
|
||||
extern int gels ( double A[], double R[], int M, double EPS, double AUX[] );
|
||||
extern double hyp2f1 ( double a, double b, double c, double x );
|
||||
extern double hyperg ( double, double, double );
|
||||
extern double hyp2f0 ( double a, double b, double x, int type, double *err );
|
||||
extern double i0 ( double );
|
||||
extern double i0e ( double x );
|
||||
extern double i1 ( double );
|
||||
extern double i1e ( double x );
|
||||
extern double igamc ( double, double );
|
||||
extern double igam ( double, double );
|
||||
extern double igami ( double, double );
|
||||
extern double incbet ( double, double, double );
|
||||
extern double incbi ( double, double, double );
|
||||
extern double iv ( double v, double x );
|
||||
extern double j0 ( double );
|
||||
extern double y0 ( double );
|
||||
extern double j1 ( double );
|
||||
extern double y1 ( double );
|
||||
extern double jn ( int n, double x );
|
||||
extern double jv ( double, double );
|
||||
extern double k0 ( double x );
|
||||
extern double k0e ( double x );
|
||||
extern double k1 ( double x );
|
||||
extern double k1e ( double x );
|
||||
extern double kn ( int nn, double x );
|
||||
extern int levnsn ( int n, double r[], double a[], double e[], double refl[] );
|
||||
extern double log10 ( double );
|
||||
extern double log2 ( double );
|
||||
extern long lrand ( void );
|
||||
extern long lsqrt ( long x );
|
||||
extern int minv ( double A[], double X[], int n, double B[], int IPS[] );
|
||||
extern int mmmpy ( int r, int c, double *A, double *B, double *Y );
|
||||
extern int mtherr ( char *name, int code );
|
||||
extern int mtransp ( int n, double *A, double *T );
|
||||
extern int mvmpy ( int r, int c, double *A, double *V, double *Y );
|
||||
extern double nbdtrc ( int k, int n, double p );
|
||||
extern double nbdtr ( int k, int n, double p );
|
||||
extern double nbdtri ( int k, int n, double p );
|
||||
extern double ndtr ( double a );
|
||||
extern double erfc ( double );
|
||||
extern double erf ( double );
|
||||
extern double ndtri ( double );
|
||||
extern double pdtrc ( int k, double m );
|
||||
extern double pdtr ( int k, double m );
|
||||
extern double pdtri ( int k, double y );
|
||||
extern double pow ( double, double );
|
||||
extern double powi ( double, int );
|
||||
extern double psi ( double );
|
||||
extern void revers ( double y[], double x[], int n );
|
||||
extern double rgamma ( double x );
|
||||
extern double round ( double );
|
||||
extern int sprec ( void );
|
||||
extern int dprec ( void );
|
||||
extern int ldprec ( void );
|
||||
extern int shichi ( double x, double *si, double *ci );
|
||||
extern int sici ( double x, double *si, double *ci );
|
||||
extern double simpsn ( double f[], double delta );
|
||||
extern int simq ( double A[], double B[], double X[], int n, int flag, int IPS[] );
|
||||
extern double radian ( double d, double m, double s );
|
||||
/*
|
||||
extern int sincos ( double x, double *s, double *c, int flg );
|
||||
*/
|
||||
extern double sindg ( double x );
|
||||
extern double cosdg ( double x );
|
||||
extern double sinh ( double );
|
||||
extern double spence ( double );
|
||||
extern double stdtr ( int k, double t );
|
||||
extern double stdtri ( int k, double p );
|
||||
extern double onef2 ( double a, double b, double c, double x, double *err );
|
||||
extern double threef0 ( double a, double b, double c, double x, double *err );
|
||||
extern double struve ( double v, double x );
|
||||
extern double tan ( double );
|
||||
extern double cot ( double );
|
||||
extern double tandg ( double x );
|
||||
extern double cotdg ( double x );
|
||||
extern double tanh ( double );
|
||||
extern double log1p ( double );
|
||||
extern double exmp1 ( double );
|
||||
extern double cosm1 ( double x );
|
||||
extern double yn ( int, double );
|
||||
extern double zeta ( double x, double q );
|
||||
extern double zetac ( double );
|
||||
extern int drand ( double *a );
|
||||
double smirnov ( int, double );
|
||||
double smirnovi ( int, double );
|
||||
double kolmogorov ( double );
|
||||
double kolmogi ( double );
|
||||
|
||||
/* polyn.c */
|
||||
extern void polini ( int maxdeg );
|
||||
extern void polprt ( double a[], int na, int d );
|
||||
extern void polclr ( double *a, int n );
|
||||
extern void polmov ( double *a, int na, double *b );
|
||||
extern void polmul ( double a[], int na, double b[], int nb, double c[] );
|
||||
extern void poladd ( double a[], int na, double b[], int nb, double c[] );
|
||||
extern void polsub ( double a[], int na, double b[], int nb, double c[] );
|
||||
extern int poldiv ( double a[], int na, double b[], int nb, double c[] );
|
||||
extern void polsbt ( double a[], int na, double b[], int nb, double c[] );
|
||||
extern double poleva ( double a[], int na, double x );
|
||||
/* polmisc.c */
|
||||
extern void polatn ( double num[], double den[], double ans[], int nn );
|
||||
extern void polsqt ( double pol[], double ans[], int nn );
|
||||
extern void polsin ( double x[], double y[], int nn );
|
||||
extern void polcos ( double x[], double y[], int nn );
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/* round.c
|
||||
*
|
||||
* Round double to nearest or even integer valued double
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, round();
|
||||
*
|
||||
* y = round(x);
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns the nearest integer to x as a double precision
|
||||
* floating point result. If x ends in 0.5 exactly, the
|
||||
* nearest even integer is chosen.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* If x is greater than 1/(2*MACHEP), its closest machine
|
||||
* representation is already an integer, so rounding does
|
||||
* not change it.
|
||||
*/
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.1: January, 1989
|
||||
Copyright 1984, 1987, 1989 by Stephen L. Moshier
|
||||
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
||||
*/
|
||||
#include "mconf.h"
|
||||
#ifdef ANSIPROT
|
||||
double floor ( double );
|
||||
#else
|
||||
double floor();
|
||||
#endif
|
||||
|
||||
double round(x)
|
||||
double x;
|
||||
{
|
||||
double y, r;
|
||||
|
||||
/* Largest integer <= x */
|
||||
y = floor(x);
|
||||
|
||||
/* Fractional part */
|
||||
r = x - y;
|
||||
|
||||
/* Round up to nearest. */
|
||||
if( r > 0.5 )
|
||||
goto rndup;
|
||||
|
||||
/* Round to even */
|
||||
if( r == 0.5 )
|
||||
{
|
||||
r = y - 2.0 * floor( 0.5 * y );
|
||||
if( r == 1.0 )
|
||||
{
|
||||
rndup:
|
||||
y += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Else round down. */
|
||||
return(y);
|
||||
}
|
||||
+207
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,87 @@
|
||||
/* Set 80387 floating point hardware rounding precision */
|
||||
|
||||
.file "setprec.387"
|
||||
.text
|
||||
.align 2
|
||||
|
||||
.globl _sprec
|
||||
_sprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %eax
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
andl $0xfcff,%eax
|
||||
movl %eax,(%esp)
|
||||
fldcw (%esp)
|
||||
popl %eax
|
||||
popl %eax
|
||||
leave
|
||||
ret
|
||||
|
||||
.align 2
|
||||
|
||||
.globl _dprec
|
||||
_dprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %eax
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
/* andl $0xfcff,%eax */
|
||||
/* exception on overflow */
|
||||
andl $0xfcf7,%eax
|
||||
orl $0x200,%eax
|
||||
movl %eax,(%esp)
|
||||
fldcw (%esp)
|
||||
popl %eax
|
||||
popl %eax
|
||||
leave
|
||||
ret
|
||||
|
||||
.align 2
|
||||
|
||||
.globl _ldprec
|
||||
_ldprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %eax
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
orl $0x300,%eax
|
||||
movl %eax,(%esp)
|
||||
fldcw (%esp)
|
||||
popl %eax
|
||||
popl %eax
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
.globl _getprec
|
||||
_getprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
leave
|
||||
ret
|
||||
|
||||
.globl _setfpu
|
||||
_setfpu:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
movl 8(%ebp),%eax
|
||||
pushl %eax
|
||||
fldcw (%esp)
|
||||
fwait
|
||||
movl %ebp,%esp
|
||||
popl %ebp
|
||||
ret
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Set 68881/2 floating point rounding precision */
|
||||
/* Reference: MC68881/MC68882 Floating-Point Coprocessor */
|
||||
/* User's Manual, Motorola, Prentice-Hall, 1987 (First Edition) */
|
||||
/* Pages 1-14, 2-3, 4-68. */
|
||||
/* FPcr code $80 sets the 68882 coprocessor to */
|
||||
/* rounding precision = 53 bits */
|
||||
/* rounding mode = nearest or even */
|
||||
/* all exceptions (bits 8-15) disabled */
|
||||
/* The instruction is */
|
||||
/* FMOVE.L #$80,Fcr */
|
||||
/* if the assembler will understand it. */
|
||||
|
||||
.align 2
|
||||
.text
|
||||
|
||||
/* set to single precision */
|
||||
.globl _sprec
|
||||
_sprec
|
||||
.word 0xf23c,0x9000,0x0000,0x0040
|
||||
rts
|
||||
|
||||
/* set to double precision */
|
||||
.globl _dprec
|
||||
|
||||
_dprec:
|
||||
.word 0xf23c,0x9000,0x0000,0x0080
|
||||
rts
|
||||
|
||||
/* set to extended (long double) precision */
|
||||
.globl _ldprec
|
||||
|
||||
_ldprec:
|
||||
.word 0xf23c,0x9000,0x0000,0x0000
|
||||
rts
|
||||
|
||||
+208
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,10 @@
|
||||
/* Null stubs for coprocessor precision settings */
|
||||
|
||||
int
|
||||
sprec() {return 0; }
|
||||
|
||||
int
|
||||
dprec() {return 0; }
|
||||
|
||||
int
|
||||
ldprec() {return 0; }
|
||||
@@ -0,0 +1,83 @@
|
||||
/* Set 80387 floating point hardware rounding precision */
|
||||
|
||||
.file "setprec.387"
|
||||
.version "01.01"
|
||||
.text
|
||||
.align 16
|
||||
|
||||
.globl sprec
|
||||
sprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %eax
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
andl $0xfcff,%eax
|
||||
movl %eax,(%esp)
|
||||
fldcw (%esp)
|
||||
popl %eax
|
||||
popl %eax
|
||||
leave
|
||||
ret
|
||||
.Lfe1:
|
||||
.size sprec,.Lfe1-sprec
|
||||
.align 16
|
||||
|
||||
.globl dprec
|
||||
dprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %eax
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
andl $0xfcff,%eax
|
||||
/* trap on overflow */
|
||||
/* andl $0xfcf7,%eax */
|
||||
orl $0x200,%eax
|
||||
movl %eax,(%esp)
|
||||
fldcw (%esp)
|
||||
popl %eax
|
||||
popl %eax
|
||||
leave
|
||||
ret
|
||||
.Lfe2:
|
||||
.size dprec,.Lfe2-dprec
|
||||
.align 16
|
||||
|
||||
.globl ldprec
|
||||
ldprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %eax
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
orl $0x300,%eax
|
||||
movl %eax,(%esp)
|
||||
fldcw (%esp)
|
||||
popl %eax
|
||||
popl %eax
|
||||
leave
|
||||
ret
|
||||
.Lfe3:
|
||||
.size ldprec,.Lfe3-ldprec
|
||||
|
||||
.align 16
|
||||
.globl getprec
|
||||
getprec:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
subl $4,%esp
|
||||
fstcw (%esp)
|
||||
fwait
|
||||
movl (%esp),%eax
|
||||
leave
|
||||
ret
|
||||
.Lfe4:
|
||||
.size getprec,.Lfe4-getprec
|
||||
|
||||
+387
File diff suppressed because it is too large.
Load diff
+358
File diff suppressed because it is too large.
Load diff
+308
File diff suppressed because it is too large.
Load diff
+148
@@ -0,0 +1,148 @@
|
||||
/* sinh.c
|
||||
*
|
||||
* Hyperbolic sine
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, sinh();
|
||||
*
|
||||
* y = sinh( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns hyperbolic sine of argument in the range MINLOG to
|
||||
* MAXLOG.
|
||||
*
|
||||
* The range is partitioned into two segments. If |x| <= 1, a
|
||||
* rational function of the form x + x**3 P(x)/Q(x) is employed.
|
||||
* Otherwise the calculation is sinh(x) = ( exp(x) - exp(-x) )/2.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC +- 88 50000 4.0e-17 7.7e-18
|
||||
* IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef UNK
|
||||
const static double P[] = {
|
||||
-7.89474443963537015605E-1,
|
||||
-1.63725857525983828727E2,
|
||||
-1.15614435765005216044E4,
|
||||
-3.51754964808151394800E5
|
||||
};
|
||||
const static double Q[] = {
|
||||
/* 1.00000000000000000000E0,*/
|
||||
-2.77711081420602794433E2,
|
||||
3.61578279834431989373E4,
|
||||
-2.11052978884890840399E6
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef DEC
|
||||
static unsigned short P[] = {
|
||||
0140112,0015377,0042731,0163255,
|
||||
0142043,0134721,0146177,0123761,
|
||||
0143464,0122706,0034353,0006017,
|
||||
0144653,0140536,0157665,0054045
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0040200,0000000,0000000,0000000,*/
|
||||
0142212,0155404,0133513,0022040,
|
||||
0044015,0036723,0173271,0011053,
|
||||
0145400,0150407,0023710,0001034
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
static unsigned short P[] = {
|
||||
0x3cd6,0xe8bb,0x435f,0xbfe9,
|
||||
0xf4fe,0x398f,0x773a,0xc064,
|
||||
0x6182,0xc71d,0x94b8,0xc0c6,
|
||||
0xab05,0xdbf6,0x782b,0xc115
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0x0000,0x0000,0x0000,0x3ff0,*/
|
||||
0x6484,0x96e9,0x5b60,0xc071,
|
||||
0x2245,0x7ed7,0xa7ba,0x40e1,
|
||||
0x0044,0xe4f9,0x1a20,0xc140
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
static unsigned short P[] = {
|
||||
0xbfe9,0x435f,0xe8bb,0x3cd6,
|
||||
0xc064,0x773a,0x398f,0xf4fe,
|
||||
0xc0c6,0x94b8,0xc71d,0x6182,
|
||||
0xc115,0x782b,0xdbf6,0xab05
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
0xc071,0x5b60,0x96e9,0x6484,
|
||||
0x40e1,0xa7ba,0x7ed7,0x2245,
|
||||
0xc140,0x1a20,0xe4f9,0x0044
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double fabs ( double );
|
||||
extern double exp ( double );
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
#else
|
||||
double fabs(), exp(), polevl(), p1evl();
|
||||
#endif
|
||||
extern double INFINITY, MINLOG, MAXLOG, LOGE2;
|
||||
|
||||
double sinh(x)
|
||||
double x;
|
||||
{
|
||||
double a;
|
||||
|
||||
#ifdef MINUSZERO
|
||||
if( x == 0.0 )
|
||||
return(x);
|
||||
#endif
|
||||
a = fabs(x);
|
||||
if( (x > (MAXLOG + LOGE2)) || (x > -(MINLOG-LOGE2) ) )
|
||||
{
|
||||
mtherr( "sinh", DOMAIN );
|
||||
if( x > 0 )
|
||||
return( INFINITY );
|
||||
else
|
||||
return( -INFINITY );
|
||||
}
|
||||
if( a > 1.0 )
|
||||
{
|
||||
if( a >= (MAXLOG - LOGE2) )
|
||||
{
|
||||
a = exp(0.5*a);
|
||||
a = (0.5 * a) * a;
|
||||
if( x < 0 )
|
||||
a = -a;
|
||||
return(a);
|
||||
}
|
||||
a = exp(a);
|
||||
a = 0.5*a - (0.5/a);
|
||||
if( x < 0 )
|
||||
a = -a;
|
||||
return(a);
|
||||
}
|
||||
|
||||
a *= a;
|
||||
return( x + x * a * (polevl(a,P,3)/p1evl(a,Q,3)) );
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
/* sqrt.c
|
||||
*
|
||||
* Square root
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, sqrt();
|
||||
*
|
||||
* y = sqrt( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns the square root of x.
|
||||
*
|
||||
* Range reduction involves isolating the power of two of the
|
||||
* argument and using a polynomial approximation to obtain
|
||||
* a rough value for the square root. Then Heron's iteration
|
||||
* is used three times to converge to an accurate value.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC 0, 10 60000 2.1e-17 7.9e-18
|
||||
* IEEE 0,1.7e308 30000 1.7e-16 6.3e-17
|
||||
*
|
||||
*
|
||||
* ERROR MESSAGES:
|
||||
*
|
||||
* message condition value returned
|
||||
* sqrt domain x < 0 0.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
|
||||
#include "mconf.h"
|
||||
#ifdef ANSIPROT
|
||||
extern double frexp ( double, int * );
|
||||
extern double ldexp ( double, int );
|
||||
#else
|
||||
double frexp(), ldexp();
|
||||
#endif
|
||||
extern double SQRT2; /* SQRT2 = 1.41421356237309504880 */
|
||||
|
||||
double sqrt(x)
|
||||
double x;
|
||||
{
|
||||
int e;
|
||||
#ifndef UNK
|
||||
short *q;
|
||||
#endif
|
||||
double z, w;
|
||||
|
||||
if( x <= 0.0 )
|
||||
{
|
||||
if( x < 0.0 )
|
||||
mtherr( "sqrt", DOMAIN );
|
||||
return( 0.0 );
|
||||
}
|
||||
w = x;
|
||||
/* separate exponent and significand */
|
||||
#ifdef UNK
|
||||
z = frexp( x, &e );
|
||||
#endif
|
||||
#ifdef DEC
|
||||
q = (short *)&x;
|
||||
e = ((*q >> 7) & 0377) - 0200;
|
||||
*q &= 0177;
|
||||
*q |= 040000;
|
||||
z = x;
|
||||
#endif
|
||||
|
||||
/* Note, frexp and ldexp are used in order to
|
||||
* handle denormal numbers properly.
|
||||
*/
|
||||
#ifdef IBMPC
|
||||
z = frexp( x, &e );
|
||||
q = (short *)&x;
|
||||
q += 3;
|
||||
/*
|
||||
e = ((*q >> 4) & 0x0fff) - 0x3fe;
|
||||
*q &= 0x000f;
|
||||
*q |= 0x3fe0;
|
||||
z = x;
|
||||
*/
|
||||
#endif
|
||||
#ifdef MIEEE
|
||||
z = frexp( x, &e );
|
||||
q = (short *)&x;
|
||||
/*
|
||||
e = ((*q >> 4) & 0x0fff) - 0x3fe;
|
||||
*q &= 0x000f;
|
||||
*q |= 0x3fe0;
|
||||
z = x;
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* approximate square root of number between 0.5 and 1
|
||||
* relative error of approximation = 7.47e-3
|
||||
*/
|
||||
x = 4.173075996388649989089E-1 + 5.9016206709064458299663E-1 * z;
|
||||
|
||||
/* adjust for odd powers of 2 */
|
||||
if( (e & 1) != 0 )
|
||||
x *= SQRT2;
|
||||
|
||||
/* re-insert exponent */
|
||||
#ifdef UNK
|
||||
x = ldexp( x, (e >> 1) );
|
||||
#endif
|
||||
#ifdef DEC
|
||||
*q += ((e >> 1) & 0377) << 7;
|
||||
*q &= 077777;
|
||||
#endif
|
||||
#ifdef IBMPC
|
||||
x = ldexp( x, (e >> 1) );
|
||||
/*
|
||||
*q += ((e >>1) & 0x7ff) << 4;
|
||||
*q &= 077777;
|
||||
*/
|
||||
#endif
|
||||
#ifdef MIEEE
|
||||
x = ldexp( x, (e >> 1) );
|
||||
/*
|
||||
*q += ((e >>1) & 0x7ff) << 4;
|
||||
*q &= 077777;
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Newton iterations: */
|
||||
#ifdef UNK
|
||||
x = 0.5*(x + w/x);
|
||||
x = 0.5*(x + w/x);
|
||||
x = 0.5*(x + w/x);
|
||||
#endif
|
||||
|
||||
/* Note, assume the square root cannot be denormal,
|
||||
* so it is safe to use integer exponent operations here.
|
||||
*/
|
||||
#ifdef DEC
|
||||
x += w/x;
|
||||
*q -= 0200;
|
||||
x += w/x;
|
||||
*q -= 0200;
|
||||
x += w/x;
|
||||
*q -= 0200;
|
||||
#endif
|
||||
#ifdef IBMPC
|
||||
x += w/x;
|
||||
*q -= 0x10;
|
||||
x += w/x;
|
||||
*q -= 0x10;
|
||||
x += w/x;
|
||||
*q -= 0x10;
|
||||
#endif
|
||||
#ifdef MIEEE
|
||||
x += w/x;
|
||||
*q -= 0x10;
|
||||
x += w/x;
|
||||
*q -= 0x10;
|
||||
x += w/x;
|
||||
*q -= 0x10;
|
||||
#endif
|
||||
|
||||
return(x);
|
||||
}
|
||||
+304
File diff suppressed because it is too large.
Load diff
+267
File diff suppressed because it is too large.
Load diff
+141
@@ -0,0 +1,141 @@
|
||||
/* tanh.c
|
||||
*
|
||||
* Hyperbolic tangent
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, tanh();
|
||||
*
|
||||
* y = tanh( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns hyperbolic tangent of argument in the range MINLOG to
|
||||
* MAXLOG.
|
||||
*
|
||||
* A rational function is used for |x| < 0.625. The form
|
||||
* x + x**3 P(x)/Q(x) of Cody _& Waite is employed.
|
||||
* Otherwise,
|
||||
* tanh(x) = sinh(x)/cosh(x) = 1 - 2/(exp(2x) + 1).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC -2,2 50000 3.3e-17 6.4e-18
|
||||
* IEEE -2,2 30000 2.5e-16 5.8e-17
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Cephes Math Library Release 2.8: June, 2000
|
||||
Copyright 1984, 1995, 2000 by Stephen L. Moshier
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef UNK
|
||||
const static double P[] = {
|
||||
-9.64399179425052238628E-1,
|
||||
-9.92877231001918586564E1,
|
||||
-1.61468768441708447952E3
|
||||
};
|
||||
const static double Q[] = {
|
||||
/* 1.00000000000000000000E0,*/
|
||||
1.12811678491632931402E2,
|
||||
2.23548839060100448583E3,
|
||||
4.84406305325125486048E3
|
||||
};
|
||||
#endif
|
||||
#ifdef DEC
|
||||
static unsigned short P[] = {
|
||||
0140166,0161335,0053753,0075126,
|
||||
0141706,0111520,0070463,0040552,
|
||||
0142711,0153001,0101300,0025430
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0040200,0000000,0000000,0000000,*/
|
||||
0041741,0117624,0051300,0156060,
|
||||
0043013,0133720,0071251,0127717,
|
||||
0043227,0060201,0021020,0020136
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef IBMPC
|
||||
static unsigned short P[] = {
|
||||
0x6f4b,0xaafd,0xdc5b,0xbfee,
|
||||
0x682d,0x0e26,0xd26a,0xc058,
|
||||
0x0563,0x3058,0x3ac0,0xc099
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
/*0x0000,0x0000,0x0000,0x3ff0,*/
|
||||
0x1b86,0x8a58,0x33f2,0x405c,
|
||||
0x35fa,0x0e55,0x76fa,0x40a1,
|
||||
0x040c,0x2442,0xec10,0x40b2
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef MIEEE
|
||||
static unsigned short P[] = {
|
||||
0xbfee,0xdc5b,0xaafd,0x6f4b,
|
||||
0xc058,0xd26a,0x0e26,0x682d,
|
||||
0xc099,0x3ac0,0x3058,0x0563
|
||||
};
|
||||
static unsigned short Q[] = {
|
||||
0x405c,0x33f2,0x8a58,0x1b86,
|
||||
0x40a1,0x76fa,0x0e55,0x35fa,
|
||||
0x40b2,0xec10,0x2442,0x040c
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern double fabs ( double );
|
||||
extern double exp ( double );
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
#else
|
||||
double fabs(), exp(), polevl(), p1evl();
|
||||
#endif
|
||||
extern double MAXLOG;
|
||||
|
||||
double tanh(x)
|
||||
double x;
|
||||
{
|
||||
double s, z;
|
||||
|
||||
#ifdef MINUSZERO
|
||||
if( x == 0.0 )
|
||||
return(x);
|
||||
#endif
|
||||
z = fabs(x);
|
||||
if( z > 0.5 * MAXLOG )
|
||||
{
|
||||
if( x > 0 )
|
||||
return( 1.0 );
|
||||
else
|
||||
return( -1.0 );
|
||||
}
|
||||
if( z >= 0.625 )
|
||||
{
|
||||
s = exp(2.0*z);
|
||||
z = 1.0 - 2.0/(s + 1.0);
|
||||
if( x < 0 )
|
||||
z = -z;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( x == 0.0 )
|
||||
return(x);
|
||||
s = x * x;
|
||||
z = polevl( s, P, 2 )/p1evl(s, Q, 3);
|
||||
z = x * s * z;
|
||||
z = x + z;
|
||||
}
|
||||
return( z );
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/* unity.c
|
||||
*
|
||||
* Relative error approximations for function arguments near
|
||||
* unity.
|
||||
*
|
||||
* log1p(x) = log(1+x)
|
||||
* expm1(x) = exp(x) - 1
|
||||
* cosm1(x) = cos(x) - 1
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mconf.h"
|
||||
|
||||
#ifdef ANSIPROT
|
||||
extern int isnan (double);
|
||||
extern int isfinite (double);
|
||||
extern double log ( double );
|
||||
extern double polevl ( double, void *, int );
|
||||
extern double p1evl ( double, void *, int );
|
||||
extern double exp ( double );
|
||||
extern double cos ( double );
|
||||
#else
|
||||
double log(), polevl(), p1evl(), exp(), cos();
|
||||
int isnan(), isfinite();
|
||||
#endif
|
||||
extern double INFINITY;
|
||||
|
||||
/* log1p(x) = log(1 + x) */
|
||||
|
||||
/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
|
||||
* 1/sqrt(2) <= x < sqrt(2)
|
||||
* Theoretical peak relative error = 2.32e-20
|
||||
*/
|
||||
const static double LP[] = {
|
||||
4.5270000862445199635215E-5,
|
||||
4.9854102823193375972212E-1,
|
||||
6.5787325942061044846969E0,
|
||||
2.9911919328553073277375E1,
|
||||
6.0949667980987787057556E1,
|
||||
5.7112963590585538103336E1,
|
||||
2.0039553499201281259648E1,
|
||||
};
|
||||
const static double LQ[] = {
|
||||
/* 1.0000000000000000000000E0,*/
|
||||
1.5062909083469192043167E1,
|
||||
8.3047565967967209469434E1,
|
||||
2.2176239823732856465394E2,
|
||||
3.0909872225312059774938E2,
|
||||
2.1642788614495947685003E2,
|
||||
6.0118660497603843919306E1,
|
||||
};
|
||||
|
||||
#define SQRTH 0.70710678118654752440
|
||||
#define SQRT2 1.41421356237309504880
|
||||
|
||||
double log1p(x)
|
||||
double x;
|
||||
{
|
||||
double z;
|
||||
|
||||
z = 1.0 + x;
|
||||
if( (z < SQRTH) || (z > SQRT2) )
|
||||
return( log(z) );
|
||||
z = x*x;
|
||||
z = -0.5 * z + x * ( z * polevl( x, LP, 6 ) / p1evl( x, LQ, 6 ) );
|
||||
return (x + z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* expm1(x) = exp(x) - 1 */
|
||||
|
||||
/* e^x = 1 + 2x P(x^2)/( Q(x^2) - P(x^2) )
|
||||
* -0.5 <= x <= 0.5
|
||||
*/
|
||||
|
||||
const static double EP[3] = {
|
||||
1.2617719307481059087798E-4,
|
||||
3.0299440770744196129956E-2,
|
||||
9.9999999999999999991025E-1,
|
||||
};
|
||||
const static double EQ[4] = {
|
||||
3.0019850513866445504159E-6,
|
||||
2.5244834034968410419224E-3,
|
||||
2.2726554820815502876593E-1,
|
||||
2.0000000000000000000897E0,
|
||||
};
|
||||
|
||||
double expm1(x)
|
||||
double x;
|
||||
{
|
||||
double r, xx;
|
||||
|
||||
#ifdef NANS
|
||||
if( isnan(x) )
|
||||
return(x);
|
||||
#endif
|
||||
#ifdef INFINITIES
|
||||
if( x == INFINITY )
|
||||
return(INFINITY);
|
||||
if( x == -INFINITY )
|
||||
return(-1.0);
|
||||
#endif
|
||||
if( (x < -0.5) || (x > 0.5) )
|
||||
return( exp(x) - 1.0 );
|
||||
xx = x * x;
|
||||
r = x * polevl( xx, EP, 2 );
|
||||
r = r/( polevl( xx, EQ, 3 ) - r );
|
||||
return (r + r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* cosm1(x) = cos(x) - 1 */
|
||||
|
||||
const static double coscof[7] = {
|
||||
4.7377507964246204691685E-14,
|
||||
-1.1470284843425359765671E-11,
|
||||
2.0876754287081521758361E-9,
|
||||
-2.7557319214999787979814E-7,
|
||||
2.4801587301570552304991E-5,
|
||||
-1.3888888888888872993737E-3,
|
||||
4.1666666666666666609054E-2,
|
||||
};
|
||||
|
||||
extern double PIO4;
|
||||
|
||||
double cosm1(x)
|
||||
double x;
|
||||
{
|
||||
double xx;
|
||||
|
||||
if( (x < -PIO4) || (x > PIO4) )
|
||||
return( cos(x) - 1.0 );
|
||||
xx = x * x;
|
||||
xx = -0.5*xx + xx * xx * polevl( xx, coscof, 6 );
|
||||
return xx;
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
# Double precision Cephes library
|
||||
# Makefile for unix or GCC
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -O2 -Wall -fno-builtin
|
||||
AR = ar
|
||||
RANLIB = ranlib
|
||||
INCS = mconf.h
|
||||
AS = as
|
||||
|
||||
OBJS = acosh.o airy.o asin.o asinh.o atan.o atanh.o bdtr.o beta.o \
|
||||
btdtr.o cbrt.o chbevl.o chdtr.o clog.o cmplx.o const.o \
|
||||
cosh.o dawsn.o drand.o ellie.o ellik.o ellpe.o ellpj.o ellpk.o \
|
||||
exp.o exp10.o exp2.o expn.o fabs.o fac.o fdtr.o \
|
||||
fresnl.o gamma.o gdtr.o hyp2f1.o hyperg.o i0.o i1.o igami.o \
|
||||
incbet.o incbi.o igam.o isnan.o iv.o j0.o j1.o jn.o jv.o k0.o k1.o \
|
||||
kn.o log.o log2.o log10.o lrand.o nbdtr.o ndtr.o ndtri.o pdtr.o \
|
||||
polevl.o polmisc.o polyn.o pow.o powi.o psi.o rgamma.o round.o \
|
||||
shichi.o sici.o sin.o sindg.o sinh.o spence.o stdtr.o struve.o \
|
||||
tan.o tandg.o tanh.o unity.o yn.o zeta.o zetac.o \
|
||||
sqrt.o floor.o setprec.o mtherr.o
|
||||
|
||||
all: libmd.a mtst dtestvec dcalc paranoia # stamp-timing
|
||||
|
||||
stamp-timing: libmd.a mtst time-it
|
||||
time-it "mtst > /dev/null"
|
||||
touch stamp-timing
|
||||
|
||||
time-it: time-it.o
|
||||
$(CC) -o time-it time-it.o
|
||||
|
||||
time-it.o: time-it.c
|
||||
$(CC) -O2 -c time-it.c
|
||||
|
||||
dcalc: dcalc.o libmd.a
|
||||
$(CC) -o dcalc dcalc.o libmd.a
|
||||
# aout2exe mtst
|
||||
|
||||
mtst: mtst.o libmd.a
|
||||
$(CC) -v -o mtst mtst.o libmd.a
|
||||
# gcc -Wl,-verbose -b i486-linuxaout -v -o mtst mtst.o libmd.a
|
||||
# coff2exe mtst
|
||||
|
||||
mtst.o: mtst.c
|
||||
$(CC) -O2 -Wall -c mtst.c
|
||||
|
||||
dtestvec: dtestvec.o libmd.a
|
||||
$(CC) -o dtestvec dtestvec.o libmd.a
|
||||
|
||||
dtestvec.o: dtestvec.c
|
||||
$(CC) -g -c dtestvec.c
|
||||
|
||||
paranoia: paranoia.o setprec.o libmd.a
|
||||
$(CC) -o paranoia paranoia.o setprec.o libmd.a
|
||||
|
||||
paranoia.o: paranoia.c
|
||||
$(CC) $(CFLAGS) -c paranoia.c
|
||||
|
||||
libmd.a: $(OBJS) $(INCS)
|
||||
# for real Unix:
|
||||
$(AR) rv libmd.a $(OBJS)
|
||||
# for djgcc MSDOS:
|
||||
# >libmd.rf -rv libmd.a $(OBJS)
|
||||
# $(AR) @libmd.rf
|
||||
$(RANLIB) libmd.a
|
||||
|
||||
# If the following are all commented out, the C versions
|
||||
# will be used by default.
|
||||
|
||||
# IBM PC:
|
||||
#sqrt.o: sqrt.387
|
||||
# $(AS) -o sqrt.o sqrt.387
|
||||
#
|
||||
#floor.o: floor.387
|
||||
# $(AS) -o floor.o floor.387
|
||||
#
|
||||
#setprec.o: setprec.387
|
||||
# $(AS) -o setprec.o setprec.387
|
||||
|
||||
# ELF versions for linux (no underscores)
|
||||
sqrt.o: sqrtelf.387
|
||||
$(AS) -o sqrt.o sqrtelf.387
|
||||
|
||||
#floor.o: floorelf.387
|
||||
# $(AS) -o floor.o floorelf.387
|
||||
|
||||
setprec.o: setprelf.387
|
||||
$(AS) -o setprec.o setprelf.387
|
||||
|
||||
# Motorola 68881. Caution, subroutine return conventions vary.
|
||||
#sqrt.o: sqrt.688
|
||||
# $(AS) -o sqrt.o sqrt.688
|
||||
#
|
||||
#setprec.o: setprec.688
|
||||
# $(AS) -o setprec.o setprec.688
|
||||
|
||||
# SPARC:
|
||||
#sqrt.o: sqrt.spa
|
||||
# $(AS) -o sqrt.o sqrt.spa
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f mtst
|
||||
rm -f paranoia
|
||||
rm -f dcalc
|
||||
rm -f libmd.a
|
||||
rm -f time-it
|
||||
rm -f dtestvec
|
||||
|
||||
+336
File diff suppressed because it is too large.
Load diff
+127
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Common low-level device handling (Events, IO buffers)
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef JSDEVICES_H_
|
||||
#define JSDEVICES_H_
|
||||
|
||||
#include "jsutils.h"
|
||||
#include "platform_config.h"
|
||||
|
||||
typedef enum {
|
||||
// device type
|
||||
EV_NONE,
|
||||
EV_EXTI0,
|
||||
EV_EXTI1,
|
||||
EV_EXTI2,
|
||||
EV_EXTI3,
|
||||
EV_EXTI4,
|
||||
EV_EXTI5,
|
||||
EV_EXTI6,
|
||||
EV_EXTI7,
|
||||
EV_EXTI8,
|
||||
EV_EXTI9,
|
||||
EV_EXTI10,
|
||||
EV_EXTI11,
|
||||
EV_EXTI12,
|
||||
EV_EXTI13,
|
||||
EV_EXTI14,
|
||||
EV_EXTI15,
|
||||
EV_EXTI_MAX = EV_EXTI15,
|
||||
EV_USBSERIAL,
|
||||
EV_SERIAL1,
|
||||
EV_SERIAL2,
|
||||
EV_SERIAL3,
|
||||
EV_SERIAL4,
|
||||
EV_SERIAL5,
|
||||
EV_SERIAL6,
|
||||
EV_SERIAL_MAX = EV_SERIAL6,
|
||||
EV_SPI1,
|
||||
EV_SPI2,
|
||||
EV_SPI3,
|
||||
EV_SPI_MAX = EV_SPI3,
|
||||
EV_I2C1,
|
||||
EV_I2C2,
|
||||
EV_I2C3,
|
||||
EV_I2C_MAX = EV_I2C3,
|
||||
EV_DEVICE_MAX = EV_I2C_MAX,
|
||||
// EV_DEVICE_MAX should not be >64 - see DEVICE_INITIALISED_FLAGS
|
||||
// Also helps if we're under 32 so we can fit IOEventFlags into a byte
|
||||
EV_TYPE_MASK = NEXT_POWER_2(EV_DEVICE_MAX) - 1,
|
||||
EV_CHARS_MASK = 7 * NEXT_POWER_2(EV_DEVICE_MAX),
|
||||
// -----------------------------------------
|
||||
// if the pin we're watching is high, the handler sets this
|
||||
EV_EXTI_IS_HIGH = NEXT_POWER_2(EV_DEVICE_MAX),
|
||||
} PACKED_FLAGS IOEventFlags;
|
||||
|
||||
#define DEVICE_IS_USART(X) (((X)>=EV_USBSERIAL)&& ((X)<=EV_SERIAL_MAX))
|
||||
#define DEVICE_IS_SPI(X) (((X)>=EV_SPI1) || ((X)<=EV_SPI_MAX))
|
||||
#define DEVICE_IS_I2C(X) (((X)>=EV_I2C1) || ((X)<=EV_I2C_MAX))
|
||||
#define DEVICE_IS_EXTI(X) (((X)>=EV_EXTI0) || ((X)<=EV_EXTI_MAX))
|
||||
|
||||
#define IOEVENTFLAGS_GETTYPE(X) ((X)&EV_TYPE_MASK)
|
||||
#define IOEVENTFLAGS_GETCHARS(X) ((((X)&EV_CHARS_MASK)>>5)+1)
|
||||
#define IOEVENTFLAGS_SETCHARS(X,CHARS) ((X)=(((X)&(IOEventFlags)~EV_CHARS_MASK) | (((CHARS)-1)<<5)))
|
||||
#define IOEVENT_MAXCHARS 8
|
||||
|
||||
typedef union {
|
||||
JsSysTime time; // time event occurred
|
||||
char chars[IOEVENT_MAXCHARS];
|
||||
} PACKED_FLAGS IOEventData;
|
||||
|
||||
// IO Events - these happen when a pin changes
|
||||
typedef struct IOEvent {
|
||||
IOEventFlags flags; // where this came from, and # of chars in it
|
||||
IOEventData data;
|
||||
} PACKED_FLAGS IOEvent;
|
||||
|
||||
void jshPushIOEvent(IOEventFlags channel, JsSysTime time);
|
||||
void jshPushIOWatchEvent(IOEventFlags channel); // push an even when a pin changes state
|
||||
/// Push a single character event (for example USART RX)
|
||||
void jshPushIOCharEvent(IOEventFlags channel, char charData);
|
||||
/// Push many character events at once (for example USB RX)
|
||||
static inline void jshPushIOCharEvents(IOEventFlags channel, char *data, unsigned int count) {
|
||||
// TODO: optimise me!
|
||||
unsigned int i;
|
||||
for (i=0;i<count;i++) jshPushIOCharEvent(channel, data[i]);
|
||||
}
|
||||
bool jshPopIOEvent(IOEvent *result); ///< returns true on success
|
||||
/// Do we have any events pending? Will jshPopIOEvent return true?
|
||||
bool jshHasEvents();
|
||||
|
||||
/// How many event blocks are left? compare this to IOBUFFERMASK
|
||||
int jshGetEventsUsed();
|
||||
|
||||
/// Do we have enough space for N characters?
|
||||
bool jshHasEventSpaceForChars(int n);
|
||||
|
||||
const char *jshGetDeviceString(IOEventFlags device);
|
||||
IOEventFlags jshFromDeviceString(const char *device);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DATA TRANSMIT BUFFER
|
||||
/// Queue a character for transmission
|
||||
void jshTransmit(IOEventFlags device, unsigned char data);
|
||||
/// Wait for transmit to finish
|
||||
void jshTransmitFlush();
|
||||
/// Clear everything from a device
|
||||
void jshTransmitClearDevice(IOEventFlags device);
|
||||
/// Do we have anything we need to send?
|
||||
bool jshHasTransmitData();
|
||||
/// Try and get a character for transmission - could just return -1 if nothing
|
||||
int jshGetCharToTransmit(IOEventFlags device);
|
||||
|
||||
|
||||
/// Set whether the host should transmit or not
|
||||
void jshSetFlowControlXON(IOEventFlags device, bool hostShouldTransmit);
|
||||
|
||||
#endif /* JSDEVICES_H_ */
|
||||
+223
File diff suppressed because it is too large.
Load diff
+1686
File diff suppressed because it is too large.
Load diff
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Interactive Shell implementation
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef JSINTERACTIVE_H_
|
||||
#define JSINTERACTIVE_H_
|
||||
|
||||
#include "jsparse.h"
|
||||
#include "jshardware.h"
|
||||
|
||||
#define JSI_WATCHES_NAME ">watches"
|
||||
#define JSI_TIMERS_NAME ">timers"
|
||||
#define JSI_HISTORY_NAME ">history"
|
||||
#define JSI_INIT_CODE_NAME ">init"
|
||||
#define JSI_ONINIT_NAME "onInit"
|
||||
|
||||
/// autoLoad = do we load the current state if it exists?
|
||||
void jsiInit(bool autoLoad);
|
||||
void jsiKill();
|
||||
|
||||
void jsiLoop();
|
||||
|
||||
/// Tries to get rid of some memory (by clearing command history). Returns true if it got rid of something, false if it didn't.
|
||||
bool jsiFreeMoreMemory();
|
||||
|
||||
bool jsiHasTimers(); // are there timers still left to run?
|
||||
JsParse *jsiGetParser();
|
||||
|
||||
/// Queue up callbacks for other things (touchscreen? network?)
|
||||
void jsiQueueObjectCallbacks(JsVar *object, const char *callbackName, JsVar *arg0, JsVar *arg1);
|
||||
|
||||
|
||||
IOEventFlags jsiGetDeviceFromClass(JsVar *deviceClass);
|
||||
JsVar *jsiGetClassNameFromDevice(IOEventFlags device);
|
||||
|
||||
/// Change the console to a new location
|
||||
void jsiSetConsoleDevice(IOEventFlags device);
|
||||
/// Get the device that the console is currently on
|
||||
IOEventFlags jsiGetConsoleDevice();
|
||||
/// Transmit a byte
|
||||
void jsiConsolePrintChar(char data);
|
||||
/// Transmit a string
|
||||
void jsiConsolePrint(const char *str);
|
||||
/// Write the formatted string to the console (see vcbprintf)
|
||||
void jsiConsolePrintf(const char *fmt, ...);
|
||||
/// Print the contents of a string var - directly
|
||||
void jsiConsolePrintStringVar(JsVar *v);
|
||||
/// Transmit an integer
|
||||
void jsiConsolePrintInt(JsVarInt d);
|
||||
/// Transmit a position in the lexer (for reporting errors)
|
||||
void jsiConsolePrintPosition(struct JsLex *lex, int tokenPos);
|
||||
/// Transmit the current line, along with a marker of where the error was (for reporting errors)
|
||||
void jsiConsolePrintTokenLineMarker(struct JsLex *lex, int tokenPos);
|
||||
/// Print the contents of a string var to a device - directly
|
||||
void jsiTransmitStringVar(IOEventFlags device, JsVar *v);
|
||||
/// If the input line was shown in the console, remove it
|
||||
void jsiConsoleRemoveInputLine();
|
||||
/// Change what is in the inputline into something else (and update the console)
|
||||
void jsiReplaceInputLine(JsVar *newLine);
|
||||
|
||||
/// Flags for jsiSetBusy - THESE SHOULD BE 2^N
|
||||
typedef enum {
|
||||
BUSY_INTERACTIVE = 1,
|
||||
BUSY_TRANSMIT = 2,
|
||||
// ??? = 4
|
||||
} JsiBusyDevice;
|
||||
/// Shows a busy indicator, if one is set up
|
||||
void jsiSetBusy(JsiBusyDevice device, bool isBusy);
|
||||
/// Shows a sleep indicator, if one is set up
|
||||
void jsiSetSleep(bool isSleep);
|
||||
|
||||
|
||||
// for jswrap_interactive/io.c ----------------------------------------------------
|
||||
typedef enum {
|
||||
TODO_NOTHING = 0,
|
||||
TODO_FLASH_SAVE = 1,
|
||||
TODO_FLASH_LOAD = 2,
|
||||
TODO_RESET = 4,
|
||||
} TODOFlags;
|
||||
#define USART_CALLBACK_NAME "_callback"
|
||||
#define USART_BAUDRATE_NAME "_baudrate"
|
||||
#define DEVICE_OPTIONS_NAME "_options"
|
||||
|
||||
extern Pin pinBusyIndicator;
|
||||
extern Pin pinSleepIndicator;
|
||||
extern bool echo;
|
||||
extern bool allowDeepSleep;
|
||||
void jsiDumpState();
|
||||
void jsiSetTodo(TODOFlags newTodo);
|
||||
#define TIMER_MIN_INTERVAL 0.1 // in milliseconds
|
||||
extern JsVarRef timerArray; // Linked List of timers to check and run
|
||||
extern JsVarRef watchArray; // Linked List of input watches to check and run
|
||||
// end for jswrap_interactive/io.c ------------------------------------------------
|
||||
|
||||
|
||||
#endif /* JSINTERACTIVE_H_ */
|
||||
+501
File diff suppressed because it is too large.
Load diff
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Lexer (convert JsVar strings into a series of tokens)
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef JSLEX_H_
|
||||
#define JSLEX_H_
|
||||
|
||||
#include "jsutils.h"
|
||||
#include "jsvar.h"
|
||||
|
||||
typedef struct JsLex
|
||||
{
|
||||
// Actual Lexing related stuff
|
||||
char currCh, nextCh;
|
||||
short tk; ///< The type of the token that we have
|
||||
JslCharPos tokenStart; ///< Position in the data at the beginning of the token we have here
|
||||
JslCharPos tokenEnd; ///< Position in the data at the last character of the token we have here
|
||||
JslCharPos tokenLastStart; ///< Position in the data of the first character of the last token
|
||||
JslCharPos tokenLastEnd; ///< Position in the data of the last character of the last token
|
||||
char token[JSLEX_MAX_TOKEN_LENGTH]; ///< Data contained in the token we have here
|
||||
JsVar *tokenValue; ///< JsVar containing the current token - used only for strings
|
||||
unsigned char tokenl; ///< the current length of token
|
||||
|
||||
/* Where we get our data from...
|
||||
*
|
||||
* This is a bit more tricky than normal because the data comes from JsVars,
|
||||
* which only have fixed length strings. If we go past this, we have to go
|
||||
* to the next jsVar...
|
||||
*/
|
||||
JsVar *sourceVar; // the actual string var
|
||||
JsvStringIterator it; // Iterator for the string
|
||||
} JsLex;
|
||||
|
||||
void jslInit(JsLex *lex, JsVar *var);
|
||||
void jslKill(JsLex *lex);
|
||||
void jslReset(JsLex *lex);
|
||||
void jslSeekTo(JsLex *lex, JslCharPos seekToChar); // like jslSeek, but pre-fills characters
|
||||
|
||||
bool jslMatch(JsLex *lex, int expected_tk); ///< Match, and return true on success, false on failure
|
||||
void jslTokenAsString(int token, char *str, size_t len); ///< output the given token as a string - for debugging
|
||||
void jslGetTokenString(JsLex *lex, char *str, size_t len);
|
||||
char *jslGetTokenValueAsString(JsLex *lex);
|
||||
JsVar *jslGetTokenValueAsVar(JsLex *lex);
|
||||
|
||||
// Only for more 'internal' use
|
||||
void jslSeek(JsLex *lex, JslCharPos seekToChar); // like jslSeekTo, but doesn't pre-fill characters
|
||||
void jslGetNextCh(JsLex *lex);
|
||||
void jslGetNextToken(JsLex *lex); ///< Get the text token from our text string
|
||||
|
||||
#endif /* JSLEX_H_ */
|
||||
+2213
File diff suppressed because it is too large.
Load diff
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Recursive descent parser for code execution
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef JSPARSE_H_
|
||||
#define JSPARSE_H_
|
||||
|
||||
#include "jsvar.h"
|
||||
#include "jslex.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
JsVar *root; ///< root of symbol table
|
||||
} JsParse;
|
||||
|
||||
void jspInit(JsParse *parse);
|
||||
void jspKill(JsParse *parse);
|
||||
|
||||
// jspSoft* - 'release' or 'claim' anything we are using, but ensure that it doesn't get freed
|
||||
void jspSoftInit(JsParse *parse); ///< used when recovering from or saving to flash
|
||||
void jspSoftKill(JsParse *parse); ///< used when recovering from or saving to flash
|
||||
bool jspIsCreatedObject(JsParse *parse, JsVar *v); ///< Is v likely to have been created by this parser?
|
||||
/** Returns true if the constructor function given is the same as that
|
||||
* of the object with the given name. */
|
||||
bool jspIsConstructor(JsVar *constructor, const char *constructorName);
|
||||
|
||||
/// Create a new built-in object that jswrapper can use to check for built-in functions
|
||||
JsVar *jspNewBuiltin(const char *name);
|
||||
/** Create a new object of the given instance and add it to root with name 'name'.
|
||||
* If name!=0, added to root with name, and the name is returned
|
||||
* If name==0, not added to root and Object itself returned */
|
||||
JsVar *jspNewObject(JsParse *parse, const char *name, const char *instanceOf);
|
||||
|
||||
/// if interrupting execution, this is set
|
||||
bool jspIsInterrupted();
|
||||
/// if interrupting execution, this is set
|
||||
void jspSetInterrupted(bool interrupt);
|
||||
/// Has there been an error during parsing
|
||||
bool jspHasError();
|
||||
|
||||
bool jspAddNativeFunction(JsParse *parse, const char *funcDesc, JsCallback callbackPtr);
|
||||
JsVar *jspEvaluateVar(JsParse *parse, JsVar *str, JsVar *scope);
|
||||
JsVar *jspEvaluate(JsParse *parse, const char *str);
|
||||
bool jspExecuteFunction(JsParse *parse, JsVar *func, JsVar *parent, int argCount, JsVar **argPtr);
|
||||
|
||||
/// Evaluate a JavaScript module and return its exports
|
||||
JsVar *jspEvaluateModule(JsParse *parse, JsVar *moduleContents);
|
||||
|
||||
/** When parsing, this enum defines whether
|
||||
we are executing or not */
|
||||
typedef enum {
|
||||
EXEC_NO = 0,
|
||||
EXEC_YES = 1,
|
||||
EXEC_BREAK = 2,
|
||||
EXEC_CONTINUE = 4,
|
||||
|
||||
EXEC_INTERRUPTED = 8, // true if execution has been interrupted
|
||||
EXEC_ERROR = 16,
|
||||
EXEC_ERROR_LINE_REPORTED = 32, // if an error has been reported, set this so we don't do it too much
|
||||
|
||||
EXEC_FOR_INIT = 64, // when in for initialiser parsing - hack to avoid getting confused about multiple use for IN
|
||||
EXEC_IN_LOOP = 128, // when in a loop, set this - we can then block break/continue outside it
|
||||
EXEC_IN_SWITCH = 256, // when in a switch, set this - we can then block break outside it/loops
|
||||
|
||||
EXEC_RUN_MASK = EXEC_YES|EXEC_BREAK|EXEC_CONTINUE|EXEC_INTERRUPTED,
|
||||
EXEC_ERROR_MASK = EXEC_INTERRUPTED|EXEC_ERROR,
|
||||
EXEC_SAVE_RESTORE_MASK = EXEC_YES|EXEC_IN_LOOP|EXEC_IN_SWITCH, // the things JSP_SAVE/RESTORE_EXECUTE should keep track of
|
||||
} JsExecFlags;
|
||||
|
||||
/** This structure is used when parsing the JavaScript. It contains
|
||||
* everything that should be needed. */
|
||||
typedef struct {
|
||||
JsParse *parse;
|
||||
JsLex *lex;
|
||||
|
||||
// TODO: could store scopes as JsVar array for speed
|
||||
JsVarRef scopes[JSPARSE_MAX_SCOPES];
|
||||
int scopeCount;
|
||||
/// Value of 'this' reserved word
|
||||
JsVar *thisVar;
|
||||
|
||||
JsExecFlags execute;
|
||||
} JsExecInfo;
|
||||
|
||||
/// flags for jspParseFunction
|
||||
typedef enum {
|
||||
JSP_NOSKIP_A = 1,
|
||||
JSP_NOSKIP_B = 2,
|
||||
JSP_NOSKIP_C = 4,
|
||||
JSP_NOSKIP_D = 8,
|
||||
JSP_NOSKIP_E = 16,
|
||||
JSP_NOSKIP_F = 32,
|
||||
JSP_NOSKIP_G = 64,
|
||||
JSP_NOSKIP_H = 128,
|
||||
} JspSkipFlags;
|
||||
|
||||
/// parse function with max 4 arguments (can set arg to 0 to avoid parse). Usually first arg will be 0, but if we DON'T want to skip names on an arg stuff, we can say
|
||||
bool jspParseFunction(JspSkipFlags skipName, JsVar **a, JsVar **b, JsVar **c, JsVar **d);
|
||||
/// parse function with max 8 arguments (can set arg to 0 to avoid parse). Usually first arg will be 0, but if we DON'T want to skip names on an arg stuff, we can say
|
||||
bool jspParseFunction8(JspSkipFlags skipName, JsVar **a, JsVar **b, JsVar **c, JsVar **d, JsVar **e, JsVar **f, JsVar **g, JsVar **h);
|
||||
|
||||
bool jspParseVariableName(); ///< parse single variable name
|
||||
bool jspParseEmptyFunction(); ///< parse function with no arguments
|
||||
JsVar *jspParseSingleFunction(); ///< parse function with a single argument, return its value (no names!)
|
||||
JsVar *jspParseFunctionAsArray(); ///< parse a function with any number of argument, and return an array of de-named aruments
|
||||
|
||||
/** Handle a function call (assumes we've parsed the function name and we're
|
||||
* on the start bracket). 'thisArg' is the value of the 'this' variable when the
|
||||
* function is executed (it's usually the parent object)
|
||||
*
|
||||
* If !isParsing and arg0!=0, argument 0 is set to what is supplied (same with arg1)
|
||||
*
|
||||
* functionName is used only for error reporting - and can be 0
|
||||
*/
|
||||
JsVar *jspeFunctionCall(JsVar *function, JsVar *functionName, JsVar *thisArg, bool isParsing, int argCount, JsVar **argPtr);
|
||||
|
||||
#endif /* JSPARSE_H_ */
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Utilities and definitions for handling Pins
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "jspin.h"
|
||||
#include "jspininfo.h" // auto-generated
|
||||
|
||||
bool jshIsPinValid(Pin pin) {
|
||||
// Note, PIN_UNDEFINED is always > JSH_PIN_COUNT
|
||||
return pin < JSH_PIN_COUNT && pinInfo[pin].port!=JSH_PORT_NONE;
|
||||
}
|
||||
|
||||
|
||||
Pin jshGetPinFromString(const char *s) {
|
||||
// built in constants
|
||||
|
||||
if (s[0]=='B' && s[1]=='T' && s[2]=='N') {
|
||||
#ifdef BTN1_PININDEX
|
||||
if (!s[3]) return BTN1_PININDEX;
|
||||
if (s[3]=='1' && !s[4]) return BTN1_PININDEX;
|
||||
#endif
|
||||
#ifdef BTN2_PININDEX
|
||||
if (s[3]=='2' && !s[4]) return BTN2_PININDEX;
|
||||
#endif
|
||||
#ifdef BTN3_PININDEX
|
||||
if (s[3]=='3' && !s[4]) return BTN3_PININDEX;
|
||||
#endif
|
||||
#ifdef BTN4_PININDEX
|
||||
if (s[3]=='4' && !s[4]) return BTN4_PININDEX;
|
||||
#endif
|
||||
}
|
||||
if (s[0]=='L' && s[1]=='E' && s[2]=='D') {
|
||||
#ifdef LED1_PININDEX
|
||||
if (!s[3]) return LED1_PININDEX;
|
||||
if (s[3]=='1' && !s[4]) return LED1_PININDEX;
|
||||
#endif
|
||||
#ifdef LED2_PININDEX
|
||||
if (s[3]=='2' && !s[4]) return LED2_PININDEX;
|
||||
#endif
|
||||
#ifdef LED3_PININDEX
|
||||
if (s[3]=='3' && !s[4]) return LED3_PININDEX;
|
||||
#endif
|
||||
#ifdef LED4_PININDEX
|
||||
if (s[3]=='4' && !s[4]) return LED4_PININDEX;
|
||||
#endif
|
||||
#ifdef LED5_PININDEX
|
||||
if (s[3]=='5' && !s[4]) return LED5_PININDEX;
|
||||
#endif
|
||||
#ifdef LED6_PININDEX
|
||||
if (s[3]=='6' && !s[4]) return LED6_PININDEX;
|
||||
#endif
|
||||
#ifdef LED7_PININDEX
|
||||
if (s[3]=='7' && !s[4]) return LED7_PININDEX;
|
||||
#endif
|
||||
#ifdef LED8_PININDEX
|
||||
if (s[3]=='8' && !s[4]) return LED8_PININDEX;
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((s[0]>='A' && s[0]<='H') && s[1]) { // first 6 are analogs
|
||||
int port = JSH_PORTA+s[0]-'A';
|
||||
Pin pin = 127;
|
||||
if (!s[2] && (s[1]>='0' && s[1]<='9')) { // D0-D9
|
||||
pin = (Pin)(s[1]-'0');
|
||||
} else if (!s[3] && (s[1]>='1' && s[1]<='3' && s[2]>='0' && s[2]<='9')) { // D1X-D3X
|
||||
pin = (Pin)((s[1]-'0')*10 + (s[2]-'0'));
|
||||
}
|
||||
if (port == JSH_PORTA) {
|
||||
if (pin<JSH_PORTA_COUNT) return (Pin)(JSH_PORTA_OFFSET + pin);
|
||||
} else if (port == JSH_PORTB) {
|
||||
if (pin<JSH_PORTB_COUNT) return (Pin)(JSH_PORTB_OFFSET + pin);
|
||||
} else if (port == JSH_PORTC) {
|
||||
if (pin<JSH_PORTC_COUNT) return (Pin)(JSH_PORTC_OFFSET + pin);
|
||||
} else if (port == JSH_PORTD) {
|
||||
if (pin<JSH_PORTD_COUNT) return (Pin)(JSH_PORTD_OFFSET + pin);
|
||||
#if JSH_PORTE_OFFSET!=-1
|
||||
} else if (port == JSH_PORTE) {
|
||||
if (pin<JSH_PORTE_COUNT) return (Pin)(JSH_PORTE_OFFSET + pin);
|
||||
#endif
|
||||
#if JSH_PORTF_OFFSET!=-1
|
||||
} else if (port == JSH_PORTF) {
|
||||
if (pin<JSH_PORTF_COUNT) return (Pin)(JSH_PORTF_OFFSET + pin);
|
||||
#endif
|
||||
#if JSH_PORTG_OFFSET!=-1
|
||||
} else if (port == JSH_PORTG) {
|
||||
if (pin<JSH_PORTG_COUNT) return (Pin)(JSH_PORTG_OFFSET + pin);
|
||||
#endif
|
||||
#if JSH_PORTH_OFFSET!=-1
|
||||
} else if (port == JSH_PORTH) {
|
||||
if (pin<JSH_PORTH_COUNT) return (Pin)(JSH_PORTH_OFFSET + pin);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return PIN_UNDEFINED;
|
||||
}
|
||||
|
||||
/** Write the pin name to a string. String must have at least 8 characters (to be safe) */
|
||||
void jshGetPinString(char *result, Pin pin) {
|
||||
result[0] = 0; // just in case
|
||||
if (
|
||||
#if JSH_PORTA_OFFSET!=0
|
||||
pin>=JSH_PORTA_OFFSET &&
|
||||
#endif
|
||||
pin<JSH_PORTA_OFFSET+JSH_PORTA_COUNT) {
|
||||
result[0]='A';
|
||||
itoa(pin-JSH_PORTA_OFFSET,&result[1],10);
|
||||
} else if (pin>=JSH_PORTB_OFFSET && pin<JSH_PORTB_OFFSET+JSH_PORTB_COUNT) {
|
||||
result[0]='B';
|
||||
itoa(pin-JSH_PORTB_OFFSET,&result[1],10);
|
||||
} else if (pin>=JSH_PORTC_OFFSET && pin<JSH_PORTC_OFFSET+JSH_PORTC_COUNT) {
|
||||
result[0]='C';
|
||||
itoa(pin-JSH_PORTC_OFFSET,&result[1],10);
|
||||
} else if (pin>=JSH_PORTD_OFFSET && pin<JSH_PORTD_OFFSET+JSH_PORTD_COUNT) {
|
||||
result[0]='D';
|
||||
itoa(pin-JSH_PORTD_OFFSET,&result[1],10);
|
||||
#if JSH_PORTE_OFFSET!=-1
|
||||
} else if (pin>=JSH_PORTE_OFFSET && pin<JSH_PORTE_OFFSET+JSH_PORTE_COUNT) {
|
||||
result[0]='E';
|
||||
itoa(pin-JSH_PORTE_OFFSET,&result[1],10);
|
||||
#endif
|
||||
#if JSH_PORTF_OFFSET!=-1
|
||||
} else if (pin>=JSH_PORTF_OFFSET && pin<JSH_PORTF_OFFSET+JSH_PORTF_COUNT) {
|
||||
result[0]='F';
|
||||
itoa(pin-JSH_PORTF_OFFSET,&result[1],10);
|
||||
#endif
|
||||
#if JSH_PORTG_OFFSET!=-1
|
||||
} else if (pin>=JSH_PORTG_OFFSET && pin<JSH_PORTG_OFFSET+JSH_PORTG_COUNT) {
|
||||
result[0]='G';
|
||||
itoa(pin-JSH_PORTG_OFFSET,&result[1],10);
|
||||
#endif
|
||||
#if JSH_PORTH_OFFSET!=-1
|
||||
} else if (pin>=JSH_PORTH_OFFSET && pin<JSH_PORTH_OFFSET+JSH_PORTH_COUNT) {
|
||||
result[0]='H';
|
||||
itoa(pin-JSH_PORTH_OFFSET,&result[1],10);
|
||||
#endif
|
||||
} else {
|
||||
strncpy(result, "UNKNOWN", 8);
|
||||
}
|
||||
}
|
||||
+228
File diff suppressed because it is too large.
Load diff
+439
File diff suppressed because it is too large.
Load diff
+374
File diff suppressed because it is too large.
Load diff
+2542
File diff suppressed because it is too large.
Load diff
+612
File diff suppressed because it is too large.
Load diff
+328
File diff suppressed because it is too large.
Load diff
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript methods for Arrays
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_array_constructor(JsVar *args);
|
||||
bool jswrap_array_contains(JsVar *parent, JsVar *value);
|
||||
JsVar *jswrap_array_indexOf(JsVar *parent, JsVar *value);
|
||||
JsVar *jswrap_array_join(JsVar *parent, JsVar *filler);
|
||||
JsVar *jswrap_array_map(JsVar *parent, JsVar *funcVar, JsVar *thisVar);
|
||||
JsVar *jswrap_array_slice(JsVar *parent, JsVar *startVar, JsVar *endVar);
|
||||
JsVar *jswrap_array_splice(JsVar *parent, JsVarInt index, JsVar *howManyVar, JsVar *element1, JsVar *element2, JsVar *element3, JsVar *element4, JsVar *element5, JsVar *element6);
|
||||
void jswrap_array_forEach(JsVar *parent, JsVar *funcVar, JsVar *thisVar);
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript methods and functions in the global namespace
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_arraybuffer_constructor(JsVarInt byteLength);
|
||||
JsVar *jswrap_typedarray_constructor(JsVarDataArrayBufferViewType type, JsVar *arr, JsVarInt byteOffset, JsVarInt length);
|
||||
JsVarFloat jswrap_arraybufferview_interpolate(JsVar *parent, JsVarFloat index);
|
||||
JsVarFloat jswrap_arraybufferview_interpolate2d(JsVar *parent, JsVarInt width, JsVarFloat x, JsVarFloat y);
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* This file is designed to be parsed during the build process
|
||||
*
|
||||
* JavaScript methods and functions in the global namespace
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jswrap_functions.h"
|
||||
#include "jslex.h"
|
||||
#include "jsparse.h"
|
||||
#include "jsinteractive.h"
|
||||
|
||||
/*JSON{ "type":"variable", "name" : "arguments",
|
||||
"description" : "A variable containing the arguments given to the function",
|
||||
"generate" : "jswrap_arguments",
|
||||
"return" : ["JsVar", "An array containing all the arguments given to the function"]
|
||||
}*/
|
||||
extern JsExecInfo execInfo;
|
||||
JsVar *jswrap_arguments() {
|
||||
JsVar *scope = 0;
|
||||
if (execInfo.scopeCount>0)
|
||||
scope = jsvLock(execInfo.scopes[execInfo.scopeCount-1]);
|
||||
if (!jsvIsFunction(scope)) {
|
||||
jsvUnLock(scope);
|
||||
jsError("Can only use 'arguments' variable inside a function");
|
||||
return 0;
|
||||
}
|
||||
|
||||
JsVar *args = jsvNewWithFlags(JSV_ARRAY);
|
||||
if (!args) return 0; // out of memory
|
||||
|
||||
JsObjectIterator it;
|
||||
jsvObjectIteratorNew(&it, scope);
|
||||
while (jsvObjectIteratorHasElement(&it)) {
|
||||
JsVar *idx = jsvObjectIteratorGetKey(&it);
|
||||
if (jsvIsFunctionParameter(idx)) {
|
||||
JsVar *val = jsvSkipOneName(idx);
|
||||
jsvArrayPushAndUnLock(args, val);
|
||||
}
|
||||
jsvUnLock(idx);
|
||||
jsvObjectIteratorNext(&it);
|
||||
}
|
||||
jsvObjectIteratorFree(&it);
|
||||
jsvUnLock(scope);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
/*JSON{ "type":"function", "name" : "eval",
|
||||
"description" : "Evaluate a string containing JavaScript code",
|
||||
"generate" : "jswrap_eval",
|
||||
"params" : [ [ "code", "JsVar", ""] ],
|
||||
"return" : ["JsVar", "The result of evaluating the string"]
|
||||
}*/
|
||||
JsVar *jswrap_eval(JsVar *v) {
|
||||
if (!v) return 0;
|
||||
JsVar *s = jsvAsString(v, false); // get as a string
|
||||
JsVar *result = jspEvaluateVar(jsiGetParser(), s, 0);
|
||||
jsvUnLock(s);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*JSON{ "type":"function", "name" : "parseInt",
|
||||
"description" : "Convert a string representing a number into an integer",
|
||||
"generate" : "jswrap_parseInt",
|
||||
"params" : [ [ "string", "JsVar", ""],
|
||||
[ "radix", "JsVar", "The Radix of the string (optional)"] ],
|
||||
"return" : ["JsVar", "The integer value of the string (or NaN)"]
|
||||
}*/
|
||||
JsVar *jswrap_parseInt(JsVar *v, JsVar *radixVar) {
|
||||
int radix = 0/*don't force radix*/;
|
||||
if (jsvIsNumeric(radixVar))
|
||||
radix = (int)jsvGetInteger(radixVar);
|
||||
|
||||
char buffer[JS_NUMBER_BUFFER_SIZE];
|
||||
jsvGetString(v, buffer, JS_NUMBER_BUFFER_SIZE);
|
||||
bool hasError;
|
||||
JsVarInt i = stringToIntWithRadix(buffer, radix, &hasError);
|
||||
if (hasError) return jsvNewFromFloat(NAN);
|
||||
return jsvNewFromInteger(i);
|
||||
}
|
||||
|
||||
/*JSON{ "type":"function", "name" : "parseFloat",
|
||||
"description" : "Convert a string representing a number into an float",
|
||||
"generate" : "jswrap_parseFloat",
|
||||
"params" : [ [ "string", "JsVar", ""] ],
|
||||
"return" : ["float", "The value of the string"]
|
||||
}*/
|
||||
JsVarFloat jswrap_parseFloat(JsVar *v) {
|
||||
char buffer[JS_NUMBER_BUFFER_SIZE];
|
||||
jsvGetString(v, buffer, JS_NUMBER_BUFFER_SIZE);
|
||||
return stringToFloat(buffer);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript methods and functions in the global namespace
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_arguments();
|
||||
JsVar *jswrap_eval(JsVar *v);
|
||||
JsVar *jswrap_parseInt(JsVar *v, JsVar *radixVar);
|
||||
JsVarFloat jswrap_parseFloat(JsVar *v);
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript methods and functions for the interactive shell
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
#include "jsinteractive.h"
|
||||
|
||||
void jswrap_interface_setBusyIndicator(JsVar *pinVar);
|
||||
void jswrap_interface_setSleepIndicator(JsVar *pinVar);
|
||||
void jswrap_interface_setDeepSleep(bool sleep);
|
||||
void jswrap_interface_trace(JsVar *root);
|
||||
void jswrap_interface_print(JsVar *v);
|
||||
void jswrap_interface_edit(JsVar *funcName);
|
||||
void jswrap_interface_echo(bool echoOn);
|
||||
JsVar *jswrap_interface_getSerial();
|
||||
+437
File diff suppressed because it is too large.
Load diff
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript Hardware IO Functions
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
#include "jsinteractive.h"
|
||||
|
||||
void jswrap_io_analogWrite(Pin pin, JsVarFloat value, JsVar *options);
|
||||
void jswrap_io_digitalPulse(Pin pin, bool value, JsVarFloat time);
|
||||
void jswrap_io_digitalWrite(JsVar *pinVar, JsVarInt value);
|
||||
JsVarInt jswrap_io_digitalRead(JsVar *pinVar);
|
||||
void jswrap_io_pinMode(Pin pin, JsVar *mode);
|
||||
|
||||
JsVar *jswrap_interface_setInterval(JsVar *func, JsVarFloat timeout);
|
||||
JsVar *jswrap_interface_setTimeout(JsVar *func, JsVarFloat timeout);
|
||||
JsVar *jswrap_interface_setWatch(JsVar *funcVar, Pin pin, JsVar *repeatOrObject);
|
||||
void jswrap_interface_clearInterval(JsVar *idVar);
|
||||
void jswrap_interface_clearTimeout(JsVar *idVar);
|
||||
void jswrap_interface_changeInterval(JsVar *idVar, JsVarFloat interval);
|
||||
void jswrap_interface_clearWatch(JsVar *idVar);
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* This file is designed to be parsed during the build process
|
||||
*
|
||||
* JavaScript JSON-handling Functions
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jswrap_json.h"
|
||||
#include "jsparse.h"
|
||||
#include "jsinteractive.h"
|
||||
#include "jswrapper.h"
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "JSON", "name" : "stringify",
|
||||
"description" : "Convert the given object into a JSON string which can subsequently be parsed with JSON.parse or eval",
|
||||
"generate" : "jswrap_json_stringify",
|
||||
"params" : [ [ "data", "JsVar", "The data to be converted to a JSON string"] ],
|
||||
"return" : ["JsVar", "A JSON string"]
|
||||
}*/
|
||||
JsVar *jswrap_json_stringify(JsVar *v) {
|
||||
JsVar *result = jsvNewFromEmptyString();
|
||||
if (result) // could be out of memory
|
||||
jsfGetJSON(v, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "JSON", "name" : "parse",
|
||||
"description" : "Parse the given JSON string into a JavaScript object",
|
||||
"generate" : "jswrap_json_parse",
|
||||
"params" : [ [ "string", "JsVar", "A JSON string"] ],
|
||||
"return" : ["JsVar", "The JavaScript object created by parsing the data string"]
|
||||
}*/
|
||||
JsVar *jswrap_json_parse(JsVar *v) {
|
||||
JsVar *res = 0;
|
||||
JsVar *bracketed = jsvNewFromString("(");
|
||||
if (bracketed) { // could be out of memory
|
||||
v = jsvAsString(v, true); // try and get this as a string
|
||||
jsvAppendStringVarComplete(bracketed, v);
|
||||
jsvAppendString(bracketed, ")");
|
||||
res = jspEvaluateVar(jsiGetParser(), bracketed, 0);
|
||||
jsvUnLock(bracketed);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* This is like jsfGetJSONWithCallback, but handles ONLY functions (and does not print the initial 'function' text) */
|
||||
void jsfGetJSONForFunctionWithCallback(JsVar *var, JsfGetJSONCallbackString callbackString, JsfGetJSONCallbackVar callbackVar, void *callbackData) {
|
||||
assert(jsvIsFunction(var));
|
||||
JsVarRef coderef = 0; // TODO: this should really be in jsvAsString
|
||||
JsVarRef childref = var->firstChild;
|
||||
bool firstParm = true;
|
||||
callbackString(callbackData, "(");
|
||||
while (childref) {
|
||||
JsVar *child = jsvLock(childref);
|
||||
childref = child->nextSibling;
|
||||
if (jsvIsFunctionParameter(child)) {
|
||||
if (firstParm)
|
||||
firstParm=false;
|
||||
else
|
||||
callbackString(callbackData, ",");
|
||||
callbackVar(callbackData, child); // FIXME: escape the string
|
||||
} else if (jsvIsString(child) && jsvIsStringEqual(child, JSPARSE_FUNCTION_CODE_NAME)) {
|
||||
coderef = child->firstChild;
|
||||
}
|
||||
jsvUnLock(child);
|
||||
}
|
||||
callbackString(callbackData, ") ");
|
||||
if (coderef) {
|
||||
JsVar *codeVar = jsvLock(coderef);
|
||||
callbackVar(callbackData, codeVar);
|
||||
jsvUnLock(codeVar);
|
||||
} else callbackString(callbackData, "{}");
|
||||
}
|
||||
|
||||
void jsfGetJSONWithCallback(JsVar *var, JsfGetJSONCallbackString callbackString, JsfGetJSONCallbackVar callbackVar, void *callbackData) {
|
||||
if (jsvIsUndefined(var)) {
|
||||
callbackString(callbackData, "undefined");
|
||||
} else if (jsvIsArray(var)) {
|
||||
int length = (int)jsvGetArrayLength(var);
|
||||
int i;
|
||||
callbackString(callbackData, "[");
|
||||
for (i=0;i<length;i++) {
|
||||
JsVar *item = jsvGetArrayItem(var, i);
|
||||
jsfGetJSONWithCallback(item, callbackString, callbackVar, callbackData);
|
||||
jsvUnLock(item);
|
||||
if (i<length-1) callbackString(callbackData, ",");
|
||||
}
|
||||
callbackString(callbackData, "]");
|
||||
} else if (jsvIsArrayBuffer(var)) {
|
||||
callbackString(callbackData, "new ");
|
||||
callbackString(callbackData, jswGetBasicObjectName(var));
|
||||
callbackString(callbackData, "([");
|
||||
callbackVar(callbackData, jsvAsString(var, false));
|
||||
callbackString(callbackData, "])");
|
||||
} else if (jsvIsObject(var)) {
|
||||
bool first = true;
|
||||
JsVarRef childref = var->firstChild;
|
||||
callbackString(callbackData, "{");
|
||||
while (childref) {
|
||||
JsVar *child = jsvLock(childref);
|
||||
bool hidden = jsvIsInternalObjectKey(child);
|
||||
if (!hidden) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
callbackString(callbackData, ",");
|
||||
|
||||
callbackString(callbackData, "\"");
|
||||
callbackVar(callbackData, child); // FIXME: escape the string
|
||||
callbackString(callbackData, "\":");
|
||||
}
|
||||
JsVar *childVar = child->firstChild ? jsvLock(child->firstChild) : 0;
|
||||
childref = child->nextSibling;
|
||||
jsvUnLock(child);
|
||||
|
||||
if (!hidden) {
|
||||
jsfGetJSONWithCallback(childVar, callbackString, callbackVar, callbackData);
|
||||
}
|
||||
jsvUnLock(childVar);
|
||||
}
|
||||
callbackString(callbackData, "}");
|
||||
} else if (jsvIsFunction(var)) {
|
||||
callbackString(callbackData, "function ");
|
||||
jsfGetJSONForFunctionWithCallback(var, callbackString, callbackVar, callbackData);
|
||||
} else if (jsvIsString(var) && !jsvIsName(var)) {
|
||||
// escape the string
|
||||
callbackString(callbackData, "\"");
|
||||
JsvStringIterator it;
|
||||
jsvStringIteratorNew(&it, var, 0);
|
||||
while (jsvStringIteratorHasChar(&it)) {
|
||||
char ch = jsvStringIteratorGetChar(&it);
|
||||
callbackString(callbackData, escapeCharacter(ch));
|
||||
jsvStringIteratorNext(&it);
|
||||
}
|
||||
jsvStringIteratorFree(&it);
|
||||
callbackString(callbackData, "\"");
|
||||
} else {
|
||||
JsVar *str = jsvAsString(var, false);
|
||||
if (str) {
|
||||
callbackVar(callbackData, str);
|
||||
jsvUnLock(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jsfGetJSON(JsVar *var, JsVar *result) {
|
||||
assert(jsvIsString(result));
|
||||
jsfGetJSONWithCallback(var, (JsfGetJSONCallbackString)jsvAppendString, (JsfGetJSONCallbackVar)jsvAppendStringVarComplete, result);
|
||||
}
|
||||
|
||||
void _jsfPrintJSON_str(void *data, const char *str) { NOT_USED(data); jsiConsolePrint(str); }
|
||||
void _jsfPrintJSON_var(void *data, JsVar *var) { NOT_USED(data); jsiConsolePrintStringVar(var); }
|
||||
void jsfPrintJSON(JsVar *var) {
|
||||
jsfGetJSONWithCallback(var, _jsfPrintJSON_str, _jsfPrintJSON_var, 0);
|
||||
}
|
||||
void jsfPrintJSONForFunction(JsVar *var) {
|
||||
jsfGetJSONForFunctionWithCallback(var, _jsfPrintJSON_str, _jsfPrintJSON_var, 0);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript JSON-handling Functions
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_json_stringify(JsVar *v);
|
||||
JsVar *jswrap_json_parse(JsVar *v);
|
||||
|
||||
typedef void (*JsfGetJSONCallbackString)(void *data, const char *string);
|
||||
typedef void (*JsfGetJSONCallbackVar)(void *data, JsVar *var);
|
||||
|
||||
/* This is like jsfGetJSONWithCallback, but handles ONLY functions (and does not print the initial 'function' text) */
|
||||
void jsfGetJSONForFunctionWithCallback(JsVar *var, JsfGetJSONCallbackString callbackString, JsfGetJSONCallbackVar callbackVar, void *callbackData);
|
||||
/* Dump to JSON, using the given callbacks for printing data */
|
||||
void jsfGetJSONWithCallback(JsVar *var, JsfGetJSONCallbackString callbackString, JsfGetJSONCallbackVar callbackVar, void *callbackData);
|
||||
|
||||
/* Convenience function for using jsfGetJSONWithCallback - print to var */
|
||||
void jsfGetJSON(JsVar *var, JsVar *result);
|
||||
|
||||
/* Convenience function for using jsfGetJSONWithCallback - print to console */
|
||||
void jsfPrintJSON(JsVar *var);
|
||||
/* Convenience function for using jsfGetJSONForFunctionWithCallback - print to console */
|
||||
void jsfPrintJSONForFunction(JsVar *var);
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* This file is designed to be parsed during the build process
|
||||
*
|
||||
* JavaScript Functions for handling Modules
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jswrap_functions.h"
|
||||
#include "jslex.h"
|
||||
#include "jsvar.h"
|
||||
#include "jsparse.h"
|
||||
#include "jsinteractive.h"
|
||||
#include "jswrapper.h"
|
||||
#ifdef USE_FILESYSTEM
|
||||
#include "../libs/jswrap_fat.h"
|
||||
#endif
|
||||
|
||||
static JsVar *jswrap_modules_getModuleList() {
|
||||
JsVar *moduleListName = jsvFindChildFromString(jsiGetParser()->root, JSPARSE_MODULE_CACHE_NAME, true);
|
||||
if (!moduleListName) return 0; // out of memory
|
||||
JsVar *moduleList = jsvSkipName(moduleListName);
|
||||
if (!moduleList) {
|
||||
moduleList = jsvNewWithFlags(JSV_OBJECT);
|
||||
if (!moduleList) { jsvUnLock(moduleListName); return 0; } // out of memory
|
||||
jsvSetValueOfName(moduleListName, moduleList); // no need to unlock
|
||||
}
|
||||
jsvUnLock(moduleListName);
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
/*JSON{ "type":"function", "name" : "require",
|
||||
"description" : "Load the given module, and return the exported functions",
|
||||
"generate" : "jswrap_require",
|
||||
"params" : [ [ "moduleName", "JsVar", "A String containing the name of the given module"] ],
|
||||
"return" : ["JsVar", "The result of evaluating the string"]
|
||||
}*/
|
||||
JsVar *jswrap_require(JsVar *moduleName) {
|
||||
if (!jsvIsString(moduleName)) {
|
||||
jsWarn("Expecting a module name as a string, but got %t", moduleName);
|
||||
return 0;
|
||||
}
|
||||
// Search to see if we have already loaded this module
|
||||
|
||||
JsVar *moduleList = jswrap_modules_getModuleList();
|
||||
if (!moduleList) return 0; // out of memory
|
||||
JsVar *moduleExportName = jsvFindChildFromVar(moduleList, moduleName, true);
|
||||
jsvUnLock(moduleList);
|
||||
if (!moduleExportName) return 0; // out of memory
|
||||
JsVar *moduleExport = jsvSkipName(moduleExportName);
|
||||
if (moduleExport) {
|
||||
// Found the module!
|
||||
jsvUnLock(moduleExportName);
|
||||
return moduleExport;
|
||||
}
|
||||
|
||||
// Now check if it is built-in
|
||||
char moduleNameBuf[32];
|
||||
jsvGetString(moduleName, moduleNameBuf, sizeof(moduleNameBuf));
|
||||
if (jswIsBuiltInLibrary(moduleNameBuf)) {
|
||||
// create a 'fake' module that Espruino can use to map its built-in functions against
|
||||
moduleExport = jspNewBuiltin(moduleNameBuf);
|
||||
} else {
|
||||
// Now try and load it
|
||||
JsVar *fileContents = 0;
|
||||
//if (jsvIsStringEqual(moduleName,"http")) {}
|
||||
//if (jsvIsStringEqual(moduleName,"fs")) {}
|
||||
#ifdef USE_FILESYSTEM
|
||||
JsVar *modulePath = jsvNewFromString(
|
||||
#ifdef LINUX
|
||||
"node_modules/"
|
||||
#else
|
||||
"NODE_M~1/"
|
||||
#endif
|
||||
);
|
||||
if (!modulePath) { jsvUnLock(moduleExportName); return 0; } // out of memory
|
||||
jsvAppendStringVarComplete(modulePath, moduleName);
|
||||
jsvAppendString(modulePath,".js");
|
||||
fileContents = wrap_fat_readFile(modulePath);
|
||||
jsvUnLock(modulePath);
|
||||
#endif
|
||||
if (!fileContents || jsvIsStringEqual(fileContents,"")) {
|
||||
jsvUnLock(moduleExportName);
|
||||
jsvUnLock(fileContents);
|
||||
jsWarn("Module not found");
|
||||
return 0;
|
||||
}
|
||||
moduleExport = jspEvaluateModule(jsiGetParser(), fileContents);
|
||||
jsvUnLock(fileContents);
|
||||
}
|
||||
|
||||
assert(moduleExport);
|
||||
jsvSetValueOfName(moduleExportName, moduleExport); // save in cache
|
||||
jsvUnLock(moduleExportName);
|
||||
return moduleExport;
|
||||
}
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "Modules", "name" : "getCached",
|
||||
"description" : "Return an array of module names that have been cached",
|
||||
"generate" : "jswrap_modules_getCached",
|
||||
"return" : ["JsVar", "An array of module names"]
|
||||
}*/
|
||||
JsVar *jswrap_modules_getCached() {
|
||||
JsVar *arr = jsvNewWithFlags(JSV_ARRAY);
|
||||
if (!arr) return 0; // out of memory
|
||||
|
||||
JsVar *moduleList = jswrap_modules_getModuleList();
|
||||
if (!moduleList) return arr; // out of memory
|
||||
|
||||
JsObjectIterator it;
|
||||
jsvObjectIteratorNew(&it, moduleList);
|
||||
while (jsvObjectIteratorHasElement(&it)) {
|
||||
JsVar *idx = jsvObjectIteratorGetKey(&it);
|
||||
JsVar *idxCopy = jsvCopyNameOnly(idx, false, false);
|
||||
jsvArrayPushAndUnLock(arr, idxCopy);
|
||||
jsvUnLock(idx);
|
||||
jsvObjectIteratorNext(&it);
|
||||
}
|
||||
jsvObjectIteratorFree(&it);
|
||||
jsvUnLock(moduleList);
|
||||
return arr;
|
||||
}
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "Modules", "name" : "removeCached",
|
||||
"description" : "Remove the given module from the list of cached modules",
|
||||
"generate" : "jswrap_modules_removeCached",
|
||||
"params" : [ [ "id", "JsVar", "The module name to remove"] ]
|
||||
}*/
|
||||
void jswrap_modules_removeCached(JsVar *id) {
|
||||
if (!jsvIsString(id)) {
|
||||
jsError("The argument to removeCached must be a string");
|
||||
return;
|
||||
}
|
||||
JsVar *moduleList = jswrap_modules_getModuleList();
|
||||
if (!moduleList) return; // out of memory
|
||||
|
||||
JsVar *moduleExportName = jsvFindChildFromVar(moduleList, id, false);
|
||||
if (!moduleExportName) {
|
||||
jsWarn("Module not found");
|
||||
} else {
|
||||
jsvRemoveChild(moduleList, moduleExportName);
|
||||
jsvUnLock(moduleExportName);
|
||||
}
|
||||
|
||||
jsvUnLock(moduleList);
|
||||
}
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "Modules", "name" : "removeAllCached",
|
||||
"description" : "Remove all cached modules",
|
||||
"generate" : "jswrap_modules_removeAllCached"
|
||||
}*/
|
||||
void jswrap_modules_removeAllCached() {
|
||||
JsVar *moduleList = jswrap_modules_getModuleList();
|
||||
if (!moduleList) return; // out of memory
|
||||
jsvRemoveAllChildren(moduleList);
|
||||
jsvUnLock(moduleList);
|
||||
}
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "Modules", "name" : "addCached",
|
||||
"description" : "Add the given module to the cache",
|
||||
"generate" : "jswrap_modules_addCached",
|
||||
"params" : [ [ "id", "JsVar", "The module name to add" ],
|
||||
[ "sourcecode", "JsVar", "The module's sourcecode" ] ]
|
||||
}*/
|
||||
void jswrap_modules_addCached(JsVar *id, JsVar *sourceCode) {
|
||||
if (!jsvIsString(id) || !jsvIsString(sourceCode)) {
|
||||
jsError("Both arguments to addCached must be strings");
|
||||
return;
|
||||
}
|
||||
|
||||
JsVar *moduleList = jswrap_modules_getModuleList();
|
||||
if (!moduleList) return; // out of memory
|
||||
|
||||
JsVar *moduleExport = jspEvaluateModule(jsiGetParser(), sourceCode);
|
||||
if (!moduleExport) {
|
||||
jsWarn("Unable to load module");
|
||||
} else {
|
||||
JsVar *moduleName = jsvFindChildFromVar(moduleList, id, true);
|
||||
if (moduleName) jsvSetValueOfName(moduleName, moduleExport);
|
||||
jsvUnLock(moduleExport);
|
||||
}
|
||||
jsvUnLock(moduleList);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript Functions for handling Modules
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_require(JsVar *modulename);
|
||||
|
||||
JsVar *jswrap_modules_getCached();
|
||||
void jswrap_modules_removeCached(JsVar *id);
|
||||
void jswrap_modules_removeAllCached();
|
||||
void jswrap_modules_addCached(JsVar *id, JsVar *sourceCode);
|
||||
+332
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* JavaScript methods for Objects and Functions
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_object_length(JsVar *parent);
|
||||
JsVar *jswrap_object_toString(JsVar *parent, JsVar *arg0);
|
||||
JsVar *jswrap_object_clone(JsVar *parent);
|
||||
JsVar *jswrap_object_keys(JsVar *obj);
|
||||
|
||||
void jswrap_object_on(JsVar *parent, JsVar *event, JsVar *listener);
|
||||
void jswrap_object_emit(JsVar *parent, JsVar *event, JsVar *v1, JsVar *v2);
|
||||
void jswrap_object_removeAllListeners(JsVar *parent, JsVar *event);
|
||||
|
||||
void jswrap_function_replaceWith(JsVar *parent, JsVar *newFunc);
|
||||
JsVar *jswrap_function_call(JsVar *parent, JsVar *thisArg, JsVar *a, JsVar *b, JsVar *c, JsVar *d);
|
||||
JsVar *jswrap_function_apply(JsVar *parent, JsVar *thisArg, JsVar *argsArray);
|
||||
Loaded 100 of 115 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user