Compare commits

..

No commits in common. "5c336c7decbd0536a5bc5d719dbc634f05bec8c5" and "2c354c4a967e64309a5719b4a3785eba2daa8b6a" have entirely different histories.

4 changed files with 19 additions and 53 deletions

View file

@ -195,34 +195,6 @@ func (c *Compiler) compile(tree Node) error {
switch tree.Type() { switch tree.Type() {
case StringNodeType: case StringNodeType:
n := tree.(*StringNode)
s := ""
escaped := false
for _, ch := range n.value {
if escaped {
switch ch {
case 'n':
s += "\n"
case 't':
s += "\t"
case 'r':
s += "\r"
default:
s += string(ch)
}
escaped = false
continue
}
switch ch {
case '\\':
escaped = true
default:
s += string(ch)
}
}
c.add(InstructionConstant) c.add(InstructionConstant)
c.addConstant(&StringValue{ c.addConstant(&StringValue{
tree.(*StringNode).value, tree.(*StringNode).value,

View file

@ -1419,14 +1419,31 @@ func (p *Parser) parseSignature() (TypeSignature, error) {
name := (*p.prev).Lexeme name := (*p.prev).Lexeme
switch name { switch name {
case "str": case "string":
s = &StringSignature{} s = &StringSignature{}
case "int": case "int":
s = &IntegerSignature{} s = &IntegerSignature{}
case "float": case "float":
s = &FloatSignature{} s = &FloatSignature{}
case "bool": case "boolean":
s = &BooleanSignature{} s = &BooleanSignature{}
case "list":
if err := p.expect(TokenOpenBracket, "list must have content typed"); err != nil {
return nil, err
}
contents, err := p.parseSignature()
if err != nil {
return nil, err
}
if err := p.expect(TokenCloseBracket, "square brackets enclose list content signature"); err != nil {
return nil, err
}
s = &ListSignature{
contents,
}
case "any": case "any":
s = &AnySignature{} s = &AnySignature{}

View file

@ -470,26 +470,6 @@ var DefaultGlobals = map[string]Value{
nil, nil,
true, true,
}, },
"assert": &BuiltinFunctionValue{
"assert",
&FunctionSignature{
[]TypeSignature{
&BooleanSignature{},
},
&NilSignature{},
},
func(vm *VM, this Value, params []Value) (Value, error) {
b := params[0].(*BoolValue)
if !b.Boolean {
return nil, errors.New(fmt.Sprintf("assertion failed: %s", b))
}
return &NilValue{}, nil
},
nil,
false,
},
"assertEq": &BuiltinFunctionValue{ "assertEq": &BuiltinFunctionValue{
"assertEq", "assertEq",
&FunctionSignature{ &FunctionSignature{

View file

@ -8,6 +8,3 @@ assertEq([3, 1, 4, 1], [3, 1, 4, 1])
# Inequality # Inequality
assertNotEq(2, 3) assertNotEq(2, 3)
assert(1 < 2)
assert(1.0 < 2.0)