Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Callisto
  • Cat
  • Cognate
  • colorForth
  • Concata
  • CoSy
  • Deque
  • DSSP
  • dt
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quest32
  • Quackery
  • r3
  • Raven
  • Retro
  • RPL
  • SPL
  • Staapl
  • Stabel
  • Tal
  • Titan
  • Trith
  • Uiua
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Concatenative topics

  • Compilers
  • Interpreters
  • Type systems
  • Object systems
  • Quotations
  • Variables
  • Garbage collection
  • Example programs

Concatenative meta

  • People
  • Communities

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Meta

  • Search
  • Farkup wiki format
  • Etiquette
  • Sandbox

Mogun

Mogun is Factor-inspired and Factor-hosted language and is currently in early design stage. Its primary target is low-level speed-critical tasks, which you do not normally write on Factor itself (cell tags, GC, etc). Core of its design is programmer-friendly static typing with transparent and precise control over any compiler optimizations. Possibly, it's going to be LLVM-backended.

Basic Principles (UNDER CONSTRUCTION)

Local stack shuffling

Only local stack shuffling primitive is ( .. ) syntax. It can rearrange and name any constant number of top stack elements. All other simple shufflers and combinators are normal words:

: drop ( >X ) ;
: dup ( <X X ) ;
: swap ( <Y X >Y ) ;

: dip -- ( >X QUOT ) call X ;
: keep -- ( X QUOT ) call X ;

: 2drop drop drop ;
: 2dip -- swap [ dip ] dip ;

: bi -- [ keep ] dip call ;
: bi* -- [ dip ] dip call ;
: bi@ -- dup bi* ;

In combinators defititions you can see -- word, which do not appear in shufflers. This word is unusual for Factor and its function will be described later.

Type-system

In Mogun any element on stack belongs to one of statically-distinguished class hierarhies. Inside each hierarhy classes can be statically or dynamically converted to each other. Classes can have additional slots with optimization-assisting values, avaliable at compile-time. Class from one hierarhy can simulate behaviour of other hierarhy, and can be used in its place.

CLASS: integer { min -inf } { max +inf } ;

CLASS: uint ? integer { min 0 } ;

CLASS: sgn ;

CLASS: positive < sgn ;
CLASS: zero     < sgn ;
CLASS: negative < sgn ;

MIMIC: integer sgn

CLASS: fixed { bitcount uint } ;

CLASS: ufixed = fixed ;
CLASS: sfixed = fixed ;

MIMIC: ufixed integer
MIMIC: sfixed integer

In this example you can see three class hierarhies: integer, sgn and fixed. Class integer describes any integer value between min and max. Class uint is an alias for class integer with min value set to 0. Class sgn describes any number that can have sign. It can dynamically downcast to three subclasses: positive, zero and negative. MIMIC: integer sgn means that any integer value can be used everywhere, where sgn value or any its subclass is expected (obviously, because integers have sign). Class fixed describes bitfield of bitcount bits. Its value can be interpreted as unsigned or signed integer. Any ufixed and sfixed values can be converted to each other with static casting, and their usage in place of integer should generate different code.

Quotation semantics

Mogun quotation can be more complex then Factor one. It provides branching based on type-checking and in-place tail-cut recursion. For example, lets look at Mogun implementation of Factor times equivalent:

: times -- swap :integer
    [ :positive -- [ [ call ] keep ] [ 1- ] bi* rec
    | :zero 2drop
    ] call ;

Core loop of this word is divided by | symbol into two branches:

  • :positive -- [ [ call ] keep ] [ 1- ] bi* rec
  • :zero 2drop

Both branches start with type-checking - :positive and :zero words. This words are generated by CLASS: statement and do nothing, if top of the stack belongs to corresponding class, or raise type-checking error otherwise. First of this two branches is divided in two parts by -- word:

:positive type checking part before -- (or whole branch if no -- found, like in second branch)
[ [ call ] keep ] [ 1- ] bi* rec actual working part after --

If quotation have more then one branch, in type checking part you can use only type-checking and stack-shuffling words. When call-ed, branch, that do not raise error in its type checking part, is selected for execution. Any errors, raised in actual working part of branch, lead to failing of whole call.

At the end of the first branch you can see rec word. This is virtual symbol, used for in-place tail-cut recursion. After branch execution call checks top of the stack for rec symbol, and if it is found, removes it and call-s quotation again.

This revision created on Wed, 10 Jun 2009 12:20:00 by Keyholder

Latest Revisions Edit

All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.