Skip to content

Commit

Permalink
annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
thautwarm committed Jan 14, 2020
1 parent 8d448c5 commit 2e5b3cf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion proud/basic_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ def binary(module, head, tl: typing.Tuple[tuple, ...]):
raise NotImplementedError

def annotate(module, var, type):
raise NotImplementedError
var = module.eval(var)
type = Typing(module.comp_ctx).eval(type)
module.comp_ctx.tc_state.unify(var.type, type)
return var

def match(module, target, cases: list):
raise NotImplementedError
Expand Down
21 changes: 21 additions & 0 deletions test/annotate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from proud.parser_wrap import parse
from proud.basic_impl import Modular, CompilerCtx
from proud import types
from hybridts import type_encoding as te
mod = parse("""
module MyMod
let test : exist a. a = coerce 0 : string
""")
comp_ctx = CompilerCtx.top('a.prd', 'a')
sym = comp_ctx.scope.enter("bigint")
comp_ctx.tenv[sym] = te.App(types.type_type, types.bigint_t)
sym = comp_ctx.scope.enter("string")
comp_ctx.tenv[sym] = te.App(types.type_type, types.string_t)

modular = Modular(comp_ctx)

xs = modular.eval(mod)
tc = comp_ctx.tc_state

for k, v in comp_ctx.tenv.items():
print(k.name, ':', tc.infer(v), '============', v)
2 changes: 1 addition & 1 deletion test/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module MyMod
let add : bigint -> bigint -> bigint = coerce 0
let y : {c: string} = coerce 0
let x = {a = 0, b = 3 | y }
let x = {a = 0, b = 3 | y}
""")
comp_ctx = CompilerCtx.top('a.prd', 'a')
sym = comp_ctx.scope.enter("bigint")
Expand Down

0 comments on commit 2e5b3cf

Please sign in to comment.