šŸ¦‹ "BASIC" to Swift

Cant you select the framework to compiler against AND a deploy to target that is different ?
I recall that working in Xcode

sorry… 10.13 is as low as it can go due to features I am using

Norm… yes I can… but the code uses features that didn’t appear until 10.13

actually 10.14… when I compiled with 10.9 as the deployment target
I got 2 errors for 10.13 features
1 for a 10.10 feature
1 for a 10.11 feature
and 1 for a 10.14 feature

so 10.14 is it.

When you release a new version, I will boot on High Sierra to look at it.

I was only surprised. I too sometimes forgot things and I like when people told me (then I can try to do something when possible).

Emile… not sure that will work either… but you can try… I think Sierra won’t go past 10.12

What kind of code do you expect it to handle so far ?
I tried 22 lines from a project and it crashed :frowning:

Hence why I’m asking what you expect to be able to deal with so far

Actually it was this bit of code - nothing proprietary in here

Dim f As FolderItem
dim t as textOutputStream

Dim extension As String = ".xml"
If popRBVersion.RowTag(popRBVersion.ListIndex) <> "" Then
  extension = popRBVersion.RowTag(popRBVersion.ListIndex)
End If

f = GetSaveFolderItem("special/any","New XML File" + extension)

if f = nil then return

if f.exists then f.delete

t = f.createTextFile

t.write editField1.text

t.close

f.MacType =  "TEXT"
f.MacCreator = "RBv2"

yeah yeah yeah yeah I know mactype & maccreator are deprecated but this code is from 2005 so I’m updating it :stuck_out_tongue:

well I’ve been working on this all morning :slight_smile:
I did find an issue where it went bonkers when I fed it some real code I needed for my bigger project…

I just fed in your code from above and it accepted it…

var f : FolderItem
var t : textOutputStream
var extension : String = ".xml"
if popRBVersion.RowTag(popRBVersion.ListIndex)!= "" {
	extension = popRBVersion.RowTag(popRBVersion.ListIndex)
}
f = GetSaveFolderItem("special/any","New XML File"
+ extension)
if f == nil {
	return
}
if f.exists {
	f.delete
}
t = f.createTextFile
t.write editField1.text
t.close
f.MacType = "TEXT"
f.MacCreator = "RBv2"

Note this translator doesn’t give a sh*t about properties, or if variables are defined etc… this job it will be leaving up to Xcode. It is just looking for specific syntax/structures and converting where possible to the equivalent Swift syntax.

So the fact that Swift doesn’t have FolderItem or TextOutStream are not a concern

NOTE HOWEVER… that both of those DO exist in Swift libraries I have written that will be part of the final project… So most everything in your example WILL actually work in the bigger project :smiley:

OK - it just crahed the last ne I downloaded - hence my question :stuck_out_tongue:

I haven’t updated the online code today … yet

I’ve fixed the issues that caused it to freak out on certain syntax (It wrote 100’s of lines of { and } that weren’t needed)
Fixed issue where sometimes it didn’t add spaces around ā€œ=ā€ or ā€œ!=ā€ one of the few places where Swift DOES care about whitespace
Added ā€œ_ā€ characters into SUB/FUNC signatures… Otherwise Swift would require the labels any where the function was called, something I don’t like

func xyz(arg : Int)
xyz(arg:3)
func xyz(_ arg : Int)
xyz(3)

There are some choices in Swift that puzzle me but I’m sure they have their reasons

There are some choices in Xojo that puzzle me but I’m sure they have their reasons

but yeah I see what you mean… For me its now 2nd nature to type the underscores
Nice thing is if you enter conflicting situations, Xcode tells you and will fix it for you

That was JUST kind of starting to occur in Xojo’s compiler
You’ll see from time to time that it says ā€œI cant find a type named X did you mean Y?ā€

dim x as string
IF x="select * FROM tblStock"
	msgbox x
end if

just try this code and app crash on Mojave

While this didn’t bomb in my current version… it would in fact not ā€œcompileā€ in my developement project… it would not be syntacitally correct for my dialetic of BASIC as it is missing the required THEN

i include THEN and it still bomb

I’ll be uploading a new version in about an hour…

Both your example, and the one from Norman pass this version properly

The next version will have an expanded Xref dictionary for some (not all) Keywords, as case is important … it also partially deals with BYREF callouts

Ok new build is here :slight_smile:

Fixed a number of bugs I found when using in the ā€œreal worldā€ā€¦ since I wrote this to be a tool to help me write a much larger project…

Fixed some places where Swift REQUIRES whitespace.
Add some more word cross references (Ubound -> Count etc)

Fixed where the BASIC Sub/Func might no have an argument list

sub xyz as Integer // BASIC
func xyz() : Int // Swift

For BYREF, this will add the inout call out, but does NOT add the required &, as this requires look ahead which is currently beyond this scope… it is something I will have to add later, but for now Xcode will point out where they need to be added.

sub foo(byref xyz as integer) \\ BASIC
func foo(_ xyz : inout Int){ \\ SWIFT
1 Like

Thanks DaveS, both norm and my code work now.

Thats not valid in Xojo fwiw but …

This is true… but this translator treats SUB and FUNCTION identically… since in Swift the only difference is if a value is returned or not… I didn’t feel it was necessary to enforce the ā€œdifferenceā€ since the over all assumption will be the in the end the code the translator module will get will be ā€œvalidā€ā€¦ An assumption that is not yet enforced :smiley:

FYI… if anyone is interested… the actual translator (as of now) is less than 500 lines of Swift code… not bad I’d say :slight_smile: