{"id":18074372,"url":"https://github.com/zellyn/gocool","last_synced_at":"2025-04-12T05:53:03.577Z","repository":{"id":13223198,"uuid":"15907512","full_name":"zellyn/gocool","owner":"zellyn","description":"Go implementation of the Cool programming language","archived":false,"fork":false,"pushed_at":"2017-03-31T20:32:51.000Z","size":1773,"stargazers_count":42,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T05:52:55.753Z","etag":null,"topics":["compiler","cool","coursera","go"],"latest_commit_sha":null,"homepage":null,"language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zellyn.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-14T16:13:45.000Z","updated_at":"2024-10-15T23:16:07.000Z","dependencies_parsed_at":"2022-08-24T08:40:52.974Z","dependency_job_id":null,"html_url":"https://github.com/zellyn/gocool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zellyn%2Fgocool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zellyn%2Fgocool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zellyn%2Fgocool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zellyn%2Fgocool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zellyn","download_url":"https://codeload.github.com/zellyn/gocool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525156,"owners_count":21118616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","cool","coursera","go"],"created_at":"2024-10-31T10:12:24.983Z","updated_at":"2025-04-12T05:53:03.544Z","avatar_url":"https://github.com/zellyn.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"* gocool\n\n#+ATTR_HTML: title=\"No Maintenance Intended\"\n[[http://unmaintained.tech/][file:http://unmaintained.tech/badge.svg]]\n\nGo implementation of the [[http://theory.stanford.edu/~aiken/software/cool/cool.html][Cool programming language]].\n\nThis repository contains a Golang implementation of the homeworks for\nthe [[https://www.coursera.org/course/compilers][Coursera compilers class]].\n\n* Parts\n\nThe compiler is divided into four parts, corresponding to the four\nprogramming homework assignments: lexing, scanning, typechecking, and\ncompilation. The four shell scripts testlexer.sh, testparser.sh,\ntesttypes.sh, and testcgen.sh test each of these four parts. The test\ncases are obtained by running the \"grading.pl\" script for each\nhomework, and copying the test input and output. Minor changes have\nbeen made, as advised in the homework instructions, typically with\nregard to exact line numbers, although an effort has been made to\nmatch the examples.\n\n** Lexer\nThe lexer is a simple hand-written lexer, defined in parser/lex.go. It\nis a modified version of the [[http://golang.org/src/pkg/text/template/parse/lex.go][go template lexer]], copied and\nmodified. For more background, read or watch Rob Pike's excellent\ntalk, [[https://google.com/search?q=lexical%20scanning%20in%20go][Lexical Scanning in Go]].\n\n** Parser\nThe parser is a [[http://dinosaur.compilertools.net/yacc/][yacc]]-generated LALR(1) parser. Similarities to [[https://code.google.com/p/rsc/source/browse/cc/][Russ\nCox's C parser]] are due to the fact that it was frequently studied\nwhile wrestling with yacc. The AST classes in ast.go were defined by\nhand, and parser/dump.go contains functions that print them in the\nformat used by the C++/Java Cool scaffolding code provided in the\ncourse materials.\n\n** Typechecking\nThere's nothing interesting about the typechecking code: it was simply\nimplemented bit by bit until all the tests passed. It does a bit of\nwork (eg. symbol table generation) that could be considered part of\ncode generation.\n\n** Compilation\nThe compiler (main code in cgen/cgen.go and cgen/expr.go) is about as\nsimple as possible: a stack machine with an accumulator ($a0), and\n\"self\" saved in $s0 for easy reference. There are just a couple of\nthings not suggested in the homework assignment: the \"isa\"\ntag-checking routine, and the embedding of prototype object addresses\nand initialization functions into the dispatch tables.\n\nNo effort was made to do any optimizations or to use more registers.\n\ntestcgen.sh runs all the tests three times: once with no garbage\ncollection, once with garbage collection turned on, and once with both\ngarbage collection and collect-after-every-allocation debugging turned\non. If you set the environment variable NOSLOW before running it, it\nwill skip the third phase.\n\n* Supplementary notes\n** MIPS registers\n|----------------+--------------+------------------------------------+-------------------|\n| Number         | Name         | Function                           | Callee preserves? |\n|----------------+--------------+------------------------------------+-------------------|\n| $0             | zero         | always has value zero              |                   |\n| $1             | at           | assembler temporary                |                   |\n| $2-$3          | v0,v1        | function results. Can be temporary |                   |\n| $4-$7          | a0,a1,a2,a3  | function arguments                 |                   |\n| $8-$15,$24,$25 | t0,...,t7,t9 | temporary registers                |                   |\n| $16-$23        | s0,...,s7    | saved registers                    | Yes               |\n| $26,$27        | k0,k1        | Reserved for OS kernel             |                   |\n| $28            | gp           | global pointer                     | Yes               |\n| $29            | sp           | stack pointer                      | Yes               |\n| $30            | fp           | frame pointer                      | Yes               |\n| $31            | ra           | return address                     |                   |\n|----------------+--------------+------------------------------------+-------------------|\n\n** Code generation\nStack machine with accumulator.\n\nAccumulator: $a0: holds result of last expression evaluation.\n$s0 holds a stored copy of \"self\".\n$sp points to next location in stack (so $sp+4 is the top of the stack)\n$t0, $t1, $t2 are temporary registers.\n\n** Activation Record\n- Return address\n- Old frame pointer\n- n arguments\n- NT(e) temporary locations\n\n| arg_1          |                 |\n| ⋮              |                 |\n| arg_n          |                 |\n|----------------+-----------------|\n| Old FP         | \u003c-- SP on entry |\n| Return address |                 |\n| Temp NT(e)     |                 |\n| ⋮              |                 |\n| Temp 1         | \u003c-- New FP      |\n|                | \u003c-- New SP      |\n\n** Object layout\n\n| -4 | FFFF - garbage collector tag  |\n|  0 | class tag                     |\n|  4 | object size (in 32-bit words) |\n|  8 | dispatch pointer              |\n| 12 | attributes                    |\n|  ⋮ | ⋮                             |\n\nStrings:\n\n| 12 | Length: pointer to an Int                            |\n| 16 | Characters, nul-terminated, zero-padded to next word |\n|  ⋮ | ⋮                                                    |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzellyn%2Fgocool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzellyn%2Fgocool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzellyn%2Fgocool/lists"}