BASIC Developer & Support Resources > Compilers

Apple Swift on Ubuntu

(1/9) > >>

John:


Introduction to Open Source Swift on Linux

Swift Project Site (pre-built binaries for Apple Xcode, Ubuntu 64 bit 14.04 & 15.10)

The Swift Programming Language (Swift 2.1) 

swift-corelibs-foundation Linux version of the foundation import functions created to date on Github

Implementation Status - What works and what doesn't.

Swift Github Repository


--- Code: ---Welcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.
  1> :help

The REPL (Read-Eval-Print-Loop) acts like an interpreter.  Valid statements, expressions, and declarations are immediately compiled
and executed.

The complete set of LLDB debugging commands are also available as described below.  Commands must be prefixed with a colon at the
REPL prompt (:quit for example.)  Typing just a colon followed by return will switch to the LLDB prompt.

Debugger commands:

  apropos           -- Find a list of debugger commands related to a particular word/subject.
  breakpoint        -- A set of commands for operating on breakpoints. Also see _regexp-break.
  bugreport         -- Set of commands for creating domain specific bugreports.
  command           -- A set of commands for managing or customizing the debugger commands.
  disassemble       -- Disassemble bytes in the current function, or elsewhere in the executable program as specified by the user.
  expression        -- Evaluate an expression (ObjC++ or Swift) in the current program context, using user defined variables and
                       variables currently in scope.
  frame             -- A set of commands for operating on the current thread's frames.
  gdb-remote        -- Connect to a remote GDB server.  If no hostname is provided, localhost is assumed.
  gui               -- Switch into the curses based GUI mode.
  help              -- Show a list of all debugger commands, or give details about specific commands.
  kdp-remote        -- Connect to a remote KDP server.  udp port 41139 is the default port number.
  language          -- A set of commands for managing language-specific functionality.'.
  log               -- A set of commands for operating on logs.
  memory            -- A set of commands for operating on memory.
  platform          -- A set of commands to manage and create platforms.
  plugin            -- A set of commands for managing or customizing plugin commands.
  process           -- A set of commands for operating on a process.
  quit              -- Quit out of the LLDB debugger.
  register          -- A set of commands to access thread registers.
  script            -- Pass an expression to the script interpreter for evaluation and return the results. Drop into the
                       interactive interpreter if no expression is given.
  settings          -- A set of commands for manipulating internal settable debugger variables.
  source            -- A set of commands for accessing source file information
  target            -- A set of commands for operating on debugger targets.
  thread            -- A set of commands for operating on one or more threads within a running process.
  type              -- A set of commands for operating on the type system
  version           -- Show version of LLDB debugger.
  watchpoint        -- A set of commands for operating on watchpoints.

Current command abbreviations (type ':help command alias' for more info):

  add-dsym  -- ('target symbols add')  Add a debug symbol file to one of the target's current modules by specifying a path to a
               debug symbols file, or using the options to specify a module to download symbols for.
  attach    -- ('_regexp-attach')  Attach to a process id if in decimal, otherwise treat the argument as a process name to attach
               to.
  b         -- ('_regexp-break')  Set a breakpoint using a regular expression to specify the location, where <linenum> is in
               decimal and <address> is in hex.
  bt        -- ('_regexp-bt')  Show a backtrace.  An optional argument is accepted; if that argument is a number, it specifies the
               number of frames to display.  If that argument is 'all', full backtraces of all threads are displayed.
  c         -- ('process continue')  Continue execution of all threads in the current process.
  call      -- ('expression --')  Evaluate an expression (ObjC++ or Swift) in the current program context, using user defined
               variables and variables currently in scope.
  continue  -- ('process continue')  Continue execution of all threads in the current process.
  detach    -- ('process detach')  Detach from the current process being debugged.
  di        -- ('disassemble')  Disassemble bytes in the current function, or elsewhere in the executable program as specified by
               the user.
  dis       -- ('disassemble')  Disassemble bytes in the current function, or elsewhere in the executable program as specified by
               the user.
  display   -- ('_regexp-display')  Add an expression evaluation stop-hook.
  down      -- ('_regexp-down')  Go down "n" frames in the stack (1 frame by default).
  env       -- ('_regexp-env')  Implements a shortcut to viewing and setting environment variables.
  exit      -- ('quit')  Quit out of the LLDB debugger.
  f         -- ('frame select')  Select a frame by index from within the current thread and make it the current frame.
  file      -- ('target create')  Create a target using the argument as the main executable.
  finish    -- ('thread step-out')  Finish executing the function of the currently selected frame and return to its call site in
               specified thread (current thread, if none specified).
  image     -- ('target modules')  A set of commands for accessing information for one or more target modules.
  j         -- ('_regexp-jump')  Sets the program counter to a new address.
  jump      -- ('_regexp-jump')  Sets the program counter to a new address.
  kill      -- ('process kill')  Terminate the current process being debugged.
  l         -- ('_regexp-list')  Implements the GDB 'list' command in all of its forms except FILE:FUNCTION and maps them to the
               appropriate 'source list' commands.
  list      -- ('_regexp-list')  Implements the GDB 'list' command in all of its forms except FILE:FUNCTION and maps them to the
               appropriate 'source list' commands.
  n         -- ('thread step-over')  Source level single step in specified thread (current thread, if none specified), stepping
               over calls.
  next      -- ('thread step-over')  Source level single step in specified thread (current thread, if none specified), stepping
               over calls.
  nexti     -- ('thread step-inst-over')  Single step one instruction in specified thread (current thread, if none specified),
               stepping over calls.
  ni        -- ('thread step-inst-over')  Single step one instruction in specified thread (current thread, if none specified),
               stepping over calls.
  p         -- ('expression --')  Evaluate an expression (ObjC++ or Swift) in the current program context, using user defined
               variables and variables currently in scope.
  po        -- ('expression -O  -- ')  Evaluate an expression (ObjC++ or Swift) in the current program context, using user defined
               variables and variables currently in scope.
  print     -- ('expression --')  Evaluate an expression (ObjC++ or Swift) in the current program context, using user defined
               variables and variables currently in scope.
  q         -- ('quit')  Quit out of the LLDB debugger.
  r         -- ('process launch -X true --')  Launch the executable in the debugger.
  rbreak    -- ('breakpoint set -r %1')  Sets a breakpoint or set of breakpoints in the executable.
  repl      -- ('expression -r  -- ')  Evaluate an expression (ObjC++ or Swift) in the current program context, using user defined
               variables and variables currently in scope.
  run       -- ('process launch -X true --')  Launch the executable in the debugger.
  s         -- ('thread step-in')  Source level single step in specified thread (current thread, if none specified).
  si        -- ('thread step-inst')  Single step one instruction in specified thread (current thread, if none specified).
  step      -- ('thread step-in')  Source level single step in specified thread (current thread, if none specified).
  stepi     -- ('thread step-inst')  Single step one instruction in specified thread (current thread, if none specified).
  t         -- ('thread select')  Select a thread as the currently active thread.
  tbreak    -- ('_regexp-tbreak')  Set a one shot breakpoint using a regular expression to specify the location, where <linenum> is
               in decimal and <address> is in hex.
  undisplay -- ('_regexp-undisplay')  Remove an expression evaluation stop-hook.
  up        -- ('_regexp-up')  Go up "n" frames in the stack (1 frame by default).
  x         -- ('memory read')  Read from the memory of the process being debugged.

For more information on any command, type ':help <command-name>'.
  1> let sb="Script BASIC"
sb: String = "Script BASIC"
  2> print(sb)
Script BASIC
  3> import Glibc
  4> random() % 10
$R0: Int = 3
  5> 
 

--- End code ---


jrs@laptop:~/Swift/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin$ ls -l
total 144920
lrwxrwxrwx 1 jrs jrs       10 Dec  2 12:14 lldb -> lldb-3.8.0
-rwxr-xr-x 1 jrs jrs    56975 Dec  2 12:10 lldb-3.8.0
-rwxr-xr-x 1 jrs jrs    86550 Dec  2 12:10 lldb-argdumper
lrwxrwxrwx 1 jrs jrs       13 Dec  2 12:14 lldb-mi -> lldb-mi-3.8.0
-rwxr-xr-x 1 jrs jrs   929212 Dec  2 12:10 lldb-mi-3.8.0
lrwxrwxrwx 1 jrs jrs       17 Dec  2 12:14 lldb-server -> lldb-server-3.8.0
-rwxr-xr-x 1 jrs jrs 63360159 Dec  2 12:10 lldb-server-3.8.0
-rwxr-xr-x 1 jrs jrs     9177 Dec  2 12:09 repl_swift
-rwxr-xr-x 1 jrs jrs 73628082 Dec  2 12:01 swift
lrwxrwxrwx 1 jrs jrs        5 Dec  2 12:14 swift-autolink-extract -> swift
-rwxr-xr-x 1 jrs jrs  1742176 Dec  2 12:14 swift-build
-rwxr-xr-x 1 jrs jrs  7702803 Dec  2 12:10 swift-build-tool
lrwxrwxrwx 1 jrs jrs        5 Dec  2 12:14 swiftc -> swift
-rwxr-xr-x 1 jrs jrs   857140 Dec  2 12:00 swift-demangle
jrs@laptop:~/Swift/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin$



--- Code: Text ---jrs@laptop:~/Swift$ swiftWelcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.  1>    2.    3.     extension Double {   4.         var km: Double { return self * 1_000.0 }   5.         var m: Double { return self }   6.         var cm: Double { return self / 100.0 }   7.         var mm: Double { return self / 1_000.0 }   8.         var ft: Double { return self / 3.28084 }   9.     }  10.     let oneInch = 25.4.mm  11.     print("One inch is \(oneInch) meters")  12.     // prints "One inch is 0.0254 meters"  13.     let threeFeet = 3.ft  14.     print("Three feet is \(threeFeet) meters")  15.     // prints "Three feet is 0.914399970739201 meters"  16.  One inch is 0.0254 metersThree feet is 0.914399970739201 metersoneInch: Double = 0.025399999999999999threeFeet: Double = 0.91439997073920098 16> 17> :platform listAvailable platforms:host: Local Linux user platform plug-in.remote-freebsd: Remote FreeBSD user platform plug-in.remote-linux: Remote Linux user platform plug-in.remote-windows: Remote Windows user platform plug-in.kalimba: Kalimba user platform plug-in.remote-android: Remote Android user platform plug-in.remote-ios: Remote iOS platform plug-in.remote-macosx: Remote Mac OS X user platform plug-in.remote-gdb-server: A platform that uses the GDB remote protocol as the communication transport. 17>     
A compiled Hello World is 14,457 bytes in size. (release mode)

wangrenxin:
Nice! I like the programming paradigm in Swift as a video game developer. It would be attractive if someone would port it to Windows too; or re-create a clone as IronPython, IronRuby do.

John:
I'm happy. Swift goals sound like it's talking about Script BASIC.  :)

Swift reminds me of CERN ROOT in BASIC scripting clothing.

It seems most of the code examples from the Apple iOS Swift docs seem to work in the Linux version.

John:
I have been digging around for info on a GUI IDE like Xcode but nothing exists that I can find. Here is some info on the topic.

The curses GUI debugger is a start.

John:
Introducing the IBM Swift Sandbox





--- Quote ---The IBM Swift Sandbox is an interactive website that lets you write Swift code and execute it in a server environment – on top of Linux! Each sandbox runs on IBM Cloud in a Docker container. In addition, both the latest versions of Swift and its standard library are available for you to use.

--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version