Skip to content

Commit

Permalink
Fix CI bug, add old tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaquraish committed Apr 28, 2024
1 parent 0838e2e commit eda1132
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

RUN apt-get update
RUN apt-get install -y git valgrind gcc
RUN apt-get install -y git valgrind gcc python3

ENTRYPOINT git clone https://github.com/ocen-lang/ocen /ocen/ \
&& cd /ocen/ \
Expand All @@ -21,4 +21,4 @@ ENV PATH=$PATH:/ocen/bootstrap/
## Build the image
# docker build . --tag tide
## Run the image
# docker run --rm -it -v $(pwd):/mnt/ -w /mnt/ tide
# docker run --rm -it -v $(pwd):/mnt/ -w /mnt/ tide
19 changes: 12 additions & 7 deletions compiler/compiler.oc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import std::vector::{ Vector }
import std::span::{ Span }
import std::sv::{ SV }
import std::mem

import @ast::nodes::{ this, AST, Variable, Symbol }
import @errors::{ Error }
Expand Down Expand Up @@ -37,17 +38,19 @@ enum CompileType {
Method
}

def Compiler::make(
def Compiler::new(
vm: &VM, name: SV, span: Span,
type: CompileType,
enclosing: &Compiler = null
): Compiler {
): &Compiler {
let compiler = mem::alloc<Compiler>()

let chunk = Chunk::new(span)
let locals = Vector<LocalVar>::new(capacity: 8)
let upvars = Vector<UpVar>::new(capacity: 256)
let func = gc::allocate_object<FunctionCode>(FunctionCode, vm, enclosing)

let compiler = Compiler(
*compiler = Compiler(
vm,
func,
chunk,
Expand All @@ -56,7 +59,7 @@ def Compiler::make(
scope_depth: 0,
enclosing
)
gc::set_compiler(&compiler)
gc::set_compiler(compiler)

let name_val = vm.copy_string(name.data, name.len)
func.init(name_val.as_string(), chunk, 0) // Replace arity later...
Expand All @@ -73,6 +76,7 @@ def Compiler::make(
def Compiler::free(&this) {
.locals.free()
.upvars.free()
mem::free(this)
}

def Compiler::make_str(&this, text: SV): Value {
Expand Down Expand Up @@ -366,7 +370,7 @@ def Compiler::compile_expression(&this, node: &AST) {

def Compiler::compile_function(&this, node: &AST, func: &nodes::Function) {
let compile_type: CompileType = if func.is_method then Method else Function
let cc = Compiler::make(
let cc = Compiler::new(
.vm,
func.sym.name,
func.sym.span,
Expand Down Expand Up @@ -520,10 +524,11 @@ def Compiler::compile_ns(&this, root: &AST) {

// TODO: More complex structures than just expressions?
def compile_program(vm: &VM, root: &AST): &FunctionCode {
let compiler = Compiler::make(vm, SV("",0), root.span, Script)
let compiler = Compiler::new(vm, SV("",0), root.span, Script)
compiler.compile_ns(root)
compiler.chunk.push_op(Halt, root.span)
gc::set_compiler(null)
let func = compiler.func
compiler.free()
return compiler.func
return func
}
11 changes: 11 additions & 0 deletions tests/class_methods.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// out: <instance Foo> 5 8

class Foo {
def bar() => .x = 5
def test(a, b) => .x + a + b
}

let f = Foo()
print(f)
print(f.bar())
print(f.test(1, 2))
7 changes: 7 additions & 0 deletions tests/instance_field_access.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// out: 10 hello

class Foo {}
let x = Foo()
x.bar = 10
x.baz = "hello"
print(x.bar, x.baz)

0 comments on commit eda1132

Please sign in to comment.