GithubHelp home page GithubHelp logo

ikysil / ikforth Goto Github PK

View Code? Open in Web Editor NEW
12.0 7.0 3.0 17.28 MB

ikforth is an idiomatic Forth implementation.

Home Page: https://ikysil.github.io/ikforth/

License: The Unlicense

Forth 86.09% Assembly 10.51% C++ 1.62% Python 0.60% C 0.11% Roff 0.04% Dockerfile 0.89% Shell 0.14%
forth 32-bits dtc itc linux windows x86-32 forth-94 forth-2012

ikforth's Introduction

ikforth

ikforth is an idiomatic Forth implementation.

Build Status

A few facts:

  • 32 bits code
  • Runs on Linux and Windows (tested with Wine)
  • Supports Indirect and Direct Threaded Code representations
  • Image-based system
  • x86 assembler is used to bootstrap image capable of interpreting from files
  • Image is NOT relocatable - absolute 32 bits addresses are used in native and threaded code
  • CELL size is 32 bits
  • CHAR size is 8 bits
  • addressable unit - 1 byte (8 bits)

ikforth's People

Contributors

ikysil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ikforth's Issues

FLOAT: implement format output

\ Compact Formatted String
\ ------- --------- ------
\ FS. FS.R (FS.) Scientific
\ FE. FE.R (FE.) Engineering
\ F. F.R (F.) Fixed-point
\ G. G.R (G.) General

FLOAT: F. output format

Answers between 10^10 and 10^-2 were always displayed as floating-point numbers with the decimal point properly located and the exponent field blank.

Reorganize bootstrap dictionary source code

Reorganize bootstrap dictionary source code.

Main goal: clear separation between CPU architecture-specific code and CPU-neutral threaded code.

Sub-goals:

  • keep source files size manageable.

MainProc does not respect stdcall calling convention

This leads to SEGFAULT in PIC code as EBX is used as a GOT (Global Offset Tables) pointer.

All
The 32-bit x86 calling conventions all preserve the EDI, ESI, EBP, and EBX registers, using the EDX:EAX pair for return values.

__stdcall
This is the calling convention used for Win32, with exceptions for variadic functions (which necessarily use _cdecl) and a very few functions that use _fastcall. Parameters are pushed from right to left [corrected 10:18am] and the callee cleans the stack. Function names are decorated by a leading underscore and a trailing @-sign followed by the number of bytes of parameters taken by the function.
3:44 PM
i386
This is a 32-bit platform. The stack grows downwards. Parameters to functions are passed on the stack in reverse order such that the first parameter is the last value pushed to the stack, which will then be the lowest value on the stack. Parameters passed on the stack may be modified by the called function. Functions are called using the call instruction that pushes the address of the next instruction to the stack and jumps to the operand. Functions return to the caller using the ret instruction that pops a value from the stack and jump to it. The stack is 16-byte aligned just before the call instruction is called.

Functions preserve the registers ebx, esi, edi, ebp, and esp; while eax, ecx, edx are scratch registers. The return value is stored in the eax register, or if it is a 64-bit value, then the higher 32-bits go in edx. Functions push ebp such that the caller-return-eip is 4 bytes above it, and set ebp to the address of the saved ebp. This allows iterating through the existing stack frames. This can be eliminated by specifying the -fomit-frame-pointer GCC option.

As a special exception, GCC assumes the stack is not properly aligned and realigns it when entering main or if the attribute ((force_align_arg_pointer)) is set on the function.

Implement MARKER

https://forth-standard.org/standard/core/MARKER

MARKER
( "name" -- )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for name with the execution semantics defined below.

name Execution:
( -- )

Restore all dictionary allocation and search order pointers to the state they had just prior to the definition of name. Remove the definition of name and all subsequent definitions. Restoration of any structures still existing that could refer to deleted definitions or deallocated data space is not necessarily provided. No other contextual information such as numeric base is affected.

Open points:

  • restoring values of DEFERs
    • idea - redefine DEFER or IS

float-ieee-binary: +0e <> -0e which contradicts IEEE

Since the sign bit can take on two different values, there are two zeros, +0 and -0. If a distinction were made when comparing +0 and -0, simple tests like if (x = 0) would have very unpredictable behavior, depending on the sign of x. Thus the IEEE standard defines comparison so that +0 = -0, rather than -0 < +0. Although it would be possible always to ignore the sign of zero, the IEEE standard does not do so. When a multiplication or division involves a signed zero, the usual sign rules apply in computing the sign of the answer. Thus 3·(+0) = +0, and +0/-3 = -0. If zero did not have a sign, then the relation 1/(1/x) = x would fail to hold when x = ±. The reason is that 1/- and 1/+ both result in 0, and 1/0 results in +, the sign information having been lost. One way to restore the identity 1/(1/x) = x is to only have one kind of infinity, however that would result in the disastrous consequence of losing the sign of an overflowed quantity.

Another example of the use of signed zero concerns underflow and functions that have a discontinuity at 0, such as log. In IEEE arithmetic, it is natural to define log 0 = - and log x to be a NaN when x < 0. Suppose that x represents a small negative number that has underflowed to zero. Thanks to signed zero, x will be negative, so log can return a NaN. However, if there were no signed zero, the log function could not distinguish an underflowed negative number from 0, and would therefore have to return -. Another example of a function with a discontinuity at zero is the signum function, which returns the sign of a number.

What Every Computer Scientist Should Know About Floating-Point Arithmetic, section Signed Zero

float-ieee-binary: Square root is neither chopped nor correctly rounded.

Running test of square root(x).
Testing if sqrt(X * X) == X for 20 Integers X.
Test for sqrt monotonicity.
sqrt has passed a test for Monotonicity.
Testing whether sqrt is rounded or chopped.
Square root is neither chopped nor correctly rounded.
Observed errors run from -6.049382720070228842E-1 to 5.000000000000000000E-1  ulps.

Implement support for constants dictionary

Implement support for constants dictionary

  • no executable code in the definitions
  • 1 CELL value
  • 1 CELL pointer to additional data
  • duplicates are not searchable, only the last definition is returned
  • binary search

Build in Cygwin

Hi! How to build ikforth in Cygwin environment?

Running scons from the project root directory produces the key error: KeyError: 'HSYS' in file SConstruct, line 7.

float-ieee-binary: Improve F**

Improve F**:

  • add special handling for integer powers

paranoia report:

Testing powers Z^i for small Integers Z and i.
DEFECT computing  -1.000000000000000000E0 ^-3.000000000000000000E0
    yielded 1.000000000000000000E0
    which compared unequal to correct -1.000000000000000000E0
         they differ by 2.000000000000000000E0
Similar discrepancies have occurred 5  times.
DEFECT computing  2.000000000000000000E0 ^1.000000000000000000E0
    yielded 1.999999999999999997E0
    which compared unequal to correct 2.000000000000000000E0
         they differ by -2.168404344971008868E-18
Errors like this may invalidate financial calculations
involving interest rates.
Similar discrepancies have occurred 325  times.
Diagnosis resumes after milestone Number 100

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.