Swift For Mac
Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. And the open-source community, first released in 2014.Swift was developed as a replacement for Apple's earlier programming language Objective-C, as Objective-C had been largely unchanged since the early 1980s and lacked modern language features.Swift works with Apple's Cocoa and Cocoa Touch.
- Swift Publisher 5.5 is an easy to use, all-in-one desktop publishing solution for Mac users on a budget, now with the ability to quickly create and print disc labels, inserts, labels, envelopes.
- #swift #swiftui #mac So far, nearly all the articles I have seen about SwiftUI show it being used for iOS, more particularly for iPhone. But SwiftUI works on all Apple’s platforms, and as I am primarily a Mac developer, I decided to try out a Mac app and see what happened.
- Run Swift is a web tool where you can easily try Apple's Swift language online. Just paste any snippet, switch to the Swift version you prefer (either 2.2 - without Foundation support - 3.1, or 4.0-dev) and click Run. You may also Save your scripts and/or share with the world.
- Swift Publisher is a low-cost desktop publishing program that's perfect for graphic-design neophytes who need to produce simple documents such as posters, letterhead, cards, and fliers.
Everything application developers need is found in this development system for Windows, Linux, and macOS. Access to native system functions is easy. The Forth programming language is the high-performance foundation of this full-featured, interactive development environment.
On This Page
- Overview
- Forth Implementation Features
- Programming Tools
- Debugging Tools
- Libraries, Functions, Callbacks, and Threads
- IDE for Windows Programming
- SwiftForth Programming Language References
Overview
SwiftForth brings the fast, powerful, ANS Forth programming language to Windows, Linux, and macOS.
Highlights
- No need for an external compiler, assembler, or linker.
- Easy access to all system functions and dynamic libraries.
- Includes SWOOP™, a powerful object-oriented Forth programming system.
- Command window provides interactive development environment.
- Simple linking to the programmer’s editor of your choice.
- Advanced debugging features include built-in cross reference, source browser, and disassembler/decompiler.
- Powerful rule-based optimizing compiler.
Documentation
After installation, the full SwiftForth documentation (all in PDF format; requires Adobe Reader) will be located in the SwiftForth/doc directory. The documentation consists of:
- SwiftForth Reference Manual
- ANS Forth Standard
- Forth Programmer’s Handbook
Complete source code
The fully licensed version of SwiftForth includes complete source, including the kernel, Interactive Development Environment (IDE), and all features.
SwiftForth also includes the cross compiler, which compiles the kernel, so you can customize the kernel to your needs.
System requirements
These are the OS-specific requirements for SwiftForth:
- GUI IDE for Windows: Windows 7 or later
- Command-line IDE for macOS: Mac OS X 10.6 through macOS 10.14 (requires 32-bit library support)
- Command-line IDE for Linux: Linux 2.6 kernel with 32-bit library support
SwiftForth requires an i386-compatible CPU. If you’re looking for something for your Beaglebone, Raspberry Pi, or other embedded ARM Linux board, check out SwiftX-ARM for Linux targets.
Forth Implementation Features
SwiftForth is designed to produce optimal performance. This section describes the implementation of the Forth virtual machine, and will be of interest to experienced Forth programmers.
Execution model
SwiftForth is a 32-bit, subroutine-threaded Forth system running as user application under Windows, Linux, and macOS.
Subroutine threading is an implementation strategy in which references in a colon definition are compiled as subroutine calls. SwiftForth substitutes direct code in place of subroutine calls wherever possible for efficiency.
Colon and code definitions do not have a code field distinct from the content of the definition itself; data structures typically have a code field consisting of a call to the code for that data type. At the end of a colon definition, the conventional EXIT is replaced by a subroutine return (or by tail recursion).
The nature of a subroutine-threaded implementation lends itself to inline code expansion. SwiftForth takes advantage of this by having a header flag that indicates if a word is to be compiled inline or called. The compiler will automatically inline a definition whose INLINE field is set. Many of the kernel-level CODE words are marked to be inlined.
SwiftForth’s CPU register usage
Register | Purpose |
---|---|
EBX | top of stack |
ESI | user area pointer |
EDI | executable base address |
EBP | data stack pointer |
ESP | return stack pointer |
All other CPU registers are available for use without saving and restoring.
Memory model
SwiftForth runs in a single, contiguous, flat 32-bit address space. SwiftForth is position independent, which means it can run wherever the host OS has loaded it without having to keep track of where that is.
By being position independent, SwiftForth simplifies and speeds up interactions with the host environment. This feature is a natural consequence of subroutine threading, because i386 call instructions use relative addresses. Forth execution tokens are relative to the start of the run-time memory space, but they are used only internally and do not need conversion. All data objects that return addresses return full absolute addresses that can be passed to the host OS, if desired, without conversion.
Dictionary features
The SwiftForth dictionary can accommodate word names up to 254 characters in length. Wordlists are multithreaded via a hashing mechanism to speed up the dictionary search process. Wordlists in SwiftForth may have any number of threads; the default number of threads is 31.
ANS compliance
SwiftForth was implemented for ANS Forth compliance, and includes a copy of the Hayes compliance test suite. The Core, Core Extensions, Blocks, Double Number, Exception, Facility, File Access, Floating Point, Memory Allocation, Programming Tools, Search Order, and String wordsets are complete except for words marked obsolescent. A Local Variables wordset is provided that is compliant except for argument order.
Text and block-file support
The interpreter will handle both text and block files.
For text files, the system provides for linking to an arbitrary external editor. LOCATE is fully supported for both text and block files, displaying a portion of source in the command window with an option to switch to an external editor. The normal LIST method is used for block files.
Assembler and disassembler
A postfix assembler and disassembler are supplied. The assembler supports the required set of Intel-defined operations and addressing modes. Except for the ordering of arguments, it is essentially identical to Intel notation. Structured conditionals (IF, THEN, etc.) are implemented.
The disassembler can decompile high-level Forth words as well as CODE definitions.
Local variables
SwiftForth provides a local variables implementation that is compatible with ANS Forth. Local variables in SwiftForth are instantiated on the return stack.
Floating-point math
SwiftForth includes good support for floating-point math. Use of the hardware FP stack is optional (e.g., use it for optimum speed when you don’t require more than about six or seven floating-point values on the stack at a time).
SwiftForth includes the ANS Forth floating-point wordset, plus high-level words for trig, log and exponential functions, and words for defining and displaying matrices. Input and display formats are configurable.
SwiftForth also includes the entire Forth Scientific Library, with the required compatibility layer. Information about the contents of this library may be found at https://www.taygeta.com/fsl/scilib.html.
Optimizing Compiler
SwiftForth includes a powerful rule-based optimizing compiler.
As noted previously, SwiftForth uses inlined code and tail recursion to increase efficiency. More extensive optimization is provided by a powerful rule-based optimizer that can optimize hundreds of common high-level phrases. This optimizer is normally enabled, but can be disabled for debugging or comparison purposes.
For example, consider the definition of DIGIT, which converts a small binary number to a printable character:
With the optimizer disabled, the following code is generated (displayed here using the SwiftForth disassembler):
With the optimizer enabled, the benefits are obvious:
Programming Tools
Command-line editing and history
When you type in the command window, SwiftForth will wait to process what you’ve typed until you press the Enter key. Before pressing Enter, you may backspace or use the left- and right-arrow keys to edit your command line. The up- and down-arrow keys page through a buffer of previous command lines.
The SwiftForth command-line processor also implements tab completion. Pressing the Tab key after typing a few characters repeatedly completes the line from matching patterns in the command history buffer.
Integrated source browsing
You view the source for any word in the current search order by typing LOCATE <name>. This displays the line in the source on which the word appears, with several lines after it as well as the file in which the source is located and the line numbers of the lines displayed. Here’s an example:
Link to your favorite source editor
You may invoke your linked editor — for the word whose source was most recently displayed by LOCATE word — by typing EDIT. The editor will be launched and open with the correct source line selected.
Alternatively, you can type EDIT <name> to open the editor positioned at the line with the definition of name.
Cross-reference command
SwiftForth provides a cross-reference tool that enables you to find all references to a word. To find all the places a word is used, type:
This displays the first line of the definition of name, followed by each line of source code in which name is referenced in the currently loaded code. If there are multiple definitions with the same name, WHERE will list each definition and the references to it separately. The shortcut:
does the same thing. This command is not the same as a source search; it is based on the code that is loaded right now. This means you will be spared any instances of name in files you aren’t using and can see redifinitions and their respective references.
Debugging Tools
Disassembler and decompiler
SwiftForth includes a disassembler that can be used to generate human-readable source code from compiled definitions. This is useful as a cross check, whenever a new definition fails to work as expected, and also shows the results of SwiftForth’s optimizing compiler. By disassembling a definition, you can see exactly what instructions were generated by the compiler.
The single command SEE <name> disassembles the code generated for name.
For example, the definition of TIMER is:
It disassembles as follows:
The left column shows the memory location being disassembled. This is followed by the instruction (or data) at that location. Note that the disassembler attempts to match named locations in memory with their addresses. The right column shows the actual bytes in memory.
Single-step debugger
A simple single-step debugger allows you to step through code compiled from a source file. Here is a simple example:
Assuming this source has been compiled, you may type 4 DEBUG 5X to enter the single-step debug loop.
At each step, the source line is displayed with the next word to be stepped through highlighted. After this, the current data stack is displayed (in the familiar .S format) along with a prompt for the next step:
- Nest executes the next word, nesting if it is a call.
- Step executes the next word, with no nesting.
- Return executes to the end of the current (nested) definition without stopping.
- Finish executes to the end of the top-level definition without stopping.
SWOOP: Object-Oriented Forth Programming
Swift Publisher For Mac
SwiftForth includes a powerful object-oriented Forth programming package called SWOOP. SWOOP provides the essential features of object-oriented programming.
- Encapsulation: combining data and methods into a single package that responds to messages.
- Information hiding: the ability of an object to possess data and methods not accessible outside its class.
- Inheritance: the ability to define a new class based on a previously defined (parent) class. The new class automatically possesses all members of the parent; it may add to or replace these members, or define behaviors for deferred members.
- Polymorphism: the ability of different sub-classes of a class to respond to the same message in different ways. For example, adding a pair of scalars is different from adding a pair of vectors.
SwiftForth’s support of object-oriented programming is extensive and powerful. The following brief introductory information is excerpted from the SwiftForth Reference Manual.
POINT (defined below) is a simple class we shall use as a primary building-block example for SWOOP. It demonstrates two of the four basic class member types: data and colon. The word following CLASS is the name of the class; all definitions between CLASS and END-CLASS belong to it. These definitions are referred to as the members of the class. When a class name is executed, it leaves its handle (xt) on the stack. The constructor words are the primary consumers of this handle.
The class definition itself does not allocate any instance storage; it only records how much storage is required for each instance of the class. VARIABLE reserves a cell of space and associates it with a member name.
The colon members SHOW and DOT are like normal Forth colon definitions, but are only valid in the execution context of an object of type POINT. X and Y also behave exactly like normal VARIABLEs in the Forth programming language.
There are five kinds of members:
- Data members include all data definitions. Available data-member defining words include CREATE (normally followed by data compiled with , or C,), BUFFER: (an array whose length is specified in address units), VARIABLE, CVARIABLE (single char), or CONSTANTs.
- Colon members are definitions that may act on or use data members.
- Other previously defined objects, available within this object.
- Deferred members are colon-like definitions with default behaviors that can be referenced while defining the class, but which may have substitute behaviors defined by sub-classes defined later. These allow for polymorphism and late binding.
- Messages are unnamed responses to arbitrary numeric message values.
Objects may be static or dynamic. Both early and late binding are supported. Instance data and methods are implemented in a manner that is very efficient in the context of a Forth development environment.
Libraries, Functions, Callbacks, and Threads
Because SwiftForth was designed from the outset as a hosted system, great care has been given to make the interface to system and library functions as clean and easy to use as possible, given the inherent complexity of the OS environment.
Easy access to system functions via dynamic libraries
System functions in Windows, Linux, and macOSare provided to an application program via the dynamic library mechanism. SwiftForth supports a simple library function import mechanism that is based on the C function prototype.
Before referencing a function in a library, you must first open the library:
Any function in a library may be made available as a Forth word:
…where name is the (case-sensitive) published function name, params represents the list of paramters passed to the library function and the (optional) result is the returned value. Parameters are provided on the stack in the order described in the function prototype, so it’s easy to reference the function from a Forth program.
Both C-prototype and Pascal-prototype library functions may be called; SwiftForth passes the parameter stack to the external functions automatically. Functions with identical names from different libraries may be invoked without name collision via an alias mechanism. Lists of currently attached libraries and their imported functions may be displayed in the debug window at any time.
Here is an example of the import of the Windows global memory allocation function from Kernel32.dll:
This is the import of the Linux heap memory allocation function from libc:
The macOS version is nearly identical to the Linux one:
System callbacks
A callback is an entry point into your program. It is provided for the OS to call in certain circumstances to pass messages or signals to your program.
A callback is much like an interrupt in other programming environments, in that the code that responds to it is not executing as a sequential part of your application. In SwiftForth, callbacks are handled by a transient “task” with its own stacks and user area; it exists only for the duration of the callback function. Callbacks may execute any reentrant SwiftForth words, but may not directly communicate with the running program other than by storing data where the program may find it.
You may define a callback with any number of parameters, using the form:
…where xt is the execution token of the routine to respond to the callback, and n is the number of parameters passed to the callback.
A callback must always return a single integer result, which is used as the return value from the callback function. The defining word CB: wraps the execution of the xt with the necessary code to construct and discard the transient task environment in which the callback runs. Executing name returns the address to pass to the OS (e.g., as a message or signal handler).
Multitasking with threads
SwiftForth provides a simple facility for defining and activating tasks which are themselves threads within the SwiftForth program. A thread is similar to the background task of other Forth implementations in that it is given its own Forth stacks and user area and is executing code from within SwiftForth’s dictionary space.
IDE for Windows Programming
System messages
System messages are handled via a compiled switch mechanism, which can be easily extended to include any new messages that need to be handled. For example, this is the code to extend the standard existing Windows message handler SFMESSAGES to include keystroke events:
Windows dialogs
Dialog boxes are supported via a simple dialog compiler, which parallels the Microsoft resource compiler. SwiftForth’s console debugging tool can be used to trace the execution of Windows dialog box code.
Making DLLs and exporting functions
In SwiftForth, it is a simple matter to create Windows DLLs with exported functions. A DLL made from SwiftForth contains the entire system. Any program capable of calling DLL-based functions may import the exported functions.
DDE support
SwiftForth includes optional DDE client services, including a simple set of user words for sending or requesting data:
TELL sends a string to an item on the server and ASK gets an item from the server. For example:
Menu definition and execution
SwiftForth provides a simple means of defining menus and relating menu items to Forth words. The mechanism provides for context-sensitive item execution by the user, and is easily extensible by simply defining a Forth name that directly corresponds to the menu text. For example, the “Hello World” demo in the figure shown here includes File and About menus, defined by:
Behaviors may be attached using extensible switch structures. The menu items MI_EXIT and MI_ABOUT defined in the above popups may be assigned behaviors like this:
The code following the RUN: is an unnamed definition attached to the respective menu item. A named word that is already defined may also be attached by replacing RUN: with RUNS <name>.
Exception handler
Windows exceptions, which are caught by the standard exception filter, are trapped, logged, and generate a simple Forth THROW which the user can capture and handle. Errors during callbacks are also caught and handled.
SwiftForth Programming Language References
Windows API Reference
MSDN Library
This portion of the MSDN Library contains essential resources for developing with Win32. Use the Search box to quickly find details for specific Win32 API calls.
Intel® 64 and IA-32 Architectures
Software Developer’s Manuals
Intel® 64 and IA-32 Architectures Software Developer’s Manuals describe the architecture and programming environment of the Intel® 64 and IA-32 processors.
PlanSwift is the fastest and easiest takeoff software available.
1) Point & Click
Takeoff and Estimate in seconds, if it’s colored it’s counted.
Quick Look
2) Drag & Drop
Drag and Drop material and labor assemblies onto your takeoff.
Quick Look
3) Print or Export
Sharing your estimate is easy, and PlanSwift is fully Excel compatible.
Quick Look
Point & Click
Just Point & Click and your takeoff is done. Takeoff simple or complex areas, items, lengths, volumes, perimeters in seconds, if it’s colored it’s counted.
Drag & Drop Parts / Assemblies
Drag & Drop pre-configured Assemblies (materials, waste and labor costs) onto your takeoff items and PlanSwift instantly calculates all your costs and expenses.
This Drag & Drop feature will greatly increase the accuracy of and reduce the time it takes to Estimate a job.
Print or Export Takeoffs / Estimates
Internal Calculations
Material Calculations
Labor Calculations
PlanSwift for Trades
PlanSwift is easily customized for you and your specific trade. Simply create assemblies of commonly used materials, waste and even labor. Then drag those assemblies onto the takeoff items for instant and accurate estimates of all your costs!
General Contractors
- Takeoff in a fraction of the time with PlanSwift software click, drop, and estimate functionality.
- Manage projects large and small with accurate and timely calculations.
- Easily adjust cost projections, simply change product cost and recalculate!
- Bid more jobs, manage more efficiently and grow your business with PlanSwift takeoff and estimating software.
Fast and Accurate Drywall Takeoff
- Simply point and click to measure walls, ceilings and partitions.
- Calculate your square footage and surface areas quickly with our area and linear tools.
- PlanSwift automatically calculates materials and labor for a perfect estimate, every time.
- You’ll make more accurate estimates much quicker, saving time and money!
More on Estimating Software for Drywall
Electrical Takeoff Made Easy With PlanSwift
- Measures lengths for conduits, wiring and cables quickly and accurately
- Adds total number of switches and receptacles with ease.
- Automatically calculates materials and costs
- Export into estimate in a snap, saves time, money and effort
More about Electrical Estimating Software
Save Time on Flooring Takeoff and Estimating
Swift For Macos Apps
- One Click area select for tile,carpet , hardwood or laminate floor areas.
- Speedy perimeter measurement for nail strip and baseboard needs.
- Measure, count, calculate, print or export your estimate with our easy takeoff software.
- Estimate more accurately in less time. Bid and win more jobs.
More on Estimating Software for Flooring
Fast and Accurate Framing Estimates
- Measure joists, rafters, studs, headers, etc.
- Count posts, connectors and more.
- Calculate labor, waste and equipment hours.
- Print or export your estimate with our easy takeoff software.
- Estimate more accurately in less time. Bid and win more jobs.
More on Estimating Software for Framing
Mechanical HVAC Takeoff in a Snap
- Quickly trace linear takeoff for A/C supply lines.
- Instantly derive volume of rooms for heating and cooling.
- Generate precise material lists for HVAC assembly and instantly calculate cost.
- Do faster takeoff estimates that are mistake free!
Learn more about HVAC estimating software
Landscaping Takeoff and Estimating Software
- Easily measures square footage, volumes and linear dimensions, even if the “linear” is curved.
- Get instant, accurate area dimensions for sod, mulch, gravel and other products with a Single Click.
- Get an accurate professional estimate with a point, drag and click.
- Faster, more accurate estimates save you time and help your bottom line!
More on Estimating Software for Landscapers
Painting Takeoff & Estimating in Minutes
- Single click area select tool instantly measures every wall and ceiling surface – straight or curved.
- Simply drop pre-built custom assemblies onto the takeoff for instant estimating.
- Everything is counted and calculated including paint, primer, labor and materials for the job.
- Spend less time estimating, bid more jobs and maximize earnings!
More on Estimating Software for Painting
Fast, Easy and Accurate Takeoff for Plumbers
- Swiftly measure linear feet for CPVC, drain and supply piping.
- Get accurate instant takeoff counts for fixtures and fittings with point and click ease.
- PlanSwift calculates everything for a precise estimate every time.
- Save time, avoid costly errors and maximize profits with PlanSwift
More on Estimating Software for Plumbing
PlanSwift makes takeoffs easier, faster and more accurate no matter what your trade or job is. Rest assured, with PlanSwift all of your needs are covered.
Here are a few trades that aren’t listed to the left. We will be adding more trades pages in the near future. So, check back often.