šŸ¦‹ "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: