Skip to content

Commit

Permalink
Merge branch 'feature/project-refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimerDude committed May 16, 2020
2 parents 9f5ae7d + d7a131a commit 7392f59
Show file tree
Hide file tree
Showing 61 changed files with 640 additions and 574 deletions.
Binary file modified com.xored.f4.astView/f4astView.pod
Binary file not shown.
15 changes: 8 additions & 7 deletions com.xored.f4.astView/fan/AstView.fan
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using f4core
using f4core::FantomProjectManager
using f4model
using f4parser
using f4uiText
using [java]org.eclipse.ui
using [java]org.eclipse.ui.part
using [java]org.eclipse.swt.widgets
using [java]org.eclipse.jface.viewers
using [java]org.eclipse.dltk.ui
using [java]org.eclipse.dltk.core
using [java] org.eclipse.ui
using [java] org.eclipse.ui.part
using [java] org.eclipse.swt.widgets
using [java] org.eclipse.jface.viewers
using [java] org.eclipse.dltk.ui
using [java] org.eclipse.dltk.core

class AstView : ViewPart, IPartListener
{
Expand Down Expand Up @@ -61,7 +62,7 @@ class AstView : ViewPart, IPartListener
private static IFanNamespace getNamespace(ISourceModule? content) {
project := content?.getScriptProject?.getProject
if (project == null || !project.isOpen) return EmptyNamespace()
return FantomProjectManager.instance[project].ns
return FantomProjectManager.instance.get(project).ns
}

override Void partActivated(IWorkbenchPart? part) {
Expand Down
Binary file modified com.xored.f4.builder.ui/f4builderUI.pod
Binary file not shown.
9 changes: 1 addition & 8 deletions com.xored.f4.builder.ui/fan/CompilerPreferencePage.fan
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class CompilerOptionsBlock : AbstractOptionsBlock {
SWTFactory.createLabel(composite, "", 2)
bindControl(SWTFactory.createCheckButton(composite, "Use external compiler", null, false, 2), useExternalBuilderKey, null)

SWTFactory.createLabel(composite, "", 2)
bindControl(SWTFactory.createCheckButton(composite, "Use referenced projects only (beta)", null, false, 2), referencedPodsOnlyKey, null)

SWTFactory.createLabel(composite, "", 2)
SWTFactory.createLabel(composite, "Note: Projects need to be re-built to make use of changes made above", 2)

Expand All @@ -65,11 +62,7 @@ class CompilerOptionsBlock : AbstractOptionsBlock {
PreferenceKey(ProjectPrefs.qualifier, ProjectPrefs.useExternalBuilderName)
}

private static PreferenceKey referencedPodsOnlyKey() {
PreferenceKey(ProjectPrefs.qualifier, ProjectPrefs.referencedPodsOnlyName)
}

private static PreferenceKey[] allKeys() {
[podOutputDir, useExternalBuilderKey, referencedPodsOnlyKey]
[podOutputDir, useExternalBuilderKey]
}
}
Binary file modified com.xored.f4.builder/f4builder.pod
Binary file not shown.
3 changes: 2 additions & 1 deletion com.xored.f4.builder/fan/CompileFan.fan
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using compiler
using f4core
using f4core::FantomProjectManager

using [java]java.util::List as JList
using [java]java.util::Set as JSet
Expand Down Expand Up @@ -129,7 +130,7 @@ class CompileFan : IScriptBuilder {
//////////////////////////////////////////////////////////////////////////

private FantomProject fantomProject(IScriptProject project) {
FantomProjectManager.instance[project.getProject]
FantomProjectManager.instance.get(project.getProject)
}

//////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 1 addition & 14 deletions com.xored.f4.builder/fan/InternalBuilder.fan
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using f4core::FantomProject
using f4core::FantomProjectManager
using f4core::LogUtil
using compiler

Expand Down Expand Up @@ -38,24 +37,12 @@ class InternalBuilder : Builder {
compileDir.create
compileDir.listFiles.each { it.delete }

resolvedPods := fp.resolvePods
resolvedPods := fp.resolvedPods

bldLoc := Loc(fp.buildFile)
if (fp.resolveErrs.size > 0) {
return fp.resolveErrs.map { CompilerErr(it.toStr, bldLoc) }
}

// Blindly add all workspace pods - seems to be the only way to get F4 to compile itself (...!?)
// Without this, we get compilation errors similar to "pod not found: f4parser".
// These aren't actual dependencies and don't seem to be transitive dependencies.
// Note that adding them as actual project dependencies also solves the issue,
// But because I don't know why, I'm loath to do so - hence these 3 little lines.

// SlimerDude - Apr 2020 - Beta feature to turn this off
if (fp.prefs.referencedPodsOnly == false)
FantomProjectManager.instance.listProjects.each |p| {
resolvedPods[p.podName] = p.podOutFile
}

logger := ConsoleLogger(consumer)
input := CompilerInput.make
Expand Down
Binary file modified com.xored.f4.core/f4core.pod
Binary file not shown.
129 changes: 129 additions & 0 deletions com.xored.f4.core/fan/afConcurrent/SynchronizedState.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using concurrent::Actor
using concurrent::ActorPool
using concurrent::AtomicInt
using concurrent::Future

** Provides 'synchronized' access to a (non- 'const') mutable state object.
**
** 'SynchronizedState' creates the state object in its own thread and provides access to it via the
** 'sync()' and 'async()' methods. Note that by their nature, these methods are immutable
** boundaries. Meaning that while data in the State object can be mutable, data passed in and out
** of these these boundaries can not be.
**
** 'SynchronizedState' is designed to be *scope safe*, that is you cannot accidently call methods
** on your State object outside of the 'sync()' and 'async()' methods.
**
** Example usage:
**
** pre>
** syntax: fantom
**
** sync := SynchronizedState(ActorPool(), Mutable#)
** msg := "That's cool, dude!"
**
** val := sync.sync |Mutable state -> Int| {
** state.buf.writeChars(msg)
** return state.buf.size
** }
**
** class Mutable {
** Buf buf := Buf()
** }
** <pre
**
** Note 'SynchronizedState' overrides 'trap()' to make convenience calls to 'sync()' allowing dynamic calls:
**
** pre>
** syntax: fantom
** sync := SynchronizedState(ActorPool(), Mutable#)
**
** size := sync->buf->size //--> returns size of Mutable.buf
** <pre
internal const class SynchronizedState {
@NoDoc // advanced use only
const |->Obj?| stateFactory
@NoDoc // advanced use only
const LocalRef stateRef

** The 'lock' object should you need to 'synchronize' on the state.
const Synchronized lock

// Note we can't create a ctor(syncPool, type) 'cos that leads to ambiguous ctors in existing libs like afBedSheet / afParrotSdk2
@NoDoc // advanced use only - for setting own lock
new make(|This| f) {
f(this)
if (this.stateRef == null)
this.stateRef = LocalRef(SynchronizedState#.name)
}

** Creates a 'SynchronizedState' instance.
**
** The given state type must have a public no-args ctor as per [Type.make]`sys::Type.make`.
new makeWithType(ActorPool actorPool, Type stateType) {
this.lock = Synchronized(actorPool)
this.stateRef = LocalRef(stateType.name)
this.stateFactory = |->Obj?| { stateType.make }
}

** Creates a 'SynchronizedState' instance.
**
** The given (immutable) factory func is used to create the state object inside it's thread.
new makeWithFactory(ActorPool actorPool, |->Obj?| stateFactory) {
this.lock = Synchronized(actorPool)
this.stateRef = LocalRef(SynchronizedState#.name)
this.stateFactory = stateFactory
}

** Calls the given func synchronously, passing in the State object and returning the func's
** response.
**
** The given func should be immutable.
Obj? sync(|Obj state -> Obj?| func) {
iFunc := func.toImmutable
return lock.synchronized |->Obj?| { callFunc(iFunc) }
}

** Calls the given func asynchronously, passing in the State object.
**
** The given func should be immutable.
Future async(|Obj state -> Obj?| func) {
iFunc := func.toImmutable
return lock.async |->Obj?| { callFunc(iFunc) }
}

** Calls the given func asynchronously, passing in the State object.
**
** The given func should be immutable.
Future asyncLater(Duration duration, |Obj state -> Obj?| func) {
iFunc := func.toImmutable
return lock.asyncLater(duration) |->Obj?| { callFunc(iFunc) }
}

** Routes trap() to the enclosed state object. Allows convenience calls for calling 'sync()'
** and returning state:
**
** pre>
** syntax: fantom
** sync := SynchronizedState(ActorPool(), Buf#)
**
** size := sync->size //--> returns size of Buf
** <pre
override Obj? trap(Str name, Obj?[]? args := null) {
iargs := args?.toImmutable
return sync |state->Obj?| {
state.trap(name, iargs)
}
}

private Obj? callFunc(|Obj?->Obj?| func) {
if (stateRef.val == null)
stateRef.val = stateFactory.call
return func.call(stateRef.val)
}

** Returns a string representation the state.
override Str toStr() {
sync { it.toStr }
}
}

156 changes: 0 additions & 156 deletions com.xored.f4.core/fan/manifest/BuildfanListener.fan

This file was deleted.

Loading

0 comments on commit 7392f59

Please sign in to comment.