Esempio n. 1
0
import base

ModIndex = base.new_extrinsic('ModIndex', [int])
Filename = base.new_extrinsic('Filename', str)

Module = base.DT('Module', ('rootType', 'Type'), ('root', 'a'))

Pos = base.DT('Pos', ('module', '*Module'), ('index', int))
Location = base.new_extrinsic('Location', Pos, omni=True)

TypeOf = base.new_extrinsic('TypeOf', base.Type, omni=True)
TypeVars = base.new_extrinsic('TypeVars', [base.TypeVar])

ResultOf = base.new_extrinsic('ResultOf', base.Result, omni=True)

# if not present, assumed to be GC if boxed
LifeInfo, Heap, Stack = base.ADT('LifeInfo', 'Heap', 'Stack')
Life = base.new_extrinsic('Life', LifeInfo, omni=True)

Instantiation = base.new_extrinsic('Instantiation', {'*TypeVar': base.Type})
TypeCast = base.new_extrinsic('TypeCast', (base.Type, base.Type))
InstMap = base.new_extrinsic('InstMap', {base.TypeVar: base.Type})

GlobalInfo = base.DT('GlobalInfo', ('symbol', str), ('isFunc', bool))
GlobalSymbol = base.new_extrinsic('GlobalSymbol', GlobalInfo)
LocalSymbol = base.new_extrinsic('LocalSymbol', str)
FieldSymbol = base.new_extrinsic('FieldSymbol', str)

WRITTEN_MODULES = {}

RUNTIME_MODULE_OBJS = {
Esempio n. 2
0
from base import DT, ADT, annot, cdecl, hint, match, new_extrinsic
from maybe import *

(List, Cons, Nil) = ADT('List', 'Cons', ('car', 'a'), ('cdr', 'List(a)'),
                                'Nil')

# XXX antiquated
Set = DT('Set', ('contents', ['a']))
Dict = DT('Dict', ('contents', [('k', 'v')]))

ModDigest = new_extrinsic('ModDigest', str)
ModDeps = new_extrinsic('ModDeps', '[*Module]')

@annot('a -> a noenv')
def identity(val): return val

@annot('(a, b) -> (a, b) noenv')
def tuple2(a, b): return (a, b)

@annot('(a, b, c) -> (a, b, c) noenv')
def tuple3(a, b, c): return (a, b, c)

@annot('t(a, b) -> a noenv')
def fst(t):
    return match(t, ('(f, _)', identity))

@annot('t(a, b) -> b noenv')
def snd(t):
    return match(t, ('(_, s)', identity))

@annot('Maybe(a) -> bool noenv')