Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: '3'

tasks:
run:
cmds:
- task: run:debug
run:debug:
cmds:
- odin run . -debug
run:release:
cmds:
- odin run . -o:speed
build:
cmds:
- task: build:debug
build:debug:
cmds:
- odin build . -debug
build:release:
cmds:
- odin build . -o:speed
test:
desc: Test all packages.
cmds:
- task: test:lexer
- task: test:parser
- task: test:ast
- task: test:evaluator
test:lexer:
desc:
cmds:
- odin test lexer -debug
test:parser:
desc:
cmds:
- odin test parser -debug
test:ast:
desc:
cmds:
- odin test ast -debug
test:evaluator:
desc:
cmds:
- odin test evaluator -debug
12 changes: 5 additions & 7 deletions ast/ast.odin
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ast

import "base:intrinsics"
import "core:bytes"
import "core:fmt"
import "core:intrinsics"
import "core:mem"
import "core:strings"

import "../lexer"
Expand Down Expand Up @@ -654,7 +652,7 @@ call_expr_to_string :: proc(e: ^Call_Expr) -> bytes.Buffer {

bufs: [dynamic]bytes.Buffer
defer {
for buf in &bufs {
for &buf in &bufs {
bytes.buffer_destroy(&buf)
}
delete(bufs)
Expand All @@ -672,7 +670,7 @@ call_expr_to_string :: proc(e: ^Call_Expr) -> bytes.Buffer {

string_array: [dynamic]string
defer delete(string_array)
for b in &bufs {
for &b in &bufs {
append(&string_array, bytes.buffer_to_string(&b))
}
s := strings.join(string_array[:], ", ")
Expand All @@ -697,7 +695,7 @@ array_literal_to_string :: proc(e: ^Array_Literal) -> bytes.Buffer {

bufs: [dynamic]bytes.Buffer
defer {
for buf in &bufs {
for &buf in &bufs {
bytes.buffer_destroy(&buf)
}
delete(bufs)
Expand All @@ -711,7 +709,7 @@ array_literal_to_string :: proc(e: ^Array_Literal) -> bytes.Buffer {

string_array: [dynamic]string
defer delete(string_array)
for b in &bufs {
for &b in &bufs {
append(&string_array, bytes.buffer_to_string(&b))
}
s := strings.join(string_array[:], ", ")
Expand Down
3 changes: 2 additions & 1 deletion ast/ast_test.odin
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#+feature dynamic-literals
package ast

import "core:bytes"
Expand Down Expand Up @@ -46,7 +47,7 @@ test_to_string :: proc(t: ^testing.T) {
s := bytes.buffer_to_string(&buf)

if s != "let myVar = anotherVar;" {
testing.errorf(t, "to_string(program) wrong. got=%q", s)
testing.expectf(t, true, "to_string(program) wrong. got=%q", s)
}
}

Expand Down
3 changes: 3 additions & 0 deletions evaluator/builtins.odin
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#+feature dynamic-literals global-context
package evaluator

import "core:fmt"
Expand All @@ -6,8 +7,10 @@ import "../evaluator"
import "../object"

allocated_array: [dynamic][dynamic]^object.Object

builtins := init_builtin_functions()


init_builtin_functions :: proc() -> map[string]^object.Builtin {
bfs := map[string]object.BuiltinFunction {
"len" = builtin_function_len,
Expand Down
2 changes: 1 addition & 1 deletion evaluator/evaluator.odin
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ delete_eval :: proc() {
}
delete(env_array)

for buffer in &object.buffer_array {
for &buffer in &object.buffer_array {
bytes.buffer_destroy(&buffer)
}
delete(object.buffer_array)
Expand Down
46 changes: 28 additions & 18 deletions evaluator/evaluator_test.odin
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#+feature dynamic-literals
package evaluator

import "core:bytes"
Expand Down Expand Up @@ -43,11 +44,11 @@ test_eval :: proc(input: string) -> ^object.Object {
test_integer_object :: proc(t: ^testing.T, obj: ^object.Object, expected: i64) -> bool {
result, ok := obj.derived.(^object.Integer)
if !ok {
testing.errorf(t, "object is not Integer. got=%T (%v)", obj, obj.derived)
testing.expectf(t, true, "object is not Integer. got=%T (%v)", obj, obj.derived)
return false
}
if result.value != expected {
testing.errorf(t, "object has wrong value. got=%d, want=%d", result.value, expected)
testing.expectf(t, true, "object has wrong value. got=%d, want=%d", result.value, expected)
return false
}
return true
Expand All @@ -56,19 +57,19 @@ test_integer_object :: proc(t: ^testing.T, obj: ^object.Object, expected: i64) -
test_boolean_object :: proc(t: ^testing.T, obj: ^object.Object, expected: bool) -> bool {
result, ok := obj.derived.(^object.Boolean)
if !ok {
testing.errorf(t, "object is not Boolean. got=%T (%v)", obj, obj.derived)
testing.expectf(t, true, "object is not Boolean. got=%T (%v)", obj, obj.derived)
return false
}
if result.value != expected {
testing.errorf(t, "object has wrong value. got=%t, want=%t", result.value, expected)
testing.expectf(t, true, "object has wrong value. got=%t, want=%t", result.value, expected)
return false
}
return true
}

test_null_object :: proc(t: ^testing.T, obj: ^object.Object) -> bool {
if obj != NULL {
testing.errorf(t, "object is not NULL. got=%T (%v)", obj, obj.derived)
testing.expectf(t, true, "object is not NULL. got=%T (%v)", obj, obj.derived)
return false
}
return true
Expand Down Expand Up @@ -217,7 +218,7 @@ test_error_handling :: proc(t: ^testing.T) {
{"true + false;", "unknown operator: BOOLEAN + BOOLEAN"},
{"5; true + false; 5", "unknown operator: BOOLEAN + BOOLEAN"},
{"if (10 > 1) { true + false; }", "unknown operator: BOOLEAN + BOOLEAN"},
{
{
`
if (10 > 1) {
if (10 > 1) {
Expand All @@ -239,8 +240,9 @@ test_error_handling :: proc(t: ^testing.T) {

err_obj, ok := evaluated.derived.(^object.Error)
if !ok {
testing.errorf(
testing.expectf(
t,
true,
"no error object returned. got=%T (%v)",
evaluated,
evaluated.derived,
Expand All @@ -249,8 +251,9 @@ test_error_handling :: proc(t: ^testing.T) {
}

if err_obj.message != tt.expected_msg {
testing.errorf(
testing.expectf(
t,
true,
"wrong error message. expected=%q, got=%q",
tt.expected_msg,
err_obj.message,
Expand Down Expand Up @@ -390,7 +393,7 @@ test_string_complex_cases :: proc(t: ^testing.T) {
input: string,
expected: string,
} {
{
{
`
let a = "A";
let b = "B";
Expand All @@ -400,7 +403,7 @@ test_string_complex_cases :: proc(t: ^testing.T) {
`,
"A B",
},
{
{
`
let makeGreeter = fn(greeting) { fn(name) { greeting + " " + name + "!" } };
let hello = makeGreeter("Hello");
Expand Down Expand Up @@ -445,11 +448,18 @@ test_builtin_functions :: proc(t: ^testing.T) {
case string:
err_obj, ok := evaluated.derived.(^object.Error)
if !ok {
testing.errorf(t, "object is not Error. got=%T (%v)", evaluated, evaluated.derived)
testing.expectf(
t,
true,
"object is not Error. got=%T (%v)",
evaluated,
evaluated.derived,
)
}
if err_obj.message != expected {
testing.errorf(
testing.expectf(
t,
true,
"wrong error message. expected=%q, got=%q",
expected,
err_obj.message,
Expand Down Expand Up @@ -510,7 +520,7 @@ test_array_complex_cases :: proc(t: ^testing.T) {
input: string,
expected: Types3,
} {
{
{
`
let map = fn(arr, f) {
let iter = fn(arr, accumulated) {
Expand All @@ -529,7 +539,7 @@ test_array_complex_cases :: proc(t: ^testing.T) {
`,
[4]i64{2, 4, 6, 8},
},
{
{
`
let reduce = fn(arr, initial, f) {
let iter = fn(arr, result) {
Expand Down Expand Up @@ -583,13 +593,13 @@ test_string_hash_key :: proc(t: ^testing.T) {
diff2.value = "My name is johnny"

if object.hash_key(hello1) != object.hash_key(hello2) {
testing.errorf(t, "strings with same content have different hash keys")
testing.expectf(t, true, "strings with same content have different hash keys")
}
if object.hash_key(diff1) != object.hash_key(diff2) {
testing.errorf(t, "strings with same content have different hash keys")
testing.expectf(t, true, "strings with same content have different hash keys")
}
if object.hash_key(hello1) == object.hash_key(diff1) {
testing.errorf(t, "strings with different content have same hash keys")
testing.expectf(t, true, "strings with different content have same hash keys")
}
}

Expand Down Expand Up @@ -652,7 +662,7 @@ test_hash_literals :: proc(t: ^testing.T) {
for expected_key, expected_value in expected {
pair, ok := result.pairs[expected_key]
if !ok {
testing.errorf(t, "no pair for given key in Pairs")
testing.expectf(t, true, "no pair for given key in Pairs")
}

test_integer_object(t, pair.value, expected_value)
Expand Down
2 changes: 1 addition & 1 deletion lexer/lexer.odin
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#+feature dynamic-literals
package lexer

import "core:fmt"

ILLEGAL :: "ILLEGAL"
EOF :: "EOF"
Expand Down
1 change: 0 additions & 1 deletion object/environment.odin
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package object

import "core:fmt"

Environment :: struct {
store: map[string]^Object,
Expand Down
2 changes: 1 addition & 1 deletion object/object.odin
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package object

import "base:intrinsics"
import "core:bytes"
import "core:fmt"
import "core:hash"
import "core:intrinsics"
import "core:strings"

import "../ast"
Expand Down
17 changes: 17 additions & 0 deletions ols.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
"collections": [
{ "name": "custom_collection", "path": "c:/path/to/collection" }
],
"enable_semantic_tokens": false,
"enable_document_symbols": true,
"enable_hover": true,
"enable_snippets": true,
"profile": "default",
"profiles": [
{ "name": "default", "checker_path": ["src"], "defines": { "ODIN_DEBUG": "false" }},
{ "name": "linux_profile", "os": "linux", "checker_path": ["src/main.odin"], "defines": { "ODIN_DEBUG": "false" }},
{ "name": "mac_profile", "os": "darwin", "arch": "arm64", "defines": { "ODIN_DEBUG": "false" }},
{ "name": "windows_profile", "os": "windows", "checker_path": ["src"], "defines": { "ODIN_DEBUG": "false" }}
]
}
1 change: 1 addition & 0 deletions parser/parser.odin
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#+feature dynamic-literals
package parser

import "core:fmt"
Expand Down
Loading